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

📄 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,	   chn->size());  //#endif //--------------------------------------------------------------------------  #ifdef PACKET_TRACE  packetTrace(n,1);#endif    stime = TX_Time(n,UPSTREAM);  SET_TX_STATE(MAC_SEND);    if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):SendReq:(%lf) Request Mesage: total frame  size(bytes): %d, txTime:%lf\n",	   ss_id, UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	   chn->size(), stime);      /* Start a timer that expires when the packet transmission is complete. */  mhTxPkt_.start(n->copy(), stime);  downtarget_->recv(n, this);            #ifdef TIMINGS  //	printf("3 %lf %d %d 1\n",Scheduler::instance().clock(),  //			UpFlowTable[tbindex].upstream_record.flow_id,ss_id);   timingsTrace(p,3);#endif    return 1;}  /************************************************************************** function: int Mac802_16SS::check_concat_req(char tbindex)** inputs:  *  char tbindex : ** outputs:*  int : returns a 1 if there is at least one packet waiting in the queue*        AND concat is enabled.**************************************************************************//*! returns a 1 if there is at least one packet waiting in the queue  AND concat is enabled. */int Mac802_16SS::check_concat_req(char tbindex){int len = len_queue(UpFlowTable[tbindex].packet_list);  if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):check_concat_req:(%lf) len_queue: %d, max_thresh: %d, concat enable bit: %d \n",	   ss_id, UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock(),	   len,UpFlowTable[tbindex].max_concat_threshhold,	   bit_on(UpFlowTable[tbindex].upstream_record.flag,CONCAT_ENABLE_BIT));  //$A6//  if (((len_queue(tbindex)) >= UpFlowTable[tbindex].max_concat_threshhold) && //      (bit_on(UpFlowTable[tbindex].upstream_record.flag,CONCAT_ENABLE_BIT)))    if ((len > 0) &&       (bit_on(UpFlowTable[tbindex].upstream_record.flag,CONCAT_ENABLE_BIT)))      {      return 1;    }  else   {    return 0;  }}/**************************************************************************************************************************************************/int Mac802_16SS::check_frag_req(u_int32_t size,char tbindex){  if ( size + upchannel.overhead_bytes > UpFlowTable[tbindex].curr_gsize)    return 1;  else     return 0;}/*************************************************************************  * function: void Mac802_16SS::decide_frag(Packet* p,char tbindex)  *  * explanation:  This routine is called at the slot time that has been  *   allocated as the beginning transmission time for this packet.  *     * LOGIC:  *    -First see if this packet is a portion of a fragmented frame  *     that is being sent.  *    -Else, see if this packet needs to be sent as a fragment  *    -Else, see this packet needs a piggyback request   *  * inputs  *   Packet *p:  frame (not concatonated)  *   char tbindex:  index to US flow table  *  * outputs:  *   none  **************************************************************************//*! This routine is called at the slot time that has been  allocated as the beginning transmission time for this packet.   \param p frame (not concatonated)  \param tbindex index to US flow table*/void Mac802_16SS::decide_frag(Packet* p,char tbindex){    struct hdr_cmn* ch = HDR_CMN(p);  int frag_req = 0;  double stime;    if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ENABLE_BIT)) &&       (bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT)))    {      /* TODO:  increment statistics for this case */      if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):decide_frag:Decided to send fragment  of size %d \n",	       ss_id, UpFlowTable[tbindex].upstream_record.flow_id, ch->size());            send_frag_data(p,tbindex);	    }  else if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ENABLE_BIT)) && 	   (!bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT)))    {      /* TODO:  increment statistics for this case */      frag_req = check_frag_req(ch->size(),tbindex);            if (frag_req)	{	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(flow-id %d):decide_frag:Decided to fragment pkt of size %d \n",		   ss_id, UpFlowTable[tbindex].upstream_record.flow_id, ch->size());	  /* TODO:  increment statistics for this case */	  send_frag_data(p,tbindex);	}      else	{	  /*  Frag is enabled but not on, Can send piggyback req */	  if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT)) && 	      (!bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT)))	    {	      FillPiggyReq(tbindex,p);	    }	  else if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT)) && 		   (bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT)))	    {	      if (UpFlowTable[tbindex].debug)		printf("SS%d(flow-id %d): No Piggyback req is sent on a Concatenated frame\n",		       ss_id,		       UpFlowTable[tbindex].upstream_record.flow_id);	      /* Set the bit to indicate that no piggyback req was sent  */	      	      set_bit(&UpFlowTable[tbindex].upstream_record.flag, PIGGY_NOT_SEND,ON);	      set_bit(&UpFlowTable[tbindex].upstream_record.flag, NO_PIGGY_BIT,OFF);	      	    }	  else if (bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT))	    {	      if (UpFlowTable[tbindex].debug)		{		  if  (bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT))		    printf("SS%d(flow-id %d): No Piggyback req is sent on a Concatenated frame\n",			   ss_id, UpFlowTable[tbindex].upstream_record.flow_id);		}	      set_bit(&UpFlowTable[tbindex].upstream_record.flag, NO_PIGGY_BIT,OFF);	      	    }	  	  ch->size() += upchannel.overhead_bytes;	  stime = TX_Time(p,UPSTREAM);	  SET_TX_STATE(MAC_SEND);	  	  /* STATISTICS */	  UpFlowTable[tbindex].num_pkts++ ;	  UpFlowTable[tbindex].num_bytes += ch->size();	  total_num_sent_pkts++;	  total_num_sent_bytes += ch->size(); 	  total_num_BW_bytesUP += ch->size(); 	  //#ifdef TRACE_SS_UP_DATA  //--------------------------------------------------	  if (debug_ss)	    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 //--------------------------------------------------------------------	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(flow-id %d):decide_frag: send frame (size:%d) WITHOUT fragmentation (but frag allowed) at %lf \n",		   ss_id, UpFlowTable[tbindex].upstream_record.flow_id, 		   ch->size(), Scheduler::instance().clock());	  	  /* Start a timer that expires when the packet transmission is complete. *///$A5#ifdef US_RATE_CONTROL          if (UpFlowTable[tbindex].ratecontrol == 1)            USRateMeasure(tbindex,p);#endif	  mhTxPkt_.start(p->copy(), stime);	  downtarget_->recv(p, this);        	}    }  else if ((!bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ENABLE_BIT)) && 	   (!bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT)))    {      /*  	  Ok No fragmentation needs to be done	  Check whether piggybacking is enabled 	  and can it be done      */      if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT)) && 	  (!bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT)))	{	  FillPiggyReq(tbindex,p);	}      else if ((bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT)) && 	       (bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT)))	{	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(flow-id %d): No Piggyback req is sent on a Concatenated frame\n",		   ss_id, UpFlowTable[tbindex].upstream_record.flow_id);	  	  /* Set the bit to indicate that no piggyback req was sent */	  set_bit(&UpFlowTable[tbindex].upstream_record.flag, PIGGY_NOT_SEND,ON);	  set_bit(&UpFlowTable[tbindex].upstream_record.flag, NO_PIGGY_BIT,OFF);	  	}      else if (bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT))	{	  if (UpFlowTable[tbindex].debug)	    {	      if  (bit_on(UpFlowTable[tbindex].upstream_record.flag,PIGGY_ENABLE_BIT))		printf("SS%d(flow-id %d): No Piggyback req is sent on a Concatenated frame\n",		       ss_id, UpFlowTable[tbindex].upstream_record.flow_id);	    }	  set_bit(&UpFlowTable[tbindex].upstream_record.flag, NO_PIGGY_BIT,OFF);	}            ch->size() += upchannel.overhead_bytes;      stime = TX_Time(p,UPSTREAM);      SET_TX_STATE(MAC_SEND);            /* STATISTICS */      UpFlowTable[tbindex].num_pkts++ ;      UpFlowTable[tbindex].num_bytes += ch->size();      total_num_sent_pkts++;      total_num_sent_bytes += ch->size();       total_num_BW_bytesUP += ch->size();       //#ifdef TRACE_SS_UP_DATA  //-----------------------------------------------            if (debug_ss)        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 //-----------------------------------------------------------------      if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d):decide_frag: send frame (size:%d) WITHOUT fragmentation at %lf \n",	       ss_id,	       UpFlowTable[tbindex].upstream_record.flow_id, 	       ch->size(),	       Scheduler::instance().clock());            /* Start a timer that expires when the packet transmission is complete. *///$A5#ifdef US_RATE_CONTROL      if (UpFlowTable[tbindex].ratecontrol == 1)        USRateMeasure(tbindex,p);#endif      mhTxPkt_.start(p->copy(), stime);      downtarget_->recv(p, this);            }    return;}/************************************************************************* * routine:  void Mac802_16SS::send_frag_data(Packet* p, char tbindex) * * explanation: This routine is called when the packet p is a part of a frag *  or must be sent as a frag.  *  The 2 key state params: *	       UpFlowTable[tbindex].curr_gsize //the #bytes in current grant *	       UpFlowTable[tbindex].frag_data) //the # bytes left in the frag *  Each call to this routine will send curr_gsize of the total data left (frag_data) * * inputs:    *   Packet *p:  frame (not concatonated) *   char tbindex:  index to US flow table * * outputs: *  * *************************************************************************//*! This routine is called when the packet p is a part of a frag  or must be sent as a frag.   \param p frame (not concatonated)  \param tbindex index to US flow table */void Mac802_16SS::send_frag_data(Packet* p, char tbindex){  double stime;    if (UpFlowTable[tbindex].debug)    printf("SS%d(flow-id %d):send_frag_data:: Entered ...\n",	   ss_id, UpFlowTable[tbindex].upstream_record.flow_id);    /* Sending a packet. Turn-off NO_PIGGY_BIT in case it was turned on */  if (bit_on(UpFlowTable[tbindex].upstream_record.flag,NO_PIGGY_BIT))    {      set_bit(&UpFlowTable[tbindex].upstream_record.flag, NO_PIGGY_BIT,OFF);          }    //This is set if we are in the middle of sending a fragment  if (bit_on(UpFlowTable[tbindex].upstream_record.flag,FRAG_ON_BIT))    {      Packet* q= UpFlowTable[tbindex].frag_pkt->copy();            struct hdr_mac802_16extd* eh = HDR_MAC802_16EXTD(q);      eh->num_hdr = 0;            if (UpFlowTable[tbindex].debug)	printf("SS%d(flow-id %d)Curr grant size = %d, frag_data = %d\n",	       ss_id,	       UpFlowTable[tbindex].upstream_record.flow_id,	       UpFlowTable[tbindex].curr_gsize,	       UpFlowTable[tbindex].frag_data);            if (UpFlowTable[tbindex].curr_gsize < (UpFlowTable[tbindex].frag_data + upchannel.overhead_bytes + 16))	{	  struct hdr_cmn* ch = HDR_CMN(q);	  	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(flow-id %d)Sending middle fragment\n",		   ss_id,		   UpFlowTable[tbindex].upstream_record.flow_id);	  /* Since 16 is the overhead for sending fragment header + 802_16 hdr*/	  UpFlowTable[tbindex].frag_data -= (UpFlowTable[tbindex].curr_gsize - 16 - upchannel.overhead_bytes); 	  	  if (UpFlowTable[tbindex].debug)	    printf("SS%d(flow-id %d)frag_data = %d\n",		   ss_id,		   UpFlowTable[tbindex].upstream_record.flow_id,		   UpFlowTable[tbindex].frag_data);	  	  /* 	     No need of adding PHY overhead bytes, 802_16 hdr bytes as 	     they have already been taken care of by making size = curr_gsize 	  */	  ch->size() = UpFlowTable[tbindex].curr_gsize;	  	  	  stime = TX_Time(q,UPSTREAM);	  	  fill_extended_header(2,q,tbindex);	  	  SET_TX_STATE(MAC_SEND);	  /* STATISTICS */	  UpFlowTable[tbindex].num_pkts++ ;	  UpFlowTable[tbindex].num_bytes += ch->size();	  total_num_sent_pkts++;	  total_num_sent_bytes += ch->size(); 	  total_num_BW_bytesUP += ch->size(); 	  	  total_num_frag++;	  	  /* Start a timer that expires when the packet transmission is complete.

⌨️ 快捷键说明

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