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