📄 mac-802_11.cc~
字号:
if (!HC_ && check_PolledTXOP() == 0) return; //if (index_==0) printf(" DeferHandler winner TC: %d\n",tc_); assert((pktBeacon_ && btbs_==0) || pktCTRL_ || pktRTS_ || pktQoSTx_[winner_tc_] || pktSchElem_ ); //u_int32_t old_tc_=tc_; tc_=winner_tc_; if(check_pktCTRL() == 0) return; //else tc_=old_tc_; if(btbs_==0 && check_pktBeacon()==0) return; if(ptbs_==0 && check_pktQoSPoll()==0) { //printf("Poll sent at time %2.9f \n",Scheduler::instance().clock()); return; } //@@ FaZ if(check_pktSchElem() == 0) {// if (n_ps_sta) printf("In deferHandler for Schedule Element at time %2.9f \n",Scheduler::instance().clock()); return; }//@ FaZ assert(mhBackoff_[winner_tc].busy() == 0); //if (mhBackoff_.busy() != 0) //{ // printf("deferHandler:mhBackoff_ busy!\n"); // return; //} //tc_=winner_tc_; if(check_pktRTS() == 0) return; if(check_pktTx() == 0) return;}voidMac802_11::navHandler(u_int32_t winner_tc_){ if(is_idle(winner_tc_) && mhBackoff_[winner_tc_].paused()) mhBackoff_[winner_tc_].resume(aifs_[winner_tc_]);}voidMac802_11::recvHandler(){ recv_timer();}voidMac802_11::sendHandler(){ send_timer();}voidMac802_11::txHandler(){ tx_active_ = 0;}voidMac802_11::BeaconHandler(){ if (!(HC_ && Tcfp_>=0.0 && Tcfp_<Tsf_)) printf(" BeaconHandler assert error!\n"); assert(HC_ && Tcfp_>=0.0 && Tcfp_<Tsf_); mhBeacon_.start(Tsf_); // schedule next beacon // Create the beacon packet Packet *p = Packet::alloc(); hdr_cmn* ch = HDR_CMN(p); struct beacon_frame *bf = (struct beacon_frame*)p->access(hdr_mac::offset_); ch->uid() = 0; ch->ptype() = PT_MAC; ch->size() = ETHER_BEACON_LEN; ch->iface() = -2; ch->error() = 0; bzero(bf, MAC_HDR_LEN); bf->bf_fc.fc_protocol_version = MAC_ProtocolVersion; bf->bf_fc.fc_type = MAC_Type_Management; bf->bf_fc.fc_subtype = MAC_Subtype_Beacon; bf->bf_fc.fc_to_ds = 0; bf->bf_fc.fc_from_ds = 0; bf->bf_fc.fc_more_frag = 0; bf->bf_fc.fc_retry = 0; bf->bf_fc.fc_pwr_mgt = 0; bf->bf_fc.fc_more_data = 0; bf->bf_fc.fc_wep = 0; bf->bf_fc.fc_order = 0; unsigned int dst = MAC_BROADCAST; STORE4BYTE(&dst, (bf->bf_da)); STORE4BYTE(&index_, (bf->bf_sa)); STORE4BYTE(&index_, (bf->bf_bssid)); ch->txtime() = txtime(ch->size(), basicRate_); bf->bf_duration = 0; // SuperFrame duration, in TU bf->bf_beacon_interval = (u_int16_t)floor(Tsf_/0.001024); bf->bf_scontrol = 0; // Schedule the trasmission of the beacon //Packet::free(p); pktBeacon_ = p; //printf("\n B %2.6f \n",Scheduler::instance().clock()); // beacon debug int idle=0; for(int i=0;i<=7;i++) idle+=/*(mhBackoff_[i].busy()==0)+*/(is_idle(i)==1)/*+(mhDefer_[i].busy()==0)*/; if (idle==8) { //printf("OK->Defer PIFS bh %2.6f\n",Scheduler::instance().clock()); if (mhDefer_[tc_].busy()) mhDefer_[tc_].stop(); mhDefer_[tc_].start(pifs_); btbs_=0; } else { btbs_=1; printf("BeaconHandler Warning: Beacon DELAY occurred on time %2.9f!!!\n",Scheduler::instance().clock()); }}/* ====================================================================== The "real" Timer Handler Routines ====================================================================== */voidMac802_11::send_timer(){//@@ FaZ EnergyModel *em=netif_->node()->energy_model();//@ FaZ switch(tx_state_) { /* * Sent a RTS, but did not receive a CTS. */ case MAC_RTS: RetransmitRTS(); break; /* * Sent a CTS, but did not receive a DATA packet. */ case MAC_CTS: assert(pktCTRL_); Packet::free(pktCTRL_); pktCTRL_ = 0; break; /* * Sent DATA, but did not receive an ACK packet. */ case MAC_SEND://@@ FaZ// serve per PS EDCA... if (use_psEDCA) { if (pktQoSTx_[tc_]==0) { tc_=polled_tc_; } }//@ FaZ RetransmitDATA(); break; /* * Sent an ACK, and now ready to resume transmission. */ case MAC_ACK: assert(pktCTRL_); Packet::free(pktCTRL_); pktCTRL_ = 0;//@@ FaZ // now go sleeping if we must if (gotosleep_) { //printf("Putting node %d to sleep...\n",index_); //EnergyModel *em=netif_->node()->energy_model(); //printf("Putting STA %d in sleep mode now %2.9f \n",index_,Scheduler::instance().clock()); em->pqst_->start(0.0); //printf("STA %d sleep status: %d \n",index_,em->sleep()); gotosleep_=false; }//@ FaZ break; /* * Sent a Beacon, and now ready to resume transmission. */ case MAC_BEACON: assert(pktBeacon_); Packet::free(pktBeacon_); pktBeacon_ = 0;//@@ FaZ mhScheduler_.start(0.0);//@ FaZ break; case MAC_QoSNULL: assert(pktQoSNull_); Packet::free(pktQoSNull_); pktQoSNull_ = 0;//@@ Faz // after a QoS-NULL, STA waits for another QoS-Poll before sleeping // EnergyModel *em=netif_->node()->energy_model(); if (em && em->paraqflag() && !dont_go_sleep_after_null){ //if (em && em->paraqflag()) { em->pqst_->start( pifs_ + txtime(ETHER_HDR_LEN11,dataRate_) // related to QoS-Poll + DSSS_MaxPropagationDelay // + 0.0001 ); } else {//@ FaZ // NAV resetting for (int i=0;i<=7;i++) { nav_[i] = Scheduler::instance().clock(); if(mhNav_[i].busy()) mhNav_[i].stop(); if(is_idle(i) && mhBackoff_[i].paused()) mhBackoff_[i].resume(aifs_[i]); } } if ( em && em->paraqflag() && dont_go_sleep_after_null) dont_go_sleep_after_null=0; break; case MAC_QoSPOLL: assert(pktQoSPoll_); Packet::free(pktQoSPoll_); pktQoSPoll_ = 0; //if ( !n_ps_sta || (n_ps_sta && !mhPSPoll_.busy()) ) schedulerResume(); schedulerResume(); break;//@@ FaZ case MAC_SCHELEM: assert(pktSchElem_); Packet::free(pktSchElem_); pktSchElem_=0; scheduleParaqSta(); //printf("Scaduto il tempo di attesa per lo sch. el. \n"); break;//@ FaZ case MAC_IDLE: break; default: assert(0); } tx_resume();}/* ====================================================================== Outgoing Packet Routines ====================================================================== */intMac802_11::check_pktCTRL(){ struct hdr_mac802_11 *mh; double timeout; if(pktCTRL_ == 0) return -1; if(tx_state_ == MAC_CTS || tx_state_ == MAC_ACK) return -1; mh = HDR_MAC802_11(pktCTRL_); switch(mh->dh_fc.fc_subtype) { /* * If the medium is not IDLE, don't send the CTS. */ case MAC_Subtype_CTS: if(!is_idle(tc_)) { discard(pktCTRL_, DROP_MAC_BUSY); pktCTRL_ = 0; return 0; } // EDCF Virtual Station update for(int i=0; i<=7; i++) if(i!=tc_) set_nav(usec(txtime(pktCTRL_))+mh->dh_duration,i); SET_TX_STATE(MAC_CTS); /* * timeout: cts + data tx time calculated by * adding cts tx time to the cts duration * minus ack tx time -- this timeout is * a guess since it is unspecified * (note: mh->dh_duration == cf->cf_duration) */ timeout = txtime(ETHER_CTS_LEN, basicRate_) + DSSS_MaxPropagationDelay // XXX + sec(mh->dh_duration) + DSSS_MaxPropagationDelay // XXX - sifs_ - txtime(ETHER_ACK_LEN, basicRate_); break; /* * IEEE 802.11 specs, section 9.2.8 * Acknowledments are sent after an SIFS, without regard to * the busy/idle state of the medium. */ case MAC_Subtype_ACK: // EDCF Virtual Station update for(int i=0; i<=7; i++) if(i!=tc_) set_nav(usec(txtime(pktCTRL_))+mh->dh_duration,i); SET_TX_STATE(MAC_ACK); //if (Scheduler::instance().clock() >= 15.0) printf("STA %d is sending ACK at time %2.9f...\n",index_,Scheduler::instance().clock()); timeout = txtime(ETHER_ACK_LEN, basicRate_); break; default: fprintf(stderr, "check_pktCTRL:Invalid MAC Control subtype\n"); exit(1); } //if (HC_ && n_ps_sta) printf("HC sent ACK to STA %i at time %2.9f...\n",(u_int32_t)ETHER_ADDR(mh->dh_da),Scheduler::instance().clock()); TRANSMIT(pktCTRL_, timeout); return 0;}intMac802_11::check_pktBeacon(){ struct hdr_mac802_11 *mh; double timeout; assert(mhBackoff_[tc_].busy() == 0); if(pktBeacon_ == 0) { return -1; } //@@ FaZ else { if(n_ps_sta) printf("\nSending beacon at time %2.9f \n",Scheduler::instance().clock()); }//@ FaZ mh = HDR_MAC802_11(pktBeacon_); switch(mh->dh_fc.fc_subtype) { case MAC_Subtype_Beacon: if(! is_idle(tc_)) { btbs_=1; return 0; } SET_TX_STATE(MAC_BEACON); timeout = txtime(pktBeacon_); break; default: fprintf(stderr, "check_pktBeacon:Invalid MAC Control subtype\n"); exit(1); } TBTT_=Scheduler::instance().clock()+Tsf_; //printf("\tNode %d (HC) at time %2.6f, set TBTT=%2.6f\n",index_,Scheduler::instance().clock(),TBTT_); TRANSMIT(pktBeacon_, timeout); if (nop>0) printf("\tWARNING: not all txops was sent in previous superframe (time %2.9f) (%i remaining polls)\n",Scheduler::instance().clock(),nop);//@@ FaZ // nel precedente SuperFrame si
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -