View | Details | Raw Unified | Return to bug 2402
Collapse All | Expand All

(-)a/src/aodv/model/aodv-routing-protocol.cc (-8 / +16 lines)
 Lines 384-396    Link Here 
384
}
384
}
385
385
386
void
386
void
387
RoutingProtocol::DeferredRouteOutput (Ptr<const Packet> p, const Ipv4Header & header, 
387
RoutingProtocol::DeferredRouteOutput (Ptr<const Packet> p, const Ipv4Header & header, Ptr<const NetDevice> idev,
388
                                      UnicastForwardCallback ucb, ErrorCallback ecb)
388
                                      UnicastForwardCallback ucb, ErrorCallback ecb)
389
{
389
{
390
  NS_LOG_FUNCTION (this << p << header);
390
  NS_LOG_FUNCTION (this << p << header);
391
  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
391
  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
392
392
393
  QueueEntry newEntry (p, header, ucb, ecb);
393
  QueueEntry newEntry (p, header, idev, ucb, ecb);
394
  bool result = m_queue.Enqueue (newEntry);
394
  bool result = m_queue.Enqueue (newEntry);
395
  if (result)
395
  if (result)
396
    {
396
    {
 Lines 431-437    Link Here 
431
      DeferredRouteOutputTag tag;
431
      DeferredRouteOutputTag tag;
432
      if (p->PeekPacketTag (tag))
432
      if (p->PeekPacketTag (tag))
433
        {
433
        {
434
          DeferredRouteOutput (p, header, ucb, ecb);
434
          DeferredRouteOutput (p, header, idev, ucb, ecb);
435
          return true;
435
          return true;
436
        }
436
        }
437
    }
437
    }
 Lines 483-489    Link Here 
483
                if (m_routingTable.LookupRoute (dst, toBroadcast))
483
                if (m_routingTable.LookupRoute (dst, toBroadcast))
484
                  {
484
                  {
485
                    Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
485
                    Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
486
                    ucb (route, packet, header);
486
                    ucb (idev, route, packet, header);
487
                  }
487
                  }
488
                else
488
                else
489
                  {
489
                  {
 Lines 521-532    Link Here 
521
      return true;
521
      return true;
522
    }
522
    }
523
523
524
  // Check if input device supports IP forwarding
525
  if (m_ipv4->IsForwarding (iif) == false)
526
    {
527
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
528
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
529
      return true;
530
    }
531
524
  // Forwarding
532
  // Forwarding
525
  return Forwarding (p, header, ucb, ecb);
533
  return Forwarding (p, header, idev, ucb, ecb);
526
}
534
}
527
535
528
bool
536
bool
529
RoutingProtocol::Forwarding (Ptr<const Packet> p, const Ipv4Header & header,
537
RoutingProtocol::Forwarding (Ptr<const Packet> p, const Ipv4Header & header, Ptr<const NetDevice> idev,
530
                             UnicastForwardCallback ucb, ErrorCallback ecb)
538
                             UnicastForwardCallback ucb, ErrorCallback ecb)
531
{
539
{
532
  NS_LOG_FUNCTION (this);
540
  NS_LOG_FUNCTION (this);
 Lines 562-568    Link Here 
562
          m_nb.Update (route->GetGateway (), ActiveRouteTimeout);
570
          m_nb.Update (route->GetGateway (), ActiveRouteTimeout);
563
          m_nb.Update (toOrigin.GetNextHop (), ActiveRouteTimeout);
571
          m_nb.Update (toOrigin.GetNextHop (), ActiveRouteTimeout);
564
572
565
          ucb (route, p, header);
573
          ucb (idev, route, p, header);
566
          return true;
574
          return true;
567
        }
575
        }
568
      else
576
      else
 Lines 1723-1729    Link Here 
1723
      Ipv4Header header = queueEntry.GetIpv4Header ();
1731
      Ipv4Header header = queueEntry.GetIpv4Header ();
1724
      header.SetSource (route->GetSource ());
1732
      header.SetSource (route->GetSource ());
1725
      header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
1733
      header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
1726
      ucb (route, p, header);
1734
      ucb (queueEntry.GetInputDevice (), route, p, header);
1727
    }
1735
    }
1728
}
1736
}
1729
1737
(-)a/src/aodv/model/aodv-routing-protocol.h (-2 / +2 lines)
 Lines 168-176    Link Here 
168
  /// Start protocol operation
168
  /// Start protocol operation
169
  void Start ();
169
  void Start ();
170
  /// Queue packet and send route request
170
  /// Queue packet and send route request
171
  void DeferredRouteOutput (Ptr<const Packet> p, const Ipv4Header & header, UnicastForwardCallback ucb, ErrorCallback ecb);
171
  void DeferredRouteOutput (Ptr<const Packet> p, const Ipv4Header & header, Ptr<const NetDevice> idev, UnicastForwardCallback ucb, ErrorCallback ecb);
172
  /// If route exists and valid, forward packet.
172
  /// If route exists and valid, forward packet.
173
  bool Forwarding (Ptr<const Packet> p, const Ipv4Header & header, UnicastForwardCallback ucb, ErrorCallback ecb);
173
  bool Forwarding (Ptr<const Packet> p, const Ipv4Header & header, Ptr<const NetDevice> idev, UnicastForwardCallback ucb, ErrorCallback ecb);
