21 #define NS_LOG_APPEND_CONTEXT \ 22 if (m_ipv4 && m_ipv4->GetObject<Node> ()) { \ 23 std::clog << Simulator::Now ().GetSeconds () \ 24 << " [node " << m_ipv4->GetObject<Node> ()->GetId () << "] "; } 28 #include "ns3/names.h" 29 #include "ns3/packet.h" 31 #include "ns3/simulator.h" 32 #include "ns3/ipv4-route.h" 33 #include "ns3/output-stream-wrapper.h" 50 .SetGroupName (
"Internet")
69 NS_LOG_FUNCTION (
this << network <<
" " << networkMask <<
" " << nextHop <<
" " << interface <<
" " << metric);
89 NS_LOG_FUNCTION (
this << network <<
" " << networkMask <<
" " << interface <<
" " << metric);
108 NS_LOG_FUNCTION (
this << dest <<
" " << nextHop <<
" " << interface <<
" " << metric);
126 NS_LOG_FUNCTION (
this << nextHop <<
" " << interface <<
" " << metric);
133 uint32_t inputInterface,
134 std::vector<uint32_t> outputInterfaces)
136 NS_LOG_FUNCTION (
this << origin <<
" " << group <<
" " << inputInterface <<
" " << &outputInterfaces);
139 inputInterface, outputInterfaces);
171 "Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
193 uint32_t inputInterface)
195 NS_LOG_FUNCTION (
this << origin <<
" " << group <<
" " << inputInterface);
256 uint16_t longest_mask = 0;
257 uint32_t shortest_metric = 0xffffffff;
261 NS_ASSERT_MSG (oif,
"Try to send on link-local multicast address, and no interface index is given!");
263 rtentry = Create<Ipv4Route> ();
277 uint32_t metric =i->second;
278 Ipv4Mask mask = (j)->GetDestNetworkMask ();
281 NS_LOG_LOGIC (
"Searching for route to " << dest <<
", checking against route to " << entry <<
"/" << masklen);
282 if (mask.
IsMatch (dest, entry))
284 NS_LOG_LOGIC (
"Found global network route " << j <<
", mask length " << masklen <<
", metric " << metric);
293 if (masklen < longest_mask)
298 if (masklen > longest_mask)
300 shortest_metric = 0xffffffff;
302 longest_mask = masklen;
303 if (metric > shortest_metric)
305 NS_LOG_LOGIC (
"Equal mask length, but previous metric shorter, skipping");
308 shortest_metric = metric;
311 rtentry = Create<Ipv4Route> ();
328 NS_LOG_LOGIC (
"No matching route to " << dest <<
" found");
358 NS_LOG_LOGIC (
"Found multicast source specific route" << *i);
366 mrtentry = Create<Ipv4MulticastRoute> ();
367 mrtentry->SetGroup (route->
GetGroup ());
368 mrtentry->SetOrigin (route->
GetOrigin ());
398 uint32_t shortest_metric = 0xffffffff;
405 uint32_t metric = i->second;
406 Ipv4Mask mask = (j)->GetDestNetworkMask ();
412 if (metric > shortest_metric)
416 shortest_metric = metric;
528 uint32_t iif =
m_ipv4->GetInterfaceForDevice (idev);
541 mcb (mrtentry, p, ipHeader);
556 lcb (p, ipHeader, iif);
571 if (
m_ipv4->IsForwarding (iif) ==
false)
573 NS_LOG_LOGIC (
"Forwarding disabled for this interface");
581 NS_LOG_LOGIC (
"Found unicast destination- calling unicast callback");
582 ucb (rtentry, p, ipHeader);
587 NS_LOG_LOGIC (
"Did not find unicast destination- returning false");
624 for (uint32_t j = 0; j <
m_ipv4->GetNAddresses (i); j++)
631 m_ipv4->GetAddress (i,j).GetMask (), i);
643 if (it->first->GetInterface () == i)
659 if (!
m_ipv4->IsUp (interface))
670 networkMask, interface);
677 if (!
m_ipv4->IsUp (interface))
687 if (it->first->GetInterface () == interface
688 && it->first->IsNetwork ()
689 && it->first->GetDestNetwork () == networkAddress
690 && it->first->GetDestNetworkMask () == networkMask)
708 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces (); i++)
727 std::ios oldState (
nullptr);
728 oldState.copyfmt (*os);
730 *os << std::resetiosflags (std::ios::adjustfield) << std::setiosflags (std::ios::left);
732 *os <<
"Node: " <<
m_ipv4->GetObject<
Node> ()->GetId ()
733 <<
", Time: " <<
Now().
As (unit)
734 <<
", Local time: " <<
m_ipv4->GetObject<
Node> ()->GetLocalTime ().As (unit)
735 <<
", Ipv4StaticRouting table" << std::endl;
739 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface" << std::endl;
742 std::ostringstream dest, gw, mask, flags;
745 *os << std::setw (16) << dest.str ();
747 *os << std::setw (16) << gw.str ();
749 *os << std::setw (16) << mask.str ();
759 *os << std::setw (6) << flags.str ();
778 (*os).copyfmt (oldState);
uint32_t GetOutputInterface(uint32_t n) const
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
static Ipv4Mask GetOnes(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
bool IsMatch(Ipv4Address a, Ipv4Address b) const
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
static TypeId GetTypeId(void)
The interface Id associated with this class.
a class to represent an Ipv4 address mask
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
Ipv4RoutingTableEntry GetDefaultRoute(void)
Get the default route with lowest metric from the static routing table.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ipv4Address GetDest(void) const
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
virtual void DoDispose(void)
Destructor implementation.
SocketErrno
Enumeration of the possible errors returned by a socket.
Ipv4Address GetGateway(void) const
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a host route to the static routing table.
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Ptr< Ipv4Route > LookupStatic(Ipv4Address dest, Ptr< NetDevice > oif=0)
Lookup in the forwarding table for destination.
void SetSource(Ipv4Address src)
bool IsMulticast(void) const
virtual void NotifyInterfaceDown(uint32_t interface)
Ipv4Mask GetDestNetworkMask(void) const
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface)
Remove a route from the static multicast routing table.
Ipv4Address GetGroup(void) const
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
void SetGateway(Ipv4Address gw)
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
static Ipv4Mask GetZero(void)
Unit
The unit to use to interpret a number representing time.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
bool IsLocalMulticast(void) const
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
uint32_t GetInputInterface(void) const
uint32_t GetNOutputInterfaces(void) const
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Static routing protocol for IP version 4 stacks.
uint32_t GetInterface(void) const
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
static Ipv4Address GetZero(void)
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
bool LookupRoute(const Ipv4RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
virtual ~Ipv4StaticRouting()
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetGateway(void) const
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4 addresses are stored in host order in this class.
uint32_t GetNMulticastRoutes(void) const
Get the number of individual multicast routes that have been added to the routing table...
virtual void DoDispose(void)
Destructor implementation.
Ipv4Address GetOrigin(void) const
a class to store IPv4 address information on an interface
virtual void NotifyInterfaceUp(uint32_t interface)
NetworkRoutes m_networkRoutes
the forwarding table for network.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
bool IsGateway(void) const
static const uint32_t IF_ANY
interface wildcard, meaning any interface
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...
Abstract base class for IPv4 routing protocols.
uint16_t GetPrefixLength(void) const
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
bool IsNull(void) const
Check for null implementation.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
static const uint32_t MAX_TTL
Maximum time-to-live (TTL)
void SetDestination(Ipv4Address dest)
void SetDefaultMulticastRoute(uint32_t outputInterface)
Add a default multicast route to the static routing table.
void AddMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route to the static routing table.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.