src/routing/global-routing/global-route-manager-impl.cc
author Tom Henderson <tomh@tomh.org>
Wed, 25 Mar 2009 10:40:01 -0700
changeset 4297 d8501bae8be1
parent 3969 1db8fca96193
child 4372 d99061f1167c
permissions -rw-r--r--
Fix a previous regexp substitution that went too far
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
1457
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
     3
 * Copyright 2007 University of Washington
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
     4
 * Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
     5
 * 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 *
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * GNU General Public License for more details.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 *
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1457
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
    18
 *
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
    19
 * Authors:  Tom Henderson (tomhend@u.washington.edu)
1457
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
    20
 * 
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
    21
 * Kunihiro Ishigura, Toshiaki Takada (GNU Zebra) are attributed authors
562a7017ed93 Copyrights/licenses for routing code
Tom Henderson <tomh@tomh.org>
parents: 1421
diff changeset
    22
 * of the quagga 0.99.7/src/ospfd/ospf_spf.c code which was ported here
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
 */
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include <utility>
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include <vector>
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
#include <queue>
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
#include "ns3/assert.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
#include "ns3/fatal-error.h"
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
    30
#include "ns3/log.h"
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
#include "ns3/node-list.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
#include "ns3/ipv4.h"
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
    33
#include "ns3/ipv4-global-routing.h"
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
#include "global-router-interface.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
#include "global-route-manager-impl.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
#include "candidate-queue.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
    38
NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
namespace ns3 {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
// SPFVertex Implementation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
SPFVertex::SPFVertex () : 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
  m_vertexType (VertexUnknown), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  m_vertexId ("255.255.255.255"), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  m_lsa (0),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
  m_distanceFromRoot (SPF_INFINITY), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  m_rootOif (SPF_INFINITY),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  m_nextHop ("0.0.0.0"),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
  m_parent (0),
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
    56
  m_children (),
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
    57
  m_vertexProcessed (false)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
    59
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    62
SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  m_vertexId (lsa->GetLinkStateId ()),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
  m_lsa (lsa),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  m_distanceFromRoot (SPF_INFINITY), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  m_rootOif (SPF_INFINITY),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  m_nextHop ("0.0.0.0"),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
  m_parent (0),
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
    69
  m_children (),
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
    70
  m_vertexProcessed (false)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
    72
  NS_LOG_FUNCTION_NOARGS ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    73
  if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    74
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
    75
      NS_LOG_LOGIC ("Setting m_vertexType to VertexRouter");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    76
      m_vertexType = SPFVertex::VertexRouter;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    77
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    78
  else if (lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    79
    { 
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
    80
      NS_LOG_LOGIC ("Setting m_vertexType to VertexNetwork");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    81
      m_vertexType = SPFVertex::VertexNetwork;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
    82
    }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
SPFVertex::~SPFVertex ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
    87
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
  for ( ListOfSPFVertex_t::iterator i = m_children.begin ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
        i != m_children.end ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
        i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
      SPFVertex *p = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
      delete p;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
      p = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
      *i = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
  m_children.clear ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  void 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
SPFVertex::SetVertexType (SPFVertex::VertexType type)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   103
  NS_LOG_FUNCTION (type);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  m_vertexType = type;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  SPFVertex::VertexType 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
SPFVertex::GetVertexType (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   110
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  return m_vertexType;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
  void 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
SPFVertex::SetVertexId (Ipv4Address id)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   117
  NS_LOG_FUNCTION (id);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
  m_vertexId = id;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
  Ipv4Address
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
SPFVertex::GetVertexId (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   124
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
  return m_vertexId;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
  void 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   129
SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   131
  NS_LOG_FUNCTION (lsa);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
  m_lsa = lsa;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   135
  GlobalRoutingLSA* 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
SPFVertex::GetLSA (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   138
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
  return m_lsa;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
  void 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   143
SPFVertex::SetDistanceFromRoot (uint32_t distance)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   145
  NS_LOG_FUNCTION (distance);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
  m_distanceFromRoot = distance;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
  uint32_t
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
SPFVertex::GetDistanceFromRoot (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   152
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
  return m_distanceFromRoot;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
  void 
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   157
SPFVertex::SetOutgoingInterfaceId (uint32_t id)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   159
  NS_LOG_FUNCTION (id);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  m_rootOif = id;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
  uint32_t 
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   164
SPFVertex::GetOutgoingInterfaceId (void) const
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   166
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
  return m_rootOif;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
  void 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
SPFVertex::SetNextHop (Ipv4Address nextHop)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   173
  NS_LOG_FUNCTION (nextHop);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
  m_nextHop = nextHop;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
  Ipv4Address
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
SPFVertex::GetNextHop (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   180
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
  return m_nextHop;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
SPFVertex::SetParent (SPFVertex* parent)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   187
  NS_LOG_FUNCTION (parent);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
  m_parent = parent;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
  SPFVertex* 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
SPFVertex::GetParent (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   194
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  return m_parent;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
  uint32_t 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
SPFVertex::GetNChildren (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   201
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  return m_children.size ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
  SPFVertex* 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
SPFVertex::GetChild (uint32_t n) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   208
  NS_LOG_FUNCTION (n);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  uint32_t j = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
  for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
        i != m_children.end ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
        i++, j++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
      if (j == n)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
          return *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
    }
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   220
  NS_ASSERT_MSG (false, "Index <n> out of range.");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
  return 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
  uint32_t 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
SPFVertex::AddChild (SPFVertex* child)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   227
  NS_LOG_FUNCTION (child);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
  m_children.push_back (child);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
  return m_children.size ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   232
void 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   233
SPFVertex::SetVertexProcessed (bool value)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   234
{
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   235
  m_vertexProcessed = value;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   236
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   237
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   238
bool 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   239
SPFVertex::IsVertexProcessed (void) const
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   240
{
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   241
  return m_vertexProcessed;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   242
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   243
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   244
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
// GlobalRouteManagerLSDB Implementation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
:
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
  m_database ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   255
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   260
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
  LSDBMap_t::iterator i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
  for (i= m_database.begin (); i!= m_database.end (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   264
      NS_LOG_LOGIC ("free LSA");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   265
      GlobalRoutingLSA* temp = i->second;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
      delete temp;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
    }
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   268
  NS_LOG_LOGIC ("clear map");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
  m_database.clear ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
GlobalRouteManagerLSDB::Initialize ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   275
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
  LSDBMap_t::iterator i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
  for (i= m_database.begin (); i!= m_database.end (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
    {
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   279
      GlobalRoutingLSA* temp = i->second;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   280
      temp->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
  void
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   285
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   287
  NS_LOG_FUNCTION (addr << lsa);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
  m_database.insert (LSDBPair_t (addr, lsa));
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   291
  GlobalRoutingLSA*
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   294
  NS_LOG_FUNCTION (addr);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
// Look up an LSA by its address.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
  LSDBMap_t::const_iterator i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
  for (i= m_database.begin (); i!= m_database.end (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
  {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
    if (i->first == addr)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
      return i->second;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
  }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
  return 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   309
  GlobalRoutingLSA*
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   310
GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   311
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   312
  NS_LOG_FUNCTION (addr);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   313
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   314
// Look up an LSA by its address.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   315
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   316
  LSDBMap_t::const_iterator i;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   317
  for (i= m_database.begin (); i!= m_database.end (); i++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   318
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   319
      GlobalRoutingLSA* temp = i->second;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   320
// Iterate among temp's Link Records
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   321
      for (uint32_t j = 0; j < temp->GetNLinkRecords (); j++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   322
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   323
          GlobalRoutingLinkRecord *lr = temp->GetLinkRecord (j);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   324
          if ( lr->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork &&
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   325
               lr->GetLinkData () == addr)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   326
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   327
              return temp;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   328
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   329
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   330
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   331
  return 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   332
}
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   333
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   334
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   335
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   336
// GlobalRouteManagerImpl Implementation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   337
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   338
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   339
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   340
GlobalRouteManagerImpl::GlobalRouteManagerImpl () 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   341
: 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   342
  m_spfroot (0) 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   343
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   344
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   345
  m_lsdb = new GlobalRouteManagerLSDB ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   346
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   347
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   348
GlobalRouteManagerImpl::~GlobalRouteManagerImpl ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   349
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   350
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   351
  if (m_lsdb)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   352
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   353
      delete m_lsdb;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   354
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   355
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   356
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   357
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   358
GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   359
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   360
  NS_LOG_FUNCTION (lsdb);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   361
  if (m_lsdb)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   362
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
      delete m_lsdb;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   365
  m_lsdb = lsdb;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   366
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   367
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   368
  void
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   369
GlobalRouteManagerImpl::DeleteGlobalRoutes ()
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   370
{
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   371
  NS_LOG_FUNCTION_NOARGS ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   372
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   373
    {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   374
      Ptr<Node> node = *i;
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   375
      Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   376
      uint32_t j = 0;
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   377
      uint32_t nRoutes = gr->GetNRoutes ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   378
      NS_LOG_LOGIC ("Deleting " << gr->GetNRoutes ()<< " routes from node " << node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   379
      // Each time we delete route 0, the route index shifts downward
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   380
      // We can delete all routes if we delete the route numbered 0
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   381
      // nRoutes times
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   382
      for (j = 0; j < nRoutes; j++)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   383
        {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   384
          NS_LOG_LOGIC ("Deleting global route " << j << " from node " << node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   385
          gr->RemoveRoute (0);        
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   386
        }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   387
      NS_LOG_LOGIC ("Deleted " << j << " global routes from node "<< node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   388
    }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   389
  if (m_lsdb)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   390
    {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   391
      NS_LOG_LOGIC ("Deleting LSDB, creating new one");
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   392
      delete m_lsdb;
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   393
      m_lsdb = new GlobalRouteManagerLSDB ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   394
    }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   395
}
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   396
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   397
//
1113
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   398
// In order to build the routing database, we need at least one of the nodes
3937
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   399
// to participate as a router.  This is a convenience function that makes
1113
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   400
// all nodes routers.  We do this by walking the list of nodes in the system
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   401
// and aggregating a Global Router Interface to each of the nodes.
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   402
//
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   403
  void
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   404
GlobalRouteManagerImpl::SelectRouterNodes () 
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   405
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   406
  NS_LOG_FUNCTION_NOARGS ();
1301
440379945254 use the NodeList::Iterator type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1282
diff changeset
   407
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
1113
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   408
    {
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   409
      Ptr<Node> node = *i;
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   410
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << node->GetId ());
1113
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   411
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1881
diff changeset
   412
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
2258
666099a753e0 AddInterface -> AggregateObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   413
      node->AggregateObject (globalRouter);
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   414
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   415
      NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   416
      Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   417
      // This is the object that will keep the global routes.  We insert it
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   418
      // at slightly higher priority than static routing (which is at zero).
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   419
      // This means that global routes (e.g. host routes) will be consulted
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   420
      // before static routes
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   421
      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   422
      NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   423
        "GetObject for <Ipv4> interface failed");
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   424
      // XXX make the below  priority value an attribute
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   425
      ipv4->AddRoutingProtocol (globalRouting, 3);  
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   426
      // Locally cache the globalRouting pointer; we'll need it later
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   427
      // when we add routes
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   428
      AddGlobalRoutingProtocol (node->GetId (), globalRouting);
1113
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   429
    }
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   430
}
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   431
3937
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   432
  void
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   433
GlobalRouteManagerImpl::SelectRouterNodes (NodeContainer c) 
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   434
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   435
  NS_LOG_FUNCTION (&c);
3937
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   436
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   437
    {
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   438
      Ptr<Node> node = *i;
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   439
      NS_LOG_LOGIC ("Adding GlobalRouter interface to node " << 
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   440
        node->GetId ());
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   441
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   442
      Ptr<GlobalRouter> globalRouter = CreateObject<GlobalRouter> ();
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   443
      node->AggregateObject (globalRouter);
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   444
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   445
      NS_LOG_LOGIC ("Adding GlobalRouting Protocol to node " << node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   446
      Ptr<Ipv4GlobalRouting> globalRouting = CreateObject<Ipv4GlobalRouting> ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   447
      // This is the object that will keep the global routes.  We insert it
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   448
      // at slightly higher priority than static routing (which is at zero).
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   449
      // This means that global routes (e.g. host routes) will be consulted
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   450
      // before static routes
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   451
      Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   452
      NS_ASSERT_MSG (ipv4, "GlobalRouteManagerImpl::SelectRouterNodes (): "
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   453
        "GetObject for <Ipv4> interface failed");
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   454
      // XXX make the below  priority value an attribute
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   455
      ipv4->AddRoutingProtocol (globalRouting, 3);  
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   456
      // Locally cache the globalRouting pointer; we'll need it later
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   457
      // when we add routes
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   458
      AddGlobalRoutingProtocol (node->GetId (), globalRouting);
3937
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   459
    }
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   460
}
04f9377661b8 convince global routing not to crash in the presence of bridges
Craig Dowell <craigdo@ee.washington.edu>
parents: 3365
diff changeset
   461
1113
5b63b39161e7 remove routing environment, move router interface creation to global-route-manager
Craig Dowell <craigdo@ee.washington.edu>
parents: 1111
diff changeset
   462
//
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   463
// In order to build the routing database, we need to walk the list of nodes
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   464
// in the system and look for those that support the GlobalRouter interface.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   465
// These routers will export a number of Link State Advertisements (LSAs)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   466
// that describe the links and networks that are "adjacent" (i.e., that are
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   467
// on the other side of a point-to-point link).  We take these LSAs and put
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   468
// add them to the Link State DataBase (LSDB) from which the routes will 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   469
// ultimately be computed.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   470
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   471
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   472
GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   473
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   474
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   475
//
3939
206f627bd5af factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents: 3937
diff changeset
   476
// Walk the list of nodes looking for the GlobalRouter Interface.  Nodes with
206f627bd5af factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents: 3937
diff changeset
   477
// global router interfaces are, not too surprisingly, our routers.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   478
//
1301
440379945254 use the NodeList::Iterator type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1282
diff changeset
   479
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   480
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   481
      Ptr<Node> node = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   482
3939
206f627bd5af factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents: 3937
diff changeset
   483
      Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   484
//      
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   485
// Ignore nodes that aren't participating in routing.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   486
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   487
      if (!rtr)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   488
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   489
          continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   491
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   492
// You must call DiscoverLSAs () before trying to use any routing info or to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
// update LSAs.  DiscoverLSAs () drives the process of discovering routes in
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   494
// the GlobalRouter.  Afterward, you may use GetNumLSAs (), which is a very
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   495
// computationally inexpensive call.  If you call GetNumLSAs () before calling 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   496
// DiscoverLSAs () will get zero as the number since no routes have been 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   497
// found.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   498
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   499
      uint32_t numLSAs = rtr->DiscoverLSAs ();
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   500
      NS_LOG_LOGIC ("Found " << numLSAs << " LSAs");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   501
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   502
      for (uint32_t j = 0; j < numLSAs; ++j)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   503
        {
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   504
          GlobalRoutingLSA* lsa = new GlobalRoutingLSA ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   505
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   506
// This is the call to actually fetch a Link State Advertisement from the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
// router.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   509
          rtr->GetLSA (j, *lsa);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   510
          NS_LOG_LOGIC (*lsa);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   511
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   512
// Write the newly discovered link state advertisement to the database.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   513
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   514
          m_lsdb->Insert (lsa->GetLinkStateId (), lsa); 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   515
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   516
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   517
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   518
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   519
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   520
// For each node that is a global router (which is determined by the presence
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   521
// of an aggregated GlobalRouter interface), run the Dijkstra SPF calculation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   522
// on the database rooted at that router, and populate the node forwarding
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   523
// tables.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   524
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   525
// This function parallels RFC2328, Section 16.1.1, and quagga ospfd
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   526
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   527
// This calculation yields the set of intra-area routes associated
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   528
// with an area (called hereafter Area A).  A router calculates the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   529
// shortest-path tree using itself as the root.  The formation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   530
// of the shortest path tree is done here in two stages.  In the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   531
// first stage, only links between routers and transit networks are
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   532
// considered.  Using the Dijkstra algorithm, a tree is formed from
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   533
// this subset of the link state database.  In the second stage,
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
// leaves are added to the tree by considering the links to stub
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   535
// networks.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   536
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   537
// The area's link state database is represented as a directed graph.  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
// The graph's vertices are routers, transit networks and stub networks.  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   539
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   540
// The first stage of the procedure (i.e., the Dijkstra algorithm)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   541
// can now be summarized as follows. At each iteration of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   542
// algorithm, there is a list of candidate vertices.  Paths from
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   543
// the root to these vertices have been found, but not necessarily
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   544
// the shortest ones.  However, the paths to the candidate vertex
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   545
// that is closest to the root are guaranteed to be shortest; this
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   546
// vertex is added to the shortest-path tree, removed from the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   547
// candidate list, and its adjacent vertices are examined for
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   548
// possible addition to/modification of the candidate list.  The
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   549
// algorithm then iterates again.  It terminates when the candidate
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   550
// list becomes empty. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   551
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   552
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   553
GlobalRouteManagerImpl::InitializeRoutes ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   554
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
   555
  NS_LOG_FUNCTION_NOARGS ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   557
// Walk the list of nodes in the system.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   558
//
1301
440379945254 use the NodeList::Iterator type
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1282
diff changeset
   559
  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   560
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   561
      Ptr<Node> node = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   562
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   563
// Look for the GlobalRouter interface that indicates that the node is
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   564
// participating in routing.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   565
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   566
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   567
        node->GetObject<GlobalRouter> ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   568
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   569
// if the node has a global router interface, then run the global routing
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   570
// algorithms.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   571
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   572
      if (rtr && rtr->GetNumLSAs () )
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   573
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   574
          SPFCalculate (rtr->GetRouterId ());
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   575
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   576
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   577
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   578
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   579
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   580
// This method is derived from quagga ospf_spf_next ().  See RFC2328 Section 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   581
// 16.1 (2) for further details.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   582
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   583
// We're passed a parameter <v> that is a vertex which is already in the SPF
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   584
// tree.  A vertex represents a router node.  We also get a reference to the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   585
// SPF candidate queue, which is a priority queue containing the shortest paths
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   586
// to the networks we know about.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   587
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   588
// We examine the links in v's LSA and update the list of candidates with any
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   589
// vertices not already on the list.  If a lower-cost path is found to a
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   590
// vertex already on the candidate list, store the new (lower) cost.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   591
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   592
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   593
GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   594
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   595
  NS_LOG_FUNCTION (v << &candidate);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   596
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   597
  SPFVertex* w = 0;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   598
  GlobalRoutingLSA* w_lsa = 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   599
  GlobalRoutingLinkRecord *l = 0;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   600
  uint32_t distance = 0;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   601
  uint32_t numRecordsInVertex = 0;
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   602
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   603
// V points to a Router-LSA or Network-LSA
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   604
// Loop over the links in router LSA or attached routers in Network LSA
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   605
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   606
  if (v->GetVertexType () == SPFVertex::VertexRouter)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   607
    {
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   608
      numRecordsInVertex = v->GetLSA ()->GetNLinkRecords (); 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   609
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   610
  if (v->GetVertexType () == SPFVertex::VertexNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   611
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   612
      numRecordsInVertex = v->GetLSA ()->GetNAttachedRouters (); 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   613
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   614
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   615
  for (uint32_t i = 0; i < numRecordsInVertex; i++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   616
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   617
// Get w_lsa:  In case of V is Router-LSA
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   618
      if (v->GetVertexType () == SPFVertex::VertexRouter) 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   619
        {
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   620
          NS_LOG_LOGIC ("Examining link " << i << " of " << 
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   621
            v->GetVertexId () << "'s " <<
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   622
            v->GetLSA ()->GetNLinkRecords () << " link records");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   623
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   624
// (a) If this is a link to a stub network, examine the next link in V's LSA.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   625
// Links to stub networks will be considered in the second stage of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   626
// shortest path calculation.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   627
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   628
          l = v->GetLSA ()->GetLinkRecord (i);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   629
          if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   630
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   631
              NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   632
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   633
            }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   634
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   635
// (b) Otherwise, W is a transit vertex (router or transit network).  Look up
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   636
// the vertex W's LSA (router-LSA or network-LSA) in Area A's link state
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   637
// database. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   638
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   639
          if (l->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   640
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   641
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   642
// Lookup the link state advertisement of the new link -- we call it <w> in
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   643
// the link state database.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   644
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   645
              w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   646
              NS_ASSERT (w_lsa);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   647
              NS_LOG_LOGIC ("Found a P2P record from " << 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   648
                v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   649
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   650
          else if (l->GetLinkType () == 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   651
            GlobalRoutingLinkRecord::TransitNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   652
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   653
              w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   654
              NS_ASSERT (w_lsa);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   655
              NS_LOG_LOGIC ("Found a Transit record from " << 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   656
                v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   657
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   658
          else 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   659
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   660
              NS_ASSERT_MSG (0, "illegal Link Type");
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   661
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   662
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   663
// Get w_lsa:  In case of V is Network-LSA
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   664
      if (v->GetVertexType () == SPFVertex::VertexNetwork) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   665
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   666
          w_lsa = m_lsdb->GetLSAByLinkData 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   667
            (v->GetLSA ()->GetAttachedRouter (i)); 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   668
          if (!w_lsa)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   669
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   670
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   671
            }
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   672
          NS_LOG_LOGIC ("Found a Network LSA from " << 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   673
            v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   674
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   675
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   676
// Note:  w_lsa at this point may be either RouterLSA or NetworkLSA
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
// (c) If vertex W is already on the shortest-path tree, examine the next
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   679
// link in the LSA.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   680
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   681
// If the link is to a router that is already in the shortest path first tree
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
// then we have it covered -- ignore it.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   683
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   684
      if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_IN_SPFTREE) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   685
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   686
          NS_LOG_LOGIC ("Skipping ->  LSA "<< 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   687
            w_lsa->GetLinkStateId () << " already in SPF tree");
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   688
          continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   689
        }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   690
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   691
// (d) Calculate the link state cost D of the resulting path from the root to 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   692
// vertex W.  D is equal to the sum of the link state cost of the (already 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
// calculated) shortest path to vertex V and the advertised cost of the link
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
// between vertices V and W.  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   695
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   696
      if (v->GetLSA ()->GetLSType () == GlobalRoutingLSA::RouterLSA)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   697
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   698
          distance = v->GetDistanceFromRoot () + l->GetMetric ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   699
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   700
      else
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   701
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   702
          distance = v->GetDistanceFromRoot ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   703
        }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   704
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   705
      NS_LOG_LOGIC ("Considering w_lsa " << w_lsa->GetLinkStateId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   706
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   707
// Is there already vertex w in candidate list?
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   708
      if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   709
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   710
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   711
// prepare vertex w
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   712
          w = new SPFVertex (w_lsa);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   713
// Calculate nexthop to w
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   714
// We need to figure out how to actually get to the new router represented
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   715
// by <w>.  This will (among other things) find the next hop address to send
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   716
// packets destined for this network to, and also find the outbound interface
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   717
// used to forward the packets.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   718
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   719
          if (SPFNexthopCalculation (v, w, l, distance))
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   720
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   721
              w_lsa->SetStatus (GlobalRoutingLSA::LSA_SPF_CANDIDATE);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   723
// Push this new vertex onto the priority queue (ordered by distance from the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   724
// root node).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   725
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   726
              candidate.Push (w);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   727
              NS_LOG_LOGIC ("Pushing " << 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   728
                w->GetVertexId () << ", parent vertexId: " << 
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   729
                v->GetVertexId () << ", distance: " <<
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   730
                w->GetDistanceFromRoot ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   731
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   732
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   733
      else if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_CANDIDATE)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   734
        {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   736
// We have already considered the link represented by <w>.  What wse have to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   737
// do now is to decide if this new router represents a route with a shorter
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   738
// distance metric.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   739
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   740
// So, locate the vertex in the candidate queue and take a look at the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   741
// distance.
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   742
          w = candidate.Find (w_lsa->GetLinkStateId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   743
          if (w->GetDistanceFromRoot () < distance)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   744
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   745
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   746
// This is not a shorter path, so don't do anything.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   748
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   749
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   750
          else if (w->GetDistanceFromRoot () == distance)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   751
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   752
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   753
// This path is one with an equal cost.  Do nothing for now -- we're not doing
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   754
// equal-cost multipath cases yet.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   755
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   756
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   757
          else
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   758
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   759
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   760
// this path represents a new, lower-cost path to <w> (the vertex we found in
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   761
// the current link record of the link state advertisement of the current root
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   762
// (vertex <v>)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   763
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   764
// N.B. the nexthop_calculation is conditional, if it finds a valid nexthop
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   765
// it will call spf_add_parents, which will flush the old parents
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   766
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   767
              if (SPFNexthopCalculation (v, w, l, distance))
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   768
                {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   769
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   770
// If we've changed the cost to get to the vertex represented by <w>, we 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   771
// must reorder the priority queue keyed to that cost.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   772
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   773
                  candidate.Reorder ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   774
                }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   775
            } // new lower cost path found   
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   776
        } // end W is already on the candidate list
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   777
    } // end loop over the links in V's LSA
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   778
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   779
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   780
//
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   781
// This method is derived from quagga ospf_nexthop_calculation() 16.1.1.  
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   782
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   783
// Calculate nexthop from root through V (parent) to vertex W (destination)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   784
// with given distance from root->W.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   785
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   786
// As appropriate, set w's parent, distance, and nexthop information
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   787
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   788
// For now, this is greatly simplified from the quagga code
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   789
//                  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   790
  int
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   791
GlobalRouteManagerImpl::SPFNexthopCalculation (
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   792
  SPFVertex* v, 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   793
  SPFVertex* w,
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   794
  GlobalRoutingLinkRecord* l,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   795
  uint32_t distance)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   796
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   797
  NS_LOG_FUNCTION (v << w << l << distance);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   798
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   799
// If w is a NetworkVertex, l should be null
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   800
/*
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   801
  if (w->GetVertexType () == SPFVertex::VertexNetwork && l)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   802
    {
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   803
        NS_ASSERT_MSG (0, "Error:  SPFNexthopCalculation parameter problem");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   804
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   805
*/
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   806
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   807
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   808
// The vertex m_spfroot is a distinguished vertex representing the node at
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   809
// the root of the calculations.  That is, it is the node for which we are
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   810
// calculating the routes.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   811
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   812
// There are two distinct cases for calculating the next hop information.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   813
// First, if we're considering a hop from the root to an "adjacent" network
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   814
// (one that is on the other side of a point-to-point link connected to the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   815
// root), then we need to store the information needed to forward down that
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   816
// link.  The second case is if the network is not directly adjacent.  In that
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   817
// case we need to use the forwarding information from the vertex on the path
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   818
// to the destination that is directly adjacent [node 1] in both cases of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   819
// diagram below.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   820
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   821
// (1) [root] -> [point-to-point] -> [node 1]
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   822
// (2) [root] -> [point-to-point] -> [node 1] -> [point-to-point] -> [node 2]
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   823
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   824
// We call the propagation of next hop information down vertices of a path
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   825
// "inheriting" the next hop information.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   826
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   827
// The point-to-point link information is only useful in this calculation when
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   828
// we are examining the root node. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   829
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   830
  if (v == m_spfroot)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   831
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   832
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   833
// In this case <v> is the root node, which means it is the starting point
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   834
// for the packets forwarded by that node.  This also means that the next hop
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   835
// address of packets headed for some arbitrary off-network destination must
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   836
// be the destination at the other end of one of the links off of the root
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   837
// node if this root node is a router.  We then need to see if this node <w>
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   838
// is a router.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   839
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   840
      if (w->GetVertexType () == SPFVertex::VertexRouter) 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   841
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   842
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   843
// In the case of point-to-point links, the link data field (m_linkData) of a
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   844
// Global Router Link Record contains the local IP address.  If we look at the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   845
// link record describing the link from the perspecive of <w> (the remote
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   846
// node from the viewpoint of <v>) back to the root node, we can discover the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   847
// IP address of the router to which <v> is adjacent.  This is a distinguished
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   848
// address -- the next hop address to get from <v> to <w> and all networks 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   849
// accessed through that path.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   850
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   851
// SPFGetNextLink () is a little odd.  used in this way it is just going to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   852
// return the link record describing the link from <w> to <v>.  Think of it as
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   853
// SPFGetLink.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   854
//
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   855
          NS_ASSERT (l);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   856
          GlobalRoutingLinkRecord *linkRemote = 0;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   857
          linkRemote = SPFGetNextLink (w, v, linkRemote);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   858
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   859
// At this point, <l> is the Global Router Link Record describing the point-
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   860
// to point link from <v> to <w> from the perspective of <v>; and <linkRemote>
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   861
// is the Global Router Link Record describing that same link from the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   862
// perspective of <w> (back to <v>).  Now we can just copy the next hop 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   863
// address from the m_linkData member variable.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   864
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   865
// The next hop member variable we put in <w> has the sense "in order to get
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   866
// from the root node to the host represented by vertex <w>, you have to send
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   867
// the packet to the next hop address specified in w->m_nextHop.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   868
//
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   869
          w->SetNextHop (linkRemote->GetLinkData ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   870
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   871
// Now find the outgoing interface corresponding to the point to point link
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   872
// from the perspective of <v> -- remember that <l> is the link "from"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   873
// <v> "to" <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   874
//
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   875
          w->SetOutgoingInterfaceId (
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   876
            FindOutgoingInterfaceId (l->GetLinkData ()));
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   877
          w->SetDistanceFromRoot (distance);
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   878
          w->SetParent (v);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   879
          NS_LOG_LOGIC ("Next hop from " << 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   880
            v->GetVertexId () << " to " << w->GetVertexId () << 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   881
            " goes through next hop " << w->GetNextHop () <<
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   882
            " via outgoing interface " << w->GetOutgoingInterfaceId () <<
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   883
            " with distance " << distance);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   884
        }  // end W is a router vertes
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   885
      else 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   886
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   887
          NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   888
// W is a directly connected network; no next hop is required
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   889
          GlobalRoutingLSA* w_lsa = w->GetLSA ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   890
          NS_ASSERT (w_lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   891
// Find outgoing interface ID for this network
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   892
          w->SetOutgoingInterfaceId (
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   893
            FindOutgoingInterfaceId (w_lsa->GetLinkStateId (), 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   894
            w_lsa->GetNetworkLSANetworkMask () ));
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   895
          w->SetDistanceFromRoot (distance);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   896
          w->SetParent (v);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   897
          NS_LOG_LOGIC ("Next hop from " << 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   898
            v->GetVertexId () << " to network " << w->GetVertexId () << 
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   899
            " via outgoing interface " << w->GetOutgoingInterfaceId () <<
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
   900
            " with distance " << distance);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   901
          return 1;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   902
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   903
    } // end v is the root
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   904
  else if (v->GetVertexType () == SPFVertex::VertexNetwork) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   905
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   906
// See if any of v's parents are the root
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   907
      if (v->GetParent () == m_spfroot)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   908
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   909
// 16.1.1 para 5. ...the parent vertex is a network that
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   910
// directly connects the calculating router to the destination
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   911
// router.  The list of next hops is then determined by
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   912
// examining the destination's router-LSA...
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   913
          NS_ASSERT (w->GetVertexType () == SPFVertex::VertexRouter);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   914
          GlobalRoutingLinkRecord *linkRemote = 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   915
          while ((linkRemote = SPFGetNextLink (w, v, linkRemote)))
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   916
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   917
/* ...For each link in the router-LSA that points back to the
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   918
 * parent network, the link's Link Data field provides the IP
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   919
 * address of a next hop router.  The outgoing interface to
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   920
 * use can then be derived from the next hop IP address (or 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   921
 * it can be inherited from the parent network).
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   922
 */
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   923
                w->SetNextHop (linkRemote->GetLinkData ());
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   924
                w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ());
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   925
                NS_LOG_LOGIC ("Next hop from " << 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   926
                  v->GetVertexId () << " to " << w->GetVertexId () << 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   927
                  " goes through next hop " << w->GetNextHop () <<
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   928
                  " via outgoing interface " << w->GetOutgoingInterfaceId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   929
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   930
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   931
      else 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   932
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   933
          w->SetNextHop (v->GetNextHop ());
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   934
          w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   935
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   936
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   937
  else 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   938
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   939
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   940
// If we're calculating the next hop information from a node (v) that is 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   941
// *not* the root, then we need to "inherit" the information needed to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   942
// forward the packet from the vertex closer to the root.  That is, we'll
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   943
// still send packets to the next hop address of the router adjacent to the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   944
// root on the path toward <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   945
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   946
// Above, when we were considering the root node, we calculated the next hop
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   947
// address and outgoing interface required to get off of the root network.  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   948
// At this point, we are further away from the root network along one of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   949
// (shortest) paths.  So the next hop and outoing interface remain the same
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   950
// (are inherited).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   951
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   952
      w->SetNextHop (v->GetNextHop ());
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
   953
      w->SetOutgoingInterfaceId (v->GetOutgoingInterfaceId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   954
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   955
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   956
// In all cases, we need valid values for the distance metric and a parent.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   957
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   958
  w->SetDistanceFromRoot (distance);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   959
  w->SetParent (v);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   960
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   961
  return 1;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   962
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   963
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   964
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   965
// This method is derived from quagga ospf_get_next_link ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   966
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   967
// First search the Global Router Link Records of vertex <v> for one
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   968
// representing a point-to point link to vertex <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   969
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   970
// What is done depends on prev_link.  Contrary to appearances, prev_link just
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   971
// acts as a flag here.  If prev_link is NULL, we return the first Global
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   972
// Router Link Record we find that describes a point-to-point link from <v> 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   973
// to <w>.  If prev_link is not NULL, we return a Global Router Link Record
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   974
// representing a possible *second* link from <v> to <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   975
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   976
  GlobalRoutingLinkRecord* 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   977
GlobalRouteManagerImpl::SPFGetNextLink (
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   978
  SPFVertex* v,
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   979
  SPFVertex* w,
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   980
  GlobalRoutingLinkRecord* prev_link) 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   981
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
   982
  NS_LOG_FUNCTION (v << w << prev_link);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   983
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   984
  bool skip = true;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   985
  bool found_prev_link = false;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   986
  GlobalRoutingLinkRecord* l;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   987
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   988
// If prev_link is 0, we are really looking for the first link, not the next 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   989
// link.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   990
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   991
  if (prev_link == 0)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   992
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   993
      skip = false;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   994
      found_prev_link = true;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   995
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   996
//  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   997
// Iterate through the Global Router Link Records advertised by the vertex
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   998
// <v> looking for records representing the point-to-point links off of this
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   999
// vertex.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1000
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1001
  for (uint32_t i = 0; i < v->GetLSA ()->GetNLinkRecords (); ++i)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1002
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1003
      l = v->GetLSA ()->GetLinkRecord (i);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1004
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1005
// The link ID of a link record representing a point-to-point link is set to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1006
// the router ID of the neighboring router -- the router to which the link
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1007
// connects from the perspective of <v> in this case.  The vertex ID is also
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1008
// set to the router ID (using the link state advertisement of a router node).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1009
// We're just checking to see if the link <l> is actually the link from <v> to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1010
// <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1011
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1012
      if (l->GetLinkId () == w->GetVertexId ()) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1013
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1014
          if (!found_prev_link)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1015
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1016
              NS_LOG_LOGIC ("Skipping links before prev_link found");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1017
              found_prev_link = true;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1018
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1019
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1020
        
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1021
          NS_LOG_LOGIC ("Found matching link l:  linkId = " <<
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1022
          l->GetLinkId () << " linkData = " << l->GetLinkData ());
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1023
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1024
// If skip is false, don't (not too surprisingly) skip the link found -- it's 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1025
// the one we're interested in.  That's either because we didn't pass in a 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1026
// previous link, and we're interested in the first one, or because we've 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1027
// skipped a previous link and moved forward to the next (which is then the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1028
// one we want).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1029
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1030
        if (skip == false) 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1031
          {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1032
            NS_LOG_LOGIC ("Returning the found link");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1033
            return l;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1034
          }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1035
        else
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1036
          {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1037
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1038
// Skip is true and we've found a link from <v> to <w>.  We want the next one.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1039
// Setting skip to false gets us the next point-to-point global router link
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1040
// record in the LSA from <v>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1041
//
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1042
            NS_LOG_LOGIC ("Skipping the found link");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1043
            skip = false;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1044
            continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1045
          }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1046
      }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1047
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1048
  return 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1049
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1050
  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1051
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1052
// Used for unit tests.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1053
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1054
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1055
GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1056
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
  1057
  NS_LOG_FUNCTION (root);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1058
  SPFCalculate (root);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1059
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1060
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1061
// quagga ospf_spf_calculate
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1062
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1063
GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1064
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2258
diff changeset
  1065
  NS_LOG_FUNCTION (this << root);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1066
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1067
  SPFVertex *v;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1068
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1069
// Initialize the Link State Database.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1070
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1071
  m_lsdb->Initialize ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1072
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1073
// The candidate queue is a priority queue of SPFVertex objects, with the top
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1074
// of the queue being the closest vertex in terms of distance from the root
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1075
// of the tree.  Initially, this queue is empty.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1076
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1077
  CandidateQueue candidate;
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
  1078
  NS_ASSERT (candidate.Size () == 0);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1079
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1080
// Initialize the shortest-path tree to only contain the router doing the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1081
// calculation.  Each router (and corresponding network) is a vertex in the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1082
// shortest path first (SPF) tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1083
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1084
  v = new SPFVertex (m_lsdb->GetLSA (root));
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1085
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1086
// This vertex is the root of the SPF tree and it is distance 0 from the root.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1087
// We also mark this vertex as being in the SPF tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1088
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1089
  m_spfroot= v;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1090
  v->SetDistanceFromRoot (0);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1091
  v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1776
0d5be0c3d229 Add support for non-unit-cost metrics for Ipv4Interfaces (for use in routing); add example script simple-alternate-routing.cc
Tom Henderson <tomh@tomh.org>
parents: 1505
diff changeset
  1092
  NS_LOG_LOGIC ("Starting SPFCalculate for node " << root);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1093
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1094
  for (;;)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1095
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1096
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1097
// The operations we need to do are given in the OSPF RFC which we reference
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1098
// as we go along.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1099
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1100
// RFC2328 16.1. (2). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1101
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1102
// We examine the Global Router Link Records in the Link State 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1103
// Advertisements of the current vertex.  If there are any point-to-point
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1104
// links to unexplored adjacent vertices we add them to the tree and update
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1105
// the distance and next hop information on how to get there.  We also add
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1106
// the new vertices to the candidate queue (the priority queue ordered by
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1107
// shortest path).  If the new vertices represent shorter paths, we use them
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1108
// and update the path cost.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1109
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1110
      SPFNext (v, candidate);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1111
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1112
// RFC2328 16.1. (3). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1113
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1114
// If at this step the candidate list is empty, the shortest-path tree (of
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1115
// transit vertices) has been completely built and this stage of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1116
// procedure terminates. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1117
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1118
      if (candidate.Size () == 0)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1119
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1120
          break;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1121
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1122
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1123
// Choose the vertex belonging to the candidate list that is closest to the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1124
// root, and add it to the shortest-path tree (removing it from the candidate
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1125
// list in the process).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1126
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1127
// Recall that in the previous step, we created SPFVertex structures for each
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1128
// of the routers found in the Global Router Link Records and added tehm to 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1129
// the candidate list.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1130
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1131
      v = candidate.Pop ();
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1132
      NS_LOG_LOGIC ("Popped vertex " << v->GetVertexId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1133
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1134
// Update the status field of the vertex to indicate that it is in the SPF
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1135
// tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1136
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1137
      v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1138
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1139
// The current vertex has a parent pointer.  By calling this rather oddly 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1140
// named method (blame quagga) we add the current vertex to the list of 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1141
// children of that parent vertex.  In the next hop calculation called during
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1142
// SPFNext, the parent pointer was set but the vertex has been orphaned up
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1143
// to now.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1144
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1145
      SPFVertexAddParent (v);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1146
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1147
// Note that when there is a choice of vertices closest to the root, network
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1148
// vertices must be chosen before router vertices in order to necessarily
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1149
// find all equal-cost paths. We don't do this at this moment, we should add
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1150
// the treatment above codes. -- kunihiro. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1151
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1152
// RFC2328 16.1. (4). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1153
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1154
// This is the method that actually adds the routes.  It'll walk the list
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1155
// of nodes in the system, looking for the node corresponding to the router
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1156
// ID of the root of the tree -- that is the router we're building the routes
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1157
// for.  It looks for the Ipv4 interface of that node and remembers it.  So
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1158
// we are only actually adding routes to that one node at the root of the SPF 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1159
// tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1160
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1161
// We're going to pop of a pointer to every vertex in the tree except the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1162
// root in order of distance from the root.  For each of the vertices, we call
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1163
// SPFIntraAddRouter ().  Down in SPFIntraAddRouter, we look at all of the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1164
// point-to-point Global Router Link Records (the links to nodes adjacent to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1165
// the node represented by the vertex).  We add a route to the IP address 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1166
// specified by the m_linkData field of each of those link records.  This will
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1167
// be the *local* IP address associated with the interface attached to the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1168
// link.  We use the outbound interface and next hop information present in 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1169
// the vertex <v> which have possibly been inherited from the root.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1170
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1171
// To summarize, we're going to look at the node represented by <v> and loop
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1172
// through its point-to-point links, adding a *host* route to the local IP
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1173
// address (at the <v> side) for each of those links.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1174
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1175
      if (v->GetVertexType () == SPFVertex::VertexRouter)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1176
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1177
          SPFIntraAddRouter (v);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1178
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1179
      else if (v->GetVertexType () == SPFVertex::VertexNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1180
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1181
          SPFIntraAddTransit (v);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1182
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1183
      else
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1184
        {
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
  1185
          NS_ASSERT_MSG (0, "illegal SPFVertex type");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1186
        }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1187
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1188
// RFC2328 16.1. (5). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1189
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1190
// Iterate the algorithm by returning to Step 2 until there are no more
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1191
// candidate vertices.
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1192
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1193
    }  // end for loop
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1194
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1195
// Second stage of SPF calculation procedure  
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1196
  SPFProcessStubs (m_spfroot);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1197
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1198
// We're all done setting the routing information for the node at the root of
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1199
// the SPF tree.  Delete all of the vertices and corresponding resources.  Go
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1200
// possibly do it again for the next router.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1201
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1202
  delete m_spfroot;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1203
  m_spfroot = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1204
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1205
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1206
// Processing logic from RFC 2328, page 166 and quagga ospf_spf_process_stubs ()
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1207
// stub link records will exist for point-to-point interfaces and for
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1208
// broadcast interfaces for which no neighboring router can be found
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1209
void
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1210
GlobalRouteManagerImpl::SPFProcessStubs (SPFVertex* v)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1211
{
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1212
  NS_LOG_FUNCTION_NOARGS ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1213
  NS_LOG_LOGIC ("Processing stubs for " << v->GetVertexId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1214
  if (v->GetVertexType () == SPFVertex::VertexRouter)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1215
    {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1216
      GlobalRoutingLSA *rlsa = v->GetLSA ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1217
      NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1218
      for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1219
        {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1220
          NS_LOG_LOGIC ("Examining link " << i << " of " << 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1221
            v->GetVertexId () << "'s " <<
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1222
            v->GetLSA ()->GetNLinkRecords () << " link records");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1223
          GlobalRoutingLinkRecord *l = v->GetLSA ()->GetLinkRecord (i);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1224
          if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1225
            {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1226
              NS_LOG_LOGIC ("Found a Stub record to " << l->GetLinkId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1227
              SPFIntraAddStub (l, v);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1228
              continue;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1229
            }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1230
        }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1231
    }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1232
    for (uint32_t i = 0; i < v->GetNChildren (); i++)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1233
      {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1234
        if (!v->GetChild (i)->IsVertexProcessed ())
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1235
          {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1236
            SPFProcessStubs (v->GetChild (i));
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1237
            v->GetChild (i)->SetVertexProcessed (true);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1238
          }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1239
      }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1240
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1241
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1242
// RFC2328 16.1. second stage. 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1243
void
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1244
GlobalRouteManagerImpl::SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1245
{
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1246
  NS_LOG_FUNCTION_NOARGS ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1247
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1248
  NS_ASSERT_MSG (m_spfroot, 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1249
    "GlobalRouteManagerImpl::SPFIntraAddStub (): Root pointer not set");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1250
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1251
  // XXX simplifed logic for the moment.  There are two cases to consider:
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1252
  // 1) the stub network is on this router; do nothing for now
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1253
  //    (already handled above)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1254
  // 2) the stub network is on a remote router, so I should use the
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1255
  // same next hop that I use to get to vertex v
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1256
  if (v->GetVertexId () == m_spfroot->GetVertexId ())
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1257
    {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1258
      NS_LOG_LOGIC ("Stub is on local host: " << v->GetVertexId () << "; returning");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1259
      return;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1260
    }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1261
      NS_LOG_LOGIC ("Stub is on remote host: " << v->GetVertexId () << "; installing");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1262
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1263
// The root of the Shortest Path First tree is the router to which we are 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1264
// going to write the actual routing table entries.  The vertex corresponding
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1265
// to this router has a vertex ID which is the router ID of that node.  We're
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1266
// going to use this ID to discover which node it is that we're actually going
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1267
// to update.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1268
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1269
  Ipv4Address routerId = m_spfroot->GetVertexId ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1270
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1271
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1272
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1273
// We need to walk the list of nodes looking for the one that has the router
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1274
// ID corresponding to the root vertex.  This is the one we're going to write
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1275
// the routing information to.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1276
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1277
  NodeList::Iterator i = NodeList::Begin (); 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1278
  for (; i != NodeList::End (); i++)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1279
    {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1280
      Ptr<Node> node = *i;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1281
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1282
// The router ID is accessible through the GlobalRouter interface, so we need
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1283
// to QI for that interface.  If there's no GlobalRouter interface, the node
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1284
// in question cannot be the router we want, so we continue.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1285
// 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1286
      Ptr<GlobalRouter> rtr = 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1287
        node->GetObject<GlobalRouter> ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1288
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1289
      if (rtr == 0)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1290
        {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1291
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1292
            node->GetId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1293
          continue;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1294
        }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1295
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1296
// If the router ID of the current node is equal to the router ID of the 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1297
// root of the SPF tree, then this node is the one for which we need to 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1298
// write the routing tables.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1299
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1300
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1301
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1302
      if (rtr->GetRouterId () == routerId)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1303
        {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1304
          NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1305
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1306
// Routing information is updated using the Ipv4 interface.  We need to QI
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1307
// for that interface.  If the node is acting as an IP version 4 router, it
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1308
// should absolutely have an Ipv4 interface.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1309
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1310
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1311
          NS_ASSERT_MSG (ipv4, 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1312
            "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1313
            "QI for <Ipv4> interface failed");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1314
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1315
// Get the Global Router Link State Advertisement from the vertex we're
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1316
// adding the routes to.  The LSA will have a number of attached Global Router
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1317
// Link Records corresponding to links off of that vertex / node.  We're going
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1318
// to be interested in the records corresponding to point-to-point links.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1319
//
3969
1db8fca96193 fix optimized build
Tom Henderson <tomh@tomh.org>
parents: 3960
diff changeset
  1320
          NS_ASSERT_MSG (v->GetLSA (), 
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1321
            "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1322
            "Expected valid LSA in SPFVertex* v");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1323
          Ipv4Mask tempmask ("255.255.255.0");
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1324
          Ipv4Address tempip = l->GetLinkId ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1325
          tempip = tempip.CombineMask (tempmask);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1326
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1327
          NS_LOG_LOGIC (" Node " << node->GetId () <<
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1328
            " add route to " << tempip <<
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1329
            " with mask " << tempmask <<
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1330
            " using next hop " << v->GetNextHop () <<
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1331
            " via interface " << v->GetOutgoingInterfaceId ());
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1332
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1333
// Here's why we did all of that work.  We're going to add a host route to the
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1334
// host address found in the m_linkData field of the point-to-point link
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1335
// record.  In the case of a point-to-point link, this is the local IP address
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1336
// of the node connected to the link.  Each of these point-to-point links
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1337
// will correspond to a local interface that has an IP address to which
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1338
// the node at the root of the SPF tree can send packets.  The vertex <v> 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1339
// (corresponding to the node that has these links and interfaces) has 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1340
// an m_nextHop address precalculated for us that is the address to which the
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1341
// root node should send packets to be forwarded to these IP addresses.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1342
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1343
// which the packets should be send for forwarding.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1344
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1345
          Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1346
          NS_ASSERT (gr);
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1347
          gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (), v->GetOutgoingInterfaceId ());
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1348
          return;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1349
        } // if
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1350
    } // for
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1351
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1352
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1353
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1354
// Return the interface index corresponding to a given IP address
1316
f357c6a2bb37 Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents: 1302
diff changeset
  1355
// This is a wrapper around GetIfIndexByIpv4Address(), but we first
f357c6a2bb37 Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents: 1302
diff changeset
  1356
// have to find the right node pointer to pass to that function.
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1357
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1358
  uint32_t
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1359
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1360
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
  1361
  NS_LOG_FUNCTION (a << amask);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1362
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1363
// We have an IP address <a> and a vertex ID of the root of the SPF tree.  
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1364
// The question is what interface index does this address correspond to.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1365
// The answer is a little complicated since we have to find a pointer to
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1366
// the node corresponding to the vertex ID, find the Ipv4 interface on that
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1367
// node in order to iterate the interfaces and find the one corresponding to
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1368
// the address in question.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1369
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1370
  Ipv4Address routerId = m_spfroot->GetVertexId ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1371
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1372
// Walk the list of nodes in the system looking for the one corresponding to
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1373
// the node at the root of the SPF tree.  This is the node for which we are
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1374
// building the routing table.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1375
//
1302
7dd6ea991e80 use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1301
diff changeset
  1376
  NodeList::Iterator i = NodeList::Begin (); 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1377
  for (; i != NodeList::End (); i++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1378
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1379
      Ptr<Node> node = *i;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1380
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1381
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1382
        node->GetObject<GlobalRouter> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1383
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1384
// If the node doesn't have a GlobalRouter interface it can't be the one
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1385
// we're interested in.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1386
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1387
      if (rtr == 0)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1388
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1389
          continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1390
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1391
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1392
      if (rtr->GetRouterId () == routerId)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1393
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1394
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1395
// This is the node we're building the routing table for.  We're going to need
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1396
// the Ipv4 interface to look for the ipv4 interface index.  Since this node
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1397
// is participating in routing IP version 4 packets, it certainly must have 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1398
// an Ipv4 interface.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1399
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1400
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1401
          NS_ASSERT_MSG (ipv4, 
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1402
            "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1403
            "QI for <Ipv4> interface failed");
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1404
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1405
// Look through the interfaces on this node for one that has the IP address
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1406
// we're looking for.  If we find one, return the corresponding interface
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1407
// index.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1408
//
1824
fd6f6604caad move ipv4 static to member functions
Tom Henderson <tomh@tomh.org>
parents: 1776
diff changeset
  1409
          return (ipv4->GetIfIndexByAddress (a, amask) );
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1410
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1411
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1412
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1413
// Couldn't find it.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1414
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1415
  return 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1416
}
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1417
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1418
//
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1419
// This method is derived from quagga ospf_intra_add_router ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1420
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1421
// This is where we are actually going to add the host routes to the routing
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1422
// tables of the individual nodes.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1423
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1424
// The vertex passed as a parameter has just been added to the SPF tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1425
// This vertex must have a valid m_root_oid, corresponding to the outgoing
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1426
// interface on the root router of the tree that is the first hop on the path
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1427
// to the vertex.  The vertex must also have a next hop address, corresponding
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1428
// to the next hop on the path to the vertex.  The vertex has an m_lsa field
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1429
// that has some number of link records.  For each point to point link record,
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1430
// the m_linkData is the local IP address of the link.  This corresponds to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1431
// a destination IP address, reachable from the root, to which we add a host
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1432
// route.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1433
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1434
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1435
GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1436
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
  1437
  NS_LOG_FUNCTION (v);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1438
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1439
  NS_ASSERT_MSG (m_spfroot, 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1440
    "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1441
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1442
// The root of the Shortest Path First tree is the router to which we are 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1443
// going to write the actual routing table entries.  The vertex corresponding
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1444
// to this router has a vertex ID which is the router ID of that node.  We're
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1445
// going to use this ID to discover which node it is that we're actually going
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1446
// to update.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1447
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1448
  Ipv4Address routerId = m_spfroot->GetVertexId ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1449
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1450
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1451
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1452
// We need to walk the list of nodes looking for the one that has the router
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1453
// ID corresponding to the root vertex.  This is the one we're going to write
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1454
// the routing information to.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1455
//
1302
7dd6ea991e80 use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1301
diff changeset
  1456
  NodeList::Iterator i = NodeList::Begin (); 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1457
  for (; i != NodeList::End (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1458
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1459
      Ptr<Node> node = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1460
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1461
// The router ID is accessible through the GlobalRouter interface, so we need
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1462
// to QI for that interface.  If there's no GlobalRouter interface, the node
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1463
// in question cannot be the router we want, so we continue.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1464
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1465
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1466
        node->GetObject<GlobalRouter> ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1467
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1468
      if (rtr == 0)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1469
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1470
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1471
            node->GetId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1472
          continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1473
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1474
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1475
// If the router ID of the current node is equal to the router ID of the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1476
// root of the SPF tree, then this node is the one for which we need to 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1477
// write the routing tables.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1478
//
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1479
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1480
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1481
      if (rtr->GetRouterId () == routerId)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1482
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1483
          NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1484
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1485
// Routing information is updated using the Ipv4 interface.  We need to QI
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1486
// for that interface.  If the node is acting as an IP version 4 router, it
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1487
// should absolutely have an Ipv4 interface.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1488
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1489
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1490
          NS_ASSERT_MSG (ipv4, 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1491
            "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1492
            "QI for <Ipv4> interface failed");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1493
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1494
// Get the Global Router Link State Advertisement from the vertex we're
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1495
// adding the routes to.  The LSA will have a number of attached Global Router
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1496
// Link Records corresponding to links off of that vertex / node.  We're going
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1497
// to be interested in the records corresponding to point-to-point links.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1498
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1499
          GlobalRoutingLSA *lsa = v->GetLSA ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1500
          NS_ASSERT_MSG (lsa, 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1501
            "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1502
            "Expected valid LSA in SPFVertex* v");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1503
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1504
          uint32_t nLinkRecords = lsa->GetNLinkRecords ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1505
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1506
// Iterate through the link records on the vertex to which we're going to add
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1507
// routes.  To make sure we're being clear, we're going to add routing table
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1508
// entries to the tables on the node corresping to the root of the SPF tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1509
// These entries will have routes to the IP addresses we find from looking at
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1510
// the local side of the point-to-point links found on the node described by
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1511
// the vertex <v>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1512
//
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1513
          NS_LOG_LOGIC (" Node " << node->GetId () <<
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1514
             " found " << nLinkRecords << " link records in LSA " << lsa << "with LinkStateId "<< lsa->GetLinkStateId ());
3091
8e720adb2d2c fix bug 183
Craig Dowell <craigdo@ee.washington.edu>
parents: 2983
diff changeset
  1515
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1516
            {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1517
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1518
// We are only concerned about point-to-point links
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1519
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1520
              GlobalRoutingLinkRecord *lr = lsa->GetLinkRecord (j);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1521
              if (lr->GetLinkType () != GlobalRoutingLinkRecord::PointToPoint)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1522
                {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1523
                  continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1524
                }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1525
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1526
              NS_LOG_LOGIC (" Node " << node->GetId () <<
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1527
                " add route to " << lr->GetLinkData () <<
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1528
                " using next hop " << v->GetNextHop () <<
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1529
                " via interface " << v->GetOutgoingInterfaceId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1530
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1531
// Here's why we did all of that work.  We're going to add a host route to the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1532
// host address found in the m_linkData field of the point-to-point link
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1533
// record.  In the case of a point-to-point link, this is the local IP address
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1534
// of the node connected to the link.  Each of these point-to-point links
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1535
// will correspond to a local interface that has an IP address to which
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1536
// the node at the root of the SPF tree can send packets.  The vertex <v> 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1537
// (corresponding to the node that has these links and interfaces) has 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1538
// an m_nextHop address precalculated for us that is the address to which the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1539
// root node should send packets to be forwarded to these IP addresses.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1540
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1541
// which the packets should be send for forwarding.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1542
//
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1543
              Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1544
              NS_ASSERT (gr);
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1545
              gr->AddHostRouteTo (lr->GetLinkData (), v->GetNextHop (),
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1546
                v->GetOutgoingInterfaceId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1547
            }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1548
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1549
// Done adding the routes for the selected node.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1550
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1551
          return;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1552
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1553
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1554
}
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1555
  void
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1556
GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1557
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
  1558
  NS_LOG_FUNCTION (v);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1559
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1560
  NS_ASSERT_MSG (m_spfroot, 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1561
    "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1562
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1563
// The root of the Shortest Path First tree is the router to which we are 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1564
// going to write the actual routing table entries.  The vertex corresponding
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1565
// to this router has a vertex ID which is the router ID of that node.  We're
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1566
// going to use this ID to discover which node it is that we're actually going
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1567
// to update.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1568
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1569
  Ipv4Address routerId = m_spfroot->GetVertexId ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1570
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1571
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1572
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1573
// We need to walk the list of nodes looking for the one that has the router
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1574
// ID corresponding to the root vertex.  This is the one we're going to write
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1575
// the routing information to.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1576
//
1302
7dd6ea991e80 use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1301
diff changeset
  1577
  NodeList::Iterator i = NodeList::Begin (); 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1578
  for (; i != NodeList::End (); i++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1579
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1580
      Ptr<Node> node = *i;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1581
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1582
// The router ID is accessible through the GlobalRouter interface, so we need
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1583
// to QI for that interface.  If there's no GlobalRouter interface, the node
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1584
// in question cannot be the router we want, so we continue.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1585
// 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1586
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1587
        node->GetObject<GlobalRouter> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1588
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1589
      if (rtr == 0)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1590
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1591
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1592
            node->GetId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1593
          continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1594
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1595
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1596
// If the router ID of the current node is equal to the router ID of the 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1597
// root of the SPF tree, then this node is the one for which we need to 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1598
// write the routing tables.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1599
//
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1600
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1601
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1602
      if (rtr->GetRouterId () == routerId)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1603
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1604
          NS_LOG_LOGIC ("setting routes for node " << node->GetId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1605
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1606
// Routing information is updated using the Ipv4 interface.  We need to QI
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1607
// for that interface.  If the node is acting as an IP version 4 router, it
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1608
// should absolutely have an Ipv4 interface.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1609
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1610
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1611
          NS_ASSERT_MSG (ipv4, 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1612
            "GlobalRouteManagerImpl::SPFIntraAddTransit (): "
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1613
            "QI for <Ipv4> interface failed");
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1614
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1615
// Get the Global Router Link State Advertisement from the vertex we're
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1616
// adding the routes to.  The LSA will have a number of attached Global Router
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1617
// Link Records corresponding to links off of that vertex / node.  We're going
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1618
// to be interested in the records corresponding to point-to-point links.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1619
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1620
          GlobalRoutingLSA *lsa = v->GetLSA ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1621
          NS_ASSERT_MSG (lsa, 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1622
            "GlobalRouteManagerImpl::SPFIntraAddTransit (): "
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1623
            "Expected valid LSA in SPFVertex* v");
1279
03ab1b7ad2d0 fix optimized build; remove old comment
Tom Henderson <tomh@tomh.org>
parents: 1278
diff changeset
  1624
          Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
03ab1b7ad2d0 fix optimized build; remove old comment
Tom Henderson <tomh@tomh.org>
parents: 1278
diff changeset
  1625
          Ipv4Address tempip = lsa->GetLinkStateId ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1626
          tempip = tempip.CombineMask (tempmask);
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1627
          Ptr<Ipv4GlobalRouting> gr = GetGlobalRoutingProtocol (node->GetId ());
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1628
          NS_ASSERT (gr);
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1629
          gr->AddNetworkRouteTo (tempip, tempmask, v->GetNextHop (),
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1630
            v->GetOutgoingInterfaceId ());
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1631
          NS_LOG_LOGIC ("Node " << node->GetId () <<
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1632
            " add network route to " << tempip <<
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1633
            " using next hop " << v->GetNextHop () <<
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1634
            " via interface " << v->GetOutgoingInterfaceId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1635
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1636
    } 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1637
}
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1638
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1639
// Derived from quagga ospf_vertex_add_parents ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1640
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1641
// This is a somewhat oddly named method (blame quagga).  Although you might
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1642
// expect it to add a parent *to* something, it actually adds a vertex
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1643
// to the list of children *in* each of its parents. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1644
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1645
// Given a pointer to a vertex, it links back to the vertex's parent that it
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1646
// already has set and adds itself to that vertex's list of children.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1647
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1648
// For now, only one parent (not doing equal-cost multipath)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1649
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1650
  void
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1651
GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1652
{
3946
6a20c485ddb5 document wifi-wired-bridging a little and add aborts if bridged net devices with IP addresses found
Craig Dowell <craigdo@ee.washington.edu>
parents: 3939
diff changeset
  1653
  NS_LOG_FUNCTION (v);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1654
  v->GetParent ()->AddChild (v);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1655
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1656
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1657
  void 
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1658
GlobalRouteManagerImpl::AddGlobalRoutingProtocol (uint32_t nodeId, Ptr<Ipv4GlobalRouting> proto)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1659
{
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1660
  NS_LOG_FUNCTION (nodeId);
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1661
  m_routingProtocols.push_back
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1662
    (std::pair<uint32_t, Ptr<Ipv4GlobalRouting> > (nodeId, proto));
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1663
  m_routingProtocols.sort ();
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1664
}
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1665
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1666
  Ptr<Ipv4GlobalRouting>
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1667
GlobalRouteManagerImpl::GetGlobalRoutingProtocol (uint32_t nodeId)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1668
{
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1669
  for (Ipv4GlobalRoutingList::const_iterator rprotoIter = m_routingProtocols.begin (); rprotoIter != m_routingProtocols.end (); rprotoIter++)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1670
    {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1671
      if ((*rprotoIter).first == nodeId)
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1672
        {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1673
          return (*rprotoIter).second;
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1674
        }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1675
    }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1676
  return 0;
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1677
}
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1678
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  1679
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1680
} // namespace ns3
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1681
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1682
#ifdef RUN_SELF_TESTS
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1683
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1684
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1685
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1686
// Unit Tests
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1687
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1688
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1689
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1690
#include "ns3/test.h"
1200
ae6244482a59 fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1121
diff changeset
  1691
#include "ns3/simulator.h"
3365
6409d2460601 bug 245: build failure with gcc 4.3.x
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3091
diff changeset
  1692
#include <stdlib.h> // for rand ()
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1693
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1694
namespace ns3 {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1695
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1696
class GlobalRouteManagerImplTest : public Test {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1697
public:
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1698
  GlobalRouteManagerImplTest ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1699
  virtual ~GlobalRouteManagerImplTest ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1700
  virtual bool RunTests (void);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1701
};
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1702
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1703
GlobalRouteManagerImplTest::GlobalRouteManagerImplTest ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1704
  : Test ("GlobalRouteManagerImpl")
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1705
{
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1706
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1707
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1708
GlobalRouteManagerImplTest::~GlobalRouteManagerImplTest ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1709
{}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1710
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1711
  bool
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1712
GlobalRouteManagerImplTest::RunTests (void)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1713
{
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1714
  bool ok = true;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1715
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1716
  CandidateQueue candidate;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1717
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1718
  for (int i = 0; i < 100; ++i)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1719
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1720
      SPFVertex *v = new SPFVertex;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1721
      v->SetDistanceFromRoot (rand () % 100);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1722
      candidate.Push (v);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1723
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1724
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1725
  uint32_t lastDistance = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1726
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1727
  for (int i = 0; i < 100; ++i)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1728
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1729
      SPFVertex *v = candidate.Pop ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1730
      if (v->GetDistanceFromRoot () < lastDistance)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1731
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1732
          ok = false;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1733
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1734
      lastDistance = v->GetDistanceFromRoot ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1735
      delete v;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1736
      v = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1737
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1738
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1739
  // Build fake link state database; four routers (0-3), 3 point-to-point
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1740
  // links
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1741
  //
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1742
  //   n0
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1743
  //      \ link 0
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1744
  //       \          link 2
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1745
  //        n2 -------------------------n3
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1746
  //       /
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1747
  //      / link 1
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1748
  //    n1
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1749
  //
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1750
  //  link0:  10.1.1.1/30, 10.1.1.2/30
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1751
  //  link1:  10.1.2.1/30, 10.1.2.2/30
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1752
  //  link2:  10.1.3.1/30, 10.1.3.2/30
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1753
  //
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1754
  // Router 0
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1755
  GlobalRoutingLinkRecord* lr0 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1756
    GlobalRoutingLinkRecord::PointToPoint, 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1757
    "0.0.0.2",  // router ID 0.0.0.2
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1758
    "10.1.1.1", // local ID
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1759
    1);         // metric
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1760
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1761
  GlobalRoutingLinkRecord* lr1 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1762
    GlobalRoutingLinkRecord::StubNetwork,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1763
    "10.1.1.1",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1764
    "255.255.255.252",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1765
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1766
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1767
  GlobalRoutingLSA* lsa0 = new GlobalRoutingLSA ();
1282
d44568322810 cleanup valgrind errors
Tom Henderson <tomh@tomh.org>
parents: 1279
diff changeset
  1768
  lsa0->SetLSType (GlobalRoutingLSA::RouterLSA);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1769
  lsa0->SetLinkStateId ("0.0.0.0");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1770
  lsa0->SetAdvertisingRouter ("0.0.0.0");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1771
  lsa0->AddLinkRecord (lr0);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1772
  lsa0->AddLinkRecord (lr1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1773
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1774
  // Router 1
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1775
  GlobalRoutingLinkRecord* lr2 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1776
    GlobalRoutingLinkRecord::PointToPoint,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1777
    "0.0.0.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1778
    "10.1.2.1",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1779
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1780
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1781
  GlobalRoutingLinkRecord* lr3 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1782
    GlobalRoutingLinkRecord::StubNetwork,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1783
    "10.1.2.1",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1784
    "255.255.255.252",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1785
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1786
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1787
  GlobalRoutingLSA* lsa1 = new GlobalRoutingLSA ();
1282
d44568322810 cleanup valgrind errors
Tom Henderson <tomh@tomh.org>
parents: 1279
diff changeset
  1788
  lsa1->SetLSType (GlobalRoutingLSA::RouterLSA);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1789
  lsa1->SetLinkStateId ("0.0.0.1");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1790
  lsa1->SetAdvertisingRouter ("0.0.0.1");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1791
  lsa1->AddLinkRecord (lr2);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1792
  lsa1->AddLinkRecord (lr3);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1793
  
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1794
  // Router 2 
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1795
  GlobalRoutingLinkRecord* lr4 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1796
    GlobalRoutingLinkRecord::PointToPoint,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1797
    "0.0.0.0",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1798
    "10.1.1.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1799
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1800
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1801
  GlobalRoutingLinkRecord* lr5 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1802
    GlobalRoutingLinkRecord::StubNetwork,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1803
    "10.1.1.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1804
    "255.255.255.252",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1805
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1806
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1807
  GlobalRoutingLinkRecord* lr6 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1808
    GlobalRoutingLinkRecord::PointToPoint,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1809
    "0.0.0.1",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1810
    "10.1.2.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1811
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1812
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1813
  GlobalRoutingLinkRecord* lr7 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1814
    GlobalRoutingLinkRecord::StubNetwork,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1815
    "10.1.2.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1816
    "255.255.255.252",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1817
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1818
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1819
  GlobalRoutingLinkRecord* lr8 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1820
    GlobalRoutingLinkRecord::PointToPoint,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1821
    "0.0.0.3",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1822
    "10.1.3.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1823
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1824
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1825
  GlobalRoutingLinkRecord* lr9 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1826
    GlobalRoutingLinkRecord::StubNetwork,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1827
    "10.1.3.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1828
    "255.255.255.252",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1829
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1830
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1831
  GlobalRoutingLSA* lsa2 = new GlobalRoutingLSA ();
1282
d44568322810 cleanup valgrind errors
Tom Henderson <tomh@tomh.org>
parents: 1279
diff changeset
  1832
  lsa2->SetLSType (GlobalRoutingLSA::RouterLSA);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1833
  lsa2->SetLinkStateId ("0.0.0.2");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1834
  lsa2->SetAdvertisingRouter ("0.0.0.2");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1835
  lsa2->AddLinkRecord (lr4);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1836
  lsa2->AddLinkRecord (lr5);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1837
  lsa2->AddLinkRecord (lr6);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1838
  lsa2->AddLinkRecord (lr7);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1839
  lsa2->AddLinkRecord (lr8);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1840
  lsa2->AddLinkRecord (lr9);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1841
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1842
  // Router 3
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1843
  GlobalRoutingLinkRecord* lr10 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1844
    GlobalRoutingLinkRecord::PointToPoint,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1845
    "0.0.0.2",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1846
    "10.1.2.1",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1847
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1848
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1849
  GlobalRoutingLinkRecord* lr11 = new GlobalRoutingLinkRecord (
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1850
    GlobalRoutingLinkRecord::StubNetwork,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1851
    "10.1.2.1",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1852
    "255.255.255.252",
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1853
    1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1854
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1855
  GlobalRoutingLSA* lsa3 = new GlobalRoutingLSA ();
1282
d44568322810 cleanup valgrind errors
Tom Henderson <tomh@tomh.org>
parents: 1279
diff changeset
  1856
  lsa3->SetLSType (GlobalRoutingLSA::RouterLSA);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1857
  lsa3->SetLinkStateId ("0.0.0.3");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1858
  lsa3->SetAdvertisingRouter ("0.0.0.3");
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1859
  lsa3->AddLinkRecord (lr10);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1860
  lsa3->AddLinkRecord (lr11);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1861
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1862
  // Test the database 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1863
  GlobalRouteManagerLSDB* srmlsdb = new GlobalRouteManagerLSDB ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1864
  srmlsdb->Insert (lsa0->GetLinkStateId (), lsa0);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1865
  srmlsdb->Insert (lsa1->GetLinkStateId (), lsa1);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1866
  srmlsdb->Insert (lsa2->GetLinkStateId (), lsa2);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1867
  srmlsdb->Insert (lsa3->GetLinkStateId (), lsa3);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1868
  NS_ASSERT (lsa2 == srmlsdb->GetLSA (lsa2->GetLinkStateId ()));
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1869
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1870
  // next, calculate routes based on the manually created LSDB
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1871
  GlobalRouteManagerImpl* srm = new GlobalRouteManagerImpl ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1872
  srm->DebugUseLsdb (srmlsdb);  // manually add in an LSDB
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1873
  // Note-- this will succeed without any nodes in the topology
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1874
  // because the NodeList is empty
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1875
  srm->DebugSPFCalculate (lsa0->GetLinkStateId ());  // node n0
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1876
1200
ae6244482a59 fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1121
diff changeset
  1877
  Simulator::Run ();
1316
f357c6a2bb37 Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents: 1302
diff changeset
  1878
f357c6a2bb37 Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents: 1302
diff changeset
  1879
// XXX here we should do some verification of the routes built
f357c6a2bb37 Provide two new Ipv4 convenience functions: GetIfIndexByIpv4Address() and GetIpv4RouteToDestination (), and align global routing code to use the first function
Tom Henderson <tomh@tomh.org>
parents: 1302
diff changeset
  1880
1200
ae6244482a59 fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1121
diff changeset
  1881
  Simulator::Destroy ();
ae6244482a59 fix memory leak
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1121
diff changeset
  1882
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1883
  // This delete clears the srm, which deletes the LSDB, which clears 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1884
  // all of the LSAs, which each destroys the attached LinkRecords.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1885
  delete srm;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1886
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1887
  return ok;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1888
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1889
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1890
// Instantiate this class for the unit tests
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1891
static GlobalRouteManagerImplTest g_globalRouteManagerTest;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1892
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1893
} // namespace ns3
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1894
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1895
#endif