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> ();
264 rtentry->SetDestination (dest);
266 rtentry->SetOutputDevice (oif);
267 rtentry->SetSource (
m_ipv4->GetAddress (
m_ipv4->GetInterfaceForDevice (oif), 0).GetLocal ());
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> ();
312 rtentry->SetDestination (route->
GetDest ());
313 rtentry->SetSource (
m_ipv4->SourceAddressSelection (interfaceIdx, route->
GetDest ()));
315 rtentry->SetOutputDevice (
m_ipv4->GetNetDevice (interfaceIdx));
324 NS_LOG_LOGIC (
"Matching route via " << rtentry->GetGateway () <<
" at the end");
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);
bool IsNull(void) const
Check for null implementation.
Ipv4 addresses are stored in host order in this class.
bool IsMulticast(void) const
bool IsLocalMulticast(void) const
static Ipv4Address GetZero(void)
static const uint32_t IF_ANY
interface wildcard, meaning any interface
a class to store IPv4 address information on an interface
a class to represent an Ipv4 address mask
uint16_t GetPrefixLength(void) const
static Ipv4Mask GetZero(void)
bool IsMatch(Ipv4Address a, Ipv4Address b) const
static Ipv4Mask GetOnes(void)
static const uint32_t MAX_TTL
Maximum time-to-live (TTL)
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetGroup(void) const
uint32_t GetOutputInterface(uint32_t n) const
Ipv4Address GetOrigin(void) const
uint32_t GetInputInterface(void) const
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
uint32_t GetNOutputInterfaces(void) const
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
uint32_t GetInterface(void) const
bool IsGateway(void) const
Ipv4Address GetDest(void) const
Ipv4Mask GetDestNetworkMask(void) const
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Ipv4Address GetGateway(void) const
Static routing protocol for IP version 4 stacks.
virtual ~Ipv4StaticRouting()
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
virtual void NotifyInterfaceDown(uint32_t interface)
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
virtual void NotifyInterfaceUp(uint32_t interface)
bool LookupRoute(const Ipv4RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
Ipv4RoutingTableEntry GetDefaultRoute(void)
Get the default route with lowest metric from the static routing table.
uint32_t GetNRoutes(void) const
Get the number of individual unicast routes that have been added to the routing table.
void SetDefaultMulticastRoute(uint32_t outputInterface)
Add a default multicast route to the static routing table.
virtual void DoDispose(void)
Destructor implementation.
void AddMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route to the static routing table.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
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)
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast 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.
NetworkRoutes m_networkRoutes
the forwarding table for network.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
uint32_t GetNMulticastRoutes(void) const
Get the number of individual multicast routes that have been added to the routing table.
Ptr< Ipv4Route > LookupStatic(Ipv4Address dest, Ptr< NetDevice > oif=0)
Lookup in the forwarding table for destination.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
static TypeId GetTypeId(void)
The interface Id associated with this class.
void AddHostRouteTo(Ipv4Address dest, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a host route to the static routing table.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
bool RemoveMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface)
Remove a route from the static multicast routing table.
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,...
virtual void DoDispose(void)
Destructor implementation.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
Smart pointer class similar to boost::intrusive_ptr.
SocketErrno
Enumeration of the possible errors returned by a socket.
Unit
The unit to use to interpret a number representing time.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.