src/ and utils/ changes for IPv4 routing rework
This commit is contained in:
1 parent
bbb1ec0b67
commit
cd5025a550
76 files changed
+5534
-4444
No files matched your search
@@ -18,6 +18,7 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include "address-utils.h"
|
||||
#include "inet-socket-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -67,4 +68,20 @@ void ReadFrom (Buffer::Iterator &i, Mac48Address &ad)
|
||||
ad.CopyFrom (mac);
|
||||
}
|
||||
|
||||
namespace addressUtils {
|
||||
|
||||
bool IsMulticast (const Address &ad)
|
||||
{
|
||||
if (InetSocketAddress::IsMatchingType (ad))
|
||||
{
|
||||
InetSocketAddress inetAddr = InetSocketAddress::ConvertFrom (ad);
|
||||
Ipv4Address ipv4 = inetAddr.GetIpv4 ();
|
||||
return ipv4.IsMulticast ();
|
||||
}
|
||||
// IPv6 case can go here, in future
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace addressUtils
|
||||
|
||||
} // namespace ns3
|
||||
@@ -38,6 +38,14 @@ void ReadFrom (Buffer::Iterator &i, Ipv6Address &ad);
|
||||
void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len);
|
||||
void ReadFrom (Buffer::Iterator &i, Mac48Address &ad);
|
||||
|
||||
namespace addressUtils {
|
||||
|
||||
/**
|
||||
* \brief Address family-independent test for a multicast address
|
||||
*/
|
||||
bool IsMulticast (const Address &ad);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif /* ADDRESS_UTILS_H */
|
||||
@@ -55,6 +55,7 @@ AsciiToIpv4Host (char const *address)
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
|
||||
Ipv4Mask::Ipv4Mask ()
|
||||
: m_mask (0x66666666)
|
||||
{}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ipv4-list-routing.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv4ListRouting);
|
||||
|
||||
TypeId
|
||||
Ipv4ListRouting::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv4ListRouting")
|
||||
.SetParent<Ipv4RoutingProtocol> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
@@ -0,0 +1,61 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IPV4_LIST_ROUTING_H
|
||||
#define IPV4_LIST_ROUTING_H
|
||||
|
||||
#include "ipv4-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup ipv4
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is a specialization of Ipv4RoutingProtocol that allows
|
||||
* other instances of Ipv4RoutingProtocol to be inserted in a
|
||||
* prioritized list. Routing protocols in the list are consulted one
|
||||
* by one, from highest to lowest proirity, until a routing protocol
|
||||
* is found that will take the packet (this corresponds to a non-zero
|
||||
* return value to RouteOutput, or a return value of true to RouteInput).
|
||||
* The order by which routing protocols with the same priority value
|
||||
* are consulted is undefined.
|
||||
*
|
||||
*/
|
||||
class Ipv4ListRouting : public Ipv4RoutingProtocol
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
/**
|
||||
* \brief Register a new routing protocol to be used in this IPv4 stack
|
||||
*
|
||||
* \param routingProtocol new routing protocol implementation object
|
||||
* \param priority priority to give to this routing protocol.
|
||||
* Values may range between -32768 and +32767.
|
||||
*/
|
||||
virtual void AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol, int16_t priority) = 0;
|
||||
|
||||
virtual uint32_t GetNRoutingProtocols (void) const = 0;
|
||||
|
||||
virtual Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (uint32_t index, int16_t& priority) const = 0;
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
#endif /* IPV4_LIST_ROUTING_H */
|
||||
+64
-256
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 INRIA
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
@@ -15,259 +15,85 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include "ipv4-route.h"
|
||||
#include "net-device.h"
|
||||
#include "ns3/assert.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/*****************************************************
|
||||
* Network Ipv4Route
|
||||
*****************************************************/
|
||||
|
||||
Ipv4Route::Ipv4Route ()
|
||||
{}
|
||||
|
||||
Ipv4Route::Ipv4Route (Ipv4Route const &route)
|
||||
: m_dest (route.m_dest),
|
||||
m_destNetworkMask (route.m_destNetworkMask),
|
||||
m_gateway (route.m_gateway),
|
||||
m_interface (route.m_interface)
|
||||
{}
|
||||
|
||||
Ipv4Route::Ipv4Route (Ipv4Route const *route)
|
||||
: m_dest (route->m_dest),
|
||||
m_destNetworkMask (route->m_destNetworkMask),
|
||||
m_gateway (route->m_gateway),
|
||||
m_interface (route->m_interface)
|
||||
{}
|
||||
|
||||
Ipv4Route::Ipv4Route (Ipv4Address dest,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface)
|
||||
: m_dest (dest),
|
||||
m_destNetworkMask (Ipv4Mask::GetZero ()),
|
||||
m_gateway (gateway),
|
||||
m_interface (interface)
|
||||
{}
|
||||
Ipv4Route::Ipv4Route (Ipv4Address dest,
|
||||
uint32_t interface)
|
||||
: m_dest (dest),
|
||||
m_destNetworkMask (Ipv4Mask::GetZero ()),
|
||||
m_gateway (Ipv4Address::GetZero ()),
|
||||
m_interface (interface)
|
||||
{}
|
||||
Ipv4Route::Ipv4Route (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface)
|
||||
: m_dest (network),
|
||||
m_destNetworkMask (networkMask),
|
||||
m_gateway (gateway),
|
||||
m_interface (interface)
|
||||
{}
|
||||
Ipv4Route::Ipv4Route (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface)
|
||||
: m_dest (network),
|
||||
m_destNetworkMask (networkMask),
|
||||
m_gateway (Ipv4Address::GetZero ()),
|
||||
m_interface (interface)
|
||||
{}
|
||||
|
||||
bool
|
||||
Ipv4Route::IsHost (void) const
|
||||
void
|
||||
Ipv4Route::SetDestination (Ipv4Address dest)
|
||||
{
|
||||
if (m_destNetworkMask.IsEqual (Ipv4Mask::GetZero ()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_dest = dest;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4Route::GetDest (void) const
|
||||
Ipv4Route::GetDestination (void) const
|
||||
{
|
||||
return m_dest;
|
||||
}
|
||||
bool
|
||||
Ipv4Route::IsNetwork (void) const
|
||||
|
||||
void
|
||||
Ipv4Route::SetSource (Ipv4Address src)
|
||||
{
|
||||
return !IsHost ();
|
||||
}
|
||||
bool
|
||||
Ipv4Route::IsDefault (void) const
|
||||
{
|
||||
if (m_dest.IsEqual (Ipv4Address::GetZero ()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_source = src;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4Route::GetDestNetwork (void) const
|
||||
Ipv4Route::GetSource (void) const
|
||||
{
|
||||
return m_dest;
|
||||
return m_source;
|
||||
}
|
||||
Ipv4Mask
|
||||
Ipv4Route::GetDestNetworkMask (void) const
|
||||
|
||||
void
|
||||
Ipv4Route::SetGateway (Ipv4Address gw)
|
||||
{
|
||||
return m_destNetworkMask;
|
||||
}
|
||||
bool
|
||||
Ipv4Route::IsGateway (void) const
|
||||
{
|
||||
if (m_gateway.IsEqual (Ipv4Address::GetZero ()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
m_gateway = gw;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4Route::GetGateway (void) const
|
||||
{
|
||||
return m_gateway;
|
||||
}
|
||||
uint32_t
|
||||
Ipv4Route::GetInterface (void) const
|
||||
|
||||
void
|
||||
Ipv4Route::SetOutputDevice (Ptr<NetDevice> outputDevice)
|
||||
{
|
||||
return m_interface;
|
||||
m_outputDevice = outputDevice;
|
||||
}
|
||||
|
||||
Ipv4Route
|
||||
Ipv4Route::CreateHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
Ptr<NetDevice>
|
||||
Ipv4Route::GetOutputDevice (void) const
|
||||
{
|
||||
return Ipv4Route (dest, nextHop, interface);
|
||||
return m_outputDevice;
|
||||
}
|
||||
Ipv4Route
|
||||
Ipv4Route::CreateHostRouteTo (Ipv4Address dest,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4Route (dest, interface);
|
||||
}
|
||||
Ipv4Route
|
||||
Ipv4Route::CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4Route (network, networkMask,
|
||||
nextHop, interface);
|
||||
}
|
||||
Ipv4Route
|
||||
Ipv4Route::CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4Route (network, networkMask,
|
||||
interface);
|
||||
}
|
||||
Ipv4Route
|
||||
Ipv4Route::CreateDefaultRoute (Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4Route (Ipv4Address::GetZero (), nextHop, interface);
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv4Route const& route)
|
||||
{
|
||||
if (route.IsDefault ())
|
||||
{
|
||||
NS_ASSERT (route.IsGateway ());
|
||||
os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else if (route.IsHost ())
|
||||
{
|
||||
if (route.IsGateway ())
|
||||
{
|
||||
os << "host="<< route.GetDest () <<
|
||||
", out=" << route.GetInterface () <<
|
||||
", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "host="<< route.GetDest () <<
|
||||
", out=" << route.GetInterface ();
|
||||
}
|
||||
}
|
||||
else if (route.IsNetwork ())
|
||||
{
|
||||
if (route.IsGateway ())
|
||||
{
|
||||
os << "network=" << route.GetDestNetwork () <<
|
||||
", mask=" << route.GetDestNetworkMask () <<
|
||||
",out=" << route.GetInterface () <<
|
||||
", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "network=" << route.GetDestNetwork () <<
|
||||
", mask=" << route.GetDestNetworkMask () <<
|
||||
",out=" << route.GetInterface ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
return os;
|
||||
os << "source=" << route.GetSource () << " dest="<< route.GetDestination () <<" gw=" << route.GetGateway ();
|
||||
return os;
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* Ipv4MulticastRoute
|
||||
*****************************************************/
|
||||
|
||||
Ipv4MulticastRoute::Ipv4MulticastRoute ()
|
||||
{
|
||||
uint32_t initial_ttl = MAX_TTL;
|
||||
// Initialize array to MAX_TTL, which means that all interfaces are "off"
|
||||
for (uint32_t i = 0; i < MAX_INTERFACES; i++)
|
||||
{
|
||||
m_ttls.push_back(initial_ttl);
|
||||
}
|
||||
}
|
||||
|
||||
Ipv4MulticastRoute::Ipv4MulticastRoute (Ipv4MulticastRoute const &route)
|
||||
:
|
||||
m_origin (route.m_origin),
|
||||
m_group (route.m_group),
|
||||
m_inputInterface (route.m_inputInterface),
|
||||
m_outputInterfaces (route.m_outputInterfaces)
|
||||
void
|
||||
Ipv4MulticastRoute::SetGroup (const Ipv4Address group)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4MulticastRoute::Ipv4MulticastRoute (Ipv4MulticastRoute const *route)
|
||||
:
|
||||
m_origin (route->m_origin),
|
||||
m_group (route->m_group),
|
||||
m_inputInterface (route->m_inputInterface),
|
||||
m_outputInterfaces (route->m_outputInterfaces)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4MulticastRoute::Ipv4MulticastRoute (
|
||||
Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces)
|
||||
{
|
||||
m_origin = origin;
|
||||
m_group = group;
|
||||
m_inputInterface = inputInterface;
|
||||
m_outputInterfaces = outputInterfaces;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4MulticastRoute::GetOrigin (void) const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
@@ -276,58 +102,40 @@ Ipv4MulticastRoute::GetGroup (void) const
|
||||
return m_group;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4MulticastRoute::SetOrigin (const Ipv4Address origin)
|
||||
{
|
||||
m_origin = origin;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4MulticastRoute::GetOrigin (void) const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4MulticastRoute::SetParent (uint32_t parent)
|
||||
{
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Ipv4MulticastRoute::GetInputInterface (void) const
|
||||
Ipv4MulticastRoute::GetParent (void) const
|
||||
{
|
||||
return m_inputInterface;
|
||||
return m_parent;
|
||||
}
|
||||
|
||||
void
|
||||
Ipv4MulticastRoute::SetOutputTtl (uint32_t oif, uint32_t ttl)
|
||||
{
|
||||
m_ttls[oif] = ttl;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Ipv4MulticastRoute::GetNOutputInterfaces (void) const
|
||||
Ipv4MulticastRoute::GetOutputTtl (uint32_t oif) const
|
||||
{
|
||||
return m_outputInterfaces.size ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Ipv4MulticastRoute::GetOutputInterface (uint32_t n) const
|
||||
{
|
||||
NS_ASSERT_MSG(n < m_outputInterfaces.size (),
|
||||
"Ipv4MulticastRoute::GetOutputInterface (): index out of bounds");
|
||||
|
||||
return m_outputInterfaces[n];
|
||||
}
|
||||
|
||||
std::vector<uint32_t>
|
||||
Ipv4MulticastRoute::GetOutputInterfaces (void) const
|
||||
{
|
||||
return m_outputInterfaces;
|
||||
}
|
||||
|
||||
Ipv4MulticastRoute
|
||||
Ipv4MulticastRoute::CreateMulticastRoute (
|
||||
Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces)
|
||||
{
|
||||
return Ipv4MulticastRoute (origin, group, inputInterface, outputInterfaces);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<< (std::ostream& os, Ipv4MulticastRoute const& route)
|
||||
{
|
||||
os << "origin=" << route.GetOrigin () <<
|
||||
", group=" << route.GetGroup () <<
|
||||
", input interface=" << route.GetInputInterface () <<
|
||||
", output interfaces=";
|
||||
|
||||
for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
|
||||
{
|
||||
os << route.GetOutputInterface (i) << " ";
|
||||
|
||||
}
|
||||
|
||||
return os;
|
||||
return m_ttls[oif];
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
+46
-122
@@ -1,6 +1,6 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 INRIA
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
@@ -15,7 +15,6 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#ifndef IPV4_ROUTE_H
|
||||
#define IPV4_ROUTE_H
|
||||
@@ -24,157 +23,82 @@
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
#include "ns3/ref-count-base.h"
|
||||
#include "ipv4-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class NetDevice;
|
||||
|
||||
/**
|
||||
* \ingroup ipv4
|
||||
* \brief A record of an IPv4 route
|
||||
*\brief Ipv4 route cache entry (similar to Linux struct rtable)
|
||||
*
|
||||
* In the future, we will add other entries from struct dst_entry, struct rtable, and struct dst_ops as needed.
|
||||
*/
|
||||
class Ipv4Route {
|
||||
class Ipv4Route : public RefCountBase {
|
||||
public:
|
||||
/**
|
||||
* \brief This constructor does nothing
|
||||
*/
|
||||
Ipv4Route ();
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4Route (Ipv4Route const &route);
|
||||
void SetDestination (Ipv4Address dest);
|
||||
Ipv4Address GetDestination (void) const;
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4Route (Ipv4Route const *route);
|
||||
void SetSource (Ipv4Address src);
|
||||
Ipv4Address GetSource (void) const;
|
||||
|
||||
bool IsHost (void) const;
|
||||
/**
|
||||
* \return The IPv4 address of the destination of this route
|
||||
*/
|
||||
Ipv4Address GetDest (void) const;
|
||||
|
||||
bool IsNetwork (void) const;
|
||||
Ipv4Address GetDestNetwork (void) const;
|
||||
Ipv4Mask GetDestNetworkMask (void) const;
|
||||
/**
|
||||
* \return True if this route is a default route; false otherwise
|
||||
*/
|
||||
bool IsDefault (void) const;
|
||||
|
||||
bool IsGateway (void) const;
|
||||
void SetGateway (Ipv4Address gw);
|
||||
Ipv4Address GetGateway (void) const;
|
||||
|
||||
uint32_t GetInterface (void) const;
|
||||
// dst_entry.dev
|
||||
void SetOutputDevice (Ptr<NetDevice> outputDevice);
|
||||
Ptr<NetDevice> GetOutputDevice (void) const;
|
||||
|
||||
#ifdef NOTYET
|
||||
// rtable.idev
|
||||
void SetInputIfIndex (uint32_t iif);
|
||||
uint32_t GetInputIfIndex (void) const;
|
||||
#endif
|
||||
|
||||
static Ipv4Route CreateHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface);
|
||||
static Ipv4Route CreateHostRouteTo (Ipv4Address dest,
|
||||
uint32_t interface);
|
||||
static Ipv4Route CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface);
|
||||
static Ipv4Route CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface);
|
||||
static Ipv4Route CreateDefaultRoute (Ipv4Address nextHop,
|
||||
uint32_t interface);
|
||||
|
||||
private:
|
||||
Ipv4Route (Ipv4Address network,
|
||||
Ipv4Mask mask,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface);
|
||||
Ipv4Route (Ipv4Address dest,
|
||||
Ipv4Mask mask,
|
||||
uint32_t interface);
|
||||
Ipv4Route (Ipv4Address dest,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface);
|
||||
Ipv4Route (Ipv4Address dest,
|
||||
uint32_t interface);
|
||||
|
||||
Ipv4Address m_dest;
|
||||
Ipv4Mask m_destNetworkMask;
|
||||
Ipv4Address m_source;
|
||||
Ipv4Address m_gateway;
|
||||
uint32_t m_interface;
|
||||
Ptr<NetDevice> m_outputDevice;
|
||||
#ifdef NOTYET
|
||||
uint32_t m_inputIfIndex;
|
||||
#endif
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv4Route const& route);
|
||||
|
||||
/**
|
||||
* \ingroup ipv4
|
||||
* \brief A record of an IPv4 multicast route
|
||||
*\brief Ipv4 multicast route cache entry (similar to Linux struct mfc_cache)
|
||||
*/
|
||||
class Ipv4MulticastRoute {
|
||||
class Ipv4MulticastRoute : public RefCountBase {
|
||||
public:
|
||||
/**
|
||||
* \brief This constructor does nothing
|
||||
*/
|
||||
Ipv4MulticastRoute ();
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4MulticastRoute (Ipv4MulticastRoute const &route);
|
||||
void SetGroup (const Ipv4Address group);
|
||||
Ipv4Address GetGroup (void) const;
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4MulticastRoute (Ipv4MulticastRoute const *route);
|
||||
void SetOrigin (const Ipv4Address group);
|
||||
Ipv4Address GetOrigin (void) const;
|
||||
|
||||
void SetParent (uint32_t iif);
|
||||
uint32_t GetParent (void) const;
|
||||
|
||||
/**
|
||||
* \return The IPv4 address of the source of this route
|
||||
*/
|
||||
Ipv4Address GetOrigin (void) const;
|
||||
|
||||
/**
|
||||
* \return The IPv4 address of the multicast group of this route
|
||||
*/
|
||||
Ipv4Address GetGroup (void) const;
|
||||
|
||||
/**
|
||||
* \return The IPv4 address of the input interface of this route
|
||||
*/
|
||||
uint32_t GetInputInterface (void) const;
|
||||
|
||||
/**
|
||||
* \return The number of output interfaces of this route
|
||||
*/
|
||||
uint32_t GetNOutputInterfaces (void) const;
|
||||
|
||||
/**
|
||||
* \return A specified output interface.
|
||||
*/
|
||||
uint32_t GetOutputInterface (uint32_t n) const;
|
||||
|
||||
/**
|
||||
* \return A vector of all of the output interfaces of this route.
|
||||
*/
|
||||
std::vector<uint32_t> GetOutputInterfaces (void) const;
|
||||
|
||||
static Ipv4MulticastRoute CreateMulticastRoute (Ipv4Address origin,
|
||||
Ipv4Address group, uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces);
|
||||
void SetOutputTtl (uint32_t oif, uint32_t ttl);
|
||||
uint32_t GetOutputTtl (uint32_t oif) const;
|
||||
|
||||
static const uint32_t MAX_INTERFACES = 16;
|
||||
static const uint32_t MAX_TTL = 255;
|
||||
|
||||
private:
|
||||
Ipv4MulticastRoute (Ipv4Address origin, Ipv4Address group,
|
||||
uint32_t inputInterface, std::vector<uint32_t> outputInterfaces);
|
||||
|
||||
Ipv4Address m_origin;
|
||||
Ipv4Address m_group;
|
||||
uint32_t m_inputInterface;
|
||||
std::vector<uint32_t> m_outputInterfaces;
|
||||
Ipv4Address m_group; // Group
|
||||
Ipv4Address m_origin; // Source of packet
|
||||
uint32_t m_parent; // Source interface
|
||||
std::vector<uint32_t> m_ttls;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv4MulticastRoute const& route);
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
#endif /* IPV4_ROUTE_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ipv4-route.h"
|
||||
#include "ipv4-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv4RoutingProtocol);
|
||||
|
||||
TypeId Ipv4RoutingProtocol::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv4RoutingProtocol")
|
||||
.SetParent<Object> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
@@ -0,0 +1,96 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef IPV4_ROUTING_PROTOCOL_H
|
||||
#define IPV4_ROUTING_PROTOCOL_H
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ipv4-header.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv4MulticastRoute;
|
||||
class Ipv4Route;
|
||||
class NetDevice;
|
||||
|
||||
/**
|
||||
* \ingroup ipv4
|
||||
* Abstract base class for Ipv4 routing protocols. Defines two
|
||||
* virtual functions for packet routing and forwarding. The first,
|
||||
* RouteOutput(), is used for locally originated packets, and the second,
|
||||
* RouteInput(), is used for forwarding and/or delivering received packets.
|
||||
* Also defines the signatures of four callbacks used in RouteInput().
|
||||
*
|
||||
*/
|
||||
class Ipv4RoutingProtocol : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
typedef Callback<void, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &> UnicastForwardCallback;
|
||||
typedef Callback<void, Ptr<Ipv4MulticastRoute>, Ptr<const Packet>, const Ipv4Header &> MulticastForwardCallback;
|
||||
typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, uint32_t > LocalDeliverCallback;
|
||||
typedef Callback<void, Ptr<const Packet>, const Ipv4Header &> ErrorCallback;
|
||||
|
||||
/**
|
||||
* \brief Query routing cache for an existing route, for an outbound packet
|
||||
*
|
||||
* This lookup is used by transport protocols. It does not cause any
|
||||
* packet to be forwarded, and is synchronous. Can be used for
|
||||
* multicast or unicast. The Linux equivalent is ip_route_output()
|
||||
*
|
||||
* \param header input parameter (used to form key to search for the route)
|
||||
* \param oif Output interface index. May be zero, or may be bound via
|
||||
* socket options to a particular output interface.
|
||||
* \param sockerr Output parameter; socket errno
|
||||
*
|
||||
* \returns a code that indicates what happened in the lookup
|
||||
*/
|
||||
virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr) = 0;
|
||||
|
||||
/**
|
||||
* \brief Route an input packet (to be forwarded or locally delivered)
|
||||
*
|
||||
* This lookup is used in the forwarding process. The packet is
|
||||
* handed over to the Ipv4RoutingProtocol, and will get forwarded onward
|
||||
* by one of the callbacks. The Linux equivalent is ip_route_input().
|
||||
* There are four valid outcomes, and a matching callbacks to handle each.
|
||||
*
|
||||
* \param p received packet
|
||||
* \param header input parameter used to form a search key for a route
|
||||
* \param idev Pointer to ingress network device
|
||||
* \param ucb Callback for the case in which the packet is to be forwarded
|
||||
* as unicast
|
||||
* \param mcb Callback for the case in which the packet is to be forwarded
|
||||
* as multicast
|
||||
* \param lcb Callback for the case in which the packet is to be locally
|
||||
* delivered
|
||||
* \param ecb Callback to call if there is an error in forwarding
|
||||
* \returns true if the Ipv4RoutingProtocol takes responsibility for
|
||||
* forwarding or delivering the packet, false otherwise
|
||||
*/
|
||||
virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
||||
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
||||
LocalDeliverCallback lcb, ErrorCallback ecb) = 0;
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
#endif /* IPV4_ROUTING_PROTOCOL_H */
|
||||
@@ -0,0 +1,333 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 INRIA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include "ipv4-routing-table-entry.h"
|
||||
#include "ns3/assert.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/*****************************************************
|
||||
* Network Ipv4RoutingTableEntry
|
||||
*****************************************************/
|
||||
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry ()
|
||||
{}
|
||||
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4RoutingTableEntry const &route)
|
||||
: m_dest (route.m_dest),
|
||||
m_destNetworkMask (route.m_destNetworkMask),
|
||||
m_gateway (route.m_gateway),
|
||||
m_interface (route.m_interface)
|
||||
{}
|
||||
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4RoutingTableEntry const *route)
|
||||
: m_dest (route->m_dest),
|
||||
m_destNetworkMask (route->m_destNetworkMask),
|
||||
m_gateway (route->m_gateway),
|
||||
m_interface (route->m_interface)
|
||||
{}
|
||||
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address dest,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface)
|
||||
: m_dest (dest),
|
||||
m_destNetworkMask (Ipv4Mask::GetZero ()),
|
||||
m_gateway (gateway),
|
||||
m_interface (interface)
|
||||
{}
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address dest,
|
||||
uint32_t interface)
|
||||
: m_dest (dest),
|
||||
m_destNetworkMask (Ipv4Mask::GetZero ()),
|
||||
m_gateway (Ipv4Address::GetZero ()),
|
||||
m_interface (interface)
|
||||
{}
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface)
|
||||
: m_dest (network),
|
||||
m_destNetworkMask (networkMask),
|
||||
m_gateway (gateway),
|
||||
m_interface (interface)
|
||||
{}
|
||||
Ipv4RoutingTableEntry::Ipv4RoutingTableEntry (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface)
|
||||
: m_dest (network),
|
||||
m_destNetworkMask (networkMask),
|
||||
m_gateway (Ipv4Address::GetZero ()),
|
||||
m_interface (interface)
|
||||
{}
|
||||
|
||||
bool
|
||||
Ipv4RoutingTableEntry::IsHost (void) const
|
||||
{
|
||||
if (m_destNetworkMask.IsEqual (Ipv4Mask::GetZero ()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Ipv4Address
|
||||
Ipv4RoutingTableEntry::GetDest (void) const
|
||||
{
|
||||
return m_dest;
|
||||
}
|
||||
bool
|
||||
Ipv4RoutingTableEntry::IsNetwork (void) const
|
||||
{
|
||||
return !IsHost ();
|
||||
}
|
||||
bool
|
||||
Ipv4RoutingTableEntry::IsDefault (void) const
|
||||
{
|
||||
if (m_dest.IsEqual (Ipv4Address::GetZero ()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Ipv4Address
|
||||
Ipv4RoutingTableEntry::GetDestNetwork (void) const
|
||||
{
|
||||
return m_dest;
|
||||
}
|
||||
Ipv4Mask
|
||||
Ipv4RoutingTableEntry::GetDestNetworkMask (void) const
|
||||
{
|
||||
return m_destNetworkMask;
|
||||
}
|
||||
bool
|
||||
Ipv4RoutingTableEntry::IsGateway (void) const
|
||||
{
|
||||
if (m_gateway.IsEqual (Ipv4Address::GetZero ()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Ipv4Address
|
||||
Ipv4RoutingTableEntry::GetGateway (void) const
|
||||
{
|
||||
return m_gateway;
|
||||
}
|
||||
uint32_t
|
||||
Ipv4RoutingTableEntry::GetInterface (void) const
|
||||
{
|
||||
return m_interface;
|
||||
}
|
||||
|
||||
Ipv4RoutingTableEntry
|
||||
Ipv4RoutingTableEntry::CreateHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4RoutingTableEntry (dest, nextHop, interface);
|
||||
}
|
||||
Ipv4RoutingTableEntry
|
||||
Ipv4RoutingTableEntry::CreateHostRouteTo (Ipv4Address dest,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4RoutingTableEntry (dest, interface);
|
||||
}
|
||||
Ipv4RoutingTableEntry
|
||||
Ipv4RoutingTableEntry::CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4RoutingTableEntry (network, networkMask,
|
||||
nextHop, interface);
|
||||
}
|
||||
Ipv4RoutingTableEntry
|
||||
Ipv4RoutingTableEntry::CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4RoutingTableEntry (network, networkMask,
|
||||
interface);
|
||||
}
|
||||
Ipv4RoutingTableEntry
|
||||
Ipv4RoutingTableEntry::CreateDefaultRoute (Ipv4Address nextHop,
|
||||
uint32_t interface)
|
||||
{
|
||||
return Ipv4RoutingTableEntry (Ipv4Address::GetZero (), nextHop, interface);
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route)
|
||||
{
|
||||
if (route.IsDefault ())
|
||||
{
|
||||
NS_ASSERT (route.IsGateway ());
|
||||
os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else if (route.IsHost ())
|
||||
{
|
||||
if (route.IsGateway ())
|
||||
{
|
||||
os << "host="<< route.GetDest () <<
|
||||
", out=" << route.GetInterface () <<
|
||||
", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "host="<< route.GetDest () <<
|
||||
", out=" << route.GetInterface ();
|
||||
}
|
||||
}
|
||||
else if (route.IsNetwork ())
|
||||
{
|
||||
if (route.IsGateway ())
|
||||
{
|
||||
os << "network=" << route.GetDestNetwork () <<
|
||||
", mask=" << route.GetDestNetworkMask () <<
|
||||
",out=" << route.GetInterface () <<
|
||||
", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "network=" << route.GetDestNetwork () <<
|
||||
", mask=" << route.GetDestNetworkMask () <<
|
||||
",out=" << route.GetInterface ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* Ipv4MulticastRoutingTableEntry
|
||||
*****************************************************/
|
||||
|
||||
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry ()
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const &route)
|
||||
:
|
||||
m_origin (route.m_origin),
|
||||
m_group (route.m_group),
|
||||
m_inputInterface (route.m_inputInterface),
|
||||
m_outputInterfaces (route.m_outputInterfaces)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const *route)
|
||||
:
|
||||
m_origin (route->m_origin),
|
||||
m_group (route->m_group),
|
||||
m_inputInterface (route->m_inputInterface),
|
||||
m_outputInterfaces (route->m_outputInterfaces)
|
||||
{
|
||||
}
|
||||
|
||||
Ipv4MulticastRoutingTableEntry::Ipv4MulticastRoutingTableEntry (
|
||||
Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces)
|
||||
{
|
||||
m_origin = origin;
|
||||
m_group = group;
|
||||
m_inputInterface = inputInterface;
|
||||
m_outputInterfaces = outputInterfaces;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4MulticastRoutingTableEntry::GetOrigin (void) const
|
||||
{
|
||||
return m_origin;
|
||||
}
|
||||
|
||||
Ipv4Address
|
||||
Ipv4MulticastRoutingTableEntry::GetGroup (void) const
|
||||
{
|
||||
return m_group;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Ipv4MulticastRoutingTableEntry::GetInputInterface (void) const
|
||||
{
|
||||
return m_inputInterface;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Ipv4MulticastRoutingTableEntry::GetNOutputInterfaces (void) const
|
||||
{
|
||||
return m_outputInterfaces.size ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Ipv4MulticastRoutingTableEntry::GetOutputInterface (uint32_t n) const
|
||||
{
|
||||
NS_ASSERT_MSG(n < m_outputInterfaces.size (),
|
||||
"Ipv4MulticastRoutingTableEntry::GetOutputInterface (): index out of bounds");
|
||||
|
||||
return m_outputInterfaces[n];
|
||||
}
|
||||
|
||||
std::vector<uint32_t>
|
||||
Ipv4MulticastRoutingTableEntry::GetOutputInterfaces (void) const
|
||||
{
|
||||
return m_outputInterfaces;
|
||||
}
|
||||
|
||||
Ipv4MulticastRoutingTableEntry
|
||||
Ipv4MulticastRoutingTableEntry::CreateMulticastRoute (
|
||||
Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces)
|
||||
{
|
||||
return Ipv4MulticastRoutingTableEntry (origin, group, inputInterface, outputInterfaces);
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route)
|
||||
{
|
||||
os << "origin=" << route.GetOrigin () <<
|
||||
", group=" << route.GetGroup () <<
|
||||
", input interface=" << route.GetInputInterface () <<
|
||||
", output interfaces=";
|
||||
|
||||
for (uint32_t i = 0; i < route.GetNOutputInterfaces (); ++i)
|
||||
{
|
||||
os << route.GetOutputInterface (i) << " ";
|
||||
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
@@ -0,0 +1,181 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 INRIA
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#ifndef IPV4_ROUTING_TABLE_ENTRY_H
|
||||
#define IPV4_ROUTING_TABLE_ENTRY_H
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
#include "ns3/ipv4-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup internetStack
|
||||
* \brief A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting
|
||||
*/
|
||||
class Ipv4RoutingTableEntry {
|
||||
public:
|
||||
/**
|
||||
* \brief This constructor does nothing
|
||||
*/
|
||||
Ipv4RoutingTableEntry ();
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4RoutingTableEntry (Ipv4RoutingTableEntry const &route);
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4RoutingTableEntry (Ipv4RoutingTableEntry const *route);
|
||||
|
||||
bool IsHost (void) const;
|
||||
/**
|
||||
* \return The IPv4 address of the destination of this route
|
||||
*/
|
||||
Ipv4Address GetDest (void) const;
|
||||
|
||||
bool IsNetwork (void) const;
|
||||
Ipv4Address GetDestNetwork (void) const;
|
||||
Ipv4Mask GetDestNetworkMask (void) const;
|
||||
/**
|
||||
* \return True if this route is a default route; false otherwise
|
||||
*/
|
||||
bool IsDefault (void) const;
|
||||
|
||||
bool IsGateway (void) const;
|
||||
Ipv4Address GetGateway (void) const;
|
||||
|
||||
uint32_t GetInterface (void) const;
|
||||
|
||||
static Ipv4RoutingTableEntry CreateHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface);
|
||||
static Ipv4RoutingTableEntry CreateHostRouteTo (Ipv4Address dest,
|
||||
uint32_t interface);
|
||||
static Ipv4RoutingTableEntry CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface);
|
||||
static Ipv4RoutingTableEntry CreateNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface);
|
||||
static Ipv4RoutingTableEntry CreateDefaultRoute (Ipv4Address nextHop,
|
||||
uint32_t interface);
|
||||
|
||||
private:
|
||||
Ipv4RoutingTableEntry (Ipv4Address network,
|
||||
Ipv4Mask mask,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface);
|
||||
Ipv4RoutingTableEntry (Ipv4Address dest,
|
||||
Ipv4Mask mask,
|
||||
uint32_t interface);
|
||||
Ipv4RoutingTableEntry (Ipv4Address dest,
|
||||
Ipv4Address gateway,
|
||||
uint32_t interface);
|
||||
Ipv4RoutingTableEntry (Ipv4Address dest,
|
||||
uint32_t interface);
|
||||
|
||||
Ipv4Address m_dest;
|
||||
Ipv4Mask m_destNetworkMask;
|
||||
Ipv4Address m_gateway;
|
||||
uint32_t m_interface;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route);
|
||||
|
||||
/**
|
||||
* \ingroup internetStack
|
||||
* \brief A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting
|
||||
*/
|
||||
class Ipv4MulticastRoutingTableEntry {
|
||||
public:
|
||||
/**
|
||||
* \brief This constructor does nothing
|
||||
*/
|
||||
Ipv4MulticastRoutingTableEntry ();
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const &route);
|
||||
|
||||
/**
|
||||
* \brief Copy Constructor
|
||||
* \param route The route to copy
|
||||
*/
|
||||
Ipv4MulticastRoutingTableEntry (Ipv4MulticastRoutingTableEntry const *route);
|
||||
|
||||
/**
|
||||
* \return The IPv4 address of the source of this route
|
||||
*/
|
||||
Ipv4Address GetOrigin (void) const;
|
||||
|
||||
/**
|
||||
* \return The IPv4 address of the multicast group of this route
|
||||
*/
|
||||
Ipv4Address GetGroup (void) const;
|
||||
|
||||
/**
|
||||
* \return The IPv4 address of the input interface of this route
|
||||
*/
|
||||
uint32_t GetInputInterface (void) const;
|
||||
|
||||
/**
|
||||
* \return The number of output interfaces of this route
|
||||
*/
|
||||
uint32_t GetNOutputInterfaces (void) const;
|
||||
|
||||
/**
|
||||
* \return A specified output interface.
|
||||
*/
|
||||
uint32_t GetOutputInterface (uint32_t n) const;
|
||||
|
||||
/**
|
||||
* \return A vector of all of the output interfaces of this route.
|
||||
*/
|
||||
std::vector<uint32_t> GetOutputInterfaces (void) const;
|
||||
|
||||
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute (Ipv4Address origin,
|
||||
Ipv4Address group, uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces);
|
||||
|
||||
private:
|
||||
Ipv4MulticastRoutingTableEntry (Ipv4Address origin, Ipv4Address group,
|
||||
uint32_t inputInterface, std::vector<uint32_t> outputInterfaces);
|
||||
|
||||
Ipv4Address m_origin;
|
||||
Ipv4Address m_group;
|
||||
uint32_t m_inputInterface;
|
||||
std::vector<uint32_t> m_outputInterfaces;
|
||||
};
|
||||
|
||||
std::ostream& operator<< (std::ostream& os, Ipv4MulticastRoutingTableEntry const& route);
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
#endif /* IPV4_ROUTING_TABLE_ENTRY_H */
|
||||
@@ -0,0 +1,34 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2009 University of Washington
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ipv4-static-routing.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (Ipv4StaticRouting);
|
||||
|
||||
TypeId
|
||||
Ipv4StaticRouting::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv4StaticRouting")
|
||||
.SetParent<Ipv4RoutingProtocol> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
@@ -0,0 +1,366 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2006 Georgia Tech Research Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: George F. Riley<riley@ece.gatech.edu>
|
||||
* Gustavo Carneiro <gjc@inescporto.pt>
|
||||
*/
|
||||
|
||||
#ifndef IPV4_STATIC_ROUTING_H
|
||||
#define IPV4_STATIC_ROUTING_H
|
||||
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/ipv4-header.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/ipv4.h"
|
||||
#include "ns3/ipv4-routing-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Packet;
|
||||
class NetDevice;
|
||||
class Ipv4Interface;
|
||||
class Ipv4Address;
|
||||
class Ipv4Header;
|
||||
class Node;
|
||||
|
||||
class Ipv4RoutingTableEntry;
|
||||
class Ipv4MulticastRoutingTableEntry;
|
||||
|
||||
/**
|
||||
* \brief Static routing protocol for IP version 4 stacks.
|
||||
*
|
||||
* In ns-3 we have the concept of a pluggable routing protocol. Routing
|
||||
* protocols are added to a list maintained by the Ipv4L3Protocol. Every
|
||||
* stack gets one routing protocol for free -- the Ipv4StaticRouting routing
|
||||
* protocol is added in the constructor of the Ipv4L3Protocol (this is the
|
||||
* piece of code that implements the functionality of the IP layer).
|
||||
*
|
||||
* The Ipv4StaticRouting class inherits from the abstract base class
|
||||
* Ipv4RoutingProtocol that defines the interface methods that a routing
|
||||
* protocol must support.
|
||||
*
|
||||
* When a packet arrives in the Ipv4L3Protocol for transmission, it comes
|
||||
* either from a local source via Ipv4L3Protocol::Send or from a remote
|
||||
* source via Ipv4L3Protocol::Forwarding. In both cases, a function is called
|
||||
* (Ipv4L3Protocol::Lookup) to look up the routing information for the packet.
|
||||
*
|
||||
* The lookup function iterates through the list of routing protocols asking
|
||||
* each to see if it can find a route and send the packet. A callback is
|
||||
* provided during each of these calls that should be considered a pre-
|
||||
* packaged send call. This is done to allow asynchronous calls into
|
||||
* routing subsystems in order to support on-demand routing, for example. The
|
||||
* method for requesting this operation is Ipv4StaticRouting::RequestRoute for
|
||||
* the static routing protocol.
|
||||
*
|
||||
* Each routing protocol is also free to implement its own methods for managing
|
||||
* routes which you will find below. This class manages a set of "static" or
|
||||
* manually configured routes for host, network and multicast routes.
|
||||
*
|
||||
* \see Ipv4RoutingProtocol
|
||||
* \see Ipv4L3Protocol::AddRoutingProtocol
|
||||
* \see Ipv4L3Protocol::Ipv4L3Protocol
|
||||
*/
|
||||
class Ipv4StaticRouting : public Ipv4RoutingProtocol
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
/**
|
||||
* \brief Add a host route to the static routing table.
|
||||
*
|
||||
* \param dest The Ipv4Address destination for this route.
|
||||
* \param nextHop The Ipv4Address of the next hop in the route.
|
||||
* \param interface The network interface index used to send packets to the
|
||||
* destination.
|
||||
*
|
||||
* \see Ipv4Address
|
||||
*/
|
||||
virtual void AddHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface) = 0;
|
||||
/**
|
||||
* \brief Add a host route to the static routing table.
|
||||
*
|
||||
* \param dest The Ipv4Address destination for this route.
|
||||
* \param interface The network interface index used to send packets to the
|
||||
* destination.
|
||||
*
|
||||
* \see Ipv4Address
|
||||
*/
|
||||
virtual void AddHostRouteTo (Ipv4Address dest, uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Add a network route to the static routing table.
|
||||
*
|
||||
* \param network The Ipv4Address network for this route.
|
||||
* \param networkMask The Ipv4Mask to extract the network.
|
||||
* \param nextHop The next hop in the route to the destination network.
|
||||
* \param interface The network interface index used to send packets to the
|
||||
* destination.
|
||||
*
|
||||
* \see Ipv4Address
|
||||
*/
|
||||
virtual void AddNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Add a network route to the static routing table.
|
||||
*
|
||||
* \param network The Ipv4Address network for this route.
|
||||
* \param networkMask The Ipv4Mask to extract the network.
|
||||
* \param interface The network interface index used to send packets to the
|
||||
* destination.
|
||||
*
|
||||
* \see Ipv4Address
|
||||
*/
|
||||
virtual void AddNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Add a default route to the static routing table.
|
||||
*
|
||||
* This method tells the routing system what to do in the case where a specific
|
||||
* route to a destination is not found. The system forwards packets to the
|
||||
* specified node in the hope that it knows better how to route the packet.
|
||||
*
|
||||
* If the default route is set, it is returned as the selected route from
|
||||
* LookupStatic irrespective of destination address if no specific route is
|
||||
* found.
|
||||
*
|
||||
* \param nextHop The Ipv4Address to send packets to in the hope that they
|
||||
* will be forwarded correctly.
|
||||
* \param interface The network interface index used to send packets.
|
||||
*
|
||||
* \see Ipv4Address
|
||||
* \see Ipv4StaticRouting::Lookup
|
||||
*/
|
||||
virtual void SetDefaultRoute (Ipv4Address nextHop, uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Get the number of individual unicast routes that have been added
|
||||
* to the routing table.
|
||||
*
|
||||
* \warning The default route counts as one of the routes.
|
||||
*/
|
||||
virtual uint32_t GetNRoutes (void) = 0;
|
||||
|
||||
/**
|
||||
* \brief Get the default route from the static routing table.
|
||||
*
|
||||
* \return If the default route is set, a pointer to that Ipv4RoutingTableEntry is
|
||||
* returned, otherwise a zero pointer is returned.
|
||||
*
|
||||
* \see Ipv4RoutingTableEntry
|
||||
*/
|
||||
virtual Ipv4RoutingTableEntry GetDefaultRoute (void) = 0;
|
||||
|
||||
/**
|
||||
* \brief Get a route from the static unicast routing table.
|
||||
*
|
||||
* Externally, the unicast static routing table appears simply as a table with
|
||||
* n entries. The one sublety of note is that if a default route has been set
|
||||
* it will appear as the zeroth entry in the table. This means that if you
|
||||
* add only a default route, the table will have one entry that can be accessed
|
||||
* either by explicity calling GetDefaultRoute () or by calling GetRoute (0).
|
||||
*
|
||||
* Similarly, if the default route has been set, calling RemoveRoute (0) will
|
||||
* remove the default route.
|
||||
*
|
||||
* \param i The index (into the routing table) of the route to retrieve. If
|
||||
* the default route has been set, it will occupy index zero.
|
||||
* \return If route is set, a pointer to that Ipv4RoutingTableEntry is returned, otherwise
|
||||
* a zero pointer is returned.
|
||||
*
|
||||
* \see Ipv4RoutingTableEntry
|
||||
* \see Ipv4StaticRouting::RemoveRoute
|
||||
*/
|
||||
virtual Ipv4RoutingTableEntry GetRoute (uint32_t i) = 0;
|
||||
|
||||
/**
|
||||
* \brief Remove a route from the static unicast routing table.
|
||||
*
|
||||
* Externally, the unicast static routing table appears simply as a table with
|
||||
* n entries. The one sublety of note is that if a default route has been set
|
||||
* it will appear as the zeroth entry in the table. This means that if the
|
||||
* default route has been set, calling RemoveRoute (0) will remove the
|
||||
* default route.
|
||||
*
|
||||
* \param i The index (into the routing table) of the route to remove. If
|
||||
* the default route has been set, it will occupy index zero.
|
||||
*
|
||||
* \see Ipv4RoutingTableEntry
|
||||
* \see Ipv4StaticRouting::GetRoute
|
||||
* \see Ipv4StaticRouting::AddRoute
|
||||
*/
|
||||
virtual void RemoveRoute (uint32_t i) = 0;
|
||||
|
||||
/**
|
||||
* \brief Add a multicast route to the static routing table.
|
||||
*
|
||||
* A multicast route must specify an origin IP address, a multicast group and
|
||||
* an input network interface index as conditions and provide a vector of
|
||||
* output network interface indices over which packets matching the conditions
|
||||
* are sent.
|
||||
*
|
||||
* Typically there are two main types of multicast routes: routes of the
|
||||
* first kind are used during forwarding. All of the conditions must be
|
||||
* exlicitly provided. The second kind of routes are used to get packets off
|
||||
* of a local node. The difference is in the input interface. Routes for
|
||||
* forwarding will always have an explicit input interface specified. Routes
|
||||
* off of a node will always set the input interface to a wildcard specified
|
||||
* by the index Ipv4RoutingProtocol::INTERFACE_ANY.
|
||||
*
|
||||
* For routes off of a local node wildcards may be used in the origin and
|
||||
* multicast group addresses. The wildcard used for Ipv4Adresses is that
|
||||
* address returned by Ipv4Address::GetAny () -- typically "0.0.0.0". Usage
|
||||
* of a wildcard allows one to specify default behavior to varying degrees.
|
||||
*
|
||||
* For example, making the origin address a wildcard, but leaving the
|
||||
* multicast group specific allows one (in the case of a node with multiple
|
||||
* interfaces) to create different routes using different output interfaces
|
||||
* for each multicast group.
|
||||
*
|
||||
* If the origin and multicast addresses are made wildcards, you have created
|
||||
* essentially a default multicast address that can forward to multiple
|
||||
* interfaces. Compare this to the actual default multicast address that is
|
||||
* limited to specifying a single output interface for compatibility with
|
||||
* existing functionality in other systems.
|
||||
*
|
||||
* \param origin The Ipv4Address of the origin of packets for this route. May
|
||||
* be Ipv4Address:GetAny for open groups.
|
||||
* \param group The Ipv4Address of the multicast group or this route.
|
||||
* \param inputInterface The input network interface index over which to
|
||||
* expect packets destined for this route. May be
|
||||
* Ipv4RoutingProtocol::INTERFACE_ANY for packets of local origin.
|
||||
* \param outputInterfaces A vector of network interface indices used to specify
|
||||
* how to send packets to the destination(s).
|
||||
*
|
||||
* \see Ipv4Address
|
||||
*/
|
||||
virtual void AddMulticastRoute (Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces) = 0;
|
||||
|
||||
/**
|
||||
* \brief Add a default multicast route to the static routing table.
|
||||
*
|
||||
* This is the multicast equivalent of the unicast version SetDefaultRoute.
|
||||
* We tell the routing system what to do in the case where a specific route
|
||||
* to a destination multicast group is not found. The system forwards
|
||||
* packets out the specified interface in the hope that "something out there"
|
||||
* knows better how to route the packet. This method is only used in
|
||||
* initially sending packets off of a host. The default multicast route is
|
||||
* not consulted during forwarding -- exact routes must be specified using
|
||||
* AddMulticastRoute for that case.
|
||||
*
|
||||
* Since we're basically sending packets to some entity we think may know
|
||||
* better what to do, we don't pay attention to "subtleties" like origin
|
||||
* address, nor do we worry about forwarding out multiple interfaces. If the
|
||||
* default multicast route is set, it is returned as the selected route from
|
||||
* LookupStatic irrespective of origin or multicast group if another specific
|
||||
* route is not found.
|
||||
*
|
||||
* \param outputInterface The network interface index used to specify where
|
||||
* to send packets in the case of unknown routes.
|
||||
*
|
||||
* \see Ipv4Address
|
||||
*/
|
||||
virtual void SetDefaultMulticastRoute (uint32_t outputInterface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Get the number of individual multicast routes that have been added
|
||||
* to the routing table.
|
||||
*
|
||||
* \warning The default multicast route counts as one of the routes.
|
||||
*/
|
||||
virtual uint32_t GetNMulticastRoutes (void) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Get a route from the static multicast routing table.
|
||||
*
|
||||
* Externally, the multicast static routing table appears simply as a table
|
||||
* with n entries.
|
||||
*
|
||||
* \param i The index (into the routing table) of the multicast route to
|
||||
* retrieve.
|
||||
* \return If route \e i is set, a pointer to that Ipv4MulticastRoutingTableEntry is
|
||||
* returned, otherwise a zero pointer is returned.
|
||||
*
|
||||
* \see Ipv4MulticastRoutingTableEntry
|
||||
* \see Ipv4StaticRouting::RemoveRoute
|
||||
*/
|
||||
virtual Ipv4MulticastRoutingTableEntry GetMulticastRoute (uint32_t i) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Remove a route from the static multicast routing table.
|
||||
*
|
||||
* Externally, the multicast static routing table appears simply as a table
|
||||
* with n entries.
|
||||
* This method causes the multicast routing table to be searched for the first
|
||||
* route that matches the parameters and removes it.
|
||||
*
|
||||
* Wildcards may be provided to this function, but the wildcards are used to
|
||||
* exacly match wildcards in the routes (see AddMulticastRoute). That is,
|
||||
* calling RemoveMulticastRoute with the origin set to "0.0.0.0" will not
|
||||
* remove routes with any address in the origin, but will only remove routes
|
||||
* with "0.0.0.0" set as the the origin.
|
||||
*
|
||||
* \param origin The IP address specified as the origin of packets for the
|
||||
* route.
|
||||
* \param group The IP address specified as the multicast group addres of
|
||||
* the route.
|
||||
* \param inputInterface The network interface index specified as the expected
|
||||
* input interface for the route.
|
||||
* \returns true if a route was found and removed, false otherwise.
|
||||
*
|
||||
* \see Ipv4MulticastRoutingTableEntry
|
||||
* \see Ipv4StaticRouting::AddMulticastRoute
|
||||
*/
|
||||
virtual bool RemoveMulticastRoute (Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Remove a route from the static multicast routing table.
|
||||
*
|
||||
* Externally, the multicast static routing table appears simply as a table
|
||||
* with n entries.
|
||||
*
|
||||
* \param index The index (into the multicast routing table) of the route to
|
||||
* remove.
|
||||
*
|
||||
* \see Ipv4RoutingTableEntry
|
||||
* \see Ipv4StaticRouting::GetRoute
|
||||
* \see Ipv4StaticRouting::AddRoute
|
||||
*/
|
||||
virtual void RemoveMulticastRoute (uint32_t index) = 0;
|
||||
|
||||
virtual void SetNode (Ptr<Node> node) = 0;
|
||||
virtual Ptr<Node> GetNode (void) const = 0;
|
||||
|
||||
};
|
||||
|
||||
} // Namespace ns3
|
||||
|
||||
#endif /* IPV4_STATIC_ROUTING_H */
|
||||
+15
-20
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/boolean.h"
|
||||
#include "ipv4.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -30,7 +31,20 @@ TypeId
|
||||
Ipv4::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Ipv4")
|
||||
.SetParent<Object> ();
|
||||
.SetParent<Object> ()
|
||||
.AddAttribute ("IpForward", "If enabled, node can act as unicast router.",
|
||||
BooleanValue (true),
|
||||
MakeBooleanAccessor (&Ipv4::SetIpForward,
|
||||
&Ipv4::GetIpForward),
|
||||
MakeBooleanChecker ())
|
||||
#if 0
|
||||
.AddAttribute ("MtuDiscover", "If enabled, every outgoing ip packet will have the DF flag set.",
|
||||
BooleanValue (false),
|
||||
MakeBooleanAccessor (&UdpSocket::SetMtuDiscover,
|
||||
&UdpSocket::GetMtuDiscover),
|
||||
MakeBooleanChecker ())
|
||||
#endif
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
@@ -40,23 +54,4 @@ Ipv4::Ipv4 ()
|
||||
Ipv4::~Ipv4 ()
|
||||
{}
|
||||
|
||||
uint32_t
|
||||
Ipv4::GetInterfaceByAddress (Ipv4Address addr, Ipv4Mask mask)
|
||||
{
|
||||
for (uint32_t i = 0; i < GetNInterfaces (); i++)
|
||||
{
|
||||
for (uint32_t j = 0; j < GetNAddresses (i); j++)
|
||||
{
|
||||
Ipv4InterfaceAddress ipv4InAddr = GetAddress (i, j);
|
||||
if (ipv4InAddr.GetLocal ().CombineMask(mask) == addr.CombineMask(mask) )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mapping not found
|
||||
NS_ASSERT_MSG (false, "Ipv4::GetInterfaceByAddress failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
+94
-353
@@ -21,19 +21,18 @@
|
||||
#define IPV4_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/ipv4-interface-address.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/socket.h"
|
||||
#include "ns3/callback.h"
|
||||
#include "ipv4-route.h"
|
||||
#include "ipv4-routing-protocol.h"
|
||||
#include "ipv4-address.h"
|
||||
#include "ipv4-interface-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class NetDevice;
|
||||
class Packet;
|
||||
class Ipv4Route;
|
||||
class Ipv4Header;
|
||||
|
||||
/**
|
||||
* \ingroup node
|
||||
@@ -41,129 +40,35 @@ class Ipv4Header;
|
||||
*/
|
||||
|
||||
/**
|
||||
* \ingroup ipv4
|
||||
* \brief Access to the Ipv4 forwarding table, interfaces, and configuration
|
||||
*
|
||||
* \brief Base class for IPv4 routing protocols.
|
||||
*
|
||||
* This class represents the interface between the IPv4 routing core
|
||||
* and a specific IPv4 routing protocol. The interface is
|
||||
* asynchronous (callback based) in order to support reactive routing
|
||||
* protocols (e.g. AODV).
|
||||
*/
|
||||
class Ipv4RoutingProtocol : public Object
|
||||
{
|
||||
public:
|
||||
// void (*RouteReply) (bool found, Ipv4Route route, Packet packet, Ipv4Header const &ipHeader);
|
||||
|
||||
|
||||
/**
|
||||
* \brief Callback to be invoked when route discovery is completed
|
||||
*
|
||||
* \param bool flag indicating whether a route was actually found;
|
||||
* when this is false, the Ipv4Route parameter is ignored
|
||||
*
|
||||
* \param Ipv4Route the route found
|
||||
*
|
||||
* \param Packet the packet for which a route was requested; can be
|
||||
* modified by the routing protocol
|
||||
*
|
||||
* \param Ipv4Header the IP header supplied to the route request
|
||||
* method (possibly modified in case a new routing header is
|
||||
* inserted and consequently the protocol type has to change).
|
||||
*
|
||||
*/
|
||||
typedef Callback<void, bool, const Ipv4Route&, Ptr<Packet>, const Ipv4Header&> RouteReplyCallback;
|
||||
|
||||
/**
|
||||
* \brief Request that a packet be routed.
|
||||
*
|
||||
* \param interface The interface index on which the packet was received.
|
||||
* \param ipHeader IP header of the packet
|
||||
* \param packet packet that is being sent or forwarded
|
||||
* \param routeReply callback that will receive the route reply
|
||||
*
|
||||
* \returns true if the routing protocol should be able to get the
|
||||
* route, false otherwise.
|
||||
*
|
||||
* This method is called whenever a node's IPv4 forwarding engine
|
||||
* needs to lookup a route for a given packet and IP header.
|
||||
*
|
||||
* The routing protocol implementation may determine immediately it
|
||||
* should not be handling this particular the route request. For
|
||||
* instance, a routing protocol may decline to search for routes for
|
||||
* certain classes of addresses, like link-local. In this case,
|
||||
* RequestRoute() should return false and the routeReply callback
|
||||
* must not be invoked.
|
||||
*
|
||||
* If the routing protocol implementation assumes that it can provide
|
||||
* the requested route, then it should return true, and the
|
||||
* routeReply callback must be invoked, either immediately before
|
||||
* returning true (synchronously), or in the future (asynchronous).
|
||||
* The routing protocol may use any information available in the IP
|
||||
* header and packet as routing key, although most routing protocols
|
||||
* use only the destination address (as given by
|
||||
* ipHeader.GetDestination ()). The routing protocol is also
|
||||
* allowed to add a new header to the packet, which will appear
|
||||
* immediately after the IP header, although most routing do not
|
||||
* insert any extra header.
|
||||
*
|
||||
* Multicast routing is expected to be supported in this method. If a
|
||||
* multicast route is encountered, all routes to a given multicast
|
||||
* destination will be serviced by cloning the packet and calling the
|
||||
* route reply callback once for each outgoing interface in the route.
|
||||
*/
|
||||
virtual bool RequestRoute (uint32_t interface,
|
||||
const Ipv4Header &ipHeader,
|
||||
Ptr<Packet> packet,
|
||||
RouteReplyCallback routeReply) = 0;
|
||||
|
||||
/**
|
||||
* \brief Synchronously check to see if we can determine the interface index
|
||||
* that will be used if a packet is sent to this destination.
|
||||
*
|
||||
* This method addresses a problem in the IP stack where a destination address
|
||||
* must be present and checksummed into the IP header before the actual
|
||||
* interface over which the packet is sent can be determined. The answer is
|
||||
* to implement a known and intentional cross-layer violation. This is the
|
||||
* endpoint of a call chain that started up quite high in the stack (sockets)
|
||||
* and has found its way down to the Ipv4L3Protocol which is consulting the
|
||||
* routing protocols for what they would do if presented with a packet of the
|
||||
* given destination.
|
||||
*
|
||||
* Note that the a single interface index is returned. This means that if
|
||||
* the destination address is a multicast, and an explicit route is present
|
||||
* that includeds multiple output interfaces, that route cannot be used.
|
||||
* This class defines the API to manipulate the following aspects of
|
||||
* the Ipv4 implementation:
|
||||
* -# set/get an Ipv4RoutingProtocol
|
||||
* -# register a NetDevice for use by the Ipv4 layer (basically, to
|
||||
* create Ipv4-related state such as addressing and neighbor cache that
|
||||
* is associated with a NetDevice)
|
||||
* -# manipulate the status of the NetDevice from the Ipv4 perspective,
|
||||
* such as marking it as Up or Down,
|
||||
* -# adding, deleting, and getting addresses associated to the Ipv4
|
||||
* interfaces.
|
||||
* -# exporting Ipv4 configuration attributes
|
||||
*
|
||||
* If there are multiple paths out of the node, the resolution is performed
|
||||
* by Ipv4L3Protocol::GetInterfaceforDestination which has access to more
|
||||
* contextual information that is useful for making a determination.
|
||||
* Each NetDevice has conceptually a single Ipv4 interface associated
|
||||
* with it (the corresponding structure in the Linux Ipv4 implementation
|
||||
* is struct in_device). Each interface may have one or more Ipv4
|
||||
* addresses associated with it. Each Ipv4 address may have different
|
||||
* subnet mask, scope, etc., so all of this per-address information
|
||||
* is stored in an Ipv4InterfaceAddress class (the corresponding
|
||||
* structure in Linux is struct in_ifaddr)
|
||||
*
|
||||
* \param destination The Ipv4Address if the destination of a hypothetical
|
||||
* packet. This may be a multicast group address.
|
||||
* \param interface A reference to the interface index over which a packet
|
||||
* sent to this destination would be sent.
|
||||
* \return Returns true if a route is found to the destination that involves
|
||||
* a single output interface index, otherwise false.
|
||||
* Ipv4 attributes such as whether IP forwarding is enabled and disabled
|
||||
* are also stored in this class
|
||||
*
|
||||
* TO DO: Add API to allow access to the Ipv4 neighbor table
|
||||
*
|
||||
* \see Ipv4StaticRouting
|
||||
* \see Ipv4RoutingProtocol
|
||||
* \see Ipv4L3Protocol
|
||||
*/
|
||||
virtual bool RequestInterface (Ipv4Address destination,
|
||||
uint32_t& interface) = 0;
|
||||
|
||||
static const uint32_t INTERFACE_ANY = 0xffffffff;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Access to the Ipv4 forwarding table and to the ipv4 interfaces
|
||||
*
|
||||
* This class allows you to create ipv4 interfaces based on a NetDevice.
|
||||
* Multiple interfaces can be created for a single NetDevice, hence
|
||||
* achieving multihoming.
|
||||
*
|
||||
* This class also allows you to control the content of the ipv4
|
||||
* forwarding table.
|
||||
* \see Ipv4InterfaceAddress
|
||||
*/
|
||||
class Ipv4 : public Object
|
||||
{
|
||||
@@ -173,143 +78,27 @@ public:
|
||||
virtual ~Ipv4 ();
|
||||
|
||||
/**
|
||||
* \brief Register a new routing protocol to be used in this IPv4 stack
|
||||
* \brief Register a new routing protocol to be used by this Ipv4 stack
|
||||
*
|
||||
* This call will replace any routing protocol that has been previously
|
||||
* registered. If you want to add multiple routing protocols, you must
|
||||
* add them to a Ipv4ListRoutingProtocol directly.
|
||||
*
|
||||
* \param routingProtocol new routing protocol implementation object
|
||||
* \param priority priority to give to this routing protocol.
|
||||
* Values may range between -32768 and +32767. The priority 0
|
||||
* corresponds to static routing table lookups, higher values have
|
||||
* more priority. The order by which routing protocols with the
|
||||
* same priority value are consulted is undefined.
|
||||
* \param routing smart pointer to Ipv4RoutingProtocol object
|
||||
*/
|
||||
virtual void AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
|
||||
int16_t priority) = 0;
|
||||
|
||||
/**
|
||||
* \param dest destination address
|
||||
* \param nextHop address of next hop.
|
||||
* \param interface interface of next hop.
|
||||
*
|
||||
* Add route to host dest through host nextHop
|
||||
* on interface.
|
||||
*/
|
||||
virtual void AddHostRouteTo (Ipv4Address dest,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface) = 0;
|
||||
/**
|
||||
* \param dest destination address
|
||||
* \param interface of next hop
|
||||
*
|
||||
* add route to host dest on interface.
|
||||
*/
|
||||
virtual void AddHostRouteTo (Ipv4Address dest,
|
||||
uint32_t interface) = 0;
|
||||
virtual void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol) = 0;
|
||||
|
||||
/**
|
||||
* \param network destination network
|
||||
* \param networkMask netmask of destination network
|
||||
* \param nextHop address of next hop
|
||||
* \param interface interface of next hop
|
||||
* \brief Get the routing protocol to be used by this Ipv4 stack
|
||||
*
|
||||
* add route to network dest with netmask
|
||||
* through host nextHop on interface
|
||||
* \returns smart pointer to Ipv4RoutingProtocol object, or null pointer if none
|
||||
*/
|
||||
virtual void AddNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
Ipv4Address nextHop,
|
||||
uint32_t interface) = 0;
|
||||
virtual Ptr<Ipv4RoutingProtocol> GetRoutingProtocol (void) const = 0;
|
||||
|
||||
/**
|
||||
* \param network destination network
|
||||
* \param networkMask netmask of destination network
|
||||
* \param interface interface of next hop
|
||||
*
|
||||
* add route to network dest with netmask
|
||||
* on interface
|
||||
*/
|
||||
virtual void AddNetworkRouteTo (Ipv4Address network,
|
||||
Ipv4Mask networkMask,
|
||||
uint32_t interface) = 0;
|
||||
/**
|
||||
* \param nextHop address of default next hop
|
||||
* \param interface interface of default next hop.
|
||||
*
|
||||
* set the default route to host nextHop on
|
||||
* interface.
|
||||
*/
|
||||
virtual void SetDefaultRoute (Ipv4Address nextHop,
|
||||
uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \returns the number of entries in the routing table.
|
||||
*/
|
||||
virtual uint32_t GetNRoutes (void) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of route to return
|
||||
* \returns the route whose index is i
|
||||
*/
|
||||
virtual Ipv4Route GetRoute (uint32_t i) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of route to remove from routing table.
|
||||
*/
|
||||
virtual void RemoveRoute (uint32_t i) = 0;
|
||||
|
||||
/**
|
||||
* \brief Add a static multicast route for a given multicast source and
|
||||
* group.
|
||||
*
|
||||
* \param origin The Ipv4 address of the multicast source.
|
||||
* \param group The multicast group address.
|
||||
* \param inputInterface The interface index over which the packet arrived.
|
||||
* \param outputInterfaces The list of output interface indices over which
|
||||
* the packet should be sent (excluding the inputInterface).
|
||||
*/
|
||||
virtual void AddMulticastRoute (Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface,
|
||||
std::vector<uint32_t> outputInterfaces) = 0;
|
||||
/**
|
||||
* \brief Remove a static multicast route for a given multicast source and
|
||||
* group.
|
||||
*
|
||||
* \param origin The Ipv4 address of the multicast source.
|
||||
* \param group The multicast group address.
|
||||
* \param inputInterface The interface index over which the packet arrived.
|
||||
*/
|
||||
virtual void RemoveMulticastRoute (Ipv4Address origin,
|
||||
Ipv4Address group,
|
||||
uint32_t inputInterface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Set the default static multicast route.
|
||||
*
|
||||
* \param outputInterface The network output interface index over which
|
||||
* packets without specific routes should be sent.
|
||||
*/
|
||||
virtual void SetDefaultMulticastRoute (uint32_t outputInterface) = 0;
|
||||
|
||||
/**
|
||||
* \returns the number of entries in the multicast routing table.
|
||||
*/
|
||||
virtual uint32_t GetNMulticastRoutes (void) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of route to return
|
||||
* \returns the route whose index is i
|
||||
*/
|
||||
virtual Ipv4MulticastRoute GetMulticastRoute (uint32_t i) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of route to remove from routing table.
|
||||
*/
|
||||
virtual void RemoveMulticastRoute (uint32_t i) = 0;
|
||||
|
||||
/**
|
||||
* \param device device to add to the list of ipv4 interfaces
|
||||
* \param device device to add to the list of Ipv4 interfaces
|
||||
* which can be used as output interfaces during packet forwarding.
|
||||
* \returns the index of the ipv4 interface added.
|
||||
* \returns the index of the Ipv4 interface added.
|
||||
*
|
||||
* Once a device has been added, it can never be removed: if you want
|
||||
* to disable it, you can invoke Ipv4::SetDown which will
|
||||
@@ -323,73 +112,50 @@ public:
|
||||
virtual uint32_t GetNInterfaces (void) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Find and return the interface ID of the interface that has been
|
||||
* \brief Return the interface number of the interface that has been
|
||||
* assigned the specified IP address.
|
||||
* \param addr The IP address assigned to the interface of interest.
|
||||
* \returns The index of the ipv4 interface with the given address.
|
||||
*
|
||||
* Each IP interface has an IP address associated with it. It is often
|
||||
* useful to search the list of interfaces for one that corresponds to
|
||||
* a known IP Address. This call takes an IP address as a parameter and
|
||||
* returns the interface index of the first interface that has been assigned
|
||||
* that address. If the address is not found, this function asserts.
|
||||
* \param address The IP address being searched for
|
||||
* \returns The interface number of the Ipv4 interface with the given
|
||||
* address or -1 if not found.
|
||||
*
|
||||
* Each IP interface has one or more IP addresses associated with it.
|
||||
* This method searches the list of interfaces for one that holds a
|
||||
* particular address. This call takes an IP address as a parameter and
|
||||
* returns the interface number of the first interface that has been assigned
|
||||
* that address, or -1 if not found. There must be an exact match.
|
||||
*/
|
||||
virtual uint32_t FindInterfaceForAddr (Ipv4Address addr) const = 0;
|
||||
virtual int32_t GetInterfaceForAddress (Ipv4Address address) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Find and return the interface ID of the interface that has been
|
||||
* assigned the specified (masked) IP address.
|
||||
* \param addr The IP address assigned to the interface of interest.
|
||||
* \param mask The address mask to be used in address matching.
|
||||
* \returns The index of the ipv4 interface with the given address.
|
||||
* \brief Return the interface number of first interface found that
|
||||
* has an Ipv4 address within the prefix specified by the input
|
||||
* address and mask parameters
|
||||
*
|
||||
* Each IP interface has an IP address associated with it. It is often
|
||||
* useful to search the list of interfaces for one that corresponds to
|
||||
* a known IP Address. This call takes an IP address and an IP address
|
||||
* mask as parameters and returns the interface index of the first interface
|
||||
* that matches the masked IP address.
|
||||
* \param addr The IP address assigned to the interface of interest.
|
||||
* \returns The interface number of the Ipv4 interface with the given
|
||||
* address or -1 if not found.
|
||||
*
|
||||
* Each IP interface has one or more IP addresses associated with it.
|
||||
* This method searches the list of interfaces for the first one found
|
||||
* that holds an address that is included within the prefix
|
||||
* formed by the input address and mask parameters. The value -1 is
|
||||
* returned if no match is found.
|
||||
*/
|
||||
virtual uint32_t FindInterfaceForAddr (Ipv4Address addr,
|
||||
virtual int32_t GetInterfaceForPrefix (Ipv4Address address,
|
||||
Ipv4Mask mask) const = 0;
|
||||
|
||||
/**
|
||||
* \brief Find and return the interface ID of the interface that has been
|
||||
* associated with the specified (masked) NetDevice
|
||||
* \param nd The net device of the interface of interest.
|
||||
* \returns The index of the ipv4 interface associated with the given net
|
||||
* device or -1 if not found.
|
||||
*
|
||||
* Each IP interface is associated with a net device. It is often
|
||||
* useful to search the list of interfaces for one that corresponds to
|
||||
* a known net device. This call takes an smart pointer to a net device
|
||||
* and returns the interface index of the first interface that matches the
|
||||
* net device.
|
||||
* \param interface The interface number of an Ipv4 interface.
|
||||
* \returns The NetDevice associated with the Ipv4 interface number.
|
||||
*/
|
||||
virtual int32_t FindInterfaceForDevice(Ptr<NetDevice> nd) const = 0;
|
||||
virtual Ptr<NetDevice> GetNetDevice (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \returns the NetDevice associated with the ipv4 interface index
|
||||
* \param device The NetDevice for an Ipv4Interface
|
||||
* \returns The interface number of an Ipv4 interface or -1 if not found.
|
||||
*/
|
||||
virtual Ptr<NetDevice> GetNetDevice (uint32_t i) = 0;
|
||||
|
||||
/**
|
||||
* \brief Join a multicast group for a given multicast source and
|
||||
* group.
|
||||
*
|
||||
* \param origin The Ipv4 address of the multicast source.
|
||||
* \param group The multicast group address.
|
||||
*/
|
||||
virtual void JoinMulticastGroup (Ipv4Address origin, Ipv4Address group) = 0;
|
||||
|
||||
/**
|
||||
* \brief Leave a multicast group for a given multicast source and
|
||||
* group.
|
||||
*
|
||||
* \param origin The Ipv4 address of the multicast source.
|
||||
* \param group The multicast group address.
|
||||
*/
|
||||
virtual void LeaveMulticastGroup (Ipv4Address origin, Ipv4Address group) = 0;
|
||||
virtual int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const = 0;
|
||||
|
||||
/**
|
||||
* \param interface Interface number of an Ipv4 interface
|
||||
@@ -406,86 +172,61 @@ public:
|
||||
|
||||
/**
|
||||
* \param interface Interface number of an Ipv4 interface
|
||||
* \param addressIndex index of Ipv4InterfaceAddress
|
||||
* \param addressIndex index of Ipv4InterfaceAddress
|
||||
* \returns the Ipv4InterfaceAddress associated to the interface and addresIndex
|
||||
*/
|
||||
virtual Ipv4InterfaceAddress GetAddress (uint32_t interface, uint32_t addressIndex) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param interface The interface number of an Ipv4 interface
|
||||
* \param metric routing metric (cost) associated to the underlying
|
||||
* ipv4 interface
|
||||
* Ipv4 interface
|
||||
*/
|
||||
virtual void SetMetric (uint32_t i, uint16_t metric) = 0;
|
||||
virtual void SetMetric (uint32_t interface, uint16_t metric) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param interface The interface number of an Ipv4 interface
|
||||
* \returns routing metric (cost) associated to the underlying
|
||||
* ipv4 interface
|
||||
* Ipv4 interface
|
||||
*/
|
||||
virtual uint16_t GetMetric (uint32_t i) const = 0;
|
||||
virtual uint16_t GetMetric (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param destination The IP address of a hypothetical destination.
|
||||
* \returns The IP address assigned to the interface that will be used
|
||||
* if we were to send a packet to destination.
|
||||
*
|
||||
* Note that the broadcast address for this interface may be fetched
|
||||
* from the Ipv4Address object returned here using
|
||||
* Ipv4Address::GetSubnetDirectedBroadcast(mask), where the mask for
|
||||
* the interface may be retrived using Ipv4::GetNetworkMask(i).
|
||||
*/
|
||||
virtual Ipv4Address GetSourceAddress (Ipv4Address destination) const = 0;
|
||||
|
||||
/**
|
||||
* \param dest The IP address of a hypothetical destination.
|
||||
* \param interface filled in with the interface index that will be used to
|
||||
* send a packet to the hypothetical destination.
|
||||
* \returns true if a single interface can be identified, false otherwise.
|
||||
*/
|
||||
virtual bool GetInterfaceForDestination (Ipv4Address dest,
|
||||
uint32_t &interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param interface Interface number of Ipv4 interface
|
||||
* \returns the Maximum Transmission Unit (in bytes) associated
|
||||
* to the underlying ipv4 interface
|
||||
* to the underlying Ipv4 interface
|
||||
*/
|
||||
virtual uint16_t GetMtu (uint32_t i) const = 0;
|
||||
virtual uint16_t GetMtu (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param interface Interface number of Ipv4 interface
|
||||
* \returns true if the underlying interface is in the "up" state,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool IsUp (uint32_t i) const = 0;
|
||||
virtual bool IsUp (uint32_t interface) const = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param i interface Interface number of Ipv4 interface
|
||||
*
|
||||
* Set the interface into the "up" state. In this state, it is
|
||||
* considered valid during ipv4 forwarding.
|
||||
* considered valid during Ipv4 forwarding.
|
||||
*/
|
||||
virtual void SetUp (uint32_t i) = 0;
|
||||
virtual void SetUp (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \param i index of ipv4 interface
|
||||
* \param interface Interface number of Ipv4 interface
|
||||
*
|
||||
* Set the interface into the "down" state. In this state, it is
|
||||
* ignored during ipv4 forwarding.
|
||||
* ignored during Ipv4 forwarding.
|
||||
*/
|
||||
virtual void SetDown (uint32_t i) = 0;
|
||||
virtual void SetDown (uint32_t interface) = 0;
|
||||
|
||||
/**
|
||||
* \brief Convenience function to return the interface corresponding
|
||||
* to the Ipv4Address provided
|
||||
*
|
||||
* \param addr Ipv4Address
|
||||
* \param mask corresponding Ipv4Mask
|
||||
* \returns interface corresponding to a/amask
|
||||
*/
|
||||
virtual uint32_t GetInterfaceByAddress (Ipv4Address addr,
|
||||
Ipv4Mask mask = Ipv4Mask("255.255.255.255"));
|
||||
static const uint32_t IF_ANY = 0xffffffff;
|
||||
|
||||
private:
|
||||
// Indirect the Ipv4 attributes through private pure virtual methods
|
||||
virtual void SetIpForward (bool forward) = 0;
|
||||
virtual bool GetIpForward (void) const = 0;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
+15
-2
@@ -21,6 +21,7 @@
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/uinteger.h"
|
||||
#include "ns3/integer.h"
|
||||
#include "ns3/boolean.h"
|
||||
#include "ns3/trace-source-accessor.h"
|
||||
#include "udp-socket.h"
|
||||
@@ -47,13 +48,25 @@ UdpSocket::GetTypeId (void)
|
||||
UintegerValue (0),
|
||||
MakeUintegerAccessor (&UdpSocket::GetIpTtl,
|
||||
&UdpSocket::SetIpTtl),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
MakeUintegerChecker<uint8_t> ())
|
||||
.AddAttribute ("IpMulticastTtl",
|
||||
"socket-specific TTL for multicast IP packets (if non-zero)",
|
||||
UintegerValue (0),
|
||||
MakeUintegerAccessor (&UdpSocket::GetIpMulticastTtl,
|
||||
&UdpSocket::SetIpMulticastTtl),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
MakeUintegerChecker<uint8_t> ())
|
||||
.AddAttribute ("IpMulticastIf",
|
||||
"interface index for outgoing multicast on this socket; -1 indicates to use default interface",
|
||||
IntegerValue (-1),
|
||||
MakeUintegerAccessor (&UdpSocket::GetIpMulticastTtl,
|
||||
&UdpSocket::SetIpMulticastTtl),
|
||||
MakeIntegerChecker<int32_t> ())
|
||||
.AddAttribute ("IpMulticastLoop",
|
||||
"whether outgoing multicast sent also to loopback interface",
|
||||
BooleanValue (false),
|
||||
MakeUintegerAccessor (&UdpSocket::GetIpMulticastLoop,
|
||||
&UdpSocket::SetIpMulticastLoop),
|
||||
MakeBooleanChecker ())
|
||||
.AddAttribute ("MtuDiscover", "If enabled, every outgoing ip packet will have the DF flag set.",
|
||||
BooleanValue (false),
|
||||
MakeBooleanAccessor (&UdpSocket::SetMtuDiscover,
|
||||
|
||||
+56
-5
@@ -40,7 +40,8 @@ class Packet;
|
||||
* \brief (abstract) base class of all UdpSockets
|
||||
*
|
||||
* This class exists solely for hosting UdpSocket attributes that can
|
||||
* be reused across different implementations.
|
||||
* be reused across different implementations, and for declaring
|
||||
* UDP-specific multicast API.
|
||||
*/
|
||||
class UdpSocket : public Socket
|
||||
{
|
||||
@@ -50,14 +51,64 @@ public:
|
||||
UdpSocket (void);
|
||||
virtual ~UdpSocket (void);
|
||||
|
||||
/**
|
||||
* \brief Corresponds to socket option MCAST_JOIN_GROUP
|
||||
*
|
||||
* \param interface interface number, or 0
|
||||
* \param groupAddress multicast group address
|
||||
* \returns on success, zero is returned. On error, -1 is returned,
|
||||
* and errno is set appropriately
|
||||
*
|
||||
* Enable reception of multicast datagrams for this socket on the
|
||||
* interface number specified. If zero is specified as
|
||||
* the interface, then a single local interface is chosen by
|
||||
* system. In the future, this function will generate trigger IGMP
|
||||
* joins as necessary when IGMP is implemented, but for now, this
|
||||
* just enables multicast datagram reception in the system if not already
|
||||
* enabled for this interface/groupAddress combination.
|
||||
*
|
||||
* \attention IGMP is not yet implemented in ns-3
|
||||
*
|
||||
* This function may be called repeatedly on a given socket but each
|
||||
* join must be for a different multicast address, or for the same
|
||||
* multicast address but on a different interface from previous joins.
|
||||
* This enables host multihoming, and the ability to join the same
|
||||
* group on different interfaces.
|
||||
*/
|
||||
virtual int MulticastJoinGroup (uint32_t interface, const Address &groupAddress) = 0;
|
||||
|
||||
/**
|
||||
* \brief Corresponds to socket option MCAST_LEAVE_GROUP
|
||||
*
|
||||
* \param interface interface number, or 0
|
||||
* \param groupAddress multicast group address
|
||||
* \returns on success, zero is returned. On error, -1 is returned,
|
||||
* and errno is set appropriately
|
||||
*
|
||||
* Disable reception of multicast datagrams for this socket on the
|
||||
* interface number specified. If zero is specified as
|
||||
* the interfaceIndex, then a single local interface is chosen by
|
||||
* system. In the future, this function will generate trigger IGMP
|
||||
* leaves as necessary when IGMP is implemented, but for now, this
|
||||
* just disables multicast datagram reception in the system if this
|
||||
* socket is the last for this interface/groupAddress combination.
|
||||
*
|
||||
* \attention IGMP is not yet implemented in ns-3
|
||||
*/
|
||||
virtual int MulticastLeaveGroup (uint32_t interface, const Address &groupAddress) = 0;
|
||||
|
||||
private:
|
||||
// Indirect the attribute setting and getting through private virtual methods
|
||||
virtual void SetRcvBufSize (uint32_t size) = 0;
|
||||
virtual uint32_t GetRcvBufSize (void) const = 0;
|
||||
virtual void SetIpTtl (uint32_t ipTtl) = 0;
|
||||
virtual uint32_t GetIpTtl (void) const = 0;
|
||||
virtual void SetIpMulticastTtl (uint32_t ipTtl) = 0;
|
||||
virtual uint32_t GetIpMulticastTtl (void) const = 0;
|
||||
virtual void SetIpTtl (uint8_t ipTtl) = 0;
|
||||
virtual uint8_t GetIpTtl (void) const = 0;
|
||||
virtual void SetIpMulticastTtl (uint8_t ipTtl) = 0;
|
||||
virtual uint8_t GetIpMulticastTtl (void) const = 0;
|
||||
virtual void SetIpMulticastIf (int32_t ipIf) = 0;
|
||||
virtual int32_t GetIpMulticastIf (void) const = 0;
|
||||
virtual void SetIpMulticastLoop (bool loop) = 0;
|
||||
virtual bool GetIpMulticastLoop (void) const = 0;
|
||||
virtual void SetMtuDiscover (bool discover) = 0;
|
||||
virtual bool GetMtuDiscover (void) const = 0;
|
||||
};
|
||||
|
||||
@@ -19,6 +19,10 @@ def build(bld):
|
||||
'ethernet-header.cc',
|
||||
'ethernet-trailer.cc',
|
||||
'ipv4-route.cc',
|
||||
'ipv4-routing-protocol.cc',
|
||||
'ipv4-list-routing.cc',
|
||||
'ipv4-static-routing.cc',
|
||||
'ipv4-routing-table-entry.cc',
|
||||
'queue.cc',
|
||||
'drop-tail-queue.cc',
|
||||
'channel.cc',
|
||||
@@ -52,11 +56,16 @@ def build(bld):
|
||||
'packet-socket-address.h',
|
||||
'node.h',
|
||||
'ipv4-address.h',
|
||||
'ipv4-interface-address.h',
|
||||
'ipv4-address-generator.h',
|
||||
'ipv4-header.h',
|
||||
'net-device.h',
|
||||
'address-utils.h',
|
||||
'ipv4-route.h',
|
||||
'ipv4-routing-protocol.h',
|
||||
'ipv4-list-routing.h',
|
||||
'ipv4-static-routing.h',
|
||||
'ipv4-routing-table-entry.h',
|
||||
'queue.h',
|
||||
'drop-tail-queue.h',
|
||||
'llc-snap-header.h',
|
||||
|
||||
Reference in new issue
Block a user