A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-static-routing.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 */
8
10
11#include "ipv6-route.h"
13
14#include "ns3/log.h"
15#include "ns3/names.h"
16#include "ns3/net-device.h"
17#include "ns3/node.h"
18#include "ns3/packet.h"
19#include "ns3/simulator.h"
20
21#include <iomanip>
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("Ipv6StaticRouting");
27
28NS_OBJECT_ENSURE_REGISTERED(Ipv6StaticRouting);
29
30TypeId
32{
33 static TypeId tid = TypeId("ns3::Ipv6StaticRouting")
35 .SetGroupName("Internet")
36 .AddConstructor<Ipv6StaticRouting>();
37 return tid;
38}
39
41 : m_ipv6(nullptr)
42{
43 NS_LOG_FUNCTION(this);
44}
45
50
51void
53{
54 NS_LOG_FUNCTION(this << ipv6);
55 NS_ASSERT(!m_ipv6 && ipv6);
56 uint32_t i = 0;
57 m_ipv6 = ipv6;
58
59 for (i = 0; i < m_ipv6->GetNInterfaces(); i++)
60 {
61 if (m_ipv6->IsUp(i))
62 {
64 }
65 else
66 {
68 }
69 }
70}
71
72// Formatted like output of "route -n" command
73void
75{
76 NS_LOG_FUNCTION(this << stream);
77 std::ostream* os = stream->GetStream();
78 // Copy the current ostream state
79 std::ios oldState(nullptr);
80 oldState.copyfmt(*os);
81
82 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
83
84 *os << "Node: " << m_ipv6->GetObject<Node>()->GetId() << ", Time: " << Now().As(unit)
85 << ", Local time: " << m_ipv6->GetObject<Node>()->GetLocalTime().As(unit)
86 << ", Ipv6StaticRouting table" << std::endl;
87
88 if (GetNRoutes() > 0)
89 {
90 *os << "Destination Next Hop Flag Met Ref Use If"
91 << std::endl;
92 for (uint32_t j = 0; j < GetNRoutes(); j++)
93 {
94 std::ostringstream dest;
95 std::ostringstream gw;
96 std::ostringstream mask;
97 std::ostringstream flags;
99 dest << route.GetDest() << "/" << int(route.GetDestNetworkPrefix().GetPrefixLength());
100 *os << std::setw(31) << dest.str();
101 gw << route.GetGateway();
102 *os << std::setw(27) << gw.str();
103 flags << "U";
104 if (route.IsHost())
105 {
106 flags << "H";
107 }
108 else if (route.IsGateway())
109 {
110 flags << "G";
111 }
112 *os << std::setw(5) << flags.str();
113 *os << std::setw(4) << GetMetric(j);
114 // Ref ct not implemented
115 *os << "-"
116 << " ";
117 // Use not implemented
118 *os << "-"
119 << " ";
120 if (!Names::FindName(m_ipv6->GetNetDevice(route.GetInterface())).empty())
121 {
123 }
124 else
125 {
126 *os << route.GetInterface();
127 }
128 *os << std::endl;
129 }
130 }
131 *os << std::endl;
132 // Restore the previous ostream state
133 (*os).copyfmt(oldState);
134}
135
136void
138 Ipv6Address nextHop,
139 uint32_t interface,
140 Ipv6Address prefixToUse,
141 uint32_t metric)
142{
143 NS_LOG_FUNCTION(this << dst << nextHop << interface << prefixToUse << metric);
144 if (nextHop.IsLinkLocal())
145 {
146 NS_LOG_WARN("Ipv6StaticRouting::AddHostRouteTo - Next hop should be link-local");
147 }
148
149 AddNetworkRouteTo(dst, Ipv6Prefix::GetOnes(), nextHop, interface, prefixToUse, metric);
150}
151
152void
154{
155 NS_LOG_FUNCTION(this << dst << interface << metric);
156 AddNetworkRouteTo(dst, Ipv6Prefix::GetOnes(), interface, metric);
157}
158
159void
161 Ipv6Prefix networkPrefix,
162 Ipv6Address nextHop,
163 uint32_t interface,
164 uint32_t metric)
165{
166 NS_LOG_FUNCTION(this << network << networkPrefix << nextHop << interface << metric);
167
169 Ipv6RoutingTableEntry::CreateNetworkRouteTo(network, networkPrefix, nextHop, interface);
170
171 if (!LookupRoute(route, metric))
172 {
173 auto routePtr = new Ipv6RoutingTableEntry(route);
174 m_networkRoutes.emplace_back(routePtr, metric);
175 }
176}
177
178void
180 Ipv6Prefix networkPrefix,
181 Ipv6Address nextHop,
182 uint32_t interface,
183 Ipv6Address prefixToUse,
184 uint32_t metric)
185{
186 NS_LOG_FUNCTION(this << network << networkPrefix << nextHop << interface << prefixToUse
187 << metric);
188 if (nextHop.IsLinkLocal())
189 {
190 NS_LOG_WARN("Ipv6StaticRouting::AddNetworkRouteTo - Next hop should be link-local");
191 }
192
194 networkPrefix,
195 nextHop,
196 interface,
197 prefixToUse);
198 if (!LookupRoute(route, metric))
199 {
200 auto routePtr = new Ipv6RoutingTableEntry(route);
201 m_networkRoutes.emplace_back(routePtr, metric);
202 }
203}
204
205void
207 Ipv6Prefix networkPrefix,
208 uint32_t interface,
209 uint32_t metric)
210{
211 NS_LOG_FUNCTION(this << network << networkPrefix << interface);
212
214 Ipv6RoutingTableEntry::CreateNetworkRouteTo(network, networkPrefix, interface);
215 if (!LookupRoute(route, metric))
216 {
217 auto routePtr = new Ipv6RoutingTableEntry(route);
218 m_networkRoutes.emplace_back(routePtr, metric);
219 }
220}
221
222void
224 uint32_t interface,
225 Ipv6Address prefixToUse,
226 uint32_t metric)
227{
228 NS_LOG_FUNCTION(this << nextHop << interface << prefixToUse);
231 nextHop,
232 interface,
233 prefixToUse,
234 metric);
235}
236
237void
239 Ipv6Address group,
240 uint32_t inputInterface,
241 std::vector<uint32_t> outputInterfaces)
242{
243 NS_LOG_FUNCTION(this << origin << group << inputInterface);
244 auto route = new Ipv6MulticastRoutingTableEntry();
246 group,
247 inputInterface,
248 outputInterfaces);
249 m_multicastRoutes.push_back(route);
250}
251
252void
254{
255 NS_LOG_FUNCTION(this << outputInterface);
256 auto route = new Ipv6RoutingTableEntry();
257 Ipv6Address network = Ipv6Address("ff00::"); /* RFC 3513 */
258 Ipv6Prefix networkMask = Ipv6Prefix(8);
259 *route = Ipv6RoutingTableEntry::CreateNetworkRouteTo(network, networkMask, outputInterface);
260 m_networkRoutes.emplace_back(route, 0);
261}
262
265{
266 NS_LOG_FUNCTION(this);
267 return m_multicastRoutes.size();
268}
269
272{
273 NS_LOG_FUNCTION(this << index);
274 NS_ASSERT_MSG(index < m_multicastRoutes.size(),
275 "Ipv6StaticRouting::GetMulticastRoute () : Index out of range");
276
277 if (index < m_multicastRoutes.size())
278 {
279 uint32_t tmp = 0;
280 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
281 {
282 if (tmp == index)
283 {
284 return *i;
285 }
286 tmp++;
287 }
288 }
289 return nullptr;
290}
291
292bool
294 Ipv6Address group,
295 uint32_t inputInterface)
296{
297 NS_LOG_FUNCTION(this << origin << group << inputInterface);
298 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
299 {
301 if (origin == route->GetOrigin() && group == route->GetGroup() &&
302 inputInterface == route->GetInputInterface())
303 {
304 delete *i;
305 m_multicastRoutes.erase(i);
306 return true;
307 }
308 }
309 return false;
310}
311
312void
314{
315 NS_LOG_FUNCTION(this << index);
316 uint32_t tmp = 0;
317
318 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
319 {
320 if (tmp == index)
321 {
322 delete *i;
323 m_multicastRoutes.erase(i);
324 return;
325 }
326 tmp++;
327 }
328}
329
330bool
332{
333 NS_LOG_FUNCTION(this << network << interfaceIndex);
334
335 /* in the network table */
336 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
337 {
338 Ipv6RoutingTableEntry* rtentry = j->first;
339 Ipv6Prefix prefix = rtentry->GetDestNetworkPrefix();
340 Ipv6Address entry = rtentry->GetDestNetwork();
341
342 if (prefix.IsMatch(network, entry) && rtentry->GetInterface() == interfaceIndex)
343 {
344 return true;
345 }
346 }
347
348 /* beuh!!! not route at all */
349 return false;
350}
351
352bool
354{
355 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j++)
356 {
357 Ipv6RoutingTableEntry* rtentry = j->first;
358
359 if (rtentry->GetDest() == route.GetDest() &&
360 rtentry->GetDestNetworkPrefix() == route.GetDestNetworkPrefix() &&
361 rtentry->GetGateway() == route.GetGateway() &&
362 rtentry->GetInterface() == route.GetInterface() &&
363 rtentry->GetPrefixToUse() == route.GetPrefixToUse() && j->second == metric)
364 {
365 return true;
366 }
367 }
368 return false;
369}
370
373{
374 NS_LOG_FUNCTION(this << dst << interface);
375 Ptr<Ipv6Route> rtentry = nullptr;
376 uint16_t longestMask = 0;
377 uint32_t shortestMetric = 0xffffffff;
378
379 /* when sending on link-local multicast, there have to be interface specified */
380 if (dst.IsLinkLocalMulticast())
381 {
383 interface,
384 "Try to send on link-local multicast address, and no interface index is given!");
385 rtentry = Create<Ipv6Route>();
386 rtentry->SetSource(
388 rtentry->SetDestination(dst);
389 rtentry->SetGateway(Ipv6Address::GetZero());
390 rtentry->SetOutputDevice(interface);
391 return rtentry;
392 }
393
394 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
395 {
396 Ipv6RoutingTableEntry* j = it->first;
397 uint32_t metric = it->second;
399 uint16_t maskLen = mask.GetPrefixLength();
400 Ipv6Address entry = j->GetDestNetwork();
401
402 NS_LOG_LOGIC("Searching for route to " << dst << ", mask length " << maskLen << ", metric "
403 << metric);
404
405 if (mask.IsMatch(dst, entry))
406 {
407 NS_LOG_LOGIC("Found global network route " << *j << ", mask length " << maskLen
408 << ", metric " << metric);
409
410 /* if interface is given, check the route will output on this interface */
411 if (!interface || interface == m_ipv6->GetNetDevice(j->GetInterface()))
412 {
413 if (maskLen < longestMask)
414 {
415 NS_LOG_LOGIC("Previous match longer, skipping");
416 continue;
417 }
418
419 if (maskLen > longestMask)
420 {
421 shortestMetric = 0xffffffff;
422 }
423
424 longestMask = maskLen;
425 if (metric > shortestMetric)
426 {
427 NS_LOG_LOGIC("Equal mask length, but previous metric shorter, skipping");
428 continue;
429 }
430
431 shortestMetric = metric;
432 Ipv6RoutingTableEntry* route = j;
433 uint32_t interfaceIdx = route->GetInterface();
434 rtentry = Create<Ipv6Route>();
435
436 if (route->GetGateway().IsAny() || !route->GetDest().IsAny())
437 {
438 rtentry->SetSource(
439 m_ipv6->SourceAddressSelection(interfaceIdx, route->GetDest()));
440 }
441 else
442 {
443 // Default route
444 rtentry->SetSource(m_ipv6->SourceAddressSelection(
445 interfaceIdx,
446 route->GetPrefixToUse().IsAny() ? dst : route->GetPrefixToUse()));
447 }
448
449 rtentry->SetDestination(route->GetDest());
450 rtentry->SetGateway(route->GetGateway());
451 rtentry->SetOutputDevice(m_ipv6->GetNetDevice(interfaceIdx));
452 if (maskLen == 128)
453 {
454 break;
455 }
456 }
457 }
458 }
459
460 if (rtentry)
461 {
462 NS_LOG_LOGIC("Matching route via " << rtentry->GetDestination() << " (Through "
463 << rtentry->GetGateway() << ") at the end");
464 }
465 return rtentry;
466}
467
468void
470{
471 NS_LOG_FUNCTION(this);
472
473 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end(); j = m_networkRoutes.erase(j))
474 {
475 delete j->first;
476 }
477 m_networkRoutes.clear();
478
479 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end();
480 i = m_multicastRoutes.erase(i))
481 {
482 delete (*i);
483 }
484 m_multicastRoutes.clear();
485
486 m_ipv6 = nullptr;
488}
489
492{
493 NS_LOG_FUNCTION(this << origin << group << interface);
494 Ptr<Ipv6MulticastRoute> mrtentry = nullptr;
495
496 for (auto i = m_multicastRoutes.begin(); i != m_multicastRoutes.end(); i++)
497 {
499
500 /*
501 We've been passed an origin address, a multicast group address and an
502 interface index. We have to decide if the current route in the list is
503 a match.
504
505 The first case is the restrictive case where the origin, group and index
506 matches. This picks up exact routes during forwarded and exact routes from
507 the local node (in which case the ifIndex is a wildcard).
508 */
509
510 if (origin == route->GetOrigin() && group == route->GetGroup())
511 {
512 /* skipping SSM case */
513 NS_LOG_LOGIC("Find source specific multicast route" << *i);
514 }
515
516 if (group == route->GetGroup())
517 {
518 if (interface == Ipv6::IF_ANY || interface == route->GetInputInterface())
519 {
520 NS_LOG_LOGIC("Found multicast route" << *i);
521 mrtentry = Create<Ipv6MulticastRoute>();
522 mrtentry->SetGroup(route->GetGroup());
523 mrtentry->SetOrigin(route->GetOrigin());
524 mrtentry->SetParent(route->GetInputInterface());
525 for (uint32_t j = 0; j < route->GetNOutputInterfaces(); j++)
526 {
527 if (route->GetOutputInterface(j))
528 {
529 NS_LOG_LOGIC("Setting output interface index "
530 << route->GetOutputInterface(j));
531 mrtentry->SetOutputTtl(route->GetOutputInterface(j),
533 }
534 }
535 return mrtentry;
536 }
537 }
538 }
539 return mrtentry;
540}
541
544{
545 return m_networkRoutes.size();
546}
547
550{
551 NS_LOG_FUNCTION(this);
552 Ipv6Address dst("::");
553 uint32_t shortestMetric = 0xffffffff;
554 Ipv6RoutingTableEntry* result = nullptr;
555
556 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
557 {
558 Ipv6RoutingTableEntry* j = it->first;
559 uint32_t metric = it->second;
561 uint16_t maskLen = mask.GetPrefixLength();
562 Ipv6Address entry = j->GetDestNetwork();
563
564 if (maskLen)
565 {
566 continue;
567 }
568
569 if (metric > shortestMetric)
570 {
571 continue;
572 }
573 shortestMetric = metric;
574 result = j;
575 }
576
577 if (result)
578 {
579 return result;
580 }
581 else
582 {
583 return Ipv6RoutingTableEntry();
584 }
585}
586
589{
590 NS_LOG_FUNCTION(this << index);
591 uint32_t tmp = 0;
592
593 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
594 {
595 if (tmp == index)
596 {
597 return it->first;
598 }
599 tmp++;
600 }
601 NS_ASSERT(false);
602 // quiet compiler.
603 return nullptr;
604}
605
608{
609 NS_LOG_FUNCTION(this << index);
610 uint32_t tmp = 0;
611
612 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
613 {
614 if (tmp == index)
615 {
616 return it->second;
617 }
618 tmp++;
619 }
620 NS_ASSERT(false);
621 // quiet compiler.
622 return 0;
623}
624
625void
627{
628 NS_LOG_FUNCTION(this << index);
629 uint32_t tmp = 0;
630
631 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
632 {
633 if (tmp == index)
634 {
635 delete it->first;
636 m_networkRoutes.erase(it);
637 return;
638 }
639 tmp++;
640 }
641 NS_ASSERT(false);
642}
643
644void
646 Ipv6Prefix prefix,
647 uint32_t ifIndex,
648 Ipv6Address prefixToUse)
649{
650 NS_LOG_FUNCTION(this << network << prefix << ifIndex);
651
652 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
653 {
654 Ipv6RoutingTableEntry* rtentry = it->first;
655 if (network == rtentry->GetDest() && rtentry->GetInterface() == ifIndex &&
656 rtentry->GetPrefixToUse() == prefixToUse)
657 {
658 delete it->first;
659 m_networkRoutes.erase(it);
660 return;
661 }
662 }
663}
664
667 const Ipv6Header& header,
668 Ptr<NetDevice> oif,
669 Socket::SocketErrno& sockerr)
670{
671 NS_LOG_FUNCTION(this << header << oif);
672 Ipv6Address destination = header.GetDestination();
673 Ptr<Ipv6Route> rtentry = nullptr;
674
675 if (destination.IsMulticast())
676 {
677 // Note: Multicast routes for outbound packets are stored in the
678 // normal unicast table. An implication of this is that it is not
679 // possible to source multicast datagrams on multiple interfaces.
680 // This is a well-known property of sockets implementation on
681 // many Unix variants.
682 // So, we just log it and fall through to LookupStatic ()
683 NS_LOG_LOGIC("RouteOutput ()::Multicast destination");
684 }
685
686 rtentry = LookupStatic(destination, oif);
687 if (rtentry)
688 {
689 sockerr = Socket::ERROR_NOTERROR;
690 }
691 else
692 {
694 }
695 return rtentry;
696}
697
698bool
700 const Ipv6Header& header,
702 const UnicastForwardCallback& ucb,
703 const MulticastForwardCallback& mcb,
704 const LocalDeliverCallback& lcb,
705 const ErrorCallback& ecb)
706{
707 NS_LOG_FUNCTION(this << p << header << header.GetSource() << header.GetDestination() << idev);
709 // Check if input device supports IP
712 Ipv6Address dst = header.GetDestination();
713
714 // Multicast recognition; handle local delivery here
715 if (dst.IsMulticast())
716 {
717 NS_LOG_LOGIC("Multicast destination");
719 header.GetDestination(),
721
722 // \todo check if we want to forward up the packet
723 if (mrtentry)
724 {
725 NS_LOG_LOGIC("Multicast route found");
726 mcb(idev, mrtentry, p, header); // multicast forwarding callback
727 return true;
728 }
729 else
730 {
731 NS_LOG_LOGIC("Multicast route not found");
732 return false; // Let other routing protocols try to handle this
733 }
734 }
735
736 // Check if input device supports IP forwarding
737 if (!m_ipv6->IsForwarding(iif))
738 {
739 NS_LOG_LOGIC("Forwarding disabled for this interface");
740 if (!ecb.IsNull())
741 {
742 ecb(p, header, Socket::ERROR_NOROUTETOHOST);
743 }
744 return true;
745 }
746 // Next, try to find a route
747 NS_LOG_LOGIC("Unicast destination");
748 Ptr<Ipv6Route> rtentry = LookupStatic(header.GetDestination());
749
750 if (rtentry)
751 {
752 NS_LOG_LOGIC("Found unicast destination- calling unicast callback");
753 ucb(idev, rtentry, p, header); // unicast forwarding callback
754 return true;
755 }
756 else
757 {
758 NS_LOG_LOGIC("Did not find unicast destination- returning false");
759 return false; // Let other routing protocols try to handle this
760 }
761}
762
763void
765{
766 for (uint32_t j = 0; j < m_ipv6->GetNAddresses(i); j++)
767 {
769
770 if (addr.GetAddress() != Ipv6Address() && addr.GetPrefix() != Ipv6Prefix())
771 {
772 if (addr.GetPrefix() == Ipv6Prefix(128))
773 {
774 /* host route */
775 AddHostRouteTo(addr.GetAddress(), i);
776 }
777 else
778 {
779 if (addr.GetOnLink())
780 {
782 addr.GetPrefix(),
783 i);
784 }
785 }
786 }
787 }
788}
789
790void
792{
793 NS_LOG_FUNCTION(this << i);
794
795 /* remove all static routes that are going through this interface */
796 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
797 {
798 if (it->first->GetInterface() == i)
799 {
800 delete it->first;
801 it = m_networkRoutes.erase(it);
802 }
803 else
804 {
805 it++;
806 }
807 }
808}
809
810void
812{
813 if (!m_ipv6->IsUp(interface))
814 {
815 return;
816 }
817}
818
819void
821{
822 if (!m_ipv6->IsUp(interface))
823 {
824 return;
825 }
826
827 Ipv6Address networkAddress = address.GetAddress().CombinePrefix(address.GetPrefix());
828 Ipv6Prefix networkMask = address.GetPrefix();
829
830 // Remove all static routes that are going through this interface
831 // which reference this network
832 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
833 {
834 if (it->first->GetInterface() == interface && it->first->IsNetwork() &&
835 it->first->GetDestNetwork() == networkAddress &&
836 it->first->GetDestNetworkPrefix() == networkMask)
837 {
838 delete it->first;
839 it = m_networkRoutes.erase(it);
840 }
841 else
842 {
843 it++;
844 }
845 }
846}
847
848void
850 Ipv6Prefix mask,
851 Ipv6Address nextHop,
852 uint32_t interface,
853 Ipv6Address prefixToUse)
854{
855 NS_LOG_FUNCTION(this << dst << mask << nextHop << interface << prefixToUse);
856 if (nextHop == Ipv6Address::GetZero())
857 {
858 AddNetworkRouteTo(dst, mask, interface);
859 }
860 else if (dst != Ipv6Address::GetZero())
861 {
862 AddNetworkRouteTo(dst, mask, nextHop, interface);
863 }
864 else /* default route */
865 {
866 /* this case is mainly used by configuring default route following RA processing,
867 * in case of multiple prefix in RA, the first will configured default route
868 */
869
870 /* for the moment, all default route has the same metric
871 * so according to the longest prefix algorithm,
872 * the default route chosen will be the last added
873 */
874 SetDefaultRoute(nextHop, interface, prefixToUse);
875 }
876}
877
878void
880 Ipv6Prefix mask,
881 Ipv6Address nextHop,
882 uint32_t interface,
883 Ipv6Address prefixToUse)
884{
885 NS_LOG_FUNCTION(this << dst << mask << nextHop << interface);
886 if (dst != Ipv6Address::GetZero())
887 {
888 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end();)
889 {
890 Ipv6RoutingTableEntry* rtentry = j->first;
891 Ipv6Prefix prefix = rtentry->GetDestNetworkPrefix();
892 Ipv6Address entry = rtentry->GetDestNetwork();
893
894 if (dst == entry && prefix == mask && rtentry->GetInterface() == interface)
895 {
896 delete j->first;
897 j = m_networkRoutes.erase(j);
898 }
899 else
900 {
901 ++j;
902 }
903 }
904 }
905 else
906 {
907 /* default route case */
908 RemoveRoute(dst, mask, interface, prefixToUse);
909 }
910}
911
912} /* namespace ns3 */
bool IsNull() const
Check for null implementation.
Definition callback.h:555
Describes an IPv6 address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
bool IsAny() const
If the IPv6 address is the "Any" address.
Ipv6Address CombinePrefix(const Ipv6Prefix &prefix) const
Combine this address with a prefix.
Packet header for IPv6.
Definition ipv6-header.h:24
Ipv6Address GetDestination() const
Get the "Destination address" field.
Ipv6Address GetSource() const
Get the "Source address" field.
virtual Ipv6InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Get IPv6 address on specified IPv6 interface.
virtual Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)=0
Choose the source address to use with destination address.
static const uint32_t IF_ANY
Any interface magic number.
Definition ipv6.h:389
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
Get the interface index of the specified NetDevice.
virtual uint32_t GetNInterfaces() const =0
Get number of interfaces.
virtual bool IsUp(uint32_t interface) const =0
If the specified interface index is in "up" state.
virtual bool IsForwarding(uint32_t interface) const =0
If the specified IPv6 interface has forwarding enabled.
virtual uint32_t GetNAddresses(uint32_t interface) const =0
Get number of addresses on specified IPv6 interface.
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
Get the NetDevice of the specified interface number.
IPv6 address associated with an interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
Ipv6Prefix GetPrefix() const
Get the IPv6 prefix.
bool GetOnLink() const
Get the on-link property.
static const uint32_t MAX_TTL
Maximum Time-To-Live (TTL).
Definition ipv6-route.h:137
A record of an IPv6 multicast route.
uint32_t GetInputInterface() const
Get the input interface address.
uint32_t GetOutputInterface(uint32_t n) const
Get a specified output interface.
Ipv6Address GetGroup() const
Get the group.
static Ipv6MulticastRoutingTableEntry CreateMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Create a multicast route.
uint32_t GetNOutputInterfaces() const
Get the number of output interfaces of this route.
Ipv6Address GetOrigin() const
Get the source of this route.
Describes an IPv6 prefix.
uint8_t GetPrefixLength() const
Get prefix length.
static Ipv6Prefix GetZero()
Get the zero prefix ( /0).
bool IsMatch(Ipv6Address a, Ipv6Address b) const
If the Address match the type.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
Abstract base class for IPv6 routing protocols.
A record of an IPv6 route.
Ipv6Address GetDest() const
Get the destination.
Ipv6Address GetDestNetwork() const
Get the destination network.
Ipv6Address GetPrefixToUse() const
Get the prefix to use (for multihomed link).
bool IsHost() const
Is the route entry correspond to a host ?
uint32_t GetInterface() const
Get the interface index.
Ipv6Prefix GetDestNetworkPrefix() const
Get the destination prefix.
static Ipv6RoutingTableEntry CreateNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface)
Create a route to a network.
Ipv6Address GetGateway() const
Get the gateway.
bool IsGateway() const
Is it the gateway ?
Static routing protocol for IP version 6 stacks.
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Ipv6RoutingTableEntry GetRoute(uint32_t i) const
Get a specified route.
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
void RemoveRoute(uint32_t i)
Remove a route from the routing table.
Ptr< Ipv6Route > RouteOutput(Ptr< Packet > p, const Ipv6Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
static TypeId GetTypeId()
The interface Id associated with this class.
Ptr< Ipv6Route > LookupStatic(Ipv6Address dest, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
bool HasNetworkDest(Ipv6Address dest, uint32_t interfaceIndex)
If the destination is already present in network destination list.
bool LookupRoute(const Ipv6RoutingTableEntry &route, uint32_t metric)
Checks if a route is already present in the forwarding table.
void AddMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface, std::vector< uint32_t > outputInterfaces)
Add a multicast route for a given multicast source and group.
void AddHostRouteTo(Ipv6Address dest, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Add route to host.
uint32_t GetNRoutes() const
Get the number or entries in the routing table.
Ipv6MulticastRoutingTableEntry GetMulticastRoute(uint32_t i) const
Get the specified multicast route.
Ipv6RoutingTableEntry GetDefaultRoute()
Get the default route.
MulticastRoutes m_multicastRoutes
the forwarding table for multicast.
uint32_t GetNMulticastRoutes() const
Get the number of entries in the multicast routing table.
bool RemoveMulticastRoute(Ipv6Address origin, Ipv6Address group, uint32_t inputInterface)
Remove a static multicast route.
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
void DoDispose() override
Dispose this object.
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric=0)
Add route to network.
NetworkRoutes m_networkRoutes
the forwarding table for network.
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
void SetDefaultMulticastRoute(uint32_t outputInterface)
Set the default multicast route.
bool RouteInput(Ptr< const Packet > p, const Ipv6Header &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)
uint32_t GetMetric(uint32_t index) const
Get a metric for route from the static unicast routing table.
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Ptr< Ipv6 > m_ipv6
Ipv6 reference.
void SetDefaultRoute(Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address("::"), uint32_t metric=0)
Set the default route.
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_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#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.