patch-wimax-prerelease-092206
上传用户:hzie11
上传日期:2013-10-07
资源大小:1487k
文件大小:477k
- +{
- + assert (agent);
- + ctrlagent_ = agent;
- +}
- +
- +/**
- + * Process a packet received by the Mac. Only scheduling related packets should be sent here (BW request, UL_MAP...)
- + * @param p The packet to process
- + */
- +void BSScheduler::process (Packet * p)
- +{
- + //assert (mac_);
- + //debug2 ("BSScheduler received packet to processn");
- +
- + assert (mac_ && HDR_CMN(p)->ptype()==PT_MAC);
- + debug2 ("BSScheduler received packet to processn");
- +
- + hdr_mac802_16 *wimaxHdr = HDR_MAC802_16(p);
- + gen_mac_header_t header = wimaxHdr->header;
- +
- + //check if this is a bandwidth request
- + if (header.ht == 1) {
- + process_bw_req (p);
- + return;
- + }
- +
- + //we cast to this frame because all management frame start with
- + //a type
- + mac802_16_dl_map_frame *frame = (mac802_16_dl_map_frame*) p->accessdata();
- +
- + switch (frame->type) {
- + case MAC_RNG_REQ:
- + process_ranging_req (p);
- + break;
- + case MAC_REG_REQ:
- + process_reg_req (p);
- + break;
- + case MAC_MOB_SCN_REQ:
- + if (ctrlagent_)
- + ctrlagent_->process_scan_request (p);
- + else
- + fprintf (stderr, "Warning: no controler to handle scan request in BS %dn", mac_->addr());
- + break;
- + case MAC_MOB_MSHO_REQ:
- + process_msho_req (p);
- + break;
- + case MAC_MOB_HO_IND:
- + process_ho_ind (p);
- + break;
- + default:
- + mac_->debug ("unknown packet in BSn");
- + }
- +
- + Packet::free (p);
- +}
- +
- +
- +/**
- + * Return the type of STA this scheduler is good for
- + * @return STA_BS
- + */
- +station_type_t BSScheduler::getNodeType ()
- +{
- + return STA_BS;
- +}
- +
- +/**
- + * Start a new frame
- + */
- +void BSScheduler::start_ulsubframe ()
- +{
- + //mac_->debug ("At %f in Mac %d BS scheduler ulsubframe expiresn", NOW, mac_->addr());
- +
- + //change PHY state
- + mac_->getPhy()->setMode (OFDM_RECV);
- +
- + //start handler of ulsubframe
- + map_->getUlSubframe()->getTimer()->sched (0);
- +
- + //reschedule for next frame
- + ul_timer_->resched (mac_->getFrameDuration());
- +}
- +
- +/**
- + * Start a new frame
- + */
- +void BSScheduler::start_dlsubframe ()
- +{
- + debug2 ("At %f in Mac %d BS scheduler dlsubframe expires (frame=%d)n",
- + NOW, mac_->addr(), mac_->frame_number_+1);
- +
- + assert (map_);
- +
- + Packet *p;
- + Burst *b;
- + struct hdr_cmn *ch;
- + double txtime;
- + int txtime_s;
- + OFDMPhy *phy = mac_->getPhy();
- +
- + //increment frame number
- + mac_->frame_number_ ++;
- +
- + //adjust frame start information
- + map_->setStarttime(NOW);
- +
- + /* First lets clear the peers we haven't heard of for long time */
- + for (PeerNode *pn = mac_->getPeerNode_head() ; pn ; ) {
- + PeerNode *tmp = pn->next_entry(); //next elem
- + if (isPeerScanning(pn->getPeerNode())) {
- + //since a scanning node cannot send data we push the
- + //timeout while it is scanning
- + pn->setRxTime(NOW);
- + } else if (NOW-pn->getRxTime()>mac_->macmib_.client_timeout) {
- + mac_->debug ("Client timeout for node %dn", pn->getPeerNode());
- + mac_->removePeerNode(pn);
- + }
- + pn = tmp;
- + }
- +
- + /**** Step one : burst allocation ****/
- + int nbPS = (int) round((mac_->getFrameDuration()/phy->getPS()));
- + int nbPS_left = nbPS - mac_->phymib_.rtg - mac_->phymib_.ttg;
- + int nbSymbols = (int) ((phy->getPS()*nbPS_left)/phy->getSymbolTime());
- + int dlduration = INIT_DL_DURATION+DL_PREAMBLE;
- + int ulduration = 0;
- + debug2 ("Frame: duration=%f, PSduration=%e, symboltime=%e, nbPS=%d, rtg=%d, ttg=%d, PSleft=%d, nbSymbols=%d, ",
- + mac_->getFrameDuration(), phy->getPS(), phy->getSymbolTime(), nbPS, mac_->phymib_.rtg, mac_->phymib_.ttg, nbPS_left, nbSymbols);
- +
- + //remove control messages
- + nbSymbols -= INIT_DL_DURATION+DL_PREAMBLE;
- +
- + nbSymbols -=10;
- + for (Connection *c = mac_->getCManager()->get_down_connection (); c && nbSymbols>0 ; c=c->next_entry()) {
- + if (c->getPeerNode() && !isPeerScanning (c->getPeerNode()->getPeerNode())) {
- + int queuesize = c->queueByteLength();
- + int tmp = (int) round((phy->getTrxTime (queuesize, map_->getDlSubframe()->getProfile (DIUC_PROFILE_1)->getEncoding())/phy->getSymbolTime()));
- + if (tmp < nbSymbols) {
- + dlduration += tmp;
- + nbSymbols -= tmp;
- + }else{
- + dlduration +=nbSymbols;
- + nbSymbols -= nbSymbols;
- + break;
- + }
- + }
- + }
- + nbSymbols +=10;
- +
- + map_->getDlSubframe()->getPdu()->getBurst(0)->setDuration (dlduration);
- + map_->getUlSubframe()->setStarttime (dlduration*phy->getSymbolPS()+mac_->phymib_.rtg);
- + ul_timer_->resched (map_->getUlSubframe()->getStarttime()*mac_->getPhy()->getPS());
- +
- + debug2 ("dlduration=%d, ", dlduration);
- + //update the END_OF_MAP start time
- + b = (DlBurst*) map_->getDlSubframe()->getPdu ()->getBurst (1);
- + b->setStarttime (dlduration);
- +
- + while (map_->getUlSubframe()->getNbPdu()>0) {
- + PhyPdu *pdu = map_->getUlSubframe()->getPhyPdu(0);
- + map_->getUlSubframe()->removePhyPdu(pdu);
- + delete (pdu);
- + }
- +
- + int rangingduration = 0;
- + int bwduration = 0;
- + int pduIndex = 0;
- + debug2 ("In Mac %d Nb symbols left before contention =%dn", mac_->addr(), nbSymbols);
- +
- + int contentionslots = (int) round((contention_size_*((getBWopportunity()+getInitRangingopportunity())*mac_->getPhy()->getPS()/mac_->getPhy()->getSymbolTime())));
- + if (nbSymbols > contentionslots) {
- + int starttime, slotleft, rangingslot, bwslot;
- + //create uplink
- + //start of UL subframe is after DL and TTG and unit is PS
- + starttime = map_->getUlSubframe()->getStarttime();
- + slotleft = nbPS - starttime - mac_->phymib_.rtg;
- + //if there is at least one peer, then use only contention_size_ symbols,
- + //otherwise use all the bw
- + if (mac_->getPeerNode_head() || fast_ranging_head_.lh_first) {
- + rangingslot = contention_size_*getInitRangingopportunity();
- + bwslot = contention_size_*getBWopportunity();
- + nbSymbols -= contentionslots;
- + debug2 ("nbSymbols after contention=%dn", nbSymbols);
- + }
- + else {
- + rangingslot = (int) (floor (slotleft/(2.0*getInitRangingopportunity()))*getInitRangingopportunity());
- + bwslot = (int) (floor ((slotleft-rangingslot)/getBWopportunity())*getBWopportunity());
- + nbSymbols = 0;
- + }
- + rangingduration =(int) round(((mac_->getPhy()->getPS()*rangingslot)/mac_->getPhy()->getSymbolTime()));
- + bwduration = (int) round (((mac_->getPhy()->getPS()*bwslot)/mac_->getPhy()->getSymbolTime()));
- + //we open the uplink to initial ranging and bw requests
- + ContentionSlot *slot = map_->getUlSubframe()->getRanging ();
- + //create burst to represent the contention slot
- + Burst* b2 = map_->getUlSubframe()->addPhyPdu (pduIndex,0)->addBurst (0);
- + pduIndex++;
- + b2->setIUC (UIUC_INITIAL_RANGING);
- + b2->setDuration (rangingduration);
- + b2->setStarttime (ulduration); //we put the contention at the begining
- + ulduration += rangingduration;
- +
- + //now the bw request
- + slot = map_->getUlSubframe()->getBw_req ();
- + b2 = map_->getUlSubframe()->addPhyPdu (pduIndex,0)->addBurst (0);
- + pduIndex++;
- + b2->setIUC (UIUC_REQ_REGION_FULL);
- + b2->setDuration (bwduration);
- + b2->setStarttime (ulduration); //start after the ranging slot
- + ulduration += bwduration;
- + }
- +
- + //check if there is Fast Ranging allocation to do
- + while (fast_ranging_head_.lh_first !=NULL
- + && fast_ranging_head_.lh_first->frame() == mac_->getFrameNumber()) {
- + //we need to include a fast ranging allocation
- + b = map_->getUlSubframe()->addPhyPdu (pduIndex,0)->addBurst (0);
- + pduIndex++;
- + int tmp =(int) round(((mac_->getPhy()->getPS()*getInitRangingopportunity())/mac_->getPhy()->getSymbolTime()));
- + b->setIUC (UIUC_EXT_UIUC);
- + b->setDuration (tmp);
- + b->setStarttime (ulduration); //start after previous slot
- + ((UlBurst*)b)->setFastRangingParam (fast_ranging_head_.lh_first->macAddr(), UIUC_INITIAL_RANGING);
- + ulduration += tmp;
- + mac_->debug ("At %f in Mac %d adding fast ranging for %dn", NOW, mac_->addr(), fast_ranging_head_.lh_first->macAddr());
- + fast_ranging_head_.lh_first->remove_entry();
- + }
- +
- + //get the next node to allocate bw.
- + //PB: the node may have been removed. We need to check that
- + PeerNode *peer = mac_->getPeerNode_head();
- + PeerNode *start_peer = mac_->getPeerNode_head();
- + int i=0;
- +
- + if (start_peer != NULL) {
- + //we have at least one element in the list
- + for (peer = mac_->getPeerNode_head(); peer->next_entry() ; peer=peer->next_entry());
- + debug2 ("start_peer=%d, peer=%dn", start_peer->getPeerNode(), peer->getPeerNode());
- + while (start_peer != peer) {
- + if (!isPeerScanning(peer->getPeerNode())) {
- + debug2 ("peer %d not scanning take itn", peer->getPeerNode());
- + break; //we found next station
- + }
- + debug2 ("peer %d scanning move itn", peer->getPeerNode());
- + peer->remove_entry();
- + mac_->addPeerNode (peer); //we put it at head of the list
- + for (peer = mac_->getPeerNode_head(); peer->next_entry() ; peer=peer->next_entry());
- + }
- + }
- + if (peer)
- + debug2 ("final pick is %dn", peer->getPeerNode());
- +
- + //update variables
- + bw_node_index_ = i;
- + bw_peer_ = peer;
- +
- + //the next peer node takes the rest of the bw
- + if (nbSymbols > 0 && peer && !isPeerScanning(peer->getPeerNode())) {
- + debug2 ("Allocate uplink for STA %dn", peer->getPeerNode());
- + peer->remove_entry();
- + mac_->addPeerNode (peer); //we put it at head of the list
- + //printf ("NbSymbols for node=%dn", nbSymbols);
- + //add burst
- + Burst *b3 = map_->getUlSubframe()->addPhyPdu (pduIndex,0)->addBurst (0);
- + pduIndex++;
- + b3->setIUC (UIUC_PROFILE_1);
- + b3->setCid (peer->getPrimary()->get_cid());
- + b3->setDuration (nbSymbols);
- + b3->setStarttime (ulduration);
- + //add profile if not existing
- + Profile *p = map_->getUlSubframe()->getProfile (UIUC_PROFILE_1);
- + if (p==NULL) {
- + p = map_->getUlSubframe()->addProfile (0, default_mod_);
- + p->setIUC (UIUC_PROFILE_1);
- + }
- + }
- +
- + //end of map
- + Burst *b2 = map_->getUlSubframe()->addPhyPdu (pduIndex,0)->addBurst (0);
- + pduIndex++;
- + b2->setIUC (UIUC_END_OF_MAP);
- + b2->setStarttime (rangingduration+bwduration+nbSymbols);
- +
- +
- +
- + //we need to fill up the outgoing queues
- + for (int index = 0 ; index < map_->getDlSubframe()->getPdu ()->getNbBurst() ; index++) {
- + b = map_->getDlSubframe()->getPdu ()->getBurst (index);
- + int duration = 0;
- +
- + if (b->getIUC()==DIUC_END_OF_MAP) {
- + //consistency check..
- + assert (index == map_->getDlSubframe()->getPdu ()->getNbBurst()-1);
- + break;
- + }
- +
- + //we can get the next one after we check END_OF_MAP
- + //b2 = map_->getDlSubframe()->getPdu ()->getBurst (index+1);
- +
- + //if this is the first buffer, add DL_MAP...messages
- + if (index==0) {
- + p = map_->getDL_MAP();
- + ch = HDR_CMN(p);
- + txtime = phy->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + txtime_s = (int) round(txtime/phy->getSymbolTime ()); //in units of symbol
- + assert ((duration+txtime_s) <= b->getDuration());
- + b->enqueue(p); //enqueue into burst
- + duration += txtime_s;
- + p = map_->getUL_MAP();
- + ch = HDR_CMN(p);
- + txtime = phy->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + txtime_s = (int) round(txtime/phy->getSymbolTime ()); //in units of symbol
- + assert ((duration+txtime_s) <= b->getDuration());
- + b->enqueue(p); //enqueue into burst
- + duration += txtime_s;
- +
- + if (sendDCD || map_->getDlSubframe()->getCCC()!= dlccc_) {
- + p = map_->getDCD();
- + ch = HDR_CMN(p);
- + txtime = phy->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + txtime_s = (int) round(txtime/phy->getSymbolTime ()); //in units of symbol
- + assert ((duration+txtime_s) <= b->getDuration());
- + b->enqueue(p); //enqueue into burst
- + duration += txtime_s;
- + sendDCD = false;
- + dlccc_ = map_->getDlSubframe()->getCCC();
- + //reschedule timer
- + dcdtimer_->stop();
- + dcdtimer_->start (mac_->macmib_.dcd_interval);
- + }
- +
- + if (sendUCD || map_->getUlSubframe()->getCCC()!= ulccc_) {
- + p = map_->getUCD();
- + ch = HDR_CMN(p);
- + txtime = phy->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + txtime_s = (int) round(txtime/phy->getSymbolTime ()); //in units of symbol
- + assert ((duration+txtime_s) <= b->getDuration());
- + b->enqueue(p); //enqueue into burst
- + duration += txtime_s;
- + sendUCD = false;
- + ulccc_ = map_->getUlSubframe()->getCCC();
- + //reschedule timer
- + ucdtimer_->stop();
- + ucdtimer_->start (mac_->macmib_.ucd_interval);
- + }
- + }
- +
- + //get the packets from the connection with the same CID
- + //Connection *c=mac_->getCManager ()->get_connection (b->getCid());
- + int nb_down = 0;
- + for (Connection *c = mac_->getCManager()->get_down_connection (); c ; c=c->next_entry()){ nb_down++;}
- + Connection **tmp_con = (Connection **) malloc (nb_down*sizeof (Connection *));
- + int i=0;
- + for (Connection *c = mac_->getCManager()->get_down_connection (); c ; c=c->next_entry()){
- + tmp_con[i] = c;
- + i++;
- + }
- + //we randomly pick the connection we'll start serving first
- + int start_index = (int) round (Random::uniform(0, nb_down));
- + debug2 ("Picked connection %d as firstn", start_index);
- +
- + //for (Connection *c = mac_->getCManager()->get_down_connection (); c ; c=c->next_entry()) {
- + for (i=0; i < nb_down ; i++) {
- + int index = (i+start_index)%nb_down;
- + Connection *c=tmp_con[index];
- +
- + if (c->getPeerNode() && isPeerScanning (c->getPeerNode()->getPeerNode()))
- + continue;
- +
- + duration = transfer_packets (c, b, duration);
- + }
- + }
- +
- + //change PHY state
- + mac_->getPhy()->setMode (OFDM_SEND);
- +
- + //start handler of dlsubframe
- + map_->getDlSubframe()->getTimer()->sched (0);
- +
- + //reschedule for next time (frame duration)
- + dl_timer_->resched (mac_->getFrameDuration());
- +}
- +
- +/** Add a new Fast Ranging allocation
- + * @param time The time when to allocate data
- + * @param macAddr The MN address
- + */
- +void BSScheduler::addNewFastRanging (double time, int macAddr)
- +{
- + //compute the frame where the allocation will be located
- + int frame = int ((time-NOW)/mac_->getFrameDuration()) +2 ;
- + frame += mac_->getFrameNumber();
- + //printf ("Added fast RA for frame %d (current=%d) for time (%f)n",
- + // frame, mac_->getFrameNumber(), time);
- + FastRangingInfo *info= new FastRangingInfo (frame, macAddr);
- + info->insert_entry(&fast_ranging_head_);
- +}
- +
- +
- +/**** Packet processing methods ****/
- +
- +/**
- + * Process a RNG-REQ message
- + * @param p The packet containing the ranging request information
- + */
- +void BSScheduler::process_ranging_req (Packet *p)
- +{
- + UlSubFrame *ulsubframe = map_->getUlSubframe();
- + mac802_16_rng_req_frame *req = (mac802_16_rng_req_frame *) p->accessdata();
- +
- + if (HDR_MAC802_16(p)->header.cid != INITIAL_RANGING_CID) {
- + //process request for DIUC
- + } else {
- + //here we can make decision to accept the SS or not.
- + //for now, accept everybody
- + //check if CID already assigned for the SS
- + PeerNode *peer = mac_->getPeerNode (req->ss_mac_address);
- + if (peer==NULL) {
- + mac_->debug ("New peer node requesting ranging (%d)n",req->ss_mac_address);
- + //Assign Management CIDs
- + Connection *basic = new Connection (CONN_BASIC);
- + Connection *upbasic = new Connection (CONN_BASIC, basic->get_cid());
- + Connection *primary = new Connection (CONN_PRIMARY);
- + Connection *upprimary = new Connection (CONN_PRIMARY, primary->get_cid());
- +
- + //Create Peer information
- + peer = new PeerNode (req->ss_mac_address);
- + peer->setBasic (basic);
- + peer->setPrimary (primary);
- + upbasic->setPeerNode (peer);
- + upprimary->setPeerNode (peer);
- + mac_->addPeerNode (peer);
- + mac_->getCManager()->add_connection (upbasic, true);
- + mac_->getCManager()->add_connection (basic, false);
- + mac_->getCManager()->add_connection (upprimary, true);
- + mac_->getCManager()->add_connection (primary, false);
- + //schedule timer in case the node never register
- + addtimer17 (req->ss_mac_address);
- +
- + //create packet for answers
- + Packet *rep = mac_->getPacket ();
- + struct hdr_cmn *ch = HDR_CMN(rep);
- + rep->allocdata (sizeof (struct mac802_16_rng_rsp_frame));
- + mac802_16_rng_rsp_frame *frame = (mac802_16_rng_rsp_frame*) rep->accessdata();
- + frame->type = MAC_RNG_RSP;
- + frame->uc_id = ulsubframe->getChannelID();
- + frame->rng_status = RNG_SUCCESS;
- + frame->ss_mac_address = req->ss_mac_address;
- + frame->basic_cid = basic->get_cid();
- + frame->primary_cid = primary->get_cid();
- + ch->size() = RNG_RSP_SIZE;
- + //compute transmission time
- + Burst *b = map_->getDlSubframe()->getPdu ()->getBurst (0);
- + double txtime = mac_->getPhy()->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + //enqueue packet
- + mac_->getCManager()->get_connection (BROADCAST_CID, false)->enqueue (rep);
- +
- + if (cl_head_==NULL) {
- + cl_head_ = (new_client_t*)malloc (sizeof (new_client_t));
- + cl_tail_ = cl_head_;
- + } else {
- + cl_tail_->next = (new_client_t*)malloc (sizeof (new_client_t));
- + cl_tail_=cl_tail_->next;
- + }
- + cl_tail_->cid = primary->get_cid();
- + cl_tail_->next = NULL;
- +
- +#ifdef USE_802_21
- + mac_->send_link_detected (mac_->addr(), peer->getPeerNode(), 1);
- +#endif
- +
- + } else {
- + mac_->debug ("Received ranging for known station (%d)n", req->ss_mac_address);
- + //reset invited ranging retries for SS
- + //create packet for answers
- + Connection *basic = peer->getBasic();
- + Connection *primary = peer->getPrimary();
- + Packet *rep = mac_->getPacket ();
- + struct hdr_cmn *ch = HDR_CMN(rep);
- + rep->allocdata (sizeof (struct mac802_16_rng_rsp_frame));
- + mac802_16_rng_rsp_frame *frame = (mac802_16_rng_rsp_frame*) rep->accessdata();
- + frame->type = MAC_RNG_RSP;
- + frame->uc_id = ulsubframe->getChannelID();
- + frame->rng_status = RNG_SUCCESS;
- + frame->ss_mac_address = req->ss_mac_address;
- + frame->basic_cid = basic->get_cid();
- + frame->primary_cid = primary->get_cid();
- + ch->size() = RNG_RSP_SIZE;
- + //compute transmission time
- + Burst *b = map_->getDlSubframe()->getPdu ()->getBurst (0);
- + double txtime = mac_->getPhy()->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + //enqueue packet
- + mac_->getCManager()->get_connection (BROADCAST_CID, false)->enqueue (rep);
- + }
- + }
- +}
- +
- +/**
- + * Add a new timer17 in the list. It also performs cleaning of the list
- + * @param index The client address
- + */
- +void BSScheduler::addtimer17 (int index)
- +{
- + //clean expired timers
- + T17Element *entry;
- + for (entry = t17_head_.lh_first; entry ; ) {
- + if (entry->paused ()) {
- + T17Element *tmp = entry;
- + entry = entry->next_entry();
- + tmp->remove_entry();
- + free (tmp);
- + }
- + entry = entry->next_entry();
- + }
- +
- + entry = new T17Element (mac_, index);
- + entry->insert_entry (&t17_head_);
- +}
- +/**
- + * Cancel and remove the timer17 associated with the node
- + * @param index The client address
- + */
- +void BSScheduler::removetimer17 (int index)
- +{
- + //clean expired timers
- + T17Element *entry;
- + for (entry = t17_head_.lh_first; entry ; entry = entry->next_entry()) {
- + if (entry->index ()==index) {
- + entry->cancel();
- + entry->remove_entry();
- + delete (entry);
- + break;
- + }
- + }
- +}
- +
- +/**
- + * Process bandwidth request
- + * @param p The request
- + */
- +void BSScheduler::process_bw_req (Packet *p)
- +{
- + hdr_mac802_16 *wimaxHdr = HDR_MAC802_16(p);
- + gen_mac_header_t header = wimaxHdr->header;
- +
- + bw_req_header_t *req;
- + req = (bw_req_header_t *)&header;
- +
- + mac_->debug ("received bandwidth request of %d bytes from %dn", req->br, req->cid);
- +
- +}
- +
- +/**
- + * Process registration request
- + * @param p The request
- + */
- +void BSScheduler::process_reg_req (Packet *req)
- +{
- + hdr_mac802_16 *wimaxHdr_req = HDR_MAC802_16(req);
- + gen_mac_header_t header_req = wimaxHdr_req->header;
- +
- + mac_->debug ("received registration request from %dn", header_req.cid);
- +
- + Packet *p;
- + struct hdr_cmn *ch;
- + hdr_mac802_16 *wimaxHdr;
- + mac802_16_reg_rsp_frame *reg_frame;
- + PeerNode *peer;
- +
- + //create packet for request
- + p = mac_->getPacket ();
- + ch = HDR_CMN(p);
- + wimaxHdr = HDR_MAC802_16(p);
- + p->allocdata (sizeof (struct mac802_16_reg_rsp_frame));
- + reg_frame = (mac802_16_reg_rsp_frame*) p->accessdata();
- + reg_frame->type = MAC_REG_RSP;
- + reg_frame->response = 0; //OK
- + peer = mac_->getCManager()->get_connection (header_req.cid, false)->getPeerNode();
- + Connection *secondary = peer->getSecondary ();
- + if (secondary==NULL) {
- + //first time
- + secondary = new Connection (CONN_SECONDARY);
- + Connection *upsecondary = new Connection (CONN_SECONDARY, secondary->get_cid());
- + mac_->getCManager()->add_connection (upsecondary, true);
- + mac_->getCManager()->add_connection (secondary, false);
- + peer->setSecondary (secondary);
- + upsecondary->setPeerNode (peer);
- + }
- + reg_frame->sec_mngmt_cid = secondary->get_cid();
- + wimaxHdr->header.cid = header_req.cid;
- + ch->size() = REG_RSP_SIZE;
- +
- + //compute transmission time
- + Burst *b = map_->getDlSubframe()->getPdu ()->getBurst (0);
- + double txtime = mac_->getPhy()->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + //enqueue packet
- + mac_->getCManager()->get_connection (BROADCAST_CID, false)->enqueue (p);
- + //clear t17 timer for this node
- + removetimer17 (peer->getPeerNode());
- +
- +#ifdef USE_802_21
- + mac_->debug ("At %f in Mac %d, send link upn", NOW, mac_->addr());
- + mac_->send_link_up (peer->getPeerNode(),mac_->addr());
- +#endif
- +}
- +
- +/**
- + * Send a neighbor advertisement message
- + */
- +void BSScheduler::send_nbr_adv ()
- +{
- + mac_->debug ("At %f in BS %d send_nbr_adv (nb_neighbor=%d)n", NOW, mac_->addr(), nbr_db_->getNbNeighbor());
- + Packet *p;
- + struct hdr_cmn *ch;
- + hdr_mac802_16 *wimaxHdr;
- + mac802_16_mob_nbr_adv_frame *frame;
- + //PeerNode *peer;
- +
- + //create packet for request
- + p = mac_->getPacket ();
- + ch = HDR_CMN(p);
- + wimaxHdr = HDR_MAC802_16(p);
- + p->allocdata (sizeof (struct mac802_16_mob_nbr_adv_frame));
- + frame = (mac802_16_mob_nbr_adv_frame*) p->accessdata();
- + frame->type = MAC_MOB_NBR_ADV;
- + frame->n_neighbors = nbr_db_->getNbNeighbor();
- + frame->skip_opt_field = 0;
- + for (int i = 0 ; i < frame->n_neighbors ; i++) {
- + frame->nbr_info[i].phy_profile_id.FAindex = 0;
- + frame->nbr_info[i].phy_profile_id.bs_eirp = 0;
- + frame->nbr_info[i].nbr_bsid= nbr_db_->getNeighbors()[i]->getID();
- + frame->nbr_info[i].dcd_included = true;
- + memcpy (&(frame->nbr_info[i].dcd_settings), nbr_db_->getNeighbors ()[i]->getDCD(), sizeof(mac802_16_dcd_frame));
- + frame->nbr_info[i].ucd_included = true;
- + memcpy (&(frame->nbr_info[i].ucd_settings), nbr_db_->getNeighbors ()[i]->getUCD(), sizeof(mac802_16_ucd_frame));
- + frame->nbr_info[i].phy_included = false;
- + }
- + ch->size() = Mac802_16pkt::getMOB_NBR_ADV_size(frame);
- + mac_->getCManager()->get_connection (BROADCAST_CID, false)->enqueue (p);
- +
- +}
- +
- +/**
- + * Finds out if the given station is currently scanning
- + * @param nodeid The MS id
- + */
- +bool BSScheduler::isPeerScanning (int nodeid)
- +{
- + ScanningStation *sta;
- + for (sta = scan_stations_.lh_first; sta ; sta = sta->next_entry()) {
- + if (sta->getNodeId()==nodeid && sta->isScanning(mac_->frame_number_)) {
- + //printf ("station %d scanningn", nodeid);
- + return true;
- + }
- + }
- + return false;
- +}
- +
- +/**
- + * Process handover request
- + * @param p The request
- + */
- +void BSScheduler::process_msho_req (Packet *req)
- +{
- + hdr_mac802_16 *wimaxHdr_req = HDR_MAC802_16(req);
- + gen_mac_header_t header_req = wimaxHdr_req->header;
- + mac802_16_mob_msho_req_frame *req_frame =
- + (mac802_16_mob_msho_req_frame*) req->accessdata();
- +
- + mac_->debug ("At %f in Mac %d received handover request from %dn", NOW, mac_->addr(), header_req.cid);
- +
- + //check the BS that has stronger power
- + int maxIndex = 0;
- + int maxRssi = 0; //max value
- + for (int i = 0; i < req_frame->n_new_bs_full ; i++) {
- + if (req_frame->bs_full[i].bs_rssi_mean >= maxRssi) {
- + maxIndex = i;
- + maxRssi = req_frame->bs_full[i].bs_rssi_mean;
- + }
- + }
- + //reply with one recommended BS
- + Packet *p;
- + struct hdr_cmn *ch;
- + hdr_mac802_16 *wimaxHdr;
- + mac802_16_mob_bsho_rsp_frame *rsp_frame;
- +
- + send_nbr_adv (); //to force update with latest information
- +
- + //create packet for request
- + p = mac_->getPacket ();
- + ch = HDR_CMN(p);
- + wimaxHdr = HDR_MAC802_16(p);
- + p->allocdata (sizeof (struct mac802_16_mob_bsho_rsp_frame)+sizeof (mac802_16_mob_bsho_rsp_rec));
- + rsp_frame = (mac802_16_mob_bsho_rsp_frame*) p->accessdata();
- + rsp_frame->type = MAC_MOB_BSHO_RSP;
- +
- + rsp_frame->mode = 0; //HO request
- + rsp_frame->ho_operation_mode = 1; //mandatory handover response
- + rsp_frame->n_recommended = 1;
- + rsp_frame->resource_retain_flag = 0; //release connection information
- + rsp_frame->n_rec[0].neighbor_bsid = req_frame->bs_full[maxIndex].neighbor_bs_index;
- + rsp_frame->n_rec[0].ho_process_optimization=0; //no optimization
- +
- + ch->size() += Mac802_16pkt::getMOB_BSHO_RSP_size(rsp_frame);
- + wimaxHdr->header.cid = header_req.cid;
- + mac_->getCManager()->get_connection (BROADCAST_CID, false)->enqueue (p);
- +}
- +
- +/**
- + * Process handover indication
- + * @param p The indication
- + */
- +void BSScheduler::process_ho_ind (Packet *p)
- +{
- + hdr_mac802_16 *wimaxHdr_req = HDR_MAC802_16(p);
- + gen_mac_header_t header_req = wimaxHdr_req->header;
- + //mac802_16_mob_ho_ind_frame *req_frame =
- + // (mac802_16_mob_ho_ind_frame*) p->accessdata();
- +
- + mac_->debug ("At %f in Mac %d received handover indication from %dn", NOW, mac_->addr(), header_req.cid);
- +
- +
- +}
- +
- +/**
- + * Send a scan response to the MN
- + * @param rsp The response from the control
- + */
- +void BSScheduler::send_scan_response (mac802_16_mob_scn_rsp_frame *rsp, int cid)
- +{
- + //create packet for request
- + Packet *p = mac_->getPacket ();
- + struct hdr_cmn *ch = HDR_CMN(p);
- + hdr_mac802_16 *wimaxHdr = HDR_MAC802_16(p);
- + p->allocdata (sizeof (struct mac802_16_mob_scn_rsp_frame));
- + mac802_16_mob_scn_rsp_frame* rsp_frame = (mac802_16_mob_scn_rsp_frame*) p->accessdata();
- + memcpy (rsp_frame, rsp, sizeof (mac802_16_mob_scn_rsp_frame));
- + rsp_frame->type = MAC_MOB_SCN_RSP;
- +
- + wimaxHdr->header.cid = cid;
- + ch->size() += Mac802_16pkt::getMOB_SCN_RSP_size(rsp_frame);
- +
- + //add scanning station to the list
- + PeerNode *peer = mac_->getCManager()->get_connection (cid, false)->getPeerNode();
- +
- + /* The request is received in frame i, the reply is sent in frame i+1
- + * so the frame at which the scanning start is start_frame+2
- + */
- + ScanningStation *sta = new ScanningStation (peer->getPeerNode(), rsp_frame->scan_duration & 0xFF,
- + rsp_frame->start_frame+mac_->frame_number_+2,
- + rsp_frame->interleaving_interval & 0xFF,
- + rsp_frame->scan_iteration & 0xFF);
- + sta->insert_entry_head (&scan_stations_);
- +
- + //compute transmission time
- + Burst *b = map_->getDlSubframe()->getPdu ()->getBurst (0);
- + double txtime = mac_->getPhy()->getTrxTime (ch->size(), map_->getDlSubframe()->getProfile (b->getIUC())->getEncoding());
- + ch->txtime() = txtime;
- + //enqueue packet
- + mac_->getCManager()->get_connection (BROADCAST_CID, false)->enqueue (p);
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/bsscheduler.h ns-2.29/wimax/scheduling/bsscheduler.h
- --- ns-2.29-org/wimax/scheduling/bsscheduler.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/bsscheduler.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,322 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef BSSCHEDULER_H
- +#define BSSCHEDULER_H
- +
- +#include "wimaxscheduler.h"
- +#include "scanningstation.h"
- +
- +#define INIT_DL_DURATION 20 //enough for DL_MAP, UL_MAP, DCD, UCD and some RNG-RSP
- +#define MIN_CONTENTION_SIZE 5 //minimum number of opportunity for allocation
- +
- +/** Information about a new client */
- +struct new_client_t {
- + int cid; //primary cid of new client
- + new_client_t *next;
- +};
- +
- +class T17Element;
- +LIST_HEAD (t17element, T17Element);
- +/** Object to handle timer t17 */
- +class T17Element {
- + public:
- + T17Element (Mac802_16 *mac, int index) {
- + index_ = index;
- + timer = new WimaxT17Timer (mac, index);
- + timer->start (mac->macmib_.t17_timeout);
- + }
- +
- + ~T17Element () { delete (timer); }
- +
- + int index () { return index_; }
- + int paused () { return timer->paused(); }
- + void cancel () { timer->stop(); }
- +
- + // Chain element to the list
- + inline void insert_entry(struct t17element *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + // Return next element in the chained list
- + T17Element* next_entry(void) const { return link.le_next; }
- +
- + // Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- + protected:
- +
- + /*
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(T17Element) link;
- + //LIST_ENTRY(T17Element); //for magic draw
- +
- + private:
- + int index_;
- + WimaxT17Timer *timer;
- +};
- +
- +class FastRangingInfo;
- +LIST_HEAD (fastRangingInfo, FastRangingInfo);
- +/** Store information about a fast ranging request to send */
- +class FastRangingInfo {
- + public:
- + FastRangingInfo (int frame, int macAddr) {
- + frame_ = frame;
- + macAddr_ = macAddr;
- + }
- +
- + int frame () { return frame_; }
- + int macAddr () { return macAddr_; }
- +
- + // Chain element to the list
- + inline void insert_entry(struct fastRangingInfo *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + // Return next element in the chained list
- + FastRangingInfo* next_entry(void) const { return link.le_next; }
- +
- + // Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- + protected:
- +
- + /*
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(FastRangingInfo) link;
- + //LIST_ENTRY(FastRangingInfo); //for magic draw
- +
- + private:
- + int frame_;
- + int macAddr_;
- +};
- +
- +class WimaxCtrlAgent;
- +/**
- + * Class BSScheduler
- + * Implement the packet scheduler on the BS side
- + */
- +class BSScheduler : public WimaxScheduler {
- + //friend class SendTimer;
- + public:
- + /*
- + * Create a scheduler
- + */
- + BSScheduler ();
- +
- + /*
- + * Interface with the TCL script
- + * @param argc The number of parameter
- + * @param argv The list of parameters
- + */
- + int command(int argc, const char*const* argv);
- +
- + /**
- + * Process a packet received by the Mac. Only scheduling related packets should be sent here (BW request, UL_MAP...)
- + * @param p The packet to process
- + */
- + void process (Packet * p);
- +
- + /**
- + * Return the type of STA this scheduler is good for
- + */
- + virtual station_type_t getNodeType ();
- +
- + /**
- + * Initializes the scheduler
- + */
- + virtual void init ();
- +
- + /**
- + * Called when a timer expires
- + * @param The timer ID
- + */
- + virtual void expire (timer_id id);
- +
- + /**
- + * Start a new DL subframe
- + */
- + virtual void start_dlsubframe ();
- +
- + /**
- + * Start a new UL subframe
- + */
- + virtual void start_ulsubframe ();
- +
- + /**
- + * Finds out if the given station is currently scanning
- + * @param nodeid The MS id
- + */
- + bool isPeerScanning (int nodeid);
- +
- + /**
- + * Set the control agent
- + * @param agent The control agent
- + */
- + void setCtrlAgent (WimaxCtrlAgent *agent);
- +
- + /** Add a new Fast Ranging allocation
- + * @param time The time when to allocate data
- + * @param macAddr The MN address
- + */
- + void addNewFastRanging (double time, int macAddr);
- +
- + /**
- + * Send a scan response to the MN
- + * @param rsp The response from the control
- + * @cid The CID for the MN
- + */
- + void send_scan_response (mac802_16_mob_scn_rsp_frame *rsp, int cid);
- +
- + protected:
- +
- + /**
- + * Default modulation
- + */
- + Ofdm_mod_rate default_mod_;
- +
- + /**
- + * Number of transmission opportunity for initial ranging
- + * and bw request (i.e contention slots)
- + */
- + int contention_size_;
- +
- + /**
- + * Compute and return the bandwidth request opportunity size
- + * @return The bandwidth request opportunity size
- + */
- + int getBWopportunity ();
- +
- + /**
- + * Compute and return the initial ranging opportunity size
- + * @return The initial ranging opportunity size
- + */
- + int getInitRangingopportunity ();
- +
- + private:
- +
- + /**
- + * Process a RNG-REQ message
- + * @param frame The ranging request information
- + */
- + void process_ranging_req (Packet *p);
- +
- + /**
- + * Process bandwidth request
- + * @param p The request
- + */
- + void process_bw_req (Packet *p);
- +
- + /**
- + * Process bandwidth request
- + * @param p The request
- + */
- + void process_reg_req (Packet *p);
- +
- + /**
- + * Process handover request
- + * @param req The request
- + */
- + void process_msho_req (Packet *req);
- +
- + /**
- + * Process handover indication
- + * @param p The indication
- + */
- + void process_ho_ind (Packet *p);
- +
- + /**
- + * Send a neighbor advertisement message
- + */
- + void send_nbr_adv ();
- +
- +
- + /**
- + * Add a new timer 17 for client
- + * @param index The client address
- + */
- + void addtimer17 (int index);
- +
- + /**
- + * Cancel and remove the timer17 associated with the node
- + * @param index The client address
- + */
- + void removetimer17 (int index);
- +
- + struct new_client_t *cl_head_;
- + struct new_client_t *cl_tail_;
- +
- + struct t17element t17_head_;
- +
- + /**
- + * The index of the last SS that had bandwidth allocation
- + */
- + int bw_node_index_;
- +
- + /**
- + * The node that had the last bandwidth allocation
- + */
- + PeerNode *bw_peer_;
- +
- + /**
- + * Timer for DCD
- + */
- + WimaxDCDTimer *dcdtimer_;
- +
- + /**
- + * Timer for UCD
- + */
- + WimaxUCDTimer *ucdtimer_;
- +
- + /**
- + * Timer for MOB-NBR_ADV messages
- + */
- + WimaxMobNbrAdvTimer *nbradvtimer_;
- +
- + /**
- + * Indicates if it is time to send a DCD message
- + */
- + bool sendDCD;
- + int dlccc_;
- + bool sendUCD;
- + int ulccc_;
- +
- + /**
- + * List of station in scanning
- + */
- + struct scanningStation scan_stations_;
- +
- + /**
- + * The Wimax control for BS synchronization
- + */
- + WimaxCtrlAgent *ctrlagent_;
- +
- + /**
- + * List of the upcoming Fast Ranging allocation
- + */
- + struct fastRangingInfo fast_ranging_head_;
- +
- +};
- +
- +#endif //BSSCHEDULER_H
- +
- diff -Naur ns-2.29-org/wimax/scheduling/burst.cc ns-2.29/wimax/scheduling/burst.cc
- --- ns-2.29-org/wimax/scheduling/burst.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/burst.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,155 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "burst.h"
- +
- +
- +/**
- + * Creates a burst
- + * @param phypdu The PhyPdu where it is located
- + */
- +Burst::Burst (PhyPdu *phypdu) : cid_(-1), duration_(0),
- + starttime_(0),iuc_(-1)
- +{
- + assert (phypdu);
- + phypdu_ = phypdu;
- + queue_ = NULL;
- +}
- +
- +/*
- + * Delete the object
- + */
- +Burst::~Burst ()
- +{
- + //delete packets in queue
- + if (queue_!=NULL) {
- + for (Packet *p = dequeue(); p ; p=dequeue()) {
- + Packet::free (p);
- + }
- + delete (queue_);
- + }
- +}
- +
- +/**
- + * Set burst CID
- + * @param cid The burst CID
- + */
- +void Burst::setCid( int cid )
- +{
- + cid_ = cid;
- +}
- +
- +/**
- + * Return the CID for this burst
- + * @return the CID for this burst
- + */
- +int Burst::getCid( )
- +{
- + return cid_;
- +}
- +
- +/**
- + * Return the burst duration in units of OFDM symbols
- + * @return the burst duration
- + */
- +int Burst::getDuration( )
- +{
- + return duration_;
- +}
- +
- +/**
- + * Set the duration of the burst in units of OFDM symbols
- + * @param duration The burst duration
- + */
- +void Burst::setDuration (int duration)
- +{
- + duration_=duration;
- +}
- +
- +/**
- + * Set burst IUC
- + * @param iuc The burst IUC
- + */
- +void Burst::setIUC( int iuc )
- +{
- + iuc_ = iuc;
- +}
- +
- +/**
- + * Return the Interval Usage Code
- + * @return the burst start time
- + */
- +int Burst::getIUC( )
- +{
- + return iuc_;
- +}
- +
- +/**
- + * Set burst start time in units of symbol duration
- + * @param starttime the burst start time
- + */
- +void Burst::setStarttime( int starttime )
- +{
- + assert (starttime >= 0);
- + starttime_ = starttime;
- +}
- +
- +/**
- + * Return the burst start time in units of symbol duration
- + * @return the burst start time
- + */
- +int Burst::getStarttime( )
- +{
- + return starttime_;
- +}
- +
- +/**
- + * Enqueue the given packet
- + * @param p The packet to enqueue
- + */
- +void Burst::enqueue (Packet * p)
- +{
- + if (queue_ == NULL) {
- + //this is the first packet we enqueue, create queue
- + queue_ = new PacketQueue();
- + }
- + queue_->enque (p);
- +}
- +
- +/**
- + * Dequeue a packet from the queue
- + * @param p The packet to enqueue
- + */
- +Packet * Burst::dequeue ()
- +{
- + if (queue_==NULL) //in case there was never an enqueue
- + return NULL;
- + return queue_->deque ();
- +}
- +
- +/**
- + * Trigger the timer to send packets for this burst
- + * @param time The time the trigger expires
- + */
- +/*
- +void Burst::trigger_timer (double time)
- +{
- + //assert (NOW < time);
- + timer_.resched (time);
- +}
- +*/
- diff -Naur ns-2.29-org/wimax/scheduling/burst.h ns-2.29/wimax/scheduling/burst.h
- --- ns-2.29-org/wimax/scheduling/burst.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/burst.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,189 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef BURST_H
- +#define BURST_H
- +
- +#include "queue.h"
- +#include "packet.h"
- +
- +class PhyPdu;
- +
- +class Burst;
- +LIST_HEAD (burst, Burst);
- +
- +/**
- + * This class describe a burst
- + */
- +class Burst
- +{
- + friend class WimaxBurstTimer;
- +
- + public:
- + /**
- + * Creates a burst
- + * @param phypdu The PhyPdu where it is located
- + */
- + Burst (PhyPdu *phypdu);
- +
- + /**
- + * Delete the object
- + */
- + ~Burst ();
- +
- + /**
- + * Return the CID for this burst
- + * @return the CID for this burst
- + */
- + int getCid( );
- +
- + /**
- + * Return the burst duration in units of OFDM symbols
- + * @return the burst duration
- + */
- + int getDuration( );
- +
- + /**
- + * Set the duration of the burst in units of OFDM symbols
- + * @param duration The burst duration
- + */
- + void setDuration (int duration);
- +
- + /**
- + * Return the burst start time in units of symbol duration
- + * @return the burst start time
- + */
- + int getStarttime( );
- +
- + /**
- + * Return the Interval Usage Code
- + * @return the burst start time
- + */
- + int getIUC( );
- +
- + /**
- + * Set burst CID
- + * @param cid The burst CID
- + */
- + void setCid( int cid );
- +
- + /**
- + * Set burst start time in units of symbol duration
- + * @param starttime the burst start time
- + */
- + void setStarttime( int starttime );
- +
- + /**
- + * Set burst IUC
- + * @param iuc The burst IUC
- + */
- + void setIUC( int iuc );
- +
- + /**
- + * Enqueue a packet to be schedule in this burst
- + * @param p The packet to queue
- + */
- + void enqueue (Packet *p);
- +
- + /**
- + * Dequeue a packet from the queue
- + * @param p The packet to enqueue
- + */
- + Packet * dequeue ();
- +
- + /**
- + * Return the queue size in bytes
- + */
- + int getQueueLength() { return queue_->byteLength();}
- +
- + /**
- + * Schedule the timer for this burst
- + * @param time The time the trigger expires
- + */
- + //void trigger_timer (double time);
- +
- + // Chain element to the list
- + inline void insert_entry_head(struct burst *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + // Chain element to the list
- + inline void insert_entry(Burst *elem) {
- + LIST_INSERT_AFTER(elem, this, link);
- + }
- +
- + // Return next element in the chained list
- + Burst* next_entry(void) const { return link.le_next; }
- +
- + // Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- +
- +protected:
- + /**
- + * A timer use to transmit the burst
- + */
- + //WimaxBurstTimer timer_;
- +
- + /**
- + * Packets to be sent during this burst
- + */
- + PacketQueue* queue_;
- +
- + /**
- + * Return the PhyPdu
- + * @return the PhyPdu
- + */
- + inline PhyPdu *getPhyPdu () { return phypdu_; }
- +
- + /*
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(Burst) link;
- + //LIST_ENTRY(Burst); //for magic draw
- +
- + private:
- + /**
- + * The CID for the burst. If a broadcast or multicast is used, then Mac SDUs for different SSs can be included in the burst.
- + */
- + int cid_;
- +
- + /**
- + * The burst duration in units of OFDM Symbols
- + */
- + int duration_;
- +
- + /**
- + * The start time of the burst in units of Symbol Duration
- + */
- + int starttime_;
- +
- + /**
- + * The profile ID
- + */
- + int iuc_;
- +
- + /**
- + * The PhyPdu where it is located
- + */
- + PhyPdu *phypdu_;
- +
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/contentionrequest.cc ns-2.29/wimax/scheduling/contentionrequest.cc
- --- ns-2.29-org/wimax/scheduling/contentionrequest.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/contentionrequest.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,217 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "contentionrequest.h"
- +#include "contentionslot.h"
- +#include "framemap.h"
- +#include "wimaxscheduler.h"
- +#include "random.h"
- +
- +/*
- + * Handling function for WimaxFrameTimer
- + * @param e The event that occured
- + */
- +void WimaxBackoffTimer::handle(Event *e)
- +{
- + busy_ = 0;
- + paused_ = 0;
- + stime = 0.0;
- + rtime = 0.0;
- +
- + mac->transmit (c_->p_->copy());
- +
- + //start timeout trigger
- + c_->starttimeout ();
- +}
- +
- +void WimaxBackoffTimer::pause()
- +{
- + Scheduler &s = Scheduler::instance();
- +
- + //the caculation below make validation pass for linux though it
- + // looks dummy
- +
- + double st = s.clock();
- + double rt = stime;
- + double sr = st - rt;
- +
- + assert(busy_ && ! paused_);
- +
- + paused_ = 1;
- + rtime -= sr;
- +
- + assert(rtime >= 0.0);
- +
- + s.cancel(&intr);
- +}
- +
- +
- +void WimaxBackoffTimer::resume()
- +{
- + Scheduler &s = Scheduler::instance();
- +
- + assert(busy_ && paused_);
- +
- + paused_ = 0;
- + stime = s.clock();
- +
- + assert(rtime >= 0.0);
- + s.schedule(this, &intr, rtime);
- +}
- +
- +/*
- + * Creates a contention slot for the given frame
- + * @param s The contention slot
- + * @param p The packet to send
- + */
- +ContentionRequest::ContentionRequest (ContentionSlot *s, Packet *p)
- +{
- + assert (s);
- + assert (p);
- + s_=s;
- + mac_ = s_->map_->getMac();
- + window_ = s_->getBackoff_start();
- + nb_retry_ = 0;
- + p_=p;
- + backoff_timer_ = new WimaxBackoffTimer (this, mac_);
- + timeout_timer_ = new ContentionTimer (this);
- + int result = Random::random() % ((int)(pow (2, window_)+1));
- + mac_->debug ("At %f in Mac %d Start contention in %f(backoff=%d, size=%d, ps=%f)n", NOW, mac_->addr(), result*s_->getSize()*mac_->getPhy()->getPS(),result,s_->getSize(),mac_->getPhy()->getPS());
- + backoff_timer_->start (result*s_->getSize()*mac_->getPhy()->getPS());
- + backoff_timer_->pause();
- +}
- +
- +ContentionRequest::~ContentionRequest ()
- +{
- + //printf ("canceling timeoutn");
- + //the timeout timer need not be triggered
- + //this can happen when the STA received bw allocation
- + //when it is not waiting for one (or it's still in backoff)
- + if (timeout_timer_->status()!=TIMER_IDLE)
- + timeout_timer_->cancel();
- + if (backoff_timer_->busy())
- + backoff_timer_->stop();
- + delete backoff_timer_;
- + delete timeout_timer_;
- + assert (p_);
- + Packet:: free (p_);
- +}
- +
- +/*
- + * Called when timeout expired
- + */
- +void ContentionRequest::expire ()
- +{
- +
- +}
- +
- +/*
- + * Called when timeout expired
- + */
- +void ContentionRequest::starttimeout ()
- +{
- + timeout_timer_->sched (timeout_);
- +}
- +
- +/*
- + * Pause the backoff timer
- + */
- +void ContentionRequest::pause ()
- +{
- + if (backoff_timer_->busy() && !backoff_timer_->paused())
- + backoff_timer_->pause();
- +}
- +
- +/*
- + * Resume the backoff timer
- + */
- +void ContentionRequest::resume ()
- +{
- + if (backoff_timer_->paused() && timeout_timer_->status()==TIMER_IDLE)
- + backoff_timer_->resume();
- +}
- +
- +/*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- +RangingRequest::RangingRequest (ContentionSlot *s, Packet *p) : ContentionRequest (s,p)
- +{
- + type_ = WimaxT3TimerID;
- + timeout_ = mac_->macmib_.t3_timeout;
- +}
- +
- +/*
- + * Called when timeout expired
- + */
- +void RangingRequest::expire ()
- +{
- + mac_->debug ("Ranging request expiresn");
- + if (nb_retry_ == (int)mac_->macmib_.contention_rng_retry) {
- + //max retries reached, inform the scheduler
- + mac_->getScheduler ()->expire (type_);
- + } else {
- + if (window_ < s_->getBackoff_stop())
- + window_++;
- + nb_retry_++;
- + int result = Random::random() % ((int)(pow (2, window_)+1));
- + mac_->debug ("Start Ranging contention in %f(backoff=%d, size=%d, ps=%f)n", result*s_->getSize()*mac_->getPhy()->getPS(),result,s_->getSize(),mac_->getPhy()->getPS());
- + backoff_timer_->start (result*s_->getSize()*mac_->getPhy()->getPS());
- + backoff_timer_->pause();
- + }
- +}
- +
- +/*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- +BwRequest::BwRequest (ContentionSlot *s, Packet *p, int cid, int len) : ContentionRequest (s,p)
- +{
- + type_ = WimaxT16TimerID;
- + timeout_ = mac_->macmib_.t16_timeout;
- + cid_ = cid;
- + size_ = len;
- +}
- +
- +/*
- + * Called when timeout expired
- + */
- +void BwRequest::expire ()
- +{
- + printf ("Bw request expiresn");
- + if (nb_retry_ == (int)mac_->macmib_.request_retry) {
- + //max retries reached, delete the pdu that were waiting
- + Connection *c = mac_->getCManager()->get_connection (cid_, true);
- + int len = 0;
- + printf ("Dropping packet because bw req exceededn");
- + while (len < size_) {
- + Packet *p = c->dequeue();
- + assert (p);
- + len += HDR_CMN(p)->size();
- + Packet::free (p);
- + }
- + } else {
- + if (window_ < s_->getBackoff_stop())
- + window_++;
- + nb_retry_++;
- + int result = Random::random() % ((int)(pow (2, window_)+1));
- + printf ("Start BW contention in %f(backoff=%d, size=%d, ps=%f)n", result*s_->getSize()*mac_->getPhy()->getPS(),result,s_->getSize(),mac_->getPhy()->getPS());
- + backoff_timer_->start (result*s_->getSize()*mac_->getPhy()->getPS());
- + backoff_timer_->pause();
- + }
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/contentionrequest.h ns-2.29/wimax/scheduling/contentionrequest.h
- --- ns-2.29-org/wimax/scheduling/contentionrequest.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/contentionrequest.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,211 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef CONTENTIONREQUEST_H
- +#define CONTENTIONREQUEST_H
- +
- +#include "mac802_16.h"
- +#include "mac802_16timer.h"
- +
- +class ContentionSlot;
- +class ContentionTimer;
- +class Mac802_16;
- +
- +class ContentionRequest;
- +/** Timer for backoff */
- +class WimaxBackoffTimer : public WimaxTimer {
- + public:
- + WimaxBackoffTimer(ContentionRequest *c, Mac802_16 *m) : WimaxTimer(m) {c_=c;}
- +
- + void handle(Event *e);
- + void pause(void);
- + void resume(void);
- + private:
- + ContentionRequest *c_;
- +};
- +
- +
- +class ContentionRequest;
- +LIST_HEAD (contentionRequest, ContentionRequest);
- +
- +/**
- + * This class is used to manage contention opportunities
- + * supports list
- + */
- +class ContentionRequest
- +{
- + friend class WimaxBackoffTimer;
- + public:
- + /**
- + * Creates a contention slot for the given frame
- + * @param s The contention slot
- + * @param p The packet to send
- + */
- + ContentionRequest (ContentionSlot *s, Packet *p);
- + virtual ~ContentionRequest ();
- + /**
- + * Called when timeout expired
- + */
- + virtual void expire ();
- +
- + /**
- + * Start the timeout timer
- + */
- + void starttimeout();
- +
- + /**
- + * Pause the backoff timer
- + */
- + void pause ();
- +
- + /**
- + * Resume the backoff timer
- + */
- + void resume ();
- +
- + /// Chain element to the list
- + inline void insert_entry_head(struct contentionRequest *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + /// Chain element to the list
- + inline void insert_entry(ContentionRequest *elem) {
- + LIST_INSERT_AFTER(elem, this, link);
- + }
- +
- + /// Return next element in the chained list
- + ContentionRequest* next_entry(void) const { return link.le_next; }
- +
- + /// Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- +
- + protected:
- +
- + /**
- + * The contention slot information
- + */
- + ContentionSlot *s_;
- +
- + /**
- + * The backoff timer
- + */
- + WimaxBackoffTimer *backoff_timer_;
- +
- + /**
- + * The timeout timer
- + */
- + ContentionTimer *timeout_timer_;
- +
- + /**
- + * Type of timer
- + */
- + timer_id type_;
- +
- + /**
- + * Value for timeout
- + */
- + double timeout_;
- +
- + /**
- + * The current window size
- + */
- + int window_;
- +
- + /**
- + * Number of retry
- + */
- + int nb_retry_;
- +
- + /**
- + * The scheduler to inform about timeout
- + */
- + Mac802_16 *mac_;
- +
- + /**
- + * The packet to send when the backoff expires
- + */
- + Packet *p_;
- +
- + /**
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(ContentionRequest) link;
- + //LIST_ENTRY(ContentionRequest); //for magic draw
- +};
- +
- +/**
- + * Class to handle ranging opportunities
- + */
- +class RangingRequest: public ContentionRequest
- +{
- + public:
- +
- + /**
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- + RangingRequest (ContentionSlot *s, Packet *p);
- +
- + /**
- + * Called when timeout expired
- + */
- + void expire ();
- +
- + private:
- +};
- +
- +
- +/**
- + * Class to handle bandwidth request opportunities
- + */
- +class BwRequest: public ContentionRequest
- +{
- + public:
- +
- + /**
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- + BwRequest (ContentionSlot *s, Packet *p, int cid, int length);
- +
- + /**
- + * Called when timeout expired
- + */
- + void expire ();
- +
- + /**
- + * Return the CID for this request
- + * @return the CID for this request
- + */
- + inline int getCID () { return cid_; }
- +
- + private:
- + /**
- + * The CID for the request
- + */
- + int cid_;
- +
- + /**
- + * The size in bytes of the bandwidth requested
- + */
- + int size_;
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/contentionslot.cc ns-2.29/wimax/scheduling/contentionslot.cc
- --- ns-2.29-org/wimax/scheduling/contentionslot.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/contentionslot.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,211 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "contentionslot.h"
- +#include <random.h>
- +#include <math.h>
- +
- +/*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- +ContentionSlot::ContentionSlot (FrameMap *map)
- +{
- + assert (map);
- + map_ = map;
- +}
- +
- +/**
- + * Destructor
- + */
- +ContentionSlot::~ContentionSlot() {}
- +
- +/*
- + * Set the initial contention slot window size
- + * @param backoff_start the initial contention slot window size
- + */
- +void ContentionSlot::setBackoff_start( int backoff_start )
- +{
- + backoff_start_ = backoff_start;
- +}
- +
- +/*
- + * Set the final contention slot window size
- + * @param backoff_stop the final contention slot window size
- + */
- +void ContentionSlot::setBackoff_stop( int backoff_stop )
- +{
- + backoff_stop_ = backoff_stop;
- +}
- +
- +/**
- + * Resume the timers for the requests
- + */
- +void ContentionSlot::resumeTimers () {}
- +
- +/**
- + * Pause the timers for the requests
- + */
- +void ContentionSlot::pauseTimers () {}
- +
- +/**** Methods for Ranging Contention slot ****/
- +
- +/*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- +RngContentionSlot::RngContentionSlot (FrameMap *map) : ContentionSlot (map)
- +{
- + request_ = NULL;
- +}
- +
- +/**
- + * Destructor
- + */
- +RngContentionSlot::~RngContentionSlot()
- +{
- + if (request_)
- + delete request_;
- +}
- +
- +
- +/*
- + * Add a ranging request
- + * @param p The packet to be sent during the ranging opportunity
- + */
- +void RngContentionSlot::addRequest (Packet *p)
- +{
- + assert (request_ == NULL);
- + request_ = new RangingRequest (this, p);
- +}
- +
- +/*
- + * Remove the pending request
- + */
- +void RngContentionSlot::removeRequest ()
- +{
- + //assert (request_);
- + if (request_) {
- + delete request_;
- + request_ = NULL;
- + }
- +}
- +
- +/**
- + * Resume the timers for the requests
- + */
- +void RngContentionSlot::resumeTimers ()
- +{
- + if (request_)
- + request_->resume();
- +}
- +
- +/**
- + * Pause the timers for the requests
- + */
- +void RngContentionSlot::pauseTimers ()
- +{
- + if (request_)
- + request_->pause();
- +}
- +
- +/**** Methods for Bandwidth Contention slot ****/
- +
- +/*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- +BwContentionSlot::BwContentionSlot (FrameMap *map) : ContentionSlot (map)
- +{
- + LIST_INIT (&request_list_);
- +}
- +
- +/**
- + * Destructor
- + */
- +BwContentionSlot::~BwContentionSlot() {}
- +
- +/*
- + * Add a bandwidth request
- + * @param p The packet to be sent during the ranging opportunity
- + * @param cid The CID of the bandwidth request
- + * @param len The size in bytes of the bandwidth request
- + */
- +void BwContentionSlot::addRequest (Packet *p, int cid, int len)
- +{
- + assert (getRequest (cid)==NULL);
- + BwRequest *b = new BwRequest (this, p, cid, len);
- + b->insert_entry_head (&request_list_);
- +}
- +
- +/*
- + * Remove the pending request
- + */
- +void BwContentionSlot::removeRequest (int cid)
- +{
- + BwRequest *b = getRequest (cid);
- + if (b!=NULL) {
- + b->remove_entry ();
- + delete b;
- + }
- +}
- +
- +/*
- + * Remove all pending reuquest
- + */
- +void BwContentionSlot::removeRequests ()
- +{
- + for (BwRequest *c = (BwRequest *)request_list_.lh_first; c ; c=(BwRequest *)request_list_.lh_first) {
- + c->remove_entry();
- + delete c;
- + }
- +}
- +
- +
- +/*
- + * Get the request for the given CID
- + * @param cid The CID for the request
- + */
- +BwRequest* BwContentionSlot::getRequest (int cid)
- +{
- + for (BwRequest *c = (BwRequest *)request_list_.lh_first; c ; c=(BwRequest *)(c->next_entry())) {
- + if (c->getCID()==cid)
- + return c;
- + }
- + return NULL;
- +}
- +
- +/**
- + * Resume the timers for the requests
- + */
- +void BwContentionSlot::resumeTimers ()
- +{
- + for (BwRequest *c = (BwRequest *)request_list_.lh_first; c ; c=(BwRequest *)(c->next_entry())) {
- + c->resume();
- + }
- +}
- +
- +/**
- + * Pause the timers for the requests
- + */
- +void BwContentionSlot::pauseTimers ()
- +{
- + for (BwRequest *c = (BwRequest *)request_list_.lh_first; c ; c=(BwRequest *)(c->next_entry())) {
- + c->pause();
- + }
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/contentionslot.h ns-2.29/wimax/scheduling/contentionslot.h
- --- ns-2.29-org/wimax/scheduling/contentionslot.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/contentionslot.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,214 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef CONTENTIONSLOT_H
- +#define CONTENTIONSLOT_H
- +
- +#include "packet.h"
- +#include "queue.h"
- +#include "contentiontimer.h"
- +
- +class FrameMap;
- +
- +/**
- + * This class contains information about a contention slot
- + */
- +class ContentionSlot
- +{
- + friend class ContentionRequest;
- +
- + public:
- + /*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- + ContentionSlot (FrameMap *map);
- +
- + /**
- + * Destructor
- + */
- + virtual ~ContentionSlot();
- +
- + /*
- + * Return the initial contention slot window size
- + * @return the initial contention slot window size
- + */
- + inline int getBackoff_start( ) { return backoff_start_; }
- +
- + /*
- + * Return the final contention slot window size
- + * @return the final contention slot window size
- + */
- + inline int getBackoff_stop( ) { return backoff_stop_; }
- +
- + /*
- + * Return the opportunity size
- + * @return the opportunity size
- + */
- + inline int getSize( ) { return size_; }
- +
- + /*
- + * Set the initial contention slot window size
- + * @param backoff_start the initial contention slot window size
- + */
- + void setBackoff_start( int backoff_start );
- +
- + /*
- + * Set the final contention slot window size
- + * @param backoff_stop the final contention slot window size
- + */
- + void setBackoff_stop( int backoff_stop );
- +
- + /*
- + * Set the opportunity size
- + * @param size The opportunity size
- + */
- + inline void setSize( int size ) { size_ = size; }
- +
- + /**
- + * Resume the timers for the requests
- + */
- + virtual void resumeTimers ();
- +
- + /**
- + * Pause the timers for the requests
- + */
- + virtual void pauseTimers ();
- +
- + protected:
- + /**
- + * The frame map where this contention slot is located
- + */
- + FrameMap *map_;
- +
- + /**
- + * Initial backoff window size. Must be power of 2
- + */
- + int backoff_start_;
- +
- + /**
- + * Final backoff window size
- + */
- + int backoff_stop_;
- +
- + /**
- + * The duration in PS of the contention slot
- + */
- + int size_;
- + private:
- +
- +};
- +
- +/**
- + * Subclass used for ranging contention slot
- + */
- +class RngContentionSlot: public ContentionSlot {
- + friend class RngContentionTimer;
- + public:
- +
- + /*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- + RngContentionSlot (FrameMap *map);
- +
- + /**
- + * Destructor
- + */
- + virtual ~RngContentionSlot();
- +
- + /*
- + * Add a ranging request
- + * @param p The packet to be sent during the ranging opportunity
- + */
- + void addRequest (Packet *p);
- +
- + /*
- + * Remove the pending request
- + */
- + void removeRequest ();
- +
- + /**
- + * Resume the timers for the requests
- + */
- + void resumeTimers ();
- +
- + /**
- + * Pause the timers for the requests
- + */
- + void pauseTimers ();
- +
- + private:
- + RangingRequest *request_;
- +};
- +
- +/**
- + * Subclass used for ranging contention slot
- + */
- +class BwContentionSlot: public ContentionSlot {
- + public:
- + /*
- + * Creates a contention slot for the given frame
- + * @param frame The frame map
- + */
- + BwContentionSlot (FrameMap *map);
- +
- + /**
- + * Destructor
- + */
- + virtual ~BwContentionSlot();
- +
- + /*
- + * Add a bandwidth request
- + * @param p The packet to be sent during the ranging opportunity
- + * @param cid The CID of the bandwidth request
- + * @param len The size in bytes of the bandwidth request
- + */
- + void addRequest (Packet *p, int cid, int len);
- +
- + /*
- + * Remove the pending request
- + */
- + void removeRequest (int cid);
- +
- + /*
- + * Remove all pending reuquest
- + */
- + void removeRequests ();
- +
- + /*
- + * Get the request for the given CID
- + * @param cid The CID for the request
- + */
- + BwRequest * getRequest (int cid);
- +
- + /**
- + * Resume the timers for the requests
- + */
- + void resumeTimers ();
- +
- + /**
- + * Pause the timers for the requests
- + */
- + void pauseTimers ();
- +
- + private:
- + struct contentionRequest request_list_;
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/contentiontimer.cc ns-2.29/wimax/scheduling/contentiontimer.cc
- --- ns-2.29-org/wimax/scheduling/contentiontimer.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/contentiontimer.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,40 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "contentiontimer.h"
- +
- +/**
- + * Creates a timer to handle the burst's transmission
- + * @param c The contention slot
- + */
- +ContentionTimer::ContentionTimer( ContentionRequest* c ) : TimerHandler()
- +{
- + assert (c);
- + c_ = c;
- +}
- +
- +/**
- + * When it expires, the timer will handle the next packet to send
- + * @param e not used
- + */
- +void ContentionTimer::expire( Event* e )
- +{
- + c_->expire();
- +}
- +
- +
- diff -Naur ns-2.29-org/wimax/scheduling/contentiontimer.h ns-2.29/wimax/scheduling/contentiontimer.h
- --- ns-2.29-org/wimax/scheduling/contentiontimer.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/contentiontimer.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,51 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef CONTENTIONTIMER_H
- +#define CONTENTIONTIMER_H
- +
- +#include "timer-handler.h"
- +#include "contentionrequest.h"
- +
- +/**
- + * Timer for contention window
- + */
- +class ContentionTimer: public TimerHandler
- +{
- + public:
- + /**
- + * Creates a timer to handle the burst's transmission
- + * @param c The contention slot
- + */
- + ContentionTimer( ContentionRequest* c );
- +
- + /**
- + * When it expires, the timer will handle the next packet to send
- + * @param e not used
- + */
- + void expire( Event* e );
- +
- + private:
- +
- + /**
- + * The contention slot containing the packets to send
- + */
- + ContentionRequest* c_;
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/dlburst.cc ns-2.29/wimax/scheduling/dlburst.cc
- --- ns-2.29-org/wimax/scheduling/dlburst.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/dlburst.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,28 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "dlburst.h"
- +
- +/**
- + * Creates a downlink burst
- + * @param phypdu The PhyPdu where it is located
- + */
- +DlBurst::DlBurst (PhyPdu *phypdu) : Burst (phypdu)
- +{
- +
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/dlburst.h ns-2.29/wimax/scheduling/dlburst.h
- --- ns-2.29-org/wimax/scheduling/dlburst.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/dlburst.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,78 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef DLBURST_H
- +#define DLBURST_H
- +
- +#include "burst.h"
- +
- +/* Defines the OFDM DIUC values */
- +enum diuc_t {
- + DIUC_STC_ZONE=0,
- + //1-11 reserved for burst profiles
- + DIUC_PROFILE_1,
- + DIUC_PROFILE_2,
- + DIUC_PROFILE_3,
- + DIUC_PROFILE_4,
- + DIUC_PROFILE_5,
- + DIUC_PROFILE_6,
- + DIUC_PROFILE_7,
- + DIUC_PROFILE_8,
- + DIUC_PROFILE_9,
- + DIUC_PROFILE_10,
- + DIUC_PROFILE_11,
- + //12 is reserved
- + DIUC_GAP=13,
- + DIUC_END_OF_MAP,
- + DIUC_EXT_DIUC
- +};
- +
- +/**
- + * Downlink Burst Description
- + */
- +class DlBurst : public Burst
- +{
- + public:
- +
- + /**
- + * Default contructor
- + * @param phypdu The PhyPdu where it is located
- + */
- + DlBurst (PhyPdu *phypdu);
- +
- + /**
- + * Return true if preamble is present in the burst
- + * @return true if preamble is present in the burst
- + */
- + inline bool isPreamble( ) { return preamble_; }
- +
- + /**
- + * Set the preamble flag for the burst
- + * @param preamble The flag
- + */
- + inline void setPreamble( bool preamble ) { preamble_ = preamble; }
- +
- + private:
- + /**
- + * Indicate if a preamble is included in the burst of not
- + */
- + bool preamble_;
- +
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/dlsubframetimer.cc ns-2.29/wimax/scheduling/dlsubframetimer.cc
- --- ns-2.29-org/wimax/scheduling/dlsubframetimer.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/dlsubframetimer.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,101 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "dlsubframetimer.h"
- +#include "framemap.h"
- +#include "subframe.h"
- +#include "wimaxscheduler.h"
- +#include "contentionslot.h"
- +
- +/**
- + * Creates a timer to handle the subframe transmission
- + * @param subframe The DlSubframe
- + */
- +DlSubFrameTimer::DlSubFrameTimer (DlSubFrame *subframe): burstIndex_(0), newburst_(true), mac_(0)
- +{
- + assert (subframe);
- + subframe_ = subframe;
- +}
- +
- +/**
- + * Reset the timer
- + */
- +void DlSubFrameTimer::reset ()
- +{
- + burstIndex_ = 0;
- + newburst_ = true;
- + if (status()==TIMER_PENDING)
- + cancel();
- +}
- +
- +/**
- + * When it expires, the timer will handle the next packet to send
- + * @param e not used
- + */
- +void DlSubFrameTimer::expire( Event* e )
- +{
- + if (!mac_) {
- + mac_= subframe_->map_->getMac();
- + }
- +
- + //printf ("At %f in Mac %d DlsubFrameTimer expiresn", NOW, mac_->addr());
- + int iuc;
- + Burst *b = subframe_->getPdu()->getBurst(burstIndex_);
- + if (newburst_) {
- + //printf ("tburst=%x type=%dn", b,b->getIUC());
- + if (b->getIUC()==DIUC_END_OF_MAP) {
- + //printf ("tend of subframen");
- + burstIndex_=0;//reset for next frame
- + if (mac_->getScheduler()->getNodeType()==STA_MN) {
- + mac_->getPhy()->setMode (OFDM_SEND);
- + } else {
- + mac_->getPhy()->setMode (OFDM_RECV);
- + }
- + return; //end of subframe
- + }
- + //change modulation
- + iuc = b->getIUC();
- + Ofdm_mod_rate rate = subframe_->getProfile (iuc)->getEncoding();
- + mac_->getPhy()->setModulation (rate);
- + }
- + //check if packet to send
- + Packet *p = b->dequeue();
- + if (p) {
- + newburst_ = false;
- + double txtime = HDR_CMN(p)->txtime();
- + //schedule for next packet
- + mac_->transmit (p);
- + //printf ("tNext packet at %f(in %f)n", NOW+txtime, txtime);
- + if (b->getQueueLength()!=0) {
- + resched (txtime); //wait transmition time
- + return;
- + }
- + }
- +
- + //no packet to send...schedule for next phypdu
- + newburst_= true;
- + burstIndex_++;
- + double stime=0.0;
- + assert (b->next_entry());
- +
- + stime = subframe_->map_->getStarttime();
- + stime += b->next_entry()->getStarttime()*mac_->getPhy()->getSymbolTime();
- + //printf ("tNext burst at %fn", stime);
- + resched (stime-NOW);
- +
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/dlsubframetimer.h ns-2.29/wimax/scheduling/dlsubframetimer.h
- --- ns-2.29-org/wimax/scheduling/dlsubframetimer.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/dlsubframetimer.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,73 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef DLSUBFRAME_H
- +#define DLSUBFRAME_H
- +
- +#include "mac802_16.h"
- +#include "phypdu.h"
- +
- +class DlSubFrame;
- +/**
- + * This timer is used to handle the transmission of
- + * a UlSubframe.
- + */
- +class DlSubFrameTimer: public TimerHandler
- +{
- + public:
- + /**
- + * Creates a timer to handle the subframe transmission
- + * @param subframe The UlSubframe
- + */
- + DlSubFrameTimer (DlSubFrame *subframe);
- +
- + /**
- + * When it expires, the timer will handle the next packet to send
- + * @param e not used
- + */
- + void expire( Event* e );
- +
- + /**
- + * Reset the timer
- + */
- + void reset ();
- +
- + private:
- + /**
- + * The subframe
- + */
- + DlSubFrame *subframe_;
- +
- + /**
- + * The current Burst being handled
- + */
- + int burstIndex_;
- +
- + /**
- + * Tag to know if we are changing PhyPdu
- + */
- + bool newburst_;
- +
- + /**
- + * Store local variables for faster access
- + */
- + Mac802_16 *mac_;
- +
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/framemap.cc ns-2.29/wimax/scheduling/framemap.cc
- --- ns-2.29-org/wimax/scheduling/framemap.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/framemap.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,323 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + File * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +
- +#include "framemap.h"
- +#include "wimaxscheduler.h"
- +#include "ulburst.h"
- +#include "dlburst.h"
- +
- +/*
- + * Creates a map of the frame
- + * @param mac Pointer to the mac layer
- + */
- +FrameMap::FrameMap (Mac802_16 *mac): dlsubframe_(this), ulsubframe_(this)
- +{
- + assert (mac);
- + mac_ = mac;
- +
- + //retreive information from mac
- + rtg_ = mac_->phymib_.rtg;
- + ttg_ = mac_->phymib_.ttg;
- + duration_ = mac_->getFrameDuration();
- +}
- +
- +/**
- + * Compute the DL_MAP packet based on the information contained in the structure
- + */
- +Packet* FrameMap::getDL_MAP( )
- +{
- + Packet *p = mac_->getPacket();
- + hdr_cmn* ch = HDR_CMN(p);
- +
- + //printf ("Creating DL_MAP:");
- + int nbies = dlsubframe_.getPdu()->getNbBurst();
- + //printf ("nbies=%dn",nbies);
- +
- + //allocate data for DL_MAP
- + p->allocdata (sizeof (struct mac802_16_dl_map_frame));
- + mac802_16_dl_map_frame *frame = (mac802_16_dl_map_frame*) p->accessdata();
- +
- + frame->type = MAC_DL_MAP;
- + frame->bsid = mac_->addr();
- + frame->nb_ies = nbies;
- +
- + //allocate IEs
- + mac802_16_dlmap_ie *ies = frame->ies;
- +
- + for (int i = 0 ; i < nbies ; i++) {
- + Burst *b = dlsubframe_.getPdu()->getBurst(i);
- + ies[i].diuc = b->getIUC();
- + ies[i].start_time = b->getStarttime();
- + if (b->getIUC()!=DIUC_END_OF_MAP) {
- + ies[i].cid = b->getCid();
- + if (i==0)
- + ies[i].preamble = dlsubframe_.getPdu()->getPreamble();
- + else
- + ies[i].preamble = 0;
- + }
- + }
- +
- + ch->size() += GET_DL_MAP_SIZE(nbies);
- +
- + return p;
- +}
- +
- +/**
- + * Compute and return the DCD frame
- + */
- +Packet* FrameMap::getDCD( )
- +{
- + Packet *p = mac_->getPacket ();
- + hdr_cmn* ch = HDR_CMN(p);
- +
- + //allocate data for DL_MAP
- + //printf ("getDCD...nbprofile=%dn", dlsubframe_.getNbProfile());
- + p->allocdata (sizeof (struct mac802_16_dcd_frame));
- + mac802_16_dcd_frame *frame = (mac802_16_dcd_frame*) p->accessdata();
- +
- + frame->type = MAC_DCD;
- + frame->dcid = mac_->addr(); //to check if needs to be different from ucid
- + frame->config_change_count = dlsubframe_.getCCC();
- + frame->frame_duration_code = mac_->getFrameDurationCode ();
- + frame->frame_number = mac_->frame_number_;
- + frame->nb_prof = dlsubframe_.getNbProfile();
- + frame->ttg = mac_->phymib_.ttg;
- + frame->rtg = mac_->phymib_.rtg;
- + frame->frequency = (int) (mac_->getPhy()->getFreq()/1000);
- +
- + //allocate IEs
- + mac802_16_dcd_profile *profiles = frame->profiles;
- +
- + int i=0;
- + for (Profile *p = dlsubframe_.getFirstProfile() ; p ; p=p->next_entry()) {
- + //set data for first burst
- + profiles[i].diuc = p->getIUC();
- + profiles[i].frequency = p->getFrequency();
- + profiles[i].fec = p->getEncoding();
- + i++;
- + }
- + //the end of map is already included in the frame length
- +
- + ch->size() += GET_DCD_SIZE(dlsubframe_.getNbProfile());
- + return p;
- +}
- +
- +/**
- + * Compute and return the UL_MAP frame
- + */
- +Packet* FrameMap::getUL_MAP( )
- +{
- + Packet *p = mac_->getPacket ();
- + hdr_cmn* ch = HDR_CMN(p);
- +
- + int nbies = ulsubframe_.getNbPdu(); //there is one burst per UL phy PDU
- + //printf ("getUL_MAP, nbies=%dn", nbies);
- + //allocate data for DL_MAP
- + p->allocdata (sizeof (struct mac802_16_ul_map_frame));
- + mac802_16_ul_map_frame *frame = (mac802_16_ul_map_frame*) p->accessdata();
- +
- + frame->type = MAC_UL_MAP;
- + frame->ucid = mac_->addr(); //set channel ID to index_ to be unique
- + frame->ucd_count = ulsubframe_.getCCC();
- + frame->allocation_start = ulsubframe_.getStarttime(); //the subframe starts with the contention slot
- + frame->nb_ies = nbies;
- +
- + //allocate IEs
- + mac802_16_ulmap_ie *ies = frame->ies;
- +
- + int i=0;
- + for (PhyPdu *p = ulsubframe_.getFirstPdu(); p ; p= p ->next_entry()) {
- + UlBurst *b = (UlBurst*) p->getBurst(0);
- + ies[i].uiuc = b->getIUC(); //end of map
- + ies[i].start_time = b->getStarttime();
- + if (b->getIUC()!=UIUC_END_OF_MAP) {
- + ies[i].cid = b->getCid();
- + ies[i].midamble_rep = b->getMidamble();
- + ies[i].duration = b->getDuration();
- + if (b->getIUC() == UIUC_EXT_UIUC) {
- + ies[i].extended_uiuc = b->getExtendedUIUC();
- + if (b->getExtendedUIUC ()== UIUC_FAST_RANGING) {
- + ies[i].fast_ranging.mac_addr = b->getFastRangingMacAddr ();
- + ies[i].fast_ranging.uiuc = b->getFastRangingUIUC ();
- + }
- + }
- + }
- + i++;
- + }
- +
- + ch->size() += GET_UL_MAP_SIZE(nbies);
- + return p;
- +}
- +
- +/**
- + * Compute and return the UCD frame
- + */
- +Packet* FrameMap::getUCD( )
- +{
- + Packet *p = mac_->getPacket ();
- + hdr_cmn* ch = HDR_CMN(p);
- +
- + //allocate data for DL_MAP
- + p->allocdata (sizeof (struct mac802_16_ucd_frame));
- + mac802_16_ucd_frame *frame = (mac802_16_ucd_frame*) p->accessdata();
- +
- + frame->type = MAC_UCD;
- + frame->config_change_count = 0; //changed by scheduler
- + frame->rng_backoff_start = ulsubframe_.getRanging()->getBackoff_start();
- + frame->rng_backoff_end = ulsubframe_.getRanging()->getBackoff_stop();
- + frame->rng_req_size = ulsubframe_.getRanging()->getSize();
- + frame->req_backoff_start = ulsubframe_.getBw_req()->getBackoff_start();
- + frame->req_backoff_end = ulsubframe_.getBw_req()->getBackoff_stop()+1;
- + frame->bw_req_size = ulsubframe_.getBw_req()->getSize();
- +
- + frame->nb_prof = ulsubframe_.getNbProfile();
- + //allocate IEs
- + mac802_16_ucd_profile *profiles = frame->profiles;
- +
- + int i=0;
- + for (Profile *p = ulsubframe_.getFirstProfile() ; p ; p=p->next_entry()) {
- + //set data for first burst
- + profiles[i].uiuc = p->getIUC();
- + profiles[i].fec = p->getEncoding();
- + i++;
- + }
- +
- + //the end of map is already included in the frame length
- + ch->size() += GET_UCD_SIZE(ulsubframe_.getNbProfile());
- + return p;
- +}
- +
- +/**
- + * Parse a DL_MAP message and create the data structure
- + * @param frame The DL frame information
- + */
- +void FrameMap::parseDLMAPframe (mac802_16_dl_map_frame *frame)
- +{
- + //printf ("parse DL-MAP in %dn", mac_->addr());
- + // Clear previous information
- + while (dlsubframe_.getPdu()->getNbBurst()>0) {
- + Burst *b = dlsubframe_.getPdu()->getBurst (0);
- + dlsubframe_.getPdu()->removeBurst (b);
- + delete b;
- + }
- +
- + int nbies = frame->nb_ies;
- + mac802_16_dlmap_ie *ies = frame->ies;
- +
- + for (int i = 0 ; i < nbies ; i++) {
- + Burst *b = dlsubframe_.getPdu()->addBurst(i);
- + b->setIUC(ies[i].diuc);
- + b->setStarttime(ies[i].start_time);
- + if (b->getIUC()!=DIUC_END_OF_MAP) {
- + b->setCid(ies[i].cid);
- + if (i==0) //first burst contains preamble
- + dlsubframe_.getPdu()->setPreamble(ies[i].preamble);
- + }
- + //printf ("t Adding burst %d: cid=%d, iuc=%d start=%dn", i, b->getCid(), b->getIUC(),b->getStarttime());
- + }
- + //should we parse end of map too?
- +}
- +
- +/**
- + * Parse a DCD message and create the data structure
- + * @param frame The DL frame information
- + */
- +void FrameMap::parseDCDframe (mac802_16_dcd_frame *frame)
- +{
- + //clear previous profiles
- + dlsubframe_.removeProfiles();
- +
- + int nb_prof = frame->nb_prof;
- + mac_->frame_number_ = frame->frame_number;
- + mac802_16_dcd_profile *profiles = frame->profiles;
- + mac_->setFrameDurationCode (frame->frame_duration_code);
- +
- + for (int i = 0 ; i < nb_prof ; i++) {
- + Profile *p = dlsubframe_.addProfile (profiles[i].frequency, (Ofdm_mod_rate)profiles[i].fec);
- + p->setIUC (profiles[i].diuc);
- + //printf ("t Adding dl profile %i: f=%d, rate=%d, iuc=%dn", i, p->getFrequency(), p->getEncoding(), p->getIUC());
- + }
- +}
- +
- +/**
- + * Parse a UL_MAP message and create the data structure
- + * @param frame The UL frame information
- + */
- +void FrameMap::parseULMAPframe (mac802_16_ul_map_frame *frame)
- +{
- + //printf ("parse UL-MAPn");
- + // Clear previous information
- + for (PhyPdu *p = ulsubframe_.getFirstPdu(); p ; p = ulsubframe_.getFirstPdu()) {
- + ulsubframe_.removePhyPdu(p);
- + delete (p);
- + }
- +
- + int nbies = frame->nb_ies;
- + mac802_16_ulmap_ie *ies = frame->ies;
- +
- + ulsubframe_.setStarttime(frame->allocation_start);
- + //mac_->debug ("tul start time = %d %fn", frame->allocation_start, frame->allocation_start*mac_->getPhy()->getPS());
- +
- + for (int i = 0 ; i < nbies ; i++) {
- + UlBurst *b = (UlBurst*)(ulsubframe_.addPhyPdu(i,0))->addBurst(0);
- + b->setIUC(ies[i].uiuc);
- + b->setStarttime(ies[i].start_time);
- + if (b->getIUC()!=UIUC_END_OF_MAP) {
- + b->setCid(ies[i].cid);
- + b->setMidamble(ies[i].midamble_rep);
- + b->setDuration(ies[i].duration);
- + if (b->getIUC() == UIUC_EXT_UIUC) {
- + if(ies[i].extended_uiuc== UIUC_FAST_RANGING) {
- + b->setFastRangingParam (ies[i].fast_ranging.mac_addr, ies[i].fast_ranging.uiuc);
- + }
- + }
- + }
- + /*mac_->debug ("t Adding burst %d: cid=%d, iuc=%d start=%d (%f) duration=%dn",
- + i, b->getCid(), b->getIUC(),b->getStarttime(), starttime_+frame->allocation_start*mac_->getPhy()->getPS()+b->getStarttime()*mac_->getPhy()->getSymbolTime(), b->getDuration());*/
- + }
- +}
- +
- +/**
- + * Parse a UCD message and create the data structure
- + * @param frame The DL frame information
- + */
- +void FrameMap::parseUCDframe (mac802_16_ucd_frame *frame)
- +{
- + assert (frame);
- + //clear previous profiles
- + ulsubframe_.removeProfiles();
- +
- + /*printf ("parse UCD..rng_start=%d, rng_stop=%d, req_start=%d, req_stop=%dn",
- + frame->rng_backoff_start, frame->rng_backoff_end, frame->req_backoff_start,
- + frame->req_backoff_end);*/
- + ulsubframe_.getRanging()->setBackoff_start(frame->rng_backoff_start);
- + ulsubframe_.getRanging()->setBackoff_stop(frame->rng_backoff_end);
- + ulsubframe_.getRanging()->setSize(frame->rng_req_size);
- + ulsubframe_.getBw_req()->setBackoff_start(frame->req_backoff_start);
- + ulsubframe_.getBw_req()->setBackoff_stop(frame->req_backoff_end);
- + ulsubframe_.getBw_req()->setSize(frame->bw_req_size);
- +
- + int nb_prof = frame->nb_prof;
- + mac802_16_ucd_profile *profiles = frame->profiles;
- + for (int i = 0 ; i < nb_prof ; i++) {
- + Profile *p = ulsubframe_.addProfile (0, (Ofdm_mod_rate)(profiles[i].fec));
- + p->setIUC (profiles[i].uiuc);
- + //printf ("t Adding ul profile %i: f=%d, rate=%d, iuc=%dn", i, p->getFrequency(), p->getEncoding(), p->getIUC());
- + }
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/framemap.h ns-2.29/wimax/scheduling/framemap.h
- --- ns-2.29-org/wimax/scheduling/framemap.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/framemap.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,148 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef FRAMEMAP_H
- +#define FRAMEMAP_H
- +
- +#include "subframe.h"
- +#include "mac802_16.h"
- +
- +/**
- + * This class contains the datastructure to describe a frame
- + */
- +class FrameMap
- +{
- + public:
- + /*
- + * Creates a map of the frame
- + * @param mac Pointer to the mac layer
- + */
- + FrameMap (Mac802_16 *mac);
- +
- + /**
- + * Compute and return the DCD frame
- + */
- + Packet* getDCD( );
- + /**
- + * Compute the DL_MAP packet based on the information contained in the structure
- + */
- + Packet* getDL_MAP( );
- +
- + /**
- + * Compute and return the UCD frame
- + */
- + Packet* getUCD( );
- +
- + /**
- + * Compute and return the UL_MAP frame
- + */
- + Packet* getUL_MAP( );
- +
- + /**
- + * Return the attached mac
- + * @return the mac
- + */
- + inline Mac802_16 * getMac () { return mac_; }
- +
- + /**
- + * Return the DL subframe
- + * @return the DL subframe
- + */
- + inline DlSubFrame * getDlSubframe () { return &dlsubframe_; }
- +
- +
- + /**
- + * Return the UL subframe
- + * @return the UL subframe
- + */
- + inline UlSubFrame * getUlSubframe () { return &ulsubframe_; }
- +
- +
- + /**
- + * Parse a DL_MAP message and create the data structure
- + * @param frame The DL frame information
- + */
- + void parseDLMAPframe (mac802_16_dl_map_frame *frame);
- +
- + /**
- + * Parse a DCD message and create the data structure
- + * @param frame The DL frame information
- + */
- + void parseDCDframe (mac802_16_dcd_frame *frame);
- +
- + /**
- + * Parse a UL_MAP message and create the data structure
- + * @param frame The UL frame information
- + */
- + void parseULMAPframe (mac802_16_ul_map_frame *frame);
- +
- + /**
- + * Parse a UCD message and create the data structure
- + * @param frame The DL frame information
- + */
- + void parseUCDframe (mac802_16_ucd_frame *frame);
- +
- + /**
- + * Set the start time of the frame
- + */
- + inline void setStarttime (double time) { starttime_ = time; }
- +
- + /**
- + * Return the time the frame started
- + * @return The time the frame started
- + */
- + inline double getStarttime () { return starttime_; }
- +
- +private:
- + /**
- + * The mac layer
- + */
- + Mac802_16 *mac_;
- +
- + /**
- + * The frame duration
- + */
- + double duration_;
- +
- + /**
- + * Time the frame started. Used for synchronization
- + */
- + double starttime_;
- +
- + /**
- + * The number of PS required to switch from receiver to transmitter
- + */
- + int rtg_;
- +
- + /**
- + * The number of PS required to switch from sender to receiver
- + */
- + int ttg_;
- +
- + /**
- + * The downlink subframe
- + */
- + DlSubFrame dlsubframe_;
- +
- + /**
- + * The uplink subframe
- + */
- + UlSubFrame ulsubframe_;
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/phypdu.cc ns-2.29/wimax/scheduling/phypdu.cc
- --- ns-2.29-org/wimax/scheduling/phypdu.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/phypdu.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,174 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "phypdu.h"
- +
- +/**
- + * Create a phy pdu with the given preamble size
- + * @param preamble The preamble size in OFDM symbols
- + */
- +PhyPdu::PhyPdu (FrameMap *map, int preamble)
- +{
- + assert (preamble >=0 && map);
- + preamble_ = preamble;
- + map_ = map;
- + nb_burst_=0;
- + LIST_INIT(&burst_list_);
- +}
- +
- +/*
- + * Delete the object
- + */
- +PhyPdu::~PhyPdu ()
- +{
- + for (Burst *b = burst_list_.lh_first; b ; b=burst_list_.lh_first) {
- + b->remove_entry ();
- + delete (b);
- + }
- +}
- +
- +
- +/**
- + * Set the preamble size for the PDU in unit of OFDM symbols
- + * @param preamble the preamble size for the PDU
- + */
- +void PhyPdu::setPreamble( int preamble )
- +{
- + assert (preamble>=0);
- + preamble_ = preamble;
- +}
- +
- +/**
- + * Return the preamble size for the PDU in unit of OFDM symbols
- + * @return the preamble size for the PDU
- + */
- +int PhyPdu::getPreamble( )
- +{
- + return preamble_;
- +}
- +
- +/**
- + * Add a burst in the PDU
- + * @param pos The position of the burst
- + */
- +Burst* PhyPdu::addBurst(int pos)
- +{
- + assert (pos >= 0 && pos <= nb_burst_ );
- + Burst *b = new Burst (this);
- + if (pos==0)
- + b->insert_entry_head (&burst_list_);
- + else {
- + Burst *prev = burst_list_.lh_first ;
- + Burst *b2 = prev->next_entry();
- + int index = 1;
- + while (index < pos) {
- + prev=b2;
- + b2=b2->next_entry();
- + index++;
- + }
- + b->insert_entry (prev);
- + }
- + nb_burst_++;
- + return b;
- +}
- +
- +/**
- + * Remove a burst in the PDU
- + * @param burst The burst to remove
- + */
- +void PhyPdu::removeBurst(Burst *b)
- +{
- + b->remove_entry();
- + nb_burst_--;
- +}
- +
- +/**
- + * Return the burst located at the given index
- + * @param pos The position of the burst
- + */
- +Burst* PhyPdu::getBurst(int pos)
- +{
- + assert (pos >= 0 && pos < nb_burst_ );
- + Burst *b = burst_list_.lh_first ;
- + for (int i = 0 ; i < pos ; i++) {
- + b=b->next_entry();
- + }
- + return b;
- +}
- +
- +/** Methods for class DlPhyPdu **/
- +
- +/**
- + * Create a phy pdu with the given preamble size
- + * @param preamble The preamble size in OFDM symbols
- + */
- +DlPhyPdu::DlPhyPdu (FrameMap *map, int preamble) : PhyPdu(map, preamble)
- +{
- +
- +}
- +
- +/**
- + * Add a burst in the PDU
- + * @param pos The position of the burst
- + */
- +Burst* DlPhyPdu::addBurst(int pos)
- +{
- + assert (pos >= 0 && pos <= nb_burst_ );
- + DlBurst *b = new DlBurst (this);
- + if (pos==0 || nb_burst_==0)
- + b->insert_entry_head (&burst_list_);
- + else {
- + Burst *prev = burst_list_.lh_first ;
- + Burst *b2 = prev->next_entry();
- + int index = 1;
- + while (b2 && index < pos) {
- + prev=b2;
- + b2=b2->next_entry();
- + index++;
- + }
- + b->insert_entry (prev);
- + }
- + nb_burst_++;
- + return b;
- +}
- +
- +
- +/** Methods for class UlPhyPdu **/
- +
- +/**
- + * Create a phy pdu with the given preamble size
- + * @param preamble The preamble size in OFDM symbols
- + */
- +UlPhyPdu::UlPhyPdu (FrameMap *map, int preamble) : PhyPdu(map, preamble)
- +{
- +
- +}
- +
- +/**
- + * Add a burst in the PDU
- + * @param pos The position of the burst
- + */
- +Burst* UlPhyPdu::addBurst(int pos)
- +{
- + //UlPhyPdu only have one burst
- + assert (pos == 0 && nb_burst_==0 );
- + UlBurst *b = new UlBurst (this);
- + b->insert_entry_head (&burst_list_);
- + nb_burst_++;
- + return b;
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/phypdu.h ns-2.29/wimax/scheduling/phypdu.h
- --- ns-2.29-org/wimax/scheduling/phypdu.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/phypdu.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,175 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef PHYPDU_H
- +#define PHYPDU_H
- +
- +#include "burst.h"
- +#include "dlburst.h"
- +#include "ulburst.h"
- +
- +class FrameMap;
- +class PhyPdu;
- +LIST_HEAD (phyPdu, PhyPdu);
- +/**
- + * This class describte the content of a Phy PDU
- + */
- +class PhyPdu
- +{
- + public:
- + /**
- + * Create a phy pdu with the given preamble size
- + * @param preamble The preamble size in OFDM symbols
- + */
- + PhyPdu (FrameMap *map, int preamble);
- +
- + /**
- + * Delete the object
- + */
- + virtual ~PhyPdu ();
- +
- + /**
- + * Return the preamble size for the PDU in unit of OFDM symbols
- + * @return the preamble size for the PDU
- + */
- + int getPreamble( );
- +
- + /**
- + * Set the preamble size for the PDU in unit of OFDM symbols
- + * @param preamble the preamble size for the PDU
- + */
- + void setPreamble( int preamble );
- +
- + /**
- + * Create and return a burst in the PDU
- + * @param pos The position of the burst
- + * @return The burst created
- + */
- + virtual Burst * addBurst(int pos);
- +
- + /**
- + * Remove a burst in the PDU
- + * @param burst The burst to remove
- + */
- + void removeBurst(Burst *b);
- +
- + /**
- + * Return the burst located at the given index
- + * @param pos The position of the burst
- + */
- + Burst* getBurst(int pos);
- +
- + /**
- + * Return the number of burst in the PhyPDU
- + */
- + inline int getNbBurst () { return nb_burst_; }
- +
- + /**
- + * Return the FrameMap
- + */
- + inline FrameMap * getMap() { return map_; }
- +
- + // Chain element to the list
- + inline void insert_entry_head(struct phyPdu *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + // Chain element to the list
- + inline void insert_entry(PhyPdu *elem) {
- + LIST_INSERT_AFTER(elem, this, link);
- + }
- +
- + // Return next element in the chained list
- + PhyPdu* next_entry(void) const { return link.le_next; }
- +
- + // Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- + protected:
- + /*
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(PhyPdu) link;
- + //LIST_ENTRY(PhyPdu); //for magic draw
- +
- + /**
- + * Curent number of bursts
- + */
- + int nb_burst_;
- +
- + /**
- + * The list of burst contained in this PDU.
- + * For uplink Phy PDU, only one burst is allowed
- + */
- + struct burst burst_list_;
- +
- + private:
- + /**
- + * Size of the preamble in units of OFDM symbols
- + */
- + int preamble_;
- +
- + /**
- + * The frame map
- + */
- + FrameMap *map_;
- +
- +};
- +
- +/**
- + * Define subclass for downlink phy pdu
- + */
- +class DlPhyPdu: public PhyPdu
- +{
- + public:
- + /**
- + * Create a phy pdu with the given preamble size
- + * @param preamble The preamble size in OFDM symbols
- + */
- + DlPhyPdu (FrameMap *map, int preamble);
- +
- + /**
- + * Create and return a burst in the PDU
- + * @param pos The position of the burst
- + * @return The burst created
- + */
- + virtual Burst * addBurst(int pos);
- +};
- +
- +/**
- + * Define subclass for uplink phy pdu
- + */
- +class UlPhyPdu: public PhyPdu
- +{
- + public:
- + /**
- + * Create a phy pdu with the given preamble size
- + * @param preamble The preamble size in OFDM symbols
- + */
- + UlPhyPdu (FrameMap *map, int preamble);
- +
- + /**
- + * Create and return a burst in the PDU
- + * @param pos The position of the burst
- + * @return The burst created
- + */
- + virtual Burst * addBurst(int pos);
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/profile.cc ns-2.29/wimax/scheduling/profile.cc
- --- ns-2.29-org/wimax/scheduling/profile.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/profile.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,95 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "profile.h"
- +#include "subframe.h"
- +
- +/**
- + * Creates a profile with the given frequency and encoding
- + * @param f The frequency information for the profile
- + * @param enc The encoding type
- + */
- +Profile::Profile (SubFrame *subframe, int f, Ofdm_mod_rate enc) : iuc_(0)
- +{
- + assert (subframe);
- + subframe_ = subframe;
- + frequency_ = f;
- + encoding_ = enc;
- +}
- +
- +/**
- + * Return the encoding type
- + * @return the encoding type
- + */
- +Ofdm_mod_rate Profile::getEncoding( )
- +{
- + return encoding_;
- +}
- +
- +/**
- + * Set the encoding type
- + * @param enc the encoding type
- + */
- +void Profile::setEncoding( Ofdm_mod_rate enc )
- +{
- + if (encoding_ != enc)
- + subframe_->incrCCC();
- + encoding_ = enc;
- +}
- +
- +/**
- + * Return the frequency in unit of kHz
- + * @return the frequency
- + */
- +int Profile::getFrequency( )
- +{
- + return frequency_;
- +}
- +
- +/**
- + * Set the frequency in unit of kHz
- + * @param f the frequency
- + */
- +void Profile::setFrequency( int f )
- +{
- + if (frequency_ != f)
- + subframe_->incrCCC();
- + frequency_ = f;
- +}
- +
- +/**
- + * Return the frequency in unit of kHz
- + * @return the frequency
- + */
- +int Profile::getIUC( )
- +{
- + return iuc_;
- +}
- +
- +/**
- + * Set the IUC number for this profile
- + * @param iuc The IUC number for this profile
- + */
- +void Profile::setIUC( int iuc )
- +{
- + if (iuc_!=0 && iuc_!= iuc)
- + subframe_->incrCCC();
- + iuc_ = iuc;
- +}
- +
- +
- diff -Naur ns-2.29-org/wimax/scheduling/profile.h ns-2.29/wimax/scheduling/profile.h
- --- ns-2.29-org/wimax/scheduling/profile.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/profile.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,121 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef PROFILE_H
- +#define PROFILE_H
- +
- +#include "ofdmphy.h"
- +
- +class SubFrame;
- +
- +class Profile;
- +LIST_HEAD (profile, Profile);
- +
- +/**
- + * This class contains information about burst such as modulation, frequency...
- + */
- +class Profile
- +{
- + public:
- + /**
- + * Creates a profile with the given frequency and encoding
- + * @param f The frequency information for the profile
- + * @param enc The encoding type
- + */
- + Profile (SubFrame *subframe, int f, Ofdm_mod_rate enc);
- +
- + /**
- + * Set the IUC number for this profile
- + * @param iuc The IUC number for this profile
- + */
- + void setIUC( int iuc );
- +
- + /**
- + * Return the frequency in unit of kHz
- + * @return the frequency
- + */
- + int getIUC();
- +
- + /**
- + * Return the encoding type
- + * @return the encoding type
- + */
- + Ofdm_mod_rate getEncoding( );
- +
- + /**
- + * Return the frequency in unit of kHz
- + * @return the frequency
- + */
- + int getFrequency( );
- +
- + /**
- + * Set the encoding type
- + * @param enc the encoding type
- + */
- + void setEncoding( Ofdm_mod_rate enc );
- +
- + /**
- + * Set the frequency in unit of kHz
- + * @param f the frequency
- + */
- + void setFrequency( int f );
- +
- + // Chain element to the list
- + inline void insert_entry(struct profile *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + // Return next element in the chained list
- + Profile* next_entry(void) const { return link.le_next; }
- +
- + // Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- +
- + private:
- + /**
- + * The type of modulation used by the burst
- + */
- + Ofdm_mod_rate encoding_;
- +
- + /**
- + * The downlink frequency in kHz
- + */
- + int frequency_;
- +
- + /**
- + * The Interval Usage Code for the profile
- + */
- + int iuc_;
- +
- + /**
- + * The subframe containing this profile
- + * Used to inform configuration change
- + */
- + SubFrame *subframe_;
- +
- + /*
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(Profile) link;
- + //LIST_ENTRY(Profile); //for magic draw
- +
- +};
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/scanningstation.cc ns-2.29/wimax/scheduling/scanningstation.cc
- --- ns-2.29-org/wimax/scheduling/scanningstation.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/scanningstation.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,50 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "scanningstation.h"
- +
- +/**
- + * Create an data object with the given attributes
- + * @param nodeid The node
- + * @param duration The scanning duration
- + * @param start The frame at which the scanning start
- + * @param interleaving The interleaving interval
- + * @param iteration The number of iterations
- + */
- +ScanningStation::ScanningStation (int nodeid, int duration, int start, int interleaving, int iteration)
- +{
- + nodeid_ = nodeid;
- + duration_ = duration;
- + start_frame_ = start;
- + interleaving_ = interleaving;
- + iteration_ = iteration;
- +}
- +
- +/**
- + * Determines if the node is currently scanning
- + * @param frame The current frame
- + */
- +bool ScanningStation::isScanning (int frame)
- +{
- + //printf ("isScanning %d frame=%d, start_frame=%d, duration=%d, interleaving=%d iteration %dn", nodeid_, frame, start_frame_, duration_, interleaving_, iteration_);
- + if ((frame < start_frame_)||(frame > (start_frame_ + (duration_+interleaving_)*iteration_)))
- + return false;
- + else {
- + return (((frame-start_frame_)%(duration_+interleaving_))-duration_)<0;
- + }
- +}
- diff -Naur ns-2.29-org/wimax/scheduling/scanningstation.h ns-2.29/wimax/scheduling/scanningstation.h
- --- ns-2.29-org/wimax/scheduling/scanningstation.h 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/scanningstation.h 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,112 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#ifndef SCANNINGSTATION_H
- +#define SCANNINGSTATION_H
- +
- +#include "packet.h"
- +
- +class ScanningStation;
- +LIST_HEAD (scanningStation, ScanningStation);
- +
- +/**
- + * Contains information about a scanning station and
- + * helps to determine if it is in a scanning or interleaving
- + * time.
- + */
- +class ScanningStation
- +{
- + public:
- + /**
- + * Create an data object with the given attributes
- + * @param nodeid The node
- + * @param duration The scanning duration
- + * @param start The frame at which the scanning start
- + * @param interleaving The interleaving interval
- + * @param iteration The number of iterations
- + */
- + ScanningStation (int nodeid, int duration, int start, int interleaving, int iteration);
- +
- + /**
- + * Determines if the node is currently scanning
- + * @param frame The current frame
- + */
- + bool isScanning (int frame);
- +
- + /**
- + * Return the node id
- + */
- + int getNodeId () { return nodeid_; }
- +
- + // Chain element to the list
- + inline void insert_entry_head(struct scanningStation *head) {
- + LIST_INSERT_HEAD(head, this, link);
- + }
- +
- + // Chain element to the list
- + inline void insert_entry(ScanningStation *elem) {
- + LIST_INSERT_AFTER(elem, this, link);
- + }
- +
- + // Return next element in the chained list
- + ScanningStation* next_entry(void) const { return link.le_next; }
- +
- + // Remove the entry from the list
- + inline void remove_entry() {
- + LIST_REMOVE(this, link);
- + }
- +
- + protected:
- +
- + /**
- + * Pointer to next in the list
- + */
- + LIST_ENTRY(ScanningStation) link;
- + //LIST_ENTRY(ScanningStation); //for magic draw
- +
- +
- + private:
- + /**
- + * Duration of scanning allocation in frames
- + */
- + int duration_;
- +
- + /**
- + * Start frame (absolute)
- + */
- + int start_frame_;
- +
- + /**
- + * interleaving in frames
- + */
- + int interleaving_;
- +
- + /**
- + * number of iterations
- + */
- + int iteration_;
- +
- + /**
- + * The node that is scanning
- + */
- + int nodeid_;
- +};
- +
- +
- +
- +#endif
- diff -Naur ns-2.29-org/wimax/scheduling/ssscheduler.cc ns-2.29/wimax/scheduling/ssscheduler.cc
- --- ns-2.29-org/wimax/scheduling/ssscheduler.cc 1969-12-31 19:00:00.000000000 -0500
- +++ ns-2.29/wimax/scheduling/ssscheduler.cc 2006-09-22 17:27:47.000000000 -0400
- @@ -0,0 +1,1436 @@
- +/* This software was developed at the National Institute of Standards and
- + * Technology by employees of the Federal Government in the course of
- + * their official duties. Pursuant to title 17 Section 105 of the United
- + * States Code this software is not subject to copyright protection and
- + * is in the public domain.
- + * NIST assumes no responsibility whatsoever for its use by other parties,
- + * and makes no guarantees, expressed or implied, about its quality,
- + * reliability, or any other characteristic.
- + * <BR>
- + * We would appreciate acknowledgement if the software is used.
- + * <BR>
- + * NIST ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
- + * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
- + * FROM THE USE OF THIS SOFTWARE.
- + * </PRE></P>
- + * @author rouil
- + */
- +
- +#include "ssscheduler.h"
- +#include "burst.h"
- +
- +/**
- + * Tcl hook for creating SS scheduler
- + */
- +static class SSschedulerClass : public TclClass {
- +public:
- + SSschedulerClass() : TclClass("WimaxScheduler/SS") {}
- + TclObject* create(int, const char*const*) {
- + return (new SSscheduler());
- +
- + }
- +} class_ssscheduler;
- +
- +/*
- + * Create a scheduler
- + */
- +SSscheduler::SSscheduler (): t1timer_(0),t2timer_(0),t6timer_(0), t12timer_(0),
- + t21timer_(0), lostDLMAPtimer_(0), lostULMAPtimer_(0),
- + t44timer_(0), scan_info_(0)
- +{
- + debug2 ("SSscheduler createdn");
- +}
- +
- +/**
- + * Initializes the scheduler
- + */
- +void SSscheduler::init ()
- +{
- + WimaxScheduler::init();
- +
- + //At initialization, the SS is looking for synchronization
- + mac_->setMacState (MAC802_16_WAIT_DL_SYNCH);
- + mac_->getPhy()->setMode (OFDM_RECV);
- + //start timer for expiration
- + t21timer_ = new WimaxT21Timer (mac_);
- + t21timer_->start (mac_->macmib_.t21_timeout);
- +
- + //creates other timers
- + t1timer_ = new WimaxT1Timer (mac_);
- + t12timer_ = new WimaxT12Timer (mac_);
- + t2timer_ = new WimaxT2Timer (mac_);
- + lostDLMAPtimer_ = new WimaxLostDLMAPTimer (mac_);
- + lostULMAPtimer_ = new WimaxLostULMAPTimer (mac_);
- +
- + nb_scan_req_ = 0;
- +
- + scan_info_ = (struct scanning_structure *) malloc (sizeof (struct scanning_structure));
- + memset (scan_info_, 0, sizeof (struct scanning_structure));
- + scan_info_->nbr = NULL;
- + scan_info_->substate = NORMAL;
- +}
- +
- +/**
- + * Interface with the TCL script
- + * @param argc The number of parameter
- + * @param argv The list of parameters
- + */
- +int SSscheduler::command(int argc, const char*const* argv)
- +{
- + if (argc == 2) {
- + if (strcmp(argv[1], "send-scan") == 0) {
- + send_scan_request();
- + return TCL_OK;
- + }
- + }
- +
- + return TCL_ERROR;
- +}
- +
- +/**
- + * Start a new frame
- + */
- +void SSscheduler::start_dlsubframe ()
- +{
- + //mac_->debug ("At %f in Mac %d SS scheduler dlsubframe expires %dn", NOW, mac_->addr(), scan_info_->substate);
- +
- + mac_->frame_number_++;
- +
- + switch (scan_info_->substate) {
- + case SCAN_PENDING:
- + if (scan_info_->count == 0) {
- + resume_scanning();
- + return;
- + }
- + scan_info_->count--;
- + break;
- + case HANDOVER_PENDING:
- + if (scan_info_->handoff_timeout == 0) {
- + assert (scan_info_->nbr);
- +#ifdef USE_802_21
- + mac_->debug ("At %f in Mac %d link handoff proceedingn", NOW, mac_->addr());
- + mac_->send_link_handoff_proceeding (mac_->addr(), mac_->getPeerNode_head()->getPeerNode(), scan_info_->nbr->getID());
- +#endif
- + scan_info_->substate = HANDOVER;
- + //restore previous state
- + //mac_->restore_state (scan_info_->nbr->getState()->state_info);
- + mac_->setChannel (scan_info_->nbr->getState()->state_info->channel);
- + lost_synch ();
- + //add target as peer
- + mac_->addPeerNode (new PeerNode(scan_info_->nbr->getID()));
- + return;
- + }
- + scan_info_->handoff_timeout--;
- + break;
- + default:
- + break;
- + }
- +
- + //change state of PHY
- + //mac_->getPhy()->setMode (OFDM_RECV);
- +
- + //this is the begining of new frame
- + map_->setStarttime (NOW);
- +
- + //start handler of dlsubframe
- + map_->getDlSubframe()->getTimer()->sched (0);
- +
- + //reschedule for next frame
- + dl_timer_->resched (mac_->getFrameDuration());
- +}
- +
- +/**
- + * Start a new frame
- + */
- +void SSscheduler::start_ulsubframe ()
- +{
- + //mac_->debug ("At %f in Mac %d SS scheduler ulsubframe expiresn", NOW, mac_->addr());
- +
- + //change state of PHY: even though it should have been done before
- + //there are some cases where it does not (during scanning)
- + mac_->getPhy()->setMode (OFDM_SEND);
- +
- + //1-Transfert the packets from the queues in Connections to burst queues
- + Burst *b;
- + OFDMPhy *phy = mac_->getPhy();
- + //printf ("SS has %d ul burstsn", map_->getUlSubframe()->getNbPdu ());
- +
- + PeerNode *peer = mac_->getPeerNode_head(); //this is the BS
- + assert (peer!=NULL);
- +
- + for (int index = 0 ; index < map_->getUlSubframe()->getNbPdu (); index++) {
- + b = map_->getUlSubframe()->getPhyPdu (index)->getBurst (0);
- +
- + if (b->getIUC()==UIUC_END_OF_MAP) {
- + //consistency check..
- + assert (index == map_->getUlSubframe()->getNbPdu ()-1);
- + break;
- + }
- +
- + if (b->getIUC()==UIUC_INITIAL_RANGING || b->getIUC()==UIUC_REQ_REGION_FULL)
- + continue;
- + int duration = 0;
- + //get the packets from the connection with the same CID
- + //printf ("tBurst CID=%dn", b->getCid());
- + Connection *c=mac_->getCManager ()->get_connection (b->getCid(), true);
- + //assert (c);
- + if (!c)
- + continue; //I do not have this CID. Must be for another node
- + //transfert the packets until it reaches burst duration or no more packets
- + assert (c->getType()==CONN_PRIMARY);
- + if (peer->getBasic()!= NULL)
- + duration = transfer_packets (peer->getBasic(), b, duration);
- + if (peer->getPrimary()!= NULL)
- + duration = transfer_packets (peer->getPrimary(), b, duration);
- + if (peer->getSecondary()!= NULL)
- + duration = transfer_packets (peer->getSecondary(), b, duration);
- + if (peer->getOutData()!=NULL)
- + duration = transfer_packets (peer->getOutData(), b, duration);
- + }
- +
- + //2-compute size of data left to create bandwidth requests
- + if (peer->getBasic()!= NULL)
- + create_request (peer->getBasic());
- + if (peer->getPrimary()!= NULL)
- + create_request (peer->getPrimary());
- + if (peer->getSecondary()!= NULL)
- + create_request (peer->getSecondary());
- + if (peer->getOutData()!=NULL)
- + create_request (peer->getOutData());
- +
- + //start handler for ulsubframe
- + b = map_->getUlSubframe()->getPhyPdu (0)->getBurst (0);
- + map_->getUlSubframe()->getTimer()->sched (b->getStarttime()*phy->getSymbolTime());
- +
- + //reschedule for next frame
- + ul_timer_->resched (mac_->getFrameDuration());
- +}
- +
- +/**
- + * Create a request for the given connection
- + * @param con The connection to check
- + */
- +void SSscheduler::create_request (Connection *con)
- +{
- + if (con->queueLength()==0)
- + return; //queue is empty
- + else if (map_->getUlSubframe()->getBw_req()->getRequest (con->get_cid())!=NULL) {
- + debug2 ("At %f in Mac %d already pending requests for cid=%dn", NOW, mac_->addr(), con->get_cid());
- + return; //there is already a pending request
- + }
- +
- + Packet *p= mac_->getPacket();
- + hdr_cmn* ch = HDR_CMN(p);
- + bw_req_header_t *header = (bw_req_header_t *)&(HDR_MAC802_16(p)->header);
- + header->ht=1;
- + header->ec=1;
- + header->type = 0; //incremental..to check meaning
- + header->br = con->queueByteLength();
- + header->cid = con->get_cid();
- +
- + double txtime = mac_->getPhy()->getTrxTime (ch->size(), map_->getUlSubframe()->getProfile (UIUC_REQ_REGION_FULL)->getEncoding());
- + ch->txtime() = txtime;
- + map_->getUlSubframe()->getBw_req()->addRequest (p, con->get_cid(), con->queueByteLength());
- + debug2 ("SSscheduler enqueued request for cid=%d len=%dn", con->get_cid(), con->queueByteLength());
- + //start timeout for request
- +}
- +
- +/**
- + * Process a packet received by the Mac. Only scheduling related packets should be sent here (BW request, UL_MAP...)
- + * @param p The packet to process
- + */
- +void SSscheduler::process (Packet * p)
- +{
- + assert (mac_ && HDR_CMN(p)->ptype()==PT_MAC);
- + debug2 ("SSScheduler received packet to processn");
- +
- + hdr_mac802_16 *wimaxHdr = HDR_MAC802_16(p);
- + gen_mac_header_t header = wimaxHdr->header;
- +
- + //we cast to this frame because all management frame start with
- + //a type
- + mac802_16_dl_map_frame *frame = (mac802_16_dl_map_frame*) p->accessdata();
- +
- + switch (frame->type) {
- + case MAC_DL_MAP:
- + map_->setStarttime (NOW-HDR_CMN(p)->txtime());
- + //printf ("At %f frame start at %fn", NOW, map_->getStarttime());
- + process_dl_map (frame);
- + break;
- + case MAC_DCD:
- + process_dcd ((mac802_16_dcd_frame*)frame);
- + break;
- + case MAC_UL_MAP:
- + process_ul_map ((mac802_16_ul_map_frame*)frame);
- + break;
- + case MAC_UCD:
- + process_ucd ((mac802_16_ucd_frame*)frame);
- + break;
- + case MAC_RNG_RSP:
- + process_ranging_rsp ((mac802_16_rng_rsp_frame*) frame);
- + break;
- + case MAC_REG_RSP:
- + process_reg_rsp ((mac802_16_reg_rsp_frame*) frame);
- + break;
- + case MAC_MOB_SCN_RSP:
- + process_scan_rsp ((mac802_16_mob_scn_rsp_frame *) frame);
- + break;
- + case MAC_MOB_BSHO_RSP:
- + process_bsho_rsp ((mac802_16_mob_bsho_rsp_frame *) frame);
- + break;
- + case MAC_MOB_NBR_ADV:
- + process_nbr_adv ((mac802_16_mob_nbr_adv_frame *) frame);
- + break;
- + default:
- + mac_->debug ("unknown packet in SS %dn", mac_->addr());
- + //exit (0);
- + }
- + Packet::free (p);
- +}
- +
- +/**
- + * Return the type of STA this scheduler is good for
- + * @return STA_SS
- + */
- +station_type_t SSscheduler::getNodeType ()
- +{
- + return STA_MN;
- +}
- +
- +/**
- + * Called when lost synchronization
- + */
- +void SSscheduler::lost_synch ()
- +{
- + //reset timers
- + if (t1timer_->busy()!=0)
- + t1timer_->stop();
- + if (t12timer_->busy()!=0)
- + t12timer_->stop();
- + if (t21timer_->busy()!=0)
- + t21timer_->stop();
- + if (lostDLMAPtimer_->busy()!=0)
- + lostDLMAPtimer_->stop();
- + if (lostULMAPtimer_->busy()!=0)
- + lostULMAPtimer_->stop();
- + if (t2timer_->busy()!=0)
- + t2timer_->stop();
- + if (t44timer_ && t44timer_->busy()!=0)
- + t44timer_->stop();
- + //we need to go to receiving mode
- + //printf ("Set phy to recv %xn", mac_->getPhy());
- + mac_->getPhy()->setMode (OFDM_RECV);
- + if (mac_->getMacState()==MAC802_16_CONNECTED) {
- + //remove possible pending requests
- + map_->getUlSubframe()->getBw_req()->removeRequests();
- +
- +#ifdef USE_802_21
- + mac_->debug ("At %f in Mac %d, send link downn", NOW, mac_->addr());
- + mac_->send_link_down (mac_->addr(), RC_FAIL_NORESOURCE);
- +#endif
- + }
- +
- + //remove information about peer node
- + if (mac_->getPeerNode_head())
- + mac_->removePeerNode (mac_->getPeerNode_head());
- +
- + //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();