src/internet/model/global-route-manager-impl.cc
author Brian Swenson <bswenson3@gatech.edu>
Tue, 22 Apr 2014 11:52:55 -0400
changeset 10694 4af272d94cfd
parent 10476 8abf67214c5d
child 10968 2d29fee2b7b8
permissions -rw-r--r--
Bug 1791
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>
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    28
#include <algorithm>
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    29
#include <iostream>
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
#include "ns3/assert.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
#include "ns3/fatal-error.h"
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
    32
#include "ns3/log.h"
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#include "ns3/node-list.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
#include "ns3/ipv4.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
    35
#include "ns3/ipv4-routing-protocol.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
    36
#include "ns3/ipv4-list-routing.h"
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 5935
diff changeset
    37
#include "ns3/mpi-interface.h"
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
#include "global-router-interface.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
#include "global-route-manager-impl.h"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
#include "candidate-queue.h"
4527
7a1359808b0e move global routing code into global routing directory
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4476
diff changeset
    41
#include "ipv4-global-routing.h"
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
    43
NS_LOG_COMPONENT_DEFINE ("GlobalRouteManagerImpl");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
namespace ns3 {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
10440
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    47
/**
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    48
 * \brief Stream insertion operator.
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    49
 *
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    50
 * \param os the reference to the output stream
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    51
 * \param exit the exit node
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    52
 * \returns the reference to the output stream
1e48ff9185f1 Bug 938 - missing Doxygen in ns-3 (internet model + helper)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9802
diff changeset
    53
 */
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    54
std::ostream& 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    55
operator<< (std::ostream& os, const SPFVertex::NodeExit_t& exit)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    56
{
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    57
  os << "(" << exit.first << " ," << exit.second << ")";
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    58
  return os;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    59
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    60
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    61
std::ostream& 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    62
operator<< (std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    63
{
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    64
  typedef SPFVertex::ListOfSPFVertex_t::const_iterator CIter_t;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    65
  os << "{";
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    66
  for (CIter_t iter = vs.begin (); iter != vs.end ();)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    67
    {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    68
      os << (*iter)->m_vertexId;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    69
      if (++iter != vs.end ()) 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    70
        {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    71
          os << ", ";
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    72
        }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    73
      else 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    74
        { 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    75
          break;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    76
        }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    77
    }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    78
  os << "}";
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    79
  return os;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    80
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    81
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
// ---------------------------------------------------------------------------
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
// SPFVertex Implementation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
SPFVertex::SPFVertex () : 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
  m_vertexType (VertexUnknown), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
  m_vertexId ("255.255.255.255"), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
  m_lsa (0),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
  m_distanceFromRoot (SPF_INFINITY), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
  m_rootOif (SPF_INFINITY),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
  m_nextHop ("0.0.0.0"),
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
    95
  m_parents (),
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
    96
  m_children (),
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
    97
  m_vertexProcessed (false)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
    99
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   102
SPFVertex::SPFVertex (GlobalRoutingLSA* lsa) : 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
  m_vertexId (lsa->GetLinkStateId ()),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  m_lsa (lsa),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  m_distanceFromRoot (SPF_INFINITY), 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  m_rootOif (SPF_INFINITY),
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  m_nextHop ("0.0.0.0"),
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   108
  m_parents (),
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   109
  m_children (),
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   110
  m_vertexProcessed (false)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   112
  NS_LOG_FUNCTION (this << lsa);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   113
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   114
  if (lsa->GetLSType () == GlobalRoutingLSA::RouterLSA) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   115
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   116
      NS_LOG_LOGIC ("Setting m_vertexType to VertexRouter");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   117
      m_vertexType = SPFVertex::VertexRouter;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   118
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   119
  else if (lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   120
    { 
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   121
      NS_LOG_LOGIC ("Setting m_vertexType to VertexNetwork");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   122
      m_vertexType = SPFVertex::VertexNetwork;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   123
    }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
SPFVertex::~SPFVertex ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   128
  NS_LOG_FUNCTION (this);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   129
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   130
  NS_LOG_LOGIC ("Children vertices - " << m_children);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   131
  NS_LOG_LOGIC ("Parent verteices - " << m_parents);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   132
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   133
  // find this node from all its parents and remove the entry of this node
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   134
  // from all its parents
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   135
  for (ListOfSPFVertex_t::iterator piter = m_parents.begin (); 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   136
       piter != m_parents.end ();
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   137
       piter++)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
    {
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   139
      // remove the current vertex from its parent's children list. Check
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   140
      // if the size of the list is reduced, or the child<->parent relation
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   141
      // is not bidirectional
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   142
      uint32_t orgCount = (*piter)->m_children.size ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   143
      (*piter)->m_children.remove (this);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   144
      uint32_t newCount = (*piter)->m_children.size ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   145
      if (orgCount > newCount)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   146
        {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   147
          NS_ASSERT_MSG (orgCount > newCount, "Unable to find the current vertex from its parents --- impossible!");
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   148
        }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   149
    }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   150
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   151
  // delete children
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   152
  while (m_children.size () > 0)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   153
    {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   154
      // pop out children one by one. Some children may disapper 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   155
      // when deleting some other children in the list. As a result,
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   156
      // it is necessary to use pop to walk through all children, instead
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   157
      // of using iterator.
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   158
      //
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   159
      // Note that m_children.pop_front () is not necessary as this
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   160
      // p is removed from the children list when p is deleted
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   161
      SPFVertex* p = m_children.front ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   162
      // 'p' == 0, this child is already deleted by its other parent
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   163
      if (p == 0) continue;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   164
      NS_LOG_LOGIC ("Parent vertex-" << m_vertexId << " deleting its child vertex-" << p->GetVertexId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
      delete p;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
      p = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
  m_children.clear ();
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   169
  // delete parents
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   170
  m_parents.clear ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   171
  // delete root exit direction
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   172
  m_ecmpRootExits.clear ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   173
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   174
  NS_LOG_LOGIC ("Vertex-" << m_vertexId << " completed deleted");
1111
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
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   177
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
SPFVertex::SetVertexType (SPFVertex::VertexType type)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   180
  NS_LOG_FUNCTION (this << type);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
  m_vertexType = type;
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
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   184
SPFVertex::VertexType
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
SPFVertex::GetVertexType (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   187
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
  return m_vertexType;
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
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   191
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
SPFVertex::SetVertexId (Ipv4Address id)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   194
  NS_LOG_FUNCTION (this << id);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  m_vertexId = id;
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
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   198
Ipv4Address
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
SPFVertex::GetVertexId (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   201
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
  return m_vertexId;
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
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   205
void
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   206
SPFVertex::SetLSA (GlobalRoutingLSA* lsa)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   208
  NS_LOG_FUNCTION (this << lsa);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  m_lsa = lsa;
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
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   212
GlobalRoutingLSA*
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
SPFVertex::GetLSA (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   215
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
  return m_lsa;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   219
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
SPFVertex::SetDistanceFromRoot (uint32_t distance)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   222
  NS_LOG_FUNCTION (this << distance);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
  m_distanceFromRoot = distance;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   226
uint32_t
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
SPFVertex::GetDistanceFromRoot (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   229
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
  return m_distanceFromRoot;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   233
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
SPFVertex::SetParent (SPFVertex* parent)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   236
  NS_LOG_FUNCTION (this << parent);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   237
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   238
  // always maintain only one parent when using setter/getter methods
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   239
  m_parents.clear ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   240
  m_parents.push_back (parent);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   243
SPFVertex*
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   244
SPFVertex::GetParent (uint32_t i) const
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   246
  NS_LOG_FUNCTION (this << i);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   247
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   248
  // If the index i is out-of-range, return 0 and do nothing
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   249
  if (m_parents.size () <= i)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   250
    {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   251
      NS_LOG_LOGIC ("Index to SPFVertex's parent is out-of-range.");
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   252
      return 0;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   253
    }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   254
  ListOfSPFVertex_t::const_iterator iter = m_parents.begin ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   255
  while (i-- > 0) 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   256
    {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   257
      iter++;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   258
    }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   259
  return *iter;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   260
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   261
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   262
void 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   263
SPFVertex::MergeParent (const SPFVertex* v)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   264
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   265
  NS_LOG_FUNCTION (this << v);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   266
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   267
  NS_LOG_LOGIC ("Before merge, list of parents = " << m_parents);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   268
  // combine the two lists first, and then remove any duplicated after
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   269
  m_parents.insert (m_parents.end (), 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   270
                    v->m_parents.begin (), v->m_parents.end ());
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   271
  // remove duplication
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   272
  m_parents.sort ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   273
  m_parents.unique ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   274
  NS_LOG_LOGIC ("After merge, list of parents = " << m_parents);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   275
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   276
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   277
void 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   278
SPFVertex::SetRootExitDirection (Ipv4Address nextHop, int32_t id)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   279
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   280
  NS_LOG_FUNCTION (this << nextHop << id);
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   281
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   282
  // always maintain only one root's exit
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   283
  m_ecmpRootExits.clear ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   284
  m_ecmpRootExits.push_back (NodeExit_t (nextHop, id));
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   285
  // update the following in order to be backward compatitable with
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   286
  // GetNextHop and GetOutgoingInterface methods
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   287
  m_nextHop = nextHop;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   288
  m_rootOif = id;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   289
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   290
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   291
void 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   292
SPFVertex::SetRootExitDirection (SPFVertex::NodeExit_t exit)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   293
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   294
  NS_LOG_FUNCTION (this << exit);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   295
  SetRootExitDirection (exit.first, exit.second);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   298
SPFVertex::NodeExit_t
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   299
SPFVertex::GetRootExitDirection (uint32_t i) const
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   300
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   301
  NS_LOG_FUNCTION (this << i);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   302
  typedef ListOfNodeExit_t::const_iterator CIter_t;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   303
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   304
  NS_ASSERT_MSG (i < m_ecmpRootExits.size (), "Index out-of-range when accessing SPFVertex::m_ecmpRootExits!");
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   305
  CIter_t iter = m_ecmpRootExits.begin ();
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   306
  while (i-- > 0) { iter++; }
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   307
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   308
  return *iter;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   309
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   310
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   311
SPFVertex::NodeExit_t 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   312
SPFVertex::GetRootExitDirection () const
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   313
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   314
  NS_LOG_FUNCTION (this);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   315
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   316
  NS_ASSERT_MSG (m_ecmpRootExits.size () <= 1, "Assumed there is at most one exit from the root to this vertex");
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   317
  return GetRootExitDirection (0);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   318
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   319
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   320
void 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   321
SPFVertex::MergeRootExitDirections (const SPFVertex* vertex)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   322
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   323
  NS_LOG_FUNCTION (this << vertex);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   324
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   325
  // obtain the external list of exit directions
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   326
  //
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   327
  // Append the external list into 'this' and remove duplication afterward
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   328
  const ListOfNodeExit_t& extList = vertex->m_ecmpRootExits;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   329
  m_ecmpRootExits.insert (m_ecmpRootExits.end (), 
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
   330
                          extList.begin (), extList.end ());
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   331
  m_ecmpRootExits.sort ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   332
  m_ecmpRootExits.unique ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   333
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   334
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   335
void 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   336
SPFVertex::InheritAllRootExitDirections (const SPFVertex* vertex)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   337
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   338
  NS_LOG_FUNCTION (this << vertex);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   339
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 6113
diff changeset
   340
  // discard all exit direction currently associated with this vertex,
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   341
  // and copy all the exit directions from the given vertex
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   342
  if (m_ecmpRootExits.size () > 0)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   343
    {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   344
      NS_LOG_WARN ("x root exit directions in this vertex are going to be discarded");
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   345
    }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   346
  m_ecmpRootExits.clear ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   347
  m_ecmpRootExits.insert (m_ecmpRootExits.end (), 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   348
                          vertex->m_ecmpRootExits.begin (), vertex->m_ecmpRootExits.end ());
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   349
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   350
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   351
uint32_t 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   352
SPFVertex::GetNRootExitDirections () const
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   353
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   354
  NS_LOG_FUNCTION (this);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   355
  return m_ecmpRootExits.size ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   356
}
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   357
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   358
uint32_t 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   359
SPFVertex::GetNChildren (void) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   360
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   361
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   362
  return m_children.size ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   363
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   364
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   365
SPFVertex*
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   366
SPFVertex::GetChild (uint32_t n) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   367
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   368
  NS_LOG_FUNCTION (this << n);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   369
  uint32_t j = 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   370
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   371
  for ( ListOfSPFVertex_t::const_iterator i = m_children.begin ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   372
        i != m_children.end ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   373
        i++, j++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   374
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   375
      if (j == n)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   376
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   377
          return *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   378
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   379
    }
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   380
  NS_ASSERT_MSG (false, "Index <n> out of range.");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   381
  return 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   382
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   383
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   384
uint32_t
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   385
SPFVertex::AddChild (SPFVertex* child)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   386
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   387
  NS_LOG_FUNCTION (this << child);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   388
  m_children.push_back (child);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   389
  return m_children.size ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   390
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   391
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   392
void 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   393
SPFVertex::SetVertexProcessed (bool value)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   394
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   395
  NS_LOG_FUNCTION (this << value);
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   396
  m_vertexProcessed = value;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   397
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   398
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   399
bool 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   400
SPFVertex::IsVertexProcessed (void) const
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   401
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   402
  NS_LOG_FUNCTION (this);
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   403
  return m_vertexProcessed;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   404
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   405
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   406
void
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   407
SPFVertex::ClearVertexProcessed (void)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   408
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   409
  NS_LOG_FUNCTION (this);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   410
  for (uint32_t i = 0; i < this->GetNChildren (); i++)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   411
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   412
      this->GetChild (i)->ClearVertexProcessed ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   413
    }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   414
  this->SetVertexProcessed (false);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   415
}
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
   416
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   417
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   418
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   419
// GlobalRouteManagerLSDB Implementation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   420
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   421
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   422
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   423
GlobalRouteManagerLSDB::GlobalRouteManagerLSDB ()
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   424
  :
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   425
    m_database (),
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   426
    m_extdatabase ()
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   427
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   428
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   429
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   430
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   431
GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   432
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   433
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   434
  LSDBMap_t::iterator i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   435
  for (i= m_database.begin (); i!= m_database.end (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   436
    {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   437
      NS_LOG_LOGIC ("free LSA");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   438
      GlobalRoutingLSA* temp = i->second;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   439
      delete temp;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   440
    }
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   441
  for (uint32_t j = 0; j < m_extdatabase.size (); j++)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   442
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   443
      NS_LOG_LOGIC ("free ASexternalLSA");
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   444
      GlobalRoutingLSA* temp = m_extdatabase.at (j);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   445
      delete temp;
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   446
    }
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   447
  NS_LOG_LOGIC ("clear map");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   448
  m_database.clear ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   449
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   450
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   451
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   452
GlobalRouteManagerLSDB::Initialize ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   453
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   454
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   455
  LSDBMap_t::iterator i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   456
  for (i= m_database.begin (); i!= m_database.end (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   457
    {
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   458
      GlobalRoutingLSA* temp = i->second;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   459
      temp->SetStatus (GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   460
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   461
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   462
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   463
void
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   464
GlobalRouteManagerLSDB::Insert (Ipv4Address addr, GlobalRoutingLSA* lsa)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   465
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   466
  NS_LOG_FUNCTION (this << addr << lsa);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   467
  if (lsa->GetLSType () == GlobalRoutingLSA::ASExternalLSAs) 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   468
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   469
      m_extdatabase.push_back (lsa);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   470
    } 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   471
  else
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   472
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   473
      m_database.insert (LSDBPair_t (addr, lsa));
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   474
    }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   475
}
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   476
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   477
GlobalRoutingLSA*
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   478
GlobalRouteManagerLSDB::GetExtLSA (uint32_t index) const
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   479
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   480
  NS_LOG_FUNCTION (this << index);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   481
  return m_extdatabase.at (index);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   482
}
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   483
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   484
uint32_t
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   485
GlobalRouteManagerLSDB::GetNumExtLSAs () const
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   486
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   487
  NS_LOG_FUNCTION (this);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   488
  return m_extdatabase.size ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   489
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   490
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   491
GlobalRoutingLSA*
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   492
GlobalRouteManagerLSDB::GetLSA (Ipv4Address addr) const
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   493
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   494
  NS_LOG_FUNCTION (this << addr);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   495
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   496
// Look up an LSA by its address.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   497
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   498
  LSDBMap_t::const_iterator i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   499
  for (i= m_database.begin (); i!= m_database.end (); i++)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   500
    {
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   501
      if (i->first == addr)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   502
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   503
          return i->second;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   504
        }
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
  return 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   507
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   508
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   509
GlobalRoutingLSA*
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   510
GlobalRouteManagerLSDB::GetLSAByLinkData (Ipv4Address addr) const
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   511
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   512
  NS_LOG_FUNCTION (this << addr);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   513
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   514
// Look up an LSA by its address.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   515
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   516
  LSDBMap_t::const_iterator i;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   517
  for (i= m_database.begin (); i!= m_database.end (); i++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   518
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   519
      GlobalRoutingLSA* temp = i->second;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   520
// Iterate among temp's Link Records
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   521
      for (uint32_t j = 0; j < temp->GetNLinkRecords (); j++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   522
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   523
          GlobalRoutingLinkRecord *lr = temp->GetLinkRecord (j);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   524
          if ( lr->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork &&
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   525
               lr->GetLinkData () == addr)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   526
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   527
              return temp;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   528
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   529
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   530
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   531
  return 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   532
}
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   533
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   534
// ---------------------------------------------------------------------------
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   535
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   536
// GlobalRouteManagerImpl Implementation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   537
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   538
// ---------------------------------------------------------------------------
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
GlobalRouteManagerImpl::GlobalRouteManagerImpl () 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   541
  :
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   542
    m_spfroot (0)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   543
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   544
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   545
  m_lsdb = new GlobalRouteManagerLSDB ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   546
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   547
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   548
GlobalRouteManagerImpl::~GlobalRouteManagerImpl ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   549
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   550
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   551
  if (m_lsdb)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   552
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   553
      delete m_lsdb;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   554
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   555
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   556
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   557
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   558
GlobalRouteManagerImpl::DebugUseLsdb (GlobalRouteManagerLSDB* lsdb)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   559
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   560
  NS_LOG_FUNCTION (this << lsdb);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   561
  if (m_lsdb)
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
      delete m_lsdb;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   564
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   565
  m_lsdb = lsdb;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   566
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   567
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   568
void
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   569
GlobalRouteManagerImpl::DeleteGlobalRoutes ()
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   570
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   571
  NS_LOG_FUNCTION (this);
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
   572
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
   573
  for (NodeList::Iterator i = NodeList::Begin (); i != listEnd; i++)
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   574
    {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   575
      Ptr<Node> node = *i;
4616
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
   576
      Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
   577
      if (router == 0)
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
   578
        {
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
   579
          continue;
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
   580
        }
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
   581
      Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   582
      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
   583
      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
   584
      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
   585
      // 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
   586
      // 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
   587
      // nRoutes times
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   588
      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
   589
        {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   590
          NS_LOG_LOGIC ("Deleting global route " << j << " from node " << node->GetId ());
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   591
          gr->RemoveRoute (0);
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   592
        }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   593
      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
   594
    }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   595
  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
   596
    {
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   597
      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
   598
      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
   599
      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
   600
    }
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   601
}
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
   602
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   603
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   604
// 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
   605
// in the system and look for those that support the GlobalRouter interface.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   606
// These routers will export a number of Link State Advertisements (LSAs)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   607
// 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
   608
// 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
   609
// 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
   610
// ultimately be computed.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   611
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   612
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   613
GlobalRouteManagerImpl::BuildGlobalRoutingDatabase () 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   614
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   615
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   616
//
3939
206f627bd5af factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents: 3937
diff changeset
   617
// 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
   618
// global router interfaces are, not too surprisingly, our routers.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   619
//
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
   620
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
   621
  for (NodeList::Iterator i = NodeList::Begin (); i != listEnd; i++)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   622
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   623
      Ptr<Node> node = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   624
3939
206f627bd5af factor DiscoverLSAs into understandable modules
Craig Dowell <craigdo@ee.washington.edu>
parents: 3937
diff changeset
   625
      Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   626
//
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   627
// Ignore nodes that aren't participating in routing.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   628
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   629
      if (!rtr)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   630
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   631
          continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   632
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   633
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   634
// 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
   635
// update LSAs.  DiscoverLSAs () drives the process of discovering routes in
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   636
// the GlobalRouter.  Afterward, you may use GetNumLSAs (), which is a very
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   637
// computationally inexpensive call.  If you call GetNumLSAs () before calling 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   638
// DiscoverLSAs () will get zero as the number since no routes have been 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   639
// found.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   640
//
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
   641
      Ptr<Ipv4GlobalRouting> grouting = rtr->GetRoutingProtocol ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   642
      uint32_t numLSAs = rtr->DiscoverLSAs ();
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   643
      NS_LOG_LOGIC ("Found " << numLSAs << " LSAs");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   644
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   645
      for (uint32_t j = 0; j < numLSAs; ++j)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   646
        {
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   647
          GlobalRoutingLSA* lsa = new GlobalRoutingLSA ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   648
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   649
// 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
   650
// router.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   651
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   652
          rtr->GetLSA (j, *lsa);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   653
          NS_LOG_LOGIC (*lsa);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   654
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   655
// Write the newly discovered link state advertisement to the database.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   656
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   657
          m_lsdb->Insert (lsa->GetLinkStateId (), lsa); 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   658
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   659
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   660
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   661
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   662
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   663
// 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
   664
// of an aggregated GlobalRouter interface), run the Dijkstra SPF calculation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   665
// on the database rooted at that router, and populate the node forwarding
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   666
// tables.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   667
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   668
// This function parallels RFC2328, Section 16.1.1, and quagga ospfd
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   669
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   670
// This calculation yields the set of intra-area routes associated
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   671
// with an area (called hereafter Area A).  A router calculates the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   672
// shortest-path tree using itself as the root.  The formation
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   673
// 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
   674
// first stage, only links between routers and transit networks are
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   675
// considered.  Using the Dijkstra algorithm, a tree is formed from
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   676
// this subset of the link state database.  In the second stage,
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   677
// leaves are added to the tree by considering the links to stub
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   678
// networks.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   679
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   680
// The area's link state database is represented as a directed graph.
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   681
// The graph's vertices are routers, transit networks and stub networks.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   682
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   683
// The first stage of the procedure (i.e., the Dijkstra algorithm)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   684
// can now be summarized as follows. At each iteration of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   685
// algorithm, there is a list of candidate vertices.  Paths from
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   686
// the root to these vertices have been found, but not necessarily
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   687
// the shortest ones.  However, the paths to the candidate vertex
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   688
// that is closest to the root are guaranteed to be shortest; this
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   689
// vertex is added to the shortest-path tree, removed from the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   690
// candidate list, and its adjacent vertices are examined for
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   691
// possible addition to/modification of the candidate list.  The
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   692
// algorithm then iterates again.  It terminates when the candidate
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   693
// list becomes empty. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   694
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   695
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   696
GlobalRouteManagerImpl::InitializeRoutes ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   697
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   698
  NS_LOG_FUNCTION (this);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   699
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   700
// Walk the list of nodes in the system.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   701
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   702
  NS_LOG_INFO ("About to start SPF calculation");
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
   703
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
   704
  for (NodeList::Iterator i = NodeList::Begin (); i != listEnd; i++)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   705
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   706
      Ptr<Node> node = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   707
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   708
// Look for the GlobalRouter interface that indicates that the node is
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   709
// participating in routing.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   710
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   711
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
   712
        node->GetObject<GlobalRouter> ();
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 5935
diff changeset
   713
10476
8abf67214c5d Null message scheduler
Steven Smith <smith84@llnl.gov>
parents: 10440
diff changeset
   714
      uint32_t systemId = MpiInterface::GetSystemId ();
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 5935
diff changeset
   715
      // Ignore nodes that are not assigned to our systemId (distributed sim)
10476
8abf67214c5d Null message scheduler
Steven Smith <smith84@llnl.gov>
parents: 10440
diff changeset
   716
      if (node->GetSystemId () != systemId) 
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 5935
diff changeset
   717
        {
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 5935
diff changeset
   718
          continue;
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 5935
diff changeset
   719
        }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   720
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   721
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   722
// 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
   723
// algorithms.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   724
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   725
      if (rtr && rtr->GetNumLSAs () )
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   726
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   727
          SPFCalculate (rtr->GetRouterId ());
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   728
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   729
    }
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   730
  NS_LOG_INFO ("Finished SPF calculation");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   731
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   732
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   733
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   734
// This method is derived from quagga ospf_spf_next ().  See RFC2328 Section 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   735
// 16.1 (2) for further details.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   736
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   737
// 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
   738
// 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
   739
// SPF candidate queue, which is a priority queue containing the shortest paths
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   740
// to the networks we know about.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   741
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   742
// 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
   743
// 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
   744
// vertex already on the candidate list, store the new (lower) cost.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   745
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   746
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   747
GlobalRouteManagerImpl::SPFNext (SPFVertex* v, CandidateQueue& candidate)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   748
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   749
  NS_LOG_FUNCTION (this << v << &candidate);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   750
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   751
  SPFVertex* w = 0;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   752
  GlobalRoutingLSA* w_lsa = 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   753
  GlobalRoutingLinkRecord *l = 0;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   754
  uint32_t distance = 0;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   755
  uint32_t numRecordsInVertex = 0;
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   756
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   757
// V points to a Router-LSA or Network-LSA
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   758
// 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
   759
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   760
  if (v->GetVertexType () == SPFVertex::VertexRouter)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   761
    {
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   762
      numRecordsInVertex = v->GetLSA ()->GetNLinkRecords (); 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   763
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   764
  if (v->GetVertexType () == SPFVertex::VertexNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   765
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   766
      numRecordsInVertex = v->GetLSA ()->GetNAttachedRouters (); 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   767
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   768
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   769
  for (uint32_t i = 0; i < numRecordsInVertex; i++)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   770
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   771
// Get w_lsa:  In case of V is Router-LSA
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   772
      if (v->GetVertexType () == SPFVertex::VertexRouter) 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   773
        {
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
   774
          NS_LOG_LOGIC ("Examining link " << i << " of " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   775
                        v->GetVertexId () << "'s " <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   776
                        v->GetLSA ()->GetNLinkRecords () << " link records");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   777
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   778
// (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
   779
// 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
   780
// shortest path calculation.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   781
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   782
          l = v->GetLSA ()->GetLinkRecord (i);
9784
740a983ed25b [Coverity] Unchecked dynamic_cast (FORWARD_NULL)
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 7256
diff changeset
   783
          NS_ASSERT (l != 0);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   784
          if (l->GetLinkType () == GlobalRoutingLinkRecord::StubNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   785
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   786
              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
   787
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   788
            }
1111
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
// (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
   791
// 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
   792
// database. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   793
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   794
          if (l->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   795
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   796
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   797
// 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
   798
// the link state database.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   799
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   800
              w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   801
              NS_ASSERT (w_lsa);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   802
              NS_LOG_LOGIC ("Found a P2P record from " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   803
                            v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
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
          else if (l->GetLinkType () == 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   806
                   GlobalRoutingLinkRecord::TransitNetwork)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   807
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   808
              w_lsa = m_lsdb->GetLSA (l->GetLinkId ());
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   809
              NS_ASSERT (w_lsa);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   810
              NS_LOG_LOGIC ("Found a Transit record from " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   811
                            v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   812
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   813
          else 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   814
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   815
              NS_ASSERT_MSG (0, "illegal Link Type");
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   816
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   817
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   818
// Get w_lsa:  In case of V is Network-LSA
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   819
      if (v->GetVertexType () == SPFVertex::VertexNetwork) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   820
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   821
          w_lsa = m_lsdb->GetLSAByLinkData 
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   822
              (v->GetLSA ()->GetAttachedRouter (i));
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   823
          if (!w_lsa)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   824
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   825
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   826
            }
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   827
          NS_LOG_LOGIC ("Found a Network LSA from " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   828
                        v->GetVertexId () << " to " << w_lsa->GetLinkStateId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   829
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   830
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   831
// 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
   832
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   833
// (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
   834
// link in the LSA.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   835
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   836
// 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
   837
// then we have it covered -- ignore it.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   838
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   839
      if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_IN_SPFTREE) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   840
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   841
          NS_LOG_LOGIC ("Skipping ->  LSA "<< 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   842
                        w_lsa->GetLinkStateId () << " already in SPF tree");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   843
          continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   844
        }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   845
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   846
// (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
   847
// 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
   848
// calculated) shortest path to vertex V and the advertised cost of the link
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   849
// between vertices V and W.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   850
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   851
      if (v->GetLSA ()->GetLSType () == GlobalRoutingLSA::RouterLSA)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   852
        {
9793
bd8de25954e4 [Coverity] Explicit null dereferenced (FORWARD_NULL)
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9784
diff changeset
   853
          NS_ASSERT (l != 0);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   854
          distance = v->GetDistanceFromRoot () + l->GetMetric ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   855
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   856
      else
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   857
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   858
          distance = v->GetDistanceFromRoot ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   859
        }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   860
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   861
      NS_LOG_LOGIC ("Considering w_lsa " << w_lsa->GetLinkStateId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   862
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   863
// Is there already vertex w in candidate list?
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   864
      if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_NOT_EXPLORED)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   865
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   866
// Calculate nexthop to w
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   867
// 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
   868
// 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
   869
// packets destined for this network to, and also find the outbound interface
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   870
// used to forward the packets.
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   871
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   872
// prepare vertex w
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   873
          w = new SPFVertex (w_lsa);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   874
          if (SPFNexthopCalculation (v, w, l, distance))
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   875
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   876
              w_lsa->SetStatus (GlobalRoutingLSA::LSA_SPF_CANDIDATE);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   877
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   878
// 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
   879
// root node).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   880
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   881
              candidate.Push (w);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   882
              NS_LOG_LOGIC ("Pushing " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   883
                            w->GetVertexId () << ", parent vertexId: " <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   884
                            v->GetVertexId () << ", distance: " <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   885
                            w->GetDistanceFromRoot ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   886
            }
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   887
          else
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   888
            NS_ASSERT_MSG (0, "SPFNexthopCalculation never " 
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
   889
                           << "return false, but it does now!");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   890
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   891
      else if (w_lsa->GetStatus () == GlobalRoutingLSA::LSA_SPF_CANDIDATE)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   892
        {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   893
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   894
// 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
   895
// 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
   896
// distance metric.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   897
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   898
// 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
   899
// distance.
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   900
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   901
/* (quagga-0.98.6) W is already on the candidate list; call it cw.
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   902
* Compare the previously calculated cost (cw->distance)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   903
* with the cost we just determined (w->distance) to see
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   904
* if we've found a shorter path.
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   905
*/
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   906
          SPFVertex* cw;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   907
          cw = candidate.Find (w_lsa->GetLinkStateId ());
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   908
          if (cw->GetDistanceFromRoot () < distance)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   909
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   910
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   911
// This is not a shorter path, so don't do anything.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   912
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   913
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   914
            }
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   915
          else if (cw->GetDistanceFromRoot () == distance)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   916
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   917
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   918
// This path is one with an equal cost.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   919
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   920
              NS_LOG_LOGIC ("Equal cost multiple paths found.");
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   921
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   922
// At this point, there are two instances 'w' and 'cw' of the
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   923
// same vertex, the vertex that is currently being considered
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   924
// for adding into the shortest path tree. 'w' is the instance
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   925
// as seen from the root via vertex 'v', and 'cw' is the instance 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   926
// as seen from the root via some other vertices other than 'v'.
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   927
// These two instances are being merged in the following code.
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   928
// In particular, the parent nodes, the next hops, and the root's
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   929
// output interfaces of the two instances are being merged.
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   930
// 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   931
// Note that this is functionally equivalent to calling
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   932
// ospf_nexthop_merge (cw->nexthop, w->nexthop) in quagga-0.98.6
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   933
// (ospf_spf.c::859), although the detail implementation
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   934
// is very different from quagga (blame ns3::GlobalRouteManagerImpl)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   935
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   936
// prepare vertex w
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   937
              w = new SPFVertex (w_lsa);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   938
              SPFNexthopCalculation (v, w, l, distance);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   939
              cw->MergeRootExitDirections (w);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   940
              cw->MergeParent (w);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   941
// SPFVertexAddParent (w) is necessary as the destructor of 
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   942
// SPFVertex checks if the vertex and its parent is linked
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   943
// bidirectionally
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   944
              SPFVertexAddParent (w);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   945
              delete w;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   946
            }
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   947
          else // cw->GetDistanceFromRoot () > w->GetDistanceFromRoot ()
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   948
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   949
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   950
// 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
   951
// 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
   952
// (vertex <v>)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   953
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   954
// 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
   955
// it will call spf_add_parents, which will flush the old parents
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   956
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
   957
              if (SPFNexthopCalculation (v, cw, l, distance))
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   958
                {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   959
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   960
// 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
   961
// must reorder the priority queue keyed to that cost.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   962
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   963
                  candidate.Reorder ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   964
                }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   965
            } // new lower cost path found
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   966
        } // end W is already on the candidate list
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   967
    } // end loop over the links in V's LSA
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   968
}
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
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   971
// 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
   972
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   973
// 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
   974
// with given distance from root->W.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   975
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   976
// As appropriate, set w's parent, distance, and nexthop information
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   977
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   978
// For now, this is greatly simplified from the quagga code
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   979
//
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
   980
int
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   981
GlobalRouteManagerImpl::SPFNexthopCalculation (
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   982
  SPFVertex* v, 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   983
  SPFVertex* w,
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   984
  GlobalRoutingLinkRecord* l,
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   985
  uint32_t distance)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   986
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
   987
  NS_LOG_FUNCTION (this << v << w << l << distance);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
   988
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   989
// If w is a NetworkVertex, l should be null
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   990
/*
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   991
  if (w->GetVertexType () == SPFVertex::VertexNetwork && l)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   992
    {
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
   993
        NS_ASSERT_MSG (0, "Error:  SPFNexthopCalculation parameter problem");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   994
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   995
*/
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
   996
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   997
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   998
// The vertex m_spfroot is a distinguished vertex representing the node at
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   999
// 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
  1000
// calculating the routes.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1001
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1002
// There are two distinct cases for calculating the next hop information.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1003
// 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
  1004
// (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
  1005
// 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
  1006
// 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
  1007
// 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
  1008
// 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
  1009
// diagram below.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1010
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1011
// (1) [root] -> [point-to-point] -> [node 1]
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1012
// (2) [root] -> [point-to-point] -> [node 1] -> [point-to-point] -> [node 2]
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1013
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1014
// 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
  1015
// "inheriting" the next hop information.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1016
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1017
// 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
  1018
// we are examining the root node. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1019
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1020
  if (v == m_spfroot)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1021
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1022
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1023
// 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
  1024
// 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
  1025
// address of packets headed for some arbitrary off-network destination must
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1026
// 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
  1027
// 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
  1028
// is a router.
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 (w->GetVertexType () == SPFVertex::VertexRouter) 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1031
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1032
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1033
// 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
  1034
// 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
  1035
// link record describing the link from the perspecive of <w> (the remote
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1036
// 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
  1037
// 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
  1038
// 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
  1039
// accessed through that path.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1040
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1041
// 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
  1042
// 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
  1043
// SPFGetLink.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1044
//
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
  1045
          NS_ASSERT (l);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1046
          GlobalRoutingLinkRecord *linkRemote = 0;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1047
          linkRemote = SPFGetNextLink (w, v, linkRemote);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1048
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1049
// 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
  1050
// 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
  1051
// is the Global Router Link Record describing that same link from the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1052
// 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
  1053
// address from the m_linkData member variable.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1054
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1055
// 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
  1056
// 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
  1057
// the packet to the next hop address specified in w->m_nextHop.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1058
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1059
          Ipv4Address nextHop = linkRemote->GetLinkData ();
1111
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
// Now find the outgoing interface corresponding to the point to point link
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1062
// from the perspective of <v> -- remember that <l> is the link "from"
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1063
// <v> "to" <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1064
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1065
          uint32_t outIf = FindOutgoingInterfaceId (l->GetLinkData ());
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1066
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1067
          w->SetRootExitDirection (nextHop, outIf);
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
  1068
          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
  1069
          w->SetParent (v);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1070
          NS_LOG_LOGIC ("Next hop from " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1071
                        v->GetVertexId () << " to " << w->GetVertexId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1072
                        " goes through next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1073
                        " via outgoing interface " << outIf <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1074
                        " with distance " << distance);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1075
        }  // end W is a router vertes
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1076
      else 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1077
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1078
          NS_ASSERT (w->GetVertexType () == SPFVertex::VertexNetwork);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1079
// 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
  1080
          GlobalRoutingLSA* w_lsa = w->GetLSA ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1081
          NS_ASSERT (w_lsa->GetLSType () == GlobalRoutingLSA::NetworkLSA);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1082
// Find outgoing interface ID for this network
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1083
          uint32_t outIf = FindOutgoingInterfaceId (w_lsa->GetLinkStateId (), 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1084
                                                    w_lsa->GetNetworkLSANetworkMask () );
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1085
// Set the next hop to 0.0.0.0 meaning "not exist"
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1086
          Ipv4Address nextHop = Ipv4Address::GetZero ();
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1087
          w->SetRootExitDirection (nextHop, outIf);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1088
          w->SetDistanceFromRoot (distance);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1089
          w->SetParent (v);
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1090
          NS_LOG_LOGIC ("Next hop from " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1091
                        v->GetVertexId () << " to network " << w->GetVertexId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1092
                        " via outgoing interface " << outIf <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1093
                        " with distance " << distance);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1094
          return 1;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1095
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1096
    } // end v is the root
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1097
  else if (v->GetVertexType () == SPFVertex::VertexNetwork) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1098
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1099
// See if any of v's parents are the root
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1100
      if (v->GetParent () == m_spfroot)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1101
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1102
// 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
  1103
// directly connects the calculating router to the destination
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1104
// router.  The list of next hops is then determined by
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1105
// examining the destination's router-LSA...
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1106
          NS_ASSERT (w->GetVertexType () == SPFVertex::VertexRouter);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1107
          GlobalRoutingLinkRecord *linkRemote = 0;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1108
          while ((linkRemote = SPFGetNextLink (w, v, linkRemote)))
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1109
            {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1110
/* ...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
  1111
 * 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
  1112
 * address of a next hop router.  The outgoing interface to
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1113
 * 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
  1114
 * it can be inherited from the parent network).
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1115
 */
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1116
              Ipv4Address nextHop = linkRemote->GetLinkData ();
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1117
              uint32_t outIf = v->GetRootExitDirection ().second;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1118
              w->SetRootExitDirection (nextHop, outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1119
              NS_LOG_LOGIC ("Next hop from " <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1120
                            v->GetVertexId () << " to " << w->GetVertexId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1121
                            " goes through next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1122
                            " via outgoing interface " << outIf);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1123
            }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1124
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1125
      else 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1126
        {
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1127
          w->SetRootExitDirection (v->GetRootExitDirection ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1128
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1129
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1130
  else 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1131
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1132
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1133
// 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
  1134
// *not* the root, then we need to "inherit" the information needed to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1135
// 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
  1136
// 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
  1137
// root on the path toward <w>.
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
// Above, when we were considering the root node, we calculated the next hop
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1140
// address and outgoing interface required to get off of the root network.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1141
// 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
  1142
// (shortest) paths.  So the next hop and outoing interface remain the same
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1143
// (are inherited).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1144
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1145
      w->InheritAllRootExitDirections (v);
1111
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
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1148
// 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
  1149
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1150
  w->SetDistanceFromRoot (distance);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1151
  w->SetParent (v);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1152
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1153
  return 1;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1154
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1155
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1156
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1157
// This method is derived from quagga ospf_get_next_link ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1158
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1159
// First search the Global Router Link Records of vertex <v> for one
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1160
// representing a point-to point link to vertex <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1161
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1162
// 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
  1163
// 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
  1164
// 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
  1165
// 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
  1166
// representing a possible *second* link from <v> to <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1167
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1168
GlobalRoutingLinkRecord*
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1169
GlobalRouteManagerImpl::SPFGetNextLink (
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1170
  SPFVertex* v,
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1171
  SPFVertex* w,
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1172
  GlobalRoutingLinkRecord* prev_link) 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1173
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1174
  NS_LOG_FUNCTION (this << v << w << prev_link);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1175
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1176
  bool skip = true;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1177
  bool found_prev_link = false;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1178
  GlobalRoutingLinkRecord* l;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1179
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1180
// 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
  1181
// link.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1182
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1183
  if (prev_link == 0)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1184
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1185
      skip = false;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1186
      found_prev_link = true;
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1187
    }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1188
//
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1189
// Iterate through the Global Router Link Records advertised by the vertex
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1190
// <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
  1191
// vertex.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1192
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1193
  for (uint32_t i = 0; i < v->GetLSA ()->GetNLinkRecords (); ++i)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1194
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1195
      l = v->GetLSA ()->GetLinkRecord (i);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1196
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1197
// 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
  1198
// 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
  1199
// 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
  1200
// 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
  1201
// 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
  1202
// <w>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1203
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1204
      if (l->GetLinkId () == w->GetVertexId ()) 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1205
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1206
          if (!found_prev_link)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1207
            {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1208
              NS_LOG_LOGIC ("Skipping links before prev_link found");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1209
              found_prev_link = true;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1210
              continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1211
            }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1212
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1213
          NS_LOG_LOGIC ("Found matching link l:  linkId = " <<
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1214
                        l->GetLinkId () << " linkData = " << l->GetLinkData ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1215
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1216
// 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
  1217
// 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
  1218
// 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
  1219
// 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
  1220
// one we want).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1221
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1222
          if (skip == false)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1223
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1224
              NS_LOG_LOGIC ("Returning the found link");
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1225
              return l;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1226
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1227
          else
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1228
            {
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1229
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1230
// 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
  1231
// 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
  1232
// record in the LSA from <v>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1233
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1234
              NS_LOG_LOGIC ("Skipping the found link");
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1235
              skip = false;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1236
              continue;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1237
            }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1238
        }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1239
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1240
  return 0;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1241
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1242
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1243
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1244
// Used for unit tests.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1245
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1246
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1247
GlobalRouteManagerImpl::DebugSPFCalculate (Ipv4Address root)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1248
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1249
  NS_LOG_FUNCTION (this << root);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1250
  SPFCalculate (root);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1251
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1252
4628
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1253
//
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1254
// Used to test if a node is a stub, from an OSPF sense.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1255
// If there is only one link of type 1 or 2, then a default route
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1256
// can safely be added to the next-hop router and SPF does not need
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1257
// to be run
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1258
//
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1259
bool
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1260
GlobalRouteManagerImpl::CheckForStubNode (Ipv4Address root)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1261
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1262
  NS_LOG_FUNCTION (this << root);
4628
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1263
  GlobalRoutingLSA *rlsa = m_lsdb->GetLSA (root);
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1264
  Ipv4Address myRouterId = rlsa->GetLinkStateId ();
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1265
  int transits = 0;
4630
b72cd6ed9862 quiet optimizer
Craig Dowell <craigdo@ee.washington.edu>
parents: 4628
diff changeset
  1266
  GlobalRoutingLinkRecord *transitLink = 0;
4628
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1267
  for (uint32_t i = 0; i < rlsa->GetNLinkRecords (); i++)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1268
    {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1269
      GlobalRoutingLinkRecord *l = rlsa->GetLinkRecord (i);
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1270
      if (l->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1271
        {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1272
          transits++;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1273
          transitLink = l;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1274
        }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1275
      else if (l->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1276
        {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1277
          transits++;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1278
          transitLink = l;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1279
        }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1280
    }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1281
  if (transits == 0)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1282
    {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1283
      // This router is not connected to any router.  Probably, global
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1284
      // routing should not be called for this node, but we can just raise
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1285
      // a warning here and return true.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1286
      NS_LOG_WARN ("all nodes should have at least one transit link:" << root );
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1287
      return true;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1288
    }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1289
  if (transits == 1)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1290
    {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1291
      if (transitLink->GetLinkType () == GlobalRoutingLinkRecord::TransitNetwork)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1292
        {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1293
          // Install default route to next hop router
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1294
          // What is the next hop?  We need to check all neighbors on the link.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1295
          // If there is a single router that has two transit links, then
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1296
          // that is the default next hop.  If there are more than one
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1297
          // routers on link with multiple transit links, return false.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1298
          // Not yet implemented, so simply return false
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1299
          NS_LOG_LOGIC ("TBD: Would have inserted default for transit");
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1300
          return false;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1301
        }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1302
      else if (transitLink->GetLinkType () == GlobalRoutingLinkRecord::PointToPoint)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1303
        {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1304
          // Install default route to next hop
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1305
          // The link record LinkID is the router ID of the peer.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1306
          // The Link Data is the local IP interface address
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1307
          GlobalRoutingLSA *w_lsa = m_lsdb->GetLSA (transitLink->GetLinkId ());
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1308
          uint32_t nLinkRecords = w_lsa->GetNLinkRecords ();
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1309
          for (uint32_t j = 0; j < nLinkRecords; ++j)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1310
            {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1311
              //
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1312
              // We are only concerned about point-to-point links
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1313
              //
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1314
              GlobalRoutingLinkRecord *lr = w_lsa->GetLinkRecord (j);
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1315
              if (lr->GetLinkType () != GlobalRoutingLinkRecord::PointToPoint)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1316
                {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1317
                  continue;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1318
                }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1319
              // Find the link record that corresponds to our routerId
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1320
              if (lr->GetLinkId () == myRouterId)
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1321
                {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1322
                  // Next hop is stored in the LinkID field of lr
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1323
                  Ptr<GlobalRouter> router = rlsa->GetNode ()->GetObject<GlobalRouter> ();
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1324
                  NS_ASSERT (router);
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1325
                  Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1326
                  NS_ASSERT (gr);
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1327
                  gr->AddNetworkRouteTo (Ipv4Address ("0.0.0.0"), Ipv4Mask ("0.0.0.0"), lr->GetLinkData (), 
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1328
                                         FindOutgoingInterfaceId (transitLink->GetLinkData ()));
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1329
                  NS_LOG_LOGIC ("Inserting default route for node " << myRouterId << " to next hop " << 
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1330
                                lr->GetLinkData () << " via interface " << 
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1331
                                FindOutgoingInterfaceId (transitLink->GetLinkData ()));
4628
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1332
                  return true;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1333
                }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1334
            }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1335
        }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1336
    }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1337
  return false;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1338
}
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1339
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1340
// quagga ospf_spf_calculate
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1341
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1342
GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1343
{
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
  1344
  NS_LOG_FUNCTION (this << root);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1345
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1346
  SPFVertex *v;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1347
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1348
// Initialize the Link State Database.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1349
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1350
  m_lsdb->Initialize ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1351
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1352
// 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
  1353
// 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
  1354
// of the tree.  Initially, this queue is empty.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1355
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1356
  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
  1357
  NS_ASSERT (candidate.Size () == 0);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1358
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1359
// Initialize the shortest-path tree to only contain the router doing the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1360
// calculation.  Each router (and corresponding network) is a vertex in the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1361
// shortest path first (SPF) tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1362
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1363
  v = new SPFVertex (m_lsdb->GetLSA (root));
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1364
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1365
// 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
  1366
// We also mark this vertex as being in the SPF tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1367
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1368
  m_spfroot= v;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1369
  v->SetDistanceFromRoot (0);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1370
  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
  1371
  NS_LOG_LOGIC ("Starting SPFCalculate for node " << root);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1372
4628
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1373
//
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1374
// Optimize SPF calculation, for ns-3.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1375
// We do not need to calculate SPF for every node in the network if this
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1376
// node has only one interface through which another router can be 
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1377
// reached.  Instead, short-circuit this computation and just install
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1378
// a default route in the CheckForStubNode() method.
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1379
//
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1380
  if (NodeList::GetNNodes () > 0 && CheckForStubNode (root))
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1381
    {
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1382
      NS_LOG_LOGIC ("SPFCalculate truncated for stub node " << root);
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1383
      delete m_spfroot;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1384
      return;
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1385
    }
a5a8c44e4240 bug 521. Ipv4 global routing inefficient. Updated Tom's patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 4616
diff changeset
  1386
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1387
  for (;;)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1388
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1389
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1390
// 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
  1391
// as we go along.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1392
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1393
// RFC2328 16.1. (2). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1394
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1395
// We examine the Global Router Link Records in the Link State 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1396
// Advertisements of the current vertex.  If there are any point-to-point
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1397
// 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
  1398
// 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
  1399
// the new vertices to the candidate queue (the priority queue ordered by
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1400
// shortest path).  If the new vertices represent shorter paths, we use them
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1401
// and update the path cost.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1402
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1403
      SPFNext (v, candidate);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1404
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1405
// RFC2328 16.1. (3). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1406
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1407
// 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
  1408
// transit vertices) has been completely built and this stage of the
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1409
// procedure terminates. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1410
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1411
      if (candidate.Size () == 0)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1412
        {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1413
          break;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1414
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1415
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1416
// 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
  1417
// 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
  1418
// list in the process).
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1419
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1420
// Recall that in the previous step, we created SPFVertex structures for each
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1421
// 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
  1422
// the candidate list.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1423
//
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1424
      NS_LOG_LOGIC (candidate);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1425
      v = candidate.Pop ();
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1426
      NS_LOG_LOGIC ("Popped vertex " << v->GetVertexId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1427
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1428
// 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
  1429
// tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1430
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1431
      v->GetLSA ()->SetStatus (GlobalRoutingLSA::LSA_SPF_IN_SPFTREE);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1432
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1433
// The current vertex has a parent pointer.  By calling this rather oddly 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1434
// 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
  1435
// children of that parent vertex.  In the next hop calculation called during
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1436
// 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
  1437
// to now.
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
      SPFVertexAddParent (v);
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1440
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1441
// 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
  1442
// vertices must be chosen before router vertices in order to necessarily
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1443
// find all equal-cost paths. 
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1444
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1445
// RFC2328 16.1. (4). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1446
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1447
// 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
  1448
// 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
  1449
// 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
  1450
// 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
  1451
// 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
  1452
// tree.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1453
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1454
// 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
  1455
// 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
  1456
// SPFIntraAddRouter ().  Down in SPFIntraAddRouter, we look at all of the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1457
// 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
  1458
// 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
  1459
// 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
  1460
// be the *local* IP address associated with the interface attached to the 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1461
// link.  We use the outbound interface and next hop information present in 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1462
// the vertex <v> which have possibly been inherited from the root.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1463
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1464
// 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
  1465
// 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
  1466
// address (at the <v> side) for each of those links.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1467
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1468
      if (v->GetVertexType () == SPFVertex::VertexRouter)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1469
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1470
          SPFIntraAddRouter (v);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1471
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1472
      else if (v->GetVertexType () == SPFVertex::VertexNetwork)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1473
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1474
          SPFIntraAddTransit (v);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1475
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1476
      else
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1477
        {
3947
756887a9bbea disallow routing on bridge devices with IP address, fix wifi-wired-bridging
Craig Dowell <craigdo@ee.washington.edu>
parents: 3946
diff changeset
  1478
          NS_ASSERT_MSG (0, "illegal SPFVertex type");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1479
        }
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
// RFC2328 16.1. (5). 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1482
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1483
// 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
  1484
// candidate vertices.
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1485
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1486
    }  // end for loop
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1487
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1488
// Second stage of SPF calculation procedure
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1489
  SPFProcessStubs (m_spfroot);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1490
  for (uint32_t i = 0; i < m_lsdb->GetNumExtLSAs (); i++)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1491
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1492
      m_spfroot->ClearVertexProcessed ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1493
      GlobalRoutingLSA *extlsa = m_lsdb->GetExtLSA (i);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1494
      NS_LOG_LOGIC ("Processing External LSA with id " << extlsa->GetLinkStateId ());
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1495
      ProcessASExternals (m_spfroot, extlsa);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1496
    }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1497
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1498
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1499
// 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
  1500
// the SPF tree.  Delete all of the vertices and corresponding resources.  Go
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1501
// possibly do it again for the next router.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1502
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1503
  delete m_spfroot;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1504
  m_spfroot = 0;
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
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1507
void
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1508
GlobalRouteManagerImpl::ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1509
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1510
  NS_LOG_FUNCTION (this << v << extlsa);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1511
  NS_LOG_LOGIC ("Processing external for destination " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1512
                extlsa->GetLinkStateId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1513
                ", for router "  << v->GetVertexId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1514
                ", advertised by " << extlsa->GetAdvertisingRouter ());
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1515
  if (v->GetVertexType () == SPFVertex::VertexRouter)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1516
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1517
      GlobalRoutingLSA *rlsa = v->GetLSA ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1518
      NS_LOG_LOGIC ("Processing router LSA with id " << rlsa->GetLinkStateId ());
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1519
      if ((rlsa->GetLinkStateId ()) == (extlsa->GetAdvertisingRouter ()))
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1520
        {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1521
          NS_LOG_LOGIC ("Found advertising router to destination");
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1522
          SPFAddASExternal (extlsa,v);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1523
        }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1524
    }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1525
  for (uint32_t i = 0; i < v->GetNChildren (); i++)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1526
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1527
      if (!v->GetChild (i)->IsVertexProcessed ())
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1528
        {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1529
          NS_LOG_LOGIC ("Vertex's child " << i << " not yet processed, processing...");
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1530
          ProcessASExternals (v->GetChild (i), extlsa);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1531
          v->GetChild (i)->SetVertexProcessed (true);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1532
        }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1533
    }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1534
}
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1535
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1536
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1537
// Adding external routes to routing table - modeled after
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1538
// SPFAddIntraAddStub()
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1539
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1540
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1541
void
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1542
GlobalRouteManagerImpl::SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1543
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1544
  NS_LOG_FUNCTION (this << extlsa << v);
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1545
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1546
  NS_ASSERT_MSG (m_spfroot, "GlobalRouteManagerImpl::SPFAddASExternal (): Root pointer not set");
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1547
// Two cases to consider: We are advertising the external ourselves
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1548
// => No need to add anything
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1549
// OR find best path to the advertising router
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1550
  if (v->GetVertexId () == m_spfroot->GetVertexId ())
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1551
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1552
      NS_LOG_LOGIC ("External is on local host: " 
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
  1553
                    << v->GetVertexId () << "; returning");
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1554
      return;
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1555
    }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1556
  NS_LOG_LOGIC ("External is on remote host: " 
7252
c8200621e252 rerun check-style.py with uncrustify-0.58
Tom Henderson <tomh@tomh.org>
parents: 7176
diff changeset
  1557
                << extlsa->GetAdvertisingRouter () << "; installing");
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1558
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1559
  Ipv4Address routerId = m_spfroot->GetVertexId ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1560
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1561
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1562
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1563
// We need to walk the list of nodes looking for the one that has the router
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1564
// ID corresponding to the root vertex.  This is the one we're going to write
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1565
// the routing information to.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1566
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1567
  NodeList::Iterator i = NodeList::Begin (); 
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1568
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1569
  for (; i != listEnd; i++)
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1570
    {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1571
      Ptr<Node> node = *i;
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1572
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1573
// The router ID is accessible through the GlobalRouter interface, so we need
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1574
// to QI for that interface.  If there's no GlobalRouter interface, the node
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1575
// in question cannot be the router we want, so we continue.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1576
// 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1577
      Ptr<GlobalRouter> rtr = node->GetObject<GlobalRouter> ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1578
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1579
      if (rtr == 0)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1580
        {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1581
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << node->GetId ());
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1582
          continue;
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1583
        }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1584
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1585
// If the router ID of the current node is equal to the router ID of the 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1586
// root of the SPF tree, then this node is the one for which we need to 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1587
// write the routing tables.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1588
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1589
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1590
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1591
      if (rtr->GetRouterId () == routerId)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1592
        {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1593
          NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1594
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1595
// Routing information is updated using the Ipv4 interface.  We need to QI
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1596
// for that interface.  If the node is acting as an IP version 4 router, it
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1597
// should absolutely have an Ipv4 interface.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1598
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1599
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1600
          NS_ASSERT_MSG (ipv4, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1601
                         "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1602
                         "QI for <Ipv4> interface failed");
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1603
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1604
// Get the Global Router Link State Advertisement from the vertex we're
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1605
// adding the routes to.  The LSA will have a number of attached Global Router
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1606
// Link Records corresponding to links off of that vertex / node.  We're going
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1607
// to be interested in the records corresponding to point-to-point links.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1608
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1609
          NS_ASSERT_MSG (v->GetLSA (), 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1610
                         "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1611
                         "Expected valid LSA in SPFVertex* v");
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1612
          Ipv4Mask tempmask = extlsa->GetNetworkLSANetworkMask ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1613
          Ipv4Address tempip = extlsa->GetLinkStateId ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1614
          tempip = tempip.CombineMask (tempmask);
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1615
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1616
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1617
// Here's why we did all of that work.  We're going to add a host route to the
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1618
// host address found in the m_linkData field of the point-to-point link
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1619
// record.  In the case of a point-to-point link, this is the local IP address
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1620
// of the node connected to the link.  Each of these point-to-point links
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1621
// will correspond to a local interface that has an IP address to which
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1622
// the node at the root of the SPF tree can send packets.  The vertex <v> 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1623
// (corresponding to the node that has these links and interfaces) has 
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1624
// an m_nextHop address precalculated for us that is the address to which the
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1625
// root node should send packets to be forwarded to these IP addresses.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1626
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1627
// which the packets should be send for forwarding.
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1628
//
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1629
          Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1630
          if (router == 0)
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1631
            {
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1632
              continue;
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1633
            }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1634
          Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1635
          NS_ASSERT (gr);
5934
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1636
          // walk through all next-hop-IPs and out-going-interfaces for reaching
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1637
          // the stub network gateway 'v' from the root node
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1638
          for (uint32_t i = 0; i < v->GetNRootExitDirections (); i++)
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1639
            {
5934
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1640
              SPFVertex::NodeExit_t exit = v->GetRootExitDirection (i);
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1641
              Ipv4Address nextHop = exit.first;
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1642
              int32_t outIf = exit.second;
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1643
              if (outIf >= 0)
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1644
                {
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1645
                  gr->AddASExternalRouteTo (tempip, tempmask, nextHop, outIf);
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1646
                  NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1647
                                " add external network route to " << tempip <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1648
                                " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1649
                                " via interface " << outIf);
5934
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1650
                }
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1651
              else
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1652
                {
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1653
                  NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1654
                                " NOT able to add network route to " << tempip <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1655
                                " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1656
                                " since outgoing interface id is negative");
5934
71a3dd5e7a08 [bug 789] Globalrouting externalroutes to use the new GetRootExitDirections()
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5858
diff changeset
  1657
                }
4745
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1658
            }
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1659
          return;
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1660
        } // if
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1661
    } // for
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1662
}
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1663
a0e27af57c8d Allow injection of routes to Ipv4GlobalRouting
Antti Makela <zarhan@cc.hut.fi>
parents: 4630
diff changeset
  1664
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1665
// 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
  1666
// 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
  1667
// 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
  1668
void
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1669
GlobalRouteManagerImpl::SPFProcessStubs (SPFVertex* v)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1670
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1671
  NS_LOG_FUNCTION (this << v);
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1672
  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
  1673
  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
  1674
    {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1675
      GlobalRoutingLSA *rlsa = v->GetLSA ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1676
      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
  1677
      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
  1678
        {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1679
          NS_LOG_LOGIC ("Examining link " << i << " of " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1680
                        v->GetVertexId () << "'s " <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1681
                        v->GetLSA ()->GetNLinkRecords () << " link records");
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1682
          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
  1683
          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
  1684
            {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1685
              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
  1686
              SPFIntraAddStub (l, v);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1687
              continue;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1688
            }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1689
        }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1690
    }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1691
  for (uint32_t i = 0; i < v->GetNChildren (); i++)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1692
    {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1693
      if (!v->GetChild (i)->IsVertexProcessed ())
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1694
        {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1695
          SPFProcessStubs (v->GetChild (i));
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1696
          v->GetChild (i)->SetVertexProcessed (true);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1697
        }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1698
    }
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1699
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1700
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1701
// 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
  1702
void
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1703
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
  1704
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1705
  NS_LOG_FUNCTION (this << l << v);
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1706
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1707
  NS_ASSERT_MSG (m_spfroot, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1708
                 "GlobalRouteManagerImpl::SPFIntraAddStub (): Root pointer not set");
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1709
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1710
  // 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
  1711
  // 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
  1712
  //    (already handled above)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1713
  // 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
  1714
  // 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
  1715
  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
  1716
    {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1717
      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
  1718
      return;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1719
    }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1720
  NS_LOG_LOGIC ("Stub is on remote host: " << v->GetVertexId () << "; installing");
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1721
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1722
// 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
  1723
// 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
  1724
// 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
  1725
// 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
  1726
// to update.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1727
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1728
  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
  1729
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1730
  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
  1731
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1732
// 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
  1733
// 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
  1734
// the routing information to.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1735
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1736
  NodeList::Iterator i = NodeList::Begin (); 
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1737
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1738
  for (; i != listEnd; i++)
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1739
    {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1740
      Ptr<Node> node = *i;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1741
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1742
// 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
  1743
// 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
  1744
// 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
  1745
// 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1746
      Ptr<GlobalRouter> rtr = 
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1747
        node->GetObject<GlobalRouter> ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1748
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1749
      if (rtr == 0)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1750
        {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1751
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1752
                        node->GetId ());
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1753
          continue;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1754
        }
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1755
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1756
// 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
  1757
// 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
  1758
// write the routing tables.
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1759
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1760
      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
  1761
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1762
      if (rtr->GetRouterId () == routerId)
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1763
        {
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1764
          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
  1765
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1766
// 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
  1767
// 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
  1768
// 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
  1769
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1770
          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
  1771
          NS_ASSERT_MSG (ipv4, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1772
                         "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1773
                         "QI for <Ipv4> interface failed");
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1774
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1775
// 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
  1776
// 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
  1777
// 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
  1778
// 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
  1779
//
3969
1db8fca96193 fix optimized build
Tom Henderson <tomh@tomh.org>
parents: 3960
diff changeset
  1780
          NS_ASSERT_MSG (v->GetLSA (), 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1781
                         "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1782
                         "Expected valid LSA in SPFVertex* v");
6297
d58f84b6191b bug in global routing stub computation
Tom Henderson <tomh@tomh.org>
parents: 6273
diff changeset
  1783
          Ipv4Mask tempmask (l->GetLinkData ().Get ());
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1784
          Ipv4Address tempip = l->GetLinkId ();
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1785
          tempip = tempip.CombineMask (tempmask);
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1786
//
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1787
// 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
  1788
// 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
  1789
// 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
  1790
// 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
  1791
// 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
  1792
// 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
  1793
// (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
  1794
// 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
  1795
// 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
  1796
// 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
  1797
// 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
  1798
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1799
4616
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  1800
          Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  1801
          if (router == 0)
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  1802
            {
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  1803
              continue;
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  1804
            }
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  1805
          Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1806
          NS_ASSERT (gr);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1807
          // walk through all next-hop-IPs and out-going-interfaces for reaching
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1808
          // the stub network gateway 'v' from the root node
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1809
          for (uint32_t i = 0; i < v->GetNRootExitDirections (); i++)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1810
            {
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1811
              SPFVertex::NodeExit_t exit = v->GetRootExitDirection (i);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1812
              Ipv4Address nextHop = exit.first;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1813
              int32_t outIf = exit.second;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1814
              if (outIf >= 0)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1815
                {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1816
                  gr->AddNetworkRouteTo (tempip, tempmask, nextHop, outIf);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1817
                  NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1818
                                " add network route to " << tempip <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1819
                                " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1820
                                " via interface " << outIf);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1821
                }
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1822
              else
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1823
                {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1824
                  NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1825
                                " NOT able to add network route to " << tempip <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1826
                                " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1827
                                " since outgoing interface id is negative");
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  1828
                }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1829
            }
3960
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1830
          return;
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1831
        } // if
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1832
    } // for
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1833
}
34908804c029 Add processing logic for stub links in global routing code
Tom Henderson <tomh@tomh.org>
parents: 3959
diff changeset
  1834
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1835
//
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1836
// Return the interface number corresponding to a given IP address and mask
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1837
// This is a wrapper around GetInterfaceForPrefix(), but we first
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
  1838
// have to find the right node pointer to pass to that function.
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1839
// If no such interface is found, return -1 (note:  unit test framework
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1840
// for routing assumes -1 to be a legal return value)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1841
//
4476
4763b00ff02f fix build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
  1842
int32_t
4297
d8501bae8be1 Fix a previous regexp substitution that went too far
Tom Henderson <tomh@tomh.org>
parents: 3969
diff changeset
  1843
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1844
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1845
  NS_LOG_FUNCTION (this << a << amask);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1846
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1847
// We have an IP address <a> and a vertex ID of the root of the SPF tree.
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1848
// 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
  1849
// 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
  1850
// 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
  1851
// 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
  1852
// the address in question.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1853
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1854
  Ipv4Address routerId = m_spfroot->GetVertexId ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1855
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1856
// 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
  1857
// 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
  1858
// building the routing table.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1859
//
1302
7dd6ea991e80 use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1301
diff changeset
  1860
  NodeList::Iterator i = NodeList::Begin (); 
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1861
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1862
  for (; i != listEnd; i++)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1863
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1864
      Ptr<Node> node = *i;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1865
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1866
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1867
        node->GetObject<GlobalRouter> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1868
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1869
// 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
  1870
// we're interested in.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1871
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1872
      if (rtr == 0)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1873
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1874
          continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1875
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1876
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1877
      if (rtr->GetRouterId () == routerId)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1878
        {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1879
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1880
// 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
  1881
// 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
  1882
// 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
  1883
// an Ipv4 interface.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1884
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1885
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1886
          NS_ASSERT_MSG (ipv4, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1887
                         "GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1888
                         "GetObject for <Ipv4> interface failed");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1889
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1890
// 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
  1891
// we're looking for.  If we find one, return the corresponding interface
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1892
// index, or -1 if not found.
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1893
//
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1894
          int32_t interface = ipv4->GetInterfaceForPrefix (a, amask);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1895
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1896
#if 0
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1897
          if (interface < 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1898
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1899
              NS_FATAL_ERROR ("GlobalRouteManagerImpl::FindOutgoingInterfaceId(): "
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1900
                              "Expected an interface associated with address a:" << a);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1901
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1902
#endif 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1903
          return interface;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1904
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1905
    }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1906
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1907
// Couldn't find it.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1908
//
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1909
  NS_LOG_LOGIC ("FindOutgoingInterfaceId():Can't find root node " << routerId);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1910
  return -1;
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1911
}
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1912
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1913
//
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1914
// This method is derived from quagga ospf_intra_add_router ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1915
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1916
// 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
  1917