174
  /**
174
  /**
175
  * To reduce congestion in a network, repeated attempts by a source node at route discovery
175
  * To reduce congestion in a network, repeated attempts by a source node at route discovery
176
  * for a single destination MUST utilize a binary exponential backoff.
176
  * for a single destination MUST utilize a binary exponential backoff.
(-)a/src/aodv/model/aodv-rqueue.cc (-4 / +2 lines)
 Lines 50-61    Link Here 
50
RequestQueue::Enqueue (QueueEntry & entry)
50
RequestQueue::Enqueue (QueueEntry & entry)
51
{
51
{
52
  Purge ();
52
  Purge ();
53
  for (std::vector<QueueEntry>::const_iterator i = m_queue.begin (); i
53
  for (std::vector<QueueEntry>::const_iterator i = m_queue.begin (); i != m_queue.end (); ++i)
54
       != m_queue.end (); ++i)
55
    {
54
    {
56
      if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ())
55
      if ((i->GetPacket ()->GetUid () == entry.GetPacket ()->GetUid ())
57
          && (i->GetIpv4Header ().GetDestination ()
56
          && (i->GetIpv4Header ().GetDestination () == entry.GetIpv4Header ().GetDestination ()))
58
              == entry.GetIpv4Header ().GetDestination ()))
59
        return false;
57
        return false;
60
    }
58
    }
61
  entry.SetExpireTime (m_queueTimeout);
59
  entry.SetExpireTime (m_queueTimeout);
(-)a/src/aodv/model/aodv-rqueue.h (-2 / +6 lines)
 Lines 47-55    Link Here 
47
  typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback;
47
  typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback;
48
  /// c-tor
48
  /// c-tor
49
  QueueEntry (Ptr<const Packet> pa = 0, Ipv4Header const & h = Ipv4Header (),
49
  QueueEntry (Ptr<const Packet> pa = 0, Ipv4Header const & h = Ipv4Header (),
50
              Ptr<const NetDevice> idev = 0,
50
              UnicastForwardCallback ucb = UnicastForwardCallback (),
51
              UnicastForwardCallback ucb = UnicastForwardCallback (),
51
              ErrorCallback ecb = ErrorCallback (), Time exp = Simulator::Now ()) :
52
              ErrorCallback ecb = ErrorCallback (), Time exp = Simulator::Now ()) :
52
    m_packet (pa), m_header (h), m_ucb (ucb), m_ecb (ecb),
53
    m_packet (pa), m_header (h), m_idev(idev), m_ucb (ucb), m_ecb (ecb),
53
    m_expire (exp + Simulator::Now ())
54
    m_expire (exp + Simulator::Now ())
54
  {}
55
  {}
55
56
 Lines 73-85    Link Here 
73
  void SetIpv4Header (Ipv4Header h) { m_header = h; }
74
  void SetIpv4Header (Ipv4Header h) { m_header = h; }
74
  void SetExpireTime (Time exp) { m_expire = exp + Simulator::Now (); }
75
  void SetExpireTime (Time exp) { m_expire = exp + Simulator::Now (); }
75
  Time GetExpireTime () const { return m_expire - Simulator::Now (); }
76
  Time GetExpireTime () const { return m_expire - Simulator::Now (); }
76
77
  void SetInputDevice (Ptr<const NetDevice> idev) { m_idev = idev; }
78
  Ptr<const NetDevice> GetInputDevice () const { return m_idev; }
77
private:
79
private:
78
  
80
  
79
  /// Data packet
81
  /// Data packet
80
  Ptr<const Packet> m_packet;
82
  Ptr<const Packet> m_packet;
81
  /// IP header
83
  /// IP header
82
  Ipv4Header m_header;
84
  Ipv4Header m_header;
85
  /// Input Device
86
  Ptr<const NetDevice> m_idev;
83
  /// Unicast forward callback
87
  /// Unicast forward callback
84
  UnicastForwardCallback m_ucb;
88
  UnicastForwardCallback m_ucb;
85
  /// Error callback
89
  /// Error callback
(-)a/src/aodv/test/aodv-test-suite.cc (-9 / +9 lines)
 Lines 258-266    Link Here 
258
struct QueueEntryTest : public TestCase
258
struct QueueEntryTest : public TestCase
259
{
259
{
260
  QueueEntryTest () : TestCase ("QueueEntry") {}
260
  QueueEntryTest () : TestCase ("QueueEntry") {}
261
  void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
261
  void Unicast (Ptr<const NetDevice> idev, Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
262
  void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
262
  void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
263
  void Unicast2 (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
263
  void Unicast2 (Ptr<const NetDevice> idev, Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
264
  void Error2 (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
264
  void Error2 (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
265
  virtual void DoRun ()
265
  virtual void DoRun ()
266
  {
266
  {
 Lines 270-276    Link Here 
270
    h.SetSource (Ipv4Address ("4.3.2.1"));
270
    h.SetSource (Ipv4Address ("4.3.2.1"));
271
    Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&QueueEntryTest::Unicast, this);
271
    Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&QueueEntryTest::Unicast, this);
272
    Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&QueueEntryTest::Error, this);
272
    Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&QueueEntryTest::Error, this);
273
    QueueEntry entry (packet, h, ucb, ecb, Seconds (1));
273
    QueueEntry entry (packet, h, 0, ucb, ecb, Seconds (1));
274
    NS_TEST_EXPECT_MSG_EQ (h.GetDestination (),  entry.GetIpv4Header ().GetDestination (), "trivial");
274
    NS_TEST_EXPECT_MSG_EQ (h.GetDestination (),  entry.GetIpv4Header ().GetDestination (), "trivial");
275
    NS_TEST_EXPECT_MSG_EQ (h.GetSource (),  entry.GetIpv4Header ().GetSource (), "trivial");
275
    NS_TEST_EXPECT_MSG_EQ (h.GetSource (),  entry.GetIpv4Header ().GetSource (), "trivial");
276
    NS_TEST_EXPECT_MSG_EQ (ucb.IsEqual (entry.GetUnicastForwardCallback ()), true, "trivial");
276
    NS_TEST_EXPECT_MSG_EQ (ucb.IsEqual (entry.GetUnicastForwardCallback ()), true, "trivial");
 Lines 297-303    Link Here 
297
{
297
{
298
  AodvRqueueTest () : TestCase ("Rqueue"), q (64, Seconds (30)) {}
298
  AodvRqueueTest () : TestCase ("Rqueue"), q (64, Seconds (30)) {}
299
  virtual void DoRun ();
299
  virtual void DoRun ();
300
  void Unicast (Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
300
  void Unicast (Ptr<const NetDevice> idev, Ptr<Ipv4Route> route, Ptr<const Packet> packet, const Ipv4Header & header) {}
301
  void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
301
  void Error (Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno) {}
302
  void CheckSizeLimit ();
302
  void CheckSizeLimit ();
303
  void CheckTimeout ();
303
  void CheckTimeout ();
 Lines 321-327    Link Here 
321
  h.SetSource (Ipv4Address ("4.3.2.1"));
321
  h.SetSource (Ipv4Address ("4.3.2.1"));
322
  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&AodvRqueueTest::Unicast, this);
322
  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&AodvRqueueTest::Unicast, this);
323
  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&AodvRqueueTest::Error, this);
323
  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&AodvRqueueTest::Error, this);
324
  QueueEntry e1 (packet, h, ucb, ecb, Seconds (1));
324
  QueueEntry e1 (packet, h, 0, ucb, ecb, Seconds (1));
325
  q.Enqueue (e1);
325
  q.Enqueue (e1);
326
  q.Enqueue (e1);
326
  q.Enqueue (e1);
327
  q.Enqueue (e1);
327
  q.Enqueue (e1);
 Lines 333-343    Link Here 
333
  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "trivial");
333
  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 0, "trivial");
334
334
335
  h.SetDestination (Ipv4Address ("2.2.2.2"));
335
  h.SetDestination (Ipv4Address ("2.2.2.2"));
336
  QueueEntry e2 (packet, h, ucb, ecb, Seconds (1));
336
  QueueEntry e2 (packet, h, 0, ucb, ecb, Seconds (1));
337
  q.Enqueue (e1);
337
  q.Enqueue (e1);
338
  q.Enqueue (e2);
338
  q.Enqueue (e2);
339
  Ptr<Packet> packet2 = Create<Packet> ();
339
  Ptr<Packet> packet2 = Create<Packet> ();
340
  QueueEntry e3 (packet2, h, ucb, ecb, Seconds (1));
340
  QueueEntry e3 (packet2, h, 0, ucb, ecb, Seconds (1));
341
  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("3.3.3.3"), e3), false, "trivial");
341
  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("3.3.3.3"), e3), false, "trivial");
342
  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("2.2.2.2"), e3), true, "trivial");
342
  NS_TEST_EXPECT_MSG_EQ (q.Dequeue (Ipv4Address ("2.2.2.2"), e3), true, "trivial");
343
  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("2.2.2.2")), false, "trivial");
343
  NS_TEST_EXPECT_MSG_EQ (q.Find (Ipv4Address ("2.2.2.2")), false, "trivial");
 Lines 346-352    Link Here 
346
  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
346
  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 2, "trivial");
347
  Ptr<Packet> packet4 = Create<Packet> ();
347
  Ptr<Packet> packet4 = Create<Packet> ();
348
  h.SetDestination (Ipv4Address ("1.2.3.4"));
348
  h.SetDestination (Ipv4Address ("1.2.3.4"));
349
  QueueEntry e4 (packet4, h, ucb, ecb, Seconds (20));
349
  QueueEntry e4 (packet4, h, 0, ucb, ecb, Seconds (20));
350
  q.Enqueue (e4);
350
  q.Enqueue (e4);
351
  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
351
  NS_TEST_EXPECT_MSG_EQ (q.GetSize (), 3, "trivial");
352
  q.DropPacketWithDst (Ipv4Address ("1.2.3.4"));
352
  q.DropPacketWithDst (Ipv4Address ("1.2.3.4"));
 Lines 371-377    Link Here 
371
  Ipv4Header header;
371
  Ipv4Header header;
372
  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&AodvRqueueTest::Unicast, this);
372
  Ipv4RoutingProtocol::UnicastForwardCallback ucb = MakeCallback (&AodvRqueueTest::Unicast, this);
373
  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&AodvRqueueTest::Error, this);
373
  Ipv4RoutingProtocol::ErrorCallback ecb = MakeCallback (&AodvRqueueTest::Error, this);
374
  QueueEntry e1 (packet, header, ucb, ecb, Seconds (1));
374
  QueueEntry e1 (packet, header, 0, ucb, ecb, Seconds (1));
375
375
376
  for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
376
  for (uint32_t i = 0; i < q.GetMaxQueueLen (); ++i)
377
    q.Enqueue (e1);
377
    q.Enqueue (e1);
(-)a/src/dsdv/model/dsdv-packet-queue.h (+12 lines)
 Lines 49-58    Link Here 
49
  typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback;
49
  typedef Ipv4RoutingProtocol::ErrorCallback ErrorCallback;
50
  /// c-tor
50
  /// c-tor
51
  QueueEntry (Ptr<const Packet> pa = 0, Ipv4Header const & h = Ipv4Header (),
51
  QueueEntry (Ptr<const Packet> pa = 0, Ipv4Header const & h = Ipv4Header (),
52
              Ptr<const NetDevice> idev = 0,
52
              UnicastForwardCallback ucb = UnicastForwardCallback (),
53
              UnicastForwardCallback ucb = UnicastForwardCallback (),
53
              ErrorCallback ecb = ErrorCallback ())
54
              ErrorCallback ecb = ErrorCallback ())
54
    : m_packet (pa),
55
    : m_packet (pa),
55
      m_header (h),
56
      m_header (h),
57
      m_idev (idev),
56
      m_ucb (ucb),
58
      m_ucb (ucb),
57
      m_ecb (ecb),
59
      m_ecb (ecb),
58
      m_expire (Seconds (0))
60
      m_expire (Seconds (0))
 Lines 101-106    Link Here 
101
  {
103
  {
102
    m_header = h;
104
    m_header = h;
103
  }
105
  }
106
  Ptr<const NetDevice> GetInputDevice () const
107
  {
108
    return m_idev;
109
  }
110
  void SetInputDevice (Ptr<const NetDevice> idev)
111
  {
112
    m_idev = idev;
113
  }
104
  void SetExpireTime (Time exp)
114
  void SetExpireTime (Time exp)
105
  {
115
  {
106
    m_expire = exp + Simulator::Now ();
116
    m_expire = exp + Simulator::Now ();
 Lines 115-120    Link Here 
115
  Ptr<const Packet> m_packet;
125
  Ptr<const Packet> m_packet;
116
  /// IP header
126
  /// IP header
117
  Ipv4Header m_header;
127
  Ipv4Header m_header;
128
  /// Input Device
129
  Ptr<const NetDevice> m_idev;
118
  /// Unicast forward callback
130
  /// Unicast forward callback
119
  UnicastForwardCallback m_ucb;
131
  UnicastForwardCallback m_ucb;
120
  /// Error callback
132
  /// Error callback
(-)a/src/dsdv/model/dsdv-routing-protocol.cc (-8 / +19 lines)
 Lines 349-360    Link Here 
349
void
349
void
350
RoutingProtocol::DeferredRouteOutput (Ptr<const Packet> p,
350
RoutingProtocol::DeferredRouteOutput (Ptr<const Packet> p,
351
                                      const Ipv4Header & header,
351
                                      const Ipv4Header & header,
352
                                      Ptr<const NetDevice> idev,
352
                                      UnicastForwardCallback ucb,
353
                                      UnicastForwardCallback ucb,
353
                                      ErrorCallback ecb)
354
                                      ErrorCallback ecb)
354
{
355
{
355
  NS_LOG_FUNCTION (this << p << header);
356
  NS_LOG_FUNCTION (this << p << header);
356
  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
357
  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
357
  QueueEntry newEntry (p,header,ucb,ecb);
358
  QueueEntry newEntry (p,header,idev,ucb,ecb);
358
  bool result = m_queue.Enqueue (newEntry);
359
  bool result = m_queue.Enqueue (newEntry);
359
  if (result)
360
  if (result)
360
    {
361
    {
 Lines 400-406    Link Here 
400
      DeferredRouteOutputTag tag;
401
      DeferredRouteOutputTag tag;
401
      if (p->PeekPacketTag (tag))
402
      if (p->PeekPacketTag (tag))
402
        {
403
        {
403
          DeferredRouteOutput (p,header,ucb,ecb);
404
          DeferredRouteOutput (p,header,idev,ucb,ecb);
404
          return true;
405
          return true;
405
        }
406
        }
406
    }
407
    }
 Lines 441-447    Link Here 
441
                  if (m_routingTable.LookupRoute (dst,toBroadcast,true))
442
                  if (m_routingTable.LookupRoute (dst,toBroadcast,true))
442
                    {
443
                    {
443
                      Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
444
                      Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
444
                      ucb (route,packet,header);
445
                      ucb (idev, route,packet,header);
445
                    }
446
                    }
446
                  else
447
                  else
447
                    {
448
                    {
 Lines 467-472    Link Here 
467
        }
468
        }
468
      return true;
469
      return true;
469
    }
470
    }
471
472
  // Check if input device supports IP forwarding
473
  if (m_ipv4->IsForwarding (iif) == false)
474
    {
475
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
476
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
477
      return true;
478
    }
479
470
  RoutingTableEntry toDst;
480
  RoutingTableEntry toDst;
471
  if (m_routingTable.LookupRoute (dst,toDst))
481
  if (m_routingTable.LookupRoute (dst,toDst))
472
    {
482
    {
 Lines 478-484    Link Here 
478
                                      << " to " << dst
488
                                      << " to " << dst
479
                                      << " from " << header.GetSource ()
489
                                      << " from " << header.GetSource ()
480
                                      << " via nexthop neighbor " << toDst.GetNextHop ());
490
                                      << " via nexthop neighbor " << toDst.GetNextHop ());
481
          ucb (route,p,header);
491
          ucb (idev, route, p, header);
482
          return true;
492
          return true;
483
        }
493
        }
484
    }
494
    }
 Lines 1078-1084    Link Here 
1078
}
1088
}
1079
1089
1080
void
1090
void
1081
RoutingProtocol::Send (Ptr<Ipv4Route> route,
1091
RoutingProtocol::Send (Ptr<const NetDevice> idev,
1092
                       Ptr<Ipv4Route> route,
1082
                       Ptr<const Packet> packet,
1093
                       Ptr<const Packet> packet,
1083
                       const Ipv4Header & header)
1094
                       const Ipv4Header & header)
1084
{
1095
{
 Lines 1139-1145    Link Here 
1139
{
1150
{
1140
  NS_LOG_DEBUG (m_mainAddress << " is sending a queued packet to destination " << dst);
1151
  NS_LOG_DEBUG (m_mainAddress << " is sending a queued packet to destination " << dst);
1141
  QueueEntry queueEntry;
1152
  QueueEntry queueEntry;
1142
  if (m_queue.Dequeue (dst,queueEntry))
1153
  if (m_queue.Dequeue (dst, queueEntry))
1143
    {
1154
    {
1144
      DeferredRouteOutputTag tag;
1155
      DeferredRouteOutputTag tag;
1145
      Ptr<Packet> p = ConstCast<Packet> (queueEntry.GetPacket ());
1156
      Ptr<Packet> p = ConstCast<Packet> (queueEntry.GetPacket ());
 Lines 1155-1165    Link Here 
1155
      Ipv4Header header = queueEntry.GetIpv4Header ();
1166
      Ipv4Header header = queueEntry.GetIpv4Header ();
1156
      header.SetSource (route->GetSource ());
1167
      header.SetSource (route->GetSource ());
1157
      header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
1168
      header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
1158
      ucb (route,p,header);
1169
      ucb (queueEntry.GetInputDevice (), route, p, header);
1159
      if (m_queue.GetSize () != 0 && m_queue.Find (dst))
1170
      if (m_queue.GetSize () != 0 && m_queue.Find (dst))
1160
        {
1171
        {
1161
          Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)),
1172
          Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)),
1162
                               &RoutingProtocol::SendPacketFromQueue,this,dst,route);
1173
                               &RoutingProtocol::SendPacketFromQueue, this, dst, route);
1163
        }
1174
        }
1164
    }
1175
    }
1165
}
1176
}
(-)a/src/dsdv/model/dsdv-routing-protocol.h (-2 / +2 lines)
 Lines 149-155    Link Here 
149
  Start ();
149
  Start ();
150
  /// Queue packet untill we find a route
150
  /// Queue packet untill we find a route
151
  void
151
  void
152
  DeferredRouteOutput (Ptr<const Packet> p, const Ipv4Header & header, UnicastForwardCallback ucb, ErrorCallback ecb);
152
  DeferredRouteOutput (Ptr<const Packet> p, const Ipv4Header & header, Ptr<const NetDevice> idev, UnicastForwardCallback ucb, ErrorCallback ecb);
153
  /// Look for any queued packets to send them out
153
  /// Look for any queued packets to send them out
154
  void
154
  void
155
  LookForQueuedPackets (void);
155
  LookForQueuedPackets (void);
 Lines 170-176    Link Here 
170
  RecvDsdv (Ptr<Socket> socket);
170
  RecvDsdv (Ptr<Socket> socket);
171
171
172
  void
172
  void
173
  Send (Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &);
173
  Send (Ptr<const NetDevice> idev, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &);
174
  /// Create loopback route for given header
174
  /// Create loopback route for given header
175
  Ptr<Ipv4Route>
175
  Ptr<Ipv4Route>
176
  LoopbackRoute (const Ipv4Header & header, Ptr<NetDevice> oif) const;
176
  LoopbackRoute (const Ipv4Header & header, Ptr<NetDevice> oif) const;
(-)a/src/internet/model/ipv4-global-routing.cc (-3 / +4 lines)
 Lines 481-487    Link Here 
481
}
481
}
482
482
483
bool 
483
bool 
484
Ipv4GlobalRouting::RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
484
Ipv4GlobalRouting::RouteInput  (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
485
                                UnicastForwardCallback ucb, MulticastForwardCallback mcb,
485
                                LocalDeliverCallback lcb, ErrorCallback ecb)
486
                                LocalDeliverCallback lcb, ErrorCallback ecb)
486
{ 
487
{ 
487
  NS_LOG_FUNCTION (this << p << header << header.GetSource () << header.GetDestination () << idev << &lcb << &ecb);
488
  NS_LOG_FUNCTION (this << p << header << header.GetSource () << header.GetDestination () << idev << &lcb << &ecb);
 Lines 513-519    Link Here 
513
    {
514
    {
514
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
515
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
515
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
516
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
516
      return false;
517
      return true;
517
    }
518
    }
518
  // Next, try to find a route
519
  // Next, try to find a route
519
  NS_LOG_LOGIC ("Unicast destination- looking up global route");
520
  NS_LOG_LOGIC ("Unicast destination- looking up global route");
 Lines 521-527    Link Here 
521
  if (rtentry != 0)
522
  if (rtentry != 0)
522
    {
523
    {
523
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
524
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
524
      ucb (rtentry, p, header);
525
      ucb (idev, rtentry, p, header);
525
      return true;
526
      return true;
526
    }
527
    }
527
  else
528
  else
(-)a/src/internet/model/ipv4-l3-protocol.cc (-2 / +17 lines)
 Lines 990-1000    Link Here 
990
990
991
// This function analogous to Linux ip_mr_forward()
991
// This function analogous to Linux ip_mr_forward()
992
void
992
void
993
Ipv4L3Protocol::IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, Ptr<const Packet> p, const Ipv4Header &header)
993
Ipv4L3Protocol::IpMulticastForward (Ptr<const NetDevice> idev, Ptr<Ipv4MulticastRoute> mrtentry, Ptr<const Packet> p, const Ipv4Header &header)
994
{
994
{
995
  NS_LOG_FUNCTION (this << mrtentry << p << header);
995
  NS_LOG_FUNCTION (this << mrtentry << p << header);
996
  NS_LOG_LOGIC ("Multicast forwarding logic for node: " << m_node->GetId ());
996
  NS_LOG_LOGIC ("Multicast forwarding logic for node: " << m_node->GetId ());
997
997
998
  if (GetInterface (GetInterfaceForDevice (idev))->IsForwarding () == false)
999
    {
1000
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
1001
      RouteInputError (p, header, Socket::ERROR_NOROUTETOHOST);
1002
      return;
1003
    }
1004
998
  std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
1005
  std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
999
  std::map<uint32_t, uint32_t>::iterator mapIter;
1006
  std::map<uint32_t, uint32_t>::iterator mapIter;
1000
1007
 Lines 1025-1034    Link Here 
1025
1032
1026
// This function analogous to Linux ip_forward()
1033
// This function analogous to Linux ip_forward()
1027
void
1034
void
1028
Ipv4L3Protocol::IpForward (Ptr<Ipv4Route> rtentry, Ptr<const Packet> p, const Ipv4Header &header)
1035
Ipv4L3Protocol::IpForward (Ptr<const NetDevice> idev, Ptr<Ipv4Route> rtentry, Ptr<const Packet> p, const Ipv4Header &header)
1029
{
1036
{
1030
  NS_LOG_FUNCTION (this << rtentry << p << header);
1037
  NS_LOG_FUNCTION (this << rtentry << p << header);
1031
  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
1038
  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
1039
1040
  if (GetInterface (GetInterfaceForDevice (idev))->IsForwarding () == false)
1041
    {
1042
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
1043
      RouteInputError (p, header, Socket::ERROR_NOROUTETOHOST);
1044
      return;
1045
    }
1046
1032
  // Forwarding
1047
  // Forwarding
1033
  Ipv4Header ipHeader = header;
1048
  Ipv4Header ipHeader = header;
1034
  Ptr<Packet> packet = p->Copy ();
1049
  Ptr<Packet> packet = p->Copy ();
(-)a/src/internet/model/ipv4-l3-protocol.h (-7 / +6 lines)
 Lines 175-185    Link Here 
175
  void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
175
  void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
176
176
177
  uint32_t AddInterface (Ptr<NetDevice> device);
177
  uint32_t AddInterface (Ptr<NetDevice> device);
178
  /**
179
   * \brief Get an interface.
180
   * \param i interface index
181
   * \return IPv4 interface pointer
182
   */
