DESERT 3.5.1
Loading...
Searching...
No Matches
DESERT_Addons/uwmphy_modem/uwmphy_modem.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
38#ifndef UWMPHY_MODEM_H
39#define UWMPHY_MODEM_H
40
41#include "uwmdriver.h"
42#include <uwal.h>
43#include <hdr-uwal.h>
44#include <uwip-module.h>
45#include <mac.h>
46#include <mphy.h>
47
48#include <stdlib.h>
49#include <iostream>
50#include <stdio.h>
51#include <fstream>
52#include <string.h>
53#include <errno.h>
54#include <cstring>
55#include <sstream>
56#include <sys/types.h>
57#include <sys/stat.h>
58#include <fcntl.h>
59#include <unistd.h>
60#include <cmath>
61#include <time.h>
62
63#define _MTBL \
64 5
67#define MIN_MODEM_QUEUE_LENGTH 2
68#define MAX_MODEM_QUEUE_LENGTH 30
69
70
71
72// Forward declaration
73class DropTimer;
74class CheckTimer;
75
86class UWMPhy_modem : public MPhy
87{
93 friend class CheckTimer;
94
95 friend class DropTimer;
96
97public:
104 UWMPhy_modem(std::string);
105
110
118 virtual void recv(Packet *);
119
128 virtual int command(int, const char *const *);
129
130 virtual int recvSyncClMsg(ClMessage *m) = 0;
136 inline int
138 {
139 return ID;
140 }
147 inline double
149 {
150 return period;
151 }
152
159 std::string
161 {
162 return pToDevice;
163 }
164
165 uint
167 {
168 return queue_length;
169 }
170
176 int
178 {
179 return debug_;
180 }
186 std::string
188 {
189 return logFile;
190 }
191
200 {
201 return (log_level_t) loglevel_;
202 }
203
208 inline unsigned long int
210 {
211 return time(NULL);
212 }
213
223 void updatePktRx(Packet *);
224
225protected:
231
232 int ID;
234 double period;
235 Packet *modemTxBuff[_MTBL];
239 int t;
241 Packet *PktRx;
242 std::string pToDevice;
245 int debug_;
247 std::ofstream outLog;
249 std::string logFile;
251 char *log_suffix;
252 int loglevel_;
254 int SetModemID;
256 uint queue_length;
257
272
279 virtual void start();
280
286 virtual void stop();
287
299
306 virtual void startTx(Packet *);
307
316 virtual void endTx(Packet *);
317
326 virtual void startRx(Packet *);
327
335 virtual void endRx(Packet *);
336
343 Packet *popTxBuff();
344
352 virtual inline double
353 getTxDuration(Packet *p)
354 {
355 }
356
365 virtual inline int
367 {
368 }
369};
370
376class CheckTimer : public TimerHandler
377{
378public:
386 : TimerHandler()
387 {
388 pmModem = pmModem_;
389 if (pmModem->getDebug() >= 2) {
390 cout << this
391 << ": in constructor of CheckTimer which points to modem: "
392 << pmModem << "\n";
393 }
394 }
395
396protected:
402 virtual void expire(Event *e);
403
408};
409
410class DropTimer : public TimerHandler
411{
412public:
414 : TimerHandler()
415 {
416 pModem = pModem_;
417 }
418
419protected:
420 virtual void expire(Event *e);
422};
423
424#endif /* UWMPHY_MODEM_H */
#define _MTBL
Defintion of the maximum length of the transmission buffer to store \ packets at the interface level.
Header of the class needed by UWMPhy_modem to handle the different transmissions cases and correspond...
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.
CheckTimer(UWMPhy_modem *pmModem_)
Class constructor.
virtual void expire(Event *e)
The main class implementing the module used to implement the interface between ns2/NS-Miracle and rea...
virtual double getTxDuration(Packet *p)
Method to get the transmission duration for a given packet.
Packet * popTxBuff()
Method to pop the oldest packet in the TX buffer or to delete after a tx or to drop it.
unsigned long int getEpoch()
Calculate the epoch of the event.
std::ofstream outLog
output strem to print into a disk-file log messages.
virtual void startRx(Packet *)
Method to start a packet reception.
virtual void endTx(Packet *)
Method to end a packet transmission.
int debug_
Flag to enable debug mode (i.e., printing of debug messages) if set to 1.
char * log_suffix
Possibility to insert a log suffix.
CheckTimer * pcheckTmr
Pointer to an object to schedule the "check-modem" events.
virtual int getModulationType(Packet *p)
Method to get the modulation type used to transmit/receive a given packet.
UWMdriver * pmDriver
Pointer to an object to drive the modem operations.
std::string getLogFile()
Method to return the name of the file where to log messages.
virtual modem_state_t check_modem()=0
Modem checker.
UWMPhy_modem(std::string)
Class constructor.
virtual int recvSyncClMsg(ClMessage *m)=0
std::string getPathToDevice()
Method to return the path to the device to be connect with the network simulator.
log_level_t getLogLevel()
Method to return the flag used to enable the printing of log messages in UWMPhy_modem::logFile.
int getID()
Method to return the node ID.
double period
Checking period of the modem's buffer.
virtual void start()
Connection starter.
virtual void endRx(Packet *)
Method to end a packet reception.
~UWMPhy_modem()
Class destructor.
virtual void stop()
Connection stopper.
int SetModemID
Flag to indicate if the interface has to force the modem to have the ID indicated in the tcl script.
Packet * modemTxBuff[_MTBL]
Transmission buffer to store packets that cannot be sent immediately because the real acoustic modem ...
Packet * PktRx
Transmission buffer's index; it must be in {-1, 0, 1, ..., _MTBL-1}.
virtual int command(int, const char *const *)
Method to map tcl commands into c++ methods.
std::string logFile
Name of the disk-file where to write the interface's log messages.
int loglevel_
Log level on file, from ERROR (0) to DEBUG (2) in UWMPhy_modem::logFile.
std::string pToDevice
A string containing the path to the device to be connected with the network simulator.
virtual void recv(Packet *)
Method to handle the reception of packets arriving from the upper layers of the network simulator.
virtual void startTx(Packet *)
Method to send to an UWMdriver object the packet to be transmitted, see UWMdriver::modemTx().
double getPeriod()
Method to return the checking period of the modem (i.e., the time interval between two succesive chec...
int getDebug()
Method to return the flag used to enable debug messages.
void setConnections(CheckTimer *, UWMdriver *, DropTimer *)
Link connector.
void updatePktRx(Packet *)
Method to update the value of the pointer to the last received packet.
The class needed by UWMPhy_modem to handle the different transmissions cases and corresponding protoc...
int getDebug()
Method to return the flag used to enable debug messages.
Definition uwmodem.h:199
Header of the class providing the Uwal header's description.
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.