DESERT 3.6.0
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
48#define NOT_FOR_ME_REASON \
49 "NFM"
50#define DESTINATION_ADDR_UNSET \
51 "DAU"
52#define ORIGINATED_BY_ME \
53 "OBM"
54#define INVALID_DESTINATION_ADDR \
55 "IDA"
57#define HDR_UWIP(P) (hdr_uwip::access(P))
58
59static const uint8_t UWIP_BROADCAST = static_cast<uint8_t>(
60 0x000000ff);
62extern packet_t PT_UWIP;
63
67typedef struct hdr_uwip {
68 uint8_t saddr_;
69 uint8_t daddr_;
71 static int offset_;
76 static int &
78 {
79 return offset_;
80 }
81
82 static hdr_uwip *
83 access(const Packet *p)
84 {
85 return (hdr_uwip *) p->access(offset_);
86 }
87
91 uint8_t &
93 {
94 return saddr_;
95 }
96
100 uint8_t &
102 {
103 return daddr_;
104 }
105
107
112class UWIPModule : public Module
113{
114
115public:
119 UWIPModule();
120
124 virtual ~UWIPModule() = default;
125
131 virtual void recv(Packet *p);
132
143 virtual int command(int argc, const char *const *argv);
144
152 virtual int recvSyncClMsg(ClMessage *m);
153
161 static const string printIP(const nsaddr_t &);
162
170 static const string printIP(const uint8_t &);
171
175 void
177 {
178 std::cout << "UWIP packets IDs:" << std::endl;
179 std::cout << "PT_UWIP: \t\t" << PT_UWIP << std::endl;
180 }
181
182protected:
183 static uint8_t lastIP;
184 uint8_t ipAddr_;
185 int debug_;
195 static int
197 {
198 return sizeof(hdr_uwip);
199 }
200};
201
202#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 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.
virtual ~UWIPModule()=default
Destructor of UWIPModule class.
hdr_uwip describes UWIP packets.
Definition uwip-module.h:67
uint8_t & daddr()
Reference to the daddr_ variable.
uint8_t daddr_
IP of the destination.
Definition uwip-module.h:69
static int & offset()
Reference to the offset_ variable.
Definition uwip-module.h:77
uint8_t & saddr()
Reference to the saddr_ variable.
Definition uwip-module.h:92
static int offset_
Required by the PacketHeaderManager.
Definition uwip-module.h:71
static hdr_uwip * access(const Packet *p)
Definition uwip-module.h:83
uint8_t saddr_
IP of the source.
Definition uwip-module.h:68
static const uint8_t UWIP_BROADCAST
Variable used to represent a broadcast UWIP.
Definition uwip-module.h:59