src/dsdv/model/dsdv-routing-protocol.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 26 Sep 2014 15:51:00 -0700
changeset 10968 2d29fee2b7b8
parent 10933 7442f5603ef4
child 11370 3da01e490844
permissions -rw-r--r--
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     2
/*
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     3
 * Copyright (c) 2010 Hemanth Narra, Yufei Cheng
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     4
 *
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     8
 *
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    13
 *
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    17
 *
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    18
 * Author: Hemanth Narra <hemanth@ittc.ku.com>
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    19
 * Author: Yufei Cheng   <yfcheng@ittc.ku.edu>
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    20
 *
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    21
 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    22
 * ResiliNets Research Group  http://wiki.ittc.ku.edu/resilinets
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    23
 * Information and Telecommunication Technology Center (ITTC)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    24
 * and Department of Electrical Engineering and Computer Science
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    25
 * The University of Kansas Lawrence, KS USA.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    26
 *
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    27
 * Work supported in part by NSF FIND (Future Internet Design) Program
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    28
 * under grant CNS-0626918 (Postmodern Internet Architecture),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    29
 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    30
 * US Department of Defense (DoD), and ITTC at The University of Kansas.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    31
 */
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    32
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    33
#include "dsdv-routing-protocol.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    34
#include "ns3/log.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    35
#include "ns3/inet-socket-address.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    36
#include "ns3/trace-source-accessor.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    37
#include "ns3/udp-socket-factory.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    38
#include "ns3/wifi-net-device.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    39
#include "ns3/boolean.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    40
#include "ns3/double.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    41
#include "ns3/uinteger.h"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    42
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10933
diff changeset
    43
