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