183
  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
178
  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
184
  uint32_t GetNInterfaces (void) const;
179
  uint32_t GetNInterfaces (void) const;
185
180
 Lines 324-346    Link Here 
324
319
325
  /**
320
  /**
326
   * \brief Forward a packet.
321
   * \brief Forward a packet.
322
   * \param idev Pointer to ingress network device
327
   * \param rtentry route
323
   * \param rtentry route
328
   * \param p packet to forward
324
   * \param p packet to forward
329
   * \param header IPv4 header to add to the packet
325
   * \param header IPv4 header to add to the packet
330
   */
326
   */
331
  void 
327
  void 
332
  IpForward (Ptr<Ipv4Route> rtentry, 
328
  IpForward (Ptr<const NetDevice> idev,
329
             Ptr<Ipv4Route> rtentry,
333
             Ptr<const Packet> p, 
330
             Ptr<const Packet> p, 
334
             const Ipv4Header &header);
331
             const Ipv4Header &header);
335
332
336
  /**
333
  /**
337
   * \brief Forward a multicast packet.
334
   * \brief Forward a multicast packet.
335
   * \param idev Pointer to ingress network device
338
   * \param mrtentry route
336
   * \param mrtentry route
339
   * \param p packet to forward
337
   * \param p packet to forward
340
   * \param header IPv4 header to add to the packet
338
   * \param header IPv4 header to add to the packet
341
   */
