DESERT 3.5.1
Loading...
Searching...
No Matches
uwtdma.h
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
40#ifndef UWTDMA_H
41#define UWTDMA_H
42
43#include <mmac.h>
44#include <queue>
45#include <deque>
46#include <iostream>
47#include <assert.h>
48#include <sstream>
49#include <fstream>
50#include <sys/time.h>
51
52#define UW_TDMA_STATUS_MY_SLOT 1
53#define UW_TDMA_STATUS_NOT_MY_SLOT 2
57class UwTDMA;
58
64class UwTDMATimer : public TimerHandler
65{
66
67public:
73 : TimerHandler()
74 {
75 assert(m != NULL);
76 module = m;
77 }
78
79protected:
84 virtual void expire(Event *e);
85 UwTDMA *module;
86};
87
91class UwTDMA : public MMac
92{
93
94 friend class UwTDMATimer;
95
96public:
100 UwTDMA();
101
105 virtual ~UwTDMA();
106
107
114 virtual int recvSyncClMsg(ClMessage* m);
115
116protected:
120 virtual void txData();
125 virtual void stateTxData();
129 virtual void changeStatus();
134 virtual void start(double delay);
138 virtual void stop();
144 virtual void recvFromUpperLayers(Packet *p);
150 virtual void Phy2MacEndRx(Packet *p);
156 virtual void Phy2MacStartRx(const Packet *p);
162 virtual void Mac2PhyStartTx(Packet *p);
168 virtual void Phy2MacEndTx(const Packet *p);
174 virtual void rxPacketNotForMe(Packet *p);
180 virtual void initPkt(Packet *p);
185 inline unsigned long int
187 {
188 return time(NULL);
189 }
190
202 virtual int command(int argc, const char *const *argv);
207
211 int debug_;
223 double guard_time;
225 double start_time;
227 std::deque<Packet *> buffer;
228 std::ofstream out_file_stats;
229 bool enable;
230
237 std::string name_label_;
240};
241
242#endif
UwTDMATimer class is used to handle the scheduling period of UWTDMA slots.
Definition uwtdma.h:65
UwTDMATimer(UwTDMA *m)
Costructor of the class UwTDMATimer.
Definition uwtdma.h:72
virtual void expire(Event *e)
Method call when the timer expire.
Definition uwtdma.cpp:74
Class that represents a TDMA Node.
Definition uwtdma.h:92
std::string name_label_
label added in the log file, empty string by default
Definition uwtdma.h:237
UwTDMA()
Constructor of the TDMA class.
Definition uwtdma.cpp:79
virtual void recvFromUpperLayers(Packet *p)
Receive the packet from the upper layer (e.g.
Definition uwtdma.cpp:145
virtual void initPkt(Packet *p)
Method called to add the MAC header size.
Definition uwtdma.cpp:341
virtual void txData()
Transmit a data packet if in my slot.
Definition uwtdma.cpp:203
int checkPriority
flag to set to 1 if UWCBR module uses packets with priority, set to 0 otherwise.
Definition uwtdma.h:238
UWTDMA_STATUS transceiver_status
Variable holding the status enum type.
Definition uwtdma.h:209
virtual void start(double delay)
Schedule the beginning of each TDMA cycle, each one after delay.
Definition uwtdma.cpp:389
int tot_slots
Number of slots in the frame (fair_mode)
Definition uwtdma.h:217
double guard_time
Guard time between slots.
Definition uwtdma.h:223
int sea_trial_
Written log variable.
Definition uwtdma.h:213
int max_packet_per_slot
max numer of packet it can transmit per slot
Definition uwtdma.h:232
int drop_old_
flag to set the drop packet policy in case of buffer overflow: if 0 (default) drops the new packet,...
Definition uwtdma.h:235
virtual void stateTxData()
Change transceiver status and and start to transmit if in my slot Used when there's spare time,...
Definition uwtdma.cpp:195
virtual void Phy2MacStartRx(const Packet *p)
Method called when the Phy Layer start to receive a Packet.
Definition uwtdma.cpp:271
virtual void rxPacketNotForMe(Packet *p)
Method called when the Packet received is determined to be not for me.
Definition uwtdma.cpp:352
int debug_
Debug variable: 0 for no info, >-5 for small info, <-5 for complete info.
Definition uwtdma.h:211
int max_queue_size
Maximum dimension of Queue.
Definition uwtdma.h:231
int HDR_size
Size of the HDR if any.
Definition uwtdma.h:221
int fair_mode
Fair modality on if 1: then only set tot_slots and common guard_time.
Definition uwtdma.h:214
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
Definition uwtdma.cpp:423
UwTDMATimer tdma_timer
TDMA timer handler.
Definition uwtdma.h:226
std::ofstream out_file_stats
File stream for the log file.
Definition uwtdma.h:228
virtual ~UwTDMA()
Destructor of the TDMA class.
Definition uwtdma.cpp:140
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
Definition uwtdma.cpp:507
virtual void Mac2PhyStartTx(Packet *p)
Method called when the Mac Layer start to transmit a Packet.
Definition uwtdma.cpp:236
virtual void Phy2MacEndTx(const Packet *p)
Method called when the Mac Layer finish to transmit a Packet.
Definition uwtdma.cpp:258
virtual void stop()
Terminate a TDMA cycle, essentially cancel the TDMA timer.
Definition uwtdma.cpp:412
unsigned long int getEpoch()
Calculate the epoch of the event.
Definition uwtdma.h:186
bool enable
Definition uwtdma.h:229
virtual void Phy2MacEndRx(Packet *p)
Method called when the Phy Layer finish to receive a Packet.
Definition uwtdma.cpp:281
int packet_sent_curr_slot_
counter of packet has been sent in the current slot
Definition uwtdma.h:233
double frame_duration
Frame duration.
Definition uwtdma.h:222
double start_time
Time to wait before starting the protocol.
Definition uwtdma.h:225
int slot_status
Is it my turn to transmit data?
Definition uwtdma.h:210
virtual void changeStatus()
Alternate TDMA status between MY_STATUS and NOT_MY_STATUS.
Definition uwtdma.cpp:359
UWTDMA_STATUS
Enumeration class of UWTDMA status.
Definition uwtdma.h:206
@ RECEIVING
Definition uwtdma.h:206
@ TRANSMITTING
Definition uwtdma.h:206
@ IDLE
Definition uwtdma.h:206
double slot_duration
Slot duration.
Definition uwtdma.h:224
std::deque< Packet * > buffer
Buffer of the MAC node.
Definition uwtdma.h:227
int slot_number
set the position of the node in the frame (fair_mode) (starting from 0 to tot_slots-1)
Definition uwtdma.h:218