9#define NS_LOG_APPEND_CONTEXT \
10 if (m_ipv4 && m_ipv4->GetObject<Node>()) \
12 std::clog << Simulator::Now().GetSeconds() << " [node " \
13 << m_ipv4->GetObject<Node>()->GetId() << "] "; \
24#include "ns3/output-stream-wrapper.h"
25#include "ns3/packet.h"
26#include "ns3/simulator.h"
44 .SetGroupName(
"Internet")
63 << interface <<
" " << metric);
159 "Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
221 rtentry->GetDestNetworkMask() ==
route.GetDestNetworkMask() &&
223 rtentry->GetInterface() ==
route.GetInterface() &&
j->second == metric)
239 if (
dest.IsLocalMulticast())
243 "Try to send on link-local multicast address, and no interface index is given!");
257 Ipv4Mask mask = (
j)->GetDestNetworkMask();
265 <<
", metric " << metric);
268 if (oif !=
m_ipv4->GetNetDevice(
j->GetInterface()))
286 NS_LOG_LOGIC(
"Equal mask length, but previous metric shorter, skipping");
347 if (
route->GetOutputInterface(
j))
350 <<
route->GetOutputInterface(
j));
381 Ipv4Mask mask = (
j)->GetDestNetworkMask();
510 if (
ipHeader.GetDestination().IsMulticast())
560 NS_LOG_LOGIC(
"Found unicast destination- calling unicast callback");
566 NS_LOG_LOGIC(
"Did not find unicast destination- returning false");
607 m_ipv4->GetAddress(
i,
j).GetLocal().CombineMask(
m_ipv4->GetAddress(
i,
j).GetMask()),
621 if (
it->first->GetInterface() ==
i)
637 if (!
m_ipv4->IsUp(interface))
654 if (!
m_ipv4->IsUp(interface))
664 if (
it->first->GetInterface() ==
interface &&
it->first->IsNetwork() &&
702 std::ostream* os = stream->GetStream();
707 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
709 *os <<
"Node: " <<
m_ipv4->GetObject<
Node>()->GetId() <<
", Time: " <<
Now().
As(unit)
710 <<
", Local time: " <<
m_ipv4->GetObject<
Node>()->GetLocalTime().As(unit)
711 <<
", Ipv4StaticRouting table" << std::endl;
715 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface"
719 std::ostringstream
dest;
720 std::ostringstream
gw;
721 std::ostringstream mask;
722 std::ostringstream flags;
725 *os << std::setw(16) <<
dest.str();
727 *os << std::setw(16) <<
gw.str();
728 mask <<
route.GetDestNetworkMask();
729 *os << std::setw(16) << mask.str();
735 else if (
route.IsGateway())
739 *os << std::setw(6) << flags.str();
753 *os <<
route.GetInterface();
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetZero()
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.
static Ipv4MulticastRoutingTableEntry CreateMulticastRoute(Ipv4Address origin, Ipv4Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
static Ipv4RoutingTableEntry CreateNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface)
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.
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.
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.