A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-static-routing.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2006 Georgia Tech Research Corporation
3//
4// SPDX-License-Identifier: GPL-2.0-only
5//
6// Author: George F. Riley<riley@ece.gatech.edu>
7// Gustavo Carneiro <gjc@inescporto.pt>
8
9#define NS_LOG_APPEND_CONTEXT \
10 if (m_ipv4 && m_ipv4->GetObject<Node>()) \
11 { \
12 std::clog << Simulator::Now().GetSeconds() << " [node " \
13 << m_ipv4->GetObject<Node>()->GetId() << "] "; \
14 }
15
16#include "ipv4-static-routing.h"
17
18#include "ipv4-route.h"
20
21#include "ns3/log.h"
22#include "ns3/names.h"
23#include "ns3/node.h"
24#include "ns3/output-stream-wrapper.h"
25#include "ns3/packet.h"
26#include "ns3/simulator.h"
27
28#include <iomanip>
29
30using std::make_pair;
31
32namespace ns3
33{
34
35NS_LOG_COMPONENT_DEFINE("Ipv4StaticRouting");
36
37NS_OBJECT_ENSURE_REGISTERED(Ipv4StaticRouting);
38
39TypeId
41{
42 static TypeId tid = TypeId("ns3::Ipv4StaticRouting")
44 .SetGroupName("Internet")
45 .AddConstructor<Ipv4StaticRouting>();
46 return tid;
47}
48
50 : m_ipv4(nullptr)
51{
52 NS_LOG_FUNCTION(this);
53}
54
55void
57 Ipv4Mask networkMask,
58 Ipv4Address nextHop,
59 uint32_t interface,
60 uint32_t metric)
61{
62 NS_LOG_FUNCTION(this << network << " " << networkMask << " " << nextHop << " "
63 << interface << " " << metric);
64
66 Ipv4RoutingTableEntry::CreateNetworkRouteTo(network, networkMask, nextHop, interface);
67
68 if (!LookupRoute(route, metric))
69 {
70 auto routePtr = new Ipv4RoutingTableEntry(route);
71 m_networkRoutes.emplace_back(routePtr, metric);
72 }
73}
74
75void
77 Ipv4Mask networkMask,
78 uint32_t interface,
79 uint32_t metric)
80{
81 NS_LOG_FUNCTION(this << network << " " << networkMask << " " << interface << " " << metric);
82
84 Ipv4RoutingTableEntry::CreateNetworkRouteTo(network, networkMask, interface);
85 if (!LookupRoute(route, metric))
86 {
87 auto routePtr = new Ipv4RoutingTableEntry(route);
88
89 m_networkRoutes.emplace_back(routePtr, metric);
90 }
91}
92
93void
95 Ipv4Address nextHop,
96 uint32_t interface,
97 uint32_t metric)
98{
99 NS_LOG_FUNCTION(this << dest << " " << nextHop << " " << interface << " " << metric);
100 AddNetworkRouteTo(dest, Ipv4Mask::GetOnes(), nextHop, interface, metric);
101}
102
103void
105{
106 NS_LOG_FUNCTION(this << dest << " " << interface << " " << metric);
107 AddNetworkRouteTo(dest, Ipv4Mask::GetOnes(), interface, metric);
108}
109
110void
112{
113 NS_LOG_FUNCTION(this << nextHop << " " << interface << " " << metric);
114 AddNetworkRouteTo(Ipv4Address("0.0.0.0"), Ipv4Mask::GetZero(), nextHop, interface, metric);
115}
116
117void
119 Ipv4Address group,
120 uint32_t inputInterface,
121 std::vector<uint32_t> outputInterfaces)
122{
123 NS_LOG_FUNCTION(this << origin << " " << group << " " << inputInterface << " "
124 << &outputInterfaces);
125 auto route = new Ipv4MulticastRoutingTableEntry();
127 group,
128 inputInterface,
129 outputInterfaces);
130 m_multicastRoutes.push_back(route);
131}
132
133// default multicast routes are stored as a network route
134// these routes are _not_ consulted in the forwarding process-- only
135// for originating packets
136void
138{
139 NS_LOG_FUNCTION(this << outputInterface);
140 auto route = new Ipv4RoutingTableEntry();
141 Ipv4Address network("224.0.0.0");
142 Ipv4Mask networkMask("240.0.0.0");
143 *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo(network, networkMask, outputInterface);
144 m_networkRoutes.emplace_back(route, 0);
145}
146
149{
150 NS_LOG_FUNCTION(this);
151 return m_multicastRoutes.size();
152}
153
156{
157 NS_LOG_FUNCTION(this << index);
158 NS_ASSERT_MSG(index < m_multicastRoutes.size(),
159 "Ipv4StaticRouting::GetMulticastRoute (): Index out of range");
160
161 if (index < m_multicastRoutes.size())
162 {
163 uint32_t tmp = 0;
164 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
165 {
166 if (tmp == index)
167 {
168 return *i;
169 }
170 tmp++;
171 }
172 }
173 return nullptr;
174}
175
176bool
178 Ipv4Address group,
179 uint32_t inputInterface)
180{
181 NS_LOG_FUNCTION(this << origin << " " << group << " " << inputInterface);
182 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
183 {
185 if (origin == route->GetOrigin() && group == route->GetGroup() &&
186 inputInterface == route->GetInputInterface())
187 {
188 delete *i;
189 m_multicastRoutes.erase(i);
190 return true;
191 }
192 }
193 return false;
194}
195
196void
198{
199 NS_LOG_FUNCTION(this << index);
200 uint32_t tmp = 0;
201 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
202 {
203 if (tmp == index)
204 {
205 delete *i;
206 m_multicastRoutes.erase(i);
207 return;
208 }
209 tmp++;
210 }
211}
212
213bool
215{
216 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
217 {
218 Ipv4RoutingTableEntry* rtentry = j->first;
219
220 if (rtentry->GetDest() == route.GetDest() &&
221 rtentry->GetDestNetworkMask() == route.GetDestNetworkMask() &&
222 rtentry->GetGateway() == route.GetGateway() &&
223 rtentry->GetInterface() == route.GetInterface() && j->second == metric)
224 {
225 return true;
226 }
227 }
228 return false;
229}
230
233{
234 NS_LOG_FUNCTION(this << dest << " " << oif);
235 Ptr<Ipv4Route> rtentry = nullptr;
236 uint16_t longest_mask = 0;
237 uint32_t shortest_metric = 0xffffffff;
238 /* when sending on local multicast, there have to be interface specified */
239 if (dest.IsLocalMulticast())
240 {
242 oif,
243 "Try to send on link-local multicast address, and no interface index is given!");
244
245 rtentry = Create<Ipv4Route>();
246 rtentry->SetDestination(dest);
247 rtentry->SetGateway(Ipv4Address::GetZero());
248 rtentry->SetOutputDevice(oif);
249 rtentry->SetSource(m_ipv4->GetAddress(m_ipv4->GetInterfaceForDevice(oif), 0).GetLocal());
250 return rtentry;
251 }
252
253 for (auto i = m_networkRoutes.begin(); i != m_networkRoutes.end(); i++)
254 {
255 Ipv4RoutingTableEntry* j = i->first;
256 uint32_t metric = i->second;
257 Ipv4Mask mask = (j)->GetDestNetworkMask();
258 uint16_t masklen = mask.GetPrefixLength();
259 Ipv4Address entry = (j)->GetDestNetwork();
260 NS_LOG_LOGIC("Searching for route to " << dest << ", checking against route to " << entry
261 << "/" << masklen);
262 if (mask.IsMatch(dest, entry))
263 {
264 NS_LOG_LOGIC("Found global network route " << j << ", mask length " << masklen
265 << ", metric " << metric);
266 if (oif)
267 {
268 if (oif != m_ipv4->GetNetDevice(j->GetInterface()))
269 {
270 NS_LOG_LOGIC("Not on requested interface, skipping");
271 continue;
272 }
273 }
274 if (masklen < longest_mask) // Not interested if got shorter mask
275 {
276 NS_LOG_LOGIC("Previous match longer, skipping");
277 continue;
278 }
279 if (masklen > longest_mask) // Reset metric if longer masklen
280 {
281 shortest_metric = 0xffffffff;
282 }
283 longest_mask = masklen;
284 if (metric > shortest_metric)
285 {
286 NS_LOG_LOGIC("Equal mask length, but previous metric shorter, skipping");
287 continue;
288 }
289 shortest_metric = metric;
290 Ipv4RoutingTableEntry* route = (j);
291 uint32_t interfaceIdx = route->GetInterface();
292 rtentry = Create<Ipv4Route>();
293 rtentry->SetDestination(route->GetDest());
294 rtentry->SetSource(m_ipv4->SourceAddressSelection(interfaceIdx, route->GetDest()));
295 rtentry->SetGateway(route->GetGateway());
296 rtentry->SetOutputDevice(m_ipv4->GetNetDevice(interfaceIdx));
297 if (masklen == 32)
298 {
299 break;
300 }
301 }
302 }
303 if (rtentry)
304 {
305 NS_LOG_LOGIC("Matching route via " << rtentry->GetGateway() << " at the end");
306 }
307 else
308 {
309 NS_LOG_LOGIC("No matching route to " << dest << " found");
310 }
311 return rtentry;
312}
313
316{
317 NS_LOG_FUNCTION(this << origin << " " << group << " " << interface);
318 Ptr<Ipv4MulticastRoute> mrtentry = nullptr;
319
320 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
321 {
323 //
324 // We've been passed an origin address, a multicast group address and an
325 // interface index. We have to decide if the current route in the list is
326 // a match.
327 //
328 // The first case is the restrictive case where the origin, group and index
329 // matches.
330 //
331 if (origin == route->GetOrigin() && group == route->GetGroup())
332 {
333 // Skipping this case (SSM) for now
334 NS_LOG_LOGIC("Found multicast source specific route" << *i);
335 }
336 if (group == route->GetGroup())
337 {
338 if (interface == Ipv4::IF_ANY || interface == route->GetInputInterface())
339 {
340 NS_LOG_LOGIC("Found multicast route" << *i);
341 mrtentry = Create<Ipv4MulticastRoute>();
342 mrtentry->SetGroup(route->GetGroup());
343 mrtentry->SetOrigin(route->GetOrigin());
344 mrtentry->SetParent(route->GetInputInterface());
345 for (uint32_t j = 0; j < route->GetNOutputInterfaces(); j++)
346 {
347 if (route->GetOutputInterface(j))
348 {
349 NS_LOG_LOGIC("Setting output interface index "
350 << route->GetOutputInterface(j));
351 mrtentry->SetOutputTtl(route->GetOutputInterface(j),
353 }
354 }
355 return mrtentry;
356 }
357 }
358 }
359 return mrtentry;
360}
361
364{
365 NS_LOG_FUNCTION(this);
366 return m_networkRoutes.size();
367}
368
371{
372 NS_LOG_FUNCTION(this);
373 // Basically a repeat of LookupStatic, retained for backward compatibility
374 Ipv4Address dest("0.0.0.0");
375 uint32_t shortest_metric = 0xffffffff;
376 Ipv4RoutingTableEntry* result = nullptr;
377 for (auto i = m_networkRoutes.begin(); i != m_networkRoutes.end(); i++)
378 {
379 Ipv4RoutingTableEntry* j = i->first;
380 uint32_t metric = i->second;
381 Ipv4Mask mask = (j)->GetDestNetworkMask();
382 uint16_t masklen = mask.GetPrefixLength();
383 if (masklen != 0)
384 {
385 continue;
386 }
387 if (metric > shortest_metric)
388 {
389 continue;
390 }
391 shortest_metric = metric;
392 result = j;
393 }
394 if (result)
395 {
396 return result;
397 }
398 else
399 {
400 return Ipv4RoutingTableEntry();
401 }
402}
403
406{
407 NS_LOG_FUNCTION(this << index);
408 uint32_t tmp = 0;
409 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
410 {
411 if (tmp == index)
412 {
413 return j->first;
414 }
415 tmp++;
416 }
417 NS_ASSERT(false);
418 // quiet compiler.
419 return nullptr;
420}
421
424{
425 NS_LOG_FUNCTION(this << index);
426 uint32_t tmp = 0;
427 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
428 {
429 if (tmp == index)
430 {
431 return j->second;
432 }
433 tmp++;
434 }
435 NS_ASSERT(false);
436 // quiet compiler.
437 return 0;
438}
439
440void
442{
443 NS_LOG_FUNCTION(this << index);
444 uint32_t tmp = 0;
445 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
446 {
447 if (tmp == index)
448 {
449 delete j->first;
450 m_networkRoutes.erase(j);
451 return;
452 }
453 tmp++;
454 }
455 NS_ASSERT(false);
456}
457
460 const Ipv4Header& header,
461 Ptr<NetDevice> oif,
462 Socket::SocketErrno& sockerr)
463{
464 NS_LOG_FUNCTION(this << p << header << oif << sockerr);
465 Ipv4Address destination = header.GetDestination();
466 Ptr<Ipv4Route> rtentry = nullptr;
467
468 // Multicast goes here
469 if (destination.IsMulticast())
470 {
471 // Note: Multicast routes for outbound packets are stored in the
472 // normal unicast table. An implication of this is that it is not
473 // possible to source multicast datagrams on multiple interfaces.
474 // This is a well-known property of sockets implementation on
475 // many Unix variants.
476 // So, we just log it and fall through to LookupStatic ()
477 NS_LOG_LOGIC("RouteOutput()::Multicast destination");
478 }
479 rtentry = LookupStatic(destination, oif);
480 if (rtentry)
481 {
482 sockerr = Socket::ERROR_NOTERROR;
483 }
484 else
485 {
487 }
488 return rtentry;
489}
490
491bool
493 const Ipv4Header& ipHeader,
495 const UnicastForwardCallback& ucb,
496 const MulticastForwardCallback& mcb,
497 const LocalDeliverCallback& lcb,
498 const ErrorCallback& ecb)
499{
500 NS_LOG_FUNCTION(this << p << ipHeader << ipHeader.GetSource() << ipHeader.GetDestination()
501 << idev << &ucb << &mcb << &lcb << &ecb);
502
504 // Check if input device supports IP
507
508 // Multicast recognition; handle local delivery here
509
510 if (ipHeader.GetDestination().IsMulticast())
511 {
512 NS_LOG_LOGIC("Multicast destination");
513 Ptr<Ipv4MulticastRoute> mrtentry = LookupStatic(ipHeader.GetSource(),
514 ipHeader.GetDestination(),
516
517 if (mrtentry)
518 {
519 NS_LOG_LOGIC("Multicast route found");
520 mcb(mrtentry, p, ipHeader); // multicast forwarding callback
521 return true;
522 }
523 else
524 {
525 NS_LOG_LOGIC("Multicast route not found");
526 return false; // Let other routing protocols try to handle this
527 }
528 }
529
530 if (m_ipv4->IsDestinationAddress(ipHeader.GetDestination(), iif))
531 {
532 if (!lcb.IsNull())
533 {
534 NS_LOG_LOGIC("Local delivery to " << ipHeader.GetDestination());
535 lcb(p, ipHeader, iif);
536 return true;
537 }
538 else
539 {
540 // The local delivery callback is null. This may be a multicast
541 // or broadcast packet, so return false so that another
542 // multicast routing protocol can handle it. It should be possible
543 // to extend this to explicitly check whether it is a unicast
544 // packet, and invoke the error callback if so
545 return false;
546 }
547 }
548
549 // Check if input device supports IP forwarding
550 if (!m_ipv4->IsForwarding(iif))
551 {
552 NS_LOG_LOGIC("Forwarding disabled for this interface");
553 ecb(p, ipHeader, Socket::ERROR_NOROUTETOHOST);
554 return true;
555 }
556 // Next, try to find a route
557 Ptr<Ipv4Route> rtentry = LookupStatic(ipHeader.GetDestination());
558 if (rtentry)
559 {
560 NS_LOG_LOGIC("Found unicast destination- calling unicast callback");
561 ucb(rtentry, p, ipHeader); // unicast forwarding callback
562 return true;
563 }
564 else
565 {
566 NS_LOG_LOGIC("Did not find unicast destination- returning false");
567 return false; // Let other routing protocols try to handle this
568 }
569}
570
575
576void
578{
579 NS_LOG_FUNCTION(this);
580 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j = m_networkRoutes.erase(j))
581 {
582 delete (j->first);
583 }
584 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end();
585 i = m_multicastRoutes.erase(i))
586 {
587 delete (*i);
588 }
589 m_ipv4 = nullptr;
591}
592
593void
595{
596 NS_LOG_FUNCTION(this << i);
597 // If interface address and network mask have been set, add a route
598 // to the network of the interface (like e.g. ifconfig does on a
599 // Linux box)
600 for (uint32_t j = 0; j < m_ipv4->GetNAddresses(i); j++)
601 {
602 if (m_ipv4->GetAddress(i, j).GetLocal() != Ipv4Address() &&
603 m_ipv4->GetAddress(i, j).GetMask() != Ipv4Mask() &&
605 {
608 m_ipv4->GetAddress(i, j).GetMask(),
609 i);
610 }
611 }
612}
613
614void
616{
617 NS_LOG_FUNCTION(this << i);
618 // Remove all static routes that are going through this interface
619 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
620 {
621 if (it->first->GetInterface() == i)
622 {
623 delete it->first;
624 it = m_networkRoutes.erase(it);
625 }
626 else
627 {
628 it++;
629 }
630 }
631}
632
633void
635{
636 NS_LOG_FUNCTION(this << interface << " " << address.GetLocal());
637 if (!m_ipv4->IsUp(interface))
638 {
639 return;
640 }
641
642 Ipv4Address networkAddress = address.GetLocal().CombineMask(address.GetMask());
643 Ipv4Mask networkMask = address.GetMask();
644 if (address.GetLocal() != Ipv4Address() && address.GetMask() != Ipv4Mask())
645 {
646 AddNetworkRouteTo(networkAddress, networkMask, interface);
647 }
648}
649
650void
652{
653 NS_LOG_FUNCTION(this << interface << " " << address.GetLocal());
654 if (!m_ipv4->IsUp(interface))
655 {
656 return;
657 }
658 Ipv4Address networkAddress = address.GetLocal().CombineMask(address.GetMask());
659 Ipv4Mask networkMask = address.GetMask();
660 // Remove all static routes that are going through this interface
661 // which reference this network
662 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
663 {
664 if (it->first->GetInterface() == interface && it->first->IsNetwork() &&
665 it->first->GetDestNetwork() == networkAddress &&
666 it->first->GetDestNetworkMask() == networkMask)
667 {
668 delete it->first;
669 it = m_networkRoutes.erase(it);
670 }
671 else
672 {
673 it++;
674 }
675 }
676}
677
678void
680{
681 NS_LOG_FUNCTION(this << ipv4);
682 NS_ASSERT(!m_ipv4 && ipv4);
683 m_ipv4 = ipv4;
684 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces(); i++)
685 {
686 if (m_ipv4->IsUp(i))
687 {
689 }
690 else
691 {
693 }
694 }
695}
696
697// Formatted like output of "route -n" command
698void
700{
701 NS_LOG_FUNCTION(this << stream);
702 std::ostream* os = stream->GetStream();
703 // Copy the current ostream state
704 std::ios oldState(nullptr);
705 oldState.copyfmt(*os);
706
707 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
708
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;
712
713 if (GetNRoutes() > 0)
714 {
715 *os << "Destination Gateway Genmask Flags Metric Ref Use Iface"
716 << std::endl;
717 for (uint32_t j = 0; j < GetNRoutes(); j++)
718 {
719 std::ostringstream dest;
720 std::ostringstream gw;
721 std::ostringstream mask;
722 std::ostringstream flags;
724 dest << route.GetDest();
725 *os << std::setw(16) << dest.str();
726 gw << route.GetGateway();
727 *os << std::setw(16) << gw.str();
728 mask << route.GetDestNetworkMask();
729 *os << std::setw(16) << mask.str();
730 flags << "U";
731 if (route.IsHost())
732 {
733 flags << "HS";
734 }
735 else if (route.IsGateway())
736 {
737 flags << "GS";
738 }
739 *os << std::setw(6) << flags.str();
740 *os << std::setw(7) << GetMetric(j);
741 // Ref ct not implemented
742 *os << "-"
743 << " ";
744 // Use not implemented
745 *os << "-"
746 << " ";
747 if (!Names::FindName(m_ipv4->GetNetDevice(route.GetInterface())).empty())
748 {
750 }
751 else
752 {
753 *os << route.GetInterface();
754 }
755 *os << std::endl;
756 }
757 }
758 *os << std::endl;
759 // Restore the previous ostream state
760 (*os).copyfmt(oldState);
761}
762
763} // namespace ns3
bool IsNull() const
Check for null implementation.
Definition callback.h:555
Ipv4 addresses are stored in host order in this class.
bool IsMulticast() const
static Ipv4Address GetZero()
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
bool IsLocalMulticast() const
Packet header for IPv4.
Definition ipv4-header.h:23
Ipv4Address GetSource() const
Ipv4Address GetDestination() const
virtual bool IsForwarding(uint32_t interface) const =0
virtual uint32_t GetNAddresses(uint32_t interface) const =0
virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
virtual bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const =0
Determine whether address and interface corresponding to received packet can be accepted for local de...
static const uint32_t IF_ANY
interface wildcard, meaning any interface
Definition ipv4.h:431
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest)=0
Choose the source address to use with destination address.
virtual uint32_t GetNInterfaces() const =0
virtual bool IsUp(uint32_t interface) const =0
a class to store IPv4 address information on an interface
Ipv4Mask GetMask() const
Get the network mask.
Ipv4Address GetLocal() const
Get the local address.
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)
Definition ipv4-route.h:148
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
bool IsHost() const
bool IsGateway() 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.
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,...
Definition names.cc:818
A network Node.
Definition node.h:46
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
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:404
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Every class exported by the ns3 library is enclosed in the ns3 namespace.