OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2015 Amir Modarresi |
| 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: Amir Modarresi <amodarresi@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 in part by NSF FIND (Future Internet Design) Program |
| 27 * under grant CNS-0626918 (Postmodern Internet Architecture), |
| 28 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimenta
tion on GENI), |
| 29 * US Department of Defense (DoD), and ITTC at The University of Kansas. |
| 30 */ |
| 31 |
| 32 #define TTL 64 |
| 33 #define HEADER_SIZE 48 |
| 34 |
| 35 #include "ns3/assert.h" |
| 36 #include "ns3/log.h" |
| 37 #include "ns3/header.h" |
| 38 #include "sift-header.h" |
| 39 #include "ns3/address-utils.h" |
| 40 |
| 41 namespace ns3 { |
| 42 namespace sift { |
| 43 |
| 44 NS_LOG_COMPONENT_DEFINE ("SiftHeader"); |
| 45 |
| 46 NS_OBJECT_ENSURE_REGISTERED (SiftHeader); |
| 47 |
| 48 TypeId SiftHeader::GetTypeId () |
| 49 { |
| 50 static TypeId tid = TypeId ("ns3::sift::SiftHeader") |
| 51 .AddConstructor<SiftHeader> () |
| 52 .SetParent<Header> () |
| 53 ; |
| 54 return tid; |
| 55 } |
| 56 |
| 57 TypeId SiftHeader::GetInstanceTypeId () const |
| 58 { |
| 59 return GetTypeId (); |
| 60 } |
| 61 |
| 62 SiftHeader::SiftHeader () |
| 63 : m_nextHeader (17), |
| 64 // Protocol number in layer 4 (TCP=6, UDP=17, ICMP=1) |
| 65 m_optionLength (0), |
| 66 m_messageType (47), |
| 67 // Generic Routing Encapsulation GRE |
| 68 m_segmentsLeft (48), |
| 69 // Total Sift Header size |
| 70 //m_data (0), |
| 71 m_sourceId (0), |
| 72 m_sourceXLoc (0), |
| 73 // Source x Location, it doesn't change until reaches to final destination |
| 74 m_sourceYLoc (0), |
| 75 // Source y Location, it doesn't change until reaches to final destination |
| 76 m_lastsourceXLoc (0), |
| 77 // Last source X Location, this field changes in each hop |
| 78 m_lastsourceYLoc (0), |
| 79 // Last source Y Location, this field changes in each hop |
| 80 m_destId (0), |
| 81 m_destXLoc (0), |
| 82 m_destYLoc (0), |
| 83 m_headerSeqNo (0), |
| 84 m_headerTTL (TTL), |
| 85 m_sourceAddress ((Ipv4Address)"127.0.0.1"), |
| 86 m_destAddress ((Ipv4Address)"127.0.0.1") |
| 87 //m_ipv4Address (0) |
| 88 { |
| 89 |
| 90 |
| 91 } |
| 92 |
| 93 SiftHeader::~SiftHeader () |
| 94 { |
| 95 } |
| 96 |
| 97 void SiftHeader::SetNextHeader (uint8_t protocol) |
| 98 { |
| 99 m_nextHeader = protocol; |
| 100 } |
| 101 |
| 102 uint8_t SiftHeader::GetNextHeader () const |
| 103 { |
| 104 return m_nextHeader; |
| 105 } |
| 106 |
| 107 void SiftHeader::SetOptionLength (uint8_t optionLength) |
| 108 { |
| 109 m_optionLength = optionLength; |
| 110 } |
| 111 |
| 112 uint8_t SiftHeader::GetOptionLength () const |
| 113 { |
| 114 return m_optionLength; |
| 115 } |
| 116 |
| 117 void SiftHeader::SetSourceAddress (Ipv4Address address) |
| 118 { |
| 119 m_sourceAddress = address; |
| 120 } |
| 121 |
| 122 Ipv4Address SiftHeader::GetSourceAddress () const |
| 123 { |
| 124 return m_sourceAddress; |
| 125 } |
| 126 |
| 127 void SiftHeader::SetDestAddress (Ipv4Address address) |
| 128 { |
| 129 m_destAddress = address; |
| 130 } |
| 131 |
| 132 Ipv4Address SiftHeader::GetDestAddress () const |
| 133 { |
| 134 return m_destAddress; |
| 135 } |
| 136 |
| 137 void SiftHeader::SetSegmentsLeft (uint8_t segmentsLeft) |
| 138 { |
| 139 m_segmentsLeft = segmentsLeft; |
| 140 } |
| 141 |
| 142 uint8_t SiftHeader::GetSegmentsLeft () const |
| 143 { |
| 144 return m_segmentsLeft; |
| 145 } |
| 146 |
| 147 void SiftHeader::SetMessageType (uint8_t messageType) |
| 148 { |
| 149 m_messageType = messageType; |
| 150 } |
| 151 |
| 152 uint8_t SiftHeader::GetMessageType () const |
| 153 { |
| 154 return m_messageType; |
| 155 } |
| 156 // New get and set functions for location |
| 157 void SiftHeader::SetSourceXLoc (int32_t x) |
| 158 { |
| 159 m_sourceXLoc = x; |
| 160 } |
| 161 |
| 162 int32_t SiftHeader::GetSourceXLoc () const |
| 163 { |
| 164 return m_sourceXLoc; |
| 165 } |
| 166 |
| 167 void SiftHeader::SetSourceYLoc (int32_t y) |
| 168 { |
| 169 m_sourceYLoc = y; |
| 170 } |
| 171 |
| 172 int32_t SiftHeader::GetSourceYLoc () const |
| 173 { |
| 174 return m_sourceYLoc; |
| 175 } |
| 176 |
| 177 void SiftHeader::SetLastSourceXLoc (int32_t x) |
| 178 { |
| 179 m_lastsourceXLoc = x; |
| 180 } |
| 181 |
| 182 int32_t SiftHeader::GetLastSourceXLoc () const |
| 183 { |
| 184 return m_lastsourceXLoc; |
| 185 } |
| 186 |
| 187 void SiftHeader::SetLastSourceYLoc (int32_t y) |
| 188 { |
| 189 m_lastsourceYLoc = y; |
| 190 } |
| 191 |
| 192 int32_t SiftHeader::GetLastSourceYLoc () const |
| 193 { |
| 194 return m_lastsourceYLoc; |
| 195 } |
| 196 |
| 197 void SiftHeader::SetDestXLoc (int32_t x) |
| 198 { |
| 199 m_destXLoc = x; |
| 200 } |
| 201 |
| 202 int32_t SiftHeader::GetDestXLoc () const |
| 203 { |
| 204 return m_destXLoc; |
| 205 } |
| 206 |
| 207 void SiftHeader::SetDestYLoc (int32_t y) |
| 208 { |
| 209 m_destYLoc = y; |
| 210 } |
| 211 |
| 212 int32_t SiftHeader::GetDestYLoc () const |
| 213 { |
| 214 return m_destYLoc; |
| 215 } |
| 216 // end of set and get functions for locations |
| 217 void SiftHeader::SetHeaderSeqNo (uint16_t seqNo) |
| 218 { |
| 219 m_headerSeqNo = seqNo; |
| 220 } |
| 221 |
| 222 uint16_t SiftHeader::GetHeaderSeqNo () const |
| 223 { |
| 224 return m_headerSeqNo; |
| 225 } |
| 226 |
| 227 void SiftHeader::SetHeaderTTL (uint8_t ttl) |
| 228 { |
| 229 m_headerTTL = ttl; |
| 230 } |
| 231 |
| 232 uint8_t SiftHeader::GetHeaderTTL () const |
| 233 { |
| 234 return m_headerTTL; |
| 235 } |
| 236 |
| 237 void SiftHeader::UpdateHeaderTTL () |
| 238 { |
| 239 m_headerTTL = m_headerTTL - 1; |
| 240 } |
| 241 |
| 242 |
| 243 void SiftHeader::SetNumberAddress (uint8_t n) |
| 244 { |
| 245 m_ipv4Address.clear (); |
| 246 m_ipv4Address.assign (n, Ipv4Address ("")); |
| 247 } |
| 248 |
| 249 void SiftHeader::SetNodesAddress (std::vector<Ipv4Address> ipv4Address) |
| 250 { |
| 251 m_ipv4Address = ipv4Address; |
| 252 SetOptionLength (10); |
| 253 } |
| 254 |
| 255 std::vector<Ipv4Address> SiftHeader::GetNodesAddresses () const |
| 256 { |
| 257 return m_ipv4Address; |
| 258 } |
| 259 |
| 260 void SiftHeader::SetNodeAddress (uint8_t index, Ipv4Address addr) |
| 261 { |
| 262 m_ipv4Address.at (index) = addr; |
| 263 } |
| 264 |
| 265 Ipv4Address SiftHeader::GetNodeAddress (uint8_t index) const |
| 266 { |
| 267 return m_ipv4Address.at (index); |
| 268 } |
| 269 |
| 270 uint8_t SiftHeader::GetNodeListSize () const |
| 271 { |
| 272 return m_ipv4Address.size (); |
| 273 } |
| 274 |
| 275 void SiftHeader::Print (std::ostream &os) const |
| 276 { |
| 277 NS_LOG_FUNCTION (this << "SiftHeader::Print"); |
| 278 os |
| 279 << " Next Protocol Header: " << (uint32_t)GetNextHeader () |
| 280 << " optionLength: " << (uint32_t)GetOptionLength () |
| 281 << " messageType: " << (uint32_t)GetMessageType () |
| 282 << " Source IP Address: " << GetSourceAddress () |
| 283 << " SourceXLoc= " << (uint32_t)GetSourceXLoc () |
| 284 << " SourceYLoc= " << (uint32_t)GetSourceYLoc () |
| 285 << " Last Source Xloc= " << (uint32_t)GetLastSourceXLoc () |
| 286 << " Last source Yloc= " << (uint32_t)GetLastSourceYLoc () |
| 287 << " Destination Ip Address: " << GetDestAddress () |
| 288 << " Dest Xloc= " << (uint32_t)GetDestXLoc () |
| 289 << " Dest YLoc= " << (uint32_t)GetDestYLoc () |
| 290 << " Seq No= " << (uint32_t) GetHeaderSeqNo () |
| 291 << " TTL= " << (uint32_t)GetHeaderTTL (); |
| 292 |
| 293 |
| 294 |
| 295 } |
| 296 void SiftHeader::Print () |
| 297 { |
| 298 |
| 299 std::cout << "Next header= " << (uint32_t)GetNextHeader () << std::endl; |
| 300 std::cout << "Option Length= " << (uint32_t)GetOptionLength () << std::endl; |
| 301 std::cout << "MessageType= " << (uint32_t)GetMessageType () << std::endl; |
| 302 std::cout << "SegmenstLeft= " << (uint32_t)GetSegmentsLeft () << std::endl; |
| 303 std::cout << "Source Address= " << GetSourceAddress () << std::endl; |
| 304 std::cout << "Destination Address= " << GetDestAddress () << std::endl; |
| 305 std::cout << "SourceXLoc= " << GetSourceXLoc () << std::endl; |
| 306 std::cout << "SourceYLoc= " << GetSourceYLoc () << std::endl; |
| 307 std::cout << "last Source Xloc= " << GetLastSourceXLoc () << std::endl; |
| 308 std::cout << "last source Yloc= " << GetLastSourceYLoc () << std::endl; |
| 309 std::cout << "dest Xloc= " << GetDestXLoc () << std::endl; |
| 310 std::cout << "dest YLoc= " << GetDestYLoc () << std::endl; |
| 311 std::cout << " Seq No= " << (uint32_t) GetHeaderSeqNo () << "\n"; |
| 312 std::cout << " TTL= " << (uint32_t)GetHeaderTTL () << "\n"; |
| 313 } |
| 314 |
| 315 uint32_t SiftHeader::GetSerializedSize () const |
| 316 { |
| 317 return HEADER_SIZE; |
| 318 } |
| 319 |
| 320 void SiftHeader::Serialize (Buffer::Iterator start) const |
| 321 { |
| 322 |
| 323 Buffer::Iterator i = start; |
| 324 |
| 325 i.WriteU8 (m_nextHeader); |
| 326 i.WriteU8 (m_optionLength); |
| 327 i.WriteU8 (m_messageType); |
| 328 i.WriteU8 (m_segmentsLeft); |
| 329 i.WriteU32 (m_sourceId); |
| 330 i.WriteU32 (m_sourceXLoc); |
| 331 i.WriteU32 (m_sourceYLoc); |
| 332 i.WriteU32 (m_lastsourceXLoc); |
| 333 i.WriteU32 (m_lastsourceYLoc); |
| 334 i.WriteU32 (m_destId); |
| 335 i.WriteU32 (m_destXLoc); |
| 336 i.WriteU32 (m_destYLoc); |
| 337 i.WriteU16 (m_headerSeqNo); |
| 338 i.WriteU8 (m_headerTTL); |
| 339 i.WriteU8 (m_pad); |
| 340 WriteTo (i, m_sourceAddress); |
| 341 WriteTo (i, m_destAddress); |
| 342 } |
| 343 |
| 344 uint32_t SiftHeader::Deserialize (Buffer::Iterator start) |
| 345 { |
| 346 Buffer::Iterator i = start; |
| 347 |
| 348 m_nextHeader = i.ReadU8 (); |
| 349 m_optionLength = i.ReadU8 (); |
| 350 m_messageType = i.ReadU8 (); |
| 351 m_segmentsLeft = i.ReadU8 (); |
| 352 m_sourceId = i.ReadU32 (); |
| 353 m_sourceXLoc = i.ReadU32 (); |
| 354 m_sourceYLoc = i.ReadU32 (); |
| 355 m_lastsourceXLoc = i.ReadU32 (); |
| 356 m_lastsourceYLoc = i.ReadU32 (); |
| 357 m_destId = i.ReadU32 (); |
| 358 m_destXLoc = i.ReadU32 (); |
| 359 m_destYLoc = i.ReadU32 (); |
| 360 m_headerSeqNo = i.ReadU16 (); |
| 361 m_headerTTL = i.ReadU8 (); |
| 362 m_pad = i.ReadU8 (); |
| 363 |
| 364 ReadFrom (i, m_sourceAddress); |
| 365 ReadFrom (i, m_destAddress); |
| 366 |
| 367 return GetSerializedSize (); |
| 368 } |
| 369 |
| 370 } /* namespace sift */ |
| 371 } /* namespace ns3 */ |
OLD | NEW |