DESERT 4.0.0
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 <map>
44#include <string>
45
46#define UWJAMMER_DROP_REASON_BUFFER_FULL "DBF"
47#define UWJAMMER_DROP_REASON_JAMMER_PROTOCOL "DJP"
52class Uwjammer : public MMac
53{
54public:
58 Uwjammer();
59
63 virtual ~Uwjammer() = default;
64
75 virtual int command(int argc, const char *const *argv) override;
76
84 virtual int crLayCommand(ClMessage *m) override;
85
86protected:
90 enum class JammerStatus { IDLE = 1, BUSY };
91
97 virtual void recvFromUpperLayers(Packet *p) override;
98
103 virtual void txJam();
104
110 virtual void Mac2PhyStartTx(Packet *p);
111
117 virtual void Phy2MacEndTx(const Packet *p) override;
118
122 virtual void stateIdle();
123
129 virtual void Phy2MacEndRx(Packet *p) override;
130
135 inline int
137 {
138 return n_jam_sent;
139 }
140
146 inline int
148 {
149 return n_jam_discarded;
150 }
151
157 inline int
159 {
160 return n_data_discarded;
161 }
162
167 inline virtual void
169 {
170 curr_state = state;
171 }
172
174 uint node_id;
176 size_t n_jam_sent;
182 std::queue<Packet *> Q_data;
185 static const std::map<JammerStatus, std::string>
188 constexpr static const int MAX_BUFFER_SIZE =
189 100;
190};
191
192#endif /* UWJAMMER_H */
Definition uwjammer.h:53
int getJamSent() const
Definition uwjammer.h:136
int getJamDiscarded() const
Definition uwjammer.h:147
size_t n_data_discarded
Definition uwjammer.h:179
JammerStatus curr_state
Definition uwjammer.h:184
virtual void txJam()
Definition uwjammer.cpp:167
size_t n_jam_sent
Definition uwjammer.h:176
JammerStatus
Definition uwjammer.h:90
int buffer_data_pkts
Definition uwjammer.h:173
std::queue< Packet * > Q_data
Definition uwjammer.h:182
int getDataDiscarded() const
Definition uwjammer.h:158
uint JAMMER_uid
Definition uwjammer.h:175
virtual void Phy2MacEndRx(Packet *p) override
Definition uwjammer.cpp:221
virtual int crLayCommand(ClMessage *m) override
Definition uwjammer.cpp:134
uint node_id
Definition uwjammer.h:174
virtual ~Uwjammer()=default
virtual void stateIdle()
Definition uwjammer.cpp:214
virtual int command(int argc, const char *const *argv) override
Definition uwjammer.cpp:92
static constexpr const int MAX_BUFFER_SIZE
Definition uwjammer.h:188
size_t n_jam_discarded
Definition uwjammer.h:177
virtual void recvFromUpperLayers(Packet *p) override
Definition uwjammer.cpp:143
Packet * curr_data_pkt
Definition uwjammer.h:181
static const std::map< JammerStatus, std::string > status_info
Definition uwjammer.h:44
virtual void Mac2PhyStartTx(Packet *p)
Definition uwjammer.cpp:190
Uwjammer()
Definition uwjammer.cpp:73
virtual void Phy2MacEndTx(const Packet *p) override
Definition uwjammer.cpp:201
virtual void refreshState(JammerStatus state)
Definition uwjammer.h:168