21 #include "ns3/names.h"
23 #include "ns3/simulator.h"
24 #include "ns3/object.h"
25 #include "ns3/packet.h"
26 #include "ns3/net-device.h"
27 #include "ns3/ipv4-route.h"
28 #include "ns3/ipv4-routing-table-entry.h"
29 #include "ns3/boolean.h"
44 .AddAttribute (
"RandomEcmpRouting",
45 "Set to true if packets are randomly routed among ECMP; set to false for using only one route consistently",
48 MakeBooleanChecker ())
49 .AddAttribute (
"RespondToInterfaceEvents",
50 "Set to true if you want to dynamically recompute the global routes upon Interface notification events (up/down, or add/remove address)",
53 MakeBooleanChecker ())
59 : m_randomEcmpRouting (false),
60 m_respondToInterfaceEvents (false)
64 m_rand = CreateObject<UniformRandomVariable> ();
141 NS_LOG_LOGIC (
"Looking for route for destination " << dest);
144 typedef std::vector<Ipv4RoutingTableEntry*> RouteVec_t;
145 RouteVec_t allRoutes;
153 if ((*i)->GetDest ().IsEqual (dest))
163 allRoutes.push_back (*i);
164 NS_LOG_LOGIC (allRoutes.size () <<
"Found global host route" << *i);
167 if (allRoutes.size () == 0)
174 Ipv4Mask mask = (*j)->GetDestNetworkMask ();
176 if (mask.
IsMatch (dest, entry))
186 allRoutes.push_back (*j);
187 NS_LOG_LOGIC (allRoutes.size () <<
"Found global network route" << *j);
191 if (allRoutes.size () == 0)
197 Ipv4Mask mask = (*k)->GetDestNetworkMask ();
199 if (mask.
IsMatch (dest, entry))
210 allRoutes.push_back (*k);
215 if (allRoutes.size () > 0 )
220 uint32_t selectIndex;
231 rtentry = Create<Ipv4Route> ();
404 *os <<
"Destination Gateway Genmask Flags Metric Ref Use Iface" << std::endl;
407 std::ostringstream dest, gw, mask, flags;
410 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
412 *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
414 *os << std::setiosflags (std::ios::left) << std::setw (16) << mask.str ();
424 *os << std::setiosflags (std::ios::left) << std::setw (6) << flags.str ();
454 NS_LOG_LOGIC (
"Multicast destination-- returning false");
485 NS_LOG_LOGIC (
"Multicast destination-- returning false");
512 NS_LOG_LOGIC (
"For me (destination " << addr <<
" match)");
518 lcb (p, header, iif);
524 lcb (p, header, iif);
533 NS_LOG_LOGIC (
"Forwarding disabled for this interface");
538 NS_LOG_LOGIC (
"Unicast destination- looking up global route");
542 NS_LOG_LOGIC (
"Found unicast destination- calling unicast callback");
543 ucb (rtentry, p, header);
548 NS_LOG_LOGIC (
"Did not find unicast destination- returning false");