339
   */
342
  void
340
  void
343
  IpMulticastForward (Ptr<Ipv4MulticastRoute> mrtentry, 
341
  IpMulticastForward (Ptr<const NetDevice> idev,
342
                      Ptr<Ipv4MulticastRoute> mrtentry,
344
                      Ptr<const Packet> p, 
343
                      Ptr<const Packet> p, 
345
                      const Ipv4Header &header);
344
                      const Ipv4Header &header);
346
345
(-)a/src/internet/model/ipv4-list-routing.cc (-1 / +1 lines)
 Lines 161-167    Link Here 
161
    {
161
    {
162
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
162
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
163
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
163
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
164
      return false;
164
      return true;
165
    }
165
    }
166
  // Next, try to find a route
166
  // Next, try to find a route
167
  // If we have already delivered a packet locally (e.g. multicast)
167
  // If we have already delivered a packet locally (e.g. multicast)
(-)a/src/internet/model/ipv4-routing-protocol.h (-2 / +2 lines)
 Lines 57-66    Link Here 
57
  static TypeId GetTypeId (void);
57
  static TypeId GetTypeId (void);
58
58
59
  /// Callback for unicast packets to be forwarded
59
  /// Callback for unicast packets to be forwarded
60
  typedef Callback<void, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &> UnicastForwardCallback;
