📄 mac-802_11.cc~
字号:
bind_bw("dataRate_", &dataRate_); else dataRate_ = bandwidth_; printf(" QoS Mac/802_11 object created with index_=%d\n",index_);}intMac802_11::command(int argc, const char*const* argv){//@@ FaZ if ((argc == 9) || (argc == 10)) {//@@ FaZ if (strcmp(argv[1], "TSPEC") == 0) { if(!HC_) return TCL_ERROR; u_int32_t tspec_node=atoi(argv[2]); if(tspec_node>=cache_node_count_) return TCL_ERROR; u_int32_t tspec_tc=atoi(argv[3]); if (tspec_tc>=8) return TCL_ERROR; u_int32_t tspec_MSDU=atoi(argv[4]); if (tspec_MSDU>2304) return TCL_ERROR; double tspec_TargetDelay=atof(argv[5]); if (tspec_TargetDelay<=0.0) return TCL_ERROR; double tspec_DataRate=atof(argv[6]); if (tspec_DataRate<=0.0) return TCL_ERROR; u_int32_t tspec_MaxMSDU=atoi(argv[7]); if (tspec_MaxMSDU>2304) return TCL_ERROR; if (tspec_MaxMSDU<tspec_MSDU) return TCL_ERROR; double tspec_SourceRate=atof(argv[8]); if (tspec_SourceRate<=0.0) return TCL_ERROR;//@@ FaZ u_char tspec_PS; if (argc == 10) { tspec_PS=atoi(argv[9]); if (tspec_PS) n_ps_sta++; } else { tspec_PS=0; // default no PS Mode }//@ FaZ printf(" TSPEC (Node %d, TC %d): Nominal MSDU is %d bytes, Max MSDU is %d bytes, target delay is %2.6f s, phy rate is %2.0f bps, source rate is %2.0f bps, PS Mode is %d\n",tspec_node,tspec_tc,tspec_MSDU,tspec_MaxMSDU,tspec_TargetDelay,tspec_DataRate,tspec_SourceRate,tspec_PS); QueueSizeTable *esta_node = &ESTA_[tspec_node]; esta_node->NominalMSDU[tspec_tc] = tspec_MSDU; esta_node->MaxMSDU[tspec_tc] = tspec_MaxMSDU; esta_node->TargetDelay[tspec_tc] = tspec_TargetDelay; esta_node->toPoll[tspec_tc] = 1; esta_node->DataRate = tspec_DataRate; esta_node->SourceRate[tspec_tc] = tspec_SourceRate;//@@ FaZ esta_node->PS = tspec_PS;//@ FaZ return TCL_OK; } } else if (argc == 3) { if (strcmp(argv[1], "log-target") == 0) { logtarget_ = (NsObject*) TclObject::lookup(argv[2]); if(logtarget_ == 0) return TCL_ERROR; return TCL_OK; } else if(strcmp(argv[1], "nodes") == 0) { if(cache_) return TCL_ERROR; cache_node_count_ = atoi(argv[2]); //printf(" Node %d: num_nodes=%d\n",index_,atoi(argv[2])); cache_ = new Host[cache_node_count_ + 1]; assert(cache_); bzero(cache_, sizeof(Host) * (cache_node_count_+1 )); return TCL_OK; } else if(strcmp(argv[1], "set-TC") == 0) { tc_= atoi(argv[2]); if (tc_>7) tc_=TC_DEFAULT_; //rst_cw(tc_); printf(" Traffic Class for node %d on time %2.9f set to: %d\n",index_,Scheduler::instance().clock(),tc_); return TCL_OK; } else if(strcmp(argv[1], "set-Tsf") == 0) { Tsf_= atoi(argv[2])*0.001024; // conversion from TU to s if (Tsf_<=0.0) { printf(" ERROR: invalid Tsf, it must be in TU (1TU=1024us)\n"); return TCL_ERROR; } if (HC_==0) { HC_=1; mhBeacon_.start(Tsf_); printf(" Node %d on time %2.9f becomes Hybrid Coordinator\n",index_,Scheduler::instance().clock()); // Inizialization of HCF scheduler data collection's table ESTA_ = new QueueSizeTable[cache_node_count_ + 1]; assert(ESTA_); bzero(ESTA_, sizeof(QueueSizeTable) * (cache_node_count_+1 )); } printf(" Node %d (Hybrid Coordinator) on time %2.9f set SuperFrame=%f\n",index_,Scheduler::instance().clock(),Tsf_); return TCL_OK; } else if(strcmp(argv[1], "select-scheduler") == 0) { if (!HC_) return TCL_ERROR; if (strcmp(argv[2],"BCGM") == 0) sched=0; else if (strcmp(argv[2],"draft4.0") == 0) sched=1;//@@ FaZ else if (strcmp(argv[2],"BCGM-noPrePoll") == 0) { sched=0; no_pre_poll=1; }//@ FaZ else return TCL_ERROR; printf(" Selected scheduler: %s\n",argv[2]); return TCL_OK; } else if(strcmp(argv[1], "trace-delays") == 0) { char tracefilename[500]; strcpy(tracefilename,argv[2]); logdelays_=fopen(tracefilename,"w"); if (logdelays_==NULL) return TCL_ERROR; printf(" Node %d trace packet's delays to file: %s\n",index_,tracefilename); return TCL_OK; } else if(strcmp(argv[1], "trace-statistics") == 0) { if (!HC_) return TCL_ERROR; char tracefilename[500]; strcpy(tracefilename,argv[2]); logstatistics_=fopen(tracefilename,"w"); if (logstatistics_==NULL) return TCL_ERROR; printf(" HC (node %d) trace HCF usage statistics to file: %s\n",index_,tracefilename); return TCL_OK; } //@@ FaZ else if(strcmp(argv[1], "ps-sta") == 0) { if(!HC_) return TCL_ERROR; u_int32_t ps_node=atoi(argv[2]); QueueSizeTable *esta_node = &ESTA_[ps_node]; esta_node->PS = 1; n_ps_sta++; printf("Node %d becomes a PS STA...\n",index_); return TCL_OK; }//@ FaZ /*else if(strcmp(argv[1], "set-CFP") == 0) { Tcfp_= atof(argv[2]); if (Tcfp_<=0.0) { printf(" ERROR: invalid CFP\n"); return TCL_ERROR; } if (HC_==0) { HC_=1; mhBeacon_.start(Tsf_); printf(" Node %d on time %2.9f becomes Hybrid Coordinator\n",index_,Scheduler::instance().clock()); } printf(" Node %d (Hybrid Coordinator) on time %2.9f set CFP=%f\n",index_,Scheduler::instance().clock(),Tcfp_); return TCL_OK; }*/ } else if (argc == 2) { if (strcmp(argv[1], "show-params") == 0) { printf("\nShow-params for node %d on time %2.9f:\n",index_,Scheduler::instance().clock()); printf("\tbasicRate_ %f\n",basicRate_); printf("\tdataRate_ %f\n",dataRate_); printf("\tsifs_ %f\n",sifs_); printf("\tpifs_ %f\n",pifs_); printf("\tdifs_ %f\n",difs_); printf("\teifs_ %f\n",eifs_); printf("\ttx_sifs_ %f\n",tx_sifs_); printf("\ttx_difs_ %f\n",tx_difs_); //printf("\ttx_eifs_ %f\n",tx_eifs_); printf("\tmacmib_->RTSThreshold %d\n",macmib_->RTSThreshold); printf("\tphymib_->CWMin %d\n",phymib_->CWMin); printf("\tphymib_->CWMax %d\n",phymib_->CWMax); printf("\tphymib_->SIFSTime %f\n",phymib_->SIFSTime); printf("\tphymib_->SlotTime %f\n",phymib_->SlotTime); printf("\tphymib_->RxTxTurnaroundTime %f\n",phymib_->RxTxTurnaroundTime); printf("\tphymib_->PLCPPreambleRate %f\n",phymib_->PLCPPreambleRate); printf("\tphymib_->PLCPHeaderRate %f\n",phymib_->PLCPHeaderRate); printf("\tPLCP_HDR_LEN %d\n",PLCP_HDR_LEN); printf("\tphymib_->PLCPHeaderLength %d\n",phymib_->PLCPHeaderLength); printf("\tphymib_->PLCPPreambleLength %d\n",phymib_->PLCPPreambleLength); printf("\tETHER_ACK_LEN %d\n",ETHER_ACK_LEN); printf("\tETHER_RTS_LEN %d\n",ETHER_RTS_LEN); printf("\tETHER_CTS_LEN %d\n",ETHER_CTS_LEN); printf("\tETHER_HDR_LEN11 %d\n",ETHER_HDR_LEN11); printf("\tETHER_BEACON_LEN %d\n",ETHER_BEACON_LEN); printf("\ttc_ %d\n",tc_); printf("\n"); return TCL_OK; } else if(strcmp(argv[1], "close-trace-delays") == 0) { if (logdelays_==NULL) return TCL_ERROR; fclose(logdelays_); logdelays_=NULL; //printf(" Node %d closing trace packet's delays file\n",index_); return TCL_OK; } else if(strcmp(argv[1], "close-trace-statistics") == 0) { if (logstatistics_==NULL) return TCL_ERROR; fclose(logstatistics_); logstatistics_=NULL; //printf(" Node %d closing trace packet's delays file\n",index_); return TCL_OK; } else if(strcmp(argv[1], "EnableScheduler") == 0) { if (!HC_) { printf(" ERROR: EnableScheduler is possible only on HC\n"); return TCL_ERROR; } printf(" HCF Scheduler enabled\n"); es_=1; return TCL_OK; } else if(strcmp(argv[1], "show-HCFstatistics") == 0) { if (!HC_) { printf(" ERROR: show-max_assigned_txop is possible only on HC\n"); return TCL_ERROR; } printf(" HCF Scheduler: Maximum Assigned Txop is %d\n",maximum_assigned_txop); printf(" Maximum Reassigned Txop is %d\n",maximum_reassigned_txop); printf(" Maximum Superframe usage is %2.2f\%\n",maximum_superframe_usage); printf(" Maximum Superframe Reusage is %2.2f\%\n",maximum_superframe_reusage); printf(" Maximum Txop Number in a SF is %d\n",max_txop_number); return TCL_OK; } else if(strcmp(argv[1], "dot11a") == 0) { phymib_->SIFSTime = 0.000016; // 16us phymib_->SlotTime = 0.000009; // 9us phymib_->RxTxTurnaroundTime = 0.000002; phymib_->PLCPPreambleRate = 6.0e6; // 6Mbps phymib_->PLCPHeaderRate = 6.0e6; // 6Mbps phymib_->PLCPPreambleLength = 120; // 120bits; this approssimation leads to 20us of preamble phymib_->PLCPHeaderLength = 24; // 24bits; this approssimation leads to 4us of header phymib_->CWMin = 15; phymib_->CWMax = 1023; printf(" Physical MIB updated for IEEE 802.11a on node %d\n",index_); sifs_ = phymib_->SIFSTime; pifs_ = sifs_ + phymib_->SlotTime; difs_ = sifs_ + 2*phymib_->SlotTime; eifs_ = sifs_ + (8 * ETHER_ACK_LEN / phymib_->PLCPPreambleRate) + difs_; tx_sifs_ = sifs_ - phymib_->RxTxTurnaroundTime; tx_pifs_ = tx_sifs_ + phymib_->SlotTime; tx_difs_ = tx_sifs_ + 2 * phymib_->SlotTime; // AC 3 (Draft 4.0 default) High priority CWMin_[0]=((phymib_->CWMin+1)/4)-1; CWMax_[0]=((phymib_->CWMin+1)/2)-1; rst_cw(0); aifs_[0]=1*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[1]=((phymib_->CWMin+1)/4)-1; CWMax_[1]=((phymib_->CWMin+1)/2)-1; rst_cw(1); aifs_[1]=1*phymib_->SlotTime+phymib_->SIFSTime; // AC 2 (Draft 4.0 default) CWMin_[2]=((phymib_->CWMin+1)/2)-1; CWMax_[2]=phymib_->CWMin; rst_cw(2); aifs_[2]=1*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[3]=((phymib_->CWMin+1)/2)-1; CWMax_[3]=phymib_->CWMin; rst_cw(3); aifs_[3]=1*phymib_->SlotTime+phymib_->SIFSTime; // AC 1 (Draft 4.0 default) CWMin_[4]=phymib_->CWMin; CWMax_[4]=phymib_->CWMax; rst_cw(4); aifs_[4]=1*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[5]=phymib_->CWMin; CWMax_[5]=phymib_->CWMax; rst_cw(5); aifs_[5]=1*phymib_->SlotTime+phymib_->SIFSTime; // AC 0 (Draft 4.0 default) Low priority CWMin_[6]=phymib_->CWMin; CWMax_[6]=phymib_->CWMax; rst_cw(3); aifs_[6]=2*phymib_->SlotTime+phymib_->SIFSTime; CWMin_[7]=phymib_->CWMin; CWMax_[7]=phymib_->CWMax; rst_cw(7); aifs_[7]=2*phymib_->SlotTime+phymib_->SIFSTime; return TCL_OK; }//@@ FaZ else if(strcmp(argv[1], "paraqwlan") == 0) { EnergyModel *em=netif_->node()->energy_model(); if (!em) { printf("Error, cannot get Energy Model for STA %d\n",index_); exit(1); } em->paraqflag() = 1; printf("Starting Paraq for node %d \n",index_); em->start_paraq(this); return TCL_OK; } else if(strcmp(argv[1], "use-psEDCA") == 0) { EnergyModel *em=netif_->node()->energy_model(); if (!em) { printf("Error, cannot get Energy Model for STA %d\n",index_); exit(1); } use_psEDCA=1; return TCL_OK; } else if(strcmp(argv[1], "use-only-psEDCA") == 0) { EnergyModel *em=netif_->node()->energy_model(); if (!em) { printf("Error, cannot get Energy Model for STA %d\n",index_); exit(1); } if (use_psEDCA) { printf("Error, cannot use both \"only-EDCA\" and Paraq at node %d\n",index_); exit(1); }; use_only_psEDCA=1; return TCL_OK; } else if(strcmp(argv[1], "NoScheduleElement") == 0) { if (HC_) dont_use_sch_el=1; return TCL_OK; } else if(strcmp(argv[1], "UseWrkAroundFirstSchEl") == 0) { if (HC_) use_wa_first_schel=1; printf("Using workaround for first schedule element...\n"); return TCL_OK; }//@ FaZ } return Mac::command(argc, argv);}/* ====================================================================== Debugging Routines ====================================================================== */voidMac802_11::trace_pkt(Packet *p) { struct hdr_cmn *ch = HDR_CMN(p); struct hdr_mac802_11* dh = HDR_MAC802_11(p); u_int16_t *t = (u_int16_t*) &dh->dh_fc; fprintf(stderr, "\t[ %2x %2x %2x %2x ] %x %s %d\n", *t, dh->dh_duration, ETHER_ADDR(dh->dh_da), ETHER_ADDR(dh->dh_sa), index_, packet_info.name(ch->ptype()), ch->size());}voidMac802_11::dump(char *fname){ fprintf(stderr, "\n%s --- (INDEX: %d, time: %2.9f)\n", fname, index_, Scheduler::instance().clock()); fprintf(stderr, "\ttx_state_: %x, rx_state_: %x, nav: %2.9f, idle: %d\n", tx_state_, rx_state_, nav_[tc_], is_idle(tc_)); fprintf(stderr, "\tpktTx_: %x, pktRx_: %x, pktRTS_: %x, pktCTRL_: %x, callback: %x\n", (int) pktTx_, (int) pktRx_, (int) pktRTS_, (int) pktCTRL_, (int) callback_); fprintf(stderr, "\tDefer: %d, Backoff: %d (%d), Recv: %d, Timer: %d Nav: %d\n", mhDefer_[tc_].busy(), mhBackoff_[tc_].busy(), mhBackoff_[tc_].paused(), mhRecv_.busy(), mhSend_.busy(), mhNav_[tc_].busy()); fprintf(stderr, "\tBackoff Expire: %f\n", mhBackoff_[tc_].expire());}/* ====================================================================== Packet Headers Routines ====================================================================== */inline intMac802_11::hdr_dst(char* hdr, int dst ){ struct hdr_mac802_11 *dh = (struct hdr_mac802_11*) hdr; //dst = (u_int32_t)(dst); if(dst > -2) STORE4BYTE(&dst, (dh->dh_da)); return ETHER_ADDR(dh->dh_da);}inline int Mac802_11::hdr_src(char* hdr, int src ){ struct hdr_mac802_11 *dh = (struct hdr_mac802_11*) hdr; if(src > -2) STORE4BYTE(&src, (dh->dh_sa)); return ETHER_ADDR(dh->dh_sa);}inline int Mac802_11::hdr_type(char* hdr, u_int16_t type){ struct hdr_mac802_11 *dh = (struct hdr_mac802_11*) hdr; if(type) STORE2BYTE(&type,(dh->dh_body)); return GET2BYTE(dh->dh_body);}/* ====================================================================== Misc Routines ====================================================================== */inline intMac802_11::is_idle(u_int32_t nav_tc_){ if(rx_state_ != MAC_IDLE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -