DESERT 3.5.1
Loading...
Searching...
No Matches
uwjammer.h
Go to the documentation of this file.
1//
2// Copyright (c) 2024 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 UWJAMMER_H
40#define UWJAMMER_H
41
42#include "mmac.h"
43#include <string>
44#include <map>
45
46#define UWJAMMER_DROP_REASON_BUFFER_FULL\
47 "DBF"
48#define UWJAMMER_DROP_REASON_JAMMER_PROTOCOL \
49 "DJP"
54class Uwjammer : public MMac
55{
56public:
60 Uwjammer();
61
65 virtual ~Uwjammer() = default;
66
77 virtual int command(int argc, const char *const *argv) override;
78
86 virtual int crLayCommand(ClMessage *m) override;
87
88protected:
89
93 enum class JammerStatus { IDLE = 1, BUSY };
94
100 virtual void recvFromUpperLayers(Packet *p) override;
101
106 virtual void txJam();
107
113 virtual void Mac2PhyStartTx(Packet *p);
114
120 virtual void Phy2MacEndTx(const Packet *p) override;
121
125 virtual void stateIdle();
126
127
133 virtual void Phy2MacEndRx(Packet *p) override;
134
139 inline int
140 getJamSent() const { return n_jam_sent; }
141
146 inline int
148
153 inline int
155
160 inline virtual void
162
164 uint node_id;
166 size_t n_jam_sent;
171 std::queue<Packet *> Q_data;
174 static const std::map<JammerStatus, std::string> status_info;
176 constexpr static const int MAX_BUFFER_SIZE = 100;
177};
178
179#endif /* UWJAMMER_H */
Class that describes a Uwjammer module.
Definition uwjammer.h:55
int getJamSent() const
Returns the number of packets sent during the simulation.
Definition uwjammer.h:140
int getJamDiscarded() const
Returns the number of packets discarded during the simulation because the buffer is full.
Definition uwjammer.h:147
size_t n_data_discarded
Number of packets received and discarded.
Definition uwjammer.h:168
JammerStatus curr_state
Current state of the protocol.
Definition uwjammer.h:173
virtual void txJam()
Transmits the jam packet (calling Mac2PhyStartTx) and increment the counter of transmitted jam packet...
Definition uwjammer.cpp:167
size_t n_jam_sent
Number of packets sent.
Definition uwjammer.h:166
JammerStatus
Enum that rapresents the status of the protocol machine state.
Definition uwjammer.h:93
int buffer_data_pkts
Size of the buffer in number of packets.
Definition uwjammer.h:163
std::queue< Packet * > Q_data
Queue of DATA in number of packets.
Definition uwjammer.h:171
int getDataDiscarded() const
Returns the number of packets received and discarded during the simulation.
Definition uwjammer.h:154
uint JAMMER_uid
JAMMER Unique ID.
Definition uwjammer.h:165
virtual void Phy2MacEndRx(Packet *p) override
Method called when the Phy Layer finish to receive a Packet.
Definition uwjammer.cpp:221
virtual int crLayCommand(ClMessage *m) override
Cross-Layer messages interpreter.
Definition uwjammer.cpp:134
uint node_id
Unique Node ID.
Definition uwjammer.h:164
virtual ~Uwjammer()=default
Destructor of the class.
virtual void stateIdle()
IDLE state, check if there is at least one more packet to transmit.
Definition uwjammer.cpp:214
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
Definition uwjammer.cpp:92
static constexpr const int MAX_BUFFER_SIZE
Maximum size of the queue in number of packets.
Definition uwjammer.h:176
size_t n_jam_discarded
Number of packets discarded because the buffer is full.
Definition uwjammer.h:167
virtual void recvFromUpperLayers(Packet *p) override
Receives the packet from the upper layer (e.g.
Definition uwjammer.cpp:143
Packet * curr_data_pkt
Pointer to the current DATA packet.
Definition uwjammer.h:170
static const std::map< JammerStatus, std::string > status_info
Textual info of the state.
Definition uwjammer.h:44
virtual void Mac2PhyStartTx(Packet *p)
Pass the packet to the PHY layer.
Definition uwjammer.cpp:190
Uwjammer()
Constructor of the class.
Definition uwjammer.cpp:73
virtual void Phy2MacEndTx(const Packet *p) override
Method called when the PHY layer finish to transmit the packet.
Definition uwjammer.cpp:201
virtual void refreshState(JammerStatus state)
Refresh the state of the protocol.
Definition uwjammer.h:161