DESERT 3.5.1
Loading...
Searching...
No Matches
packer-uwcbr.cpp
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-uwcbr.h"
37
41static class PackerUWCBRClass : public TclClass {
42public:
43
44 PackerUWCBRClass() : TclClass("UW/CBR/Packer") {
45 }
46
47 TclObject* create(int, const char*const*) {
48 return (new packerUWCBR());
49 }
51
53 SN_Bits = 8 * sizeof (u_int32_t);
54 RFTT_Bits = 0;
57
58 bind("SN_Bits", (int*) &SN_Bits);
59 bind("RFTT_Bits", (int*) &RFTT_Bits);
60 bind("RFTT_VALID_Bits", (int*) &RFTT_VALID_Bits);
61 bind("TRAFFIC_TYPE_Bits", (int*) &TRAFFIC_TYPE_Bits);
62
63 if (debug_)
64 cout << "Initialization (from constructor) of n_bits for the UWCBR packer " << endl;
65
66 n_bits.clear();
67
68 n_bits.push_back(SN_Bits);
69 n_bits.push_back(RFTT_Bits);
70 n_bits.push_back(RFTT_VALID_Bits);
71 n_bits.push_back(TRAFFIC_TYPE_Bits);
72
73}
74
78
80
81 if (debug_)
82 cout << "Re-initialization of n_bits for the UWCBR packer " << endl;
83
84 n_bits.clear();
85
86 n_bits.push_back(SN_Bits);
87 n_bits.push_back(RFTT_Bits);
88 n_bits.push_back(RFTT_VALID_Bits);
89 n_bits.push_back(TRAFFIC_TYPE_Bits);
90}
91
92size_t packerUWCBR::packMyHdr(Packet* p, unsigned char* buf, size_t offset) {
93
94 // Pointer to the UWCBR packet header
95 hdr_cmn* ch = HDR_CMN(p);
96 hdr_uwcbr* uch = HDR_UWCBR(p);
97
98 if ( ch->ptype() == PT_UWCBR ) {
99 int field_idx = 0;
100
101 offset += put(buf, offset, &(uch->sn_), n_bits[field_idx++]);
102
103 offset += put(buf, offset, &(uch->rftt_), n_bits[field_idx++]);
104
105 offset += put(buf, offset, &(uch->rftt_valid_), n_bits[field_idx++]);
106
107 offset += put(buf, offset, &(uch->traffic_type_), n_bits[field_idx++]);
108
109 if (debug_) {
110 printf("\033[0;46;30m TX CBR packer hdr \033[0m \n");
112 }
113 }
114
115 return offset;
116}
117
118size_t packerUWCBR::unpackMyHdr(unsigned char* buf, size_t offset, Packet* p) {
119
120 // Pointer to the UWCBR packet header
121 hdr_cmn* ch = HDR_CMN(p);
122 hdr_uwcbr* uch = HDR_UWCBR(p);
123
124 if ( ch->ptype() == PT_UWCBR ) {
125 int field_idx = 0;
126
127 memset(&(uch->sn_), 0, sizeof (uch->sn_));
128 offset += get(buf, offset, &(uch->sn_), n_bits[field_idx++]);
129
130 memset(&(uch->rftt_), 0, sizeof (uch->rftt_));
131 offset += get(buf, offset, &(uch->rftt_), n_bits[field_idx++]);
132
133 memset(&(uch->rftt_valid_), 0, sizeof (uch->rftt_valid_));
134 offset += get(buf, offset, &(uch->rftt_valid_), n_bits[field_idx++]);
135
136 memset(&(uch->traffic_type_), 0, sizeof (uch->traffic_type_));
137 offset += get(buf, offset, &(uch->traffic_type_), n_bits[field_idx++]);
138
139 if (debug_) {
140 printf("\033[0;46;30m RX CBR packer hdr \033[0m \n");
142 }
143 }
144
145 return offset;
146}
147
149 std::cout << "\033[0;46;30m Packer Name \033[0m: UWCBR \n";
150 std::cout << "\033[0;46;30m sn: \033[0m" << SN_Bits << " bits \n";
151 std::cout << "\033[0;46;30m rftt: \033[0m" << RFTT_Bits << " bits \n";
152 std::cout << "\033[0;46;30m rftt valid: \033[0m" << RFTT_VALID_Bits << " bits" << std::endl;
153 std::cout << "\033[0;46;30m traffic type: \033[0m" << TRAFFIC_TYPE_Bits << " bits" << std::endl;
154}
155
156
158 hdr_uwcbr* uch = HDR_UWCBR(p);
159
160 if (n_bits[0] != 0) std::cout << "\033[0;46;30m sn: \033[0m" << uch->sn() << std::endl;
161 if (n_bits[1] != 0) std::cout << "\033[0;46;30m rftt: \033[0m" << uch->rftt() << std::endl;
162 if (n_bits[2] != 0) std::cout << "\033[0;46;30m rftt_valid: \033[0m" << uch->rftt_valid() << std::endl;
163 if (n_bits[3] != 0) std::cout << "\033[0;46;30m traffic_type: \033[0m" << uch->traffic_type() << std::endl;
164}
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.
void init()
Init the Packer.
void printMyHdrFields(Packet *)
Method used for debug purposes.
size_t RFTT_VALID_Bits
Bit length of the rftt_ field to be put in the header stream of bits.
size_t packMyHdr(Packet *, unsigned char *, size_t)
Method to transform the headers of Uwpolling into a stream of bits.
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 SN_Bits
size_t RFTT_Bits
Bit length of the sn_ field to be put in the header stream of bits.
size_t TRAFFIC_TYPE_Bits
Bit length of the rftt_valid_ field to be put in the header stream of bits.
void printMyHdrMap()
Method used for debug purposes.
packerUWCBR()
Class constructor.
~packerUWCBR()
Class destructor.
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
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
PackerUWCBRClass class_module_packerUWCBR
Header of the class responsible to map the NS-Miracle packet of uw-cbr into a bit stream,...
hdr_uwcbr describes UWCBR packets.
float & rftt()
Reference to the rftt_ variable.
uint16_t traffic_type_
Traffic type: (video, audio, image, etc..) meaning left to the user.
bool rftt_valid_
Flag used to set the validity of the fft field.
uint16_t & traffic_type()
Reference to the rftt_ variable.
bool & rftt_valid()
Reference to the rftt_valid_ variable.
float rftt_
Forward Trip Time of the packet.
uint16_t sn_
Serial number of the packet.
uint16_t & sn()
Reference to the sn_ variable.
#define HDR_UWCBR(p)