📄 ssscheduler.cc
字号:
if (t6timer_->busy()) t6timer_->pause(); scan_info_->normal_state.t6timer = t6timer_; if (t12timer_->busy()) t12timer_->pause(); scan_info_->normal_state.t12timer = t12timer_; if (t21timer_->busy()) t21timer_->pause(); scan_info_->normal_state.t21timer = t21timer_; if (lostDLMAPtimer_->busy()) lostDLMAPtimer_->pause(); scan_info_->normal_state.lostDLMAPtimer = lostDLMAPtimer_; if (lostULMAPtimer_->busy()) lostULMAPtimer_->pause(); scan_info_->normal_state.lostULMAPtimer = lostULMAPtimer_; scan_info_->normal_state.map = map_; if (scan_info_->iteration == 0) { //reset state t1timer_ = new WimaxT1Timer (mac_); t2timer_ = new WimaxT2Timer (mac_); t6timer_ = new WimaxT6Timer (mac_); t12timer_ = new WimaxT12Timer (mac_); t21timer_ = new WimaxT21Timer (mac_); lostDLMAPtimer_ = new WimaxLostDLMAPTimer (mac_); lostULMAPtimer_ = new WimaxLostULMAPTimer (mac_); map_ = new FrameMap (mac_); mac_->nextChannel(); scan_info_->scn_timer_ = new WimaxScanIntervalTimer (mac_); //start waiting for DL synch mac_->setMacState (MAC802_16_WAIT_DL_SYNCH); t21timer_->start (mac_->macmib_.t21_timeout); if (dl_timer_->status()==TIMER_PENDING) dl_timer_->cancel(); map_->getDlSubframe()->getTimer()->reset(); if (ul_timer_->status()==TIMER_PENDING) ul_timer_->cancel(); map_->getUlSubframe()->getTimer()->reset(); }else{ //restore where we left //restore previous timers mac_->restore_state(scan_info_->scan_state.state_info); t1timer_ = scan_info_->scan_state.t1timer; if (t1timer_->paused()) t1timer_->resume(); t2timer_ = scan_info_->scan_state.t2timer; if (t2timer_->paused()) t2timer_->resume(); t6timer_ = scan_info_->scan_state.t6timer; if (t6timer_->paused()) t6timer_->resume(); t12timer_ = scan_info_->scan_state.t12timer; if (t12timer_->paused()) t12timer_->resume(); t21timer_ = scan_info_->scan_state.t21timer; if (t21timer_->paused()) t21timer_->resume(); lostDLMAPtimer_ = scan_info_->scan_state.lostDLMAPtimer; if (lostDLMAPtimer_->paused()) lostDLMAPtimer_->resume(); lostULMAPtimer_ = scan_info_->scan_state.lostULMAPtimer; if (lostULMAPtimer_->paused()) lostULMAPtimer_->resume(); map_ = scan_info_->scan_state.map; mac_->getPhy()->setMode (OFDM_RECV); if (ul_timer_->status()==TIMER_PENDING) ul_timer_->cancel(); } mac_->setNotify_upper (false); //printf ("Scan duration=%d, frameduration=%f\n", scan_info_->rsp->scan_duration, mac_->getFrameDuration()); scan_info_->scn_timer_->start (scan_info_->rsp->scan_duration*mac_->getFrameDuration()); scan_info_->iteration++; }/** * Pause scanning */void SSscheduler::pause_scanning (){ if (scan_info_->iteration < scan_info_->rsp->scan_iteration) mac_->debug ("At %f in Mac %d, pause scanning\n", NOW, mac_->addr()); else mac_->debug ("At %f in Mac %d, stop scanning\n", NOW, mac_->addr()); //return to normal mode if (scan_info_->iteration < scan_info_->rsp->scan_iteration) { //backup current state scan_info_->scan_state.state_info = mac_->backup_state(); if (t1timer_->busy()) t1timer_->pause(); scan_info_->scan_state.t1timer = t1timer_; if (t2timer_->busy()) t2timer_->pause(); scan_info_->scan_state.t2timer = t2timer_; if (t6timer_->busy()) t6timer_->pause(); scan_info_->scan_state.t6timer = t6timer_; if (t12timer_->busy()) t12timer_->pause(); scan_info_->scan_state.t12timer = t12timer_; if (t21timer_->busy()) t21timer_->pause(); scan_info_->scan_state.t21timer = t21timer_; if (lostDLMAPtimer_->busy()) lostDLMAPtimer_->pause(); scan_info_->scan_state.lostDLMAPtimer = lostDLMAPtimer_; if (lostULMAPtimer_->busy()) lostULMAPtimer_->pause(); scan_info_->scan_state.lostULMAPtimer = lostULMAPtimer_; scan_info_->scan_state.map = map_; scan_info_->count = scan_info_->rsp->interleaving_interval; } else { //else scanning is over, no need to save data //reset timers if (t1timer_->busy()!=0) t1timer_->stop(); delete (t1timer_); if (t12timer_->busy()!=0) t12timer_->stop(); delete (t12timer_); if (t21timer_->busy()!=0) t21timer_->stop(); delete (t21timer_); if (lostDLMAPtimer_->busy()!=0) lostDLMAPtimer_->stop(); delete (lostDLMAPtimer_); if (lostULMAPtimer_->busy()!=0) lostULMAPtimer_->stop(); delete (lostULMAPtimer_); if (t2timer_->busy()!=0) t2timer_->stop(); delete (t2timer_); } //restore previous timers mac_->restore_state(scan_info_->normal_state.state_info); t1timer_ = scan_info_->normal_state.t1timer; if (t1timer_->paused()) t1timer_->resume(); t2timer_ = scan_info_->normal_state.t2timer; if (t2timer_->paused()) t2timer_->resume(); t6timer_ = scan_info_->normal_state.t6timer; if (t6timer_->paused()) t6timer_->resume(); t12timer_ = scan_info_->normal_state.t12timer; if (t12timer_->paused()) t12timer_->resume(); t21timer_ = scan_info_->normal_state.t21timer; if (t21timer_->paused()) t21timer_->resume(); lostDLMAPtimer_ = scan_info_->normal_state.lostDLMAPtimer; if (lostDLMAPtimer_->paused()) lostDLMAPtimer_->resume(); lostULMAPtimer_ = scan_info_->normal_state.lostULMAPtimer; if (lostULMAPtimer_->paused()) lostULMAPtimer_->resume(); map_ = scan_info_->normal_state.map; mac_->setNotify_upper (true); dl_timer_->resched (0); if (scan_info_->iteration == scan_info_->rsp->scan_iteration) { scan_info_->substate = NORMAL; /** here we check if there is a better BS **/ send_msho_req(); scan_info_->count--; //to avoid restarting scanning //delete (scan_info_); //scan_info_ = NULL; } else { scan_info_->substate = SCAN_PENDING; }}/** * Send a MSHO-REQ message to the BS */void SSscheduler::send_msho_req (){ Packet *p; struct hdr_cmn *ch; hdr_mac802_16 *wimaxHdr; mac802_16_mob_msho_req_frame *req_frame; double rssi; PeerNode *peer = mac_->getPeerNode_head(); int nbPref = 0; for (int i = 0 ; i < nbr_db_->getNbNeighbor() ; i++) { NeighborEntry *entry = nbr_db_->getNeighbors()[i]; if (entry->isDetected()) { mac_->debug ("At %f in Mac %d Found new AP %d..need to send HO message\n",NOW, mac_->addr(), entry->getID()); nbPref++; } } if (nbPref==0) return; //no other BS found //create packet for request p = mac_->getPacket (); ch = HDR_CMN(p); wimaxHdr = HDR_MAC802_16(p); p->allocdata (sizeof (struct mac802_16_mob_msho_req_frame)+nbPref*sizeof (mac802_16_mob_msho_req_bs_index)); req_frame = (mac802_16_mob_msho_req_frame*) p->accessdata(); memset (req_frame, 0, sizeof (mac802_16_mob_msho_req_bs_index)); req_frame->type = MAC_MOB_MSHO_REQ; req_frame->report_metric = 0x2; //include RSSI req_frame->n_new_bs_index = 0; req_frame->n_new_bs_full = nbPref; req_frame->n_current_bs = 1; rssi = mac_->getPeerNode_head()->getStatWatch()->average(); debug2 ("RSSI=%e, %d, bs=%d\n", rssi, (u_char)((rssi+103.75)/0.25), mac_->getPeerNode_head()->getPeerNode()); req_frame->bs_current[0].temp_bsid = mac_->getPeerNode_head()->getPeerNode(); req_frame->bs_current[0].bs_rssi_mean = (u_char)((rssi+103.75)/0.25); for (int i = 0, j=0; i < nbr_db_->getNbNeighbor() ; i++) { NeighborEntry *entry = nbr_db_->getNeighbors()[i]; //TBD: there is an error measuring RSSI for current BS during scanning //anyway, we don't put it in the least, so it's ok for now if (entry->isDetected() && entry->getID()!= mac_->getPeerNode_head()->getPeerNode()) { req_frame->bs_full[j].neighbor_bs_index = entry->getID(); rssi = entry->getState()->state_info->peer_list->lh_first->getStatWatch()->average(); debug2 ("RSSI=%e, %d, bs=%d\n", rssi, (u_char)((rssi+103.75)/0.25), entry->getID()); req_frame->bs_full[j].bs_rssi_mean = (u_char)((rssi+103.75)/0.25); //the rest of req_frame->bs_full is unused for now.. req_frame->bs_full[j].arrival_time_diff_ind = 0; j++; } } ch->size() += Mac802_16pkt::getMOB_MSHO_REQ_size(req_frame); wimaxHdr->header.cid = peer->getPrimary()->get_cid(); peer->getPrimary()->enqueue (p);}/** * Process a BSHO-RSP message * @param frame The handover response frame */void SSscheduler::process_bsho_rsp (mac802_16_mob_bsho_rsp_frame *frame){ mac_->debug ("At %f in Mac %d, received handover response\n", NOW, mac_->addr()); //go and switch to the channel recommended by the BS int targetBS = frame->n_rec[0].neighbor_bsid; PeerNode *peer = mac_->getPeerNode_head(); if (peer->getPeerNode ()==targetBS) { mac_->debug ("\tDecision to stay in current BS\n"); return; } scan_info_->nbr = nbr_db_->getNeighbor (targetBS); Packet *p; struct hdr_cmn *ch; hdr_mac802_16 *wimaxHdr; mac802_16_mob_ho_ind_frame *ind_frame; p = mac_->getPacket (); ch = HDR_CMN(p); wimaxHdr = HDR_MAC802_16(p); p->allocdata (sizeof (struct mac802_16_mob_ho_ind_frame)); ind_frame = (mac802_16_mob_ho_ind_frame*) p->accessdata(); ind_frame->type = MAC_MOB_HO_IND; ind_frame->mode = 0; //HO ind_frame->ho_ind_type = 0; //Serving BS release ind_frame->rng_param_valid_ind = 0; ind_frame->target_bsid = targetBS; ch->size() += Mac802_16pkt::getMOB_HO_IND_size(ind_frame); wimaxHdr->header.cid = peer->getPrimary()->get_cid(); peer->getPrimary()->enqueue (p); #ifdef USE_802_21 mac_->send_link_handoff_imminent (mac_->addr(), peer->getPeerNode(), targetBS); mac_->debug ("At %f in Mac %d link handoff imminent\n", NOW, mac_->addr()); #endif mac_->debug ("\tHandover to BS %d\n", targetBS); scan_info_->handoff_timeout = 20; scan_info_->substate = HANDOVER_PENDING; //mac_->setChannel (scan_info_->bs_infos[i].channel); //lost_synch (); }/** * Process a NBR_ADV message * @param frame The handover response frame */void SSscheduler::process_nbr_adv (mac802_16_mob_nbr_adv_frame *frame){ mac_->debug ("At %f in Mac %d, received neighbor advertisement\n", NOW, mac_->addr()); mac802_16_mob_nbr_adv_frame *copy; copy = (mac802_16_mob_nbr_adv_frame *) malloc (sizeof (mac802_16_mob_nbr_adv_frame)); memcpy (copy, frame, sizeof (mac802_16_mob_nbr_adv_frame)); //all we need is to store the information. We will process that only //when we will look for another station for (int i = 0 ; i < frame->n_neighbors ; i++) { int nbrid = frame->nbr_info[i].nbr_bsid; mac802_16_nbr_adv_info *info = (mac802_16_nbr_adv_info *) malloc (sizeof(mac802_16_nbr_adv_info)); NeighborEntry *entry = nbr_db_->getNeighbor (nbrid); if (entry==NULL){ entry = new NeighborEntry (nbrid); nbr_db_->addNeighbor (entry); } memcpy(info, &(frame->nbr_info[i]), sizeof(mac802_16_nbr_adv_info)); if (entry->getNbrAdvMessage ()) free (entry->getNbrAdvMessage()); entry->setNbrAdvMessage(info); if (info->dcd_included) { //set DCD mac802_16_dcd_frame *tmp = (mac802_16_dcd_frame *)malloc (sizeof(mac802_16_dcd_frame)); memcpy(tmp, &(info->dcd_settings), sizeof(mac802_16_dcd_frame)); entry->setDCD(tmp); } else entry->setDCD(NULL); if (info->ucd_included) { //set DCD mac802_16_ucd_frame *tmp = (mac802_16_ucd_frame *)malloc (sizeof(mac802_16_ucd_frame)); memcpy(tmp, &(info->ucd_settings), sizeof(mac802_16_ucd_frame)); entry->setUCD(tmp);#ifdef DEBUG_WIMAX debug2 ("Dump information nbr in Mac %d for nbr %d %lx\n", mac_->addr(), nbrid, (long)tmp); int nb_prof = tmp->nb_prof; mac802_16_ucd_profile *profiles = tmp->profiles; for (int i = 0 ; i < nb_prof ; i++) { debug2 ("\t Reading ul profile %i: f=%d, rate=%d, iuc=%d\n", i, 0, profiles[i].fec, profiles[i].uiuc); }#endif } else entry->setUCD(NULL); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -