?? mac-802_16-fsm.cc
字號:
double etime, current_time; Packet* t; if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d) RTPOLL_TOSEND state \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); switch(e) { case SEND_PKT: /* Function to find out the first data grant big enough for this packet (indicated by 0) */ etime = timer_expiration(tbindex, p, DATA_GRANT); if (etime == -1.0) { printf("SS%d(flow-id %d) Timer expiration error: exiting..\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); exit(1); } //printf("Starting snd timer..\n"); current_time = Scheduler::instance().clock(); //TESTE //fprintf(stderr,"rtpoll_tosend em %lf evento %p para %lf\n",current_time,&UpFlowTable[tbindex].intr,etime+current_time); mhSSSend_.start((Packet *)(&UpFlowTable[tbindex].intr), etime); insert_sndlist(current_time + etime, tbindex); break; case PKT_ARRIVAL: insert_pkt(p,tbindex); break; case MAP_ARRIVAL: UpdateAllocationTable(tbindex); //printf("\nAllocation table for flow %d\n", //UpFlowTable[tbindex].upstream_record.flow_id); //print_alloclist(tbindex); break; case SEND_TIMER: /* Senddown shud set pkt to NULL & free the pkt */ //printf("Allocation-table for flow-id %d\n", //UpFlowTable[tbindex].upstream_record.flow_id); //print_alloclist(tbindex); //deque_pkt(tbindex); //TESTE //printf("flow id %d send packet at %lf\n",UpFlowTable[tbindex].upstream_record.flow_id,Scheduler::instance().clock()); //TESTE //fprintf(stderr,"rtpoll_tosend send_timer em %lf\n",Scheduler::instance().clock()); SendData(p,tbindex); UpFlowTable[tbindex].pkt = 0; if ((len_queue(UpFlowTable[tbindex].packet_list)) > 0) { UpFlowTable[tbindex].state = RTPOLL_DECISION; t = deque_pkt(tbindex); UpFlowTable[tbindex].pkt = t; rtpoll_decision(tbindex, PKT_ARRIVAL, t); } else UpFlowTable[tbindex].state = RTPOLL_IDLE; break; default: printf("SS%d(flow-id %d) RTPOLL-TOSEND state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } return 1;}/**************************************************************************************************************************************************/int Mac802_16SS::rtpoll_tosendreq(char tbindex, EventType e, Packet* p){ double etime,current_time; if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d) RTPOLL_TOSENDREQ state \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); switch(e) { case SEND_UREQ: /* Function to find out the first data grant big enough for this packet (indicated by 1) */ etime = timer_expiration(tbindex, p, UREQ_GRANT); if (etime == -1.0) { printf("SS%d(flow-id %d) Timer expiration error: exiting..\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); exit(1); } //TESTE //fprintf(stderr,"rtpoll_tosendreq em %lf evento %p para %lf\n",current_time,&UpFlowTable[tbindex].intr,etime+current_time); mhReq_.start((Packet*)(&UpFlowTable[tbindex].intr), etime); current_time = Scheduler::instance().clock(); insert_reqlist(current_time + etime, tbindex); break; case PKT_ARRIVAL: insert_pkt(p,tbindex); break; case MAP_ARRIVAL: UpdateAllocationTable(tbindex); if (CanBeSent(UpFlowTable[tbindex].alloc_list,p,tbindex)) { mhReq_.stop((Packet*)(&UpFlowTable[tbindex].intr)); //$A8 //refresh_reqlist(); UpFlowTable[tbindex].req_time = 999999.0; UpFlowTable[tbindex].state = RTPOLL_TOSEND; rtpoll_tosend(tbindex, SEND_PKT, p); } break; case REQ_TIMER: SendReq(tbindex, p); //$A11 UpFlowTable[tbindex].state = RTPOLL_REQSENT; UpFlowTable[tbindex].state = RTPOLL_WAITFORMAP; //TESTE //fprintf(stderr,"rtpoll_tosendreq req_timer em %lf\n",Scheduler::instance().clock()); break; default: printf("SS%d(flow-id %d) RTPOLL-TOSENDREQ state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } return 1;}/**************************************************************************************************************************************************$A11int Mac802_16SS::rtpoll_reqsent(char tbindex, EventType e, Packet* p){ if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d) RTPOLL_REQSENT state \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); switch(e) { case PKT_ARRIVAL: insert_pkt(p,tbindex); break; case MAP_ARRIVAL: UpdateAllocationTable(tbindex); //printf("\nAllocation table for flow %d\n", //UpFlowTable[tbindex].upstream_record.flow_id); //print_alloclist(tbindex); if (CanBeSent(UpFlowTable[tbindex].alloc_list,p,tbindex)) { UpFlowTable[tbindex].state = RTPOLL_TOSEND; rtpoll_tosend(tbindex, SEND_PKT, p); } else if (!DataGrantPending(tbindex) && (MapSentAfterReq(tbindex))) { UpFlowTable[tbindex].state = RTPOLL_DECISION; rtpoll_decision(tbindex, PKT_ARRIVAL, p); } break; default: printf("SS%d(flow-id %d) RTPOLL-REQSENT state error: Unknown event received\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); break; } return 1;}*//*===========================END RT-RTPOLL STATE MACHINE FUNCTIONS===================*///$A5/*===========================NRT-POLL STATE MACHINE FUNCTIONS===================*//************************************************************************* tbindex denotes the service-flow entry on which packet has been mapped *************************************************************************//*! \param tbindex denotes the service-flow entry on which packet has been mapped */int Mac802_16SS::nrtpoll_idle(char tbindex, EventType e, Packet* p){ if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_idle(%lf): NRT-POLL_IDLE state \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock()); switch(e) { case PKT_ARRIVAL:#ifdef TIMINGS timingsTrace(p,1);#endif if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrt-poll_idle(%lf):Packet arrived, go to decision state\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock()); UpFlowTable[tbindex].pkt = p; /* Since this pkt is not being queued, so update the enque_time variable */ UpFlowTable[tbindex].enque_time = Scheduler::instance().clock(); UpFlowTable[tbindex].queuing_samples++; nrtpoll_decision(tbindex, PKT_ARRIVAL, p); break; case MAP_ARRIVAL: UpdateAllocationTable(tbindex); if (UpFlowTable[tbindex].debug) { printf("SS%d(flow-id %d):nrt-poll_idle(%lf): MAP arrived, new state: %d \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(), UpFlowTable[tbindex].state); printf("SS%d(flow-id %d) Allocation table \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); print_alloclist(tbindex); } break; default: printf("SS%d(flow-id %d) NRTPOLL-IDLE state error: Unknown event received %d\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id,e); break; } return 1;}/**************************************************************************************************************************************************/ int Mac802_16SS::nrtpoll_decision(char tbindex, EventType e, Packet* p){ if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_decision(%lf): entered with event %d \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(),e); switch(e) { case PKT_ARRIVAL:#ifdef TIMINGS //We only get here from another state... //We enter a new request process timingsTrace(p,2);#endif if (!CanBeSent(UpFlowTable[tbindex].alloc_list,p,tbindex)) { if (UpFlowTable[tbindex].debug) printf("SS%d (flow-id %d):nrtpoll_decision(%lf): Can NOT BeSent! \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock()); if (!CanUnicastReqBeSent(tbindex)) { if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_decision(%lf):Unicast Req Can NOT BeSent!\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock()); /*$A11 if (DataGrantPending(tbindex)) { if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_decision(%lf):DataGrant is pending... goto REQSENT state\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock()); turn_off_contention(tbindex); UpFlowTable[tbindex].state = NRTPOLL_REQSENT; } else */ if (CanContentionReqBeSent(tbindex)) { UpFlowTable[tbindex].state = NRTPOLL_CONTENTION; if (!UpFlowTable[tbindex].contention_on) nrtpoll_contention(tbindex, CONTENTION_ON, p); else /* Contention is on and reached decision state, that implies that back-off has occured */ nrtpoll_contention(tbindex, CONTENTION_BKOFF, p); if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_decision(%lf):ContentionRequ COULD be sent:updated state:%d\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(), UpFlowTable[tbindex].state); } else { UpFlowTable[tbindex].state = NRTPOLL_WAITFORMAP; } if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_decision(%lf):Unicast req COULD NOT be sent:updated state:%d\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(), UpFlowTable[tbindex].state); } else { UpFlowTable[tbindex].state = NRTPOLL_TOSENDREQ; turn_off_contention(tbindex); nrtpoll_tosendreq(tbindex,SEND_UREQ, p); if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_decision(%lf):Unicast req CAN be sent:updated state:%d \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(), UpFlowTable[tbindex].state); } } else { turn_off_contention(tbindex); UpFlowTable[tbindex].state = NRTPOLL_TOSEND; nrtpoll_tosend(tbindex, SEND_PKT, p); } break; default: printf("SS%d(flow-id %d) NRTPOLL-DECISION state error: Unknown event received %d\n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id,e); break; } return 1;}/**************************************************************************************************************************************************/int Mac802_16SS::nrtpoll_waitformap(char tbindex, EventType e, Packet* p){ if (UpFlowTable[tbindex].debug) printf("SS%d(flow-id %d):nrtpoll_waitformap(%lf): entered with event %d \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id, Scheduler::instance().clock(),e); switch(e) { case PKT_ARRIVAL:#ifdef TIMINGS timingsTrace(p,1);#endif insert_pkt(p,tbindex); break; case MAP_ARRIVAL: UpdateAllocationTable(tbindex); if (UpFlowTable[tbindex].debug) { printf("SS%d(flow-id %d) Allocation table \n", ss_id,UpFlowTable[tbindex].upstream_record.flow_id); print_alloclist(tbindex); } if ( CanBeSent(UpFlowTable[tbindex].alloc_list,p,tbindex)) { turn_off_contention(tbindex); UpFlowTable[tbindex].state = NRTPOLL_TOSEND; nrtpoll_tosend(tbindex, SEND_PKT, p); } else if ( CanUnicastReqBeSent(tbindex)) { turn_off_contention(tbindex); UpFlowTable[tbindex].state = NRTPOLL_TOSENDREQ; nrtpoll_tosendreq(tbindex, SEND_UREQ, p); } else if ( CanContentionReqBeSent(tbindex)) { UpFlowTable[tbindex].state = NRTPOLL_CONTENTION; if (UpFlowTable[tbindex].contention_on) nrtpoll_contention(tbindex, CONTENTION_SLOTS, p); else nrtpoll_contention(tbindex, CONTENTION_ON, p); } /*$A11 else if (DataGrantPending(tbindex))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -