DESERT 3.5.1
Loading...
Searching...
No Matches
frame-set.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//
29
38#include "frame-set.h"
39#include "packer.h"
40
41#include <limits.h>
42
43typedef unsigned char BARR_ELTYPE;
44
49#define BARR_ELBITS (CHAR_BIT * sizeof(BARR_ELTYPE))
50
51#define BARR_ELNUM(N) ((N) / BARR_ELBITS)
52
53#define BARR_BITNUM(N) ((N) % BARR_ELBITS)
54
55#define BARR_SET(barr, N) \
56 (((BARR_ELTYPE *) (barr))[BARR_ELNUM(N)] |= (BARR_ELTYPE) 1 \
57 << BARR_BITNUM(N))
58
59#define BARR_TEST(barr, N) \
60 (((BARR_ELTYPE *) (barr))[BARR_ELNUM(N)] & \
61 ((BARR_ELTYPE) 1 << BARR_BITNUM(N)))
62
63RxFrameSetKey::RxFrameSetKey(uint8_t srcID, unsigned int pktID)
64{
65 srcID_ = srcID;
66 pktID_ = pktID;
67}
68
72
73bool
75{
76
77 if (srcID_ == key2.srcID_)
78 return pktID_ < key2.pktID_;
79 else
80 return srcID_ < key2.srcID_;
81}
82
83std::string
85{
86
87 std::string str;
88 std::stringstream sstr("");
89 sstr << "srcID_:" << (int) srcID_ << ",pktID_:" << pktID_;
90 sstr >> str;
91
92 return str;
93}
94
105
109
110std::string
112{
113
114 std::string str("");
115 std::stringstream sstr;
116
117 sstr << "binPayload_:" << packer::hexdump_nice(binPayload(false))
118 << "binPayloadCheck_:"
121 << ",tot_length_:" << tot_length() << ",curr_length_:" << curr_length()
122 << ",t_last_rx_frame_:" << t_last_rx_frame();
123
124 sstr >> str;
125
126 return str;
127}
128
129std::string
130RxFrameSet::binPayload(bool extract) const
131{
132
133 std::string res;
134
135 if (extract) {
136
137 if (tot_length_ > -1)
138 res.assign(binPayload_, tot_length_);
139 else
140 res = "";
141 } else {
142
144 }
145
146 return res;
147}
148
149void
151 char *frame, size_t offset, size_t length, int tot_length, double time)
152{
153
154 if (offset + length > MAX_BIN_PAYLOAD_ARRAY_LENGTH) {
155 cout << "ERROR in RxFrameSet::UpdateRxFrameSet, offset: " << offset
156 << ", length:" << length << ", but MAX_BIN_PAYLOAD_ARRAY_LENGTH:"
158 return;
159 }
160
162 cout << "ERROR in RxFrameSet::UpdateRxFrameSet, tot_length: "
163 << tot_length << ", but MAX_BIN_PAYLOAD_ARRAY_LENGTH:"
165 return;
166 }
167
168 if (BARR_TEST(binPayloadCheck_, offset)) {
169 cout << "WARNING in RxFrameSet::UpdateRxFrameSet, duplicated or "
170 "overlapping frame has been received."
171 << endl;
172 return;
173 }
174
175 for (int i = offset; i < offset + length; i++) {
177 }
178
179 memcpy(binPayload_ + offset, frame, length);
180
181 curr_length_ += length;
182
183 t_last_rx_frame_ = time;
184
185 if (tot_length > -1) {
186
188 }
189}
bool operator<(RxFrameSetKey) const
Definition frame-set.cpp:74
RxFrameSetKey(uint8_t, unsigned int)
Definition frame-set.cpp:63
uint8_t srcID() const
Return the srcID_ variable.
Definition frame-set.h:72
unsigned int pktID_
ID of the packet.
Definition frame-set.h:61
uint8_t srcID_
ID of the packet's source node.
Definition frame-set.h:60
std::string displayKey() const
Definition frame-set.cpp:84
unsigned int pktID() const
Return the pktID_ variable.
Definition frame-set.h:81
bool error_
Definition frame-set.h:103
char binPayloadCheck_[MAX_BIN_PAYLOAD_CHECK_ARRAY_LENGTH]
array to count already received frames.
Definition frame-set.h:98
size_t curr_length_
Definition frame-set.h:101
int tot_length_
Definition frame-set.h:100
size_t curr_length() const
Reference to the curr_length_ variable.
Definition frame-set.h:123
char binPayload_[MAX_BIN_PAYLOAD_ARRAY_LENGTH]
array to store binary data received as frames.
Definition frame-set.h:94
std::string displaySet()
std::string binPayload() const
Return the content of the binPayload_ from 0 until tot_length_ array.
Definition frame-set.h:141
void UpdateRxFrameSet(char *, size_t, size_t, int, double)
int tot_length() const
Reference to the tot_length_ variable.
Definition frame-set.h:114
double t_last_rx_frame_
Definition frame-set.h:102
double t_last_rx_frame() const
Reference to the pktID_ variable.
Definition frame-set.h:132
static std::string hexdump_nice(std::string)
Function used for log and debug purposes (in order to print binary strings, even if they contain spec...
Definition packer.cpp:697
static std::string bindump(std::string)
Definition packer.cpp:1113
#define BARR_SET(barr, N)
Definition frame-set.cpp:55
unsigned char BARR_ELTYPE
Definition frame-set.cpp:43
#define BARR_TEST(barr, N)
Definition frame-set.cpp:59
Header of the classes defining the frame elements (key and set) exploited by Uwal objects to reassebl...
#define MAX_BIN_PAYLOAD_ARRAY_LENGTH
Definition frame-set.h:50
#define MAX_BIN_PAYLOAD_CHECK_ARRAY_LENGTH
Definition frame-set.h:52
Header of the class responsible to map an NS-Miracle packet into a bit stream, and vice-versa.