DESERT 4.0.0
uwmodem.h
Go to the documentation of this file.
1//
2// Copyright (c) 2018 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
37#ifndef UWMODEM_H
38#define UWMODEM_H
39
40#include <iostream>
41#include <memory>
42#include <queue>
43#include <string>
44
45#include <functional>
46#include <hdr-uwal.h>
47#include <mac.h>
48#include <mphy.h>
49#include <tclcl.h>
50#include <uwal.h>
51#include <uwip-module.h>
52
53class CheckTimer;
54struct ModemEvent;
61class UwModem : public MPhy
62{
63 friend class CheckTimer;
64
65public:
72 enum class LogLevel { ERROR = 0, INFO = 1, DEBUG = 2 };
73
81 static bool string2log(const std::string &ll_string, LogLevel &ll);
82
90 static bool log2string(LogLevel ll, std::string &ll_string);
91
96 UwModem();
97
101 virtual ~UwModem();
102
109 virtual void recv(Packet *p) = 0;
110
120 virtual int command(int argc, const char *const *argv);
121
129 virtual int recvSyncClMsg(ClMessage *m) = 0;
130
138 virtual double
139 getTxDuration(Packet *p)
140 {
141 return -1.0;
142 }
143
151 virtual int
153 {
154 return 0;
155 }
156
161 void
163 {
164 modemID = ID;
165 }
166
171 int
173 {
174 return modemID;
175 }
176
181 void printOnLog(LogLevel log_level, string module, string message);
182
190 {
191 return loglevel_;
192 }
193
198 int
200 {
201 return debug_;
202 }
203
208 std::string
210 {
211 return logFile + std::to_string(modemID) + log_suffix;
212 }
213
218 void
219 realTxEnded(Packet *p)
220 {
221 endTx(p);
222 }
223
224protected:
231 std::vector<char> data_buffer;
232
234 std::queue<Packet *> tx_queue;
235
239 std::queue<Packet *> rx_queue;
240
242 unsigned int DATA_BUFFER_LEN;
243
246
252 std::string modem_address;
253
256
257 std::ofstream outLog;
259 std::string logFile;
261 std::string log_suffix;
267 double period;
269 std::queue<ModemEvent> event_q;
270
276 virtual void startTx(Packet *p) = 0;
277
284 virtual void endTx(Packet *p);
285
292 virtual void startRx(Packet *p) = 0;
293
299 virtual void endRx(Packet *p) = 0;
300
305 virtual void start() = 0;
306
312 virtual void stop() = 0;
313
317 void checkEvent();
318};
319
325class CheckTimer : public TimerHandler
326{
327public:
335 : TimerHandler()
336 {
337 pmModem = pmModem_;
338 if (pmModem->getDebug() >= 2) {
339 std::cout
340 << this
341 << ": in constructor of CheckTimer which points to modem: "
342 << pmModem << std::endl;
343 }
344 }
345
346protected:
352 virtual void expire(Event *e);
353
357};
358
360 std::function<void(UwModem &, Packet *p)> f;
361 Packet *p;
362};
363
364#endif
Definition uwmodem.h:326
UwModem * pmModem
Definition uwmodem.h:354
virtual void expire(Event *e)
Definition uwmodem.cpp:181
CheckTimer(UwModem *pmModem_)
Definition uwmodem.h:334
Definition uwmodem.h:62
void setModemID(int ID)
Definition uwmodem.h:162
void realTxEnded(Packet *p)
Definition uwmodem.h:219
LogLevel
Definition uwmodem.h:72
std::string log_suffix
Definition uwmodem.h:261
static bool string2log(const std::string &ll_string, LogLevel &ll)
Definition uwmodem.cpp:34
std::string modem_address
Definition uwmodem.h:252
UwModem()
Definition uwmodem.cpp:69
virtual void stop()=0
virtual void recv(Packet *p)=0
std::queue< ModemEvent > event_q
Definition uwmodem.h:269
int getModemID()
Definition uwmodem.h:172
static bool log2string(LogLevel ll, std::string &ll_string)
Definition uwmodem.cpp:52
virtual void startTx(Packet *p)=0
virtual void endRx(Packet *p)=0
bool log_is_open
Definition uwmodem.h:264
std::string logFile
Definition uwmodem.h:259
virtual void start()=0
virtual int recvSyncClMsg(ClMessage *m)=0
void checkEvent()
Definition uwmodem.cpp:170
int MAX_READ_BYTES
Definition uwmodem.h:245
int debug_
Definition uwmodem.h:255
CheckTimer * checkTimer
Definition uwmodem.h:265
LogLevel loglevel_
Definition uwmodem.h:262
std::queue< Packet * > tx_queue
Definition uwmodem.h:234
void printOnLog(LogLevel log_level, string module, string message)
Definition uwmodem.cpp:102
virtual ~UwModem()
Definition uwmodem.cpp:95
unsigned int DATA_BUFFER_LEN
Definition uwmodem.h:242
virtual void endTx(Packet *p)
Definition uwmodem.cpp:163
std::ofstream outLog
Definition uwmodem.h:257
virtual int getModulationType(Packet *P)
Definition uwmodem.h:152
int getDebug()
Definition uwmodem.h:199
virtual int command(int argc, const char *const *argv)
Definition uwmodem.cpp:127
virtual void startRx(Packet *p)=0
std::vector< char > data_buffer
Definition uwmodem.h:231
std::queue< Packet * > rx_queue
Definition uwmodem.h:239
virtual double getTxDuration(Packet *p)
Definition uwmodem.h:139
int modemID
Definition uwmodem.h:225
double period
Definition uwmodem.h:267
LogLevel getLogLevel()
Definition uwmodem.h:189
std::string getLogFile()
Definition uwmodem.h:209
Header of the class providing the Uwal header's description.
Definition uwmodem.h:359
std::function< void(UwModem &, Packet *p)> f
Definition uwmodem.h:360
Packet * p
Definition uwmodem.h:361
log_level
Definition uw-csma-ca.h:86
Header of the main class that implements the adaptation layer between ns2/NS-Miracle and binary data ...
Provides the UWIP packets header description. Definition of the class that define the network layer.