DESERT 4.0.0
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_
Definition uwip-module.h:113
bool addr_type_inet
Definition uwip-module.h:186
int debug_
Definition uwip-module.h:185
static const string printIP(const nsaddr_t &)
Definition uwip-module.cpp:202
virtual void recv(Packet *p)
Definition uwip-module.cpp:131
static uint8_t lastIP
Definition uwip-module.h:183
static int getIpHeaderSize()
Definition uwip-module.h:196
virtual int command(int argc, const char *const *argv)
Definition uwip-module.cpp:92
UWIPModule()
Definition uwip-module.cpp:82
virtual int recvSyncClMsg(ClMessage *m)
Definition uwip-module.cpp:188
void printIdsPkts() const
Definition uwip-module.h:176
uint8_t ipAddr_
Definition uwip-module.h:184
virtual ~UWIPModule()=default
Definition uwip-module.h:67
uint8_t & daddr()
Definition uwip-module.h:101
uint8_t daddr_
Definition uwip-module.h:69
static int & offset()
Definition uwip-module.h:77
uint8_t & saddr()
Definition uwip-module.h:92
static int offset_
Definition uwip-module.h:71
static hdr_uwip * access(const Packet *p)
Definition uwip-module.h:83
uint8_t saddr_
Definition uwip-module.h:68
packet_t PT_UWIP
Definition initlib.cpp:47