// tables of the individual nodes.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1918
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1919
// 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
  1920
// 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
  1921
// 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
  1922
// 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
  1923
// 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
  1924
// 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
  1925
// 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
  1926
// 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
  1927
// route.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1928
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1929
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1930
GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1931
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  1932
  NS_LOG_FUNCTION (this << v);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1933
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1934
  NS_ASSERT_MSG (m_spfroot, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1935
                 "GlobalRouteManagerImpl::SPFIntraAddRouter (): Root pointer not set");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1936
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1937
// 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
  1938
// going to write the actual routing table entries.  The vertex corresponding
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1939
// 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
  1940
// 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
  1941
// to update.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1942
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1943
  Ipv4Address routerId = m_spfroot->GetVertexId ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1944
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1945
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1946
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1947
// 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
  1948
// 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
  1949
// the routing information to.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1950
//
1302
7dd6ea991e80 use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1301
diff changeset
  1951
  NodeList::Iterator i = NodeList::Begin (); 
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1952
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  1953
  for (; i != listEnd; i++)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1954
    {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1955
      Ptr<Node> node = *i;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1956
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1957
// The router ID is accessible through the GlobalRouter interface, so we need
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1958
// to GetObject for that interface.  If there's no GlobalRouter interface, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1959
// the node in question cannot be the router we want, so we continue.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1960
// 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1961
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1962
        node->GetObject<GlobalRouter> ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1963
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1964
      if (rtr == 0)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1965
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1966
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1967
                        node->GetId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1968
          continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1969
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1970
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1971
// 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
  1972
// 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
  1973
// write the routing tables.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1974
//
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1975
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1976
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1977
      if (rtr->GetRouterId () == routerId)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1978
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  1979
          NS_LOG_LOGIC ("Setting routes for node " << node->GetId ());
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1980
//
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1981
// Routing information is updated using the Ipv4 interface.  We need to 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1982
// GetObject for that interface.  If the node is acting as an IP version 4 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  1983
// router, it should absolutely have an Ipv4 interface.
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1984
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  1985
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1986
          NS_ASSERT_MSG (ipv4, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1987
                         "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1988
                         "GetObject for <Ipv4> interface failed");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1989
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1990
// Get the Global Router Link State Advertisement from the vertex we're
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1991
// 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
  1992
// 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
  1993
// to be interested in the records corresponding to point-to-point links.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1994
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  1995
          GlobalRoutingLSA *lsa = v->GetLSA ();
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1996
          NS_ASSERT_MSG (lsa, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1997
                         "GlobalRouteManagerImpl::SPFIntraAddRouter (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  1998
                         "Expected valid LSA in SPFVertex* v");
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  1999
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2000
          uint32_t nLinkRecords = lsa->GetNLinkRecords ();
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2001
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2002
// 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
  2003
// 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
  2004
// 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
  2005
// 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
  2006
// 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
  2007
// the vertex <v>.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2008
//
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  2009
          NS_LOG_LOGIC (" Node " << node->GetId () <<
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2010
                        " 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
  2011
          for (uint32_t j = 0; j < nLinkRecords; ++j)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2012
            {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2013
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2014
// We are only concerned about point-to-point links
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2015
//
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2016
              GlobalRoutingLinkRecord *lr = lsa->GetLinkRecord (j);
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2017
              if (lr->GetLinkType () != GlobalRoutingLinkRecord::PointToPoint)
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2018
                {
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2019
                  continue;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2020
                }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2021
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2022
// 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
  2023
// 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
  2024
// 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
  2025
// 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
  2026
// 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
  2027
// 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
  2028
// (corresponding to the node that has these links and interfaces) has 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2029
// 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
  2030
// root node should send packets to be forwarded to these IP addresses.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2031
// Similarly, the vertex <v> has an m_rootOif (outbound interface index) to
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2032
// which the packets should be send for forwarding.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2033
//
4616
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2034
              Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2035
              if (router == 0)
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2036
                {
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2037
                  continue;
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2038
                }
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2039
              Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  2040
              NS_ASSERT (gr);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2041
              // walk through all available exit directions due to ECMP,
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2042
              // and add host route for each of the exit direction toward
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2043
              // the vertex 'v'
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2044
              for (uint32_t i = 0; i < v->GetNRootExitDirections (); i++)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2045
                {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2046
                  SPFVertex::NodeExit_t exit = v->GetRootExitDirection (i);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2047
                  Ipv4Address nextHop = exit.first;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2048
                  int32_t outIf = exit.second;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2049
                  if (outIf >= 0)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2050
                    {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2051
                      gr->AddHostRouteTo (lr->GetLinkData (), nextHop,
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2052
                                          outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2053
                      NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2054
                                    " adding host route to " << lr->GetLinkData () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2055
                                    " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2056
                                    " and outgoing interface " << outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2057
                    }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2058
                  else
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2059
                    {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2060
                      NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2061
                                    " NOT able to add host route to " << lr->GetLinkData () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2062
                                    " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2063
                                    " since outgoing interface id is negative " << outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2064
                    }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2065
                } // for all routes from the root the vertex 'v'
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2066
            }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2067
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2068
// Done adding the routes for the selected node.
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2069
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2070
          return;
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2071
        }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2072
    }
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2073
}
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2074
void
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2075
GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2076
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  2077
  NS_LOG_FUNCTION (this << v);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2078
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2079
  NS_ASSERT_MSG (m_spfroot, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2080
                 "GlobalRouteManagerImpl::SPFIntraAddTransit (): Root pointer not set");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2081
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2082
// 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
  2083
