📄 p802_15_4mac.cc
字号:
/********************************************//* NS2 Simulator for IEEE 802.15.4 *//* (per P802.15.4/D18) *//*------------------------------------------*//* by: Jianliang Zheng *//* (zheng@ee.ccny.cuny.edu) *//* Myung J. Lee *//* (lee@ccny.cuny.edu) *//* ~~~~~~~~~~~~~~~~~~~~~~~~~ *//* SAIT-CUNY Joint Lab *//********************************************/// File: p802_15_4mac.cc// Mode: C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t// $Header: p802_15_4mac.cc,v 1.1 2004/10/15 17:32:08 zheng Exp $/* * Copyright (c) 2003-2004 Samsung Advanced Institute of Technology and * The City University of New York. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Joint Lab of Samsung * Advanced Institute of Technology and The City University of New York. * 4. Neither the name of Samsung Advanced Institute of Technology nor of * The City University of New York may be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE JOINT LAB OF SAMSUNG ADVANCED INSTITUTE * OF TECHNOLOGY AND THE CITY UNIVERSITY OF NEW YORK ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL SAMSUNG ADVANCED INSTITUTE OR THE CITY UNIVERSITY OF NEW YORK * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "p802_15_4pkt.h"#include "p802_15_4mac.h"#include "p802_15_4const.h"#include "p802_15_4csmaca.h"#include "p802_15_4sscs.h"#include "p802_15_4trace.h"#include "p802_15_4fail.h"#include "p802_15_4nam.h"bool Mac802_15_4::verbose = false;UINT_8 Mac802_15_4::txOption = 0x00; //0x02=GTS; 0x04=Indirect; 0x00=Direct (only for 802.15.4-unaware upper layer app. packet)bool Mac802_15_4::ack4data = true;UINT_8 Mac802_15_4::callBack = 1; //0=no call back; 1=call back for failures; 2=call back for failures and successesUINT_32 Mac802_15_4::DBG_UID = 0;static MAC_PIB MPIB ={ def_macAckWaitDuration, def_macAssociationPermit, def_macAutoRequest, def_macBattLifeExt, def_macBattLifeExtPeriods, def_macBeaconPayload, def_macBeaconPayloadLength, def_macBeaconOrder, def_macBeaconTxTime, 0/*def_macBSN*/, def_macCoordExtendedAddress, def_macCoordShortAddress, 0/*def_macDSN*/, def_macGTSPermit, def_macMaxCSMABackoffs, def_macMinBE, def_macPANId, def_macPromiscuousMode, def_macRxOnWhenIdle, def_macShortAddress, def_macSuperframeOrder, def_macTransactionPersistenceTime, def_macACLEntryDescriptorSet, def_macACLEntryDescriptorSetSize, def_macDefaultSecurity, def_macACLDefaultSecurityMaterialLength, def_macDefaultSecurityMaterial, def_macDefaultSecuritySuite, def_macSecurityMode};void Mac802_15_4Handler::handle(Event* e){ nullEvent.uid_ = 0; if (type == macTxBcnCmdDataHType) mac->txBcnCmdDataHandler(); else if (type == macIFSHType) mac->IFSHandler(); else if (type == macBackoffBoundType) mac->backoffBoundHandler(); else assert(0);}int hdr_lrwpan::offset_;static class LRWPANHeaderClass : public PacketHeaderClass{public: LRWPANHeaderClass() : PacketHeaderClass("PacketHeader/LRWPAN", sizeof(hdr_lrwpan)) { bind_offset(&hdr_lrwpan::offset_); }} class_hdr_lrwpan;static class Mac802_15_4Class : public TclClass{public: Mac802_15_4Class() : TclClass("Mac/802_15_4") {} TclObject* create(int, const char*const*) { return (new Mac802_15_4(&MPIB)); } virtual void bind(void); virtual int method(int argc, const char*const* argv);} class_mac802_15_4;void Mac802_15_4Class::bind(void){ TclClass::bind(); add_method("wpanCmd"); add_method("wpanNam");}int Mac802_15_4Class::method(int ac, const char*const* av){ //Available methods: // ------------------------------------------------------------------------------------------ // bool Mac802_15_4::verbose; (Tcl command: Mac/802_15_4 wpanCmd verbose [on/off] // UINT_8 Mac802_15_4::txOption; (Tcl command: Mac/802_15_4 wpanCmd txOption [2/4/0] // bool Mac802_15_4::ack4data; (Tcl command: Mac/802_15_4 wpanCmd ack4data [on/off] // UINT_8 Mac802_15_4::callBack; (Tcl command: Mac/802_15_4 wpanCmd callBack [0/1/2] // link down; (Tcl command: Mac/802_15_4 wpanCmd link-down <src> <dst> // link up; (Tcl command: Mac/802_15_4 wpanCmd link-up <src> <dst> // ------------------------------------------------------------------------------------------ // bool Nam802_15_4::Nam_Status; (Tcl command: Mac/802_15_4 wpanNam namStatus [on/off] // bool Nam802_15_4::emHandling; (Tcl command: Mac/802_15_4 wpanNam emHandling [on/off] // char *Nam802_15_4::def_PANCoor_clr; (Tcl command: Mac/802_15_4 wpanNam PANCoorClr [clrName] // char *Nam802_15_4::def_Coor_clr; (Tcl command: Mac/802_15_4 wpanNam CoorClr [clrName] // char *Nam802_15_4::def_Dev_clr; (Tcl command: Mac/802_15_4 wpanNam DevClr [clrName] // char *Nam802_15_4::def_ColFlash_clr; (Tcl command: Mac/802_15_4 wpanNam ColFlashClr [clrName] // char *Nam802_15_4::def_NodeFail_clr; (Tcl command: Mac/802_15_4 wpanNam NodeFailClr [clrName] // playback rate; (Tcl command: Mac/802_15_4 wpanNam PlaybackRate [step_in_ms] // flow colors; (Tcl command: Mac/802_15_4 wpanNam FlowClr [-p <packet_type_name>] [-s <src>] [-d <dst>] [-c <clrName>] // ------------------------------------------------------------------------------------------ Tcl& tcl = Tcl::instance(); int argc = ac - 2; const char*const* argv = av + 2; if (strcmp(argv[1], "wpanCmd") == 0) if (argc == 3) { if (strcmp(argv[2], "verbose") == 0) { if (!Mac802_15_4::verbose) tcl.result("off"); else tcl.result("on"); return (TCL_OK); } else if (strcmp(argv[2], "txOption") == 0) { if (Mac802_15_4::txOption == 0x02) tcl.result("GTS"); else if (Mac802_15_4::txOption == 0x04) tcl.result("Indirect"); else tcl.result("Direct"); return (TCL_OK); } else if (strcmp(argv[2], "ack4data") == 0) { if (!Mac802_15_4::ack4data) tcl.result("off"); else tcl.result("on"); return (TCL_OK); } else if (strcmp(argv[2], "callBack") == 0) { tcl.resultf("%u",Mac802_15_4::callBack); return (TCL_OK); } } else if (argc == 4) { if (strcmp(argv[2], "verbose") == 0) { if (strcmp(argv[3], "on") == 0) Mac802_15_4::verbose = true; else Mac802_15_4::verbose = false; return (TCL_OK); } else if (strcmp(argv[2], "txOption") == 0) { Mac802_15_4::txOption = atoi(argv[3]); return (TCL_OK); } else if (strcmp(argv[2], "ack4data") == 0) { if (strcmp(argv[3], "on") == 0) Mac802_15_4::ack4data = true; else Mac802_15_4::ack4data = false; return (TCL_OK); } else if (strcmp(argv[2], "callBack") == 0) { Mac802_15_4::callBack = atoi(argv[3]); return (TCL_OK); } } else if (argc == 5) { if (strcmp(argv[2], "link-down") == 0) { chkAddLFailLink(atoi(argv[3]),atoi(argv[4])); return (TCL_OK); } else if (strcmp(argv[2], "link-up") == 0) { updateLFailLink(fl_oper_del,atoi(argv[3]),atoi(argv[4])); return (TCL_OK); } } if (strcmp(argv[1], "wpanNam") == 0) if (strcmp(argv[2], "namStatus") == 0) { if (argc == 3) { if (!Nam802_15_4::Nam_Status) tcl.result("off"); else tcl.result("on"); } else if (argc == 4) { if (strcmp(argv[3], "on") == 0) Nam802_15_4::Nam_Status = true; else Nam802_15_4::Nam_Status = false; } return (TCL_OK); } else if (strcmp(argv[2], "emHandling") == 0) { if (argc == 3) { if (!Nam802_15_4::emHandling) tcl.result("off"); else tcl.result("on"); } else if (argc == 4) { if (strcmp(argv[3], "on") == 0) Nam802_15_4::emHandling = true; else Nam802_15_4::emHandling = false; } return (TCL_OK); } else if (strcmp(argv[2], "PANCoorClr") == 0) { if (argc == 3) tcl.result(Nam802_15_4::def_PANCoor_clr); else if (argc >= 4) { strncpy(Nam802_15_4::def_PANCoor_clr,argv[3],20); Nam802_15_4::def_PANCoor_clr[20] = 0; } return (TCL_OK); } else if (strcmp(argv[2], "CoorClr") == 0) { if (argc == 3) tcl.result(Nam802_15_4::def_Coor_clr); else if (argc >= 4) { strncpy(Nam802_15_4::def_Coor_clr,argv[3],20); Nam802_15_4::def_Coor_clr[20] = 0; } return (TCL_OK); } else if (strcmp(argv[2], "DevClr") == 0) { if (argc == 3) tcl.result(Nam802_15_4::def_Dev_clr); else if (argc >= 4) { strncpy(Nam802_15_4::def_Dev_clr,argv[3],20); Nam802_15_4::def_Dev_clr[20] = 0; } return (TCL_OK); } else if (strcmp(argv[2], "ColFlashClr") == 0) { if (argc == 3) tcl.result(Nam802_15_4::def_ColFlash_clr); else if (argc >= 4) { strncpy(Nam802_15_4::def_ColFlash_clr,argv[3],20); Nam802_15_4::def_ColFlash_clr[20] = 0; } return (TCL_OK); } else if (strcmp(argv[2], "NodeFailClr") == 0) { if (argc == 3) tcl.result(Nam802_15_4::def_NodeFail_clr); else if (argc >= 4) { strncpy(Nam802_15_4::def_NodeFail_clr,argv[3],20); Nam802_15_4::def_NodeFail_clr[20] = 0; } return (TCL_OK); } else if (strcmp(argv[2], "PlaybackRate") == 0) { if (argc == 3) tcl.result("??"); else if (argc >= 4) Nam802_15_4::changePlaybackRate(CURRENT_TIME,argv[3]); return (TCL_OK); } else if (strcmp(argv[2], "FlowClr") == 0) { int i,lp,src,dst; char pName[21],cName[21]; ATTRIBUTELINK *attr; src = -2; dst = -2; strcpy(pName,packet_info.name(PT_NTYPE)); lp = (argc - 3) / 2; for (i=0;i<lp;i++) { if (strcmp(argv[i*2+3],"-p") == 0) { strncpy(pName,argv[i*2+4],20); pName[20] = 0; } else if (strcmp(argv[i*2+3],"-s") == 0) src = atoi(argv[i*2+4]); else if (strcmp(argv[i*2+3],"-d") == 0) dst = atoi(argv[i*2+4]); else if (strcmp(argv[i*2+3],"-c") == 0) { strncpy(cName,argv[i*2+4],20); cName[20] = 0; } } i = chkAddAttrLink(nam_pktName2Type(pName),cName,src,dst); if (i == 1) //already exist { attr = findAttrLink(nam_pktName2Type(pName),src,dst); if (strcmp(attr->color,cName) != 0) //color changed { strncpy(attr->color,cName,20); attr->color[20] = 0; Nam802_15_4::flowAttribute(attr->attribute,attr->color); } } else if (i == 0) //added into the link { attr = findAttrLink(nam_pktName2Type(pName),src,dst); Nam802_15_4::flowAttribute(attr->attribute,attr->color); } return (TCL_OK); } return TclClass::method(ac, av);}Mac802_15_4::Mac802_15_4(MAC_PIB *mp) : Mac(),txCmdDataH(this,macTxBcnCmdDataHType),IFSH(this,macIFSHType),backoffBoundH(this,macBackoffBoundType){ capability.cap = 0xc1; //alterPANCoor = true //FFD = true //mainsPower = false //recvOnWhenIdle = false //secuCapable = false //alloShortAddr = true capability.parse(); aExtendedAddress = index_; oneMoreBeacon = false; isPANCoor = false; inTransmission = false; mpib = *mp; mpib.macBSN = Random::random() % 0x100; mpib.macDSN = Random::random() % 0x100; macBeaconOrder2 = 15; macSuperframeOrder2 = def_macBeaconOrder;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -