src/routing/static-routing/ipv4-static-routing.cc
author Tom Henderson <tomh@tomh.org>
Sun, 21 Jun 2009 23:32:23 -0700
changeset 4573 01e876191f2e
parent 4571 src/internet-stack/ipv4-static-routing-impl.cc@2c9c600270e0
child 4603 67a0a49c1db4
permissions -rw-r--r--
move list routing and static routing to src/routing directories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
// published by the Free Software Foundation;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
// GNU General Public License for more details.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
// Author: George F. Riley<riley@ece.gatech.edu>
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
//         Gustavo Carneiro <gjc@inescporto.pt>
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include "ns3/log.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/packet.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/node.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "ns3/ipv4-route.h"
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    25
#include "ipv4-static-routing.h"
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    26
#include "ipv4-routing-table-entry.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    28
NS_LOG_COMPONENT_DEFINE ("Ipv4StaticRouting");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
namespace ns3 {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    32
NS_OBJECT_ENSURE_REGISTERED (Ipv4StaticRouting);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
TypeId
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    35
Ipv4StaticRouting::GetTypeId (void)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
{
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    37
  static TypeId tid = TypeId ("ns3::Ipv4StaticRouting")
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    38
    .SetParent<Ipv4RoutingProtocol> ()
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    39
    .AddConstructor<Ipv4StaticRouting> ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
    ;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
  return tid;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    44
Ipv4StaticRouting::Ipv4StaticRouting () 
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
    45
: m_defaultRoute (0), m_ipv4 (0)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    51
Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
                                   Ipv4Address nextHop, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
                                   uint32_t interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
  *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, nextHop, interface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
  m_hostRoutes.push_back (route);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    62
Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
                                   uint32_t interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  *route = Ipv4RoutingTableEntry::CreateHostRouteTo (dest, interface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  m_hostRoutes.push_back (route);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    72
Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
                                      Ipv4Mask networkMask, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
                                      Ipv4Address nextHop, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
                                      uint32_t interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
                                            networkMask,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
                                            nextHop,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
                                            interface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
  m_networkRoutes.push_back (route);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    87
Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
                                      Ipv4Mask networkMask, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
                                      uint32_t interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
                                            networkMask,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
                                            interface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
  m_networkRoutes.push_back (route);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   100
Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
                                    uint32_t interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  *route = Ipv4RoutingTableEntry::CreateDefaultRoute (nextHop, interface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  delete m_defaultRoute;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
  m_defaultRoute = route;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   111
Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin,
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
                                     Ipv4Address group,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
                                     uint32_t inputInterface,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
                                     std::vector<uint32_t> outputInterfaces)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
  Ipv4MulticastRoutingTableEntry *route = new Ipv4MulticastRoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
  *route = Ipv4MulticastRoutingTableEntry::CreateMulticastRoute (origin, group, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
    inputInterface, outputInterfaces);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
  m_multicastRoutes.push_back (route);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
// default multicast routes are stored as a network route
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
// these routes are _not_ consulted in the forwarding process-- only
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
// for originating packets
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   127
Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
  Ipv4Address network = Ipv4Address ("224.0.0.0");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
  Ipv4Mask networkMask = Ipv4Mask ("240.0.0.0");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
                                            networkMask,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
                                            outputInterface);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
  m_networkRoutes.push_back (route);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
uint32_t 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   140
Ipv4StaticRouting::GetNMulticastRoutes (void) const
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  return m_multicastRoutes.size ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
Ipv4MulticastRoutingTableEntry
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   147
Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
  NS_ASSERT_MSG(index < m_multicastRoutes.size (),
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   151
    "Ipv4StaticRouting::GetMulticastRoute ():  Index out of range");
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
  if (index < m_multicastRoutes.size ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
      uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
      for (MulticastRoutesCI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
           i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
           i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
          if (tmp  == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
              return *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
          tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  return 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
bool
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   171
Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin,
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
                                        Ipv4Address group,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
                                        uint32_t inputInterface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
  for (MulticastRoutesI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
       i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
       i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
      Ipv4MulticastRoutingTableEntry *route = *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
      if (origin == route->GetOrigin () &&
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
          group == route->GetGroup () &&
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
          inputInterface == route->GetInputInterface ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
          delete *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
          m_multicastRoutes.erase (i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
          return true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
  return false;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   194
Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
  uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
  for (MulticastRoutesI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
       i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
       i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
      if (tmp  == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
          delete *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
          m_multicastRoutes.erase (i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
          return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
      tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
Ptr<Ipv4Route>
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   213
Ipv4StaticRouting::LookupStatic (Ipv4Address dest)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
  Ptr<Ipv4Route> rtentry = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
  for (HostRoutesCI i = m_hostRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
       i != m_hostRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
       i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
      NS_ASSERT ((*i)->IsHost ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
      if ((*i)->GetDest ().IsEqual (dest)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
          NS_LOG_LOGIC ("Found global host route" << *i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
          Ipv4RoutingTableEntry* route = (*i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
          rtentry = Create<Ipv4Route> ();
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   227
          uint32_t interfaceIdx = route->GetInterface ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
          rtentry->SetDestination (route->GetDest ());
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   229
          rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ()));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
          rtentry->SetGateway (route->GetGateway ());
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   231
          rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
          return rtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
       j++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
      NS_ASSERT ((*j)->IsNetwork ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
      Ipv4Mask mask = (*j)->GetDestNetworkMask ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
      Ipv4Address entry = (*j)->GetDestNetwork ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
      if (mask.IsMatch (dest, entry)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
          NS_LOG_LOGIC ("Found global network route" << *j);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
          Ipv4RoutingTableEntry* route = (*j);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
          rtentry = Create<Ipv4Route> ();
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   247
          uint32_t interfaceIdx = route->GetInterface ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
          rtentry->SetDestination (route->GetDest ());
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   249
          rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ()));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
          rtentry->SetGateway (route->GetGateway ());
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   251
          rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
          return rtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
  if (m_defaultRoute != 0) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
      NS_ASSERT (m_defaultRoute->IsDefault ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
      NS_LOG_LOGIC ("Found global network route" << m_defaultRoute);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
      Ipv4RoutingTableEntry* route = m_defaultRoute;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
      rtentry = Create<Ipv4Route> ();
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   261
      uint32_t interfaceIdx = route->GetInterface ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
      rtentry->SetDestination (route->GetDest ());
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   263
      rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ()));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
      rtentry->SetGateway (route->GetGateway ());
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   265
      rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
      return rtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
  return 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
Ptr<Ipv4MulticastRoute>
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   272
Ipv4StaticRouting::LookupStatic (
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
  Ipv4Address origin, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
  Ipv4Address group,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
  uint32_t    interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
  Ptr<Ipv4MulticastRoute> mrtentry = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
  for (MulticastRoutesI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   281
       i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
       i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
      Ipv4MulticastRoutingTableEntry *route = *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
// We've been passed an origin address, a multicast group address and an 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
// interface index.  We have to decide if the current route in the list is
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
// a match.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
// The first case is the restrictive case where the origin, group and index
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
// matches.  
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
      if (origin == route->GetOrigin () && group == route->GetGroup ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
          // Skipping this case (SSM) for now
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
          NS_LOG_LOGIC ("Found multicast source specific route" << *i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
      if (group == route->GetGroup ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
          if (interface == Ipv4::IF_ANY || 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
              interface == route->GetInputInterface ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
              NS_LOG_LOGIC ("Found multicast route" << *i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
              mrtentry = Create<Ipv4MulticastRoute> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
              mrtentry->SetGroup (route->GetGroup ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
              mrtentry->SetOrigin (route->GetOrigin ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
              mrtentry->SetParent (route->GetInputInterface ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
              for (uint32_t j = 0; j < route->GetNOutputInterfaces (); j++)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
                {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
                  if (route->GetOutputInterface (j))
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
                    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
                      NS_LOG_LOGIC ("Setting output interface index " << route->GetOutputInterface (j));
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
                      mrtentry->SetOutputTtl (route->GetOutputInterface (j), Ipv4MulticastRoute::MAX_TTL - 1);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
                    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
                }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
              return mrtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
  return mrtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
uint32_t 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   324
Ipv4StaticRouting::GetNRoutes (void)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
  uint32_t n = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
  if (m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
      n++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
  n += m_hostRoutes.size ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
  n += m_networkRoutes.size ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
  return n;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
Ipv4RoutingTableEntry
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   338
Ipv4StaticRouting::GetDefaultRoute ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   340
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
  if (m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
      return *m_defaultRoute;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
      return Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   350
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
Ipv4RoutingTableEntry 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   352
Ipv4StaticRouting::GetRoute (uint32_t index)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   354
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
  if (index == 0 && m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
      return *m_defaultRoute;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
  if (index > 0 && m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   360
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
      index--;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
  if (index < m_hostRoutes.size ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
      uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
      for (HostRoutesCI i = m_hostRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
           i != m_hostRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
           i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
          if (tmp  == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
              return *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
          tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   376
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   377
  index -= m_hostRoutes.size ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   378
  uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   379
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   380
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   381
       j++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
      if (tmp == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
          return *j;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   386
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   387
      tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
  NS_ASSERT (false);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
  // quiet compiler.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
  return 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   394
Ipv4StaticRouting::RemoveRoute (uint32_t index)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
  if (index == 0 && m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
      delete m_defaultRoute;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
      m_defaultRoute = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
  if (index > 0 && m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
      index--;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
  if (index < m_hostRoutes.size ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
      uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
      for (HostRoutesI i = m_hostRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
           i != m_hostRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
           i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
          if (tmp  == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
            {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
              delete *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
              m_hostRoutes.erase (i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
              return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
          tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
  index -= m_hostRoutes.size ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
  uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
       j++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
      if (tmp == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   430
          delete *j;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
          m_networkRoutes.erase (j);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
          return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
      tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
  NS_ASSERT (false);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   437
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   438
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
Ptr<Ipv4Route> 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   440
Ipv4StaticRouting::RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
  NS_LOG_FUNCTION (this << header << oif);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
  Ipv4Address destination = header.GetDestination ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
  Ptr<Ipv4Route> rtentry = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   446
  // Multicast goes here
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   447
  if (destination.IsMulticast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   448
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   449
      // Note:  Multicast routes for outbound packets are stored in the
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   450
      // normal unicast table.  An implication of this is that it is not
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   451
      // possible to source multicast datagrams on multiple interfaces.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
      // This is a well-known property of sockets implementation on 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
      // many Unix variants.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
      // So, we just log it and fall through to LookupStatic ()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   455
      NS_LOG_LOGIC ("RouteOutput()::Multicast destination");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
  rtentry = LookupStatic (destination);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
  if (rtentry)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
    { 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
      sockerr = Socket::ERROR_NOTERROR;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   461
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   463
    { 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
      sockerr = Socket::ERROR_NOROUTETOHOST;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
  return rtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   467
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   469
// XXX this method not robust enough to work outside of ListRouting context
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   470
// because it will not perform local delivery
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
bool 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   472
Ipv4StaticRouting::RouteInput  (Ptr<const Packet> p, const Ipv4Header &ipHeader, Ptr<const NetDevice> idev,
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
                             LocalDeliverCallback lcb, ErrorCallback ecb)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   476
  NS_LOG_FUNCTION (this << p << ipHeader << ipHeader.GetSource () << ipHeader.GetDestination () << idev);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
  if (ipHeader.GetDestination ().IsMulticast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
      NS_LOG_LOGIC ("Multicast destination");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
      Ptr<Ipv4MulticastRoute> mrtentry =  LookupStatic(ipHeader.GetSource (),
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   482
        ipHeader.GetDestination (), m_ipv4->GetInterfaceForDevice (idev));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
      if (mrtentry)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
          NS_LOG_LOGIC ("Multicast route found");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
          mcb (mrtentry, p, ipHeader); // multicast forwarding callback
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
          return true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   489
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   491
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
          NS_LOG_LOGIC ("Multicast route not found");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
          return false; // Let other routing protocols try to handle this
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
// This is a unicast packet.  Check to see if we have a route for it.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
  NS_LOG_LOGIC ("Unicast destination");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
  Ptr<Ipv4Route> rtentry = LookupStatic (ipHeader.GetDestination ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
  if (rtentry != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
      NS_LOG_LOGIC ("Found unicast destination- calling unicast callback");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
      ucb (rtentry, p, ipHeader);  // unicast forwarding callback
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
      return true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   506
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   507
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
      NS_LOG_LOGIC ("Did not find unicast destination- returning false");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
      return false; // Let other routing protocols try to handle this
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   514
Ipv4StaticRouting::~Ipv4StaticRouting ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
void
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   520
Ipv4StaticRouting::DoDispose (void)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   521
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   522
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   523
  for (HostRoutesI i = m_hostRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   524
       i != m_hostRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
       i = m_hostRoutes.erase (i)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
      delete (*i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
       j = m_networkRoutes.erase (j)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
      delete (*j);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
  if (m_defaultRoute != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
      delete m_defaultRoute;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
      m_defaultRoute = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
  for (MulticastRoutesI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
       i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
       i = m_multicastRoutes.erase (i)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   543
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   544
      delete (*i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   545
    }
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   546
  m_ipv4 = 0;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   547
  Ipv4RoutingProtocol::DoDispose ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   548
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   549
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   550
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   551
Ipv4StaticRouting::NotifyInterfaceUp (uint32_t i)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   552
{
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   553
  // If interface address and network mask have been set, add a route
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   554
  // to the network of the interface (like e.g. ifconfig does on a
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   555
  // Linux box)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   556
  for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   557
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   558
      if (m_ipv4->GetAddress (i,j).GetLocal () != Ipv4Address () &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   559
          m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask ())
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   560
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   561
          AddNetworkRouteTo (m_ipv4->GetAddress (i,j).GetLocal ().CombineMask (m_ipv4->GetAddress (i,j).GetMask ()),
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   562
                             m_ipv4->GetAddress (i,j).GetMask (), i);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   563
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   564
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   565
}
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   566
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   567
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   568
Ipv4StaticRouting::NotifyInterfaceDown (uint32_t i)
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   569
{
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   570
  // Remove all static routes that are going through this interface
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   571
  for (uint32_t j = 0; j < GetNRoutes (); j++)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   572
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   573
      Ipv4RoutingTableEntry route = GetRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   574
      if (route.GetInterface () == i)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   575
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   576
          RemoveRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   577
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   578
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   581
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   582
Ipv4StaticRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   583
{
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   584
  NS_LOG_FUNCTION (this << interface);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   585
  if (!m_ipv4->IsUp (interface))
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   586
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   587
      return;
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   588
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   589
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   590
  Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ());
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   591
  Ipv4Mask networkMask = address.GetMask ();
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   592
  if (address.GetLocal () != Ipv4Address () &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   593
      address.GetMask () != Ipv4Mask ())
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   594
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   595
      AddNetworkRouteTo (networkAddress,
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   596
                         networkMask, interface);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   597
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   598
}
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   599
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   600
Ipv4StaticRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
{
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   602
  if (!m_ipv4->IsUp (interface))
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   603
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   604
      return;
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   605
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   606
  Ipv4Address networkAddress = address.GetLocal ().CombineMask (address.GetMask ());
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   607
  Ipv4Mask networkMask = address.GetMask ();
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   608
  // Remove all static routes that are going through this interface
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   609
  // which reference this network
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   610
  for (uint32_t j = 0; j < GetNRoutes (); j++)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   611
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   612
      Ipv4RoutingTableEntry route = GetRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   613
      if (route.GetInterface () == interface &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   614
          route.IsNetwork () && 
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   615
          route.GetDestNetwork () == networkAddress &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   616
          route.GetDestNetworkMask () == networkMask)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   617
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   618
          RemoveRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   619
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   620
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   621
}
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   623
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   624
Ipv4StaticRouting::SetIpv4 (Ptr<Ipv4> ipv4)
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   625
{
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   626
  NS_LOG_FUNCTION (this << ipv4);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   627
  NS_ASSERT (m_ipv4 == 0 && ipv4 != 0);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   628
  m_ipv4 = ipv4;
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   629
  for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   630
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   631
      if (m_ipv4->IsUp (i))
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   632
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   633
          NotifyInterfaceUp (i);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   634
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   635
      else
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   636
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   637
          NotifyInterfaceDown (i);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   638
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   639
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   640
}
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   641
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   642
Ipv4Address
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   643
Ipv4StaticRouting::SourceAddressSelection (uint32_t interfaceIdx, Ipv4Address dest)
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   644
{
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   645
  if (m_ipv4->GetNAddresses (interfaceIdx) == 1)  // common case
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   646
    {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   647
      return m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   648
    }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   649
  // no way to determine the scope of the destination, so adopt the
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   650
  // following rule:  pick the first available address (index 0) unless
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   651
  // a subsequent address is on link (in which case, pick the primary
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   652
  // address if there are multiple)
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   653
  Ipv4Address candidate = m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   654
  for (uint32_t i = 0; i < m_ipv4->GetNAddresses (interfaceIdx); i++)
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   655
    {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   656
      Ipv4InterfaceAddress test = m_ipv4->GetAddress (interfaceIdx, i);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   657
      if (test.GetLocal ().CombineMask (test.GetMask ()) == dest.CombineMask (test.GetMask ()))
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   658
        {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   659
          if (test.IsSecondary () == false) 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   660
            {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   661
              return test.GetLocal ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   662
            }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   663
        }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   664
    }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   665
  return candidate;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   666
}
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   667
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
}//namespace ns3