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 NS_LOG_APPEND_CONTEXT \ |
| 33 if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId (
) << "] "; } |
| 34 #define ICMP_PROTOCOL 1 |
| 35 #define TCP_PROTOCOL 6 |
| 36 #define UDP_PROTOCOL 17 |
| 37 #define GRE_PROTOCOL 47 |
| 38 #define MAX_SEQ_NO 65536 |
| 39 #define TTL 64 |
| 40 #define ALPHA 0.01 |
| 41 static const double TRANSMISSION_TIME=0.000047; |
| 42 |
| 43 #include <list> |
| 44 #include <ctime> |
| 45 #include <map> |
| 46 #include <limits> |
| 47 #include <algorithm> |
| 48 #include <iostream> |
| 49 #include <float.h> |
| 50 //#include "ns3/config.h" |
| 51 #include "ns3/enum.h" |
| 52 #include "ns3/string.h" |
| 53 #include "ns3/ptr.h" |
| 54 #include "ns3/log.h" |
| 55 #include "ns3/fatal-error.h" |
| 56 #include "ns3/assert.h" |
| 57 #include "ns3/uinteger.h" |
| 58 #include "ns3/net-device.h" |
| 59 #include "ns3/packet.h" |
| 60 #include "ns3/boolean.h" |
| 61 #include "ns3/node-list.h" |
| 62 #include "ns3/double.h" |
| 63 #include "ns3/pointer.h" |
| 64 #include "ns3/object-vector.h" |
| 65 #include "ns3/ipv4-address.h" |
| 66 #include "ns3/ipv4-header.h" |
| 67 #include "ns3/ipv4-l3-protocol.h" |
| 68 #include "ns3/ipv4-route.h" |
| 69 #include "ns3/trace-source-accessor.h" |
| 70 #include "ns3/icmpv4-l4-protocol.h" |
| 71 #include "ns3/wifi-net-device.h" |
| 72 #include "ns3/inet-socket-address.h" |
| 73 #include "ns3/udp-l4-protocol.h" |
| 74 #include "ns3/udp-socket-factory.h" |
| 75 #include "ns3/tcp-socket-factory.h" |
| 76 #include "ns3/llc-snap-header.h" |
| 77 #include "ns3/arp-header.h" |
| 78 #include "ns3/point-to-point-net-device.h" |
| 79 #include "ns3/point-to-point-channel.h" |
| 80 #include "ns3/mobility-model.h" |
| 81 #include "ns3/trace-source-accessor.h" |
| 82 #include "ns3/adhoc-wifi-mac.h" |
| 83 |
| 84 #include "sift-routing.h" |
| 85 #include "sift-header.h" |
| 86 #include "sift-geo.h" |
| 87 |
| 88 NS_LOG_COMPONENT_DEFINE ("SiftRouting"); |
| 89 |
| 90 namespace ns3 { |
| 91 namespace sift { |
| 92 |
| 93 |
| 94 NS_OBJECT_ENSURE_REGISTERED (SiftRouting); |
| 95 |
| 96 /* see http://www.iana.org/assignments/protocol-numbers */ |
| 97 const uint8_t SiftRouting::PROT_NUMBER = 47; |
| 98 /* |
| 99 * The extension header is the sift header, it is response for recognizing SIFT
option types |
| 100 * and demux to right options to process the packet. |
| 101 * |
| 102 * The header format with neighboring layers is as follows: |
| 103 * |
| 104 +-+-+-+-+-+-+-+-+-+-+-- |
| 105 | Application Header | |
| 106 +-+-+-+-+-+-+-+-+-+-+-+ |
| 107 | Transport Header | |
| 108 +-+-+-+-+-+-+-+-+-+-+-+ |
| 109 | SIFT Header | |
| 110 +-+-+-+-+-+-+-+-+-+-+-+ |
| 111 | IP Header | |
| 112 +-+-+-+-+-+-+-+-+-+-+-+ |
| 113 */ |
| 114 |
| 115 TypeId SiftRouting::GetTypeId () |
| 116 { |
| 117 static TypeId tid = TypeId ("ns3::sift::SiftRouting") |
| 118 .SetParent<IpL4Protocol> () |
| 119 .AddConstructor<SiftRouting> () |
| 120 .AddTraceSource ("Tx", "Send SIFT packet.", |
| 121 MakeTraceSourceAccessor (&SiftRouting::m_txPacketTrace), |
| 122 "ns3::SiftRouting::TxTracedValueCallbac
k") |
| 123 .AddTraceSource ("Drop", "Drop SIFT packet", |
| 124 MakeTraceSourceAccessor (&SiftRouting::m_dropTrace), |
| 125 "ns3::SiftRouting::DropTracedValueCallb
ack") |
| 126 ; |
| 127 return tid; |
| 128 } |
| 129 |
| 130 SiftRouting::SiftRouting () |
| 131 : m_seqNo (0) |
| 132 { |
| 133 NS_LOG_FUNCTION (this); |
| 134 m_uniformRandomVariable = CreateObject<UniformRandomVariable> (); |
| 135 |
| 136 } |
| 137 |
| 138 SiftRouting::~SiftRouting () |
| 139 { |
| 140 NS_LOG_FUNCTION (this); |
| 141 } |
| 142 |
| 143 void |
| 144 SiftRouting::NotifyNewAggregate () |
| 145 { |
| 146 NS_LOG_FUNCTION (this << "NotifyNewAggregate"); |
| 147 if (m_node == 0) |
| 148 { |
| 149 Ptr<Node> node = this->GetObject<Node> (); |
| 150 if (node != 0) |
| 151 { |
| 152 m_ipv4 = this->GetObject<Ipv4L3Protocol> (); |
| 153 if (m_ipv4 != 0) |
| 154 { |
| 155 this->SetNode (node); |
| 156 m_ipv4->Insert (this); |
| 157 this->SetDownTarget (MakeCallback (&Ipv4L3Protocol::Send, m_ipv4))
; |
| 158 } |
| 159 |
| 160 m_ip = node->GetObject<Ipv4> (); |
| 161 if (m_ip != 0) |
| 162 { |
| 163 NS_LOG_DEBUG ("Ipv4 started"); |
| 164 } |
| 165 } |
| 166 } |
| 167 Object::NotifyNewAggregate (); |
| 168 Simulator::ScheduleNow (&SiftRouting::Start, this); |
| 169 } |
| 170 |
| 171 void SiftRouting::Start () |
| 172 { |
| 173 NS_LOG_FUNCTION (this << "Start SIFT Routing protocol"); |
| 174 |
| 175 if (m_mainAddress == Ipv4Address ()) |
| 176 { |
| 177 |
| 178 //add the node as a neighbor of itself |
| 179 GeographicTuple geo_tuple; |
| 180 geo_tuple.nodeAddr = m_mainAddress; |
| 181 geo_tuple.nodeReceivedFrom = m_mainAddress; |
| 182 Ptr<MobilityModel> thisNodeMobility = m_ip->GetObject<Node> ()->GetObject<
MobilityModel> (); |
| 183 geo_tuple.xcoord = (int) thisNodeMobility->GetPosition ().x; |
| 184 geo_tuple.ycoord = (int) thisNodeMobility->GetPosition ().y; |
| 185 geo_tuple.zcoord = (int) thisNodeMobility->GetPosition ().z; |
| 186 geo_tuple.xvelocity = (int) thisNodeMobility->GetVelocity ().x; |
| 187 geo_tuple.yvelocity = (int) thisNodeMobility->GetVelocity ().y; |
| 188 geo_tuple.zvelocity = (int) thisNodeMobility->GetVelocity ().z; |
| 189 |
| 190 Time now = Simulator::Now (); |
| 191 geo_tuple.recordedTime = now; |
| 192 geo_tuple.dataRecordedTime = now; |
| 193 geo_tuple.startTime = now; |
| 194 geo_tuple.expireTime = Simulator::GetMaximumSimulationTime (); |
| 195 AddGeographicTuple (geo_tuple); |
| 196 |
| 197 Ipv4Address loopback ("127.0.0.1"); |
| 198 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++) |
| 199 { |
| 200 // Use primary address, if multiple |
| 201 Ipv4Address addr = m_ipv4->GetAddress (i, 0).GetLocal (); |
| 202 m_broadcast = m_ipv4->GetAddress (i, 0).GetBroadcast (); |
| 203 |
| 204 if (addr != loopback) |
| 205 { |
| 206 // Set the main address as the current ip address |
| 207 m_mainAddress = addr; |
| 208 NS_LOG_LOGIC ("Starting SIFT on node " << m_mainAddress); |
| 209 |
| 210 NS_ASSERT (m_mainAddress != Ipv4Address () && m_broadcast != Ipv4A
ddress ()); |
| 211 } |
| 212 } |
| 213 } |
| 214 } |
| 215 |
| 216 void |
| 217 SiftRouting::AddNode (Ptr<Node> node) |
| 218 { |
| 219 NS_LOG_FUNCTION (this); |
| 220 m_nodePtrs.push_back (node); |
| 221 NS_LOG_INFO (node << "in AddNode"); |
| 222 } |
| 223 |
| 224 uint32_t |
| 225 SiftRouting::GetNodesSize (void) |
| 226 { |
| 227 NS_LOG_FUNCTION (this); |
| 228 NS_LOG_DEBUG ("m_nodePtrs.size (): " << m_nodePtrs.size ()); |
| 229 return m_nodePtrs.size (); |
| 230 } |
| 231 |
| 232 void |
| 233 SiftRouting::DoDispose (void) |
| 234 { |
| 235 NS_LOG_FUNCTION (this); |
| 236 m_node = 0; |
| 237 IpL4Protocol::DoDispose (); |
| 238 } |
| 239 |
| 240 void |
| 241 SiftRouting::SetNode (Ptr<Node> node) |
| 242 { |
| 243 NS_LOG_FUNCTION (this); |
| 244 m_node = node; |
| 245 } |
| 246 |
| 247 Ptr<Node> |
| 248 SiftRouting::GetNode () const |
| 249 { |
| 250 NS_LOG_FUNCTION (this); |
| 251 return m_node; |
| 252 } |
| 253 |
| 254 Ptr<Node> |
| 255 SiftRouting::GetNodeWithAddress (Ipv4Address ipv4Address) |
| 256 { |
| 257 NS_LOG_FUNCTION (this << ipv4Address); |
| 258 int32_t nNodes = NodeList::GetNNodes (); |
| 259 for (int32_t i = 0; i < nNodes; ++i) |
| 260 { |
| 261 Ptr<Node> node = NodeList::GetNode (i); |
| 262 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 263 int32_t ifIndex = ipv4->GetInterfaceForAddress (ipv4Address); |
| 264 if (ifIndex != -1) |
| 265 { |
| 266 return node; |
| 267 } |
| 268 } |
| 269 return 0; |
| 270 } |
| 271 |
| 272 void SiftRouting::PrintVector (std::vector<Ipv4Address>& vec) |
| 273 { |
| 274 NS_LOG_FUNCTION (this); |
| 275 /* |
| 276 * Check elements in a route vector |
| 277 */ |
| 278 if (!vec.size ()) |
| 279 { |
| 280 NS_LOG_DEBUG ("The vector is empty"); |
| 281 } |
| 282 else |
| 283 { |
| 284 NS_LOG_DEBUG ("Print all the elements in a vector"); |
| 285 for (std::vector<Ipv4Address>::const_iterator i = vec.begin (); i != vec.e
nd (); ++i) |
| 286 { |
| 287 NS_LOG_DEBUG ("The ip address " << *i); |
| 288 } |
| 289 } |
| 290 } |
| 291 |
| 292 Ptr<Ipv4Route> |
| 293 SiftRouting::SetRoute (Ipv4Address nextHop, Ipv4Address srcAddress) |
| 294 { |
| 295 NS_LOG_FUNCTION (this << nextHop << srcAddress); |
| 296 m_ipv4Route = Create<Ipv4Route> (); |
| 297 m_ipv4Route->SetDestination (nextHop); |
| 298 m_ipv4Route->SetGateway (nextHop); |
| 299 m_ipv4Route->SetSource (srcAddress); |
| 300 return m_ipv4Route; |
| 301 } |
| 302 |
| 303 int |
| 304 SiftRouting::GetProtocolNumber (void) const |
| 305 { |
| 306 NS_LOG_FUNCTION (this); |
| 307 // / This is the protocol number for SIFT which is 48 |
| 308 return PROT_NUMBER; |
| 309 } |
| 310 void SiftRouting::SetSeqNo (uint16_t seqNo) |
| 311 { |
| 312 m_seqNo = seqNo; |
| 313 } |
| 314 |
| 315 uint16_t SiftRouting::GetSeqNo () |
| 316 { |
| 317 m_seqNo = (m_seqNo + 1) % MAX_SEQ_NO; |
| 318 return m_seqNo; |
| 319 } |
| 320 |
| 321 void |
| 322 SiftRouting::Send (Ptr<Packet> packet, |
| 323 Ipv4Address source, |
| 324 Ipv4Address destination, |
| 325 uint8_t protocol, |
| 326 Ptr<Ipv4Route> route) |
| 327 { |
| 328 NS_LOG_FUNCTION (this << "Send module"); |
| 329 NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol
<< route); |
| 330 |
| 331 // "packet" parameter is UDP header |
| 332 |
| 333 if (source == destination) |
| 334 { |
| 335 std::cout << "\nSimulator created similar source and destination! Source:
" << source << " destination: " << destination << "\n"; |
| 336 return; |
| 337 } |
| 338 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, SiftRouting cannot send downwa
rd"); |
| 339 |
| 340 if (1) |
| 341 { |
| 342 Time now = Simulator::Now (); |
| 343 NS_LOG_INFO ("\nSend from node (" << this->GetNode ()->GetId () << ") with
IP address: " |
| 344 << this->GetIPfromID (this->GetNode ()->
GetId ()) << " at time: " << now << "\n"); |
| 345 |
| 346 } |
| 347 if (protocol == 1) |
| 348 { |
| 349 NS_LOG_INFO ("Drop packet. Not handling ICMP packet for now"); |
| 350 } |
| 351 else |
| 352 { |
| 353 |
| 354 NS_LOG_INFO ("Protocol number if protocol<>1: " << (uint32_t)protocol); |
| 355 Ptr<Packet> cleanP = packet->Copy (); |
| 356 SiftHeader siftHeader; |
| 357 siftHeader.SetNextHeader (protocol); |
| 358 siftHeader.SetMessageType (47); |
| 359 siftHeader.SetSourceAddress (source); |
| 360 siftHeader.SetDestAddress (destination); |
| 361 |
| 362 // take this node's location |
| 363 Ptr<MobilityModel> mobility = GetObject<Node> ()->GetObject<MobilityModel>
(); |
| 364 Ptr<Node> destNode = GetNodeWithAddress (destination); |
| 365 Ptr<Node> sourceNode = GetNodeWithAddress (source); |
| 366 Ptr<MobilityModel> destMobility = destNode->GetObject<MobilityModel> (); |
| 367 Ptr<MobilityModel> sourceMobility = sourceNode->GetObject<MobilityModel> (
); |
| 368 int32_t x_ = sourceMobility->GetPosition ().x; |
| 369 int32_t y_ = sourceMobility->GetPosition ().y; |
| 370 int32_t x = mobility->GetPosition ().x; |
| 371 int32_t y = mobility->GetPosition ().y; |
| 372 int32_t x1 = destMobility->GetPosition ().x; |
| 373 int32_t y1 = destMobility->GetPosition ().y; |
| 374 siftHeader.SetSourceXLoc ((int32_t)x_); |
| 375 siftHeader.SetSourceYLoc ((int32_t)y_); |
| 376 siftHeader.SetLastSourceXLoc ((int32_t)x); |
| 377 siftHeader.SetLastSourceYLoc ((int32_t)y); |
| 378 siftHeader.SetDestXLoc ((int32_t)x1); |
| 379 siftHeader.SetDestYLoc ((int32_t)y1); |
| 380 siftHeader.SetHeaderSeqNo (GetSeqNo ()); |
| 381 siftHeader.SetHeaderTTL (TTL); |
| 382 NS_LOG_DEBUG (this << "Node positions in Send module of node: " << this->G
etNode ()->GetId () << |
| 383 " (source X, Source Y)= (" |
| 384 << x_ << ", " << y_ << ") (Current X, Current Y)= (" |
| 385 << x << ", " << y << ") (Destination X, Destination Y)=
(" |
| 386 << x1 << ", " << y1 << ")"); |
| 387 |
| 388 |
| 389 |
| 390 cleanP->AddHeader (siftHeader); |
| 391 Ptr<Packet> mtP = cleanP->Copy (); |
| 392 |
| 393 // Save a copy of packet in the buffer to check duplicate packets |
| 394 m_buffer.insert (std::pair<Ptr<Packet>,Time> (mtP,Simulator::Now ())); |
| 395 // Send the packet out with header |
| 396 SendPacket (mtP, source, m_broadcast, protocol); |
| 397 |
| 398 } |
| 399 } |
| 400 |
| 401 void |
| 402 SiftRouting::SendPacket (Ptr<Packet> packet, Ipv4Address source, Ipv4Address nex
tHop, uint8_t protocol) |
| 403 { |
| 404 NS_LOG_FUNCTION (this << "SiftRouting::SendPacket module"); |
| 405 NS_LOG_FUNCTION (this << packet << source << nextHop << (uint32_t)protocol); |
| 406 // Send out the data packet |
| 407 |
| 408 m_ipv4Route = SetRoute (nextHop, m_mainAddress); |
| 409 Ptr<NetDevice> dev = m_ip->GetNetDevice (m_ip->GetInterfaceForAddress (m_mainA
ddress)); |
| 410 m_ipv4Route->SetOutputDevice (dev); |
| 411 |
| 412 if (protocol == UDP_PROTOCOL || protocol == TCP_PROTOCOL || protocol == ICMP_P
ROTOCOL) |
| 413 { |
| 414 |
| 415 //m_downTarget (packet, source, nextHop, protocol, m_ipv4Route); |
| 416 m_downTarget (packet, source, nextHop, GetProtocolNumber (), m_ipv4Route); |
| 417 } |
| 418 else |
| 419 { |
| 420 m_downTarget (packet, source, nextHop, GetProtocolNumber (), m_ipv4Route); |
| 421 } |
| 422 } |
| 423 |
| 424 int64_t |
| 425 SiftRouting::AssignStreams (int64_t stream) |
| 426 { |
| 427 NS_LOG_FUNCTION (this << stream); |
| 428 m_uniformRandomVariable->SetStream (stream); |
| 429 return 1; |
| 430 } |
| 431 |
| 432 void |
| 433 SiftRouting::ForwardPacket (Ptr<Packet> packet, |
| 434 Ipv4Address source, |
| 435 uint8_t protocol) |
| 436 { |
| 437 NS_LOG_FUNCTION (this << "SiftRouting::ForwardPacket module"); |
| 438 NS_LOG_FUNCTION (this << packet << source << (uint32_t)protocol); |
| 439 NS_ASSERT_MSG (!m_downTarget.IsNull (), "Error, SiftRouting cannot send downwa
rd"); |
| 440 |
| 441 |
| 442 // Forward the packet here, we will not use any coding and multipath here |
| 443 SendPacket (packet, source, m_broadcast, protocol); |
| 444 } |
| 445 |
| 446 void |
| 447 SiftRouting::ScheduleTimer (Ptr<Packet> packet, Time delay, Ipv4Address source,
uint8_t protocol) |
| 448 { |
| 449 NS_LOG_FUNCTION ("SiftRouting::ScheduleTimer" << this << packet << delay << so
urce << (uint32_t)protocol); |
| 450 NS_LOG_INFO (this << packet << delay << source << protocol); |
| 451 |
| 452 |
| 453 |
| 454 SiftHeader tempSift, timerSift; |
| 455 packet->PeekHeader (tempSift); |
| 456 bool matchFound = false; |
| 457 if (m_timer.size () == 0) // Timer buffer is empty. This is the first pack
et being scheduled |
| 458 { |
| 459 NS_LOG_DEBUG ("In ScheduleTimer of node (" << this->GetNode ()->GetId () <
< ") with IP address: " |
| 460 << this->GetIPfromID (this->Get
Node ()->GetId ()) |
| 461 << "Timer buffer is empty. New
packet is scheduling. \nThis is the packet: \n" |
| 462 << " Current time: " << Seconds
(Simulator::Now ()) ); |
| 463 |
| 464 Timer timer (Timer::CANCEL_ON_DESTROY); |
| 465 m_timer[packet] = timer; |
| 466 } |
| 467 else // Timer buffer has some content
. Duplicate packets are checking and if there is no duplication, the packet is s
cheduled. |
| 468 { |
| 469 for (std::map<Ptr<Packet>,Timer >::iterator it = m_timer.begin (); it != m
_timer.end (); ++it) |
| 470 { |
| 471 (it->first)->PeekHeader (timerSift); |
| 472 NS_LOG_DEBUG (*(it->first) << " State in ScheduleTimer: " << (it->seco
nd).GetState () << " Current Time (Sec): " << Seconds (Simulator::Now ()) ); |
| 473 |
| 474 if (timerSift.GetSourceAddress () == tempSift.GetSourceAddress () |
| 475 && timerSift.GetDestAddress () == tempSift.GetDestAddress () |
| 476 && timerSift.GetHeaderSeqNo () == tempSift.GetHeaderSeqNo () |
| 477 && matchFound == false) // Checking duplicate packets |
| 478 { |
| 479 NS_LOG_DEBUG ("\nMatch was found in timer buffer (duplicate packet
). The packet is unscheduling and erasing\n"); |
| 480 |
| 481 // A duplicate packet was found for a new arrival packet. |
| 482 (it->second).Cancel (); |
| 483 //sum_timer.erase(it); |
| 484 matchFound = true; |
| 485 |
| 486 } |
| 487 if ((it->second).GetState () == Timer::EXPIRED) //Expired ev
ent |
| 488 { |
| 489 NS_LOG_DEBUG ("One expired event was removed at node (" << this->G
etNode ()->GetId () << ") with IP address: " |
| 490 << this->G
etIPfromID (this->GetNode ()->GetId ()) |
| 491 << "Curren
t time (sec): " << Seconds (Simulator::Now ())); |
| 492 |
| 493 m_timer.erase (it); |
| 494 } |
| 495 |
| 496 } |
| 497 if (matchFound == false) |
| 498 { |
| 499 NS_LOG_DEBUG ("No duplication was found. New packet is scheduling ....
Current time: " << Seconds (Simulator::Now ())); |
| 500 |
| 501 Timer timer (Timer::CANCEL_ON_DESTROY); |
| 502 m_timer[packet] = timer; |
| 503 } |
| 504 } |
| 505 |
| 506 |
| 507 // When the timer expires, it will call this function here, which is send for
this case |
| 508 m_timer[packet].SetFunction (&SiftRouting::ForwardPacket, this); |
| 509 m_timer[packet].Remove (); |
| 510 m_timer[packet].SetArguments (packet, source, protocol); |
| 511 m_timer[packet].Schedule (delay); |
| 512 } |
| 513 |
| 514 void· |
| 515 SiftRouting::CancelTimer (Ptr<Packet> p) |
| 516 { |
| 517 NS_LOG_FUNCTION ("SiftRouting::CancelTimer"); |
| 518 NS_LOG_INFO (this << p ); |
| 519 |
| 520 // We erase the timer if we have received it before |
| 521 NS_LOG_DEBUG ("\nTimer Content: \n"); |
| 522 SiftHeader tempSift, timerSift; |
| 523 p->PeekHeader (tempSift); |
| 524 for (std::map<Ptr<Packet>,Timer >::iterator it = m_timer.begin (); it != m_tim
er.end (); ++it) |
| 525 { |
| 526 (it->first)->PeekHeader (timerSift); |
| 527 NS_LOG_DEBUG (*(it->first) << " State: " << (it->second).GetState () << "
Current Time: " << Simulator::Now ()); |
| 528 |
| 529 if (timerSift.GetSourceAddress () == tempSift.GetSourceAddress () |
| 530 && timerSift.GetDestAddress () == tempSift.GetDestAddress () |
| 531 && timerSift.GetHeaderSeqNo () == tempSift.GetHeaderSeqNo ()) |
| 532 { |
| 533 NS_LOG_DEBUG ("\nMatch was found in timer buffer (Cancel Timer). The r
ecord is deleting \n"); |
| 534 (it->second).Cancel (); |
| 535 m_timer.erase (it); |
| 536 break; |
| 537 } |
| 538 |
| 539 } |
| 540 |
| 541 } |
| 542 |
| 543 enum IpL4Protocol::RxStatus |
| 544 SiftRouting::Receive (Ptr<Packet> p, |
| 545 Ipv4Header const &ip, |
| 546 Ptr<Ipv4Interface> incomingInterface) |
| 547 { |
| 548 |
| 549 NS_LOG_FUNCTION (this << *p << ip << incomingInterface); |
| 550 |
| 551 |
| 552 NS_LOG_INFO ("Our own IP address " << m_mainAddress << " The incoming interfac
e address " << incomingInterface); |
| 553 m_node = GetNode (); // Get the node |
| 554 NS_LOG_FUNCTION ("\n\nEntering Receive module of node: " << m_node->GetId () <
< " with IP address: " << this->GetIPfromID (this->GetNode ()->GetId ())); |
| 555 |
| 556 Ptr<Packet> packet = p->Copy (); // Save a copy of the received pac
ket |
| 557 |
| 558 |
| 559 SiftHeader siftHeader; |
| 560 packet->RemoveHeader (siftHeader); // Remove the SIFT header in whole |
| 561 uint8_t protocol = 0; |
| 562 protocol = GetProtocolNumber (); |
| 563 |
| 564 Ipv4Address sourceAddress = siftHeader.GetSourceAddress (); |
| 565 Ipv4Address destAddress = siftHeader.GetDestAddress (); |
| 566 int32_t sourceXLoc = siftHeader.GetSourceXLoc (); |
| 567 int32_t sourceYLoc = siftHeader.GetSourceYLoc (); |
| 568 int32_t lastsourceXLoc = siftHeader.GetLastSourceXLoc (); |
| 569 int32_t lastsourceYLoc = siftHeader.GetLastSourceYLoc (); |
| 570 int32_t destXLoc = siftHeader.GetDestXLoc (); |
| 571 int32_t destYLoc = siftHeader.GetDestYLoc (); |
| 572 |
| 573 uint8_t segmentsLeft = siftHeader.GetSegmentsLeft (); |
| 574 uint16_t headerSeqNo = siftHeader.GetHeaderSeqNo (); |
| 575 uint8_t headerTTL = siftHeader.GetHeaderTTL (); |
| 576 |
| 577 NS_LOG_FUNCTION ("\tCurrent Address= " << m_mainAddress << " with position (" |
| 578 << GetObject<Node> ()->GetObject<Mobili
tyModel> ()->GetPosition ().x << ", " |
| 579 << GetObject<Node> ()->GetObject<Mobili
tyModel> ()->GetPosition ().y << ")\n" |
| 580 << "\tSource Address= " << sourceAddres
s << " with position (" << sourceXLoc << ", " << sourceYLoc << ")\n" |
| 581 << "\tDestination Address= " << destAdd
ress << " with position (" << destXLoc << ", " << destYLoc << ")\n" |
| 582 << "\tLast Sourece Position (" << lasts
ourceXLoc << ", " << lastsourceYLoc << ")\n"); |
| 583 |
| 584 |
| 585 |
| 586 if (destAddress.IsEqual ("0.0.0.0")) |
| 587 { |
| 588 NS_LOG_DEBUG ("A 0.0.0.0 received in Receive module at time: " << Seconds
(Simulator::Now ()) |
| 589 << "\nRetur
ning from the Receive module with code RX_ENDPOINT_UNREACH\n"); |
| 590 |
| 591 return RX_ENDPOINT_UNREACH; |
| 592 } |
| 593 if ((int)GetObject<Node> ()->GetObject<MobilityModel> ()->GetPosition ().x ==
sourceXLoc |
| 594 && (int)GetObject<Node> ()->GetObject<MobilityModel> ()->GetPosition ().y
== sourceYLoc ) |
| 595 { |
| 596 NS_LOG_DEBUG ("\nCurrent node position has overlap with Source. Discarding
the packet.\n"); |
| 597 return RX_ENDPOINT_UNREACH; |
| 598 } |
| 599 |
| 600 NS_LOG_DEBUG ("The segments left in source route header " << (uint32_t)segment
sLeft); |
| 601 Ptr<Packet> tempPacket; |
| 602 SiftHeader tempSift; |
| 603 bool duplicate = false; |
| 604 NS_LOG_DEBUG ("\nChecking Receive Buffer in node: " << this->GetIPfromID (this
->GetNode ()->GetId ()) << " ... \n"); |
| 605 |
| 606 |
| 607 NS_LOG_DEBUG ("\n Comparing Source Address: " << sourceAddress << " Destinatio
n Address: " << destAddress << " Seq No: " << headerSeqNo << " with the content
of the buffer ... \n"); |
| 608 |
| 609 for (std::map<Ptr<Packet>,Time >::iterator it = m_buffer.begin (); it != m_buf
fer.end (); ++it) |
| 610 { |
| 611 if (Simulator::Now () - it->second >= Seconds (3)) |
| 612 { |
| 613 m_buffer.erase (it); |
| 614 NS_LOG_DEBUG ("One expired packet was removed from buffer of node: " <
< this->GetIPfromID (this->GetNode ()->GetId ())); |
| 615 |
| 616 } |
| 617 else |
| 618 { |
| 619 tempPacket = it->first; |
| 620 tempPacket->PeekHeader (tempSift); |
| 621 |
| 622 if (tempSift.GetSourceAddress () == sourceAddress |
| 623 && tempSift.GetDestAddress () == destAddress |
| 624 && tempSift.GetHeaderSeqNo () == headerSeqNo) |
| 625 { |
| 626 NS_LOG_INFO (" Duplicate packet received " << m_node->GetId () <<
p); |
| 627 CancelTimer (tempPacket); |
| 628 duplicate = true; |
| 629 return RX_ENDPOINT_UNREACH; |
| 630 } |
| 631 |
| 632 |
| 633 } // end of else (Simulator::Now()-it->second >= Seconds(2) |
| 634 } // end of for |
| 635 |
| 636 if (duplicate == false) |
| 637 { |
| 638 m_buffer.insert (std::pair<Ptr<Packet>,Time> (p,Simulator::Now ())); |
| 639 NS_LOG_DEBUG ("One packet was added to node " << this->GetIPfromID (this->
GetNode ()->GetId ()) |
| 640 << "Current time: " << Secon
ds (Simulator::Now ()) << "\n"); |
| 641 |
| 642 } |
| 643 |
| 644 Ipv4Address zero; |
| 645 zero.Set ("0.0.0.0"); |
| 646 if (destAddress.IsEqual (zero)) |
| 647 { |
| 648 NS_LOG_DEBUG( "Unexpected IP address 0.0.0.0 is detected" |
| 649 << "Source Address= " << sourceAddress << ", " |
| 650 << "Destination Address= " << destAddress << ", " |
| 651 << "SourceXLoc= " << sourceXLoc << ", " |
| 652 << "SourceYLoc= " << sourceYLoc << ", " |
| 653 << "last Source Xlox= " << lastsourceXLoc << ", " |
| 654 << "last source Yloc= " << lastsourceYLoc << ", " |
| 655 << "dest Xloc= " << destXLoc << ", " |
| 656 << "dest YLoc= " << destYLoc); |
| 657 std::cout << "Content of PACKET:\n"; |
| 658 packet->Print (std::cout); |
| 659 std::cout << "\nContent of P:\n"; |
| 660 p->Print (std::cout); |
| 661 std::cout << "\nContent of Sift Headre:\n"; |
| 662 siftHeader.Print (); |
| 663 |
| 664 } |
| 665 |
| 666 |
| 667 if (m_mainAddress == destAddress) // This is the final destination of the pa
cket |
| 668 { |
| 669 |
| 670 // / Get the next header, should be one transport protocol |
| 671 NS_LOG_INFO ("*** This is FINAL destination ***"); |
| 672 NS_LOG_INFO ("Sift Header details: " |
| 673 << "\n\t Source geographic location (x,y): (" << sourceXLoc <
< ", " << sourceYLoc << ")" |
| 674 << "\n\t Source IP Address: " << sourceAddress |
| 675 << "\n\t Destination geographic location (x,y): (" << destXLo
c << ", " << destYLoc << ")" |
| 676 << "\n\t Destination IP Address: " << destAddress); |
| 677 |
| 678 uint8_t nextHeader = siftHeader.GetNextHeader (); |
| 679 |
| 680 |
| 681 Ptr<Ipv4L3Protocol> l3proto = m_node->GetObject<Ipv4L3Protocol> (); |
| 682 Ptr<IpL4Protocol> nextProto = l3proto->GetProtocol (nextHeader); |
| 683 |
| 684 |
| 685 if (nextProto != 0) |
| 686 { |
| 687 // we need to make a copy in the unlikely event we hit the |
| 688 // RX_ENDPOINT_UNREACH code path |
| 689 // Here we can use the packet that has been get off whole SIFT header,
which is packet p |
| 690 |
| 691 Ipv4Header ipHeader; |
| 692 ipHeader.SetDestination (m_mainAddress); |
| 693 ipHeader.SetSource ((ip.GetSource ())); |
| 694 ipHeader.SetProtocol (ip.GetProtocol ()); |
| 695 ipHeader.SetPayloadSize (ip.GetPayloadSize ()); |
| 696 ipHeader.SetTos (ip.GetTos ()); |
| 697 ipHeader.SetTtl (ip.GetTtl ()); |
| 698 ipHeader.SetEcn (ip.GetEcn ()); |
| 699 ipHeader.SetDscp (ip.GetDscp ()); |
| 700 |
| 701 |
| 702 |
| 703 // Packet is L4 header, ipHeader is L3 header |
| 704 enum IpL4Protocol::RxStatus status = |
| 705 nextProto->Receive (packet, ipHeader, incomingInterface); |
| 706 |
| 707 NS_LOG_DEBUG ("The receive status " << status); |
| 708 |
| 709 switch (status) |
| 710 { |
| 711 case IpL4Protocol::RX_OK: |
| 712 |
| 713 NS_LOG_DEBUG ("\n*** RX_Ok for packet in node " << GetNode ()->Get
Id () << "at time: " << Simulator::Now () << "\n"); |
| 714 break; |
| 715 // fall through |
| 716 case IpL4Protocol::RX_ENDPOINT_CLOSED: |
| 717 NS_LOG_DEBUG ("\n*** RX_ENDPOINT_CLOSED for packet in node \n"); |
| 718 break; |
| 719 // fall through |
| 720 case IpL4Protocol::RX_CSUM_FAILED: |
| 721 NS_LOG_DEBUG ("\n*** RX_CSUM_FAILED for packet in node \n"); |
| 722 break; |
| 723 case IpL4Protocol::RX_ENDPOINT_UNREACH: |
| 724 NS_LOG_DEBUG ("\n*** RX_ENDPOINT_UNREACH for packet in node " << m
_node->GetId () << GetTypeId () << GetNode () << "\n"); |
| 725 |
| 726 if (ip.GetDestination ().IsBroadcast () == true |
| 727 || ip.GetDestination ().IsMulticast () == true) |
| 728 { |
| 729 |
| 730 break; // Do not reply to broadcast or multicast |
| 731 } |
| 732 // Another case to suppress ICMP is a subnet-directed broadcast |
| 733 } |
| 734 return status; |
| 735 } |
| 736 else |
| 737 { |
| 738 NS_FATAL_ERROR ("Should not have 0 next protocol value"); |
| 739 } |
| 740 } |
| 741 else // This is not final destination, forward the packet to next hop |
| 742 { |
| 743 |
| 744 GeographicTuple geoTuple; |
| 745 NS_LOG_INFO ("This is not the final destination, forward the packet to nex
t hop"); |
| 746 siftHeader.SetSegmentsLeft (segmentsLeft - 1); // decrement the segments
left field |
| 747 siftHeader.SetNextHeader (protocol); |
| 748 siftHeader.SetMessageType (2); |
| 749 siftHeader.SetSourceAddress (sourceAddress); |
| 750 siftHeader.SetSourceXLoc (sourceXLoc); // New code |
| 751 siftHeader.SetSourceYLoc (sourceYLoc); |
| 752 siftHeader.SetLastSourceXLoc (GetObject<Node> ()->GetObject<MobilityModel>
()->GetPosition ().x); |
| 753 siftHeader.SetLastSourceYLoc (GetObject<Node> ()->GetObject<MobilityModel>
()->GetPosition ().y); |
| 754 siftHeader.SetDestAddress (destAddress); |
| 755 siftHeader.SetDestXLoc (destXLoc); |
| 756 siftHeader.SetDestYLoc (destYLoc); // New c
ode |
| 757 siftHeader.SetHeaderSeqNo (headerSeqNo); |
| 758 siftHeader.SetHeaderTTL (headerTTL - 1); |
| 759 packet->AddHeader (siftHeader); |
| 760 NS_LOG_DEBUG ("Current node IP: " << this->GetIPfromID (this->GetNode ()->
GetId ()) << |
| 761 ", Current Node Id:" << this->GetNode ()->GetId () << |
| 762 ", This is not final destination for this packet in Receive
module at time: " << Seconds (Simulator::Now ()) << "\n"); |
| 763 |
| 764 |
| 765 for (uint32_t nodeNum = 0; nodeNum < GetNodesSize (); nodeNum++) |
| 766 { |
| 767 //GeographicTuple geoTuple; |
| 768 Ptr<Node> node = m_nodePtrs[nodeNum]; |
| 769 NS_ASSERT (node != 0); |
| 770 geoTuple.nodeAddr = node->GetObject<Ipv4> ()->GetAddress (1, 0).GetLoc
al (); |
| 771 Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> (); |
| 772 |
| 773 |
| 774 Time now = Simulator::Now (); |
| 775 geoTuple.nodeReceivedFrom = m_mainAddress; |
| 776 geoTuple.recordedTime = now; |
| 777 geoTuple.dataRecordedTime = now; |
| 778 geoTuple.expireTime = Simulator::GetMaximumSimulationTime (); |
| 779 geoTuple.xcoord = (int32_t) mobility->GetPosition ().x; |
| 780 geoTuple.ycoord = (int32_t) mobility->GetPosition ().y; |
| 781 geoTuple.zcoord = (int32_t) mobility->GetPosition ().z; |
| 782 geoTuple.xvelocity = (uint16_t) mobility->GetVelocity ().x; |
| 783 geoTuple.yvelocity = (uint16_t) mobility->GetVelocity ().y; |
| 784 geoTuple.zvelocity = (uint16_t) mobility->GetVelocity ().z; |
| 785 bool needTriggerUpdate = false; |
| 786 m_state.InsertGeographicTuple (geoTuple, needTriggerUpdate); |
| 787 NS_LOG_INFO ("Current Location details: " << geoTuple.nodeAddr |
| 788 << " X:" << (int)geoTuple.xc
oord |
| 789 << " Y:" << (int)geoTuple.yc
oord |
| 790 << " Z:" << (int)geoTuple.zc
oord |
| 791 << " Vx:" << (int)geoTuple.x
velocity |
| 792 << " Vy:" << (int)geoTuple.y
velocity |
| 793 << " Vz:" << (int)geoTuple.z
velocity); |
| 794 NS_LOG_INFO ("Sift Header details: " |
| 795 << "\n\t Source geographic location (x,y): (" << sourceXL
oc << ", " << sourceYLoc << ")" |
| 796 << "\n\t Source IP Address: " << sourceAddress |
| 797 << "\n\t Current geographic location (x,y): (" << (int) m
obility->GetPosition ().x << ", " << (int) mobility->GetPosition ().y << ")" |
| 798 << "\n\t Current IP Address: " << m_mainAddress |
| 799 << "\n\t Destination geographic location (x,y): (" << des
tXLoc << ", " << destYLoc << ")" |
| 800 << "\n\t Destination IP Address: " << destAddress); |
| 801 |
| 802 } |
| 803 |
| 804 |
| 805 // calculation of dist. |
| 806 double currentX = siftHeader.GetLastSourceXLoc (); |
| 807 double currentY = siftHeader.GetLastSourceYLoc (); |
| 808 double slope = 0; // slope= (destYLoc-sourceYLoc)/(destXLoc-sourceXLoc); /
/y=mx+b |
| 809 double Y = (destYLoc - sourceYLoc); |
| 810 double X = (destXLoc - sourceXLoc); |
| 811 double dTrajectory = 0.0; // Distance of the current node from the traject
ory |
| 812 double dLastSource = 0.0; // Distance of the current node from the last se
nder |
| 813 double b = 0.0; |
| 814 double xIntersect = 0.0; |
| 815 double yIntersect = 0.0; |
| 816 double delayTimer = (double)TRANSMISSION_TIME; |
| 817 |
| 818 if (Y == 0) |
| 819 { |
| 820 slope = 0; |
| 821 b = sourceYLoc - (slope * sourceXLoc); |
| 822 |
| 823 xIntersect = (currentX + slope * currentY - slope * b) / (pow (slope,2
) + 1); |
| 824 yIntersect = slope * xIntersect + b; |
| 825 dTrajectory = sqrt (pow ((xIntersect - currentX),2) + pow ((yIntersect
- currentY),2)); |
| 826 dLastSource = sqrt (pow ((lastsourceXLoc - currentX),2) + |
| 827 pow ((lastsourceYLoc - currentY),2)); |
| 828 |
| 829 |
| 830 } |
| 831 else if (X == 0) |
| 832 { |
| 833 dLastSource = sqrt (pow ((lastsourceXLoc - currentX),2) + |
| 834 pow ((lastsourceYLoc - currentY),2)); |
| 835 dTrajectory = sqrt (pow (dLastSource,2) - pow ((currentY - lastsourceY
Loc),2)); // They have the same x value |
| 836 } |
| 837 else |
| 838 { |
| 839 slope = Y / X; |
| 840 b = sourceYLoc - (slope * sourceXLoc); |
| 841 xIntersect = (currentX + slope * currentY - slope * b) / (pow (slope,2
) + 1); |
| 842 yIntersect = slope * xIntersect + b; |
| 843 dTrajectory = sqrt (pow ((xIntersect - currentX),2) + pow ((yIntersect
- currentY),2)); |
| 844 dLastSource = sqrt (pow ((lastsourceXLoc - currentX),2) + |
| 845 pow ((lastsourceYLoc - currentY),2)); |
| 846 |
| 847 } |
| 848 /// calculate the delay for each packet and pass it in |
| 849 /// as a time value, ns3 has one class called *Time* |
| 850 /// if the timer expires, we will forward the packet |
| 851 |
| 852 if (dTrajectory == 0) |
| 853 { |
| 854 dTrajectory = 1; |
| 855 } |
| 856 try |
| 857 { |
| 858 delayTimer += ALPHA * ((double)(dTrajectory / dLastSource)); |
| 859 } |
| 860 catch (int e) |
| 861 { |
| 862 std::cout << "\n\n Unable to calculate delay. dTrajectory=" << dTrajec
tory << " dLastSource= " << dLastSource << "\n"; |
| 863 Simulator::Stop (); |
| 864 } |
| 865 |
| 866 /// calculate the delay time here |
| 867 /// The default time is in Second |
| 868 Time delay = Seconds (delayTimer); |
| 869 |
| 870 NS_LOG_DEBUG (" SIFT routing calculation" |
| 871 << "\n\t destYLoc= " << destYLoc |
| 872 << ", SourceYLoc: " << sourceYLoc |
| 873 << ", destXLoc: " << destXLoc |
| 874 << ", sourceXLoc: " << sourceXLoc |
| 875 << "\n\t Slope= x1/x2 = " << slope |
| 876 << "\n\t b in y=m+b is sourceYLoc-(slope*sourceXLoc)= " <<
b |
| 877 << "\n\t dTrajectory= |y1-mx1-b|/Sqrt(m*m+1)= " << dTraject
ory |
| 878 << "\n\t dLastSource: " << dLastSource |
| 879 << "\n\t Y= (destYLoc-sourceYLoc)= " << Y |
| 880 << ", X= (destXLoc-sourceXLoc)= " << X |
| 881 << "\n\t Delay: " << delay |
| 882 << "\n\t Current time: " << Seconds (Simulator::Now ())); |
| 883 |
| 884 |
| 885 |
| 886 //*** Changed p to packet in the below command |
| 887 ScheduleTimer (packet, delay, sourceAddress, protocol); |
| 888 |
| 889 } |
| 890 |
| 891 return IpL4Protocol::RX_OK; |
| 892 } |
| 893 |
| 894 enum IpL4Protocol::RxStatus |
| 895 SiftRouting::Receive (Ptr<Packet> p, |
| 896 Ipv6Header const &ip, |
| 897 Ptr<Ipv6Interface> incomingInterface) |
| 898 { |
| 899 //NS_LOG_FUNCTION (this << p << ip.GetSourceAddress () << ip.GetDestinationAdd
ress () << incomingInterface); |
| 900 return IpL4Protocol::RX_ENDPOINT_UNREACH; |
| 901 } |
| 902 |
| 903 void |
| 904 SiftRouting::SetDownTarget (DownTargetCallback callback) |
| 905 { |
| 906 m_downTarget = callback; |
| 907 } |
| 908 |
| 909 void |
| 910 SiftRouting::SetDownTarget6 (DownTargetCallback6 callback) |
| 911 { |
| 912 NS_FATAL_ERROR ("Unimplemented"); |
| 913 } |
| 914 |
| 915 |
| 916 IpL4Protocol::DownTargetCallback |
| 917 SiftRouting::GetDownTarget (void) const |
| 918 { |
| 919 return m_downTarget; |
| 920 } |
| 921 |
| 922 IpL4Protocol::DownTargetCallback6 |
| 923 SiftRouting::GetDownTarget6 (void) const |
| 924 { |
| 925 NS_FATAL_ERROR ("Unimplemented"); |
| 926 return MakeNullCallback<void,Ptr<Packet>, Ipv6Address, Ipv6Address, uint8_t, P
tr<Ipv6Route> > (); |
| 927 } |
| 928 |
| 929 uint16_t |
| 930 SiftRouting::GetIDfromIP (Ipv4Address address) |
| 931 { |
| 932 int32_t nNodes = NodeList::GetNNodes (); |
| 933 for (int32_t i = 0; i < nNodes; ++i) |
| 934 { |
| 935 Ptr<Node> node = NodeList::GetNode (i); |
| 936 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 937 |
| 938 int tempint; |
| 939 tempint = ipv4->GetNInterfaces (); |
| 940 for (int j = 1; j < tempint; j++)· |
| 941 { |
| 942 Ipv4InterfaceAddress iaddr = ipv4->GetAddress (j, 0); |
| 943 if (iaddr.GetLocal () == address) |
| 944 { |
| 945 NS_LOG_DEBUG ("Test address " << i << "," << iaddr.GetLocal ()); |
| 946 return uint16_t (i); |
| 947 } |
| 948 } |
| 949 } |
| 950 return 256; |
| 951 } |
| 952 |
| 953 Ipv4Address |
| 954 SiftRouting::GetIPfromID (const uint32_t id) |
| 955 { |
| 956 NS_LOG_FUNCTION (this); |
| 957 |
| 958 if (id >= 256) |
| 959 { |
| 960 NS_LOG_DEBUG ("Exceed the node range"); |
| 961 return "0.0.0.0"; |
| 962 } |
| 963 else |
| 964 { |
| 965 Ptr<Node> node = NodeList::GetNode (id); |
| 966 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 967 return ipv4->GetAddress (1, 0).GetLocal (); |
| 968 } |
| 969 } |
| 970 |
| 971 void SiftRouting::AddGeographicTuple (const GeographicTuple &tuple) |
| 972 { |
| 973 bool needTriggerUpdate = false; |
| 974 m_state.InsertGeographicTuple (tuple, needTriggerUpdate); |
| 975 } |
| 976 void SiftRouting::PrintSiftHeader (SiftHeader siftHeader, GeographicTuple geoTup
le, Ptr<OutputStreamWrapper> stream) const |
| 977 { |
| 978 Ptr<Node> node = SiftRouting::GetNode (); |
| 979 Ipv4Address sourceAddress = siftHeader.GetSourceAddress (); |
| 980 Ipv4Address destAddress = siftHeader.GetDestAddress (); |
| 981 int32_t sourceXLoc = siftHeader.GetSourceXLoc (); |
| 982 int32_t sourceYLoc = siftHeader.GetSourceYLoc (); |
| 983 int32_t lastsourceXLoc = siftHeader.GetLastSourceXLoc (); |
| 984 int32_t lastsourceYLoc = siftHeader.GetLastSourceYLoc (); |
| 985 int32_t destXLoc = siftHeader.GetDestXLoc (); |
| 986 int32_t destYLoc = siftHeader.GetDestYLoc (); |
| 987 Ipv4Address currentAddress = node->GetObject<Ipv4> ()->GetAddress (1,0).GetLoc
al (); |
| 988 *stream->GetStream () << "Current Node IP address= " << currentAddress << std:
:endl |
| 989 << "Source Address= " << sourceAddress << std::endl |
| 990 << "Destination Address= " << destAddress << std::endl |
| 991 << "SourceXLoc= " << sourceXLoc << std::endl |
| 992 << "SourceYLoc= " << sourceYLoc << std::endl |
| 993 << "CurrentXLoc= " << (int)geoTuple.xcoord << std::endl |
| 994 << "CurrentYLoc= " << (int)geoTuple.ycoord << std::endl |
| 995 << "last Source Xlox= " << lastsourceXLoc << std::endl |
| 996 << "last source Yloc= " << lastsourceYLoc << std::endl |
| 997 << "dest Xloc= " << destXLoc << std::endl |
| 998 << "dest YLoc= " << destYLoc << std::endl; |
| 999 } |
| 1000 |
| 1001 void SiftRouting::PrintReceiveBuffer () |
| 1002 { |
| 1003 std::map<Ptr<Packet>, Time> receiveBuffer; |
| 1004 receiveBuffer = GetReceiveBuffer (); |
| 1005 for (std::map<Ptr<Packet>,Time >::iterator it = receiveBuffer.begin (); it !=
receiveBuffer.end (); ++it) |
| 1006 { |
| 1007 std::cout << *it->first << "=>" << it->second << '\n'; |
| 1008 } |
| 1009 |
| 1010 |
| 1011 } |
| 1012 |
| 1013 std::map<Ptr<Packet>, Time> SiftRouting::GetReceiveBuffer () |
| 1014 { |
| 1015 return m_buffer; |
| 1016 } |
| 1017 |
| 1018 |
| 1019 } /* namespace sift */ |
| 1020 } /* namespace ns3 */ |
OLD | NEW |