src/routing/static-route-manager.cc
author Tom Henderson <tomh@tomh.org>
Tue, 10 Jul 2007 13:40:36 -0700
changeset 1065 4850d9e9badd
parent 1064 25e962f8ac4c
parent 1061 007ef746ec4d
child 1066 f19baa3a0cb5
permissions -rw-r--r--
Branch merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 *
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * GNU General Public License for more details.
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 *
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 */
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
#include <utility>
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
#include <vector>
1062
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    18
#include <queue>
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
#include "ns3/assert.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
#include "ns3/fatal-error.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include "ns3/debug.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/node-list.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "static-router.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "static-route-manager.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
NS_DEBUG_COMPONENT_DEFINE ("StaticRouteManager");
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
namespace ns3 {
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    29
1062
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    30
SPFVertex::SPFVertex () : 
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    31
  m_vertexType(VertexUnknown), 
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    32
  m_vertexId("255.255.255.255"), 
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    33
  m_lsa(0),
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    34
  m_distanceFromRoot(SPF_INFINITY), 
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    35
  m_stat(false)
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    36
{
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    37
}
ea9b7839421d SPFVertex constructor
Tom Henderson <tomh@tomh.org>
parents: 1059
diff changeset
    38
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    39
SPFVertex::~SPFVertex ()
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    40
{
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    41
  delete m_lsa;
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    42
}
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    43
1063
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    44
void
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    45
SPFVertex::Initialize ()
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    46
{
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    47
  m_distanceFromRoot = SPF_INFINITY;
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    48
  m_stat = false;
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    49
  // XXX previous = 0
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    50
}
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    51
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    52
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    53
StaticRouteManagerLSDB::~StaticRouteManagerLSDB()
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    54
{
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
    55
  NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB ()");
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    56
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
    57
  LSDBMap_t::iterator i;
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
    58
  for (i= m_database.begin(); i!= m_database.end(); i++)
1063
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    59
    {
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    60
      NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB():free vertex");
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    61
      SPFVertex* temp = i->second;
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
    62
      delete temp;
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    63
    }
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
    64
  NS_DEBUG("StaticRouteManagerLSDB::~StaticRouteManagerLSDB ():  clear map");
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
    65
  m_database.clear();
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    66
}
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    67
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    68
void
1063
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    69
StaticRouteManagerLSDB::Initialize()
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    70
{
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    71
  NS_DEBUG("StaticRouteManagerLSDB::Initialize ()");
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    72
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    73
  LSDBMap_t::iterator i;
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    74
  for (i= m_database.begin(); i!= m_database.end(); i++)
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    75
    {
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    76
      SPFVertex* temp = i->second;
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    77
      temp->Initialize();
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    78
    }
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    79
}
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    80
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
    81
void
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    82
StaticRouteManagerLSDB::Insert(Ipv4Address addr, SPFVertex* vertex)
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    83
{
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    84
    m_database.insert(LSDBPair_t(addr, vertex));
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    85
}
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    86
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    87
SPFVertex*
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
    88
StaticRouteManagerLSDB::GetVertex (Ipv4Address addr)
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    89
{
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    90
  // Look up an LSA by its address
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    91
  LSDBMap_t::iterator i;
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    92
  for (i= m_database.begin(); i!= m_database.end(); i++)
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    93
  {
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    94
    if (i->first == addr)
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    95
    {
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    96
      return i->second;
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    97
    }
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    98
  }
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
    99
  return 0;
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
   100
}
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   102
StaticRouteManager::StaticRouteManager () 
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
{
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   104
  m_lsdb = new StaticRouteManagerLSDB ();
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
StaticRouteManager::~StaticRouteManager ()
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   108
{
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   109
  if (m_lsdb)
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   110
    delete m_lsdb;
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   111
}
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   112
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   113
void
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   114
StaticRouteManager::DebugUseLsdb (StaticRouteManagerLSDB* lsdb)
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   115
{
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   116
  if (m_lsdb)
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   117
    delete m_lsdb;
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   118
  m_lsdb = lsdb;
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   119
}
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
void
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
StaticRouteManager::BuildStaticRoutingDatabase () 
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
{
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
  // walk list of nodes.  QI for StaticRouter interface.
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  // if node has a StaticRouter interface, grab the LSAs 
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
  // from it and stick them in the LSDB
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  typedef std::vector < Ptr<Node> >::iterator Iterator;
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
  for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++)
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
    {
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
      Ptr<Node> node = *i;
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
      NS_DEBUG_UNCOND ("node="<< node->GetId () );
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1045
diff changeset
   132
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1045
diff changeset
   133
      Ptr<StaticRouter> rtr = 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1045
diff changeset
   134
        node->QueryInterface<StaticRouter> (StaticRouter::iid);
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1045
diff changeset
   135
      NS_ASSERT_MSG(rtr, "QI for <StaticRouter> interface failed");
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1059
diff changeset
   136
//
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1059
diff changeset
   137
// Should call DiscoverLSAs () before trying to use any routing info or to
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1059
diff changeset
   138
// update LSAs.  Subsequently you may use GetNumLSAs().  If you call
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1059
diff changeset
   139
// GetNumLSAs () before calling DiscoverLSAs () will get zero as the number.
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1059
diff changeset
   140
// 
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1059
diff changeset
   141
      uint32_t numLSAs = rtr->DiscoverLSAs();
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   142
      NS_DEBUG_UNCOND ("Found " << numLSAs << " LSAs");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   143
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   144
      for (uint32_t j = 0; j < numLSAs; ++j)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   145
        {
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   146
          StaticRouterLSA lsa;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   147
          rtr->GetLSA(j, lsa);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   148
          NS_DEBUG_UNCOND ("LSA " << j);
1057
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
   149
          NS_DEBUG_UNCOND ("----------------------------");
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
   150
          NS_DEBUG_UNCOND(lsa);
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1055
diff changeset
   151
        }
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
    }
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
  // For each node that is a static router (which can be determined by
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  // the presence of StaticRouter interface), run Dijkstra SPF calculation
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  // on the database rooted at that router, and populate the node
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  // forwarding tables
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   159
  //
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   160
void
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   161
StaticRouteManager::InitializeRoutes ()
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   162
{
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   163
  NS_DEBUG_UNCOND("StaticRouteManager::InitializeRoutes ()");
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   164
//      This function parallels RFC2328, Section 16.1.1, and quagga ospfd
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   165
//
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   166
//      This calculation yields the set of intra-area routes associated
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   167
//      with an area (called hereafter Area A).  A router calculates the
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   168
//      shortest-path tree using itself as the root.  The formation
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   169
//      of the shortest path tree is done here in two stages.  In the
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   170
//      first stage, only links between routers and transit networks are
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   171
//      considered.  Using the Dijkstra algorithm, a tree is formed from
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   172
//      this subset of the link state database.  In the second stage,
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   173
//      leaves are added to the tree by considering the links to stub
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   174
//      networks.
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   175
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   176
//      The area's link state database is represented as a directed graph.  
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   177
//      The graph's vertices are routers, transit networks and stub networks.  
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   178
//      The first stage of the procedure (i.e., the Dijkstra algorithm)
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   179
//      can now be summarized as follows. At each iteration of the
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   180
//      algorithm, there is a list of candidate vertices.  Paths from
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   181
//      the root to these vertices have been found, but not necessarily
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   182
//      the shortest ones.  However, the paths to the candidate vertex
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   183
//      that is closest to the root are guaranteed to be shortest; this
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   184
//      vertex is added to the shortest-path tree, removed from the
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   185
//      candidate list, and its adjacent vertices are examined for
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   186
//      possible addition to/modification of the candidate list.  The
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   187
//      algorithm then iterates again.  It terminates when the candidate
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   188
//      list becomes empty. 
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   189
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   190
    // For each node that is a router in the topology
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   191
  typedef std::vector < Ptr<Node> >::iterator Iterator;
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   192
  for (Iterator i = NodeList::Begin(); i != NodeList::End(); i++)
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   193
    {
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   194
      Ptr<Node> node = *i;
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   195
      NS_DEBUG_UNCOND ("node="<< node->GetId () );
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   196
      
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   197
      Ptr<StaticRouter> rtr = 
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   198
        node->QueryInterface<StaticRouter> (StaticRouter::iid);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   199
      NS_ASSERT_MSG(rtr, "QI for <StaticRouter> interface failed");
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   200
      if (rtr && rtr->GetNumLSAs () )
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   201
        {
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   202
          SPFCalculate(rtr->GetRouterId ());
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   203
        }
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   204
    }
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   207
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   208
// quagga ospf_spf_next
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   209
void
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   210
StaticRouteManager::SPFNext()
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   211
{
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   212
  // if LSA == Router_LSA, examine links
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   213
  // a) if link to stub, skip
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   214
  // b) W is transit
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   215
}
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   216
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   217
// quagga ospf_spf_calculate
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   218
void
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   219
StaticRouteManager::DebugSPFCalculate(Ipv4Address root)
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   220
{
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   221
  SPFCalculate(root);
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   222
}
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   223
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   224
// quagga ospf_spf_calculate
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   225
void
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   226
StaticRouteManager::SPFCalculate(Ipv4Address root)
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   227
{
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   228
  NS_DEBUG("StaticRouteManager::SPFCalculate ()");
1063
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
   229
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
   230
  // The SPFVertex objects may have state from a previous computation
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
   231
  m_lsdb->Initialize();
1064
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   232
  SPFVertex* v;
1063
98fe4e27c65a Initialize LSDB for SPF runs
Tom Henderson <tomh@tomh.org>
parents: 1062
diff changeset
   233
1064
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   234
  // Make a priority queue of int using a vector container
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   235
  //    priority_queue<int, vector<int>, less<int> > pq;
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   236
  //
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   237
  //priority_queue<SPFVertex*> candidate;
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   238
  //
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   239
  // Initialize the shortest-path tree to only the router doing the 
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   240
  // calculation.
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   241
  //
1064
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   242
  v= m_lsdb->GetVertex(root);
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   243
  // Set LSA position to LSA_SPF_IN_SPFTREE. This vertex is the root of the
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   244
  // spanning tree. 
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   245
  v->m_distanceFromRoot = 0;
25e962f8ac4c Initialize SPFCalculate
Tom Henderson <tomh@tomh.org>
parents: 1063
diff changeset
   246
  v->m_stat = true;
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   247
  
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   248
#if 0
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   249
  for (;;)
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   250
    {
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   251
      /* RFC2328 16.1. (2). */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   252
      ospf_spf_next (v, area, candidate);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   253
  
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   254
      /* RFC2328 16.1. (3). */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   255
      /* If at this step the candidate list is empty, the shortest-
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   256
 *          path tree (of transit vertices) has been completely built and
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   257
 *                   this stage of the procedure terminates. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   258
      if (candidate->size == 0)
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   259
        break;
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   260
  
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   261
      /* Otherwise, choose the vertex belonging to the candidate list
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   262
 *          that is closest to the root, and add it to the shortest-path
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   263
 *                   tree (removing it from the candidate list in the
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   264
 *                            process). */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   265
      /* Extract from the candidates the node with the lower key. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   266
      v = (struct vertex *) pqueue_dequeue (candidate);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   267
      /* Update stat field in vertex. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   268
      *(v->stat) = LSA_SPF_IN_SPFTREE;
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   269
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   270
      ospf_vertex_add_parent (v);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   271
      /* Note that when there is a choice of vertices closest to the
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   272
 *          root, network vertices must be chosen before router vertices
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   273
 *                   in order to necessarily find all equal-cost paths. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   274
      /* We don't do this at this moment, we should add the treatment
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   275
 *          above codes. -- kunihiro. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   276
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   277
      /* RFC2328 16.1. (4). */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   278
      if (v->type == OSPF_VERTEX_ROUTER)
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   279
        ospf_intra_add_router (new_rtrs, v, area);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   280
      else
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   281
        ospf_intra_add_transit (new_table, v, area);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   282
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   283
      /* RFC2328 16.1. (5). */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   284
      /* Iterate the algorithm by returning to Step 2. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   285
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   286
    } /* end loop until no more candidate vertices */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   287
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   288
  /* Second stage of SPF calculation procedure's  */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   289
  ospf_spf_process_stubs (area, area->spf, new_table);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   290
  
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   291
  /* Free candidate queue. */
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   292
  pqueue_delete (candidate);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   293
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   294
#endif
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   295
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   296
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   297
}
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   298
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   299
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
} // namespace ns3
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
#ifdef RUN_SELF_TESTS
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
#include "ns3/test.h"
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
namespace ns3 {
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
class StaticRouteManagerTest : public Test {
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
public:
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
  StaticRouteManagerTest ();
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
  virtual ~StaticRouteManagerTest ();
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
  virtual bool RunTests (void);
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
};
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
StaticRouteManagerTest::StaticRouteManagerTest ()
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
  : Test ("StaticRouteManager")
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
{
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
StaticRouteManagerTest::~StaticRouteManagerTest ()
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
{}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
bool
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
StaticRouteManagerTest::RunTests (void)
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
{
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
  bool ok = true;
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   327
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   328
  // Build fake link state database; four routers (0-3), 3 point-to-point
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   329
  // links
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   330
  //
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   331
  //   n0
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   332
  //      \ link 0
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   333
  //       \          link 2
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   334
  //        n2 -------------------------n3
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   335
  //       /
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   336
  //      / link 1
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   337
  //    n1
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   338
  //
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   339
  //  link0:  10.1.1.1/30, 10.1.1.2/30
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   340
  //  link1:  10.1.2.1/30, 10.1.2.2/30
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   341
  //  link2:  10.1.3.1/30, 10.1.3.2/30
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   342
  //
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   343
  // Router 0
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   344
  StaticRouterLinkRecord* lr0 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   345
  lr0->m_linkId.Set(2);  // router ID 0.0.0.2
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   346
  lr0->m_linkData.Set("10.1.1.1");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   347
  lr0->m_linkType = StaticRouterLinkRecord::PointToPoint;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   348
  lr0->m_metric = 1;
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
  StaticRouterLinkRecord* lr1 = new StaticRouterLinkRecord();
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   350
  lr1->m_linkId.Set("10.1.1.1");  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   351
  lr1->m_linkData.Set("255.255.255.252");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   352
  lr1->m_linkType = StaticRouterLinkRecord::StubNetwork;
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
  lr1->m_metric = 1;
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   354
  StaticRouterLSA* lsa0 = new StaticRouterLSA();
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
   355
  lsa0->m_linkStateId.Set("0.0.0.0");
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
   356
  lsa0->m_advertisingRtr.Set("0.0.0.0");
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   357
  lsa0->AddLinkRecord(lr0);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   358
  lsa0->AddLinkRecord(lr1);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   359
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   360
  // Router 1
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   361
  StaticRouterLinkRecord* lr2 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   362
  lr2->m_linkId.Set(2);  // router ID 0.0.0.2
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   363
  lr2->m_linkData.Set("10.1.2.1");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   364
  lr2->m_linkType = StaticRouterLinkRecord::PointToPoint;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   365
  lr2->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   366
  StaticRouterLinkRecord* lr3 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   367
  lr3->m_linkId.Set("10.1.2.1");  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   368
  lr3->m_linkData.Set("255.255.255.252");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   369
  lr3->m_linkType = StaticRouterLinkRecord::StubNetwork;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   370
  lr3->m_metric = 1;
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
  StaticRouterLSA* lsa1 = new StaticRouterLSA();
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
  lsa1->m_linkStateId.Set(1);
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
  lsa1->m_advertisingRtr.Set(1);
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   374
  lsa1->AddLinkRecord(lr2);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   375
  lsa1->AddLinkRecord(lr3);
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   376
  
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   377
  // Router 2 
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   378
  StaticRouterLinkRecord* lr4 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   379
  lr4->m_linkId.Set("0.0.0.0");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   380
  lr4->m_linkData.Set("10.1.1.2");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   381
  lr4->m_linkType = StaticRouterLinkRecord::PointToPoint;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   382
  lr4->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   383
  StaticRouterLinkRecord* lr5 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   384
  lr5->m_linkId.Set("10.1.1.2");  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   385
  lr5->m_linkData.Set("255.255.255.252");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   386
  lr5->m_linkType = StaticRouterLinkRecord::StubNetwork;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   387
  lr5->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   388
  StaticRouterLinkRecord* lr6 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   389
  lr6->m_linkId.Set(1);  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   390
  lr6->m_linkData.Set("10.1.2.2");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   391
  lr6->m_linkType = StaticRouterLinkRecord::PointToPoint;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   392
  lr6->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   393
  StaticRouterLinkRecord* lr7 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   394
  lr7->m_linkId.Set("10.1.2.2");  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   395
  lr7->m_linkData.Set("255.255.255.252");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   396
  lr7->m_linkType = StaticRouterLinkRecord::StubNetwork;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   397
  lr7->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   398
  StaticRouterLinkRecord* lr8 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   399
  lr8->m_linkId.Set(3);  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   400
  lr8->m_linkData.Set("10.1.3.2");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   401
  lr8->m_linkType = StaticRouterLinkRecord::PointToPoint;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   402
  lr8->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   403
  StaticRouterLinkRecord* lr9 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   404
  lr9->m_linkId.Set("10.1.3.2");  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   405
  lr9->m_linkData.Set("255.255.255.252");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   406
  lr9->m_linkType = StaticRouterLinkRecord::StubNetwork;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   407
  lr9->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   408
  StaticRouterLSA* lsa2 = new StaticRouterLSA();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   409
  lsa2->m_linkStateId.Set(2);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   410
  lsa2->m_advertisingRtr.Set(2);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   411
  lsa2->AddLinkRecord(lr4);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   412
  lsa2->AddLinkRecord(lr5);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   413
  lsa2->AddLinkRecord(lr6);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   414
  lsa2->AddLinkRecord(lr7);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   415
  lsa2->AddLinkRecord(lr8);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   416
  lsa2->AddLinkRecord(lr9);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   417
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   418
  // Router 3
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   419
  StaticRouterLinkRecord* lr10 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   420
  lr10->m_linkId.Set(2);  // router ID 0.0.0.2
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   421
  lr10->m_linkData.Set("10.1.2.1");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   422
  lr10->m_linkType = StaticRouterLinkRecord::PointToPoint;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   423
  lr10->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   424
  StaticRouterLinkRecord* lr11 = new StaticRouterLinkRecord();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   425
  lr11->m_linkId.Set("10.1.2.1");  
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   426
  lr11->m_linkData.Set("255.255.255.252");
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   427
  lr11->m_linkType = StaticRouterLinkRecord::StubNetwork;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   428
  lr11->m_metric = 1;
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   429
  StaticRouterLSA* lsa3 = new StaticRouterLSA();
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   430
  lsa3->m_linkStateId.Set(3);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   431
  lsa3->m_advertisingRtr.Set(3);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   432
  lsa3->AddLinkRecord(lr2);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   433
  lsa3->AddLinkRecord(lr3);
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   434
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   435
  // Create four vertices to store these four LSAs
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   436
  SPFVertex* v0 = new SPFVertex ();
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   437
  v0->m_lsa = lsa0;
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   438
  v0->m_vertexType = SPFVertex::VertexRouter;
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   439
  SPFVertex* v1 = new SPFVertex ();
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   440
  v1->m_lsa = lsa1;
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   441
  v0->m_vertexType = SPFVertex::VertexRouter;
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   442
  SPFVertex* v2 = new SPFVertex ();
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   443
  v2->m_lsa = lsa2;
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   444
  v0->m_vertexType = SPFVertex::VertexRouter;
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   445
  SPFVertex* v3 = new SPFVertex ();
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   446
  v3->m_lsa = lsa3;
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   447
  v0->m_vertexType = SPFVertex::VertexRouter;
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   448
  
1053
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
   449
  // Test the database 
57341f5736a7 Add LSDB functions
Tom Henderson <tomh@tomh.org>
parents: 1049
diff changeset
   450
  StaticRouteManagerLSDB* srmlsdb = new StaticRouteManagerLSDB();
1058
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   451
  srmlsdb->Insert(lsa0->m_linkStateId, v0);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   452
  srmlsdb->Insert(lsa1->m_linkStateId, v1);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   453
  srmlsdb->Insert(lsa2->m_linkStateId, v2);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   454
  srmlsdb->Insert(lsa3->m_linkStateId, v3);
de579b1ff195 convert LSDB to class SPFVertex
Tom Henderson <tomh@tomh.org>
parents: 1057
diff changeset
   455
  NS_ASSERT(v2 == srmlsdb->GetVertex(lsa2->m_linkStateId));
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   456
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   457
  // XXX next, calculate routes based on the manually created LSDB
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   458
  StaticRouteManager* srm = new StaticRouteManager();
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   459
  srm->DebugUseLsdb (srmlsdb);
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   460
  srm->DebugSPFCalculate(lsa0->m_linkStateId);  // node n0
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
   461
1059
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   462
  // This delete clears the srm, which deletes the LSDB, which clears 
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   463
  // all of the vertices, which each destroy the matching LSAs, which each
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   464
  // destroys the attached LinkRecords.
2ebd3bb3da3e more plumbing around SPFCalculate()
Tom Henderson <tomh@tomh.org>
parents: 1058
diff changeset
   465
  delete srm;
1049
b572b65faba3 Fill out self-tests example
Tom Henderson <tomh@tomh.org>
parents: 1048
diff changeset
   466
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   467
  return ok;
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
1055
e9580901878f Add LSDB destructor
Tom Henderson <tomh@tomh.org>
parents: 1053
diff changeset
   470
// Instantiate this class for the unit tests
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
static StaticRouteManagerTest g_staticRouteManagerTest;
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
} // namespace ns3
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
#endif