src/routing/static-routing/ipv4-static-routing.cc
author Antti Makela <zarhan@cc.hut.fi>
Mon, 31 Aug 2009 23:35:16 -0700
changeset 4747 3dc675bb8b20
parent 4603 67a0a49c1db4
child 5352 54b51a1105d6
permissions -rw-r--r--
Static routing with support for metrics and longest prefix match
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
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    30
using std::make_pair;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    31
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
namespace ns3 {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    34
NS_OBJECT_ENSURE_REGISTERED (Ipv4StaticRouting);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
TypeId
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    37
Ipv4StaticRouting::GetTypeId (void)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
{
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    39
  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
    40
    .SetParent<Ipv4RoutingProtocol> ()
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    41
    .AddConstructor<Ipv4StaticRouting> ()
4472
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
  return tid;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    46
Ipv4StaticRouting::Ipv4StaticRouting () 
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    47
: m_ipv4 (0)
4472
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
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    53
Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
                                      Ipv4Mask networkMask, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
                                      Ipv4Address nextHop, 
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    56
                                      uint32_t interface,
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    57
                                      uint32_t metric)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
                                            networkMask,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
                                            nextHop,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
                                            interface);
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    65
  m_networkRoutes.push_back (make_pair(route,metric));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
    69
Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
                                      Ipv4Mask networkMask, 
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    71
                                      uint32_t interface,
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    72
                                      uint32_t metric)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
  Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
  *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
                                            networkMask,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
                                            interface);
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    79
  m_networkRoutes.push_back (make_pair (route,metric));
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    80
}
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    81
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    82
void 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    83
Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    84
                                     Ipv4Address nextHop, 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    85
                                     uint32_t interface,
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    86
                                     uint32_t metric)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    87
{
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    88
  NS_LOG_FUNCTION_NOARGS ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    89
  AddNetworkRouteTo (dest, Ipv4Mask::GetOnes (), nextHop, interface, metric);
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    90
}
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    91
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    92
void 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    93
Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest, 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    94
                                     uint32_t interface,
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    95
                                     uint32_t metric)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    96
{
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    97
  NS_LOG_FUNCTION_NOARGS ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
    98
  AddNetworkRouteTo (dest, Ipv4Mask::GetOnes (), interface, metric);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   102
Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop, 
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   103
                                    uint32_t interface,
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   104
                                    uint32_t metric)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  NS_LOG_FUNCTION_NOARGS ();
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   107
  AddNetworkRouteTo (Ipv4Address ("0.0.0.0"), Ipv4Mask::GetZero (), nextHop, interface, metric);
4472
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);
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   136
  m_networkRoutes.push_back (make_pair(route,0));
4472
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;
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   217
  uint16_t longest_mask = 0;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   218
  uint32_t shortest_metric = 0xffffffff;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   219
  for (NetworkRoutesI i = m_networkRoutes.begin (); 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   220
       i != m_networkRoutes.end (); 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
       i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
    {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   223
      Ipv4RoutingTableEntry *j=i->first;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   224
      uint32_t metric =i->second;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   225
      Ipv4Mask mask = (j)->GetDestNetworkMask ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   226
      uint16_t masklen = mask.GetPrefixLength ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   227
      Ipv4Address entry = (j)->GetDestNetwork ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   228
      NS_LOG_LOGIC ("Searching for route to " << dest << ", checking against route to " << entry << "/" << masklen);
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   229
      if (mask.IsMatch (dest, entry)) 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
        {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   231
          NS_LOG_LOGIC ("Found global network route " << j << ", mask length " << masklen << ", metric " << metric);
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   232
          if (masklen < longest_mask) // Not interested if got shorter mask
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   233
            {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   234
              NS_LOG_LOGIC ("Previous match longer, skipping");
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   235
              continue;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   236
            }
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   237
          if (masklen > longest_mask) // Reset metric if longer masklen
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   238
            {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   239
              shortest_metric = 0xffffffff;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   240
            }
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   241
          longest_mask = masklen;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   242
          if (metric > shortest_metric)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   243
            {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   244
              NS_LOG_LOGIC ("Equal mask length, but previous metric shorter, skipping");
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   245
              continue;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   246
            }
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   247
          shortest_metric = metric;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   248
          Ipv4RoutingTableEntry* route = (j);
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   249
          uint32_t interfaceIdx = route->GetInterface ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
          rtentry = Create<Ipv4Route> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
          rtentry->SetDestination (route->GetDest ());
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   252
          rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ()));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
          rtentry->SetGateway (route->GetGateway ());
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   254
          rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
    }
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   257
  NS_LOG_LOGIC ("Matching route via " << rtentry << " at the end");
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   258
  return rtentry;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
Ptr<Ipv4MulticastRoute>
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   262
Ipv4StaticRouting::LookupStatic (
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
  Ipv4Address origin, 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
  Ipv4Address group,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
  uint32_t    interface)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
  Ptr<Ipv4MulticastRoute> mrtentry = 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
  for (MulticastRoutesI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
       i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
       i++) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
      Ipv4MulticastRoutingTableEntry *route = *i;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
// 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
   277
// 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
   278