// 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
  2084
// 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
  2085
// 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
  2086
// to update.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2087
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2088
  Ipv4Address routerId = m_spfroot->GetVertexId ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2089
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  2090
  NS_LOG_LOGIC ("Vertex ID = " << routerId);
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2091
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2092
// 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
  2093
// 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
  2094
// the routing information to.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2095
//
1302
7dd6ea991e80 use more NodeList::Iterator types
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1301
diff changeset
  2096
  NodeList::Iterator i = NodeList::Begin (); 
4758
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  2097
  NodeList::Iterator listEnd = NodeList::End ();
0f9bcd407aff Don't recompute NodeList::End () at every loop in GlobalRouteManagerImpl
Guillaume Seguin <guillaume.seguin@sophia.inria.fr>
parents: 4745
diff changeset
  2098
  for (; i != listEnd; i++)
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2099
    {
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2100
      Ptr<Node> node = *i;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2101
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2102
// The router ID is accessible through the GlobalRouter interface, so we need
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  2103
// to GetObject for that interface.  If there's no GlobalRouter interface, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  2104
// the node in question cannot be the router we want, so we continue.
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2105
// 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2106
      Ptr<GlobalRouter> rtr = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  2107
        node->GetObject<GlobalRouter> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2108
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2109
      if (rtr == 0)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2110
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  2111
          NS_LOG_LOGIC ("No GlobalRouter interface on node " << 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2112
                        node->GetId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2113
          continue;
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2114
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2115
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2116
// 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
  2117
// 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
  2118
// write the routing tables.
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2119
//
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  2120
      NS_LOG_LOGIC ("Considering router " << rtr->GetRouterId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2121
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2122
      if (rtr->GetRouterId () == routerId)
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2123
        {
1505
286ec92f4113 debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1458
diff changeset
  2124
          NS_LOG_LOGIC ("setting routes for node " << node->GetId ());
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2125
//
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  2126
// Routing information is updated using the Ipv4 interface.  We need to 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  2127
// GetObject for that interface.  If the node is acting as an IP version 4 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  2128
// router, it should absolutely have an Ipv4 interface.
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2129
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2250
diff changeset
  2130
          Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2131
          NS_ASSERT_MSG (ipv4, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2132
                         "GlobalRouteManagerImpl::SPFIntraAddTransit (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2133
                         "GetObject for <Ipv4> interface failed");
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2134
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2135
// 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
  2136
// 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
  2137
// 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
  2138
// 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
  2139
//
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2140
          GlobalRoutingLSA *lsa = v->GetLSA ();
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2141
          NS_ASSERT_MSG (lsa, 
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2142
                         "GlobalRouteManagerImpl::SPFIntraAddTransit (): "
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2143
                         "Expected valid LSA in SPFVertex* v");
1279
03ab1b7ad2d0 fix optimized build; remove old comment
Tom Henderson <tomh@tomh.org>
parents: 1278
diff changeset
  2144
          Ipv4Mask tempmask = lsa->GetNetworkLSANetworkMask ();
03ab1b7ad2d0 fix optimized build; remove old comment
Tom Henderson <tomh@tomh.org>
parents: 1278
diff changeset
  2145
          Ipv4Address tempip = lsa->GetLinkStateId ();
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2146
          tempip = tempip.CombineMask (tempmask);
4616
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2147
          Ptr<GlobalRouter> router = node->GetObject<GlobalRouter> ();
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2148
          if (router == 0)
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2149
            {
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2150
              continue;
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2151
            }
a84f60b6cd12 bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4560
diff changeset
  2152
          Ptr<Ipv4GlobalRouting> gr = router->GetRoutingProtocol ();
3959
ec65107df095 Segregate Ipv4GlobalRouting from Ipv4StaticRouting; add API for deleting and recomputing global routes
Tom Henderson <tomh@tomh.org>
parents: 3947
diff changeset
  2153
          NS_ASSERT (gr);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2154
          // walk through all available exit directions due to ECMP,
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2155
          // and add host route for each of the exit direction toward
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2156
          // the vertex 'v'
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2157
          for (uint32_t i = 0; i < v->GetNRootExitDirections (); i++)
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2158
            {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2159
              SPFVertex::NodeExit_t exit = v->GetRootExitDirection (i);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2160
              Ipv4Address nextHop = exit.first;
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2161
              int32_t outIf = exit.second;
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2162
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2163
              if (outIf >= 0)
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2164
                {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2165
                  gr->AddNetworkRouteTo (tempip, tempmask, nextHop, outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2166
                  NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2167
                                " add network route to " << tempip <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2168
                                " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2169
                                " via interface " << outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2170
                }
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2171
              else
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2172
                {
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2173
                  NS_LOG_LOGIC ("(Route " << i << ") Node " << node->GetId () <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2174
                                " NOT able to add network route to " << tempip <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2175
                                " using next hop " << nextHop <<
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2176
                                " since outgoing interface id is negative " << outIf);
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2177
                }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4372
diff changeset
  2178
            }
1278
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2179
        }
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2180
    } 
41bf67d701a5 global routing csma patch
Tom Henderson <tomh@tomh.org>
parents: 1200
diff changeset
  2181
}
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2182
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2183
// Derived from quagga ospf_vertex_add_parents ()
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2184
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2185
// This is a somewhat oddly named method (blame quagga).  Although you might
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2186
// 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
  2187
// to the list of children *in* each of its parents. 
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2188
//
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2189
// 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
  2190
// 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
  2191
//
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6967
diff changeset
  2192
void
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2193
GlobalRouteManagerImpl::SPFVertexAddParent (SPFVertex* v)
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2194
{
9704
1db7690f8e8f Partially clean up function logging of internet module.
Kristijan Lenković <k.lenkovic@me.com>
parents: 7256
diff changeset
  2195
  NS_LOG_FUNCTION (this << v);
5858
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2196
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2197
  for (uint32_t i=0;;)
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2198
    {
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2199
      SPFVertex* parent;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2200
      // check if all parents of vertex v
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2201
      if ((parent = v->GetParent (i++)) == 0) break;
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2202
      parent->AddChild (v);
afb51c7f34c2 bug 667: Add equal-cost multipath routing (ECMP) to IPv4 global routing
Wilson Thong <wilsonwk@ee.cityu.edu.hk>
parents: 5324
diff changeset
  2203
    }
1111
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2204
}
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2205
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2206
} // namespace ns3
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2207
835cd416a0a8 rename party
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
  2208