⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mac-802_16-ss.cc

📁 OPNET 中的Wimax模块, 主要用于wimax 无线网络仿真,以及普通无线网络仿真.
💻 CC
📖 第 1 页 / 共 5 页
字号:
        printf("SS%dup(flow-id: %d) %lf %f %d \n",	       ss_id,UpFlowTable[tbindex].upstream_record.flow_id,	       Scheduler::instance().clock(), 	       total_num_sent_bytes,	       ch->size());      //#endif //---------------------------------------------------------------            /* Start a timer that expires when the packet transmission is complete. //$A5#ifdef US_RATE_CONTROL      if (UpFlowTable[tbindex].ratecontrol == 1)        USRateMeasure(tbindex,q);#endif      mhTxPkt_.start(q->copy(), stime);      downtarget_->recv(q, this);              break;*/          case BEST_EFFORT:      /* Check whether concatenation is required */      if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,CONCAT_ENABLE_BIT)) && 	  (!bit_on(UpFlowTable[tbindex].upstream_record.flag,CONCAT_ON_BIT)) && 	  (!bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT)) && 	  (bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ENABLE_BIT)))	{	  concat_req = check_concat_req(tbindex);	}      else if (bit_on(UpFlowTable[tbindex].upstream_record.flag,CONCAT_ON_BIT))	{	  concat_req = 1;	}      if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):sendData: sending a packet at %lf  \n",	       ss_id,UpFlowTable[tbindex].upstream_record.flow_id,	       Scheduler::instance().clock());            if (concat_req) {#ifdef PACKET_TRACE        packetTrace(q,1);#endif	send_concat(q,tbindex);      }      else {#ifdef PACKET_TRACE        packetTrace(q,1);#endif	decide_frag(q,tbindex);      }      break;    }    /* Update the statistics variable..*/  double curr_time = Scheduler::instance().clock();    if (curr_time - UpFlowTable[tbindex].last_mfrtime >= 1.0)    {      UpFlowTable[tbindex].last_mfrtime = curr_time;      //UpFlowTable[tbindex].avg_pkts = (UpFlowTable[tbindex].avg_pkts + UpFlowTable[tbindex].num_pkts )/ 2;      //UpFlowTable[tbindex].avg_bytes = (UpFlowTable[tbindex].avg_bytes + UpFlowTable[tbindex].num_bytes )/ 2;      //UpFlowTable[tbindex].num_pkts = 0;      //UpFlowTable[tbindex].num_bytes = 0;          }     return;}//$A5/************************************************************************* * routine: int Mac802_16SS::SendReq(char tbindex, Packet* p) * * explanation: *   This is called when the SS wants to send a request to the BS *   It is invoked off the REQ_TIMER thread. *   The routine  check_concat_req(tbindex) is called to see if *   we can send a concat request.   *   The routine also calls beffort_ratecheck to see if it *   is even allowed to request bandwidth yet (subject to *   rate control). * *  We init len to the number of packets in the queue (if any) *       int len = len_queue(UpFlowTable[tbindex].packet_list); *   But we need to make sure that len is not more than the max number *   allowed in a concat frame (remember the max_concat_threshold *   has been internally converted to represent the max number of *   packets that can be inserted minus 1...) *     if ((len > 0) && (len > UpFlowTable[tbindex].max_concat_threshhold)) *       len = UpFlowTable[tbindex].max_concat_threshhold; * *   We also need to make sure len is not higher than not_requested_pkts.  *   This variable represent how many packets in the queue we has  *   not requested bandwidth for, yet.    *    * inputs * char tbindex: * Packet *p: This is the current packet that we want to send. * NOte that we might add additional packets to it. * * outputs *   Returns a  0 if an error occurs and the request is not sent, *   else a 1. * *************************************************************************//*!   This is called when the SS wants to send a request to the BS  It is invoked off the REQ_TIMER thread.  The routine  check_concat_req(tbindex) is called to see if  we can send a concat request.    The routine also calls beffort_ratecheck to see if it  is even allowed to request bandwidth yet (subject to  rate control).  \param p  This is the current packet that we want to send.  \return A 0 if an error occurs and the request is not sent,  else a 1.*/int Mac802_16SS::SendReq(char tbindex, Packet* p){  struct hdr_cmn* ch = HDR_CMN(p);  Packet* n = Packet::alloc();  hdr_cmn* chn = HDR_CMN(n);  hdr_mac802_16* dh = HDR_MAC802_16(n);  int concat_req = 0;  u_int32_t req_size;  Packet* r;  int num,i;//$A7//  u_char slots;//$A23//  u_int32_t slots;  u_int32_t phy_overhead = 0;  double stime;  int    len = len_queue(UpFlowTable[tbindex].packet_list);  dh->dshdr_.fc_parm = 2; //defining packet type = request  chn->uid() = 0;   //$A4  //chn->ptype() = PT_MAC;  chn->ptype() = PT_MAC802_16REQ;    chn->iface() = -2;    if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):SendReq:(%lf)Entered with a packet of size: %d\n",	   ss_id,	   UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	   ch->size());    if (bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT))    req_size = UpFlowTable[tbindex].frag_data;  else    req_size = ch->size();    req_size += upchannel.overhead_bytes;  if (bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT) && !concat_req)    req_size += 3; /* For piggybacked request */    /*check if we can make a request for concatenated packets*/    concat_req = check_concat_req(tbindex);  if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):SendReq:(%lf)concat_req flag: %d\n",	   ss_id,	   UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	   concat_req);    //TESTE  //printf("SendReq: len = %d not_requested = %d\n",len,UpFlowTable[tbindex].not_requested_pkts);     /* What about the MAC header 6 byte overhead for the case of no concat  ???? */  if (!(bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT)) &&(concat_req))    {      if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):SendReq:(%lf) Decided to send a Concatenated req (req_size:%d) \n",	       ss_id,	       UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	       req_size);      /* Add  6 bytes for Concat frame header */      req_size += 6;            /*$A18	len = len_queue(UpFlowTable[tbindex].packet_list);	Request bw just for the packets in queue we have not requested yet */      /*$A25 - besides checking len, we must check if is time to send an aggregate request      if (len > UpFlowTable[tbindex].not_requested_pkts)      len = UpFlowTable[tbindex].not_requested_pkts;*/        if (UpFlowTable[tbindex].req_counter > UpFlowTable[tbindex].aggreqinterval)	{	  /*It is time to send an aggregate request*/	  dh->dshdr_.fc_parm = 4; //defining packet type = aggregate request	  UpFlowTable[tbindex].req_counter = 0; 	  printf("SendReq: send aggregate req\n");	}      else 	{	  /*Send incremental request*/	  if (len > UpFlowTable[tbindex].not_requested_pkts)	    /*request bw only for the packets it was not requested yet*/	    len = UpFlowTable[tbindex].not_requested_pkts; 	  UpFlowTable[tbindex].req_counter++;	  dh->dshdr_.fc_parm = 2; //defining packet type = incremental request	}            if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):SendReq:(%lf) Requesting to carry %d packets (limit:%d)\n",	       ss_id, UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	       len+1, UpFlowTable[tbindex].max_concat_threshhold);            if ((len > 0) && (len > UpFlowTable[tbindex].max_concat_threshhold))	len = UpFlowTable[tbindex].max_concat_threshhold;            //By this point, len represents the number of packets to go in a concatonate frame.            if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):SendReq:(%lf) Actual request to carry %d packets (limit:%d,qlen=%d)\n",	       ss_id, UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	       len+1, UpFlowTable[tbindex].max_concat_threshhold,len_queue(UpFlowTable[tbindex].packet_list));         for (i = 0; i <= (len-1); i++)	{	  r = pkt_lookup(tbindex,i);	  	  if (r == 0)	    {	      printf("SS%d(flow-id %d) :Mac802_16SS:SendReq error, pkt_lookup returned NULL, exiting\n",		     ss_id,		     UpFlowTable[tbindex].upstream_record.flow_id);	      exit(1);	    }	  struct hdr_cmn* chr = HDR_CMN(r);	  	  req_size += chr->size(); 	  //$A7	  /*	  slots = (int) req_size / bytes_pminislot;	  if ((req_size % bytes_pminislot) != 0)	    slots += 1;	  */	  //$A23	  //slots = (int) ceil((double)req_size/(double)bytes_pminislot);	  //255 is max but req_size is data only....	  //	  if (slots > 240)	  //$A23 if (slots > 65521)	  if (req_size > 65521)	    {	      req_size -= chr->size();    	      	      if (UpFlowTable[tbindex].debug)		printf("SS%d(Flow-id %d):SendReq:(%lf)Can't add any more packets.... size: %d, req_size:%d bytes\n",		       ss_id, UpFlowTable[tbindex].upstream_record.flow_id,		       Scheduler::instance().clock(), chr->size(), req_size);	      UpFlowTable[tbindex].not_requested_pkts -= (i+1);	      break;	    }	  	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(Flow-id %d):SendReq:(%lf)Add frame to concat request of size: %d, req_size:%d bytes\n",		   ss_id, UpFlowTable[tbindex].upstream_record.flow_id,		   Scheduler::instance().clock(), chr->size(), req_size);	}      set_bit(&UpFlowTable[tbindex].upstream_record.flag, CONCAT_ON_BIT,ON);      //$A18      UpFlowTable[tbindex].not_requested_pkts = 0;    }	  else {    //$A18 - if not concatenated, then it will be requested BW for just one packet    if (UpFlowTable[tbindex].not_requested_pkts > 0)      UpFlowTable[tbindex].not_requested_pkts -= 1;  }  //Note: the request may or may not be concatonated here ...  //The BS actually does not see or care if the request   //is concatonated or not....  /*  slots = (int) req_size / bytes_pminislot;   if ((req_size % bytes_pminislot) != 0)  slots += 1;*/  /*$A23  //slots = (u_int32_t) ceil((double)req_size/(double)bytes_pminislot);  //assert(slots>0);*/  assert(req_size>0);    //What if slots > 255 ?   //This is illegal...   //  if (slots > 255) {  /*$A23  if (slots > 65536) {    printf("\nSendReq:  ERROR:  requesting slots > 65536 (%d)\n",slots);    exit(0);    }*/     if (req_size > 65536) {    printf("\nSendReq:  ERROR:  requesting bytes > 65536 (%d)\n",req_size);    exit(0);    } //TESTE  printf("SendReq: requisicao para req_size = %d bytes\n",req_size);  dh->dshdr_.fc_type = 3;  dh->dshdr_.ehdr_on = 0;  printf("\nSendReq: requesting %d bytes\n",req_size);  //$A7  //dh->dshdr_.mac_param = (u_char) slots;  //$A21  //dh->dshdr_.mac_param = (u_int16_t) slots;  //$A23  dh->dshdr_.mac_param = (u_int16_t) req_size;  dh->dshdr_.len = UpFlowTable[tbindex].upstream_record.flow_id;  chn->size() = MAC802_16_HDR_LEN;  chn->size() += upchannel.overhead_bytes;  //$A5#ifdef US_RATE_CONTROL  if (UpFlowTable[tbindex].ratecontrol == 1)    {      int ratecheck_returnval = 0;      ratecheck_returnval = beffort_ratecheck(tbindex, REQ_TIMER, n);            if(ratecheck_returnval != 1 && ratecheck_returnval != -1) {	printf("Error in beffort_ratecheck_returnval contention %d\n",ratecheck_returnval);		exit(0);      }      if(ratecheck_returnval == -1) {	if (UpFlowTable[tbindex].debug)	  printf("SS%d(flow-id %d):SendReq:(%lf) Insufficient tokens for this bw request- delete req pkt\n",		 ss_id, UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock());	Packet::free(n);	return 0;      }    }#endif      if (UpFlowTable[tbindex].debug)    printf("SS%d(Flow-id %d):SendReq:(%lf)Sending req for %d bytes (%d slots)\n",	   ss_id,	   UpFlowTable[tbindex].upstream_record.flow_id,	   Scheduler::instance().clock(),	   req_size,dh->dshdr_.mac_param);      /* STATISTICS */  UpFlowTable[tbindex].req_time = Scheduler::instance().clock();  UpFlowTable[tbindex].num_pkts++ ;  UpFlowTable[tbindex].num_bytes += chn->size();  total_num_sent_pkts++;  total_num_sent_bytes += chn->size();   total_num_BW_bytesUP += chn->size();   UpFlowTable[tbindex].total_creq++;    //#ifdef TRACE_SS_UP_DATA //---------------------------------------------------------  if (debug_ss)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -