24 #include "ns3/packet.h"
25 #include "ns3/simulator.h"
26 #include "ns3/ipv6-route.h"
27 #include "ns3/net-device.h"
29 #include "ipv6-static-routing.h"
30 #include "ipv6-routing-table-entry.h"
35 NS_OBJECT_ENSURE_REGISTERED (Ipv6StaticRouting);
41 .AddConstructor<Ipv6StaticRouting> ()
64 for (i = 0; i <
m_ipv6->GetNInterfaces (); i++)
85 *os <<
"Node: " <<
m_ipv6->GetObject<
Node> ()->GetId ()
87 <<
"Ipv6StaticRouting table" << std::endl;
92 *os << route << std::endl;
99 NS_LOG_FUNCTION (
this << dst << nextHop << interface << prefixToUse << metric);
111 NS_LOG_FUNCTION (
this << network << networkPrefix << nextHop << interface << metric);
119 NS_LOG_FUNCTION (
this << network << networkPrefix << nextHop << interface << prefixToUse << metric);
243 uint16_t longestMask = 0;
244 uint32_t shortestMetric = 0xffffffff;
250 NS_ASSERT_MSG (interface,
"Try to send on link-local multicast address, and no interface index is given!");
251 rtentry = Create<Ipv6Route> ();
253 rtentry->SetDestination (dst);
255 rtentry->SetOutputDevice (interface);
262 uint32_t metric = it->second;
267 NS_LOG_LOGIC (
"Searching for route to " << dst <<
", mask length " << maskLen <<
", metric " << metric);
271 NS_LOG_LOGIC (
"Found global network route " << j <<
", mask length " << maskLen <<
", metric " << metric);
276 if (maskLen < longestMask)
282 if (maskLen > longestMask)
284 shortestMetric = 0xffffffff;
287 longestMask = maskLen;
288 if (metric > shortestMetric)
290 NS_LOG_LOGIC (
"Equal mask length, but previous metric shorter, skipping");
294 shortestMetric = metric;
297 rtentry = Create<Ipv6Route> ();
312 rtentry->SetDestination (route->
GetDest ());
314 rtentry->SetOutputDevice (
m_ipv6->GetNetDevice (interfaceIdx));
321 NS_LOG_LOGIC (
"Matching route via " << rtentry->GetDestination () <<
" (throught " << rtentry->GetGateway () <<
") at the end");
368 NS_LOG_LOGIC (
"Find source specific multicast route" << *i);
376 mrtentry = Create<Ipv6MulticastRoute> ();
377 mrtentry->SetGroup (route->
GetGroup ());
378 mrtentry->SetOrigin (route->
GetOrigin ());
404 uint32_t shortestMetric = 0xffffffff;
410 uint32_t metric = it->second;
420 if (metric > shortestMetric)
424 shortestMetric = metric;
529 sockerr = Socket::ERROR_NOTERROR;
533 sockerr = Socket::ERROR_NOROUTETOHOST;
546 uint32_t iif =
m_ipv6->GetInterfaceForDevice (idev);
558 mcb (mrtentry, p, header);
574 for (uint32_t j = 0; j <
m_ipv6->GetNInterfaces (); j++)
576 for (uint32_t i = 0; i <
m_ipv6->GetNAddresses (j); i++)
584 NS_LOG_LOGIC (
"For me (destination " << addr <<
" match)");
590 lcb (p, header, iif);
597 if (
m_ipv6->IsForwarding (iif) ==
false)
599 NS_LOG_LOGIC (
"Forwarding disabled for this interface");
600 ecb (p, header, Socket::ERROR_NOROUTETOHOST);
609 NS_LOG_LOGIC (
"Found unicast destination- calling unicast callback");
610 ucb (rtentry, p, header);
615 NS_LOG_LOGIC (
"Did not find unicast destination- returning false");
622 for (uint32_t j = 0; j <
m_ipv6->GetNAddresses (i); j++)
635 m_ipv6->GetAddress (i, j).GetPrefix (), i);
665 if (!
m_ipv6->IsUp (interface))
681 if (!
m_ipv6->IsUp (interface))
707 NS_LOG_INFO (
this << dst << mask << nextHop << interface << prefixToUse);
737 if (dst == entry && prefix == mask && rtentry->
GetInterface () == interface)
757 ret =
m_ipv6->GetAddress (interface, 0).GetAddress ();
766 for (uint32_t i = 1; i <
m_ipv6->GetNAddresses (interface); i++)
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
bool IsAny() const
If the IPv6 address is the "Any" address.
static const uint32_t MAX_TTL
Maximum Time-To-Live (TTL).
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
Ipv6Address GetPrefixToUse() const
Get the prefix to use (for multihomed link).
virtual ~Ipv6StaticRouting()
Destructor.
NetworkRoutes m_networkRoutes
the forwarding table for network.
bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface)
Remove a static multicast route.
Ipv6Prefix GetDestNetworkPrefix() const
Get the destination prefix.
static Ipv6RoutingTableEntry CreateNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface)
Create a route to a network.
virtual void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify route removing.
virtual void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
A record of an IPv6 multicast route.
Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)
Choose the source address to use with destination address.
virtual void SetIpv6(Ptr< Ipv6 > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
virtual Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
uint32_t GetInputInterface() const
Get the input interface address.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
IPv6 address associated with an interface.
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
virtual void DoDispose(void)
#define NS_LOG_FUNCTION_NOARGS()
uint32_t GetNOutputInterfaces() const
Get the number of output interfaces of this route.
static Ipv6MulticastRoutingTableEntry CreateMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Create a multicast route.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
uint32_t GetNMulticastRoutes() const
Get the number of entries in the multicast routing table.
void AddHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Add route to host.
static TypeId GetTypeId()
The interface Id associated with this class.
double GetSeconds(void) const
Ipv6Address GetDestNetwork() const
Get the destination network.
Ipv6Address GetAddress() const
Get the IPv6 address.
A record of an IPv6 route.
Ptr< Ipv6 > m_ipv6
Ipv6 reference.
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
virtual void NotifyInterfaceDown(uint32_t interface)
Notify when specified interface goes DOWN.
Ptr< Ipv6Route > LookupStatic(Ipv6Address dest, Ptr< NetDevice >=0)
Lookup in the forwarding table for destination.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
void AddMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route for a given multicast source and group.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Ipv6Address GetOrigin() const
Get the source of this route.
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric=0)
Add route to network.
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
virtual void NotifyInterfaceUp(uint32_t interface)
Notify when specified interface goes UP.
#define NS_LOG_LOGIC(msg)
static Ipv6Address GetAllHostsMulticast()
Get the "all hosts multicast" address.
uint32_t GetOutputInterface(uint32_t n) const
Get a specified output interface.
static const uint32_t IF_ANY
Any interface magic number.
Ipv6RoutingTableEntry GetDefaultRoute()
Get the default route.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
Ipv6Address GetGateway() const
Get the gateway.
uint32_t GetInterface() const
Get the interface index.
Ipv6StaticRouting()
Constructor.
Ipv6RoutingTableEntry GetRoute(uint32_t i) const
Get a specified route.
#define NS_ASSERT_MSG(condition, message)
Describes an IPv6 address.
void RemoveRoute(uint32_t i)
Remove a route from the routing table.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
void SetDefaultRoute(Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Set the default route.
Ipv6Address GetGroup() const
Get the group.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
Ipv6Address GetDest() const
Get the destination.
virtual void DoDispose()
Dispose this object.
void SetDefaultMulticastRoute(uint32_t outputInterface)
Set the default multicast route.
bool IsNetwork() const
Is the route entry correspond to a network ?
virtual void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address)
Notify when specified interface add an address.
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
uint8_t GetPrefixLength() const
Get prefix length.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
uint32_t GetNRoutes() const
Get the number or entries in the routing table.
Ipv6MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get the specified multicast route.
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix)
Combine this address with a prefix.
Abstract base class for Ipv6 routing protocols.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
std::ostream * GetStream(void)
bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex)
If the destination is already present in network destination list.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.