16#include "ns3/net-device.h"
18#include "ns3/packet.h"
19#include "ns3/simulator.h"
35 .SetGroupName(
"Internet")
77 std::ostream* os = stream->GetStream();
79 std::ios oldState(
nullptr);
80 oldState.copyfmt(*os);
82 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
86 <<
", Ipv6StaticRouting table" << std::endl;
90 *os <<
"Destination Next Hop Flag Met Ref Use If"
94 std::ostringstream dest;
95 std::ostringstream gw;
96 std::ostringstream mask;
97 std::ostringstream flags;
100 *os << std::setw(31) << dest.str();
102 *os << std::setw(27) << gw.str();
112 *os << std::setw(5) << flags.str();
133 (*os).copyfmt(oldState);
143 NS_LOG_FUNCTION(
this << dst << nextHop << interface << prefixToUse << metric);
146 NS_LOG_WARN(
"Ipv6StaticRouting::AddHostRouteTo - Next hop should be link-local");
166 NS_LOG_FUNCTION(
this << network << networkPrefix << nextHop << interface << metric);
186 NS_LOG_FUNCTION(
this << network << networkPrefix << nextHop << interface << prefixToUse
190 NS_LOG_WARN(
"Ipv6StaticRouting::AddNetworkRouteTo - Next hop should be link-local");
241 std::vector<uint32_t> outputInterfaces)
275 "Ipv6StaticRouting::GetMulticastRoute () : Index out of range");
376 uint16_t longestMask = 0;
377 uint32_t shortestMetric = 0xffffffff;
384 "Try to send on link-local multicast address, and no interface index is given!");
388 rtentry->SetDestination(dst);
390 rtentry->SetOutputDevice(interface);
402 NS_LOG_LOGIC(
"Searching for route to " << dst <<
", mask length " << maskLen <<
", metric "
407 NS_LOG_LOGIC(
"Found global network route " << *j <<
", mask length " << maskLen
408 <<
", metric " << metric);
413 if (maskLen < longestMask)
419 if (maskLen > longestMask)
421 shortestMetric = 0xffffffff;
424 longestMask = maskLen;
425 if (metric > shortestMetric)
427 NS_LOG_LOGIC(
"Equal mask length, but previous metric shorter, skipping");
431 shortestMetric = metric;
449 rtentry->SetDestination(route->
GetDest());
462 NS_LOG_LOGIC(
"Matching route via " << rtentry->GetDestination() <<
" (Through "
463 << rtentry->GetGateway() <<
") at the end");
513 NS_LOG_LOGIC(
"Find source specific multicast route" << *i);
522 mrtentry->SetGroup(route->
GetGroup());
553 uint32_t shortestMetric = 0xffffffff;
569 if (metric > shortestMetric)
573 shortestMetric = metric;
726 mcb(idev, mrtentry, p, header);
752 NS_LOG_LOGIC(
"Found unicast destination- calling unicast callback");
753 ucb(idev, rtentry, p, header);
758 NS_LOG_LOGIC(
"Did not find unicast destination- returning false");
798 if (it->first->GetInterface() == i)
827 Ipv6Address networkAddress = address.GetAddress().CombinePrefix(address.GetPrefix());
834 if (it->first->GetInterface() ==
interface && it->first->IsNetwork() &&
835 it->first->GetDestNetwork() == networkAddress &&
836 it->first->GetDestNetworkPrefix() == networkMask)
855 NS_LOG_FUNCTION(
this << dst << mask << nextHop << interface << prefixToUse);
894 if (dst == entry && prefix == mask && rtentry->
GetInterface() == interface)
bool IsNull() const
Check for null implementation.
Describes an IPv6 address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
bool IsAny() const
If the IPv6 address is the "Any" address.
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
virtual Ipv6InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Get IPv6 address on specified IPv6 interface.
virtual Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)=0
Choose the source address to use with destination address.
static const uint32_t IF_ANY
Any interface magic number.
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
Get the interface index of the specified NetDevice.
virtual uint32_t GetNInterfaces() const =0
Get number of interfaces.
virtual bool IsUp(uint32_t interface) const =0
If the specified interface index is in "up" state.
virtual bool IsForwarding(uint32_t interface) const =0
If the specified IPv6 interface has forwarding enabled.
virtual uint32_t GetNAddresses(uint32_t interface) const =0
Get number of addresses on specified IPv6 interface.
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
Get the NetDevice of the specified interface number.
IPv6 address associated with an interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.
bool GetOnLink() const
Get the on-link property.
static const uint32_t MAX_TTL
Maximum Time-To-Live (TTL).
A record of an IPv6 multicast route.
uint32_t GetInputInterface() const
Get the input interface address.
uint32_t GetOutputInterface(uint32_t n) const
Get a specified output interface.
Ipv6Address GetGroup() const
Get the group.
static Ipv6MulticastRoutingTableEntry CreateMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Create a multicast route.
uint32_t GetNOutputInterfaces() const
Get the number of output interfaces of this route.
Ipv6Address GetOrigin() const
Get the source of this route.
Describes an IPv6 prefix.
uint8_t GetPrefixLength() const
Get prefix length.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
Abstract base class for IPv6 routing protocols.
A record of an IPv6 route.
Ipv6Address GetDest() const
Get the destination.
Ipv6Address GetDestNetwork() const
Get the destination network.
Ipv6Address GetPrefixToUse() const
Get the prefix to use (for multihomed link).
bool IsHost() const
Is the route entry correspond to a host ?
uint32_t GetInterface() const
Get the interface index.
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.
Ipv6Address GetGateway() const
Get the gateway.
bool IsGateway() const
Is it the gateway ?
Static routing protocol for IP version 6 stacks.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Ipv6RoutingTableEntry GetRoute(uint32_t i) const
Get a specified route.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
~Ipv6StaticRouting() override
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
void RemoveRoute(uint32_t i)
Remove a route from the routing table.
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
static TypeId GetTypeId()
The interface Id associated with this class.
Ptr< Ipv6Route > LookupStatic(Ipv6Address dest, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex)
If the destination is already present in network destination list.
bool LookupRoute(const Ipv6RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
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.
void AddHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Add route to host.
uint32_t GetNRoutes() const
Get the number or entries in the routing table.
Ipv6MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get the specified multicast route.
Ipv6RoutingTableEntry GetDefaultRoute()
Get the default route.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
uint32_t GetNMulticastRoutes() const
Get the number of entries in the multicast routing table.
bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface)
Remove a static multicast route.
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
void DoDispose() override
Dispose this object.
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric=0)
Add route to network.
NetworkRoutes m_networkRoutes
the forwarding table for network.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void SetDefaultMulticastRoute(uint32_t outputInterface)
Set the default multicast route.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) override
Route an input packet (to be forwarded or locally delivered)
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Ptr< Ipv6 > m_ipv6
Ipv6 reference.
void SetDefaultRoute(Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Set the default route.
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
SocketErrno
Enumeration of the possible errors returned by a socket.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Unit
The unit to use to interpret a number representing time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.