namespace ns3 {
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    44
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10933
diff changeset
    45
NS_LOG_COMPONENT_DEFINE ("DsdvRoutingProtocol");
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10933
diff changeset
    46
  
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    47
namespace dsdv {
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
    48
  
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
    49
NS_OBJECT_ENSURE_REGISTERED (RoutingProtocol);
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    50
7600
57ba46094a0d fix various doxygen errors
Vedran Miletić <rivanvx@gmail.com>
parents: 7444
diff changeset
    51
/// UDP Port for DSDV control traffic
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    52
const uint32_t RoutingProtocol::DSDV_PORT = 269;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    53
7600
57ba46094a0d fix various doxygen errors
Vedran Miletić <rivanvx@gmail.com>
parents: 7444
diff changeset
    54
/// Tag used by DSDV implementation
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    55
struct DeferredRouteOutputTag : public Tag
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    56
{
7600
57ba46094a0d fix various doxygen errors
Vedran Miletić <rivanvx@gmail.com>
parents: 7444
diff changeset
    57
  /// Positive if output device is fixed in RouteOutput
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    58
  int32_t oif;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    59
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    60
  DeferredRouteOutputTag (int32_t o = -1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    61
    : Tag (),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    62
      oif (o)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    63
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    64
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    65
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    66
  static TypeId
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    67
  GetTypeId ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    68
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    69
    static TypeId tid = TypeId ("ns3::dsdv::DeferredRouteOutputTag").SetParent<Tag> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    70
    return tid;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    71
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    72
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    73
  TypeId
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    74
  GetInstanceTypeId () const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    75
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    76
    return GetTypeId ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    77
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    78
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    79
  uint32_t
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    80
  GetSerializedSize () const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    81
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    82
    return sizeof(int32_t);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    83
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    84
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    85
  void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    86
  Serialize (TagBuffer i) const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    87
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    88
    i.WriteU32 (oif);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    89
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    90
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    91
  void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    92
  Deserialize (TagBuffer i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    93
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    94
    oif = i.ReadU32 ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    95
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    96
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    97
  void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    98
  Print (std::ostream &os) const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
    99
  {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   100
    os << "DeferredRouteOutputTag: output interface = " << oif;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   101
  }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   102
};
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   103
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   104
TypeId
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   105
RoutingProtocol::GetTypeId (void)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   106
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   107
  static TypeId tid = TypeId ("ns3::dsdv::RoutingProtocol")
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   108
    .SetParent<Ipv4RoutingProtocol> ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   109
    .AddConstructor<RoutingProtocol> ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   110
    .AddAttribute ("PeriodicUpdateInterval","Periodic interval between exchange of full routing tables among nodes. ",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   111
                   TimeValue (Seconds (15)),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   112
                   MakeTimeAccessor (&RoutingProtocol::m_periodicUpdateInterval),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   113
                   MakeTimeChecker ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   114
    .AddAttribute ("SettlingTime", "Minimum time an update is to be stored in adv table before sending out"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   115
                   "in case of change in metric (in seconds)",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   116
                   TimeValue (Seconds (5)),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   117
                   MakeTimeAccessor (&RoutingProtocol::m_settlingTime),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   118
                   MakeTimeChecker ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   119
    .AddAttribute ("MaxQueueLen", "Maximum number of packets that we allow a routing protocol to buffer.",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   120
                   UintegerValue (500 /*assuming maximum nodes in simulation is 100*/),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   121
                   MakeUintegerAccessor (&RoutingProtocol::m_maxQueueLen),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   122
                   MakeUintegerChecker<uint32_t> ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   123
    .AddAttribute ("MaxQueuedPacketsPerDst", "Maximum number of packets that we allow per destination to buffer.",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   124
                   UintegerValue (5),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   125
                   MakeUintegerAccessor (&RoutingProtocol::m_maxQueuedPacketsPerDst),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   126
                   MakeUintegerChecker<uint32_t> ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   127
    .AddAttribute ("MaxQueueTime","Maximum time packets can be queued (in seconds)",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   128
                   TimeValue (Seconds (30)),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   129
                   MakeTimeAccessor (&RoutingProtocol::m_maxQueueTime),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   130
                   MakeTimeChecker ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   131
    .AddAttribute ("EnableBuffering","Enables buffering of data packets if no route to destination is available",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   132
                   BooleanValue (true),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   133
                   MakeBooleanAccessor (&RoutingProtocol::SetEnableBufferFlag,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   134
                                        &RoutingProtocol::GetEnableBufferFlag),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   135
                   MakeBooleanChecker ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   136
    .AddAttribute ("EnableWST","Enables Weighted Settling Time for the updates before advertising",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   137
                   BooleanValue (true),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   138
                   MakeBooleanAccessor (&RoutingProtocol::SetWSTFlag,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   139
                                        &RoutingProtocol::GetWSTFlag),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   140
                   MakeBooleanChecker ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   141
    .AddAttribute ("Holdtimes","Times the forwarding Interval to purge the route.",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   142
                   UintegerValue (3),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   143
                   MakeUintegerAccessor (&RoutingProtocol::Holdtimes),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   144
                   MakeUintegerChecker<uint32_t> ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   145
    .AddAttribute ("WeightedFactor","WeightedFactor for the settling time if Weighted Settling Time is enabled",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   146
                   DoubleValue (0.875),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   147
                   MakeDoubleAccessor (&RoutingProtocol::m_weightedFactor),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   148
                   MakeDoubleChecker<double> ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   149
    .AddAttribute ("EnableRouteAggregation","Enables Weighted Settling Time for the updates before advertising",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   150
                   BooleanValue (false),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   151
                   MakeBooleanAccessor (&RoutingProtocol::SetEnableRAFlag,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   152
                                        &RoutingProtocol::GetEnableRAFlag),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   153
                   MakeBooleanChecker ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   154
    .AddAttribute ("RouteAggregationTime","Time to aggregate updates before sending them out (in seconds)",
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   155
                   TimeValue (Seconds (1)),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   156
                   MakeTimeAccessor (&RoutingProtocol::m_routeAggregationTime),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   157
                   MakeTimeChecker ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   158
  return tid;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   159
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   160
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   161
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   162
RoutingProtocol::SetEnableBufferFlag (bool f)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   163
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   164
  EnableBuffering = f;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   165
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   166
bool
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   167
RoutingProtocol::GetEnableBufferFlag () const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   168
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   169
  return EnableBuffering;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   170
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   171
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   172
RoutingProtocol::SetWSTFlag (bool f)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   173
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   174
  EnableWST = f;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   175
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   176
bool
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   177
RoutingProtocol::GetWSTFlag () const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   178
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   179
  return EnableWST;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   180
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   181
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   182
RoutingProtocol::SetEnableRAFlag (bool f)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   183
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   184
  EnableRouteAggregation = f;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   185
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   186
bool
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   187
RoutingProtocol::GetEnableRAFlag () const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   188
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   189
  return EnableRouteAggregation;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   190
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   191
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   192
int64_t
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   193
RoutingProtocol::AssignStreams (int64_t stream)
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   194
{
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   195
  NS_LOG_FUNCTION (this << stream);
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   196
  m_uniformRandomVariable->SetStream (stream);
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   197
  return 1;
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   198
}
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   199
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   200
RoutingProtocol::RoutingProtocol ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   201
  : m_routingTable (),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   202
    m_advRoutingTable (),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   203
    m_queue (),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   204
    m_periodicUpdateTimer (Timer::CANCEL_ON_DESTROY)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   205
{
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   206
  m_uniformRandomVariable = CreateObject<UniformRandomVariable> ();
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   207
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   208
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   209
RoutingProtocol::~RoutingProtocol ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   210
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   211
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   212
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   213
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   214
RoutingProtocol::DoDispose ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   215
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   216
  m_ipv4 = 0;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   217
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::iterator iter = m_socketAddresses.begin (); iter
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   218
       != m_socketAddresses.end (); iter++)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   219
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   220
      iter->first->Close ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   221
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   222
  m_socketAddresses.clear ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   223
  Ipv4RoutingProtocol::DoDispose ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   224
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   225
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   226
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   227
RoutingProtocol::PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   228
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   229
  *stream->GetStream () << "Node: " << m_ipv4->GetObject<Node> ()->GetId () << " Time: " << Simulator::Now ().GetSeconds () << "s ";
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   230
  m_routingTable.Print (stream);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   231
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   232
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   233
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   234
RoutingProtocol::Start ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   235
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   236
  m_queue.SetMaxPacketsPerDst (m_maxQueuedPacketsPerDst);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   237
  m_queue.SetMaxQueueLen (m_maxQueueLen);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   238
  m_queue.SetQueueTimeout (m_maxQueueTime);
7045
d13fa06886ce merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6852
diff changeset
   239
  m_routingTable.Setholddowntime (Time (Holdtimes * m_periodicUpdateInterval));
d13fa06886ce merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6852
diff changeset
   240
  m_advRoutingTable.Setholddowntime (Time (Holdtimes * m_periodicUpdateInterval));
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   241
  m_scb = MakeCallback (&RoutingProtocol::Send,this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   242
  m_ecb = MakeCallback (&RoutingProtocol::Drop,this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   243
  m_periodicUpdateTimer.SetFunction (&RoutingProtocol::SendPeriodicUpdate,this);
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   244
  m_periodicUpdateTimer.Schedule (MicroSeconds (m_uniformRandomVariable->GetInteger (0,1000)));
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   245
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   246
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   247
Ptr<Ipv4Route>
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   248
RoutingProtocol::RouteOutput (Ptr<Packet> p,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   249
                              const Ipv4Header &header,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   250
                              Ptr<NetDevice> oif,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   251
                              Socket::SocketErrno &sockerr)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   252
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   253
  NS_LOG_FUNCTION (this << header << (oif ? oif->GetIfIndex () : 0));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   254
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   255
  if (!p)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   256
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   257
      return LoopbackRoute (header,oif);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   258
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   259
  if (m_socketAddresses.empty ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   260
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   261
      sockerr = Socket::ERROR_NOROUTETOHOST;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   262
      NS_LOG_LOGIC ("No dsdv interfaces");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   263
      Ptr<Ipv4Route> route;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   264
      return route;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   265
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   266
  std::map<Ipv4Address, RoutingTableEntry> removedAddresses;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   267
  sockerr = Socket::ERROR_NOTERROR;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   268
  Ptr<Ipv4Route> route;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   269
  Ipv4Address dst = header.GetDestination ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   270
  NS_LOG_DEBUG ("Packet Size: " << p->GetSize ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   271
                                << ", Packet id: " << p->GetUid () << ", Destination address in Packet: " << dst);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   272
  RoutingTableEntry rt;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   273
  m_routingTable.Purge (removedAddresses);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   274
  for (std::map<Ipv4Address, RoutingTableEntry>::iterator rmItr = removedAddresses.begin ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   275
       rmItr != removedAddresses.end (); ++rmItr)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   276
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   277
      rmItr->second.SetEntriesChanged (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   278
      rmItr->second.SetSeqNo (rmItr->second.GetSeqNo () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   279
      m_advRoutingTable.AddRoute (rmItr->second);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   280
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   281
  if (!removedAddresses.empty ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   282
    {
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   283
      Simulator::Schedule (MicroSeconds (m_uniformRandomVariable->GetInteger (0,1000)),&RoutingProtocol::SendTriggeredUpdate,this);
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   284
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   285
  if (m_routingTable.LookupRoute (dst,rt))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   286
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   287
      if (EnableBuffering)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   288
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   289
          LookForQueuedPackets ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   290
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   291
      if (rt.GetHop () == 1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   292
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   293
          route = rt.GetRoute ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   294
          NS_ASSERT (route != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   295
          NS_LOG_DEBUG ("A route exists from " << route->GetSource ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   296
                                               << " to neighboring destination "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   297
                                               << route->GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   298
          if (oif != 0 && route->GetOutputDevice () != oif)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   299
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   300
              NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   301
              sockerr = Socket::ERROR_NOROUTETOHOST;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   302
              return Ptr<Ipv4Route> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   303
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   304
          return route;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   305
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   306
      else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   307
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   308
          RoutingTableEntry newrt;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   309
          if (m_routingTable.LookupRoute (rt.GetNextHop (),newrt))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   310
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   311
              route = newrt.GetRoute ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   312
              NS_ASSERT (route != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   313
              NS_LOG_DEBUG ("A route exists from " << route->GetSource ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   314
                                                   << " to destination " << dst << " via "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   315
                                                   << rt.GetNextHop ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   316
              if (oif != 0 && route->GetOutputDevice () != oif)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   317
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   318
                  NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   319
                  sockerr = Socket::ERROR_NOROUTETOHOST;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   320
                  return Ptr<Ipv4Route> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   321
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   322
              return route;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   323
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   324
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   325
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   326
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   327
  if (EnableBuffering)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   328
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   329
      uint32_t iif = (oif ? m_ipv4->GetInterfaceForDevice (oif) : -1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   330
      DeferredRouteOutputTag tag (iif);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   331
      if (!p->PeekPacketTag (tag))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   332
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   333
          p->AddPacketTag (tag);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   334
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   335
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   336
  return LoopbackRoute (header,oif);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   337
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   338
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   339
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   340
RoutingProtocol::DeferredRouteOutput (Ptr<const Packet> p,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   341
                                      const Ipv4Header & header,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   342
                                      UnicastForwardCallback ucb,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   343
                                      ErrorCallback ecb)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   344
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   345
  NS_LOG_FUNCTION (this << p << header);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   346
  NS_ASSERT (p != 0 && p != Ptr<Packet> ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   347
  QueueEntry newEntry (p,header,ucb,ecb);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   348
  bool result = m_queue.Enqueue (newEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   349
  if (result)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   350
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   351
      NS_LOG_DEBUG ("Added packet " << p->GetUid () << " to queue.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   352
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   353
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   354
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   355
bool
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   356
RoutingProtocol::RouteInput (Ptr<const Packet> p,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   357
                             const Ipv4Header &header,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   358
                             Ptr<const NetDevice> idev,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   359
                             UnicastForwardCallback ucb,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   360
                             MulticastForwardCallback mcb,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   361
                             LocalDeliverCallback lcb,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   362
                             ErrorCallback ecb)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   363
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   364
  NS_LOG_FUNCTION (m_mainAddress << " received packet " << p->GetUid ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   365
                                 << " from " << header.GetSource ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   366
                                 << " on interface " << idev->GetAddress ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   367
                                 << " to destination " << header.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   368
  if (m_socketAddresses.empty ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   369
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   370
      NS_LOG_DEBUG ("No dsdv interfaces");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   371
      return false;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   372
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   373
  NS_ASSERT (m_ipv4 != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   374
  // Check if input device supports IP
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   375
  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   376
  int32_t iif = m_ipv4->GetInterfaceForDevice (idev);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   377
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   378
  Ipv4Address dst = header.GetDestination ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   379
  Ipv4Address origin = header.GetSource ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   380
7444
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   381
  // DSDV is not a multicast routing protocol
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   382
  if (dst.IsMulticast ())
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   383
    {
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   384
      return false;
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   385
    }
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   386
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   387
  // Deferred route request
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   388
  if (EnableBuffering == true && idev == m_lo)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   389
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   390
      DeferredRouteOutputTag tag;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   391
      if (p->PeekPacketTag (tag))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   392
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   393
          DeferredRouteOutput (p,header,ucb,ecb);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   394
          return true;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   395
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   396
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   397
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j =
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   398
         m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   399
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   400
      Ipv4InterfaceAddress iface = j->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   401
      if (origin == iface.GetLocal ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   402
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   403
          return true;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   404
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   405
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   406
  // LOCAL DELIVARY TO DSDV INTERFACES
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   407
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   408
       != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   409
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   410
      Ipv4InterfaceAddress iface = j->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   411
      if (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()) == iif)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   412
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   413
          if (dst == iface.GetBroadcast () || dst.IsBroadcast ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   414
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   415
              Ptr<Packet> packet = p->Copy ();
7444
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   416
              if (lcb.IsNull () == false)
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   417
                {
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   418
                  NS_LOG_LOGIC ("Broadcast local delivery to " << iface.GetLocal ());
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   419
                  lcb (p, header, iif);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   420
                  // Fall through to additional processing
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   421
                }
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   422
              else
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   423
                {
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   424
                  NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   425
                  ecb (p, header, Socket::ERROR_NOROUTETOHOST);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   426
                }
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   427
              if (header.GetTtl () > 1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   428
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   429
                  NS_LOG_LOGIC ("Forward broadcast. TTL " << (uint16_t) header.GetTtl ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   430
                  RoutingTableEntry toBroadcast;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   431
                  if (m_routingTable.LookupRoute (dst,toBroadcast,true))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   432
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   433
                      Ptr<Ipv4Route> route = toBroadcast.GetRoute ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   434
                      ucb (route,packet,header);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   435
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   436
                  else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   437
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   438
                      NS_LOG_DEBUG ("No route to forward. Drop packet " << p->GetUid ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   439
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   440
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   441
              return true;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   442
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   443
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   444
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   445
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   446
  if (m_ipv4->IsDestinationAddress (dst, iif))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   447
    {
7444
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   448
      if (lcb.IsNull () == false)
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   449
        {
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   450
          NS_LOG_LOGIC ("Unicast local delivery to " << dst);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   451
          lcb (p, header, iif);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   452
        }
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   453
      else
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   454
        {
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   455
          NS_LOG_ERROR ("Unable to deliver packet locally due to null callback " << p->GetUid () << " from " << origin);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   456
          ecb (p, header, Socket::ERROR_NOROUTETOHOST);
075e6cbaa9d9 bug 1046: DSDV: NULL callback
Tom Henderson <tomh@tomh.org>
parents: 7256
diff changeset
   457
        }
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   458
      return true;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   459
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   460
  RoutingTableEntry toDst;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   461
  if (m_routingTable.LookupRoute (dst,toDst))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   462
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   463
      RoutingTableEntry ne;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   464
      if (m_routingTable.LookupRoute (toDst.GetNextHop (),ne))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   465
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   466
          Ptr<Ipv4Route> route = ne.GetRoute ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   467
          NS_LOG_LOGIC (m_mainAddress << " is forwarding packet " << p->GetUid ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   468
                                      << " to " << dst
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   469
                                      << " from " << header.GetSource ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   470
                                      << " via nexthop neighbor " << toDst.GetNextHop ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   471
          ucb (route,p,header);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   472
          return true;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   473
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   474
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   475
  NS_LOG_LOGIC ("Drop packet " << p->GetUid ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   476
                               << " as there is no route to forward it.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   477
  return false;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   478
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   479
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   480
Ptr<Ipv4Route>
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   481
RoutingProtocol::LoopbackRoute (const Ipv4Header & hdr, Ptr<NetDevice> oif) const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   482
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   483
  NS_ASSERT (m_lo != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   484
  Ptr<Ipv4Route> rt = Create<Ipv4Route> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   485
  rt->SetDestination (hdr.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   486
  // rt->SetSource (hdr.GetSource ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   487
  //
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   488
  // Source address selection here is tricky.  The loopback route is
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   489
  // returned when DSDV does not have a route; this causes the packet
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   490
  // to be looped back and handled (cached) in RouteInput() method
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   491
  // while a route is found. However, connection-oriented protocols
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   492
  // like TCP need to create an endpoint four-tuple (src, src port,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   493
  // dst, dst port) and create a pseudo-header for checksumming.  So,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   494
  // DSDV needs to guess correctly what the eventual source address
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   495
  // will be.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   496
  //
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   497
  // For single interface, single address nodes, this is not a problem.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   498
  // When there are possibly multiple outgoing interfaces, the policy
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   499
  // implemented here is to pick the first available DSDV interface.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   500
  // If RouteOutput() caller specified an outgoing interface, that
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   501
  // further constrains the selection of source address
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   502
  //
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   503
  std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   504
  if (oif)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   505
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   506
      // Iterate to find an address on the oif device
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   507
      for (j = m_socketAddresses.begin (); j != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   508
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   509
          Ipv4Address addr = j->second.GetLocal ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   510
          int32_t interface = m_ipv4->GetInterfaceForAddress (addr);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   511
          if (oif == m_ipv4->GetNetDevice (static_cast<uint32_t> (interface)))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   512
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   513
              rt->SetSource (addr);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   514
              break;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   515
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   516
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   517
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   518
  else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   519
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   520
      rt->SetSource (j->second.GetLocal ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   521
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   522
  NS_ASSERT_MSG (rt->GetSource () != Ipv4Address (), "Valid DSDV source address not found");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   523
  rt->SetGateway (Ipv4Address ("127.0.0.1"));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   524
  rt->SetOutputDevice (m_lo);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   525
  return rt;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   526
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   527
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   528
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   529
RoutingProtocol::RecvDsdv (Ptr<Socket> socket)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   530
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   531
  Address sourceAddress;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   532
  Ptr<Packet> advpacket = Create<Packet> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   533
  Ptr<Packet> packet = socket->RecvFrom (sourceAddress);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   534
  InetSocketAddress inetSourceAddr = InetSocketAddress::ConvertFrom (sourceAddress);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   535
  Ipv4Address sender = inetSourceAddr.GetIpv4 ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   536
  Ipv4Address receiver = m_socketAddresses[socket].GetLocal ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   537
  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (receiver));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   538
  uint32_t packetSize = packet->GetSize ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   539
  NS_LOG_FUNCTION (m_mainAddress << " received dsdv packet of size: " << packetSize
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   540
                                 << " and packet id: " << packet->GetUid ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   541
  uint32_t count = 0;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   542
  for (; packetSize > 0; packetSize = packetSize - 12)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   543
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   544
      count = 0;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   545
      DsdvHeader dsdvHeader, tempDsdvHeader;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   546
      packet->RemoveHeader (dsdvHeader);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   547
      NS_LOG_DEBUG ("Processing new update for " << dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   548
      /*Verifying if the packets sent by me were returned back to me. If yes, discarding them!*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   549
      for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   550
           != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   551
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   552
          Ipv4InterfaceAddress interface = j->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   553
          if (dsdvHeader.GetDst () == interface.GetLocal ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   554
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   555
              if (dsdvHeader.GetDstSeqno () % 2 == 1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   556
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   557
                  NS_LOG_DEBUG ("Sent Dsdv update back to the same Destination, "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   558
                                "with infinite metric. Time left to send fwd update: "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   559
                                << m_periodicUpdateTimer.GetDelayLeft ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   560
                  count++;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   561
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   562
              else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   563
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   564
                  NS_LOG_DEBUG ("Received update for my address. Discarding this.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   565
                  count++;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   566
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   567
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   568
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   569
      if (count > 0)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   570
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   571
          continue;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   572
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   573
      NS_LOG_DEBUG ("Received a DSDV packet from "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   574
                    << sender << " to " << receiver << ". Details are: Destination: " << dsdvHeader.GetDst () << ", Seq No: "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   575
                    << dsdvHeader.GetDstSeqno () << ", HopCount: " << dsdvHeader.GetHopCount ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   576
      RoutingTableEntry fwdTableEntry, advTableEntry;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   577
      EventId event;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   578
      bool permanentTableVerifier = m_routingTable.LookupRoute (dsdvHeader.GetDst (),fwdTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   579
      if (permanentTableVerifier == false)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   580
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   581
          if (dsdvHeader.GetDstSeqno () % 2 != 1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   582
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   583
              NS_LOG_DEBUG ("Received New Route!");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   584
              RoutingTableEntry newEntry (
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   585
                /*device=*/ dev, /*dst=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   586
                dsdvHeader.GetDst (), /*seqno=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   587
                dsdvHeader.GetDstSeqno (),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   588
                /*iface=*/ m_ipv4->GetAddress (m_ipv4->GetInterfaceForAddress (receiver), 0),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   589
                /*hops=*/ dsdvHeader.GetHopCount (), /*next hop=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   590
                sender, /*lifetime=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   591
                Simulator::Now (), /*settlingTime*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   592
                m_settlingTime, /*entries changed*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   593
                true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   594
              newEntry.SetFlag (VALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   595
              m_routingTable.AddRoute (newEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   596
              NS_LOG_DEBUG ("New Route added to both tables");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   597
              m_advRoutingTable.AddRoute (newEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   598
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   599
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   600
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   601
              // received update not present in main routing table and also with infinite metric
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   602
              NS_LOG_DEBUG ("Discarding this update as this route is not present in "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   603
                            "main routing table and received with infinite metric");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   604
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   605
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   606
      else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   607
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   608
          if (!m_advRoutingTable.LookupRoute (dsdvHeader.GetDst (),advTableEntry))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   609
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   610
              RoutingTableEntry tr;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   611
              std::map<Ipv4Address, RoutingTableEntry> allRoutes;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   612
              m_advRoutingTable.GetListOfAllRoutes (allRoutes);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   613
              for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   614
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   615
                  NS_LOG_DEBUG ("ADV table routes are:" << i->second.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   616
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   617
              // present in fwd table and not in advtable
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   618
              m_advRoutingTable.AddRoute (fwdTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   619
              m_advRoutingTable.LookupRoute (dsdvHeader.GetDst (),advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   620
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   621
          if (dsdvHeader.GetDstSeqno () % 2 != 1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   622
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   623
              if (dsdvHeader.GetDstSeqno () > advTableEntry.GetSeqNo ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   624
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   625
                  // Received update with better seq number. Clear any old events that are running
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   626
                  if (m_advRoutingTable.ForceDeleteIpv4Event (dsdvHeader.GetDst ()))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   627
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   628
                      NS_LOG_DEBUG ("Canceling the timer to update route with better seq number");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   629
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   630
                  // if its a changed metric *nomatter* where the update came from, wait  for WST
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   631
                  if (dsdvHeader.GetHopCount () != advTableEntry.GetHop ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   632
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   633
                      advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   634
                      advTableEntry.SetLifeTime (Simulator::Now ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   635
                      advTableEntry.SetFlag (VALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   636
                      advTableEntry.SetEntriesChanged (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   637
                      advTableEntry.SetNextHop (sender);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   638
                      advTableEntry.SetHop (dsdvHeader.GetHopCount ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   639
                      NS_LOG_DEBUG ("Received update with better sequence number and changed metric.Waiting for WST");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   640
                      Time tempSettlingtime = GetSettlingTime (dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   641
                      advTableEntry.SetSettlingTime (tempSettlingtime);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   642
                      NS_LOG_DEBUG ("Added Settling Time:" << tempSettlingtime.GetSeconds ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   643
                                                           << "s as there is no event running for this route");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   644
                      event = Simulator::Schedule (tempSettlingtime,&RoutingProtocol::SendTriggeredUpdate,this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   645
                      m_advRoutingTable.AddIpv4Event (dsdvHeader.GetDst (),event);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   646
                      NS_LOG_DEBUG ("EventCreated EventUID: " << event.GetUid ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   647
                      // if received changed metric, use it but adv it only after wst
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   648
                      m_routingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   649
                      m_advRoutingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   650
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   651
                  else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   652
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   653
                      // Received update with better seq number and same metric.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   654
                      advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   655
                      advTableEntry.SetLifeTime (Simulator::Now ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   656
                      advTableEntry.SetFlag (VALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   657
                      advTableEntry.SetEntriesChanged (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   658
                      advTableEntry.SetNextHop (sender);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   659
                      advTableEntry.SetHop (dsdvHeader.GetHopCount ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   660
                      m_advRoutingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   661
                      NS_LOG_DEBUG ("Route with better sequence number and same metric received. Advertised without WST");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   662
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   663
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   664
              else if (dsdvHeader.GetDstSeqno () == advTableEntry.GetSeqNo ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   665
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   666
                  if (dsdvHeader.GetHopCount () < advTableEntry.GetHop ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   667
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   668
                      /*Received update with same seq number and better hop count.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   669
                       * As the metric is changed, we will have to wait for WST before sending out this update.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   670
                       */
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   671
                      NS_LOG_DEBUG ("Canceling any existing timer to update route with same sequence number "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   672
                                    "and better hop count");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   673
                      m_advRoutingTable.ForceDeleteIpv4Event (dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   674
                      advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   675
                      advTableEntry.SetLifeTime (Simulator::Now ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   676
                      advTableEntry.SetFlag (VALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   677
                      advTableEntry.SetEntriesChanged (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   678
                      advTableEntry.SetNextHop (sender);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   679
                      advTableEntry.SetHop (dsdvHeader.GetHopCount ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   680
                      Time tempSettlingtime = GetSettlingTime (dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   681
                      advTableEntry.SetSettlingTime (tempSettlingtime);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   682
                      NS_LOG_DEBUG ("Added Settling Time," << tempSettlingtime.GetSeconds ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   683
                                                           << " as there is no current event running for this route");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   684
                      event = Simulator::Schedule (tempSettlingtime,&RoutingProtocol::SendTriggeredUpdate,this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   685
                      m_advRoutingTable.AddIpv4Event (dsdvHeader.GetDst (),event);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   686
                      NS_LOG_DEBUG ("EventCreated EventUID: " << event.GetUid ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   687
                      // if received changed metric, use it but adv it only after wst
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   688
                      m_routingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   689
                      m_advRoutingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   690
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   691
                  else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   692
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   693
                      /*Received update with same seq number but with same or greater hop count.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   694
                       * Discard that update.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   695
                       */
9922
58beef4d4613 DSDV: Modify rarely-used keywords to comply with other compilers
John Abraham <john.abraham.in@gmail.com>
parents: 8975
diff changeset
   696
                      if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   697
                        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   698
                          /*update the timer only if nexthop address matches thus discarding
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   699
                           * updates to that destination from other nodes.
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   700
                           */
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   701
                          if (advTableEntry.GetNextHop () == sender)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   702
                            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   703
                              advTableEntry.SetLifeTime (Simulator::Now ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   704
                              m_routingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   705
                            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   706
                          m_advRoutingTable.DeleteRoute (
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   707
                            dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   708
                        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   709
                      NS_LOG_DEBUG ("Received update with same seq number and "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   710
                                    "same/worst metric for, " << dsdvHeader.GetDst () << ". Discarding the update.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   711
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   712
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   713
              else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   714
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   715
                  // Received update with an old sequence number. Discard the update
9922
58beef4d4613 DSDV: Modify rarely-used keywords to comply with other compilers
John Abraham <john.abraham.in@gmail.com>
parents: 8975
diff changeset
   716
                  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   717
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   718
                      m_advRoutingTable.DeleteRoute (dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   719
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   720
                  NS_LOG_DEBUG (dsdvHeader.GetDst () << " : Received update with old seq number. Discarding the update.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   721
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   722
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   723
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   724
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   725
              NS_LOG_DEBUG ("Route with infinite metric received for "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   726
                            << dsdvHeader.GetDst () << " from " << sender);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   727
              // Delete route only if update was received from my nexthop neighbor
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   728
              if (sender == advTableEntry.GetNextHop ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   729
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   730
                  NS_LOG_DEBUG ("Triggering an update for this unreachable route:");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   731
                  std::map<Ipv4Address, RoutingTableEntry> dstsWithNextHopSrc;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   732
                  m_routingTable.GetListOfDestinationWithNextHop (dsdvHeader.GetDst (),dstsWithNextHopSrc);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   733
                  m_routingTable.DeleteRoute (dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   734
                  advTableEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   735
                  advTableEntry.SetEntriesChanged (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   736
                  m_advRoutingTable.Update (advTableEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   737
                  for (std::map<Ipv4Address, RoutingTableEntry>::iterator i = dstsWithNextHopSrc.begin (); i
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   738
                       != dstsWithNextHopSrc.end (); ++i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   739
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   740
                      i->second.SetSeqNo (i->second.GetSeqNo () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   741
                      i->second.SetEntriesChanged (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   742
                      m_advRoutingTable.AddRoute (i->second);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   743
                      m_routingTable.DeleteRoute (i->second.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   744
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   745
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   746
              else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   747
                {
9922
58beef4d4613 DSDV: Modify rarely-used keywords to comply with other compilers
John Abraham <john.abraham.in@gmail.com>
parents: 8975
diff changeset
   748
                  if (!m_advRoutingTable.AnyRunningEvent (dsdvHeader.GetDst ()))
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   749
                    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   750
                      m_advRoutingTable.DeleteRoute (dsdvHeader.GetDst ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   751
                    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   752
                  NS_LOG_DEBUG (dsdvHeader.GetDst () <<
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   753
                                " : Discard this link break update as it was received from a different neighbor "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   754
                                "and I can reach the destination");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   755
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   756
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   757
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   758
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   759
  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   760
  m_advRoutingTable.GetListOfAllRoutes (allRoutes);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   761
  if (EnableRouteAggregation && allRoutes.size () > 0)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   762
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   763
      Simulator::Schedule (m_routeAggregationTime,&RoutingProtocol::SendTriggeredUpdate,this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   764
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   765
  else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   766
    {
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   767
      Simulator::Schedule (MicroSeconds (m_uniformRandomVariable->GetInteger (0,1000)),&RoutingProtocol::SendTriggeredUpdate,this);
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   768
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   769
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   770
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   771
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   772
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   773
RoutingProtocol::SendTriggeredUpdate ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   774
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   775
  NS_LOG_FUNCTION (m_mainAddress << " is sending a triggered update");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   776
  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   777
  m_advRoutingTable.GetListOfAllRoutes (allRoutes);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   778
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   779
       != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   780
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   781
      DsdvHeader dsdvHeader;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   782
      Ptr<Socket> socket = j->first;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   783
      Ipv4InterfaceAddress iface = j->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   784
      Ptr<Packet> packet = Create<Packet> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   785
      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   786
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   787
          NS_LOG_LOGIC ("Destination: " << i->second.GetDestination ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   788
                                        << " SeqNo:" << i->second.GetSeqNo () << " HopCount:"
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   789
                                        << i->second.GetHop () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   790
          RoutingTableEntry temp = i->second;
9922
58beef4d4613 DSDV: Modify rarely-used keywords to comply with other compilers
John Abraham <john.abraham.in@gmail.com>
parents: 8975
diff changeset
   791
          if ((i->second.GetEntriesChanged () == true) && (!m_advRoutingTable.AnyRunningEvent (temp.GetDestination ())))
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   792
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   793
              dsdvHeader.SetDst (i->second.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   794
              dsdvHeader.SetDstSeqno (i->second.GetSeqNo ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   795
              dsdvHeader.SetHopCount (i->second.GetHop () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   796
              temp.SetFlag (VALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   797
              temp.SetEntriesChanged (false);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   798
              m_advRoutingTable.DeleteIpv4Event (temp.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   799
              if (!(temp.GetSeqNo () % 2))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   800
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   801
                  m_routingTable.Update (temp);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   802
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   803
              packet->AddHeader (dsdvHeader);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   804
              m_advRoutingTable.DeleteRoute (temp.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   805
              NS_LOG_DEBUG ("Deleted this route from the advertised table");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   806
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   807
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   808
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   809
              EventId event = m_advRoutingTable.GetEventId (temp.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   810
              NS_ASSERT (event.GetUid () != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   811
              NS_LOG_DEBUG ("EventID " << event.GetUid () << " associated with "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   812
                                       << temp.GetDestination () << " has not expired, waiting in adv table");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   813
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   814
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   815
      if (packet->GetSize () >= 12)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   816
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   817
          RoutingTableEntry temp2;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   818
          m_routingTable.LookupRoute (m_ipv4->GetAddress (1, 0).GetBroadcast (), temp2);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   819
          dsdvHeader.SetDst (m_ipv4->GetAddress (1, 0).GetLocal ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   820
          dsdvHeader.SetDstSeqno (temp2.GetSeqNo ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   821
          dsdvHeader.SetHopCount (temp2.GetHop () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   822
          NS_LOG_DEBUG ("Adding my update as well to the packet");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   823
          packet->AddHeader (dsdvHeader);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   824
          // Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   825
          Ipv4Address destination;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   826
          if (iface.GetMask () == Ipv4Mask::GetOnes ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   827
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   828
              destination = Ipv4Address ("255.255.255.255");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   829
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   830
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   831
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   832
              destination = iface.GetBroadcast ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   833
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   834
          socket->SendTo (packet, 0, InetSocketAddress (destination, DSDV_PORT));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   835
          NS_LOG_FUNCTION ("Sent Triggered Update from "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   836
                           << dsdvHeader.GetDst ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   837
                           << " with packet id : " << packet->GetUid () << " and packet Size: " << packet->GetSize ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   838
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   839
      else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   840
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   841
          NS_LOG_FUNCTION ("Update not sent as there are no updates to be triggered");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   842
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   843
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   844
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   845
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   846
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   847
RoutingProtocol::SendPeriodicUpdate ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   848
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   849
  std::map<Ipv4Address, RoutingTableEntry> removedAddresses, allRoutes;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   850
  m_routingTable.Purge (removedAddresses);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   851
  MergeTriggerPeriodicUpdates ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   852
  m_routingTable.GetListOfAllRoutes (allRoutes);
7767
657d0877064e bug 1369 - [LLVM] error: comparison of unsigned expression < 0 is always false
Hemanth Narra <hemanthnarra222@gmail.com>
parents: 7600
diff changeset
   853
  if (allRoutes.empty ())
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   854
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   855
      return;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   856
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   857
  NS_LOG_FUNCTION (m_mainAddress << " is sending out its periodic update");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   858
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   859
       != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   860
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   861
      Ptr<Socket> socket = j->first;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   862
      Ipv4InterfaceAddress iface = j->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   863
      Ptr<Packet> packet = Create<Packet> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   864
      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   865
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   866
          DsdvHeader dsdvHeader;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   867
          if (i->second.GetHop () == 0)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   868
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   869
              RoutingTableEntry ownEntry;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   870
              dsdvHeader.SetDst (m_ipv4->GetAddress (1,0).GetLocal ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   871
              dsdvHeader.SetDstSeqno (i->second.GetSeqNo () + 2);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   872
              dsdvHeader.SetHopCount (i->second.GetHop () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   873
              m_routingTable.LookupRoute (m_ipv4->GetAddress (1,0).GetBroadcast (),ownEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   874
              ownEntry.SetSeqNo (dsdvHeader.GetDstSeqno ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   875
              m_routingTable.Update (ownEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   876
              packet->AddHeader (dsdvHeader);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   877
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   878
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   879
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   880
              dsdvHeader.SetDst (i->second.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   881
              dsdvHeader.SetDstSeqno ((i->second.GetSeqNo ()));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   882
              dsdvHeader.SetHopCount (i->second.GetHop () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   883
              packet->AddHeader (dsdvHeader);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   884
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   885
          NS_LOG_DEBUG ("Forwarding the update for " << i->first);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   886
          NS_LOG_DEBUG ("Forwarding details are, Destination: " << dsdvHeader.GetDst ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   887
                                                                << ", SeqNo:" << dsdvHeader.GetDstSeqno ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   888
                                                                << ", HopCount:" << dsdvHeader.GetHopCount ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   889
                                                                << ", LifeTime: " << i->second.GetLifeTime ().GetSeconds ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   890
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   891
      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator rmItr = removedAddresses.begin (); rmItr
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   892
           != removedAddresses.end (); ++rmItr)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   893
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   894
          DsdvHeader removedHeader;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   895
          removedHeader.SetDst (rmItr->second.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   896
          removedHeader.SetDstSeqno (rmItr->second.GetSeqNo () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   897
          removedHeader.SetHopCount (rmItr->second.GetHop () + 1);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   898
          packet->AddHeader (removedHeader);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   899
          NS_LOG_DEBUG ("Update for removed record is: Destination: " << removedHeader.GetDst ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   900
                                                                      << " SeqNo:" << removedHeader.GetDstSeqno ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   901
                                                                      << " HopCount:" << removedHeader.GetHopCount ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   902
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   903
      socket->Send (packet);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   904
      // Send to all-hosts broadcast if on /32 addr, subnet-directed otherwise
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   905
      Ipv4Address destination;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   906
      if (iface.GetMask () == Ipv4Mask::GetOnes ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   907
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   908
          destination = Ipv4Address ("255.255.255.255");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   909
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   910
      else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   911
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   912
          destination = iface.GetBroadcast ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   913
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   914
      socket->SendTo (packet, 0, InetSocketAddress (destination, DSDV_PORT));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   915
      NS_LOG_FUNCTION ("PeriodicUpdate Packet UID is : " << packet->GetUid ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   916
    }
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
   917
  m_periodicUpdateTimer.Schedule (m_periodicUpdateInterval + MicroSeconds (25 * m_uniformRandomVariable->GetInteger (0,1000)));
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   918
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   919
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   920
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   921
RoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   922
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   923
  NS_ASSERT (ipv4 != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   924
  NS_ASSERT (m_ipv4 == 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   925
  m_ipv4 = ipv4;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   926
  // Create lo route. It is asserted that the only one interface up for now is loopback
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   927
  NS_ASSERT (m_ipv4->GetNInterfaces () == 1 && m_ipv4->GetAddress (0, 0).GetLocal () == Ipv4Address ("127.0.0.1"));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   928
  m_lo = m_ipv4->GetNetDevice (0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   929
  NS_ASSERT (m_lo != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   930
  // Remember lo route
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   931
  RoutingTableEntry rt (
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   932
    /*device=*/ m_lo,  /*dst=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   933
    Ipv4Address::GetLoopback (), /*seqno=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   934
    0,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   935
    /*iface=*/ Ipv4InterfaceAddress (Ipv4Address::GetLoopback (),Ipv4Mask ("255.0.0.0")),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   936
    /*hops=*/ 0,  /*next hop=*/
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   937
    Ipv4Address::GetLoopback (),
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   938
    /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   939
  rt.SetFlag (INVALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   940
  rt.SetEntriesChanged (false);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   941
  m_routingTable.AddRoute (rt);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   942
  Simulator::ScheduleNow (&RoutingProtocol::Start,this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   943
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   944
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   945
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   946
RoutingProtocol::NotifyInterfaceUp (uint32_t i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   947
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   948
  NS_LOG_FUNCTION (this << m_ipv4->GetAddress (i, 0).GetLocal ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   949
                        << " interface is up");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   950
  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   951
  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   952
  if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   953
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   954
      return;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   955
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   956
  // Create a socket to listen only on this interface
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   957
  Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   958
  NS_ASSERT (socket != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   959
  socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvDsdv,this));
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10652
diff changeset
   960
  socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), DSDV_PORT));
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   961
  socket->BindToNetDevice (l3->GetNetDevice (i));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   962
  socket->SetAllowBroadcast (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   963
  socket->SetAttribute ("IpTtl",UintegerValue (1));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   964
  m_socketAddresses.insert (std::make_pair (socket,iface));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   965
  // Add local broadcast record to the routing table
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   966
  Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   967
  RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (), /*seqno=*/ 0,/*iface=*/ iface,/*hops=*/ 0,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   968
                                    /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   969
  m_routingTable.AddRoute (rt);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   970
  if (m_mainAddress == Ipv4Address ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   971
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   972
      m_mainAddress = iface.GetLocal ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   973
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   974
  NS_ASSERT (m_mainAddress != Ipv4Address ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   975
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   976
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   977
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   978
RoutingProtocol::NotifyInterfaceDown (uint32_t i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   979
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   980
  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   981
  Ptr<NetDevice> dev = l3->GetNetDevice (i);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   982
  Ptr<Socket> socket = FindSocketWithInterfaceAddress (m_ipv4->GetAddress (i,0));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   983
  NS_ASSERT (socket);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   984
  socket->Close ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   985
  m_socketAddresses.erase (socket);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   986
  if (m_socketAddresses.empty ())
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   987
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   988
      NS_LOG_LOGIC ("No dsdv interfaces");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   989
      m_routingTable.Clear ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   990
      return;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   991
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   992
  m_routingTable.DeleteAllRoutesFromInterface (m_ipv4->GetAddress (i,0));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   993
  m_advRoutingTable.DeleteAllRoutesFromInterface (m_ipv4->GetAddress (i,0));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   994
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   995
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   996
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   997
RoutingProtocol::NotifyAddAddress (uint32_t i,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   998
                                   Ipv4InterfaceAddress address)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
   999
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1000
  NS_LOG_FUNCTION (this << " interface " << i << " address " << address);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1001
  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1002
  if (!l3->IsUp (i))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1003
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1004
      return;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1005
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1006
  Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1007
  Ptr<Socket> socket = FindSocketWithInterfaceAddress (iface);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1008
  if (!socket)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1009
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1010
      if (iface.GetLocal () == Ipv4Address ("127.0.0.1"))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1011
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1012
          return;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1013
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1014
      Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1015
      NS_ASSERT (socket != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1016
      socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvDsdv,this));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1017
      // Bind to any IP address so that broadcasts can be received
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1018
      socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), DSDV_PORT));
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10652
diff changeset
  1019
      socket->BindToNetDevice (l3->GetNetDevice (i));
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1020
      socket->SetAllowBroadcast (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1021
      m_socketAddresses.insert (std::make_pair (socket,iface));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1022
      Ptr<NetDevice> dev = m_ipv4->GetNetDevice (m_ipv4->GetInterfaceForAddress (iface.GetLocal ()));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1023
      RoutingTableEntry rt (/*device=*/ dev, /*dst=*/ iface.GetBroadcast (),/*seqno=*/ 0, /*iface=*/ iface,/*hops=*/ 0,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1024
                                        /*next hop=*/ iface.GetBroadcast (), /*lifetime=*/ Simulator::GetMaximumSimulationTime ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1025
      m_routingTable.AddRoute (rt);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1026
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1027
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1028
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1029
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1030
RoutingProtocol::NotifyRemoveAddress (uint32_t i,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1031
                                      Ipv4InterfaceAddress address)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1032
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1033
  Ptr<Socket> socket = FindSocketWithInterfaceAddress (address);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1034
  if (socket)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1035
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1036
      m_socketAddresses.erase (socket);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1037
      Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1038
      if (l3->GetNAddresses (i))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1039
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1040
          Ipv4InterfaceAddress iface = l3->GetAddress (i,0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1041
          // Create a socket to listen only on this interface
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1042
          Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),UdpSocketFactory::GetTypeId ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1043
          NS_ASSERT (socket != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1044
          socket->SetRecvCallback (MakeCallback (&RoutingProtocol::RecvDsdv,this));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1045
          // Bind to any IP address so that broadcasts can be received
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1046
          socket->Bind (InetSocketAddress (Ipv4Address::GetAny (), DSDV_PORT));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1047
          socket->SetAllowBroadcast (true);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1048
          m_socketAddresses.insert (std::make_pair (socket,iface));
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1049
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1050
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1051
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1052
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1053
Ptr<Socket>
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1054
RoutingProtocol::FindSocketWithInterfaceAddress (Ipv4InterfaceAddress addr) const
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1055
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1056
  for (std::map<Ptr<Socket>, Ipv4InterfaceAddress>::const_iterator j = m_socketAddresses.begin (); j
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1057
       != m_socketAddresses.end (); ++j)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1058
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1059
      Ptr<Socket> socket = j->first;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1060
      Ipv4InterfaceAddress iface = j->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1061
      if (iface == addr)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1062
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1063
          return socket;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1064
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1065
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1066
  Ptr<Socket> socket;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1067
  return socket;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1068
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1069
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1070
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1071
RoutingProtocol::Send (Ptr<Ipv4Route> route,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1072
                       Ptr<const Packet> packet,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1073
                       const Ipv4Header & header)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1074
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1075
  Ptr<Ipv4L3Protocol> l3 = m_ipv4->GetObject<Ipv4L3Protocol> ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1076
  NS_ASSERT (l3 != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1077
  Ptr<Packet> p = packet->Copy ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1078
  l3->Send (p,route->GetSource (),header.GetDestination (),header.GetProtocol (),route);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1079
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1080
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1081
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1082
RoutingProtocol::Drop (Ptr<const Packet> packet,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1083
                       const Ipv4Header & header,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1084
                       Socket::SocketErrno err)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1085
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1086
  NS_LOG_DEBUG (m_mainAddress << " drop packet " << packet->GetUid () << " to "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1087
                              << header.GetDestination () << " from queue. Error " << err);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1088
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1089
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1090
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1091
RoutingProtocol::LookForQueuedPackets ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1092
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1093
  NS_LOG_FUNCTION (this);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1094
  Ptr<Ipv4Route> route;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1095
  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1096
  m_routingTable.GetListOfAllRoutes (allRoutes);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1097
  for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1098
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1099
      RoutingTableEntry rt;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1100
      rt = i->second;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1101
      if (m_queue.Find (rt.GetDestination ()))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1102
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1103
          if (rt.GetHop () == 1)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1104
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1105
              route = rt.GetRoute ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1106
              NS_LOG_LOGIC ("A route exists from " << route->GetSource ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1107
                                                   << " to neighboring destination "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1108
                                                   << route->GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1109
              NS_ASSERT (route != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1110
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1111
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1112
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1113
              RoutingTableEntry newrt;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1114
              m_routingTable.LookupRoute (rt.GetNextHop (),newrt);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1115
              route = newrt.GetRoute ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1116
              NS_LOG_LOGIC ("A route exists from " << route->GetSource ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1117
                                                   << " to destination " << route->GetDestination () << " via "
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1118
                                                   << rt.GetNextHop ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1119
              NS_ASSERT (route != 0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1120
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1121
          SendPacketFromQueue (rt.GetDestination (),route);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1122
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1123
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1124
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1125
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1126
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1127
RoutingProtocol::SendPacketFromQueue (Ipv4Address dst,
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1128
                                      Ptr<Ipv4Route> route)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1129
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1130
  NS_LOG_DEBUG (m_mainAddress << " is sending a queued packet to destination " << dst);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1131
  QueueEntry queueEntry;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1132
  if (m_queue.Dequeue (dst,queueEntry))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1133
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1134
      DeferredRouteOutputTag tag;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1135
      Ptr<Packet> p = ConstCast<Packet> (queueEntry.GetPacket ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1136
      if (p->RemovePacketTag (tag))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1137
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1138
          if (tag.oif != -1 && tag.oif != m_ipv4->GetInterfaceForDevice (route->GetOutputDevice ()))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1139
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1140
              NS_LOG_DEBUG ("Output device doesn't match. Dropped.");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1141
              return;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1142
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1143
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1144
      UnicastForwardCallback ucb = queueEntry.GetUnicastForwardCallback ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1145
      Ipv4Header header = queueEntry.GetIpv4Header ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1146
      header.SetSource (route->GetSource ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1147
      header.SetTtl (header.GetTtl () + 1); // compensate extra TTL decrement by fake loopback routing
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1148
      ucb (route,p,header);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1149
      if (m_queue.GetSize () != 0 && m_queue.Find (dst))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1150
        {
8975
813554a05d30 Replace src/dsdv usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7767
diff changeset
  1151
          Simulator::Schedule (MilliSeconds (m_uniformRandomVariable->GetInteger (0,100)),
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1152
                               &RoutingProtocol::SendPacketFromQueue,this,dst,route);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1153
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1154
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1155
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1156
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1157
Time
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1158
RoutingProtocol::GetSettlingTime (Ipv4Address address)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1159
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1160
  NS_LOG_FUNCTION ("Calculating the settling time for " << address);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1161
  RoutingTableEntry mainrt;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1162
  Time weightedTime;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1163
  m_routingTable.LookupRoute (address,mainrt);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1164
  if (EnableWST)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1165
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1166
      if (mainrt.GetSettlingTime () == Seconds (0))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1167
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1168
          return Seconds (0);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1169
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1170
      else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1171
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1172
          NS_LOG_DEBUG ("Route SettlingTime: " << mainrt.GetSettlingTime ().GetSeconds ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1173
                                               << " and LifeTime:" << mainrt.GetLifeTime ().GetSeconds ());
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7172
diff changeset
  1174
          weightedTime = Time (m_weightedFactor * mainrt.GetSettlingTime ().GetSeconds () + (1.0 - m_weightedFactor)
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7172
diff changeset
  1175
                               * mainrt.GetLifeTime ().GetSeconds ());
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1176
          NS_LOG_DEBUG ("Calculated weightedTime:" << weightedTime.GetSeconds ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1177
          return weightedTime;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1178
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1179
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1180
  return mainrt.GetSettlingTime ();
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1181
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1182
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1183
void
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1184
RoutingProtocol::MergeTriggerPeriodicUpdates ()
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1185
{
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1186
  NS_LOG_FUNCTION ("Merging advertised table changes with main table before sending out periodic update");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1187
  std::map<Ipv4Address, RoutingTableEntry> allRoutes;
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1188
  m_advRoutingTable.GetListOfAllRoutes (allRoutes);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1189
  if (allRoutes.size () > 0)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1190
    {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1191
      for (std::map<Ipv4Address, RoutingTableEntry>::const_iterator i = allRoutes.begin (); i != allRoutes.end (); ++i)
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1192
        {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1193
          RoutingTableEntry advEntry = i->second;
9922
58beef4d4613 DSDV: Modify rarely-used keywords to comply with other compilers
John Abraham <john.abraham.in@gmail.com>
parents: 8975
diff changeset
  1194
          if ((advEntry.GetEntriesChanged () == true) && (!m_advRoutingTable.AnyRunningEvent (advEntry.GetDestination ())))
6717
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1195
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1196
              if (!(advEntry.GetSeqNo () % 2))
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1197
                {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1198
                  advEntry.SetFlag (VALID);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1199
                  advEntry.SetEntriesChanged (false);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1200
                  m_routingTable.Update (advEntry);
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1201
                  NS_LOG_DEBUG ("Merged update for " << advEntry.GetDestination () << " with main routing Table");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1202
                }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1203
              m_advRoutingTable.DeleteRoute (advEntry.GetDestination ());
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1204
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1205
          else
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1206
            {
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1207
              NS_LOG_DEBUG ("Event currently running. Cannot Merge Routing Tables");
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1208
            }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1209
        }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1210
    }
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1211
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1212
}
e041eb593928 DSDV routing protocol
Hemanth Narra <hemanth@ittc.ku.edu>
parents:
diff changeset
  1213
}