60
  typedef Callback<void, Ptr<const NetDevice>, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &> UnicastForwardCallback;
61
61
62
  /// Callback for multicast packets to be forwarded
62
  /// Callback for multicast packets to be forwarded
63
  typedef Callback<void, Ptr<Ipv4MulticastRoute>, Ptr<const Packet>, const Ipv4Header &> MulticastForwardCallback;
63
  typedef Callback<void, Ptr<const NetDevice>, Ptr<Ipv4MulticastRoute>, Ptr<const Packet>, const Ipv4Header &> MulticastForwardCallback;
64
64
65
  /// Callback for packets to be locally delivered
65
  /// Callback for packets to be locally delivered
66
  typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, uint32_t > LocalDeliverCallback;
66
  typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, uint32_t > LocalDeliverCallback;
(-)a/src/internet/model/ipv4-static-routing.cc (-3 / +4 lines)
 Lines 509-515    Link Here 
509
      if (mrtentry)
509
      if (mrtentry)
510
        {
510
        {
511
          NS_LOG_LOGIC ("Multicast route found");
511
          NS_LOG_LOGIC ("Multicast route found");
512
          mcb (mrtentry, p, ipHeader); // multicast forwarding callback
512
          mcb (idev, mrtentry, p, ipHeader); // multicast forwarding callback
513
          return true;
513
          return true;
514
        }
514
        }