// a match.
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
// 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
   281
// matches.  
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   282
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
      if (origin == route->GetOrigin () && group == route->GetGroup ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
          // Skipping this case (SSM) for now
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
          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
   287
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
      if (group == route->GetGroup ())
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
          if (interface == Ipv4::IF_ANY || 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
              interface == route->GetInputInterface ())
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
              NS_LOG_LOGIC ("Found multicast route" << *i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
              mrtentry = Create<Ipv4MulticastRoute> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
              mrtentry->SetGroup (route->GetGroup ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
              mrtentry->SetOrigin (route->GetOrigin ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
              mrtentry->SetParent (route->GetInputInterface ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
              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
   299
                {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
                  if (route->GetOutputInterface (j))
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
                    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
                      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
   303
                      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
   304
                    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   305
                }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
              return mrtentry;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
        }
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
  return mrtentry;
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
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
uint32_t 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   314
Ipv4StaticRouting::GetNRoutes (void)
4472
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
  NS_LOG_FUNCTION_NOARGS ();
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   317
  return m_networkRoutes.size ();;
4472
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
Ipv4RoutingTableEntry
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   321
Ipv4StaticRouting::GetDefaultRoute ()
4472
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
  NS_LOG_FUNCTION_NOARGS ();
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   324
  // Basically a repeat of LookupStatic, retained for backward compatibility
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   325
  Ipv4Address dest ("0.0.0.0");
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   326
  uint32_t shortest_metric = 0xffffffff;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   327
  Ipv4RoutingTableEntry *result = 0;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   328
  for (NetworkRoutesI i = m_networkRoutes.begin (); 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   329
       i != m_networkRoutes.end (); 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   330
       i++) 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
    {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   332
    Ipv4RoutingTableEntry *j = i->first;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   333
    uint32_t metric = i->second;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   334
    Ipv4Mask mask = (j)->GetDestNetworkMask ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   335
    uint16_t masklen = mask.GetPrefixLength ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   336
    Ipv4Address entry = (j)->GetDestNetwork ();
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   337
    if (masklen != 0)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   338
      {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   339
        continue;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   340
      }
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   341
    if (metric > shortest_metric)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   342
      {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   343
        continue;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   344
      }
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   345
    shortest_metric = metric;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   346
    result = j;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   347
  }
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   348
  if (result)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   349
    {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   350
      return result;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
  else
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
      return Ipv4RoutingTableEntry ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
    }
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
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
Ipv4RoutingTableEntry 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   359
Ipv4StaticRouting::GetRoute (uint32_t index)
4472
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
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   362
      uint32_t tmp = 0;
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   363
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   364
       j != m_networkRoutes.end (); 
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   365
       j++) 
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
          if (tmp  == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
            {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   369
          return j->first;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
            }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
          tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
        }
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   373
  NS_ASSERT (false);
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   374
  // quiet compiler.
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   375
  return 0;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   376
}
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   377
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   378
uint32_t
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   379
Ipv4StaticRouting::GetMetric (uint32_t index)
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   380
{
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   381
  NS_LOG_FUNCTION_NOARGS ();
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   382
  uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   383
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   384
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   385
       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
      if (tmp == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
        {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   389
          return j->second;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
      tmp++;
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
  NS_ASSERT (false);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
  // quiet compiler.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
  return 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   398
Ipv4StaticRouting::RemoveRoute (uint32_t index)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
  uint32_t tmp = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
       j++) 
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 (tmp == index)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
        {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   408
          delete j->first;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
          m_networkRoutes.erase (j);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
          return;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
      tmp++;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
  NS_ASSERT (false);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
Ptr<Ipv4Route> 
4603
67a0a49c1db4 bug 592: Ipv4RoutingProtocol::RouteOutput needs a packet pointer argument for reactive protocols
Josh Pelkey <joshpelkey@gmail.com>
parents: 4573
diff changeset
   418
Ipv4StaticRouting::RouteOutput (Ptr<Packet> p, 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
   419
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
  NS_LOG_FUNCTION (this << header << oif);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
  Ipv4Address destination = header.GetDestination ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
  Ptr<Ipv4Route> rtentry = 0;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
  // Multicast goes here
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
  if (destination.IsMulticast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   427
      // 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
   428
      // 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
   429
      // 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
   430
      // 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
   431
      // many Unix variants.
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
      // 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
   433
      NS_LOG_LOGIC ("RouteOutput()::Multicast destination");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
  rtentry = LookupStatic (destination);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
  if (rtentry)
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
      sockerr = Socket::ERROR_NOTERROR;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   440
  else
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
      sockerr = Socket::ERROR_NOROUTETOHOST;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
  return rtentry;
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
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   447
// 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
   448
// 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
   449
bool 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   450
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
   451
                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
                             LocalDeliverCallback lcb, ErrorCallback ecb)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
  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
   455
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
  if (ipHeader.GetDestination ().IsMulticast ())
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
      NS_LOG_LOGIC ("Multicast destination");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
      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
   460
        ipHeader.GetDestination (), m_ipv4->GetInterfaceForDevice (idev));
4472
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
      if (mrtentry)
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
          NS_LOG_LOGIC ("Multicast route found");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
          mcb (mrtentry, p, ipHeader); // multicast forwarding callback
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   466
          return true;
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
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
          NS_LOG_LOGIC ("Multicast route not found");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
          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
   472
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   475
// 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
   476
//
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
  NS_LOG_LOGIC ("Unicast destination");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   478
  Ptr<Ipv4Route> rtentry = LookupStatic (ipHeader.GetDestination ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   479
  if (rtentry != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
      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
   482
      ucb (rtentry, p, ipHeader);  // unicast forwarding callback
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
      return true;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   484
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
  else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
      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
   488
      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
   489
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   491
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   492
Ipv4StaticRouting::~Ipv4StaticRouting ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
  NS_LOG_FUNCTION_NOARGS ();
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
void
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   498
Ipv4StaticRouting::DoDispose (void)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   500
  NS_LOG_FUNCTION_NOARGS ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   501
  for (NetworkRoutesI j = m_networkRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
       j != m_networkRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
       j = m_networkRoutes.erase (j)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
    {
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   505
      delete (j->first);
4472
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
  for (MulticastRoutesI i = m_multicastRoutes.begin (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   508
       i != m_multicastRoutes.end (); 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   509
       i = m_multicastRoutes.erase (i)) 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   511
      delete (*i);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
    }
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   513
  m_ipv4 = 0;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
  Ipv4RoutingProtocol::DoDispose ();
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
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   517
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   518
Ipv4StaticRouting::NotifyInterfaceUp (uint32_t i)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   519
{
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   520
  // 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
   521
  // 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
   522
  // Linux box)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   523
  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
   524
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   525
      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
   526
          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
   527
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   528
          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
   529
                             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
   530
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   531
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   532
}
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   533
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   534
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   535
Ipv4StaticRouting::NotifyInterfaceDown (uint32_t i)
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   536
{
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   537
  // Remove all static routes that are going through this interface
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   538
  uint32_t j = 0;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   539
  while (j < GetNRoutes())
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   540
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   541
      Ipv4RoutingTableEntry route = GetRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   542
      if (route.GetInterface () == i)
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   543
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   544
          RemoveRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   545
        }
4747
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   546
      else
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   547
        {
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   548
          j++;
3dc675bb8b20 Static routing with support for metrics and longest prefix match
Antti Makela <zarhan@cc.hut.fi>
parents: 4603
diff changeset
   549
        }
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   550
    }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   551
}
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
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   554
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
   555
{
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   556
  NS_LOG_FUNCTION (this << interface);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   557
  if (!m_ipv4->IsUp (interface))
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   558
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   559
      return;
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
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   562
  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
   563
  Ipv4Mask networkMask = address.GetMask ();
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   564
  if (address.GetLocal () != Ipv4Address () &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   565
      address.GetMask () != Ipv4Mask ())
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
      AddNetworkRouteTo (networkAddress,
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   568
                         networkMask, interface);
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
}
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   571
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   572
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
   573
{
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   574
  if (!m_ipv4->IsUp (interface))
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
      return;
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
  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
   579
  Ipv4Mask networkMask = address.GetMask ();
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   580
  // 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
   581
  // which reference this network
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   582
  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
   583
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   584
      Ipv4RoutingTableEntry route = GetRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   585
      if (route.GetInterface () == interface &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   586
          route.IsNetwork () && 
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   587
          route.GetDestNetwork () == networkAddress &&
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   588
          route.GetDestNetworkMask () == networkMask)
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
          RemoveRoute (j);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   591
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   592
    }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   593
}
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   594
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   595
void 
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   596
Ipv4StaticRouting::SetIpv4 (Ptr<Ipv4> ipv4)
4560
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
  NS_LOG_FUNCTION (this << ipv4);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   599
  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
   600
  m_ipv4 = ipv4;
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   601
  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
   602
    {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   603
      if (m_ipv4->IsUp (i))
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   604
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   605
          NotifyInterfaceUp (i);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   606
        }
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   607
      else
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   608
        {
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   609
          NotifyInterfaceDown (i);
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4528
diff changeset
   610
        }
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
}
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
4571
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   614
Ipv4Address
4573
01e876191f2e move list routing and static routing to src/routing directories
Tom Henderson <tomh@tomh.org>
parents: 4571
diff changeset
   615
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
   616
{
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   617
  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
   618
    {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   619
      return m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   620
    }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   621
  // 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
   622
  // 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
   623
  // 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
   624
  // address if there are multiple)
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   625
  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
   626
  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
   627
    {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   628
      Ipv4InterfaceAddress test = m_ipv4->GetAddress (interfaceIdx, i);
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   629
      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
   630
        {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   631
          if (test.IsSecondary () == false) 
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   632
            {
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   633
              return test.GetLocal ();
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   634
            }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   635
        }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   636
    }
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   637
  return candidate;
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   638
}
2c9c600270e0 cleanup ip alias unfinished cases (bug 591)
Tom Henderson <tomh@tomh.org>
parents: 4560
diff changeset
   639
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   640
}//namespace ns3