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
29
32{
33 static TypeId tid = TypeId("ns3::Ipv6StaticRouting")
35 .SetGroupName("Internet")
36 .AddConstructor<Ipv6StaticRouting>();
37 return tid;
38}
39
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 {
122 *os << Names::FindName(m_ipv6->GetNetDevice(route.GetInterface()));
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(
387 m_ipv6->SourceAddressSelection(m_ipv6->GetInterfaceForDevice(interface), dst));
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
563 if (maskLen)
564 {
565 continue;
566 }
567
568 if (metric > shortestMetric)
569 {
570 continue;
571 }
572 shortestMetric = metric;
573 result = j;
574 }
575
576 if (result)
577 {
578 return result;
579 }
580 else
581 {
582 return Ipv6RoutingTableEntry();
583 }
584}
585
588{
589 NS_LOG_FUNCTION(this << index);
590 uint32_t tmp = 0;
591
592 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
593 {
594 if (tmp == index)
595 {
596 return it->first;
597 }
598 tmp++;
599 }
600 NS_ASSERT(false);
601 // quiet compiler.
602 return nullptr;
603}
604
607{
608 NS_LOG_FUNCTION(this << index);
609 uint32_t tmp = 0;
610
611 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
612 {
613 if (tmp == index)
614 {
615 return it->second;
616 }
617 tmp++;
618 }
619 NS_ASSERT(false);
620 // quiet compiler.
621 return 0;
622}
623
624void
626{
627 NS_LOG_FUNCTION(this << index);
628 uint32_t tmp = 0;
629
630 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
631 {
632 if (tmp == index)
633 {
634 delete it->first;
635 m_networkRoutes.erase(it);
636 return;
637 }
638 tmp++;
639 }
640 NS_ASSERT(false);
641}
642
643void
645 Ipv6Prefix prefix,
646 uint32_t ifIndex,
647 Ipv6Address prefixToUse)
648{
649 NS_LOG_FUNCTION(this << network << prefix << ifIndex);
650
651 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end(); it++)
652 {
653 Ipv6RoutingTableEntry* rtentry = it->first;
654 if (network == rtentry->GetDest() && rtentry->GetInterface() == ifIndex &&
655 rtentry->GetPrefixToUse() == prefixToUse)
656 {
657 delete it->first;
658 m_networkRoutes.erase(it);
659 return;
660 }
661 }
662}
663
666 const Ipv6Header& header,
667 Ptr<NetDevice> oif,
668 Socket::SocketErrno& sockerr)
669{
670 NS_LOG_FUNCTION(this << header << oif);
671 Ipv6Address destination = header.GetDestination();
672 Ptr<Ipv6Route> rtentry = nullptr;
673
674 if (destination.IsMulticast())
675 {
676 // Note: Multicast routes for outbound packets are stored in the
677 // normal unicast table. An implication of this is that it is not
678 // possible to source multicast datagrams on multiple interfaces.
679 // This is a well-known property of sockets implementation on
680 // many Unix variants.
681 // So, we just log it and fall through to LookupStatic ()
682 NS_LOG_LOGIC("RouteOutput ()::Multicast destination");
683 }
684
685 rtentry = LookupStatic(destination, oif);
686 if (rtentry)
687 {
688 sockerr = Socket::ERROR_NOTERROR;
689 }
690 else
691 {
693 }
694 return rtentry;
695}
696
697bool
699 const Ipv6Header& header,
701 const UnicastForwardCallback& ucb,
702 const MulticastForwardCallback& mcb,
703 const LocalDeliverCallback& lcb,
704 const ErrorCallback& ecb)
705{
706 NS_LOG_FUNCTION(this << p << header << header.GetSource() << header.GetDestination() << idev);
708 // Check if input device supports IP
709 NS_ASSERT(m_ipv6->GetInterfaceForDevice(idev) >= 0);
710 uint32_t iif = m_ipv6->GetInterfaceForDevice(idev);
711 Ipv6Address dst = header.GetDestination();
712
713 // Multicast recognition; handle local delivery here
714 if (dst.IsMulticast())
715 {
716 NS_LOG_LOGIC("Multicast destination");
718 header.GetDestination(),
719 m_ipv6->GetInterfaceForDevice(idev));
720
721 // \todo check if we want to forward up the packet
722 if (mrtentry)
723 {
724 NS_LOG_LOGIC("Multicast route found");
725 mcb(idev, mrtentry, p, header); // multicast forwarding callback
726 return true;
727 }
728 else
729 {
730 NS_LOG_LOGIC("Multicast route not found");
731 return false; // Let other routing protocols try to handle this
732 }
733 }
734
735 // Check if input device supports IP forwarding
736 if (!m_ipv6->IsForwarding(iif))
737 {
738 NS_LOG_LOGIC("Forwarding disabled for this interface");
739 if (!ecb.IsNull())
740 {
741 ecb(p, header, Socket::ERROR_NOROUTETOHOST);
742 }
743 return true;
744 }
745 // Next, try to find a route
746 NS_LOG_LOGIC("Unicast destination");
747 Ptr<Ipv6Route> rtentry = LookupStatic(header.GetDestination());
748
749 if (rtentry)
750 {
751 NS_LOG_LOGIC("Found unicast destination- calling unicast callback");
752 ucb(idev, rtentry, p, header); // unicast forwarding callback
753 return true;
754 }
755 else
756 {
757 NS_LOG_LOGIC("Did not find unicast destination- returning false");
758 return false; // Let other routing protocols try to handle this
759 }
760}
761
762void
764{
765 for (uint32_t j = 0; j < m_ipv6->GetNAddresses(i); j++)
766 {
767 Ipv6InterfaceAddress addr = m_ipv6->GetAddress(i, j);
768
769 if (addr.GetAddress() != Ipv6Address() && addr.GetPrefix() != Ipv6Prefix())
770 {
771 if (addr.GetPrefix() == Ipv6Prefix(128))
772 {
773 /* host route */
774 AddHostRouteTo(addr.GetAddress(), i);
775 }
776 else
777 {
778 if (addr.GetOnLink())
779 {
781 addr.GetPrefix(),
782 i);
783 }
784 }
785 }
786 }
787}
788
789void
791{
792 NS_LOG_FUNCTION(this << i);
793
794 /* remove all static routes that are going through this interface */
795 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
796 {
797 if (it->first->GetInterface() == i)
798 {
799 delete it->first;
800 it = m_networkRoutes.erase(it);
801 }
802 else
803 {
804 it++;
805 }
806 }
807}
808
809void
811{
812 if (!m_ipv6->IsUp(interface))
813 {
814 return;
815 }
816}
817
818void
820{
821 if (!m_ipv6->IsUp(interface))
822 {
823 return;
824 }
825
826 Ipv6Address networkAddress = address.GetAddress().CombinePrefix(address.GetPrefix());
827 Ipv6Prefix networkMask = address.GetPrefix();
828
829 // Remove all static routes that are going through this interface
830 // which reference this network
831 for (auto it = m_networkRoutes.begin(); it != m_networkRoutes.end();)
832 {
833 if (it->first->GetInterface() == interface && it->first->IsNetwork() &&
834 it->first->GetDestNetwork() == networkAddress &&
835 it->first->GetDestNetworkPrefix() == networkMask)
836 {
837 delete it->first;
838 it = m_networkRoutes.erase(it);
839 }
840 else
841 {
842 it++;
843 }
844 }
845}
846
847void
849 Ipv6Prefix mask,
850 Ipv6Address nextHop,
851 uint32_t interface,
852 Ipv6Address prefixToUse)
853{
854 NS_LOG_FUNCTION(this << dst << mask << nextHop << interface << prefixToUse);
855 if (nextHop == Ipv6Address::GetZero())
856 {
857 AddNetworkRouteTo(dst, mask, interface);
858 }
859 else if (dst != Ipv6Address::GetZero())
860 {
861 AddNetworkRouteTo(dst, mask, nextHop, interface);
862 }
863 else /* default route */
864 {
865 /* this case is mainly used by configuring default route following RA processing,
866 * in case of multiple prefix in RA, the first will configured default route
867 */
868
869 /* for the moment, all default route has the same metric
870 * so according to the longest prefix algorithm,
871 * the default route chosen will be the last added
872 */
873 SetDefaultRoute(nextHop, interface, prefixToUse);
874 }
875}
876
877void
879 Ipv6Prefix mask,
880 Ipv6Address nextHop,
881 uint32_t interface,
882 Ipv6Address prefixToUse)
883{
884 NS_LOG_FUNCTION(this << dst << mask << nextHop << interface);
885 if (dst != Ipv6Address::GetZero())
886 {
887 for (auto j = m_networkRoutes.begin(); j != m_networkRoutes.end();)
888 {
889 Ipv6RoutingTableEntry* rtentry = j->first;
890 Ipv6Prefix prefix = rtentry->GetDestNetworkPrefix();
891 Ipv6Address entry = rtentry->GetDestNetwork();
892
893 if (dst == entry && prefix == mask && rtentry->GetInterface() == interface)
894 {
895 delete j->first;
896 j = m_networkRoutes.erase(j);
897 }
898 else
899 {
900 ++j;
901 }
902 }
903 }
904 else
905 {
906 /* default route case */
907 RemoveRoute(dst, mask, interface, prefixToUse);
908 }
909}
910
911} /* namespace ns3 */
return result
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.
static const uint32_t IF_ANY
Any interface magic number.
Definition ipv6.h:389
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
Check whether two addresses have the same bits in the prefix portion of their addresses.
static Ipv6Prefix GetOnes()
Get the "all-1" IPv6 mask (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
Abstract base class for IPv6 routing protocols.
Callback< void, Ptr< const Packet >, const Ipv6Header &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found).
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6MulticastRoute >, Ptr< const Packet >, const Ipv6Header & > MulticastForwardCallback
Callback for multicast packets to be forwarded.
Callback< void, Ptr< const Packet >, const Ipv6Header &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6Route >, Ptr< const Packet >, const Ipv6Header & > UnicastForwardCallback
Callback for unicast packets to be forwarded.
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
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
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:409
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:102
a unique identifier for an interface.
Definition type-id.h:49
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:439
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.