20 #define NS_LOG_APPEND_CONTEXT \
21 if (m_ipv4 && m_ipv4->GetObject<Node>()) \
23 std::clog << Simulator::Now().GetSeconds() << " [node " \
24 << m_ipv4->GetObject<Node>()->GetId() << "] "; \
33 #include "ns3/names.h"
35 #include "ns3/output-stream-wrapper.h"
36 #include "ns3/packet.h"
37 #include "ns3/simulator.h"
55 .SetGroupName(
"Internet")
73 NS_LOG_FUNCTION(
this << network <<
" " << networkMask <<
" " << nextHop <<
" "
74 << interface <<
" " << metric);
92 NS_LOG_FUNCTION(
this << network <<
" " << networkMask <<
" " << interface <<
" " << metric);
110 NS_LOG_FUNCTION(
this << dest <<
" " << nextHop <<
" " << interface <<
" " << metric);
131 uint32_t inputInterface,
132 std::vector<uint32_t> outputInterfaces)
134 NS_LOG_FUNCTION(
this << origin <<
" " << group <<
" " << inputInterface <<
" "
135 << &outputInterfaces);
170 "Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
190 uint32_t inputInterface)
192 NS_LOG_FUNCTION(
this << origin <<
" " << group <<
" " << inputInterface);
247 uint16_t longest_mask = 0;
248 uint32_t shortest_metric = 0xffffffff;
254 "Try to send on link-local multicast address, and no interface index is given!");
256 rtentry = Create<Ipv4Route>();
257 rtentry->SetDestination(dest);
259 rtentry->SetOutputDevice(oif);
260 rtentry->SetSource(
m_ipv4->GetAddress(
m_ipv4->GetInterfaceForDevice(oif), 0).GetLocal());
267 uint32_t metric = i->second;
268 Ipv4Mask mask = (j)->GetDestNetworkMask();
271 NS_LOG_LOGIC(
"Searching for route to " << dest <<
", checking against route to " << entry
275 NS_LOG_LOGIC(
"Found global network route " << j <<
", mask length " << masklen
276 <<
", metric " << metric);
285 if (masklen < longest_mask)
290 if (masklen > longest_mask)
292 shortest_metric = 0xffffffff;
294 longest_mask = masklen;
295 if (metric > shortest_metric)
297 NS_LOG_LOGIC(
"Equal mask length, but previous metric shorter, skipping");
300 shortest_metric = metric;
303 rtentry = Create<Ipv4Route>();
304 rtentry->SetDestination(route->
GetDest());
305 rtentry->SetSource(
m_ipv4->SourceAddressSelection(interfaceIdx, route->
GetDest()));
307 rtentry->SetOutputDevice(
m_ipv4->GetNetDevice(interfaceIdx));
316 NS_LOG_LOGIC(
"Matching route via " << rtentry->GetGateway() <<
" at the end");
320 NS_LOG_LOGIC(
"No matching route to " << dest <<
" found");
345 NS_LOG_LOGIC(
"Found multicast source specific route" << *i);
352 mrtentry = Create<Ipv4MulticastRoute>();
353 mrtentry->SetGroup(route->
GetGroup());
386 uint32_t shortest_metric = 0xffffffff;
391 uint32_t metric = i->second;
392 Ipv4Mask mask = (j)->GetDestNetworkMask();
398 if (metric > shortest_metric)
402 shortest_metric = metric;
512 << idev << &ucb << &mcb << &lcb << &ecb);
517 uint32_t iif =
m_ipv4->GetInterfaceForDevice(idev);
526 m_ipv4->GetInterfaceForDevice(idev));
531 mcb(mrtentry, p, ipHeader);
546 lcb(p, ipHeader, iif);
561 if (!
m_ipv4->IsForwarding(iif))
571 NS_LOG_LOGIC(
"Found unicast destination- calling unicast callback");
572 ucb(rtentry, p, ipHeader);
577 NS_LOG_LOGIC(
"Did not find unicast destination- returning false");
611 for (uint32_t j = 0; j <
m_ipv4->GetNAddresses(i); j++)
618 m_ipv4->GetAddress(i, j).GetLocal().CombineMask(
m_ipv4->GetAddress(i, j).GetMask()),
619 m_ipv4->GetAddress(i, j).GetMask(),
632 if (it->first->GetInterface() == i)
648 if (!
m_ipv4->IsUp(interface))
665 if (!
m_ipv4->IsUp(interface))
675 if (it->first->GetInterface() == interface && it->first->IsNetwork() &&
676 it->first->GetDestNetwork() == networkAddress &&
677 it->first->GetDestNetworkMask() == networkMask)
695 for (uint32_t i = 0; i <
m_ipv4->GetNInterfaces(); i++)
715 std::ios oldState(
nullptr);
716 oldState.copyfmt(*os);
718 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
720 *os <<
"Node: " <<
m_ipv4->GetObject<
Node>()->GetId() <<
", Time: " <<
Now().
As(unit)
721 <<
", Local time: " <<
m_ipv4->GetObject<
Node>()->GetLocalTime().As(unit)
722 <<
", Ipv4StaticRouting table" << std::endl;
726 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface"
730 std::ostringstream dest;
731 std::ostringstream gw;
732 std::ostringstream mask;
733 std::ostringstream flags;
736 *os << std::setw(16) << dest.str();
738 *os << std::setw(16) << gw.str();
740 *os << std::setw(16) << mask.str();
750 *os << std::setw(6) << flags.str();
771 (*os).copyfmt(oldState);
bool IsNull() const
Check for null implementation.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetZero()
bool IsLocalMulticast() const
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
static Ipv4Mask GetOnes()
uint16_t GetPrefixLength() const
bool IsMatch(Ipv4Address a, Ipv4Address b) const
static Ipv4Mask GetZero()
static const uint32_t MAX_TTL
Maximum time-to-live (TTL)
A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetGroup() const
Ipv4Address GetOrigin() const
uint32_t GetOutputInterface(uint32_t n) const
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
uint32_t GetNOutputInterfaces() const
uint32_t GetInputInterface() const
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Ipv4Address GetDest() const
Ipv4Address GetGateway() const
uint32_t GetInterface() const
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
Ipv4Mask GetDestNetworkMask() const
Static routing protocol for IP version 4 stacks.
void SetIpv4(Ptr< Ipv4 > ipv4) override
void NotifyInterfaceUp(uint32_t interface) override
void DoDispose() override
Destructor implementation.
Ipv4RoutingTableEntry GetDefaultRoute()
Get the default route with lowest metric from the static routing table.
void RemoveRoute(uint32_t i)
Remove a route from the static unicast routing table.
~Ipv4StaticRouting() override
bool LookupRoute(const Ipv4RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
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.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
NetworkRoutes m_networkRoutes
the forwarding table for network.
Ptr< Ipv4Route > LookupStatic(Ipv4Address dest, Ptr< NetDevice > oif=nullptr)
Lookup in the forwarding table for destination.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
uint32_t GetNMulticastRoutes() const
Get the number of individual multicast routes that have been added to the routing table.
Ipv4RoutingTableEntry GetRoute(uint32_t i) const
Get a route from the static unicast routing table.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void NotifyInterfaceDown(uint32_t interface) override
bool RouteInput(Ptr< const Packet > p, const Ipv4Header &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)
static TypeId GetTypeId()
The interface Id associated with this class.
Ptr< Ipv4 > m_ipv4
Ipv4 reference.
Ipv4MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get a route from the static multicast routing table.
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.
uint32_t GetNRoutes() const
Get the number of individual unicast routes that have been added to the 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()
Destructor implementation.
std::ostream * GetStream()
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.
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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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.