📄 mac-802_16-bs.cc
字号:
/***************************************************************************** * WiMAX module * * Copyright (C) 2008 Juliana Freitag Borin, Flavio Kubota and Nelson L. * S. da Fonseca - wimaxgroup@lrc.ic.unicamp.br * * This program is a free result: you can redistribute it and/or modify * it under the terms of the UOL Public License Version 1 or (at your * option) any later version. The license terms are available at * http://bolsapesquisa.uol.com.br/lpu.jhtm. * * This file contains the BS object class method implementations * * Revisions: * $A0: 6/23/2003: Needed to fprintf the app bytes counts as a double * instead of an integer * $A1: 8/11/04: Added print_short_map_list which creates BSMAP.out * listing the contents of * every MAP that is sent. * $A2: 8/12/04: Added an option so that MarkUnusedSlot() will fill them * with Contention Req * opportunities. The following needs to be defined: * #define FILLWITHCONTOPS 0 * $A3: 8/12/04: Bug: FillMap returns num_rtslots+num_befslots but we * already added them ? * $A4: 9/4/04: Randomize when a management message is to be sent. * $A5: 9/6/04: I must have commented out initing map_lookahead * several weeks ago - caused bizarre problems... * $A6: 9/6/04: Adding PACKET_TRACE capability * $A7: 9/18/04: Added additional counters: * u_int32_t total_num_mgt_pkts_US;: the total mgt frames that arrived * u_int32_t total_num_rng_pkts_US; : total rng mgt from the ss's, it won't * be exactly 1*testtime for each SS since its random * u_int32_t total_num_concat_pkts_US;: The number of frames with concat data * Note: the util_total_pkts_US counter does not include this- instead it counts * each packet in the concatonated frame * u_int32_t total_num_frag_pkts_US; * u_int32_t total_num_req_pkts_US; * u_int32_t total_num_BE_pkts_US; * u_int32_t total_num_RTVBR_pkts_US; * u_int32_t total_num_UGS_pkts_US; * u_int32_t total_num_OTHER_pkts_US; * total_num_frames_US++;; the correct number of frames of all types that arrives : * plaindata (with or without piggyback req), rng frame, concat frame * (that contains mulitple packets) * frag frames, req frames. * Note: so util_total_pkts_US = plaindata + req + rng * and this wil normally be > total_num_frames * $A8 : Added packetTrace method * Changed our MAP and mgt frames from ch->ptype_ PT_MAC to PT_MAC802_16xxx * $A9: When TRACE was on, seg fault in find_best_hole in an error... * $A10: Call packetTrace for each packet contained in a concatonated * US frame. * $A11: 3/26/05: Fixed jitter calculation * $A12: 4/7/05 : Two changes. When we insert_pkt(), never drop * a Management (e.g., MAP) the pkt * Instead, insert at the head of the queue. * $A13: 5/2/05: To better simulate prop delays, we make sure that the * BS sends out a MAP that begins far enough in advance so that when * it arrives at the SS, the MAP time is still in the future. * Add MapPropDelay variable. * $A14: 9/13/05: (J. Freitag) grant_limits are not being used in any function of any class! * $A15: 2/10/06: (J. Freitag) map_stime = map_etime + size_mslots; -> first slot is used to send the MAP message, * otherwise, there would be collision between data msgs and MAP msgs. * $A15: 2/10/06: (J. Freitag) map_etime = map_stime + Conf_Table_.mapparam.time_covered - size_mslots;-> first slot is used to send the MAP message * $A16: 3/15/06: (J. Freitag) included non-real-time service * $A17: 3/16/06: (J. Freitag) instead of using a proportion of num_slots to rt-ps service and the remaining slots to be service, * the rt-ps service will use as many slots as it needs, then the nrt-ps will use as many slots as it needs * and the remaining slots will, if any, will be used by the be service. * $A18: 3/23/06: (J. Freitag) in 802.16 it is not necessary to add MPEG overhead * $A19: 3/31/06: (J. Freitag) when the sendDown function is called and macDA() = -1, the packet is a broadcast (for example an arp * request), so it must be classified as a MGMT_PKT and not as a DATA_PKT. Otherwise, the classify function * will search for a ss_id and a flow_id and it will result in error. * $A20: 4/04/06: (J. Freitag) included downlink QoS scheduling service * $A21: 8/30/06: (J. Freitag) included a new uplink scheduling algorithm * $A22: 9/13/06: (J. Freitag) in the function fill_job, the deadline assigment is wrong. Included the deadline parameter * to the function call * $A23: 4/27/07: (J. Freitag) included extended-real-time service * $A24: 05/07/07: (J. Freitag) changed bandwidht requests so that they are made in terms of the number of * bytes, instead of the number of slots. * $A25: 07/10/07: (J. Freitag) included periodic aggregate bandwidth request * $A26: 07/17/07: (J. Freitag) modification to avoid bandwidth reservation for the UGS * service in the downlink direction. This avoids the bandwidth waste * when the UGS queue is empty. ***************************************************************************//*! \file mac-802_16-bs.cc This file contains the BS object class method implementations.*/#include "mac-802_16.h"#include "random.h"#include "math.h"//$A8#include "ping.h"//Used by PACKETTRACE to trace certain flows#define FLOW_ID 0 #define SS_ID 0//#define DEBUG_SCHED 1//#define PACKET_TRACE 1//#define TRACE_BS 1//#define TRACE_BS_UP_DATA 0//#define TRACE_BS_DOWN_DATA 0#define DUMPBSMAP 0 /* If >0 then we dump each sent map to the file BSMAP.out */ //If defined, then MarkUnusedSlot() fills //unused slots with contention opportunities#define FILLWITHCONTOPS 0#define SHORT_STATS 1 /* define this to get a single line of final stats *//* Token bucket changes under ifdef RATE_CONTROL */extern int lan_num;extern Mac802_16BS* bs_arr[NUM_802_16_LANS];int Mac802_16BS::next_flowid = 3;int hdr_mac802_16extd::offset_;int hdr_mac802_16::offset_;int hdr_mac802_16mgmt::offset_;int hdr_mac802_16map::offset_;int Mac802_16::lan_num = 0;Mac802_16BS* Mac802_16::bs_arr[NUM_802_16_LANS];/**********************************************************************************************************************************************************//*! Mac802_16EHeaderClass class */static class Mac802_16EHeaderClass : public PacketHeaderClass {public: Mac802_16EHeaderClass() : PacketHeaderClass("PacketHeader/802_16BSExt", sizeof(hdr_mac802_16extd)) { bind_offset(&hdr_mac802_16extd::offset_); }} class_hdr_mac802_16extd;/**********************************************************************************************************************************************************//*! Mac802_16HeaderClass class */static class Mac802_16HeaderClass : public PacketHeaderClass {public: Mac802_16HeaderClass() : PacketHeaderClass("PacketHeader/802_16BS", sizeof(hdr_mac802_16)) { bind_offset(&hdr_mac802_16::offset_); }} class_hdr_mac802_16;/**********************************************************************************************************************************************************//*! Mac802_16MHeaderClass class */static class Mac802_16MHeaderClass : public PacketHeaderClass {public: Mac802_16MHeaderClass() : PacketHeaderClass("PacketHeader/802_16BSMgmt", sizeof(hdr_mac802_16mgmt)) { bind_offset(&hdr_mac802_16mgmt::offset_); }} class_hdr_mac802_16mgmt;/**********************************************************************************************************************************************************//*! Mac802_16MHeaderClass class */static class Mac802_16MapHeaderClass : public PacketHeaderClass {public: Mac802_16MapHeaderClass() : PacketHeaderClass("PacketHeader/802_16BSMap", sizeof(hdr_mac802_16map)) { bind_offset(&hdr_mac802_16map::offset_); }} class_hdr_mac802_16map;/***************************************************************************** TCL Hooks for the simulator*****************************************************************************//*! TCL Hooks for the simulator */static class Mac802_16BsClass : public TclClass {public: Mac802_16BsClass() : TclClass("Mac/802_16BS") {} TclObject* create(int, const char*const*) { return (new Mac802_16BS); }} class_mac_802_16bs;/**********************************************************************************************************************************************************//*! Constructor */Mac802_16BS::Mac802_16BS() : Mac802_16(), mhMap_(this), mhRng_(this), mhUcd_(this), mhSync_(this), mhBsTxPkt_(this), mhBsSend_(this), mhWdw_(this), //#ifdef RATE_CONTROL //-------------------------------------------------- mhToken_(this) //#endif //---------------------------------------------------------------{ //#ifdef RATE_CONTROL //-------------------------------------------------- TokenList = 0; //#endif //--------------------------------------------------------------- collision = 0; SizeSSTable = 0; CurrIndexSSTable = 0; SSRecord = 0; rem_overhead = 0; map_stime = 0;; map_etime = 0; map_acktime = 0; mptr = 0; num_rtslots = 0; //$A16 num_nrtslots = 0; num_befslots = 0; num_adjust_slots = 0; AckTime = 0; omap_stime = 0; omap_etime = 0; max_slots_pmap = 0; next_map = 0; BsSndList = 0;//$A13 MapPropDelay = 1; last_mrqtime = 0.0; last_mbfqtime = 0.0; size_rtqueue = 0; size_bfqueue = 0; avg_szrtqueue = 0; avg_szbfqueue = 0; num_bfreq = avg_bfreq = 0; last_mbfreq = 0; num_rtreq = avg_rtreq = 0; last_mrtreq = 0; num_dgrant = num_contention = 0; num_req = num_gpend = 0; last_dmptime = 0; SSStatistics_.avg_datagrants = 0; SSStatistics_.avg_interdpr_map = 0; SSStatistics_.num_IE = 0; SSStatistics_.num_req = 0; SSStatistics_.avg_contentionslots = 0; SSStatistics_.data_sent = 0; SSStatistics_.fragmented_count = 0; SSStatistics_.concatenation_count = 0; SSStatistics_.num_creq = 0; SSStatistics_.num_piggyreq = 0; SSStatistics_.num_creqgrant = 0; SSStatistics_.num_creqdenied = 0; SSStatistics_.total_num_cslots = 0; SSStatistics_.total_num_mgmtslots = 0; job_list[0] = job_list[1] = job_list[2] = job_list[3] = 0; job_list[4] = job_list[5] = job_list[6] = job_list[7] = 0; bs_arr[lan_num] = this; lan_num++; /* TODO: we want to use DropTail or REDQueue's .... */ //txq_ = new PacketQueue; txq_ = 0; // txq_ = new DropTail; //qlim_ = 500; //init Downstream PacketQueue to 50 packets /* TODO: We'd like this param exposed */ qnp_ = 0; /* same as len_ */ qnb_ = 0; /* no bytes in queue */ max_qnp_ = 0; max_qnb_=0; min_qnp_=0; min_qnb_=0; lastDumpTime = Scheduler::instance().clock(); lastUtilDumpTime = Scheduler::instance().clock(); /* Statistics These next two are used for periodic statistics... So beware, they may be reset during a run */ total_num_sent_pkts =0; /* total Num of packets sent */ total_num_sent_bytes =0; /* total Num of bytes received */ /* These two are used at the end of the run These should not be reset during a run */ util_total_bytes_US = 0; /* Used for end of run util stat*/ util_total_pkts_US = 0; /* Used for end of run util stat*/ util_total_bytes_DS = 0; /* used for end of run util stats */ util_total_pkts_DS = 0; /* used for end of run util stats */ util_bytes_US=0; /* used by dump802_16UtilStats*/ util_bytes_DS =0; /* used by dump802_16UtilStats*/ /* These next two are used for periodic statistics... So beware, they may be reset during a run */ total_num_rx_pkts =0; /* total Num of packets received */ total_num_rx_bytes =0; /* total Num of bytes received */ //$A7 total_num_mgt_pkts_US =0; /* total Num of packets received */ total_num_rng_pkts_US =0; total_num_concat_pkts_US =0; total_num_frag_pkts_US =0; total_num_req_pkts_US =0; total_num_plaindata_pkts_US = 0; total_num_concatdata_pkts_US = 0; total_num_frames_US = 0; total_num_BE_pkts_US == 0; total_num_RTVBR_pkts_US == 0; total_num_UGS_pkts_US == 0; total_num_OTHER_pkts_US == 0; queue_total_bytes_in = 0; /*?? needed anymore ?? */ queue_total_bytes_out = 0; /*?? needed anymore ?? */ total_num_BW_bytesDOWN =0; total_num_BW_bytesUP =0; total_num_appbytesUS = 0; total_num_appbytesDS = 0; total_packets_dropped =0; /* total Num of packets dropped */ dropped_dsq =0; /* total Num of packets dropped at DS queue*/ dropped_tokenq =0; /* total Num of packets dropped token queue*/ last_BWCalcTime = Scheduler::instance().clock(); //$A20 DOWNswitch[0] = &Mac802_16BS::down_idle; DOWNswitch[1] = &Mac802_16BS::down_decision; DOWNswitch[2] = &Mac802_16BS::down_tosend; DOWNswitch[3] = &Mac802_16BS::down_waitformap; #ifdef TRACE_BS //-------------------------------------------------------- printf("BS created successfully\n");#endif //------------------------------------------------------------------- //$A21 check if window is set, otherwise use 1 second as default; Tcl& tcl = Tcl::instance(); tcl.evalf("Mac/802_16BS set window_"); if (strcmp(tcl.result(), "0") != 0) bind_bw("window_", &window_); else window_ = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -