Improve Ipv4StaticRouting logging

This commit is contained in:
Tom Henderson
2009-12-31 10:05:05 -08:00
parent 0752fbef6f
commit 23f3592653

View File

@@ -18,9 +18,15 @@
// Author: George F. Riley<riley@ece.gatech.edu>
// Gustavo Carneiro <gjc@inescporto.pt>
#define NS_LOG_APPEND_CONTEXT \
if (m_ipv4 && m_ipv4->GetObject<Node> ()) { \
std::clog << Simulator::Now ().GetSeconds () \
<< " [node " << m_ipv4->GetObject<Node> ()->GetId () << "] "; }
#include "ns3/log.h"
#include "ns3/packet.h"
#include "ns3/node.h"
#include "ns3/simulator.h"
#include "ns3/ipv4-route.h"
#include "ipv4-static-routing.h"
#include "ipv4-routing-table-entry.h"
@@ -46,7 +52,7 @@ Ipv4StaticRouting::GetTypeId (void)
Ipv4StaticRouting::Ipv4StaticRouting ()
: m_ipv4 (0)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this);
}
void
@@ -56,7 +62,7 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network,
uint32_t interface,
uint32_t metric)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << network << " " << networkMask << " " << nextHop << " " << interface << " " << metric);
Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
*route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
networkMask,
@@ -71,7 +77,7 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network,
uint32_t interface,
uint32_t metric)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << network << " " << networkMask << " " << interface << " " << metric);
Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
*route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network,
networkMask,
@@ -85,7 +91,7 @@ Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest,
uint32_t interface,
uint32_t metric)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << dest << " " << nextHop << " " << interface << " " << metric);
AddNetworkRouteTo (dest, Ipv4Mask::GetOnes (), nextHop, interface, metric);
}
@@ -94,7 +100,7 @@ Ipv4StaticRouting::AddHostRouteTo (Ipv4Address dest,
uint32_t interface,
uint32_t metric)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << dest << " " << interface << " " << metric);
AddNetworkRouteTo (dest, Ipv4Mask::GetOnes (), interface, metric);
}
@@ -103,7 +109,7 @@ Ipv4StaticRouting::SetDefaultRoute (Ipv4Address nextHop,
uint32_t interface,
uint32_t metric)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << nextHop << " " << interface << " " << metric);
AddNetworkRouteTo (Ipv4Address ("0.0.0.0"), Ipv4Mask::GetZero (), nextHop, interface, metric);
}
@@ -113,7 +119,7 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin,
uint32_t inputInterface,
std::vector<uint32_t> outputInterfaces)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << origin << " " << group << " " << inputInterface);
Ipv4MulticastRoutingTableEntry *route = new Ipv4MulticastRoutingTableEntry ();
*route = Ipv4MulticastRoutingTableEntry::CreateMulticastRoute (origin, group,
inputInterface, outputInterfaces);
@@ -126,7 +132,7 @@ Ipv4StaticRouting::AddMulticastRoute(Ipv4Address origin,
void
Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << outputInterface);
Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry ();
Ipv4Address network = Ipv4Address ("224.0.0.0");
Ipv4Mask networkMask = Ipv4Mask ("240.0.0.0");
@@ -139,14 +145,14 @@ Ipv4StaticRouting::SetDefaultMulticastRoute(uint32_t outputInterface)
uint32_t
Ipv4StaticRouting::GetNMulticastRoutes (void) const
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this);
return m_multicastRoutes.size ();
}
Ipv4MulticastRoutingTableEntry
Ipv4StaticRouting::GetMulticastRoute (uint32_t index) const
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << index);
NS_ASSERT_MSG(index < m_multicastRoutes.size (),
"Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
@@ -172,7 +178,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin,
Ipv4Address group,
uint32_t inputInterface)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << origin << " " << group << " " << inputInterface);
for (MulticastRoutesI i = m_multicastRoutes.begin ();
i != m_multicastRoutes.end ();
i++)
@@ -193,7 +199,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(Ipv4Address origin,
void
Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << index);
uint32_t tmp = 0;
for (MulticastRoutesI i = m_multicastRoutes.begin ();
i != m_multicastRoutes.end ();
@@ -212,7 +218,7 @@ Ipv4StaticRouting::RemoveMulticastRoute(uint32_t index)
Ptr<Ipv4Route>
Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << dest << " " << oif);
Ptr<Ipv4Route> rtentry = 0;
uint16_t longest_mask = 0;
uint32_t shortest_metric = 0xffffffff;
@@ -272,7 +278,7 @@ Ipv4StaticRouting::LookupStatic (
Ipv4Address group,
uint32_t interface)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << origin << " " << group << " " << interface);
Ptr<Ipv4MulticastRoute> mrtentry = 0;
for (MulticastRoutesI i = m_multicastRoutes.begin ();
@@ -321,14 +327,14 @@ Ipv4StaticRouting::LookupStatic (
uint32_t
Ipv4StaticRouting::GetNRoutes (void)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this);
return m_networkRoutes.size ();;
}
Ipv4RoutingTableEntry
Ipv4StaticRouting::GetDefaultRoute ()
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this);
// Basically a repeat of LookupStatic, retained for backward compatibility
Ipv4Address dest ("0.0.0.0");
uint32_t shortest_metric = 0xffffffff;
@@ -366,8 +372,8 @@ Ipv4StaticRouting::GetDefaultRoute ()
Ipv4RoutingTableEntry
Ipv4StaticRouting::GetRoute (uint32_t index)
{
NS_LOG_FUNCTION_NOARGS ();
uint32_t tmp = 0;
NS_LOG_FUNCTION (this << index);
uint32_t tmp = 0;
for (NetworkRoutesI j = m_networkRoutes.begin ();
j != m_networkRoutes.end ();
j++)
@@ -386,7 +392,7 @@ Ipv4StaticRouting::GetRoute (uint32_t index)
uint32_t
Ipv4StaticRouting::GetMetric (uint32_t index)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << index);
uint32_t tmp = 0;
for (NetworkRoutesI j = m_networkRoutes.begin ();
j != m_networkRoutes.end ();
@@ -405,7 +411,7 @@ Ipv4StaticRouting::GetMetric (uint32_t index)
void
Ipv4StaticRouting::RemoveRoute (uint32_t index)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_FUNCTION (this << index);
uint32_t tmp = 0;
for (NetworkRoutesI j = m_networkRoutes.begin ();
j != m_networkRoutes.end ();
@@ -550,13 +556,11 @@ Ipv4StaticRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &ipHeader,
Ipv4StaticRouting::~Ipv4StaticRouting ()
{
NS_LOG_FUNCTION_NOARGS ();
}
void
Ipv4StaticRouting::DoDispose (void)
{
NS_LOG_FUNCTION_NOARGS ();
for (NetworkRoutesI j = m_networkRoutes.begin ();
j != m_networkRoutes.end ();
j = m_networkRoutes.erase (j))
@@ -576,6 +580,7 @@ Ipv4StaticRouting::DoDispose (void)
void
Ipv4StaticRouting::NotifyInterfaceUp (uint32_t i)
{
NS_LOG_FUNCTION (this << i);
// If interface address and network mask have been set, add a route
// to the network of the interface (like e.g. ifconfig does on a
// Linux box)
@@ -593,6 +598,7 @@ Ipv4StaticRouting::NotifyInterfaceUp (uint32_t i)
void
Ipv4StaticRouting::NotifyInterfaceDown (uint32_t i)
{
NS_LOG_FUNCTION (this << i);
// Remove all static routes that are going through this interface
uint32_t j = 0;
while (j < GetNRoutes())
@@ -612,7 +618,7 @@ Ipv4StaticRouting::NotifyInterfaceDown (uint32_t i)
void
Ipv4StaticRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address)
{
NS_LOG_FUNCTION (this << interface);
NS_LOG_FUNCTION (this << interface << " " << address.GetLocal());
if (!m_ipv4->IsUp (interface))
{
return;
@@ -630,6 +636,7 @@ Ipv4StaticRouting::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress ad
void
Ipv4StaticRouting::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address)
{
NS_LOG_FUNCTION (this << interface << " " << address.GetLocal());
if (!m_ipv4->IsUp (interface))
{
return;
@@ -673,6 +680,7 @@ Ipv4StaticRouting::SetIpv4 (Ptr<Ipv4> ipv4)
Ipv4Address
Ipv4StaticRouting::SourceAddressSelection (uint32_t interfaceIdx, Ipv4Address dest)
{
NS_LOG_FUNCTION (this << interfaceIdx << " " << dest);
if (m_ipv4->GetNAddresses (interfaceIdx) == 1) // common case
{
return m_ipv4->GetAddress (interfaceIdx, 0).GetLocal ();