515
      else
515
      else
 Lines 543-556    Link Here 
543
    {
543
    {
544
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
544
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
545
      ecb (p, ipHeader, Socket::ERROR_NOROUTETOHOST);
545
      ecb (p, ipHeader, Socket::ERROR_NOROUTETOHOST);
546
      return false;
546
      return true;
547
    }
547
    }
548
548
  // Next, try to find a route
549
  // Next, try to find a route
549
  Ptr<Ipv4Route> rtentry = LookupStatic (ipHeader.GetDestination ());
550
  Ptr<Ipv4Route> rtentry = LookupStatic (ipHeader.GetDestination ());
550
  if (rtentry != 0)
551
  if (rtentry != 0)
551
    {
552
    {
552
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
553
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
553
      ucb (rtentry, p, ipHeader);  // unicast forwarding callback
554
      ucb (idev, rtentry, p, ipHeader);  // unicast forwarding callback
554
      return true;
555
      return true;
555
    }
556
    }
556
  else
557
  else
(-)a/src/internet/model/ipv4.h (+8 lines)
 Lines 36-41    Link Here 
36
class Ipv4RoutingProtocol;
36
class Ipv4RoutingProtocol;
37
class IpL4Protocol;
37
class IpL4Protocol;
38
class Ipv4Header;
38
class Ipv4Header;
39
class Ipv4Interface;
39
40
40
/**
41
/**
41
 * \ingroup internet
42
 * \ingroup internet
 Lines 114-119    Link Here 
114
  virtual uint32_t AddInterface (Ptr<NetDevice> device) = 0;
115
  virtual uint32_t AddInterface (Ptr<NetDevice> device) = 0;
115
116
116
  /**
117
  /**
118
   * \brief Get an interface.
119
   * \param i interface index
120
   * \return IPv4 interface pointer
121
   */
