A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-routing.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2008 University of Washington
3//
4// SPDX-License-Identifier: GPL-2.0-only
5//
6
7#include "global-routing.h"
8
10#include "ipv4-route.h"
12#include "ipv6-route.h"
13
14#include "ns3/boolean.h"
15#include "ns3/log.h"
16#include "ns3/names.h"
17#include "ns3/net-device.h"
18#include "ns3/node.h"
19#include "ns3/object.h"
20#include "ns3/packet.h"
21#include "ns3/simulator.h"
22
23#include <iomanip>
24#include <vector>
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("GlobalRouting");
30
31template <typename T>
34{
35 if (IsIpv4)
36 {
37 static TypeId tid =
38 TypeId("ns3::Ipv4GlobalRouting")
39 .SetParent<T>()
40 .SetGroupName("Internet")
41 .template AddConstructor<GlobalRouting<T>>()
42 .AddAttribute(
43 "RandomEcmpRouting",
44 "Set to true if packets are randomly routed among ECMP; set to false for "
45 "using only one route consistently",
46 BooleanValue(false),
50 "RespondToInterfaceEvents",
51 "Set to true if you want to dynamically recompute the global routes upon "
52 "Interface notification events (up/down, or add/remove address)",
53 BooleanValue(false),
56 return tid;
57 }
58 else
59 {
60 static TypeId tid =
61 TypeId("ns3::Ipv6GlobalRouting")
62 .SetParent<T>()
63 .SetGroupName("Internet")
64 .template AddConstructor<GlobalRouting<T>>()
65 .AddAttribute(
66 "RandomEcmpRouting",
67 "Set to true if packets are randomly routed among ECMP; set to false for "
68 "using only one route consistently",
69 BooleanValue(false),
73 "RespondToInterfaceEvents",
74 "Set to true if you want to dynamically recompute the global routes upon "
75 "Interface notification events (up/down, or add/remove address)",
76 BooleanValue(false),
79 return tid;
80 }
81}
82
83template <typename T>
92
93template <typename T>
98
99template <typename T>
100void
102{
103 NS_LOG_FUNCTION(this << dest << nextHop << interface);
104 auto route = new IpRoutingTableEntry();
105 *route = IpRoutingTableEntry::CreateHostRouteTo(dest, nextHop, interface);
106 for (auto routePointer : m_hostRoutes)
107 {
108 if (*routePointer == *route)
109 {
110 NS_LOG_LOGIC("Route already exists");
111 delete route;
112 return;
113 }
114 }
115 m_hostRoutes.push_back(route);
116}
117
118template <typename T>
119void
121{
122 NS_LOG_FUNCTION(this << dest << interface);
123 auto route = new IpRoutingTableEntry();
124 *route = IpRoutingTableEntry::CreateHostRouteTo(dest, interface);
125 for (auto routePointer : m_hostRoutes)
126 {
127 if (*routePointer == *route)
128 {
129 NS_LOG_LOGIC("Route already exists");
130 delete route;
131 return;
132 }
133 }
134 m_hostRoutes.push_back(route);
135}
136
137template <typename T>
138void
140 IpMaskOrPrefix networkMask,
141 IpAddress nextHop,
142 uint32_t interface)
143{
144 NS_LOG_FUNCTION(this << network << networkMask << nextHop << interface);
145 auto route = new IpRoutingTableEntry();
146 *route = IpRoutingTableEntry::CreateNetworkRouteTo(network, networkMask, nextHop, interface);
147 for (auto routePointer : m_networkRoutes)
148 {
149 if (*routePointer == *route)
150 {
151 NS_LOG_LOGIC("Route already exists");
152 delete route;
153 return;
154 }
155 }
156 m_networkRoutes.push_back(route);
157}
158
159template <typename T>
160void
162 IpMaskOrPrefix networkMask,
163 uint32_t interface)
164{
165 NS_LOG_FUNCTION(this << network << networkMask << interface);
166 auto route = new IpRoutingTableEntry();
167 *route = IpRoutingTableEntry::CreateNetworkRouteTo(network, networkMask, interface);
168 for (auto routePointer : m_networkRoutes)
169 {
170 if (*routePointer == *route)
171 {
172 NS_LOG_LOGIC("Route already exists");
173 delete route;
174 return;
175 }
176 }
177 m_networkRoutes.push_back(route);
178}
179
180template <typename T>
181void
183 IpMaskOrPrefix networkMask,
184 IpAddress nextHop,
185 uint32_t interface)
186{
187 NS_LOG_FUNCTION(this << network << networkMask << nextHop << interface);
188 auto route = new IpRoutingTableEntry();
189 *route = IpRoutingTableEntry::CreateNetworkRouteTo(network, networkMask, nextHop, interface);
190 for (auto routePointer : m_ASexternalRoutes)
191 {
192 if (*routePointer == *route)
193 {
194 NS_LOG_LOGIC("Route already exists");
195 delete route;
196 return;
197 }
198 }
199 m_ASexternalRoutes.push_back(route);
200}
201
202template <typename T>
205{
206 NS_LOG_FUNCTION(this << dest << oif);
207 NS_LOG_LOGIC("Looking for route for destination " << dest);
208 Ptr<IpRoute> rtentry = nullptr;
209 // store all available routes that bring packets to their destination
210 typedef std::vector<IpRoutingTableEntry*> RouteVec_t;
211 RouteVec_t allRoutes;
212
213 NS_LOG_LOGIC("Number of m_hostRoutes = " << m_hostRoutes.size());
214 for (auto i = m_hostRoutes.begin(); i != m_hostRoutes.end(); i++)
215 {
216 NS_ASSERT((*i)->IsHost());
217 if ((*i)->GetDest() == dest)
218 {
219 if (oif)
220 {
221 if (oif != m_ip->GetNetDevice((*i)->GetInterface()))
222 {
223 NS_LOG_LOGIC("Not on requested interface, skipping");
224 continue;
225 }
226 }
227 allRoutes.push_back(*i);
228 NS_LOG_LOGIC(allRoutes.size() << "Found global host route" << *i);
229 }
230 }
231 if (allRoutes.empty()) // if no host route is found
232 {
233 NS_LOG_LOGIC("Number of m_networkRoutes" << m_networkRoutes.size());
234 // store the length of the longest mask.
235 uint16_t longest_mask = 0;
236 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
237 {
238 IpMaskOrPrefix mask;
239 if constexpr (IsIpv4)
240 {
241 mask = (*j)->GetDestNetworkMask();
242 }
243 else
244 {
245 mask = (*j)->GetDestNetworkPrefix();
246 }
247 uint16_t masklen = mask.GetPrefixLength();
248
249 IpAddress entry = (*j)->GetDestNetwork();
250 if (mask.IsMatch(dest, entry))
251 {
252 if (oif)
253 {
254 if (oif != m_ip->GetNetDevice((*j)->GetInterface()))
255 {
256 NS_LOG_LOGIC("Not on requested interface, skipping");
257 continue;
258 }
259 }
260 NS_LOG_LOGIC(allRoutes.size() << "Found global network route" << *j);
261 if (masklen < longest_mask) // Not interested if got shorter mask
262 {
263 NS_LOG_LOGIC("Previous match longer, skipping");
264 continue;
265 }
266 else if (masklen == longest_mask)
267 {
268 NS_LOG_LOGIC("Equal mask length, adding this to the list");
269 allRoutes.push_back(*j);
270 }
271 else
272 {
273 NS_LOG_LOGIC("Longer mask length found, clearing the list and adding");
274 allRoutes.clear();
275 allRoutes.push_back(*j);
276 }
277 }
278 }
279 }
280 if (allRoutes.empty()) // consider external if no host/network found
281 {
282 for (auto k = m_ASexternalRoutes.begin(); k != m_ASexternalRoutes.end(); k++)
283 {
284 IpMaskOrPrefix mask;
285 if constexpr (IsIpv4)
286 {
287 mask = (*k)->GetDestNetworkMask();
288 }
289 else
290 {
291 mask = (*k)->GetDestNetworkPrefix();
292 }
293
294 IpAddress entry = (*k)->GetDestNetwork();
295 if (mask.IsMatch(dest, entry))
296 {
297 NS_LOG_LOGIC("Found external route" << *k);
298 if (oif)
299 {
300 if (oif != m_ip->GetNetDevice((*k)->GetInterface()))
301 {
302 NS_LOG_LOGIC("Not on requested interface, skipping");
303 continue;
304 }
305 }
306 allRoutes.push_back(*k);
307 break;
308 }
309 }
310 }
311 if (!allRoutes.empty()) // if route(s) is found
312 {
313 // pick up one of the routes uniformly at random if random
314 // ECMP routing is enabled, or always select the first route
315 // consistently if random ECMP routing is disabled
316 uint32_t selectIndex;
318 {
319 selectIndex = m_rand->GetInteger(0, allRoutes.size() - 1);
320 }
321 else
322 {
323 selectIndex = 0;
324 }
325 IpRoutingTableEntry* route = allRoutes.at(selectIndex);
326 // create a Ipv4Route object from the selected routing table entry
327 rtentry = Create<IpRoute>();
328 rtentry->SetDestination(route->GetDest());
329 /// @todo handle multi-address case
330 if constexpr (IsIpv4)
331 {
332 rtentry->SetSource(m_ip->GetAddress(route->GetInterface(), 0).GetAddress());
333 }
334 else
335 {
336 rtentry->SetSource(m_ip->GetAddress(route->GetInterface(), 1).GetAddress());
337 }
338 rtentry->SetGateway(route->GetGateway());
339 uint32_t interfaceIdx = route->GetInterface();
340 rtentry->SetOutputDevice(m_ip->GetNetDevice(interfaceIdx));
341 return rtentry;
342 }
343 else
344 {
345 return nullptr;
346 }
347}
348
349template <typename T>
352{
353 NS_LOG_FUNCTION(this);
354 uint32_t n = 0;
355 n += m_hostRoutes.size();
356 n += m_networkRoutes.size();
357 n += m_ASexternalRoutes.size();
358 return n;
359}
360
361template <typename T>
364{
365 NS_LOG_FUNCTION(this << index);
366 if (index < m_hostRoutes.size())
367 {
368 uint32_t tmp = 0;
369 for (auto i = m_hostRoutes.begin(); i != m_hostRoutes.end(); i++)
370 {
371 if (tmp == index)
372 {
373 return *i;
374 }
375 tmp++;
376 }
377 }
378 index -= m_hostRoutes.size();
379 uint32_t tmp = 0;
380 if (index < m_networkRoutes.size())
381 {
382 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
383 {
384 if (tmp == index)
385 {
386 return *j;
387 }
388 tmp++;
389 }
390 }
391 index -= m_networkRoutes.size();
392 tmp = 0;
393 for (auto k = m_ASexternalRoutes.begin(); k != m_ASexternalRoutes.end(); k++)
394 {
395 if (tmp == index)
396 {
397 return *k;
398 }
399 tmp++;
400 }
401 NS_ASSERT(false);
402 // quiet compiler.
403 return nullptr;
404}
405
406template <typename T>
407void
409{
410 NS_LOG_FUNCTION(this << index);
411 if (index < m_hostRoutes.size())
412 {
413 uint32_t tmp = 0;
414 for (auto i = m_hostRoutes.begin(); i != m_hostRoutes.end(); i++)
415 {
416 if (tmp == index)
417 {
418 NS_LOG_LOGIC("Removing route " << index << "; size = " << m_hostRoutes.size());
419 delete *i;
420 m_hostRoutes.erase(i);
421 NS_LOG_LOGIC("Done removing host route "
422 << index << "; host route remaining size = " << m_hostRoutes.size());
423 return;
424 }
425 tmp++;
426 }
427 }
428 index -= m_hostRoutes.size();
429 uint32_t tmp = 0;
430 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
431 {
432 if (tmp == index)
433 {
434 NS_LOG_LOGIC("Removing route " << index << "; size = " << m_networkRoutes.size());
435 delete *j;
436 m_networkRoutes.erase(j);
437 NS_LOG_LOGIC("Done removing network route "
438 << index << "; network route remaining size = " << m_networkRoutes.size());
439 return;
440 }
441 tmp++;
442 }
443 index -= m_networkRoutes.size();
444 tmp = 0;
445 for (auto k = m_ASexternalRoutes.begin(); k != m_ASexternalRoutes.end(); k++)
446 {
447 if (tmp == index)
448 {
449 NS_LOG_LOGIC("Removing route " << index << "; size = " << m_ASexternalRoutes.size());
450 delete *k;
451 m_ASexternalRoutes.erase(k);
452 NS_LOG_LOGIC("Done removing network route "
453 << index << "; network route remaining size = " << m_networkRoutes.size());
454 return;
455 }
456 tmp++;
457 }
458 NS_ASSERT(false);
459}
460
461template <typename T>
462int64_t
464{
465 NS_LOG_FUNCTION(this << stream);
466 m_rand->SetStream(stream);
467 return 1;
468}
469
470template <typename T>
471void
473{
474 NS_LOG_FUNCTION(this);
475 for (auto i = m_hostRoutes.begin(); i != m_hostRoutes.end(); i = m_hostRoutes.erase(i))
476 {
477 delete (*i);
478 }
479 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j = m_networkRoutes.erase(j))
480 {
481 delete (*j);
482 }
483 for (auto l = m_ASexternalRoutes.begin(); l != m_ASexternalRoutes.end();
484 l = m_ASexternalRoutes.erase(l))
485 {
486 delete (*l);
487 }
488
489 IpRoutingProtocol::DoDispose();
490}
491
492// Formatted like output of "route -n" command
493template <typename T>
494void
496{
497 NS_LOG_FUNCTION(this << stream);
498 std::ostream* os = stream->GetStream();
499 // Copy the current ostream state
500 std::ios oldState(nullptr);
501 oldState.copyfmt(*os);
502
503 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
504
505 std::string name;
506 if constexpr (IsIpv4)
507 {
508 name = "Ipv4";
509 }
510 else
511 {
512 name = "Ipv6";
513 }
514
515 *os << "Node: " << m_ip->template GetObject<Node>()->GetId() << ", Time: " << Now().As(unit)
516 << ", Local time: " << m_ip->template GetObject<Node>()->GetLocalTime().As(unit) << ", "
517 << name << "GlobalRouting table" << std::endl;
518
519 if (GetNRoutes() > 0)
520 {
521 *os << "Destination Next Hop Flag Met Ref Use If"
522 << std::endl;
523 for (uint32_t j = 0; j < GetNRoutes(); j++)
524 {
525 std::ostringstream dest;
526 std::ostringstream gw;
527 std::ostringstream mask;
528 std::ostringstream flags;
529 IpRoutingTableEntry route = GetRoute(j);
530 if constexpr (IsIpv4)
531 {
532 dest << route.GetDest();
533 *os << std::setw(16) << dest.str();
534 gw << route.GetGateway();
535 *os << std::setw(16) << gw.str();
536 mask << route.GetDestNetworkMask();
537 *os << std::setw(16) << mask.str();
538 ;
539 }
540 else
541 {
542 dest << route.GetDest() << "/"
543 << int(route.GetDestNetworkPrefix().GetPrefixLength());
544 *os << std::setw(31) << dest.str();
545 gw << route.GetGateway();
546 *os << std::setw(27) << gw.str();
547 }
548 flags << "U";
549 if (route.IsHost())
550 {
551 flags << "H";
552 }
553 else if (route.IsGateway())
554 {
555 flags << "G";
556 }
557 *os << std::setw(6) << flags.str();
558 // Metric not implemented
559 *os << "-"
560 << " ";
561 // Ref ct not implemented
562 *os << "-"
563 << " ";
564 // Use not implemented
565 *os << "-"
566 << " ";
567 if (!Names::FindName(m_ip->GetNetDevice(route.GetInterface())).empty())
568 {
569 *os << Names::FindName(m_ip->GetNetDevice(route.GetInterface()));
570 }
571 else
572 {
573 *os << route.GetInterface();
574 }
575 *os << std::endl;
576 }
577 }
578 *os << std::endl;
579 // Restore the previous ostream state
580 (*os).copyfmt(oldState);
581}
582
583template <typename T>
586 const IpHeader& header,
587 Ptr<NetDevice> oif,
588 Socket::SocketErrno& sockerr)
589{
590 NS_LOG_FUNCTION(this << p << &header << oif << &sockerr);
591 //
592 // First, see if this is a multicast packet we have a route for. If we
593 // have a route, then send the packet down each of the specified interfaces.
594 //
595 if (header.GetDestination().IsMulticast())
596 {
597 NS_LOG_LOGIC("Multicast destination-- returning false");
598 return nullptr; // Let other routing protocols try to handle this
599 }
600 //
601 // See if this is a unicast packet we have a route for.
602 //
603 NS_LOG_LOGIC("Unicast destination- looking up");
604 Ptr<IpRoute> rtentry = LookupGlobal(header.GetDestination(), oif);
605 if (rtentry)
606 {
607 sockerr = Socket::ERROR_NOTERROR;
608 }
609 else
610 {
612 }
613 return rtentry;
614}
615
616template <typename T>
617bool
619 const IpHeader& header,
621 const UnicastForwardCallback& ucb,
622 const MulticastForwardCallback& mcb,
623 const LocalDeliverCallback& lcb,
624 const ErrorCallback& ecb)
625{
626 NS_LOG_FUNCTION(this << p << header << header.GetSource() << header.GetDestination() << idev
627 << &lcb << &ecb);
628 // Check if input device supports IP
629 NS_ASSERT(m_ip->GetInterfaceForDevice(idev) >= 0);
630 uint32_t iif = m_ip->GetInterfaceForDevice(idev);
631 if constexpr (IsIpv4)
632 {
633 if (m_ip->IsDestinationAddress(header.GetDestination(), iif))
634 {
635 if (!lcb.IsNull())
636 {
637 NS_LOG_LOGIC("Local delivery to " << header.GetDestination());
638 lcb(p, header, iif);
639 return true;
640 }
641 else
642 {
643 // The local delivery callback is null. This may be a multicast
644 // or broadcast packet, so return false so that another
645 // multicast routing protocol can handle it. It should be possible
646 // to extend this to explicitly check whether it is a unicast
647 // packet, and invoke the error callback if so
648 return false;
649 }
650 }
651 }
652 else
653 {
654 // for ipv6 the local delivery callback is never called. Local delivery is already handled
655 // in Ipv6l3Protocol::Receive() for now do nothing
656 }
657 // Check if input device supports IP forwarding
658 if (!m_ip->IsForwarding(iif))
659 {
660 NS_LOG_LOGIC("Forwarding disabled for this interface");
661 ecb(p, header, Socket::ERROR_NOROUTETOHOST);
662 return true;
663 }
664 // Next, try to find a route
665 NS_LOG_LOGIC("Unicast destination- looking up global route");
666 Ptr<IpRoute> rtentry = LookupGlobal(header.GetDestination());
667 if (rtentry)
668 {
669 NS_LOG_LOGIC("Found unicast destination- calling unicast callback");
670 if constexpr (IsIpv4)
671 {
672 ucb(rtentry, p, header);
673 }
674 else
675 {
676 ucb(idev, rtentry, p, header);
677 }
678 return true;
679 }
680 else
681 {
682 NS_LOG_LOGIC("Did not find unicast destination- returning false");
683 return false; // Let other routing protocols try to handle this
684 // route request.
685 }
686}
687
688template <typename T>
689void
700
701template <typename T>
702void
713
714template <typename T>
715void
726
727template <typename T>
728void
739
740template <typename T>
741void
743 Ipv6Prefix mask,
744 Ipv6Address nextHop,
745 uint32_t interface,
746 Ipv6Address prefixToUse)
747{
748}
749
750template <typename T>
751void
753 Ipv6Prefix prefix,
754 Ipv6Address nextHop,
755 uint32_t ifIndex,
756 Ipv6Address origin)
757{
758 // no-op or real behavior
759}
760
761template <typename T>
762void
764{
765 NS_LOG_FUNCTION(this << ipv4);
766 NS_ASSERT(!m_ip && ipv4);
767
768 m_ip = ipv4;
769}
770
771template <typename T>
772void
774{
775 NS_LOG_FUNCTION(this << ipv6);
776 NS_ASSERT(!m_ip && ipv6);
777 m_ip = ipv6;
778}
779
780// template <typename T>
781// void
782// GlobalRouting<T>::InitializeRouters()
783//{
784// NS_LOG_FUNCTION(this);
785// for (uint32_t i = 0; i < m_ip->GetNInterfaces(); i++)
786// {
787// m_ip->SetForwarding(i, true);
788// }
789// }
790
793
794} // namespace ns3
AttributeValue implementation for Boolean.
Definition boolean.h:26
bool IsNull() const
Check for null implementation.
Definition callback.h:561
static void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
static void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
static void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
Global routing protocol for IPv4 stacks.
Ptr< IpRoute > LookupGlobal(IpAddress dest, Ptr< NetDevice > oif=nullptr)
Lookup in the forwarding table for destination.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void NotifyRemoveAddress(uint32_t interface, IpInterfaceAddress address)
static TypeId GetTypeId()
Get the type ID.
void AddHostRouteTo(IpAddress dest, IpAddress nextHop, uint32_t interface)
Add a host route to the global routing table.
virtual void SetIpv6(Ptr< Ip > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
uint32_t GetNRoutes() const
Get the number of individual unicast routes that have been added to the routing table.
ASExternalRoutes m_ASexternalRoutes
External routes imported.
std::conditional_t< IsIpv4, MulticastForwardCallbackv4, MulticastForwardCallbackv6 > MulticastForwardCallback
Callback for multicast packets to be forwarded.
void NotifyInterfaceDown(uint32_t interface)
virtual void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify a new route.
Callback< void, Ptr< const Packet >, const IpHeader &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
void NotifyAddAddress(uint32_t interface, IpInterfaceAddress address)
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
void NotifyInterfaceUp(uint32_t interface)
HostRoutes m_hostRoutes
Routes to hosts.
Ptr< UniformRandomVariable > m_rand
A uniform random number generator for randomly routing packets among ECMP.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
virtual void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero())
Notify route removing.
bool RouteInput(Ptr< const Packet > p, const IpHeader &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb)
Route an input packet (to be forwarded or locally delivered).
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingHelper or Ipv6RoutingHelper.
std::conditional_t< IsIpv4, UnicastForwardCallbackv4, UnicastForwardCallbackv6 > UnicastForwardCallback
Callback for unicast packets to be forwarded.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void RemoveRoute(uint32_t i)
Remove a route from the global unicast routing table.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
bool m_randomEcmpRouting
Set to true if packets are randomly routed among ECMP; set to false for using only one route consiste...
GlobalRouting()
Construct an empty Ipv4GlobalRouting routing protocol,.
Callback< void, Ptr< const Packet >, const IpHeader &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found).
Ptr< IpRoute > RouteOutput(Ptr< Packet > p, const IpHeader &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
void AddNetworkRouteTo(IpAddress network, IpMaskOrPrefix networkMask, IpAddress nextHop, uint32_t interface)
Add a network route to the global routing table.
virtual void SetIpv4(Ptr< Ip > ipv4)
Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol.
bool m_respondToInterfaceEvents
Set to true if this interface should respond to interface events by globally recomputing routes.
NetworkRoutes m_networkRoutes
Routes to networks.
Ptr< Ip > m_ip
associated IPv4 instance
void AddASExternalRouteTo(IpAddress network, IpMaskOrPrefix networkMask, IpAddress nextHop, uint32_t interface)
Add an external route to the global routing table.
IpRoutingTableEntry * GetRoute(uint32_t i) const
Get a route from the global unicast routing table.
Abstract base class for IPv4 routing protocols.
Describes an IPv6 address.
Describes an IPv6 prefix.
Abstract base class for IPv6 routing protocols.
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,...
Definition names.cc:818
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
@ ERROR_NOROUTETOHOST
Definition socket.h:84
@ ERROR_NOTERROR
Definition socket.h:74
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:408
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:101
a unique identifier for an interface.
Definition type-id.h:50
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker, SupportLevel supportLevel=SupportLevel::SUPPORTED, const std::string &supportMsg="")
Record in this TypeId the fact that a new attribute exists.
Definition type-id.cc:1097
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition boolean.h:70
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:274
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_TEMPLATE_CLASS_DEFINE(type, param)
Explicitly instantiate a template class with one template parameter and register the resulting instan...
Definition object-base.h:67
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:454
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:288
Every class exported by the ns3 library is enclosed in the ns3 namespace.