58 : TclClass(
"Module/UW/TDMA")
76 ((
UwTDMA *) module)->changeStatus();
85 , transceiver_status(
IDLE)
90 , max_packet_per_slot(1)
91 , packet_sent_curr_slot_(0)
100 bind(
"debug_", (
int *) &
debug_);
103 bind(
"HDR_size_", (
int *) &
HDR_size);
107 bind(
"mac2phy_delay_", (
double *) &mac2phy_delay_);
114 cerr << NOW <<
" UwTDMA() not valid max_queue_size < 0!! set to 1 by default "
119 cerr << NOW <<
" UwTDMA() not valid frame_duration < 0!! set to 1 by default "
124 cerr << NOW <<
" UwTDMA() not valid max_packet_per_slot < 0!! set to 1 by default "
129 cerr << NOW <<
" UwTDMA() drop_old_ and checkPriority cannot be set both to 1!! "
130 <<
"checkPriority set to 0 by default " << std::endl;
133 if (mac2phy_delay_ <= 0) {
134 cerr << NOW <<
" UwTDMA() not valid mac2phy_delay_ < 0!! set to 1e-9 by default "
136 mac2phy_delay_ = 1e-9;
157 std::cout << NOW <<
" TDMA(" << addr
158 <<
")::insert packet with standard priority in the queue" << std::endl;
162 std::cout << NOW <<
" TDMA(" << addr
163 <<
")::insert packet with high priority in the queue" << std::endl;
169 cout << NOW <<
" TDMA(" << addr
170 <<
")::recvFromUpperLayers() dropping pkt due to buffer full "
173 Packet *p_old =
buffer.front();
181 Packet *p_old =
buffer.back();
208 Packet *p =
buffer.front();
215 std::cout << NOW <<
" ID " << addr <<
": Wait my slot to send"
218 std::cout << NOW <<
" ID " << addr
219 <<
": Wait earlier packet expires to send the current one"
229 cout << NOW <<
" TDMA(" << addr
245 MMac::Mac2PhyStartTx(p);
249 std::cout << NOW <<
" ID " << addr <<
": Sending packet" << std::endl;
252 <<
"::TDMA_node(" << addr <<
")::PCK_SENT packet_sent_curr_slot_ = "
264 <<
"::TDMA_node(" << addr <<
")::Phy2MacEndTx(p)"
284 hdr_cmn *ch = HDR_CMN(p);
285 hdr_mac *mach = HDR_MAC(p);
286 int dest_mac = mach->macDA();
287 int src_mac = mach->macSA();
291 cout << NOW <<
" TDMA(" << addr
292 <<
")::Phy2MacEndRx() dropping corrupted pkt from node = "
293 << src_mac << std::endl;
298 if (dest_mac != addr && dest_mac != MAC_BROADCAST) {
302 std::cout << NOW <<
" ID " << addr <<
": packet was for "
303 << dest_mac << std::endl;
309 std::cout << NOW <<
" ID " << addr
310 <<
": Received packet from " << src_mac
314 <<
"::TDMA_node(" << addr
315 <<
")::PCK_FROM:" << src_mac << std::endl;
326 std::cout << NOW <<
" ID " << addr
327 <<
": Received packet while transmitting " << std::endl;
330 <<
"::TDMA_node(" << addr <<
")::RCVD_PCK_WHILE_TX"
343 hdr_cmn *ch = hdr_cmn::access(p);
344 hdr_mac *mach = HDR_MAC(p);
346 int curr_size = ch->size();
367 std::cout << NOW <<
" Off ID " << addr <<
" "
372 <<
"::TDMA_node(" << addr <<
")::Off" << std::endl;
378 std::cout << NOW <<
" On ID " << addr <<
" "
382 <<
"::TDMA_node(" << addr <<
")::On" << std::endl;
394 std::stringstream stat_file;
395 stat_file <<
"./TDMA_node_" << addr <<
"_" <<
name_label_ <<
".out";
396 std::cout << stat_file.str().c_str() << std::endl;
400 <<
"::TDMA_node(" << addr <<
")::Start_simulation"
407 std::cout << NOW <<
" Status " <<
slot_status <<
" on ID " << addr
418 <<
"::TDMA_node(" << addr <<
")::TDMA_stopped_"
425 Tcl &tcl = Tcl::instance();
427 if (strcasecmp(argv[1],
"start") == 0) {
430 std::cout <<
"Error: number of slots set to 0" << std::endl;
436 <<
"Error: guard time or frame set incorrectly"
448 }
else if (strcasecmp(argv[1],
"stop") == 0) {
451 }
else if (strcasecmp(argv[1],
"get_buffer_size") == 0) {
452 tcl.resultf(
"%d",
buffer.size());
454 }
else if (strcasecmp(argv[1],
"get_upper_data_pkts_rx") == 0) {
455 tcl.resultf(
"%d", up_data_pkts_rx);
457 }
else if (strcasecmp(argv[1],
"get_sent_pkts") == 0) {
458 tcl.resultf(
"%d", data_pkts_tx);
460 }
else if (strcasecmp(argv[1],
"get_recv_pkts") == 0) {
461 tcl.resultf(
"%d", data_pkts_rx);
464 }
else if (argc == 3) {
465 if (strcasecmp(argv[1],
"setStartTime") == 0) {
468 }
else if (strcasecmp(argv[1],
"setSlotDuration") == 0) {
470 std::cout <<
"Fair mode is being used! Change to generic TDMA"
477 }
else if (strcasecmp(argv[1],
"setGuardTime") == 0) {
479 std::cout <<
"Fair mode is being used! Change to generic TDMA"
486 }
else if (strcasecmp(argv[1],
"setSlotNumber") == 0) {
489 }
else if (strcasecmp(argv[1],
"setMacAddr") == 0) {
490 addr = atoi(argv[2]);
492 cout <<
"TDMA MAC address of current node is " << addr
495 }
else if (strcasecmp(argv[1],
"setLogLabel") == 0) {
503 return MMac::command(argc, argv);
517 return MMac::recvSyncClMsg(m);
ClMessage_t CLMSG_UWMMAC_ENABLE
ClMsgUwMmacEnable should be and used to ask either to set or get the transmitting power of a specific...
Class that represent the binding of the protocol with tcl.
TDMAModuleClass()
Constructor of the TDMAGenericModule class.
TclObject * create(int, const char *const *)
Creates the TCL object needed for the tcl language interpretation.
virtual void expire(Event *e)
Method call when the timer expire.
Class that represents a TDMA Node.
std::string name_label_
label added in the log file, empty string by default
UwTDMA()
Constructor of the TDMA class.
virtual void recvFromUpperLayers(Packet *p)
Receive the packet from the upper layer (e.g.
virtual void initPkt(Packet *p)
Method called to add the MAC header size.
virtual void txData()
Transmit a data packet if in my slot.
int checkPriority
flag to set to 1 if UWCBR module uses packets with priority, set to 0 otherwise.
UWTDMA_STATUS transceiver_status
Variable holding the status enum type.
virtual void start(double delay)
Schedule the beginning of each TDMA cycle, each one after delay.
int tot_slots
Number of slots in the frame (fair_mode)
double guard_time
Guard time between slots.
int sea_trial_
Written log variable.
int max_packet_per_slot
max numer of packet it can transmit per slot
int drop_old_
flag to set the drop packet policy in case of buffer overflow: if 0 (default) drops the new packet,...
virtual void stateTxData()
Change transceiver status and and start to transmit if in my slot Used when there's spare time,...
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
virtual void rxPacketNotForMe(Packet *p)
Method called when the Packet received is determined to be not for me.
int debug_
Debug variable: 0 for no info, >-5 for small info, <-5 for complete info.
int max_queue_size
Maximum dimension of Queue.
int HDR_size
Size of the HDR if any.
int fair_mode
Fair modality on if 1: then only set tot_slots and common guard_time.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
UwTDMATimer tdma_timer
TDMA timer handler.
std::ofstream out_file_stats
File stream for the log file.
virtual ~UwTDMA()
Destructor of the TDMA class.
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
virtual void Mac2PhyStartTx(Packet *p)
Method called when the Mac Layer start to transmit a Packet.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the Mac Layer finish to transmit a Packet.
virtual void stop()
Terminate a TDMA cycle, essentially cancel the TDMA timer.
unsigned long int getEpoch()
Calculate the epoch of the event.
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
int packet_sent_curr_slot_
counter of packet has been sent in the current slot
double frame_duration
Frame duration.
double start_time
Time to wait before starting the protocol.
int slot_status
Is it my turn to transmit data?
virtual void changeStatus()
Alternate TDMA status between MY_STATUS and NOT_MY_STATUS.
double slot_duration
Slot duration.
std::deque< Packet * > buffer
Buffer of the MAC node.
int slot_number
set the position of the node in the frame (fair_mode) (starting from 0 to tot_slots-1)
hdr_uwcbr describes UWCBR packets.
char & priority()
Reference to the priority_ variable.
Provides the UWCBR packets header description and the definition of the class UWCBR.
TDMAModuleClass class_uwtdma
Provides the definition of the class UWTDMA.
#define UW_TDMA_STATUS_NOT_MY_SLOT
Status slot not active >
#define UW_TDMA_STATUS_MY_SLOT
Status slot active>