src/routing/static-router.cc
author Tom Henderson <tomh@tomh.org>
Tue, 10 Jul 2007 15:03:39 -0700
changeset 1067 704eb2583865
parent 1061 007ef746ec4d
child 1070 fa5ec2180ec4
permissions -rw-r--r--
Iterate link records (16.1(2))
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include "ns3/debug.h"
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    18
#include "ns3/assert.h"
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    19
#include "ns3/channel.h"
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    20
#include "ns3/net-device.h"
1035
258aae8a6007 static routing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1028
diff changeset
    21
#include "ns3/internet-node.h"
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    22
#include "ns3/ipv4.h"
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "static-router.h"
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
NS_DEBUG_COMPONENT_DEFINE ("StaticRouter");
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
namespace ns3 {
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    29
StaticRouterLSA::StaticRouterLSA()
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    30
  : 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    31
  m_linkStateId("0.0.0.0"),
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    32
  m_advertisingRtr("0.0.0.0"),
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    33
  m_linkRecords()
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
    34
{
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
    35
  NS_DEBUG("StaticRouterLSA::StaticRouterLSA ()");
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
    36
}
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    37
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    38
StaticRouterLSA::StaticRouterLSA (StaticRouterLSA& lsa)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    39
  : m_linkStateId(lsa.m_linkStateId), m_advertisingRtr(lsa.m_advertisingRtr)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    40
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    41
  NS_DEBUG("StaticRouterLSA Copy Constructor");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    42
  NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty before copy");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    43
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    44
  for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin ();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    45
        i != lsa.m_linkRecords.end (); 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    46
        i++)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    47
    {
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    48
      StaticRouterLinkRecord *pSrc = *i;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    49
      StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    50
      pDst->m_linkId = pSrc->m_linkId;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    51
      pDst->m_linkData = pSrc->m_linkData;
1067
704eb2583865 Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents: 1061
diff changeset
    52
      pDst->m_linkType = pSrc->m_linkType;
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    53
      m_linkRecords.push_back(pDst);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    54
      pDst = 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    55
    }
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    56
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    57
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    58
  StaticRouterLSA&
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
    59
StaticRouterLSA::operator= (StaticRouterLSA& lsa)
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    60
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    61
  NS_DEBUG("StaticRouterLSA Operator =");
1057
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    62
  NS_ASSERT_MSG(IsEmpty(), "The LSA must be empty before assignment");
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    63
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    64
  m_linkStateId = lsa.m_linkStateId;
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    65
  m_advertisingRtr = lsa.m_advertisingRtr;
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    66
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    67
  for ( ListOfLinkRecords_t::iterator i = lsa.m_linkRecords.begin ();
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    68
        i != lsa.m_linkRecords.end (); 
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    69
        i++)
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    70
    {
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    71
      StaticRouterLinkRecord *pSrc = *i;
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    72
      StaticRouterLinkRecord *pDst = new StaticRouterLinkRecord;
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    73
      pDst->m_linkId = pSrc->m_linkId;
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    74
      pDst->m_linkData = pSrc->m_linkData;
1067
704eb2583865 Iterate link records (16.1(2))
Tom Henderson <tomh@tomh.org>
parents: 1061
diff changeset
    75
      pDst->m_linkType = pSrc->m_linkType;
1057
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    76
      m_linkRecords.push_back(pDst);
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    77
      pDst = 0;
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    78
    }
2620020dc72c first working router
Craig Dowell <craigdo@ee.washington.edu>
parents: 1056
diff changeset
    79
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    80
  return *this;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    81
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    82
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    83
StaticRouterLSA::~StaticRouterLSA()
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
    84
{
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
    85
  NS_DEBUG("StaticRouterLSA::~StaticRouterLSA ()");
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    86
  ClearLinkRecords ();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    87
}
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    88
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    89
  void
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    90
StaticRouterLSA::ClearLinkRecords(void)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    91
{
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    92
  for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin ();
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    93
        i != m_linkRecords.end (); 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    94
        i++)
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    95
    {
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
    96
      NS_DEBUG("StaticRouterLSA::ClearLinkRecords ():  free link record");
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    97
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    98
      StaticRouterLinkRecord *p = *i;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
    99
      delete p;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   100
      p = 0;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   101
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   102
      *i = 0;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   103
    }
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   104
  NS_DEBUG("StaticRouterLSA::ClearLinkRecords():  clear list");
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   105
  m_linkRecords.clear();
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
   106
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
   107
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   108
  uint32_t
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   109
StaticRouterLSA::AddLinkRecord (StaticRouterLinkRecord* lr)
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
   110
{
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   111
  m_linkRecords.push_back (lr);
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   112
  return m_linkRecords.size ();
1045
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
   113
}
c2c43e021fb7 Add ctor/dtor to StaticRouterLSA, add the Add() method to add link records, misc. cleanup
Tom Henderson <tomh@tomh.org>
parents: 1035
diff changeset
   114
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   115
  bool
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   116
StaticRouterLSA::IsEmpty (void)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   117
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   118
  return m_linkRecords.size () == 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   119
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   120
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   121
  void 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   122
