DESERT 3.5.1
Loading...
Searching...
No Matches
packer-uwflooding.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2013 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
36#include "packer-uwflooding.h"
37
41static class PackerUwfloodingClass : public TclClass {
42public:
43
44 PackerUwfloodingClass() : TclClass("UW/FLOODING/Packer") {
45 }
46
47 TclObject* create(int, const char*const*) {
48 return (new PackerUwFlooding());
49 }
51
53 ttl_Bits = 8 * sizeof (uint8_t);
54
55 bind("ttl_Bits", (int*) &ttl_Bits);
56
57 if (debug_) {
58 std::cout << "Initialization (from constructor) of n_bits for the UWFLOODING packer " << std::endl;
59 }
60
61 n_bits.clear();
62
63 n_bits.push_back(ttl_Bits);
64}
65
69
71
72 if (debug_)
73 std::cout << "Re-initialization of n_bits for the UWFLOODING packer " << std::endl;
74
75 n_bits.clear();
76 n_bits.push_back(ttl_Bits);
77}
78
79size_t PackerUwFlooding::packMyHdr(Packet* p, unsigned char* buf, size_t offset) {
80
81 // Pointer to the UWFLOODING packet header
82 hdr_uwflooding* hflooding = HDR_UWFLOODING(p);
83
84 int field_idx = 0;
85
86 offset += put(buf, offset, &(hflooding->ttl()), n_bits[field_idx++]);
87
88 if (debug_) {
89 printf("\033[1;37;46m TX UWFLOODING packer hdr \033[0m \n");
91 }
92
93 return offset;
94}
95
96size_t PackerUwFlooding::unpackMyHdr(unsigned char* buf, size_t offset, Packet* p) {
97
98 hdr_uwflooding* hflooding = HDR_UWFLOODING(p);
99
100 int field_idx = 0;
101
102 memset(&(hflooding->ttl()), 0, sizeof (hflooding->ttl()));
103 offset += get(buf, offset, &(hflooding->ttl()), n_bits[field_idx++]);
104
105 if (debug_) {
106 printf("\033[1;37;46m RX UWFLOODING packer hdr \033[0m \n");
108 }
109
110 return offset;
111}
112
114 std::cout << "\033[1;37;46m" << " Packer Name " << "\033[0m" << " UWFLOODING" << std::endl;
115 std::cout << "\033[1;37;46m 1st field " << "\033[0m" << " ttl: " << ttl_Bits << " bits" << std::endl;
116 return;
117}
118
120 hdr_uwflooding* hflooding = HDR_UWFLOODING(p);
121
122 if (n_bits[0] != 0) {
123 std::cout << "\033[1;37;46m ttl:\033[0m " << static_cast<uint32_t>(hflooding->ttl()) << " " << hex_bytes(hflooding->ttl(), n_bits[0]) << std::endl;
124 }
125}
Class exploited by the Uwal module to map an NS-Miracle packet into a bit stream, and vice-versa.
size_t unpackMyHdr(unsigned char *, size_t, Packet *)
Method responsible to take the informations from the received buffer and store it into the headers of...
size_t packMyHdr(Packet *, unsigned char *, size_t)
Method to transform the headers of Uwpolling into a stream of bits.
void printMyHdrMap()
Method used for debug purposes.
void printMyHdrFields(Packet *)
Method used for debug purposes.
void init()
Init the Packer.
~PackerUwFlooding()
Class destructor.
PackerUwFlooding()
Class constructor.
Class to create the Otcl shadow object for an object of the class packer.
TclObject * create(int, const char *const *)
Class exploited by the Uwal module to map an NS-Miracle packet into a bit stream, and vice-versa.
Definition packer.h:57
std::vector< size_t > n_bits
Vector of elements containing the indication of the number of bits to consider for each header field.
Definition packer.h:224
size_t put(unsigned char *buffer, size_t offset, void *val, size_t h)
Method used to map in a certain number of bits, contained in a buffer of chars, a given variable.
Definition packer.cpp:685
static std::string hex_bytes(float)
Definition packer.cpp:752
size_t get(unsigned char *buffer, size_t offset, void *val, size_t h)
Method used to retrieve a given variable from a certain number of bits contained in a buffer of chars...
Definition packer.cpp:673
int debug_
Flag to enable debug messages.
Definition packer.h:227
PackerUwfloodingClass class_module_PackerUwflooding
hdr_uwflooding describes packets used by UWFLOODING.
uint8_t & ttl()
Reference to the uid_ variable.