DESERT 3.5.1
Loading...
Searching...
No Matches
uwip-module.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//
29
40#ifndef _UWIPMODULE_
41#define _UWIPMODULE_
42
43#include <module.h>
44
45#include <iostream>
46#include <string>
47#include <sstream>
48
49#define NOT_FOR_ME_REASON \
50 "NFM"
51#define DESTINATION_ADDR_UNSET \
52 "DAU"
53#define ORIGINATED_BY_ME \
54 "OBM"
55#define INVALID_DESTINATION_ADDR \
56 "IDA"
58#define HDR_UWIP(P) (hdr_uwip::access(P))
59
60
61
62static const uint8_t UWIP_BROADCAST = static_cast<uint8_t>(
63 0x000000ff);
65extern packet_t PT_UWIP;
66
70typedef struct hdr_uwip {
71 uint8_t saddr_;
72 uint8_t daddr_;
74 static int offset_;
79 inline static int &
81 {
82 return offset_;
83 }
84
85 inline static hdr_uwip *
86 access(const Packet *p)
87 {
88 return (hdr_uwip *) p->access(offset_);
89 }
90
94 uint8_t &
96 {
97 return saddr_;
98 }
99
103 uint8_t &
105 {
106 return daddr_;
107 }
108
110
115class UWIPModule : public Module
116{
117
118public:
122 UWIPModule();
123
127 virtual ~UWIPModule();
128
134 virtual void recv(Packet *p);
135
146 virtual int command(int argc, const char *const *argv);
147
155 virtual int recvSyncClMsg(ClMessage *m);
156
164 static const string printIP(const nsaddr_t &);
165
173 static const string printIP(const uint8_t &);
174
178 inline void
180 {
181 std::cout << "UWIP packets IDs:" << std::endl;
182 std::cout << "PT_UWIP: \t\t" << PT_UWIP << std::endl;
183 }
184
185protected:
186 static uint8_t lastIP;
187 uint8_t ipAddr_;
188 int debug_;
189 bool
199 static inline int
201 {
202 return sizeof(hdr_uwip);
203 }
204};
205
206#endif // _UWIPMODULE_
UWIPModule class is used to define the Internet Protocol (IP) layer of a node.
bool addr_type_inet
true if the addressing type is INET, false if it is ILINK.
int debug_
Flag to enable or disable dirrefent levels of debug.
static const string printIP(const nsaddr_t &)
Returns a string with an IP in the classic form "x.x.x.x" converting an ns2 nsaddr_t address.
virtual void recv(Packet *p)
Performs the reception of packets from upper and lower layers.
static uint8_t lastIP
Used to set a default IP address.
static int getIpHeaderSize()
Returns the size in byte of a hdr_sun_data packet header.
virtual ~UWIPModule()
Destructor of UWIPModule class.
virtual int command(int argc, const char *const *argv)
TCL command interpreter.
UWIPModule()
Constructor of UWIPModule class.
virtual int recvSyncClMsg(ClMessage *m)
Cross-Layer messages synchronous interpreter.
void printIdsPkts() const
Prints the IDs of the packet's headers defined by UWIP.
uint8_t ipAddr_
IP address of the node.
hdr_uwip describes UWIP packets.
Definition uwip-module.h:70
uint8_t & daddr()
Reference to the daddr_ variable.
uint8_t daddr_
IP of the destination.
Definition uwip-module.h:72
static int & offset()
Reference to the offset_ variable.
Definition uwip-module.h:80
uint8_t & saddr()
Reference to the saddr_ variable.
Definition uwip-module.h:95
static int offset_
Required by the PacketHeaderManager.
Definition uwip-module.h:74
static hdr_uwip * access(const Packet *p)
Definition uwip-module.h:86
uint8_t saddr_
IP of the source.
Definition uwip-module.h:71
static const uint8_t UWIP_BROADCAST
Variable used to represent a broadcast UWIP.
Definition uwip-module.h:62