DESERT 3.5.1
Loading...
Searching...
No Matches
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 << this
340 << ": in constructor of CheckTimer which points to modem: "
341 << pmModem << std::endl;
342 }
343 }
344
345protected:
351 virtual void expire(Event *e);
352
356};
357
359 std::function<void(UwModem &, Packet *p)> f;
360 Packet *p;
361};
362
363#endif
The class used by UwModem to handle simulator's event expirations; it is exploited to schedule the re...
Definition uwmodem.h:326
UwModem * pmModem
Pointer to an UwModem object.
Definition uwmodem.h:353
virtual void expire(Event *e)
Method to handle the expiration of a given event.
Definition uwmodem.cpp:181
CheckTimer(UwModem *pmModem_)
Class constructor.
Definition uwmodem.h:334
Class that implements the interface to DESERT, as used through Tcl scripts.
Definition uwmodem.h:62
void setModemID(int ID)
Set the modem's ID number.
Definition uwmodem.h:162
void realTxEnded(Packet *p)
Method to call endTx from end of real packet transmission.
Definition uwmodem.h:219
LogLevel
Enum representing the amount of logs being generated ERROR: only errors will be generated INFO : gene...
Definition uwmodem.h:72
std::string log_suffix
Possibility to insert a log suffix.
Definition uwmodem.h:261
static bool string2log(const std::string &ll_string, LogLevel &ll)
Method that converts a string representing the loglevel into the enum type of loglevel.
Definition uwmodem.cpp:34
std::string modem_address
String containing the address needed to connect to the device In case of socket, it may be expressed ...
Definition uwmodem.h:252
UwModem()
UwModem constructor.
Definition uwmodem.cpp:69
virtual void stop()=0
Method that stops the driver operations.
virtual void recv(Packet *p)=0
Method that handles the reception of packets arriving from the upper layers of the network simulator.
std::queue< ModemEvent > event_q
Queue of events that are scheduled for NS2 to execute (callbacks)
Definition uwmodem.h:269
int getModemID()
Method that returns the current ID of the modem.
Definition uwmodem.h:172
static bool log2string(LogLevel ll, std::string &ll_string)
Method that converts an enum type of the loglevel into the string representing it.
Definition uwmodem.cpp:52
virtual void startTx(Packet *p)=0
Method that triggers the transmission of a packet through a specified modem.
virtual void endRx(Packet *p)=0
Method that ends a packet reception.
bool log_is_open
Flag to check if log file has already be opened.
Definition uwmodem.h:264
std::string logFile
Name of the disk-file where to write the interface's log messages.
Definition uwmodem.h:259
virtual void start()=0
Method that starts the driver operations.
virtual int recvSyncClMsg(ClMessage *m)=0
Cross-Layer messages synchronous interpreter.
void checkEvent()
Method to check if any event from real world has to go to ns.
Definition uwmodem.cpp:170
int MAX_READ_BYTES
Maximum number of bytes to be read by a single dump of data.
Definition uwmodem.h:245
int debug_
Usual debug value that chooses the debug level through Tcl interface.
Definition uwmodem.h:255
CheckTimer * checkTimer
Pointer to an object to schedule the "check-modem" events.
Definition uwmodem.h:265
LogLevel loglevel_
Log level on file, from ERROR (0) to DEBUG (2) in UwEvoLogicsS2CModem::logFile.
Definition uwmodem.h:262
std::queue< Packet * > tx_queue
Modem's transmission queue: holds packets that are to be transmitted.
Definition uwmodem.h:234
void printOnLog(LogLevel log_level, string module, string message)
Function that, given the appropriate level of log, prints to the set log file the provided log messag...
Definition uwmodem.cpp:102
virtual ~UwModem()
UwModem destructor.
Definition uwmodem.cpp:95
unsigned int DATA_BUFFER_LEN
Size of the buffer that holds data.
Definition uwmodem.h:242
virtual void endTx(Packet *p)
Method that ends a packet transmission.
Definition uwmodem.cpp:163
std::ofstream outLog
output strem to print into a disk-file log messages.
Definition uwmodem.h:257
virtual int getModulationType(Packet *P)
Method that should return the modulation type used for the packet being transmitted.
Definition uwmodem.h:152
int getDebug()
Method to return the flag used to enable debug messages.
Definition uwmodem.h:199
virtual int command(int argc, const char *const *argv)
Tcl command interpreter: Method that maps Tcl commands into C++ methods.
Definition uwmodem.cpp:127
virtual void startRx(Packet *p)=0
Method that starts a packet reception.
std::vector< char > data_buffer
Char buffer (vector) that holds data read from the modem (unparsed data) Main container for data rece...
Definition uwmodem.h:231
std::queue< Packet * > rx_queue
Modem's reception queue: holds packets eceived from the channel awaiting to be pushed up the stack.
Definition uwmodem.h:239
virtual double getTxDuration(Packet *p)
Method that returnd the duration of a given transmitted packet.
Definition uwmodem.h:139
int modemID
Number used for identification purposes: not specified.
Definition uwmodem.h:225
double period
Checking period of the modem's buffer.
Definition uwmodem.h:267
LogLevel getLogLevel()
Method to return the flag used to enable the printing of log messages in UwEvoLogicsS2CModem::logFile...
Definition uwmodem.h:189
std::string getLogFile()
Method to return the name of the file where to log messages.
Definition uwmodem.h:209
Header of the class providing the Uwal header's description.
std::function< void(UwModem &, Packet *p)> f
Definition uwmodem.h:359
Packet * p
Definition uwmodem.h:360
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.