DESERT 3.5.1
Loading...
Searching...
No Matches
packer-uwcsma-ca.cpp
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
37#include "packer-uwcsma-ca.h"
38#include "uw-csma-ca-hdrs.h"
39
40static class packerUwCsmaCaTcl : public TclClass
41{
42public:
44 : TclClass("NS2/MAC/UW-CSMA-CA/Packer")
45 {
46 }
47
48 TclObject *
49 create(int, const char *const *)
50 {
51 return (new packerUwCsmaCa());
52 }
54
56 : packer(false)
57 , txtime_Bits(0)
58{
59 bind("txtime_Bits", (int *) &txtime_Bits);
60 this->init();
61}
62
63void
65{
66 n_bits.clear();
67 n_bits.assign(1, 0);
69}
70
71size_t
72packerUwCsmaCa::packMyHdr(Packet *p, unsigned char *buf, size_t offset)
73{
74 hdr_cmn *ch;
75 ch = HDR_CMN(p);
76
77 if (ch->ptype() == PT_CA_RTS) {
78
79 hdr_ca_RTS *rts;
80 rts = CA_RTS_HDR_ACCESS(p);
81
82 offset += put(buf, offset, &(rts->get_tx_time()), txtime_Bits);
83
84 if (debug_) {
85 cout << "\033[1;37;45m (TX) UWCSMA-CA::RTS packer hdr \033[0m"
86 << endl;
88 }
89
90 } else if (ch->ptype() == PT_CA_CTS) {
91 hdr_ca_CTS *cts;
92 cts = CA_CTS_HDR_ACCESS(p);
93
94 offset += put(buf, offset, &(cts->get_tx_time()), txtime_Bits);
95
96 if (debug_) {
97 cout << "\033[1;37;45m (TX) UWCSMA-CA::CTS packer hdr \033[0m"
98 << endl;
100 }
101 }
102 return offset;
103}
104
105size_t
106packerUwCsmaCa::unpackMyHdr(unsigned char *buf, size_t offset, Packet *p)
107{
108 hdr_cmn *ch;
109 ch = HDR_CMN(p);
110
111 if (ch->ptype() == PT_CA_RTS) {
112 hdr_ca_RTS *rts;
113 rts = CA_RTS_HDR_ACCESS(p);
114
115 memset(&(rts->get_tx_time()), 0, sizeof(uint8_t));
116 offset += get(buf, offset, &(rts->get_tx_time()), txtime_Bits);
117
118 if (debug_) {
119 cout << "\033[1;37;45m (RX) UWCSMA-CA::CTS packer hdr \033[0m"
120 << endl;
122 }
123 } else if (ch->ptype() == PT_CA_CTS) {
124 hdr_ca_CTS *cts;
125 cts = CA_CTS_HDR_ACCESS(p);
126
127 memset(&(cts->get_tx_time()), 0, sizeof(uint8_t));
128 offset += get(buf, offset, &(cts->get_tx_time()), txtime_Bits);
129
130 if (debug_) {
131 cout << "\033[1;37;45m (RX) UWCSMA-CA::CTS packer hdr \033[0m"
132 << endl;
134 }
135 }
136 return offset;
137}
138
139void
141{
142 hdr_cmn *ch = HDR_CMN(p);
143
144 if (ch->ptype() == PT_CA_RTS) {
145 hdr_ca_RTS *rts;
146 rts = CA_RTS_HDR_ACCESS(p);
147 cout << "\033[1;37;41m 1st field \033[0m, txTime_: "
148 << rts->get_tx_time() << endl;
149 } else if (ch->ptype() == PT_CA_CTS) {
150 hdr_ca_CTS *cts;
151 cts = CA_CTS_HDR_ACCESS(p);
152 cout << "\033[1;37;41m 1st field \033[0m, txTime_: "
153 << cts->get_tx_time() << endl;
154 }
155}
156
157void
159{
160 cout << "\033[1;37;45m Packer Name \033[0m: UW-CSMA-CA \n";
161 cout << "\033[1;37;45m Field: txTime \033[0m:" << txtime_Bits << " bits\n";
162}
TclObject * create(int, const char *const *)
Class to map a UwCsma-Ca header into a bit stream, and vice-versa.
size_t packMyHdr(Packet *, unsigned char *, size_t)
Method to transform the headers of UwCsma-Ca into a stream of bits.
void printMyHdrFields(Packet *)
Method used for debug purposes.
packerUwCsmaCa()
Class constructor.
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...
void printMyHdrMap()
Method used for debug purposes.
void init()
Init the Packer.
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
packerUwCsmaCaTcl class_module_packerUWCsmaCa
Header of the class responsible to map the ns2 packet of UwCsma-Ca.
uint8_t & get_tx_time()
uint8_t & get_tx_time()
Provides the headers of ctrl packets of uw-csma-ca module.
#define CA_CTS_HDR_ACCESS(p)
#define CA_RTS_HDR_ACCESS(p)