DESERT 3.5.1
Loading...
Searching...
No Matches
uw-csma-aloha-trigger-sink.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
39#ifndef UW_CSMA_UW_CS_ALOHA_TRIG_SINK_TRIGGER_SINK_H
40#define UW_CSMA_UW_CS_ALOHA_TRIG_SINK_TRIGGER_SINK_H
41
42#include "mmac.h"
43#include "mphy.h"
44#include "mac.h"
45
46#include <iostream>
47
48#define UW_CS_ALOHA_TRIG_SINK_DROP_REASON_WRONG_RECEIVER \
49 "WRCV"
50#define UW_CS_ALOHA_TRIG_SINK_DROP_REASON_UNKNOWN_TYPE \
51 "UPT"
52#define UW_CS_ALOHA_TRIG_SINK_DROP_REASON_ERROR "ERR"
53#define UW_CS_ALOHA_TRIG_SINK_DROP_REASON_RECEIVING_NOT_ENABLED \
54 "RNE"
56extern packet_t PT_MMAC_TRIGGER;
57
61class UwCsmaAloha_Trigger_SINK : public MMac
62{
63public:
82 virtual int command(int argc, const char *const *argv);
90 virtual int crLayCommand(ClMessage *m);
91
92protected:
102
112
120
124 class GenericTimer : public TimerHandler
125 {
126 public:
132 : TimerHandler()
133 , start_time(0.0)
134 , left_duration(0.0)
135 , counter(0)
136 , module(m)
138 {
139 assert(m != NULL);
140 }
141
146 {
147 }
148
152 virtual void
154 {
156 left_duration -= (NOW - start_time);
157 if (left_duration <= 0.0)
158 left_duration = module->mac2phy_delay_;
159 force_cancel();
161 }
162
167 virtual void
169 {
171 start_time = NOW;
172 assert(left_duration > 0);
173 sched(left_duration);
175 }
176
180 virtual void
182 {
184 force_cancel();
185 }
186
191 virtual void
192 schedule(double val)
193 {
194 start_time = NOW;
195 left_duration = val;
197 resched(val);
198 }
199
204 bool
206 {
208 }
209
214 bool
219
224 bool
229
234 bool
236 {
238 }
239
244 bool
250
254 void
256 {
257 counter = 0;
258 }
259
263 void
265 {
266 ++counter;
267 }
268
273 int
275 {
276 return counter;
277 }
278
283 double
285 {
286 return left_duration;
287 }
288
289 protected:
290 double start_time;
297 *module;
300 };
301
306 {
307 public:
317
322 {
323 }
324
325 protected:
330 virtual void expire(Event *e);
331 };
337 virtual void recvFromUpperLayers(Packet *p);
342 virtual void Mac2PhyStartTx(Packet *p);
347 virtual void Phy2MacEndTx(const Packet *p);
352 virtual void Phy2MacStartRx(const Packet *p);
357 virtual void Phy2MacEndRx(Packet *p);
363 virtual void initPkt(Packet *p, int dest_addr = 0);
364
368 virtual void stateIdle();
372 virtual void stateEnableRx();
376 virtual void stateDisableRx();
377
382 virtual void stateTxTRIGGER();
386 virtual void txTRIGGER(Packet *p);
390 virtual void stateRxData(Packet *p);
394 virtual void stateRxPacketNotForMe(Packet *p);
399 inline void
401 {
402 curr_state = state;
403 }
404
408 inline void
413
418 inline int
420 {
421 return trigger_pkts_tx;
422 }
423
427 virtual void waitForUser();
428
432 virtual void
434 {
435 up_data_pkts_rx++;
436 }
437
441 inline void
446
466};
467
468#endif
Class that describes the timers in the node.
UwCsmaAloha_Trigger_SINK *UW_CS_ALOHA_TRIG_SINK_TIMER_STATUS timer_status
< Pointer to an object of type CsmaAloha
bool isRunning()
checks if the timer is RUNNING
double getDuration()
Returns the left duration of the timer.
bool isExpired()
Checks if the timer is EXPIRED.
virtual ~GenericTimer()
Destructor of the GenericTimer class.
void incrCounter()
Increments the counter of the timer.
double left_duration
Left duration of the timer.
virtual void schedule(double val)
schedule a timer
bool isActive()
Checks if the timer is ACTIVE.
void resetCounter()
Resets the counter of the timer.
bool isFrozen()
Checks if the timer is FROZEN.
GenericTimer(UwCsmaAloha_Trigger_SINK *m)
Constructor of the GenericTimer class.
int getCounter()
Returns the counter of the timer.
virtual void unFreeze()
unFreezes is used to resume the timer starting from the point where it was freezed
Class used to handle the timer of the reception period.
virtual void expire(Event *e)
Method called when the timer expire.
ReceiveTimer(UwCsmaAloha_Trigger_SINK *m)
Conscructor of ReceiveTimer class.
virtual ~ReceiveTimer()
Descructor of ReceiveTimer class.
Class that describes a UwCsmaAloha_Trigger_SINK module.
virtual void Phy2MacEndTx(const Packet *p)
Method called when the PHY layers finishes to transmit packet.
UW_CS_ALOHA_TRIG_SINK_STATUS curr_state
Current state of the protocol.
void refreshReason(UW_CS_ALOHA_TRIG_SINK_REASON_STATUS reason)
Refresh the reason for the change of state.
virtual void recvFromUpperLayers(Packet *p)
Receives the packet from the upper layer (e.g.
int TRIGGER_size
Size of the TRIGGER packet.
virtual void Phy2MacStartRx(const Packet *p)
Method called when the PHY layer begins to receive a packet.
bool receiving_state_active
True if the sink is allowed to receive data packet.
int buffer_pkts
Length of data packet queue.
void incrTRIGGERPacketTx()
Increment the number of TRIGGER packets transmitted.
int getTriggerMsgSent()
Return the number of TRIGGER packets sent over the simulation.
ReceiveTimer receive_timer
timer of receive state
double tx_timer_duration
Duration of the timer in which one node is allowed to transmit.
UW_CS_ALOHA_TRIG_SINK_STATUS
< Variable that rapresent the status of the protocol machine state
virtual void stateRxData(Packet *p)
The sink receives a DATA packet from a node.
virtual void initPkt(Packet *p, int dest_addr=0)
Init the headers of the packet in transmission.
virtual void stateRxPacketNotForMe(Packet *p)
The destination address of the packet is not equal to the sink's address.
virtual void txTRIGGER(Packet *p)
Transmit the TRIGGER packet.
virtual void waitForUser()
Used for debug purposes.
virtual void stateTxTRIGGER()
The sink transmit the TRIGGER packet to begin the neighbour discovery phase.
virtual void stateIdle()
State IDLE of the protocol.
int trigger_pkts_tx
Number of TRIGGER packet received.
UW_CS_ALOHA_TRIG_SINK_REASON_STATUS last_reason
Last reason of the state change of the protocol.
virtual ~UwCsmaAloha_Trigger_SINK()
Destructor of the UwCsmaAloha_Trigger_SINK class.
virtual int crLayCommand(ClMessage *m)
Cross-Layer messages interpreter.
void refreshState(UW_CS_ALOHA_TRIG_SINK_STATUS state)
Refresh the state of the protocol.
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
virtual void stateDisableRx()
The sink is not allowed to receive the packet from a certain node anymore.
virtual void Phy2MacEndRx(Packet *p)
Method called when the PHY layer finishes to receive a packet.
virtual void incrUpperDataRx()
Increment the number of Data received from upper layers.
virtual void stateEnableRx()
State in which the sink is enabled to receive packets.
UwCsmaAloha_Trigger_SINK()
Constructor of the UwCsmaAloha_Trigger_SINK class.
UW_CS_ALOHA_TRIG_SINK_STATUS prev_state
Previous state of the protocol.
std::pair< int, int > counter
counter of collisions