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