DESERT 3.6.0
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 <sstream>
46#include <uwip-module.h>
47
48#include <map>
49#include <module.h>
50#include <set>
51
52#define DROP_UNKNOWN_PORT_NUMBER \
53 "UPN"
54#define DROP_RECEIVED_DUPLICATED_PACKET \
55 "RDP"
57#define HDR_UWUDP(P) (hdr_uwudp::access(P))
58
59extern packet_t PT_UWUDP;
60
61typedef std::map<uint8_t, std::set<int>> map_packets_el;
62
66typedef struct hdr_uwudp {
67 uint8_t sport_;
68 uint8_t dport_;
70 static int offset_;
75 static int &
77 {
78 return offset_;
79 }
80
81 static struct hdr_uwudp *
82 access(const Packet *p)
83 {
84 return (struct hdr_uwudp *) p->access(offset_);
85 }
86
90 uint8_t &
92 {
93 return sport_;
94 }
95
99 uint8_t &
101 {
102 return dport_;
103 }
105
110class UwUdp : public Module
111{
112public:
116 UwUdp();
117
121 virtual ~UwUdp() = default;
122
128 virtual void recv(Packet *) override;
129
136 virtual void recv(Packet *, int) override;
137
148 virtual int command(int, const char *const *) override;
149
156 virtual int assignPort(Module *);
157
161 void
163 {
164 std::cout << "UWUDP packets IDs:" << std::endl;
165 std::cout << "PT_UWUDP: \t\t" << PT_UWUDP << std::endl;
166 }
167
168protected:
169 uint16_t portcounter;
172 int debug_;
173 std::map<int, int> port_map;
175 std::map<int, int> id_map;
177 std::map<uint16_t, map_packets_el>
188 static 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.
std::map< int, int > port_map
Map application module id to port number (id, port_number).
std::map< int, int > id_map
Map port number to application module id (port_number, id).
virtual int command(int, const char *const *) override
TCL command interpreter.
virtual void recv(Packet *) override
Performs the reception of packets from upper and lower layers.
virtual ~UwUdp()=default
Destructor of UwUdp class.
virtual int assignPort(Module *)
Associates a module with a 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.
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_
Flag to enable or disable the drop of duplicated packets.
int debug_
Flag to enable or disable debug.
void printIdsPkts() const
Prints the IDs of the packet's headers defined by UWUDP.
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.
std::map< uint8_t, std::set< int > > map_packets_el