DESERT 4.0.0
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 <hdr-uwal.h>
43#include <mac.h>
44#include <mphy.h>
45#include <uwal.h>
46#include <uwip-module.h>
47
48#include <cmath>
49#include <cstring>
50#include <errno.h>
51#include <fcntl.h>
52#include <fstream>
53#include <iostream>
54#include <sstream>
55#include <stdio.h>
56#include <stdlib.h>
57#include <string.h>
58#include <sys/stat.h>
59#include <sys/types.h>
60#include <time.h>
61#include <unistd.h>
62
63#define _MTBL \
64 5
67#define MIN_MODEM_QUEUE_LENGTH 2
68#define MAX_MODEM_QUEUE_LENGTH 30
69
70// Forward declaration
71class DropTimer;
72class CheckTimer;
73
84class UWMPhy_modem : public MPhy
85{
91 friend class CheckTimer;
92
93 friend class DropTimer;
94
95public:
102 UWMPhy_modem(std::string);
103
108
116 virtual void recv(Packet *);
117
126 virtual int command(int, const char *const *);
127
128 virtual int recvSyncClMsg(ClMessage *m) = 0;
134 inline int
136 {
137 return ID;
138 }
145 inline double
147 {
148 return period;
149 }
150
157 std::string
159 {
160 return pToDevice;
161 }
162
163 uint
165 {
166 return queue_length;
167 }
168
174 int
176 {
177 return debug_;
178 }
184 std::string
186 {
187 return logFile;
188 }
189
198 {
199 return (log_level_t) loglevel_;
200 }
201
206 inline unsigned long int
208 {
209 return time(NULL);
210 }
211
221 void updatePktRx(Packet *);
222
223protected:
229
230 int ID;
232 double period;
233 Packet *modemTxBuff[_MTBL];
237 int t;
239 Packet *PktRx;
240 std::string pToDevice;
243 int debug_;
245 std::ofstream outLog;
247 std::string logFile;
249 char *log_suffix;
250 int loglevel_;
252 int SetModemID;
254 uint queue_length;
255
270
277 virtual void start();
278
284 virtual void stop();
285
297
304 virtual void startTx(Packet *);
305
314 virtual void endTx(Packet *);
315
324 virtual void startRx(Packet *);
325
333 virtual void endRx(Packet *);
334
341 Packet *popTxBuff();
342
350 virtual inline double
351 getTxDuration(Packet *p)
352 {
353 }
354
363 virtual inline int
365 {
366 }
367};
368
374class CheckTimer : public TimerHandler
375{
376public:
384 : TimerHandler()
385 {
386 pmModem = pmModem_;
387 if (pmModem->getDebug() >= 2) {
388 cout << this
389 << ": in constructor of CheckTimer which points to modem: "
390 << pmModem << "\n";
391 }
392 }
393
394protected:
400 virtual void expire(Event *e);
401
406};
407
408class DropTimer : public TimerHandler
409{
410public:
412 : TimerHandler()
413 {
414 pModem = pModem_;
415 }
416
417protected:
418 virtual void expire(Event *e);
420};
421
422#endif /* UWMPHY_MODEM_H */
enum MODEM_STATES modem_state_t
Definition uwmdriver.h:79
enum LOG_LEVEL log_level_t
Definition uwmdriver.h:77
Definition uwmodem.h:326
UwModem * pmModem
Definition uwmodem.h:354
virtual void expire(Event *e)
CheckTimer(UWMPhy_modem *pmModem_)
Definition uwmphy_modem.h:383
Definition uwmphy_modem.h:409
virtual void expire(Event *e)
UWMPhy_modem * pModem
Definition uwmphy_modem.h:419
DropTimer(UWMPhy_modem *pModem_)
Definition uwmphy_modem.h:411
Definition uwmphy_modem.h:85
virtual double getTxDuration(Packet *p)
Definition uwmphy_modem.h:351
Packet * popTxBuff()
unsigned long int getEpoch()
Definition uwmphy_modem.h:207
std::ofstream outLog
Definition uwmphy_modem.h:245
virtual void startRx(Packet *)
virtual void endTx(Packet *)
int debug_
Definition uwmphy_modem.h:243
char * log_suffix
Definition uwmphy_modem.h:249
CheckTimer * pcheckTmr
Definition uwmphy_modem.h:224
virtual int getModulationType(Packet *p)
Definition uwmphy_modem.h:364
UWMdriver * pmDriver
Definition uwmphy_modem.h:226
std::string getLogFile()
Definition uwmphy_modem.h:185
virtual modem_state_t check_modem()=0
UWMPhy_modem(std::string)
virtual int recvSyncClMsg(ClMessage *m)=0
std::string getPathToDevice()
Definition uwmphy_modem.h:158
int t
Definition uwmphy_modem.h:237
log_level_t getLogLevel()
Definition uwmphy_modem.h:197
DropTimer * pDropTimer
Definition uwmphy_modem.h:228
int getID()
Definition uwmphy_modem.h:135
double period
Definition uwmphy_modem.h:232
uint queue_length
Definition uwmphy_modem.h:254
virtual void start()
virtual void endRx(Packet *)
virtual void stop()
int SetModemID
Definition uwmphy_modem.h:252
Packet * modemTxBuff[_MTBL]
Definition uwmphy_modem.h:233
Packet * PktRx
Definition uwmphy_modem.h:239
int ID
Definition uwmphy_modem.h:230
virtual int command(int, const char *const *)
std::string logFile
Definition uwmphy_modem.h:247
int loglevel_
Definition uwmphy_modem.h:250
std::string pToDevice
Definition uwmphy_modem.h:240
virtual void recv(Packet *)
virtual void startTx(Packet *)
double getPeriod()
Definition uwmphy_modem.h:146
int getDebug()
Definition uwmphy_modem.h:175
void setConnections(CheckTimer *, UWMdriver *, DropTimer *)
uint getQueueLength()
Definition uwmphy_modem.h:164
void updatePktRx(Packet *)
Definition uwmdriver.h:94
int getDebug()
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.