122
  virtual Ptr<Ipv4Interface> GetInterface (uint32_t i) const = 0;
123
124
  /**
117
   * \returns the number of interfaces added by the user.
125
   * \returns the number of interfaces added by the user.
118
   */
126
   */
119
  virtual uint32_t GetNInterfaces (void) const = 0;
127
  virtual uint32_t GetNInterfaces (void) const = 0;
(-)a/src/internet/model/ipv6-list-routing.cc (-1 / +1 lines)
 Lines 115-121    Link Here 
115
    {
115
    {
116
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
116
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
117
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
117
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
118
      return false;
118
      return true;
119
    }
119
    }
120
120
121
  // We disable error callback for the called protocols.
121
  // We disable error callback for the called protocols.
(-)a/src/internet/model/ipv6-static-routing.cc (-1 / +1 lines)
 Lines 623-629    Link Here 
623
        {
623
        {
624
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
624
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
625
        }
625
        }
626
      return false;
626
      return true;
627
    }
627
    }
628
  // Next, try to find a route
628
  // Next, try to find a route
629
  NS_LOG_LOGIC ("Unicast destination");
629
  NS_LOG_LOGIC ("Unicast destination");
(-)a/src/internet/model/rip.cc (-2 / +2 lines)
 Lines 268-274    Link Here 