StaticRouterLSA::Print (std::ostream &os)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   123
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   124
  os << "m_linkStateId = " << m_linkStateId << std::endl <<
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   125
        "m_advertisingRtr = " << m_advertisingRtr << std::endl;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   126
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   127
  for ( ListOfLinkRecords_t::iterator i = m_linkRecords.begin ();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   128
        i != m_linkRecords.end (); 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   129
        i++)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   130
    {
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   131
      StaticRouterLinkRecord *p = *i;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   132
      os << "----------" << std::endl;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   133
      os << "m_linkId = " << p->m_linkId << std::endl;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   134
      os << "m_linkData = " << p->m_linkData << std::endl;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   135
    }
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   136
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   137
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   138
std::ostream& operator<< (std::ostream& os, StaticRouterLSA& lsa)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   139
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   140
  lsa.Print (os);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   141
  return os;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   142
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   143
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
const InterfaceId StaticRouter::iid = 
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
  MakeInterfaceId ("StaticRouter", Object::iid);
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
1035
258aae8a6007 static routing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1028
diff changeset
   147
StaticRouter::StaticRouter (Ptr<Node> node)
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   148
  : m_node(node), m_LSAs()
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
{
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   150
  NS_DEBUG("StaticRouter::StaticRouter ()");
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
  SetInterfaceId (StaticRouter::iid);
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   152
  m_routerId.Set(RoutingEnvironment::AllocateRouterId());
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
}
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   154
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
StaticRouter::~StaticRouter ()
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
{
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
  NS_DEBUG("StaticRouter::~StaticRouter ()");
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   158
  ClearLSAs();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   159
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   160
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   161
  void
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   162
StaticRouter::ClearLSAs ()
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   163
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   164
  NS_DEBUG("StaticRouter::ClearLSAs ()");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   165
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   166
  for ( ListOfLSAs_t::iterator i = m_LSAs.begin ();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   167
        i != m_LSAs.end (); 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   168
        i++)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   169
    {
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   170
      NS_DEBUG("StaticRouter::ClearLSAs ():  free LSA");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   171
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   172
      StaticRouterLSA *p = *i;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   173
      delete p;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   174
      p = 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   175
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   176
      *i = 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   177
    }
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   178
  NS_DEBUG("StaticRouter::ClearLSAs ():  clear list");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   179
  m_LSAs.clear();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   180
}
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   181
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   182
  Ipv4Address
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   183
  StaticRouter::GetRouterId (void)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   184
{
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   185
  return m_routerId;
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
}
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   188
//
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   189
// Go out and discover any adjacent routers and build the Link State 
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   190
// Advertisements that reflect them and their associated networks.
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   191
// 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   192
  uint32_t 
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   193
StaticRouter::DiscoverLSAs (void)
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   194
{
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   195
  NS_DEBUG("StaticRouter::DiscoverLSAs ()");
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   196
  NS_ASSERT_MSG(m_node, "<Node> interface not set");
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   197
  ClearLSAs ();
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   198
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   199
// We're aggregated to a node.  We need to ask the node for a pointer to its
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   200
// Ipv4 interface.  This is where the information regarding the attached 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   201
// interfaces lives.
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   202
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   203
  Ptr<Ipv4> ipv4Local = m_node->QueryInterface<Ipv4> (Ipv4::iid);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   204
  NS_ASSERT_MSG(ipv4Local, "QI for <Ipv4> interface failed");
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   205
//
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   206
// We need to ask the node for the number of net devices attached. This isn't
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   207
// necessarily equal to the number of links to adjacent nodes (other routers)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   208
// as the number of devices may include those for stub networks (e.g., 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   209
// ethernets, etc.).  So we have to walk through the list of net devices and
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   210
// pay attention to those that are directly connected to another router through
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   211
// a point-to-point channel.
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   212
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   213
  uint32_t numDevices = m_node->GetNDevices();
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   214
  NS_DEBUG("StaticRouter::DiscoverLSAs (): numDevices = " << numDevices);
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   215
//
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   216
// Loop through the devices looking for those connected to a point-to-point
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   217
// channel.
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   218
//
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   219
  for (uint32_t i = 0; i < numDevices; ++i)
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   220
    {
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   221
      Ptr<NetDevice> ndLocal = m_node->GetDevice(i);
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   222
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   223
      if (!ndLocal->IsPointToPoint ())
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   224
        {
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   225
          NS_DEBUG("StaticRouter::DiscoverLSAs (): non-point-to-point device");
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   226
          continue;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   227
        }
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   228
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   229
      NS_DEBUG("StaticRouter::DiscoverLSAs (): Point-to-point device");
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   230
//
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   231
// Now, we have to find the Ipv4 interface whose netdevice is the one we 
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   232
// just found.  This is still the IP on the local side of the channel.  There 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   233
// is a function to do this used down in the guts of the stack, but it's not 
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   234
// exported so we had to whip up an equivalent.
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   235
//
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   236
      uint32_t ifIndexLocal = FindIfIndexForDevice(m_node, ndLocal);
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   237
//
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   238
// Now that we have the Ipv4 interface index, we can get the address and mask
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   239
// we need.
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   240
//
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   241
      Ipv4Address addrLocal = ipv4Local->GetAddress(ifIndexLocal);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   242
      Ipv4Mask maskLocal = ipv4Local->GetNetworkMask(ifIndexLocal);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   243
      NS_DEBUG("Working with local address " << addrLocal);
1052
e10e6bbba40e forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents: 1050
diff changeset
   244
//
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   245
// Now, we're going to walk over to the remote net device on the other end of 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   246
// the point-to-point channel we now know we have.  This is where our adjacent 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   247
// router (to use OSPF lingo) is running.  
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   248
//
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   249
      Ptr<Channel> ch = ndLocal->GetChannel();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   250
      Ptr<NetDevice> ndRemote = GetAdjacent(ndLocal, ch);
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   251
//
1052
e10e6bbba40e forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents: 1050
diff changeset
   252
// The adjacent net device is aggregated to a node.  We need to ask that net 
e10e6bbba40e forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents: 1050
diff changeset
   253
// device for its node, then ask that node for its Ipv4 interface.
e10e6bbba40e forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents: 1050
diff changeset
   254
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   255
      Ptr<Node> nodeRemote = ndRemote->GetNode();
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   256
      Ptr<Ipv4> ipv4Remote = nodeRemote->QueryInterface<Ipv4> (Ipv4::iid);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   257
      NS_ASSERT_MSG(ipv4Remote, "QI for remote <Ipv4> interface failed");
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   258
//
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   259
// Per the OSPF spec, we're going to need the remote router ID, so we might as
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   260
// well get it now.
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   261
//
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   262
      Ptr<StaticRouter> srRemote = 
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   263
        nodeRemote->QueryInterface<StaticRouter> (StaticRouter::iid);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   264
      NS_ASSERT_MSG(srRemote, "QI for remote <StaticRouter> failed");
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   265
      Ipv4Address rtrIdRemote = srRemote->GetRouterId();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   266
      NS_DEBUG("Working with remote router " << rtrIdRemote);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   267
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   268
// Now, just like we did above, we need to get the IP interface index for the 
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   269
// net device on the other end of the point-to-point channel.
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   270
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   271
      uint32_t ifIndexRemote = FindIfIndexForDevice(nodeRemote, ndRemote);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   272
//
1052
e10e6bbba40e forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents: 1050
diff changeset
   273
// Now that we have the Ipv4 interface, we can get the (remote) address and
e10e6bbba40e forgot to remove a header include
Craig Dowell <craigdo@ee.washington.edu>
parents: 1050
diff changeset
   274
// mask we need.
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   275
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   276
      Ipv4Address addrRemote = ipv4Remote->GetAddress(ifIndexRemote);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   277
      Ipv4Mask maskRemote = ipv4Remote->GetNetworkMask(ifIndexRemote);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   278
      NS_DEBUG("Working with remote address " << addrRemote);
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   279
//
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   280
// Now we can fill out the link state advertisement for this link.  There
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   281
// are always two link records; the first is a point-to-point record 
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   282
// describing the link and the second is a stub network record with the 
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   283
// network number.
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   284
//
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   285
      StaticRouterLSA *pLSA = new StaticRouterLSA;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   286
      pLSA->m_linkStateId = m_routerId;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   287
      pLSA->m_advertisingRtr = m_routerId;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   288
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   289
      StaticRouterLinkRecord *plr = new StaticRouterLinkRecord;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   290
      plr->m_linkType = StaticRouterLinkRecord::PointToPoint;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   291
      plr->m_linkId = rtrIdRemote;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   292
      plr->m_linkData = addrLocal;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   293
      pLSA->AddLinkRecord(plr);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   294
      plr = 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   295
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   296
      plr = new StaticRouterLinkRecord;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   297
      plr->m_linkType = StaticRouterLinkRecord::StubNetwork;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   298
      plr->m_linkId = addrRemote;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   299
      plr->m_linkData.Set(maskRemote.GetHostOrder());  // Frown
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   300
      pLSA->AddLinkRecord(plr);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   301
      plr = 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   302
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   303
      m_LSAs.push_back (pLSA);
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   304
      NS_DEBUG(*pLSA);
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   305
    }
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   306
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   307
  return m_LSAs.size ();
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   308
}
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   309
1061
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   310
  uint32_t 
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   311
StaticRouter::GetNumLSAs (void)
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   312
{
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   313
  NS_DEBUG("StaticRouter::GetNumLSAs ()");
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   314
  return m_LSAs.size ();
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   315
}
007ef746ec4d made GetNumLSAs cheap, added DiscoverLSAs as expensive call.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1060
diff changeset
   316
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   317
//
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   318
// Get the nth link state advertisement from this router.
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   319
//
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   320
  bool
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   321
StaticRouter::GetLSA (uint32_t n, StaticRouterLSA &lsa)
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   322
{
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   323
  NS_ASSERT_MSG(lsa.IsEmpty(), "Must pass empty LSA");
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   324
//
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   325
// All of the work was done in GetNumLSAs.  All we have to do here is to
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   326
// walk the list of link state advertisements created there and return the 
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   327
// one the client is interested in.
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   328
//
1056
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   329
  ListOfLSAs_t::iterator i = m_LSAs.begin ();
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   330
  uint32_t j = 0;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   331
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   332
  for (; i != m_LSAs.end (); i++, j++)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   333
    {
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   334
      if (j == n)
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   335
        {
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   336
          StaticRouterLSA *p = *i;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   337
          lsa = *p;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   338
          return true;
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   339
        }
dc7924932154 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1052
diff changeset
   340
    }
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   341
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   342
  return false;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   343
}
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   344
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   345
//
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   346
// Link through the given channel and find the net device that's on the
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   347
// other end.  This only makes sense with a point-to-point channel.
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   348
//
1048
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   349
  Ptr<NetDevice>
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   350
StaticRouter::GetAdjacent(Ptr<NetDevice> nd, Ptr<Channel> ch)
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   351
{
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   352
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   353
// Double-check that channel agrees with device that it's a point-to-point
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   354
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   355
  NS_ASSERT(ch->GetType () == Channel::PointToPoint);
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   356
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   357
  uint32_t nDevices = ch->GetNDevices();
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   358
  NS_ASSERT_MSG(nDevices == 2, 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   359
    "Point to point channel with other than two devices is not expected");
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   360
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   361
// This is a point to point channel with two endpoints.  Get both of them.
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   362
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   363
  Ptr<NetDevice> nd1 = ch->GetDevice(0);
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   364
  Ptr<NetDevice> nd2 = ch->GetDevice(1);
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   365
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   366
// One of the endpoints is going to be "us" -- that is the net device attached
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   367
// to the node on which we're running -- i.e., "nd".  The other endpoint (the
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   368
// one to which we are connected via the channel) is the adjacent router.
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   369
//
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   370
  if (nd1 == nd)
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   371
    {
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   372
      return nd2;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   373
    }
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   374
  else if (nd2 == nd)
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   375
    {
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   376
      return nd1;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   377
    }
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   378
  else
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   379
    {
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   380
      NS_ASSERT_MSG(0, 
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   381
        "Neither channel endpoint thinks it is connected to this net device");
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   382
      return 0;
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   383
    }
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   384
}
9bbf68fe9c09 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1047
diff changeset
   385
1060
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   386
//
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   387
// Given a node and a net device, find the IPV4 interface index that 
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   388
// corresponds to that net device.
78028417caeb doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 1057
diff changeset
   389
//
1050
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   390
  uint32_t
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   391
StaticRouter::FindIfIndexForDevice(Ptr<Node> node, Ptr<NetDevice> nd)
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   392
{
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   393
  Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   394
  NS_ASSERT_MSG(ipv4, "QI for <Ipv4> interface failed");
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   395
  for (uint32_t i = 0; i < ipv4->GetNInterfaces(); ++i )
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   396
    {
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   397
      if (ipv4->GetNetDevice(i) == nd) 
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   398
        {
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   399
          return i;
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   400
        }
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   401
    }
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   402
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   403
  NS_ASSERT_MSG(0, "Cannot find interface for device");
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   404
  return 0;
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   405
}
ff779ca8ccb6 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 1048
diff changeset
   406
1028
56460b160cef beginnings of static routing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   407
} // namespace ns3