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 Ipv4RoutingTableEntry* 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 Ipv4RoutingTableEntry* 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);
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);
152 Ipv4Address network = Ipv4Address("224.0.0.0");
153 Ipv4Mask networkMask = Ipv4Mask("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 (MulticastRoutesCI 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 (MulticastRoutesI 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 (MulticastRoutesI 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 (NetworkRoutesI 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 (NetworkRoutesI 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 (MulticastRoutesI 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 (NetworkRoutesI 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 (NetworkRoutesCI 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 (NetworkRoutesCI 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 (NetworkRoutesI 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 (NetworkRoutesI j = m_networkRoutes.begin(); j != m_networkRoutes.end();
592 j = m_networkRoutes.erase(j))
593 {
594 delete (j->first);
595 }
596 for (MulticastRoutesI i = m_multicastRoutes.begin(); i != m_multicastRoutes.end();
597 i = m_multicastRoutes.erase(i))
598 {
599 delete (*i);
600 }
601 m_ipv4 = nullptr;
603}
604
605void
607{
608 NS_LOG_FUNCTION(this << i);
609 // If interface address and network mask have been set, add a route
610 // to the network of the interface (like e.g. ifconfig does on a
611 // Linux box)
612 for (uint32_t j = 0; j < m_ipv4->GetNAddresses(i); j++)
613 {
614 if (m_ipv4->GetAddress(i, j).GetLocal() != Ipv4Address() &&
615 m_ipv4->GetAddress(i, j).GetMask() != Ipv4Mask() &&
616 m_ipv4->GetAddress(i, j).GetMask() != Ipv4Mask::GetOnes())
617 {
619 m_ipv4->GetAddress(i, j).GetLocal().CombineMask(m_ipv4->GetAddress(i, j).GetMask()),
620 m_ipv4->GetAddress(i, j).GetMask(),
621 i);
622 }
623 }
624}
625
626void
628{
629 NS_LOG_FUNCTION(this << i);
630 // Remove all static routes that are going through this interface
631 for (NetworkRoutesI it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
632 {
633 if (it->first->GetInterface() == i)
634 {
635 delete it->first;
636 it = m_networkRoutes.erase(it);
637 }
638 else
639 {
640 it++;
641 }
642 }
643}
644
645void
647{
648 NS_LOG_FUNCTION(this << interface << " " << address.GetLocal());
649 if (!m_ipv4->IsUp(interface))
650 {
651 return;
652 }
653
654 Ipv4Address networkAddress = address.GetLocal().CombineMask(address.GetMask());
655 Ipv4Mask networkMask = address.GetMask();
656 if (address.GetLocal() != Ipv4Address() && address.GetMask() != Ipv4Mask())
657 {
658 AddNetworkRouteTo(networkAddress, networkMask, interface);
659 }
660}
661
662void
664{
665 NS_LOG_FUNCTION(this << interface << " " << address.GetLocal());
666 if (!m_ipv4->IsUp(interface))
667 {
668 return;
669 }
670 Ipv4Address networkAddress = address.GetLocal().CombineMask(address.GetMask());
671 Ipv4Mask networkMask = address.GetMask();
672 // Remove all static routes that are going through this interface
673 // which reference this network
674 for (NetworkRoutesI it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
675 {
676 if (it->first->GetInterface() == interface && it->first->IsNetwork() &&
677 it->first->GetDestNetwork() == networkAddress &&
678 it->first->GetDestNetworkMask() == networkMask)
679 {
680 delete it->first;
681 it = m_networkRoutes.erase(it);
682 }
683 else
684 {
685 it++;
686 }
687 }
688}
689
690void
692{
693 NS_LOG_FUNCTION(this << ipv4);
694 NS_ASSERT(!m_ipv4 && ipv4);
695 m_ipv4 = ipv4;
696 for (uint32_t i = 0; i < m_ipv4->GetNInterfaces(); i++)
697 {
698 if (m_ipv4->IsUp(i))
699 {
701 }
702 else
703 {
705 }
706 }
707}
708
709// Formatted like output of "route -n" command
710void
712{
713 NS_LOG_FUNCTION(this << stream);
714 std::ostream* os = stream->GetStream();
715 // Copy the current ostream state
716 std::ios oldState(nullptr);
717 oldState.copyfmt(*os);
718
719 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
720
721 *os << "Node: " << m_ipv4->GetObject<Node>()->GetId() << ", Time: " << Now().As(unit)
722 << ", Local time: " << m_ipv4->GetObject<Node>()->GetLocalTime().As(unit)
723 << ", Ipv4StaticRouting table" << std::endl;
724
725 if (GetNRoutes() > 0)
726 {
727 *os << "Destination Gateway Genmask Flags Metric Ref Use Iface"
728 << std::endl;
729 for (uint32_t j = 0; j < GetNRoutes(); j++)
730 {
731 std::ostringstream dest;
732 std::ostringstream gw;
733 std::ostringstream mask;
734 std::ostringstream flags;
736 dest << route.GetDest();
737 *os << std::setw(16) << dest.str();
738 gw << route.GetGateway();
739 *os << std::setw(16) << gw.str();
740 mask << route.GetDestNetworkMask();
741 *os << std::setw(16) << mask.str();
742 flags << "U";
743 if (route.IsHost())
744 {
745 flags << "HS";
746 }
747 else if (route.IsGateway())
748 {
749 flags << "GS";
750 }
751 *os << std::setw(6) << flags.str();
752 *os << std::setw(7) << GetMetric(j);
753 // Ref ct not implemented
754 *os << "-"
755 << " ";
756 // Use not implemented
757 *os << "-"
758 << " ";
759 if (!Names::FindName(m_ipv4->GetNetDevice(route.GetInterface())).empty())
760 {
761 *os << Names::FindName(m_ipv4->GetNetDevice(route.GetInterface()));
762 }
763 else
764 {
765 *os << route.GetInterface();
766 }
767 *os << std::endl;
768 }
769 }
770 *os << std::endl;
771 // Restore the previous ostream state
772 (*os).copyfmt(oldState);
773}
774
775} // namespace ns3
bool IsNull() const
Check for null implementation.
Definition: callback.h:567
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:441
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.
std::list< Ipv4MulticastRoutingTableEntry * >::const_iterator MulticastRoutesCI
Const Iterator for container for the multicast routes.
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.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::const_iterator NetworkRoutesCI
Const Iterator for container for the network routes.
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.
std::list< Ipv4MulticastRoutingTableEntry * >::iterator MulticastRoutesI
Iterator for container for the multicast routes.
std::list< std::pair< Ipv4RoutingTableEntry *, uint32_t > >::iterator NetworkRoutesI
Iterator for container for the network routes.
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:830
A network Node.
Definition: node.h:56
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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:417
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:936
#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:296
Every class exported by the ns3 library is enclosed in the ns3 namespace.