00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #ifndef ns_mac_802_16_h
00037 #define ns_mac_802_16_h
00038
00039 #include "hdr-802_16.h"
00040
00041
00042
00043 #define SET_RX_STATE(x) \
00044 { \
00045 rx_state_ = (x); \
00046 }
00047 #define SET_TX_STATE(x) \
00048 { \
00049 tx_state_ = (x); \
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00060 class Mac802_16BS;
00061
00062
00063
00064
00066 class Mac802_16 : public Mac
00067 {
00068 friend class TxPkt802_16Timer;
00069 friend class RxPkt802_16Timer;
00070
00071 public:
00072
00073 TxPkt802_16Timer mhTxPkt_ ;
00074 RxPkt802_16Timer mhRxPkt_ ;
00075
00076
00077
00078
00079
00080
00081
00082 struct upstream_channel upchannel;
00083 struct downstream_channel downchannel;
00084
00085 char collision;
00086 u_int16_t bytes_pminislot;
00087 u_int32_t minislots_psec;
00088 double size_mslots;
00089 u_int16_t size_ureqgrant;
00090
00091
00092
00093 u_int32_t avg_pkts;
00094 u_int32_t avg_bytes;
00095 u_int32_t num_pkts;
00096
00097
00098 double num_bytes;
00099
00100
00101 u_int32_t total_num_sent_pkts;
00102
00103
00104
00105
00106
00107
00108 double total_num_sent_bytes;
00109
00110
00111
00112
00113 u_int32_t total_num_mgt_pkts_US;
00114 u_int32_t total_num_rng_pkts_US;
00115 u_int32_t total_num_concat_pkts_US;
00116 u_int32_t total_num_frag_pkts_US;
00117 u_int32_t total_num_req_pkts_US;
00118 u_int32_t total_num_plaindata_pkts_US;
00119 u_int32_t total_num_concatdata_pkts_US;
00120 u_int32_t total_num_frames_US;
00121 u_int32_t total_num_BE_pkts_US;
00122 u_int32_t total_num_RTVBR_pkts_US;
00123 u_int32_t total_num_UGS_pkts_US;
00124 u_int32_t total_num_OTHER_pkts_US;
00125
00126 u_int32_t total_num_rx_pkts;
00127
00128
00129 double total_num_rx_bytes;
00130
00131
00132
00133
00134 double total_num_BW_bytesUP;
00135 double total_num_BW_bytesDOWN;
00136
00137 double total_num_appbytesUS;
00138
00139
00140 double total_num_appbytesDS;
00141
00142
00143 u_int32_t total_packets_dropped;
00144
00145
00146
00147 double last_BWCalcTime;
00148
00149 double last_rtime;
00150
00151 u_int32_t avg_mgmtpkts;
00152 u_int32_t num_mgmtpkts;
00153 u_int32_t avg_mgmtbytes;
00154 u_int32_t num_mgmtbytes;
00155 double last_mmgmttime;
00156
00157
00158
00159
00160
00161
00162 static int lan_num;
00163 static Mac802_16BS* bs_arr[NUM_802_16_LANS];
00164
00165
00166 MacState rx_state_;
00167 MacState tx_state_;
00168 int tx_active_;
00169
00170
00171 Mac802_16();
00172 virtual ~Mac802_16(){};
00173
00174 virtual void BsUcdHandler(Event *e) {};
00175 virtual void BsSyncHandler(Event *e) {};
00176 virtual void BsRngHandler(Event *e) {};
00177 virtual void BsMapHandler(Event *e) {};
00178 virtual void SSRngHandler(Event *e) {};
00179 virtual void SSSndTimerHandler(Event *e) {};
00180 virtual void SSReqTimerHandler(Event *e) {};
00181 virtual void RecvFrame(Packet* p,int i) {};
00182 virtual void BsSendHandler(Event *e) {};
00183 virtual void BsSndTimerHandler(Event *e) {};
00184
00185 virtual void BsWindowTimerHandler(Event * e) {};
00186
00187
00188 virtual void BsTokenHandler(Event *e) {};
00189
00190
00191 int command(int argc, const char*const* argv);
00192
00193
00194 void recvHandler(Event *e);
00195 void sendHandler(Event *e);
00196 void recv(Packet* p, Handler *h);
00197 void configure_upstream();
00198 void set_bit(u_char*,int,int);
00199 void dump_pkt(Packet*);
00200 char ClassifyDataMgmt(Packet*);
00201 int is_idle();
00202 int match(Packet*, struct flow_classifier);
00203 int bit_on(u_char, int);
00204 u_int32_t calculate_slots(double,double);
00205 u_int32_t power(u_int32_t,u_int32_t);
00206 double TX_Time(Packet *p,int);
00207 Packet* AllocPkt(int);
00208
00209
00210 void insert_alloclist(aptr&,u_int16_t,double,double,u_int16_t,u_int32_t);
00211 int CanBeSent(aptr&,Packet*,u_int32_t);
00212 int len_queue(plist);
00213
00214
00215 int CanErtPSBeSent(aptr&, Packet*);
00216
00217 };
00218
00219
00220
00221
00222
00223
00224
00225
00226
00228 class Mac802_16BS : public Mac802_16
00229 {
00230 friend class Map802_16Timer;
00231 friend class BsUcd802_16Timer;
00232 friend class BsRng802_16Timer;
00233 friend class BsSync802_16Timer;
00234 friend class BsTxPkt802_16Timer;
00235 friend class BsServiceFlowSendTimer;
00236
00237
00238 friend class BsToken802_16Timer;
00239
00240
00241 public:
00242 struct ss_record *SSRecord;
00243
00244 u_int16_t CurrIndexSSTable;
00245
00246
00247
00248 int register_to_bs(int macaddr,
00249 u_int16_t priority,
00250 u_char def_up,
00251 u_char def_dn,
00252 struct upstream_sflow *UpEntry,
00253 u_char UpSize,
00254 struct downstream_sflow *DownEntry,
00255 u_char DownSize);
00256
00257 int compare_priority(priority_array_p A, priority_array_p B);
00258
00259 Mac802_16BS();
00260 ~Mac802_16BS(){};
00261
00262 protected:
00263 int command(int argc, const char*const* argv);
00264
00265 private:
00266
00267
00268 double window_;
00269
00270
00271 Map802_16Timer mhMap_;
00272 BsRng802_16Timer mhRng_;
00273 BsUcd802_16Timer mhUcd_;
00274 BsSync802_16Timer mhSync_;
00275 BsTxPkt802_16Timer mhBsTxPkt_;
00276
00277 BsServiceFlowSendTimer mhBsSend_;
00278
00279
00280 BsUplinkSchedWindowTimer mhWdw_;
00281
00282
00283 BsToken802_16Timer mhToken_;
00284 tkptr TokenList;
00285
00286
00287
00288 struct bs_conf_param Conf_Table_;
00289 u_int16_t SizeSSTable;
00290
00291
00292 struct bs_statistics SSStatistics_;
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 struct job* job_list[8];
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 #define UP_HIGH_QUEUE 0
00323 #define UP_INTERM_QUEUE 1
00324 #define UP_LOW_QUEUE 2
00325 #define DOWN_UGS_QUEUE 3
00326 #define DOWN_RT_QUEUE 4
00327 #define DOWN_ERT_QUEUE 5 //$A18
00328 #define DOWN_NRT_QUEUE 6
00329 #define DOWN_BE_QUEUE 7
00330
00331
00332 mapptr mptr;
00333
00334 bs_sptr BsSndList;
00335
00336 double map_stime;
00337 double omap_stime;
00338 double map_etime;
00339 double omap_etime;
00340
00341 double map_acktime;
00342 double AckTime;
00343 double max_slots_pmap;
00344 double next_map;
00345
00346 int numIE;
00347 int map_lookahead;
00348 int MAP_LOOKAHEAD;
00349 int max_burst_slots;
00350 int rem_overhead;
00351
00352 int MapPropDelay;
00353
00354
00355 int size_rtqueue;
00356 int avg_szrtqueue;
00357 double last_mrqtime;
00358
00359 int size_bfqueue;
00360 int avg_szbfqueue;
00361 double last_mbfqtime;
00362
00363 int num_bfreq;
00364 int avg_bfreq;
00365 double last_mbfreq;
00366
00367 int num_rtreq;
00368 int avg_rtreq;
00369 double last_mrtreq;
00370
00371 double last_dmptime;
00372
00373 u_int32_t num_dgrant;
00374 u_int32_t num_contention;
00375 u_int32_t num_req;
00376 u_int32_t num_gpend;
00377
00378 u_int32_t avg_dgrant;
00379 u_int32_t avg_contention;
00380 u_int32_t avg_req;
00381 u_int32_t avg_gpend;
00382
00383 u_int32_t dropped_tokenq;
00384
00385 u_int32_t dropped_dsq;
00386
00387
00388 double proportion;
00389
00390
00391 u_char contention_thrhold;
00392
00393
00394
00395
00396
00397
00398 u_char network_status;
00399
00400 u_int32_t rtpoll_ddlinemiss;
00401
00402
00403 u_int32_t beffort_ddlinemiss;
00404
00405 int32_t num_rtslots;
00406
00407 int32_t num_nrtslots;
00408 int32_t num_befslots;
00409 u_int32_t num_adjust_slots;
00410
00411 Event intr;
00412
00413
00414 Event uintr;
00415 Event sintr;
00416 Event rintr;
00417 Event rxintr_;
00418
00419 Event wintr;
00420
00421 static int next_flowid;
00422
00423
00424
00425
00426
00427
00428
00429
00430 qlist txq_;
00431
00432
00433
00434
00435 int qnp_;
00436 int qnb_;
00437 int max_qnp_;
00438 int max_qnb_;
00439 int min_qnp_;
00440 int min_qnb_;
00441
00442 int queue_total_bytes_in, queue_total_bytes_out;
00443
00444
00445
00446 double util_total_bytes_US;
00447 double util_total_bytes_DS;
00448 int util_total_pkts_US;
00449 int util_total_pkts_DS;
00450
00451
00452 double util_bytes_US;
00453 double util_bytes_DS;
00454 int qlim_;
00455 double lastDumpTime;
00456 double lastUtilDumpTime;
00457
00458
00459 inline void SSRngHandler(Event * e) {}
00460 inline void SSSndTimerHandler(Event * e) {}
00461 inline void SSReqTimerHandler(Event * e) {}
00462 inline void UnlockQueue() {}
00463
00464 void BsMapHandler(Event *e);
00465 void BsSyncHandler(Event * e);
00466 void BsUcdHandler(Event * e);
00467 void BsRngHandler(Event * e);
00468
00469
00470 void BsWindowTimerHandler(Event * e);
00471
00472
00473
00474 void RateControl(Packet*, int,int,int);
00475 double getupdatedtokens(int,int);
00476 void BsTokenHandler(Event*);
00477 void insert_tokenlist(double,int,int);
00478
00479
00480 void sendUp(Packet* p);
00481 void sendDown(Packet* p);
00482 void RecvFrame(Packet*,int);
00483 void PassDownstream(Packet*);
00484 void HandleInData(Packet*,int,int);
00485 void HandleInMgmt(Packet*);
00486 void HandleFrag(Packet*);
00487 void HandleConcat(Packet*,int,int);
00488 void ReleaseJobs();
00489 void fill_job(struct job*,char,char,double,u_int32_t,double,double,u_int16_t);
00490 void InsertJob(struct job*,int);
00491
00492
00493 void HandleReq(u_int16_t,int,int,bool);
00494 void tune_parameters();
00495 void alloc_bw();
00496 void delete_joblist(int);
00497 void PhUnsupress(Packet*,int,int);
00498 void ApplyPhs(Packet*,int,int );
00499 void MakeAperiodicAlloc(struct job*,mapptr,int);
00500 void AllocMemSSrecord();
00501 void MakePeriodicAllocation(int,mapptr,double);
00502 void ReOrder(mapptr);
00503 void MarkOtherSlots(mapptr,u_int32_t,int);
00504 void jobdrop(mapptr);
00505 void MarkGrantPending(u_int32_t*,double);
00506 void SendMap();
00507 u_int32_t MarkUnusedSlots(u_int32_t);
00508 void find_flowindex(u_int16_t,int*,int*);
00509 void SendFrame(Packet*,int);
00510 void BsSendHandler(Event *);
00511 void dump_stats();
00512 void ParseExtHdr(Packet *);
00513 void dumpUGSJITTER(char *);
00514 void UpdateJitter(int,u_int16_t, double);
00515
00516
00517
00518 int find_size_map();
00519 int NumContSlots(mapptr *);
00520 int ChkQoSJobs(double,double);
00521 int classify(Packet*,char,int*);
00522 int insert_mapjob(int , jptr , u_int32_t *, int);
00523 int insert_mapjob(struct job*,u_int32_t*);
00524 int find_ss(int);
00525 u_int32_t MarkOtherAlloc(u_int32_t);
00526 u_int32_t FillMap(int,int,int,int,int);
00527 mapptr find_best_hole(u_int32_t);
00528 mapptr find_next(mapptr);
00529 mapptr find_prv(mapptr);
00530 mapptr TryAlloc(double,u_int32_t);
00531 double determine_deadline(char, int,int);
00532 double FitMap(mapptr,double);
00533 double CalculateAckTime();
00534
00535
00536 void print_job_list(int);
00537 void print_map_list();
00538
00539
00540 void print_short_map_list(Packet* Pkt);
00541 void delete_maplist();
00542 void dumpBWBS(char *fileName);
00543 void dumpFinalBSStats(char *fileName, int DSBW, int USBW);
00544 void dumpFinalSIDStats(int cindex, int findex,char *fileName, int DSBW);
00545 void dumpFinalDSSIDS(char *fileName, int DSBW);
00546 void dump802_16QueueStats(char *fileName, int channelBW);
00547 void dump802_16UtilStats(char *fileName, int channelDSBW, int channelUSBW);
00548
00549
00550
00551
00552 void insert_pkt_at_Head(Packet*, int , int);
00553
00554 int len_mgmtqueue();
00555
00556 Packet* deque_pkt();
00557 int packetTrace(Packet *p, int direction);
00558
00559
00560 void HandleOutData(Packet*, int, int);
00561
00562 int down_idle(int, int, EventType, Packet*);
00563 int down_decision(int, int, EventType, Packet*);
00564 int down_tosend(int, int, EventType, Packet*);
00565 int down_waitformap(int, int, EventType, Packet*);
00566 int(Mac802_16BS::*DOWNswitch[DOWNSTATES])(int, int, EventType, Packet*) ;
00567
00568 void UpdateAllocationTable(int, int);
00569 void UpdateJitter(int, int);
00570 bool insert_pkt(Packet*,int, int);
00571 double timer_expiration(int, int, Packet*);
00572 Packet * deque_pkt(int, int);
00573 void insert_mgmtpkt(Packet*, int, int);
00574 void insert_sndlist(double, int, int);
00575 void BsSndTimerHandler(Event * e);
00576
00577
00578 void alloc_ul_bw(double, double,u_int32_t);
00579 void alloc_dl_bw(double, double,u_int32_t);
00580 void checkDeadline(double, double, u_int32_t&);
00581 void checkMinimumBW(u_int32_t&, priority_array_p&, int&);
00582 void MakeAllocation(jptr, int, mapptr,char, int);
00583
00584 int CanBeSent(aptr&, Packet*);
00585
00586 };
00587
00588
00589
00590
00591
00592
00593
00594
00596 class Mac802_16SS : public Mac802_16
00597 {
00598 friend class SSRng802_16Timer;
00599 friend class SSServiceFlowSendTimer;
00600 friend class SSServiceFlowRequestTimer;
00601
00602 public:
00603 Mac802_16SS();
00604 ~Mac802_16SS(){};
00605
00606 protected:
00607 int command(int argc, const char*const* argv);
00608
00609 private:
00610
00611 RNG* rng_;
00612
00613
00614 SSRng802_16Timer mhSSRng_;
00615 SSServiceFlowSendTimer mhSSSend_;
00616 SSServiceFlowRequestTimer mhReq_;
00617
00618 Packet* map_;
00619
00620
00621 char debug_ss;
00622
00623 u_int32_t ss_id;
00624
00625 u_char my_lan;
00626
00627
00628
00629 u_char SizeUpFlowTable;
00630 struct upstream_sflow UpFlowTable[MAX_NUM_UPFLOWS_PERSS];
00631
00632 u_char SizeDownFlowTable;
00633 struct downstream_sflow DownFlowTable[MAX_NUM_DOWNFLOWS_PERSS];
00634
00635 u_char default_upstream_index_;
00636 u_char default_dstream_index_;
00637
00638 u_int16_t priority;
00639 double rng_freq;
00640 int bs_addr;
00641 double map_acktime;
00642 u_int32_t total_num_frag;
00643 u_int32_t total_num_collisions;
00644 u_int32_t total_num_bkoff;
00645
00646 u_int32_t total_collision_drops;
00647
00648
00649 u_int32_t total_queue_drops;
00650
00651
00652 sptr SndList;
00653 rptr ReqList;
00654
00655 rptr tempReqList;
00656
00657
00658
00659
00660
00661 int(Mac802_16SS::*UGSswitch[UGSSTATES])(char, EventType, Packet*) ;
00662 int(Mac802_16SS::*RTPOLLswitch[RTPOLLSTATES])(char, EventType, Packet*);
00663
00664 int(Mac802_16SS::*ERTPOLLswitch[ERTPOLLSTATES])(char, EventType, Packet*);
00665
00666 int(Mac802_16SS::*NRTPOLLswitch[NRTPOLLSTATES])(char, EventType, Packet*);
00667 int(Mac802_16SS::*BEFFORTswitch[BEFFORTSTATES])(char, EventType,Packet*);
00668
00669 Event rintr;
00670
00671 double last_dmptime;
00672
00673
00674 inline void BsMapHandler(Event * e) {}
00675 inline void BsSyncHandler(Event * e) {}
00676 inline void BsUcdHandler(Event * e) {}
00677 inline void BsRngHandler(Event * e) {}
00678 inline void BsSendHandler(Event *e) {};
00679
00680
00681 inline void BsTokenHandler(Event *e) {};
00682
00683
00684 void SSRngHandler(Event * e);
00685 void SSSndTimerHandler(Event * e);
00686 void SSReqTimerHandler(Event * e);
00687 void sendUp(Packet* p);
00688 void sendDown(Packet* p);
00689 void Initialize_entry(char direction, char index);
00690 void HandleMap(Packet*);
00691 void HandleOutData(Packet*, char);
00692 void SendData(Packet*, char);
00693
00694
00695 int SendReq(char, Packet*);
00696 void decide_frag(Packet*,char);
00697 void send_frag_data(Packet*,char);
00698 void fill_extended_header(int, Packet*, char);
00699 void send_concat(Packet*, char);
00700 void RecvFrame(Packet*,int);
00701 void handle_indata(Packet*,char);
00702 void handle_inmgmt(Packet*,char);
00703 void SetDefaultFlow();
00704 void PhUnsupress(Packet*, char);
00705 void ApplyPhs(Packet*, char);
00706
00707
00708 void print_alloclist(char);
00709
00710
00711 void print_short_map_list(Packet* Pkt);
00712 void print_classifiers();
00713 void dump_stats();
00714 char classify(Packet*,char);
00715 int check_concat_req(char);
00716 int check_frag_req(u_int32_t,char);
00717 int fill_piggyback_req(char);
00718 void MarkUsedContentionSlots(int,char);
00719 void turn_off_contention(char);
00720
00721 int back_off(char,Packet*);
00722 void insert_sndlist(double,char);
00723 void insert_reqlist(double,char);
00724 void refresh_reqlist(char);
00725
00726
00727 void reinsert_reqlist(char);
00728
00729 void insert_pkt(Packet*,char);
00730 void UpdateAllocationTable(char);
00731 void HandleOtherMgmt(Packet*);
00732
00733
00734 void print_ssalloclist();
00735 void HandleOutMgmt(Packet*,char);
00736 void FillPiggyReq(char, Packet*);
00737
00738
00739 int FillPiggyExtHdr(char,Packet*, int);
00740 void UpdateJitter(char);
00741
00742
00743
00744
00745 int CanBeSent(aptr&, Packet*, char);
00746
00747 int CanUnicastReqBeSent(char);
00748 int CanContentionReqBeSent(char);
00749 int DataGrantPending(char);
00750 int MapSentAfterReq(char);
00751 int NumContentionSlots(char);
00752
00753 void USRateMeasure(char, Packet*);
00754 void us_getupdatedtokens(char);
00755
00756
00757
00758
00759
00760 int look_at_queue(char);
00761 int filterACKPackets(Packet *pkt, char tbindex);
00762 int packetMatch(Packet *pkt1, Packet *pkt2);
00763
00764 double find_contention_slot(char,u_int32_t);
00765 double timer_expiration(char,Packet*,int);
00766 Packet * deque_pkt(char);
00767 Packet* pkt_lookup(char tbindex,int i);
00768
00769
00770 void dumpBWSS(char *fileName);
00771 void dumpUGSJITTER(char,char *filename);
00772 void dumpFinalSSStats(char *fileName);
00773 void dump802_16QueueStats(char *fileName, int channelBW);
00774 void dump802_16UtilStats(char *fileName, int channelDSBW, int channelUSBW);
00775
00776 int reqFlag, reqFlagCounter;
00777 int packetTrace(Packet *p, int direction);
00778
00779 int timingsTrace(Packet *p, int id);
00780
00781
00782 int ugs_idle(char, EventType, Packet*);
00783 int ugs_decision(char, EventType, Packet*);
00784 int ugs_tosend(char, EventType, Packet*);
00785 int ugs_waitformap(char, EventType, Packet*);
00786 int rtpoll_idle(char, EventType, Packet*);
00787 int rtpoll_decision(char, EventType, Packet*);
00788 int rtpoll_tosend(char, EventType, Packet*);
00789 int rtpoll_waitformap(char, EventType, Packet*);
00790 int rtpoll_tosendreq(char, EventType, Packet*);
00791
00792
00793
00794 int ertpoll_idle(char, EventType, Packet*);
00795 int ertpoll_decision(char, EventType, Packet*);
00796 int ertpoll_tosend(char, EventType, Packet*);
00797 int ertpoll_waitformap(char, EventType, Packet*);
00798 int ertpoll_tosendreq(char, EventType, Packet*);
00799
00800 int nrtpoll_idle(char, EventType, Packet*);
00801 int nrtpoll_decision(char, EventType, Packet*);
00802 int nrtpoll_tosend(char, EventType, Packet*);
00803 int nrtpoll_waitformap(char, EventType, Packet*);
00804 int nrtpoll_tosendreq(char, EventType, Packet*);
00805 int nrtpoll_reqsent(char, EventType, Packet*);
00806 int nrtpoll_contention(char, EventType, Packet*);
00807 int beffort_idle(char, EventType, Packet*);
00808 int beffort_decision(char, EventType, Packet*);
00809 int beffort_tosend(char, EventType, Packet*);
00810 int beffort_waitformap(char, EventType, Packet*);
00811 int beffort_tosendreq(char, EventType, Packet*);
00812 int beffort_reqsent(char, EventType, Packet*);
00813 int beffort_contention(char, EventType, Packet*);
00814
00815 int beffort_ratecheck(char, EventType, Packet*);
00816
00817
00818 void FillErtPSPiggyReq(char, Packet *);
00819 int SendErtPSReq(char, Packet*);
00820
00821 };
00822
00823
00824
00825 #endif