DESERT 3.5.1
Loading...
Searching...
No Matches
uwudp-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
42#ifndef _UWUDP_H_
43#define _UWUDP_H_
44
45#include <uwip-module.h>
46
47#include <module.h>
48#include <map>
49#include <set>
50
51#define DROP_UNKNOWN_PORT_NUMBER \
52 "UPN"
53#define DROP_RECEIVED_DUPLICATED_PACKET \
54 "RDP"
56#define HDR_UWUDP(P) (hdr_uwudp::access(P))
57
58extern packet_t PT_UWUDP;
59
63typedef struct hdr_uwudp {
64 uint8_t sport_;
65 uint8_t dport_;
67 static int offset_;
72 inline static int &
74 {
75 return offset_;
76 }
77
78 inline static struct hdr_uwudp *
79 access(const Packet *p)
80 {
81 return (struct hdr_uwudp *) p->access(offset_);
82 }
83
87 inline uint8_t &
89 {
90 return sport_;
91 }
92
96 inline uint8_t &
98 {
99 return dport_;
100 }
102
107class UwUdp : public Module
108{
109public:
113 UwUdp();
114
118 virtual ~UwUdp();
119
125 virtual void recv(Packet *);
126
133 virtual void recv(Packet *, int);
134
145 virtual int command(int, const char *const *);
146
153 virtual int assignPort(Module *);
154
158 inline void
160 {
161 std::cout << "UWUDP packets IDs:" << std::endl;
162 std::cout << "PT_UWUDP: \t\t" << PT_UWUDP << std::endl;
163 }
164
165protected:
166 uint16_t portcounter;
167 map<int, int> port_map;
168 map<int, int> id_map;
170 typedef std::map<uint8_t, std::set<int> > map_packets_el;
171 std::
172 map<uint16_t, map_packets_el>
181 int debug_;
188 static inline int
190 {
191 return sizeof(hdr_uwudp);
192 }
193};
194
195#endif // _UWUDP_H_
UwUdp class is used to manage UWUDP packets, and flows to and from upper modules.
virtual int command(int, const char *const *)
TCL command interpreter.
map< int, int > port_map
Map: value = port; key = id.
virtual int assignPort(Module *)
Associates a module with a port.
map< int, int > id_map
Map: value = id; key = port.
uint16_t portcounter
Counter used to generate new port numbers.
UwUdp()
Constructor of UwUdp class.
static int getUdpHeaderSize()
Returns the size in byte of a hdr_uwudp packet header.
virtual void recv(Packet *)
Performs the reception of packets from upper and lower layers.
std::map< uint8_t, std::set< int > > map_packets_el
std::map< uint16_t, map_packets_el > map_packets
Map used to keep track of the packets received by each port.
int drop_duplicated_packets_
Flat to enable or disable the drop of duplicated packets.
int debug_
Flag to enable or disable dirrefent levels of debug.
void printIdsPkts() const
Prints the IDs of the packet's headers defined by UWUDP.
virtual ~UwUdp()
Destructor of UwUdp class.
hdr_uwudp describes UWUDP packets.
static int offset_
Required by the PacketHeaderManager.
uint8_t dport_
Destination port number.
static struct hdr_uwudp * access(const Packet *p)
uint8_t & sport()
Reference to the sport_ variable.
uint8_t sport_
Source port number.
uint8_t & dport()
Reference to the dport_ variable.
static int & offset()
Reference to the offset_ variable.
Provides the UWIP packets header description. Definition of the class that define the network layer.