268
        {
268
        {
269
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
269
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
270
        }
270
        }
271
      return false;
271
      return true;
272
    }
272
    }
273
  // Next, try to find a route
273
  // Next, try to find a route
274
  NS_LOG_LOGIC ("Unicast destination");
274
  NS_LOG_LOGIC ("Unicast destination");
 Lines 277-283    Link Here 
277
  if (rtentry != 0)
277
  if (rtentry != 0)
278
    {
278
    {
279
      NS_LOG_LOGIC ("Found unicast destination - calling unicast callback");
279
      NS_LOG_LOGIC ("Found unicast destination - calling unicast callback");
280
      ucb (rtentry, p, header);  // unicast forwarding callback
280
      ucb (idev, rtentry, p, header);  // unicast forwarding callback
281
      return true;
281
      return true;
282
    }
282
    }
283
  else
283
  else
(-)a/src/internet/model/ripng.cc (-1 / +1 lines)
 Lines 244-250    Link Here 
244
        {
244
        {
245
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
245
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
246
        }
246
        }
247
      return false;
247
      return true;
248
    }
248
    }
249
  // Next, try to find a route
249
  // Next, try to find a route
250
  NS_LOG_LOGIC ("Unicast destination");
250
  NS_LOG_LOGIC ("Unicast destination");
(-)a/src/nix-vector-routing/examples/nix-simple.cc (+2 lines)
 Lines 48-53    Link Here 
48
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
48
  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
49
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
49
  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
50
50
51
  Packet::EnablePrinting ();
52
51
  NodeContainer nodes12;
53
  NodeContainer nodes12;
52
  nodes12.Create (2);
54
  nodes12.Create (2);
53
55
(-)a/src/nix-vector-routing/model/ipv4-nix-vector-routing.cc (-1 / +16 lines)
 Lines 644-654    Link Here 
644
        }
644
        }
645
    }
645
    }
646
646
647
  // Check if input device supports IP forwarding
648
  if (m_ipv4->IsForwarding (iif) == false)
649
    {
650
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
651
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
652
      return true;
653
    }
654
647
  Ptr<Ipv4Route> rtentry;
655
  Ptr<Ipv4Route> rtentry;
648
656
649
  // Get the nix-vector from the packet
657
  // Get the nix-vector from the packet
650
  Ptr<NixVector> nixVector = p->GetNixVector ();
658
  Ptr<NixVector> nixVector = p->GetNixVector ();
651
659
660
  if (nixVector == 0)
661
    {
662
      std::cout << *p << std::endl;
663
      std::cout << header << std::endl;
664
      std::cout << idev << std::endl;
665
    }
666
652
  // If nixVector isn't in packet, something went wrong
667
  // If nixVector isn't in packet, something went wrong
653
  NS_ASSERT (nixVector);
668
  NS_ASSERT (nixVector);
654
669
 Lines 690-696    Link Here 
690
  // local deliver is handled by Ipv4StaticRoutingImpl
705
  // local deliver is handled by Ipv4StaticRoutingImpl
691
  // so this code is never even called if the packet is
706
  // so this code is never even called if the packet is
692
  // destined for this node.
707
  // destined for this node.
693
  ucb (rtentry, p, header);
708
  ucb (idev, rtentry, p, header);
694
709
695
  return true;
710
  return true;
696
}
711
}
(-)a/src/olsr/model/olsr-routing-protocol.cc (-1 / +9 lines)
 Lines 2926-2931    Link Here 
2926
        }
2926
        }
2927
    }
2927
    }
2928
2928
2929
  // Check if input device supports IP forwarding
2930
  if (m_ipv4->IsForwarding (iif) == false)
2931
    {
2932
      NS_LOG_LOGIC ("Forwarding disabled for this interface");
2933
      ecb (p, header, Socket::ERROR_NOROUTETOHOST);
2934
      return true;
2935
    }
2936
2929
  // Forwarding
2937
  // Forwarding
2930
  Ptr<Ipv4Route> rtentry;
2938
  Ptr<Ipv4Route> rtentry;
2931
  RoutingTableEntry entry1, entry2;
2939
  RoutingTableEntry entry1, entry2;
 Lines 2964-2970    Link Here 
2964
                                 << " --> nextHop=" << entry2.nextAddr
2972
                                 << " --> nextHop=" << entry2.nextAddr
2965
                                 << " interface=" << entry2.interface);
2973
                                 << " interface=" << entry2.interface);
2966
2974
2967
      ucb (rtentry, p, header);
2975
      ucb (idev, rtentry, p, header);
2968
      return true;
2976
      return true;
2969
    }
2977
    }
2970
  else
2978
  else

Return to bug 2402