Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2013 Mohammed J.F. Alenazi | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 2 as | |
7 * published by the Free Software Foundation; | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 * | |
18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> | |
19 * | |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | |
22 * Information and Telecommunication Technology Center (ITTC) | |
23 * and Department of Electrical Engineering and Computer Science | |
24 * The University of Kansas Lawrence, KS USA. | |
25 * | |
26 * Work supported by King Saud University and the ITTC at The University of Kans as. | |
27 */ | |
28 | |
29 #include "epidemic-packet.h" | |
30 #include "ns3/address-utils.h" | |
31 #include "ns3/packet.h" | |
32 | |
33 namespace ns3 { | |
34 namespace epidemic { | |
Tom Henderson
2013/12/08 22:24:26
logging is missing in this file (both the log comp
mjf.alenazi
2013/12/30 23:11:11
Done.
| |
35 NS_OBJECT_ENSURE_REGISTERED (TypeHeader); | |
36 | |
37 TypeHeader::TypeHeader (MessageType t) | |
38 : m_type (t), | |
39 m_valid (true) | |
40 { | |
41 } | |
42 | |
43 TypeHeader::~TypeHeader () | |
44 { | |
45 } | |
46 TypeId TypeHeader::GetTypeId () | |
Peter Barnes
2013/12/10 00:02:33
I prefer return type on a separate line than the f
mjf.alenazi
2013/12/30 23:11:11
I did not understand what you mean here?
On 2013/1
| |
47 { | |
48 static TypeId tid = | |
49 TypeId ("ns3::epidemic::TypeHeader").SetParent<Header> ().AddConstructor< | |
50 TypeHeader> (); | |
51 return tid; | |
52 } | |
53 | |
54 TypeId TypeHeader::GetInstanceTypeId () const | |
55 { | |
56 return GetTypeId (); | |
57 } | |
58 | |
59 void TypeHeader::SetInstanceTypeId (MessageType type) | |
60 { | |
61 m_type = type; | |
62 } | |
63 | |
64 uint32_t TypeHeader::GetSerializedSize () const | |
65 { | |
66 return 1; | |
67 } | |
68 | |
69 void TypeHeader::Serialize (Buffer::Iterator i) const | |
70 { | |
71 i.WriteU8 ((uint8_t) m_type); | |
72 } | |
73 | |
74 uint32_t TypeHeader::Deserialize (Buffer::Iterator start) | |
75 { | |
76 Buffer::Iterator i = start; | |
77 uint8_t type = i.ReadU8 (); | |
78 m_valid = true; | |
79 switch (type) | |
80 { | |
81 case EPIDEMIC_TYPE_BEACON: | |
82 case EPIDEMIC_TYPE_REPLY: | |
83 case EPIDEMIC_TYPE_REPLY_BACK: | |
84 { | |
85 m_type = (MessageType) type; | |
86 break; | |
87 } | |
88 default: | |
89 m_valid = false; | |
90 break; | |
91 } | |
92 uint32_t dist = i.GetDistanceFrom (start); | |
93 NS_ASSERT (dist == GetSerializedSize ()); | |
94 return dist; | |
95 } | |
96 | |
97 void TypeHeader::Print (std::ostream &os) const | |
98 { | |
99 switch (m_type) | |
100 { | |
101 case EPIDEMIC_TYPE_BEACON: | |
102 { | |
103 os << "EPIDEMIC_TYPE_BEACON"; | |
104 break; | |
105 } | |
106 case EPIDEMIC_TYPE_REPLY: | |
107 { | |
108 os << "EPIDEMIC_TYPE_REPLY"; | |
109 break; | |
110 } | |
111 case EPIDEMIC_TYPE_REPLY_BACK: | |
112 { | |
113 os << "EPIDEMIC_TYPE_REPLY_BACK"; | |
114 break; | |
115 } | |
116 default: | |
117 os << "UNKNOWN_TYPE"; | |
118 break; | |
119 } | |
120 } | |
121 | |
122 bool TypeHeader::operator== (TypeHeader const & o) const | |
123 { | |
124 return (m_type == o.m_type && m_valid == o.m_valid); | |
125 } | |
126 | |
127 | |
128 MessageType TypeHeader::Get () const | |
129 { | |
130 return m_type; | |
131 } | |
132 | |
133 bool TypeHeader::IsValid () const | |
134 { | |
135 return m_valid; | |
136 } | |
137 | |
138 std::ostream & | |
139 operator<< (std::ostream & os, TypeHeader const & h) | |
140 { | |
141 h.Print (os); | |
142 return os; | |
143 } | |
144 | |
145 NS_OBJECT_ENSURE_REGISTERED (EpidemicSummaryVectorHeader); | |
146 EpidemicSummaryVectorHeader::EpidemicSummaryVectorHeader ( | |
147 std::vector<uint64_t> sv) | |
148 : m_summary_vector (sv) | |
149 { | |
150 } | |
151 | |
152 EpidemicSummaryVectorHeader::~EpidemicSummaryVectorHeader () | |
153 { | |
154 } | |
155 | |
156 TypeId EpidemicSummaryVectorHeader::GetTypeId (void) | |
157 { | |
158 static TypeId tid = | |
159 TypeId ("ns3::epidemic::EpidemicSummaryVectorHeader").SetParent< | |
160 Header> ().AddConstructor<EpidemicSummaryVectorHeader> (); | |
161 return tid; | |
162 } | |
163 | |
164 TypeId EpidemicSummaryVectorHeader::GetInstanceTypeId () const | |
165 { | |
166 return GetTypeId (); | |
167 } | |
168 | |
169 uint32_t EpidemicSummaryVectorHeader::GetSerializedSize () const | |
170 { | |
171 return 8 + (int32_t) m_summary_vector.size () * 8; | |
172 } | |
173 | |
174 void EpidemicSummaryVectorHeader::Serialize (Buffer::Iterator i) const | |
175 { | |
176 i.WriteHtonU64 (m_summary_vector.size ()); | |
177 | |
178 for (std::vector<uint64_t>::size_type j = 0; j != m_summary_vector.size (); | |
179 j++) | |
180 { | |
181 i.WriteHtonU64 (m_summary_vector[j]); | |
182 } | |
183 | |
184 } | |
185 | |
186 uint32_t EpidemicSummaryVectorHeader::Deserialize (Buffer::Iterator start) | |
187 { | |
188 Buffer::Iterator i = start; | |
189 uint64_t sm_length = i.ReadNtohU64 (); | |
190 m_summary_vector.reserve (sm_length); | |
191 for (uint64_t j = 0; j < sm_length; j++) | |
192 { | |
193 uint64_t tmp = i.ReadNtohU64 (); | |
194 m_summary_vector.push_back (tmp); | |
195 | |
196 } | |
197 uint32_t dist = i.GetDistanceFrom (start); | |
198 NS_ASSERT (dist == GetSerializedSize ()); | |
199 | |
200 return dist; | |
201 } | |
202 | |
203 void EpidemicSummaryVectorHeader::Print (std::ostream &os) const | |
204 { | |
205 os << " Summary_vector Size: " << m_summary_vector.size (); | |
206 } | |
207 | |
208 | |
209 void EpidemicSummaryVectorHeader::SetSummaryVector (std::vector<uint64_t> value ) | |
210 { | |
211 m_summary_vector = value; | |
212 } | |
213 | |
214 std::vector<uint64_t> EpidemicSummaryVectorHeader::GetSummaryVector () | |
215 { | |
216 return m_summary_vector; | |
217 } | |
218 | |
219 | |
220 NS_OBJECT_ENSURE_REGISTERED (EpidemicHeader); | |
221 | |
222 EpidemicHeader::EpidemicHeader (uint64_t pkt_ID, uint32_t hopCount, | |
223 Time timeStamp) | |
224 : m_packetID (pkt_ID), | |
225 m_hopCount (hopCount), | |
226 m_timeStamp (timeStamp) | |
227 { | |
228 } | |
229 EpidemicHeader::~EpidemicHeader () | |
230 { | |
231 } | |
232 | |
233 | |
234 void EpidemicHeader::SetPacketID (uint64_t pktID) | |
235 { | |
236 m_packetID = pktID; | |
237 } | |
238 | |
239 uint64_t EpidemicHeader::GetPacketID () const | |
240 { | |
241 return m_packetID; | |
242 } | |
243 | |
244 | |
245 void EpidemicHeader::SetHopCount (uint32_t floodCount) | |
246 { | |
247 m_hopCount = floodCount; | |
248 } | |
249 | |
250 uint32_t EpidemicHeader::GetHopCount () const | |
251 { | |
252 return m_hopCount; | |
253 } | |
254 | |
255 | |
256 void EpidemicHeader::SetTimeStamp (Time timeStamp) | |
257 { | |
258 m_timeStamp = timeStamp; | |
259 } | |
260 | |
261 | |
262 Time EpidemicHeader::GetTimeStamp () const | |
263 { | |
264 return m_timeStamp; | |
265 } | |
266 | |
267 | |
268 TypeId EpidemicHeader::GetTypeId (void) | |
269 { | |
270 static TypeId tid = | |
271 TypeId ("ns3::epidemic::EpidemicHeader").SetParent<Header> ().AddConstructor < | |
272 EpidemicHeader> (); | |
273 return tid; | |
274 } | |
275 | |
276 TypeId EpidemicHeader::GetInstanceTypeId () const | |
277 { | |
278 return GetTypeId (); | |
279 } | |
280 | |
281 uint32_t EpidemicHeader::GetSerializedSize () const | |
282 { | |
283 | |
284 return 20; | |
285 | |
286 } | |
287 | |
288 void EpidemicHeader::Serialize (Buffer::Iterator i) const | |
289 { | |
290 i.WriteHtonU64 (m_packetID); | |
291 i.WriteHtonU32 (m_hopCount); | |
292 i.WriteHtonU64 (m_timeStamp.GetNanoSeconds ()); | |
293 | |
294 } | |
295 | |
296 uint32_t EpidemicHeader::Deserialize (Buffer::Iterator start) | |
297 { | |
298 Buffer::Iterator i = start; | |
299 m_packetID = i.ReadNtohU64 (); | |
300 m_hopCount = i.ReadNtohU32 (); | |
301 m_timeStamp = Time (i.ReadNtohU64 ()); | |
302 uint32_t dist = i.GetDistanceFrom (start); | |
303 NS_ASSERT (dist == GetSerializedSize ()); | |
304 return dist; | |
305 } | |
306 | |
307 void EpidemicHeader::Print (std::ostream &os) const | |
308 { | |
309 os << " Packet ID: " << m_packetID << " Hop count: " << m_hopCount | |
310 << " TimeStamp: " << m_timeStamp; | |
311 | |
312 } | |
313 } //end namespace epidemic | |
314 } //end namespace ns3 | |
OLD | NEW |