A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ripng.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Universita' di Firenze, Italy
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 */
19
20#include "ripng.h"
21
23#include "ipv6-route.h"
24#include "ripng-header.h"
25#include "udp-header.h"
26
27#include "ns3/abort.h"
28#include "ns3/assert.h"
29#include "ns3/enum.h"
30#include "ns3/log.h"
31#include "ns3/names.h"
32#include "ns3/node.h"
33#include "ns3/random-variable-stream.h"
34#include "ns3/simulator.h"
35#include "ns3/uinteger.h"
36
37#include <iomanip>
38
39#define RIPNG_ALL_NODE "ff02::9"
40#define RIPNG_PORT 521
41
42namespace ns3
43{
44
46
48
50 : m_ipv6(nullptr),
51 m_splitHorizonStrategy(RipNg::POISON_REVERSE),
52 m_initialized(false)
53{
54 m_rng = CreateObject<UniformRandomVariable>();
55}
56
58{
59}
60
63{
64 static TypeId tid =
65 TypeId("ns3::RipNg")
67 .SetGroupName("Internet")
68 .AddConstructor<RipNg>()
69 .AddAttribute("UnsolicitedRoutingUpdate",
70 "The time between two Unsolicited Routing Updates.",
71 TimeValue(Seconds(30)),
74 .AddAttribute("StartupDelay",
75 "Maximum random delay for protocol startup (send route requests).",
79 .AddAttribute("TimeoutDelay",
80 "The delay to invalidate a route.",
81 TimeValue(Seconds(180)),
84 .AddAttribute("GarbageCollectionDelay",
85 "The delay to delete an expired route.",
86 TimeValue(Seconds(120)),
89 .AddAttribute("MinTriggeredCooldown",
90 "Min cooldown delay after a Triggered Update.",
94 .AddAttribute("MaxTriggeredCooldown",
95 "Max cooldown delay after a Triggered Update.",
99 .AddAttribute("SplitHorizon",
100 "Split Horizon strategy.",
104 "NoSplitHorizon",
106 "SplitHorizon",
108 "PoisonReverse"))
109 .AddAttribute("LinkDownValue",
110 "Value for link down in count to infinity.",
111 UintegerValue(16),
113 MakeUintegerChecker<uint8_t>());
114 return tid;
115}
116
117int64_t
118RipNg::AssignStreams(int64_t stream)
119{
120 NS_LOG_FUNCTION(this << stream);
121
122 m_rng->SetStream(stream);
123 return 1;
124}
125
126void
128{
129 NS_LOG_FUNCTION(this);
130
131 bool addedGlobal = false;
132
133 m_initialized = true;
134
135 Time delay =
138
139 for (uint32_t i = 0; i < m_ipv6->GetNInterfaces(); i++)
140 {
141 bool activeInterface = false;
142 if (m_interfaceExclusions.find(i) == m_interfaceExclusions.end())
143 {
144 activeInterface = true;
145 m_ipv6->SetForwarding(i, true);
146 }
147
148 for (uint32_t j = 0; j < m_ipv6->GetNAddresses(i); j++)
149 {
150 Ipv6InterfaceAddress address = m_ipv6->GetAddress(i, j);
151 if (address.GetScope() == Ipv6InterfaceAddress::LINKLOCAL && activeInterface)
152 {
153 NS_LOG_LOGIC("RIPng: adding socket to " << address.GetAddress());
154 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
155 Ptr<Node> theNode = GetObject<Node>();
156 Ptr<Socket> socket = Socket::CreateSocket(theNode, tid);
157 Inet6SocketAddress local = Inet6SocketAddress(address.GetAddress(), RIPNG_PORT);
158 socket->BindToNetDevice(m_ipv6->GetNetDevice(i));
159 int ret = socket->Bind(local);
160 NS_ASSERT_MSG(ret == 0, "Bind unsuccessful");
161 socket->SetRecvCallback(MakeCallback(&RipNg::Receive, this));
162 socket->SetIpv6RecvHopLimit(true);
163 socket->SetRecvPktInfo(true);
164 m_unicastSocketList[socket] = i;
165 }
166 else if (m_ipv6->GetAddress(i, j).GetScope() == Ipv6InterfaceAddress::GLOBAL)
167 {
168 addedGlobal = true;
169 }
170 }
171 }
172
174 {
175 NS_LOG_LOGIC("RIPng: adding receiving socket");
176 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
177 Ptr<Node> theNode = GetObject<Node>();
184 }
185
186 if (addedGlobal)
187 {
191 }
192
195
197}
198
201 const Ipv6Header& header,
202 Ptr<NetDevice> oif,
203 Socket::SocketErrno& sockerr)
204{
205 NS_LOG_FUNCTION(this << header << oif);
206
207 Ipv6Address destination = header.GetDestination();
208 Ptr<Ipv6Route> rtentry = nullptr;
209
210 if (destination.IsMulticast())
211 {
212 // Note: Multicast routes for outbound packets are stored in the
213 // normal unicast table. An implication of this is that it is not
214 // possible to source multicast datagrams on multiple interfaces.
215 // This is a well-known property of sockets implementation on
216 // many Unix variants.
217 // So, we just log it and fall through to LookupStatic ()
218 NS_LOG_LOGIC("RouteOutput (): Multicast destination");
219 }
220
221 rtentry = Lookup(destination, true, oif);
222 if (rtentry)
223 {
224 sockerr = Socket::ERROR_NOTERROR;
225 }
226 else
227 {
229 }
230 return rtentry;
231}
232
233bool
235 const Ipv6Header& header,
237 const UnicastForwardCallback& ucb,
238 const MulticastForwardCallback& mcb,
239 const LocalDeliverCallback& lcb,
240 const ErrorCallback& ecb)
241{
242 NS_LOG_FUNCTION(this << p << header << header.GetSource() << header.GetDestination() << idev);
243
245 // Check if input device supports IP
246 NS_ASSERT(m_ipv6->GetInterfaceForDevice(idev) >= 0);
247 uint32_t iif = m_ipv6->GetInterfaceForDevice(idev);
248 Ipv6Address dst = header.GetDestination();
249
250 if (dst.IsMulticast())
251 {
252 NS_LOG_LOGIC("Multicast route not supported by RIPng");
253 return false; // Let other routing protocols try to handle this
254 }
255
256 if (header.GetDestination().IsLinkLocal() || header.GetSource().IsLinkLocal())
257 {
258 NS_LOG_LOGIC("Dropping packet not for me and with src or dst LinkLocal");
259 if (!ecb.IsNull())
260 {
261 ecb(p, header, Socket::ERROR_NOROUTETOHOST);
262 }
263 return false;
264 }
265
266 // Check if input device supports IP forwarding
267 if (!m_ipv6->IsForwarding(iif))
268 {
269 NS_LOG_LOGIC("Forwarding disabled for this interface");
270 if (!ecb.IsNull())
271 {
272 ecb(p, header, Socket::ERROR_NOROUTETOHOST);
273 }
274 return true;
275 }
276 // Next, try to find a route
277 NS_LOG_LOGIC("Unicast destination");
278 Ptr<Ipv6Route> rtentry = Lookup(header.GetDestination(), false);
279
280 if (rtentry)
281 {
282 NS_LOG_LOGIC("Found unicast destination - calling unicast callback");
283 ucb(idev, rtentry, p, header); // unicast forwarding callback
284 return true;
285 }
286 else
287 {
288 NS_LOG_LOGIC("Did not find unicast destination - returning false");
289 return false; // Let other routing protocols try to handle this
290 }
291}
292
293void
295{
296 NS_LOG_FUNCTION(this << i);
297
298 for (uint32_t j = 0; j < m_ipv6->GetNAddresses(i); j++)
299 {
300 Ipv6InterfaceAddress address = m_ipv6->GetAddress(i, j);
301 Ipv6Prefix networkMask = address.GetPrefix();
302 Ipv6Address networkAddress = address.GetAddress().CombinePrefix(networkMask);
303
304 if (address.GetScope() == Ipv6InterfaceAddress::GLOBAL)
305 {
306 AddNetworkRouteTo(networkAddress, networkMask, i);
307 }
308 }
309
310 if (!m_initialized)
311 {
312 return;
313 }
314
315 bool sendSocketFound = false;
316 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end(); iter++)
317 {
318 if (iter->second == i)
319 {
320 sendSocketFound = true;
321 break;
322 }
323 }
324
325 bool activeInterface = false;
326 if (m_interfaceExclusions.find(i) == m_interfaceExclusions.end())
327 {
328 activeInterface = true;
329 m_ipv6->SetForwarding(i, true);
330 }
331
332 for (uint32_t j = 0; j < m_ipv6->GetNAddresses(i); j++)
333 {
334 Ipv6InterfaceAddress address = m_ipv6->GetAddress(i, j);
335
336 if (address.GetScope() == Ipv6InterfaceAddress::LINKLOCAL && !sendSocketFound &&
337 activeInterface)
338 {
339 NS_LOG_LOGIC("RIPng: adding sending socket to " << address.GetAddress());
340 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
341 Ptr<Node> theNode = GetObject<Node>();
342 Ptr<Socket> socket = Socket::CreateSocket(theNode, tid);
343 Inet6SocketAddress local = Inet6SocketAddress(address.GetAddress(), RIPNG_PORT);
344 socket->BindToNetDevice(m_ipv6->GetNetDevice(i));
345 socket->Bind(local);
346 socket->SetRecvCallback(MakeCallback(&RipNg::Receive, this));
347 socket->SetIpv6RecvHopLimit(true);
348 socket->SetRecvPktInfo(true);
349 m_unicastSocketList[socket] = i;
350 }
351 else if (address.GetScope() == Ipv6InterfaceAddress::GLOBAL)
352 {
354 }
355 }
356
358 {
359 NS_LOG_LOGIC("RIPng: adding receiving socket");
360 TypeId tid = TypeId::LookupByName("ns3::UdpSocketFactory");
361 Ptr<Node> theNode = GetObject<Node>();
368 }
369}
370
371void
373{
374 NS_LOG_FUNCTION(this << interface);
375
376 /* remove all routes that are going through this interface */
377 for (auto it = m_routes.begin(); it != m_routes.end(); it++)
378 {
379 if (it->first->GetInterface() == interface)
380 {
381 InvalidateRoute(it->first);
382 }
383 }
384
385 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end(); iter++)
386 {
387 NS_LOG_INFO("Checking socket for interface " << interface);
388 if (iter->second == interface)
389 {
390 NS_LOG_INFO("Removed socket for interface " << interface);
391 iter->first->Close();
392 m_unicastSocketList.erase(iter);
393 break;
394 }
395 }
396
397 if (m_interfaceExclusions.find(interface) == m_interfaceExclusions.end())
398 {
400 }
401}
402
403void
405{
406 NS_LOG_FUNCTION(this << interface << address);
407
408 if (!m_ipv6->IsUp(interface))
409 {
410 return;
411 }
412
413 if (m_interfaceExclusions.find(interface) != m_interfaceExclusions.end())
414 {
415 return;
416 }
417
418 Ipv6Address networkAddress = address.GetAddress().CombinePrefix(address.GetPrefix());
419 Ipv6Prefix networkMask = address.GetPrefix();
420
421 if (address.GetScope() == Ipv6InterfaceAddress::GLOBAL)
422 {
423 AddNetworkRouteTo(networkAddress, networkMask, interface);
424 }
425
427}
428
429void
431{
432 NS_LOG_FUNCTION(this << interface << address);
433
434 if (!m_ipv6->IsUp(interface))
435 {
436 return;
437 }
438
439 if (address.GetScope() != Ipv6InterfaceAddress::GLOBAL)
440 {
441 return;
442 }
443
444 Ipv6Address networkAddress = address.GetAddress().CombinePrefix(address.GetPrefix());
445 Ipv6Prefix networkMask = address.GetPrefix();
446
447 // Remove all routes that are going through this interface
448 // which reference this network
449 for (auto it = m_routes.begin(); it != m_routes.end(); it++)
450 {
451 if (it->first->GetInterface() == interface && it->first->IsNetwork() &&
452 it->first->GetDestNetwork() == networkAddress &&
453 it->first->GetDestNetworkPrefix() == networkMask)
454 {
455 InvalidateRoute(it->first);
456 }
457 }
458
459 if (m_interfaceExclusions.find(interface) == m_interfaceExclusions.end())
460 {
462 }
463}
464
465void
467 Ipv6Prefix mask,
468 Ipv6Address nextHop,
469 uint32_t interface,
470 Ipv6Address prefixToUse)
471{
472 NS_LOG_INFO(this << dst << mask << nextHop << interface << prefixToUse);
473 // \todo this can be used to add delegate routes
474}
475
476void
478 Ipv6Prefix mask,
479 Ipv6Address nextHop,
480 uint32_t interface,
481 Ipv6Address prefixToUse)
482{
483 NS_LOG_FUNCTION(this << dst << mask << nextHop << interface);
484 // \todo this can be used to delete delegate routes
485}
486
487void
489{
490 NS_LOG_FUNCTION(this << ipv6);
491
492 NS_ASSERT(!m_ipv6 && ipv6);
493 uint32_t i = 0;
494 m_ipv6 = ipv6;
495
496 for (i = 0; i < m_ipv6->GetNInterfaces(); i++)
497 {
498 if (m_ipv6->IsUp(i))
499 {
501 }
502 else
503 {
505 }
506 }
507}
508
509void
511{
512 NS_LOG_FUNCTION(this << stream);
513
514 std::ostream* os = stream->GetStream();
515 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
516
517 *os << "Node: " << m_ipv6->GetObject<Node>()->GetId() << ", Time: " << Now().As(unit)
518 << ", Local time: " << m_ipv6->GetObject<Node>()->GetLocalTime().As(unit)
519 << ", IPv6 RIPng table" << std::endl;
520
521 if (!m_routes.empty())
522 {
523 *os << "Destination Next Hop Flag Met Ref Use If"
524 << std::endl;
525 for (auto it = m_routes.begin(); it != m_routes.end(); it++)
526 {
527 RipNgRoutingTableEntry* route = it->first;
529
531 {
532 std::ostringstream dest;
533 std::ostringstream gw;
534 std::ostringstream mask;
535 std::ostringstream flags;
536
537 dest << route->GetDest() << "/"
538 << int(route->GetDestNetworkPrefix().GetPrefixLength());
539 *os << std::setw(31) << dest.str();
540 gw << route->GetGateway();
541 *os << std::setw(27) << gw.str();
542 flags << "U";
543 if (route->IsHost())
544 {
545 flags << "H";
546 }
547 else if (route->IsGateway())
548 {
549 flags << "G";
550 }
551 *os << std::setw(5) << flags.str();
552 *os << std::setw(4) << int(route->GetRouteMetric());
553 // Ref ct not implemented
554 *os << "-"
555 << " ";
556 // Use not implemented
557 *os << "-"
558 << " ";
559 if (!Names::FindName(m_ipv6->GetNetDevice(route->GetInterface())).empty())
560 {
561 *os << Names::FindName(m_ipv6->GetNetDevice(route->GetInterface()));
562 }
563 else
564 {
565 *os << route->GetInterface();
566 }
567 *os << std::endl;
568 }
569 }
570 }
571 *os << std::endl;
572}
573
574void
576{
577 NS_LOG_FUNCTION(this);
578
579 for (auto j = m_routes.begin(); j != m_routes.end(); j = m_routes.erase(j))
580 {
581 delete j->first;
582 }
583 m_routes.clear();
584
589
590 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end(); iter++)
591 {
592 iter->first->Close();
593 }
594 m_unicastSocketList.clear();
595
597 m_multicastRecvSocket = nullptr;
598
599 m_ipv6 = nullptr;
600
602}
603
605RipNg::Lookup(Ipv6Address dst, bool setSource, Ptr<NetDevice> interface)
606{
607 NS_LOG_FUNCTION(this << dst << interface);
608
609 Ptr<Ipv6Route> rtentry = nullptr;
610 uint16_t longestMask = 0;
611
612 /* when sending on link-local multicast, there have to be interface specified */
613 if (dst.IsLinkLocalMulticast())
614 {
616 interface,
617 "Try to send on link-local multicast address, and no interface index is given!");
618 rtentry = Create<Ipv6Route>();
619 rtentry->SetSource(
620 m_ipv6->SourceAddressSelection(m_ipv6->GetInterfaceForDevice(interface), dst));
621 rtentry->SetDestination(dst);
622 rtentry->SetGateway(Ipv6Address::GetZero());
623 rtentry->SetOutputDevice(interface);
624 return rtentry;
625 }
626
627 for (auto it = m_routes.begin(); it != m_routes.end(); it++)
628 {
629 RipNgRoutingTableEntry* j = it->first;
630
632 {
634 uint16_t maskLen = mask.GetPrefixLength();
635 Ipv6Address entry = j->GetDestNetwork();
636
637 NS_LOG_LOGIC("Searching for route to " << dst << ", mask length " << maskLen);
638
639 if (mask.IsMatch(dst, entry))
640 {
641 NS_LOG_LOGIC("Found global network route " << j << ", mask length " << maskLen);
642
643 /* if interface is given, check the route will output on this interface */
644 if (!interface || interface == m_ipv6->GetNetDevice(j->GetInterface()))
645 {
646 if (maskLen < longestMask)
647 {
648 NS_LOG_LOGIC("Previous match longer, skipping");
649 continue;
650 }
651
652 longestMask = maskLen;
653
654 Ipv6RoutingTableEntry* route = j;
655 uint32_t interfaceIdx = route->GetInterface();
656 rtentry = Create<Ipv6Route>();
657
658 if (setSource)
659 {
660 if (route->GetGateway().IsAny())
661 {
662 rtentry->SetSource(
663 m_ipv6->SourceAddressSelection(interfaceIdx, route->GetDest()));
664 }
665 else if (route->GetDest().IsAny()) /* default route */
666 {
667 rtentry->SetSource(m_ipv6->SourceAddressSelection(
668 interfaceIdx,
669 route->GetPrefixToUse().IsAny() ? dst : route->GetPrefixToUse()));
670 }
671 else
672 {
673 rtentry->SetSource(
674 m_ipv6->SourceAddressSelection(interfaceIdx, route->GetDest()));
675 }
676 }
677
678 rtentry->SetDestination(route->GetDest());
679 rtentry->SetGateway(route->GetGateway());
680 rtentry->SetOutputDevice(m_ipv6->GetNetDevice(interfaceIdx));
681 }
682 }
683 }
684 }
685
686 if (rtentry)
687 {
688 NS_LOG_LOGIC("Matching route via " << rtentry->GetDestination() << " (through "
689 << rtentry->GetGateway() << ") at the end");
690 }
691 return rtentry;
692}
693
694void
696 Ipv6Prefix networkPrefix,
697 Ipv6Address nextHop,
698 uint32_t interface,
699 Ipv6Address prefixToUse)
700{
701 NS_LOG_FUNCTION(this << network << networkPrefix << nextHop << interface << prefixToUse);
702
703 if (nextHop.IsLinkLocal())
704 {
705 NS_LOG_WARN("Ripng::AddNetworkRouteTo - Next hop should be link-local");
706 }
707
708 auto route =
709 new RipNgRoutingTableEntry(network, networkPrefix, nextHop, interface, prefixToUse);
710 route->SetRouteMetric(1);
711 route->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_VALID);
712 route->SetRouteChanged(true);
713
714 m_routes.emplace_back(route, EventId());
715}
716
717void
718RipNg::AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface)
719{
720 NS_LOG_FUNCTION(this << network << networkPrefix << interface);
721
722 auto route = new RipNgRoutingTableEntry(network, networkPrefix, interface);
723 route->SetRouteMetric(1);
724 route->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_VALID);
725 route->SetRouteChanged(true);
726
727 m_routes.emplace_back(route, EventId());
728}
729
730void
732{
733 NS_LOG_FUNCTION(this << *route);
734
735 for (auto it = m_routes.begin(); it != m_routes.end(); it++)
736 {
737 if (it->first == route)
738 {
741 route->SetRouteChanged(true);
742 if (it->second.IsRunning())
743 {
744 it->second.Cancel();
745 }
746 it->second =
748 return;
749 }
750 }
751 NS_ABORT_MSG("Ripng::InvalidateRoute - cannot find the route to update");
752}
753
754void
756{
757 NS_LOG_FUNCTION(this << *route);
758
759 for (auto it = m_routes.begin(); it != m_routes.end(); it++)
760 {
761 if (it->first == route)
762 {
763 delete route;
764 m_routes.erase(it);
765 return;
766 }
767 }
768 NS_ABORT_MSG("Ripng::DeleteRoute - cannot find the route to delete");
769}
770
771void
773{
774 NS_LOG_FUNCTION(this << socket);
775
776 Address sender;
777 Ptr<Packet> packet = socket->RecvFrom(sender);
779 NS_LOG_INFO("Received " << *packet << " from " << senderAddr);
780
781 Ipv6Address senderAddress = senderAddr.GetIpv6();
782 uint16_t senderPort = senderAddr.GetPort();
783
784 Ipv6PacketInfoTag interfaceInfo;
785 if (!packet->RemovePacketTag(interfaceInfo))
786 {
787 NS_ABORT_MSG("No incoming interface on RIPng message, aborting.");
788 }
789 uint32_t incomingIf = interfaceInfo.GetRecvIf();
790 Ptr<Node> node = this->GetObject<Node>();
791 Ptr<NetDevice> dev = node->GetDevice(incomingIf);
792 uint32_t ipInterfaceIndex = m_ipv6->GetInterfaceForDevice(dev);
793
794 SocketIpv6HopLimitTag hoplimitTag;
795 if (!packet->RemovePacketTag(hoplimitTag))
796 {
797 NS_ABORT_MSG("No incoming Hop Count on RIPng message, aborting.");
798 }
799 uint8_t hopLimit = hoplimitTag.GetHopLimit();
800
801 int32_t interfaceForAddress = m_ipv6->GetInterfaceForAddress(senderAddress);
802 if (interfaceForAddress != -1)
803 {
804 NS_LOG_LOGIC("Ignoring a packet sent by myself.");
805 return;
806 }
807
808 RipNgHeader hdr;
809 packet->RemoveHeader(hdr);
810
812 {
813 HandleResponses(hdr, senderAddress, ipInterfaceIndex, hopLimit);
814 }
815 else if (hdr.GetCommand() == RipNgHeader::REQUEST)
816 {
817 HandleRequests(hdr, senderAddress, senderPort, ipInterfaceIndex, hopLimit);
818 }
819 else
820 {
821 NS_LOG_LOGIC("Ignoring message with unknown command: " << int(hdr.GetCommand()));
822 }
823}
824
825void
827 Ipv6Address senderAddress,
828 uint16_t senderPort,
829 uint32_t incomingInterface,
830 uint8_t hopLimit)
831{
832 NS_LOG_FUNCTION(this << senderAddress << int(senderPort) << incomingInterface << int(hopLimit)
833 << requestHdr);
834
835 std::list<RipNgRte> rtes = requestHdr.GetRteList();
836
837 if (rtes.empty())
838 {
839 return;
840 }
841
842 // check if it's a request for the full table from a neighbor
843 if (rtes.size() == 1 && senderAddress.IsLinkLocal())
844 {
845 if (rtes.begin()->GetPrefix() == Ipv6Address::GetAny() &&
846 rtes.begin()->GetPrefixLen() == 0 && rtes.begin()->GetRouteMetric() == m_linkDown)
847 {
848 // Output whole thing. Use Split Horizon
849 if (m_interfaceExclusions.find(incomingInterface) == m_interfaceExclusions.end())
850 {
851 // we use one of the sending sockets, as they're bound to the right interface
852 // and the local address might be used on different interfaces.
853 Ptr<Socket> sendingSocket;
854 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end();
855 iter++)
856 {
857 if (iter->second == incomingInterface)
858 {
859 sendingSocket = iter->first;
860 }
861 }
862 NS_ASSERT_MSG(sendingSocket,
863 "HandleRequest - Impossible to find a socket to send the reply");
864
865 uint16_t mtu = m_ipv6->GetMtu(incomingInterface);
866 uint16_t maxRte =
870
871 Ptr<Packet> p = Create<Packet>();
873 p->RemovePacketTag(tag);
874 tag.SetHopLimit(255);
875 p->AddPacketTag(tag);
876
877 RipNgHeader hdr;
879
880 for (auto rtIter = m_routes.begin(); rtIter != m_routes.end(); rtIter++)
881 {
882 bool splitHorizoning = (rtIter->first->GetInterface() == incomingInterface);
883
884 Ipv6InterfaceAddress rtDestAddr =
885 Ipv6InterfaceAddress(rtIter->first->GetDestNetwork(),
886 rtIter->first->GetDestNetworkPrefix());
887
888 bool isGlobal = (rtDestAddr.GetScope() == Ipv6InterfaceAddress::GLOBAL);
889 bool isDefaultRoute =
890 ((rtIter->first->GetDestNetwork() == Ipv6Address::GetAny()) &&
891 (rtIter->first->GetDestNetworkPrefix() == Ipv6Prefix::GetZero()) &&
892 (rtIter->first->GetInterface() != incomingInterface));
893
894 if ((isGlobal || isDefaultRoute) &&
895 (rtIter->first->GetRouteStatus() == RipNgRoutingTableEntry::RIPNG_VALID))
896 {
897 RipNgRte rte;
898 rte.SetPrefix(rtIter->first->GetDestNetwork());
899 rte.SetPrefixLen(rtIter->first->GetDestNetworkPrefix().GetPrefixLength());
900 if (m_splitHorizonStrategy == POISON_REVERSE && splitHorizoning)
901 {
903 }
904 else
905 {
906 rte.SetRouteMetric(rtIter->first->GetRouteMetric());
907 }
908 rte.SetRouteTag(rtIter->first->GetRouteTag());
910 (m_splitHorizonStrategy == SPLIT_HORIZON && !splitHorizoning))
911 {
912 hdr.AddRte(rte);
913 }
914 }
915 if (hdr.GetRteNumber() == maxRte)
916 {
917 p->AddHeader(hdr);
918 NS_LOG_DEBUG("SendTo: " << *p);
919 sendingSocket->SendTo(p, 0, Inet6SocketAddress(senderAddress, RIPNG_PORT));
920 p->RemoveHeader(hdr);
921 hdr.ClearRtes();
922 }
923 }
924 if (hdr.GetRteNumber() > 0)
925 {
926 p->AddHeader(hdr);
927 NS_LOG_DEBUG("SendTo: " << *p);
928 sendingSocket->SendTo(p, 0, Inet6SocketAddress(senderAddress, RIPNG_PORT));
929 }
930 }
931 }
932 }
933 else
934 {
935 // note: we got the request as a single packet, so no check is necessary for MTU limit
936
937 // we use one of the sending sockets, as they're bound to the right interface
938 // and the local address might be used on different interfaces.
939 Ptr<Socket> sendingSocket;
940 if (senderAddress.IsLinkLocal())
941 {
942 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end(); iter++)
943 {
944 if (iter->second == incomingInterface)
945 {
946 sendingSocket = iter->first;
947 }
948 }
949 }
950 else
951 {
952 sendingSocket = m_multicastRecvSocket;
953 }
954
955 Ptr<Packet> p = Create<Packet>();
957 p->RemovePacketTag(tag);
958 tag.SetHopLimit(255);
959 p->AddPacketTag(tag);
960
961 RipNgHeader hdr;
963
964 for (auto iter = rtes.begin(); iter != rtes.end(); iter++)
965 {
966 bool found = false;
967 for (auto rtIter = m_routes.begin(); rtIter != m_routes.end(); rtIter++)
968 {
969 Ipv6InterfaceAddress rtDestAddr =
970 Ipv6InterfaceAddress(rtIter->first->GetDestNetwork(),
971 rtIter->first->GetDestNetworkPrefix());
972 if ((rtDestAddr.GetScope() == Ipv6InterfaceAddress::GLOBAL) &&
973 (rtIter->first->GetRouteStatus() == RipNgRoutingTableEntry::RIPNG_VALID))
974 {
975 Ipv6Address requestedAddress = iter->GetPrefix();
976 requestedAddress.CombinePrefix(Ipv6Prefix(iter->GetPrefixLen()));
977 Ipv6Address rtAddress = rtIter->first->GetDestNetwork();
978 rtAddress.CombinePrefix(rtIter->first->GetDestNetworkPrefix());
979
980 if (requestedAddress == rtAddress)
981 {
982 iter->SetRouteMetric(rtIter->first->GetRouteMetric());
983 iter->SetRouteTag(rtIter->first->GetRouteTag());
984 hdr.AddRte(*iter);
985 found = true;
986 break;
987 }
988 }
989 }
990 if (!found)
991 {
992 iter->SetRouteMetric(m_linkDown);
993 iter->SetRouteTag(0);
994 hdr.AddRte(*iter);
995 }
996 }
997 p->AddHeader(hdr);
998 NS_LOG_DEBUG("SendTo: " << *p);
999 sendingSocket->SendTo(p, 0, Inet6SocketAddress(senderAddress, senderPort));
1000 }
1001}
1002
1003void
1005 Ipv6Address senderAddress,
1006 uint32_t incomingInterface,
1007 uint8_t hopLimit)
1008{
1009 NS_LOG_FUNCTION(this << senderAddress << incomingInterface << int(hopLimit) << hdr);
1010
1011 if (m_interfaceExclusions.find(incomingInterface) != m_interfaceExclusions.end())
1012 {
1014 "Ignoring an update message from an excluded interface: " << incomingInterface);
1015 return;
1016 }
1017
1018 if (!senderAddress.IsLinkLocal())
1019 {
1020 NS_LOG_LOGIC("Ignoring an update message from a non-link-local source: " << senderAddress);
1021 return;
1022 }
1023
1024 if (hopLimit != 255)
1025 {
1026 NS_LOG_LOGIC("Ignoring an update message with suspicious hop count: " << int(hopLimit));
1027 return;
1028 }
1029
1030 std::list<RipNgRte> rtes = hdr.GetRteList();
1031
1032 // validate the RTEs before processing
1033 for (auto iter = rtes.begin(); iter != rtes.end(); iter++)
1034 {
1035 if (iter->GetRouteMetric() == 0 || iter->GetRouteMetric() > m_linkDown)
1036 {
1037 NS_LOG_LOGIC("Ignoring an update message with malformed metric: "
1038 << int(iter->GetRouteMetric()));
1039 return;
1040 }
1041 if (iter->GetPrefixLen() > 128)
1042 {
1043 NS_LOG_LOGIC("Ignoring an update message with malformed prefix length: "
1044 << int(iter->GetPrefixLen()));
1045 return;
1046 }
1047 if (iter->GetPrefix().IsLocalhost() || iter->GetPrefix().IsLinkLocal() ||
1048 iter->GetPrefix().IsMulticast())
1049 {
1050 NS_LOG_LOGIC("Ignoring an update message with wrong prefixes: " << iter->GetPrefix());
1051 return;
1052 }
1053 }
1054
1055 bool changed = false;
1056
1057 for (auto iter = rtes.begin(); iter != rtes.end(); iter++)
1058 {
1059 Ipv6Prefix rtePrefix = Ipv6Prefix(iter->GetPrefixLen());
1060 Ipv6Address rteAddr = iter->GetPrefix().CombinePrefix(rtePrefix);
1061
1062 NS_LOG_LOGIC("Processing RTE " << *iter);
1063
1064 uint8_t interfaceMetric = 1;
1065 if (m_interfaceMetrics.find(incomingInterface) != m_interfaceMetrics.end())
1066 {
1067 interfaceMetric = m_interfaceMetrics[incomingInterface];
1068 }
1069 uint16_t rteMetric = iter->GetRouteMetric() + interfaceMetric;
1070 if (rteMetric > m_linkDown)
1071 {
1072 rteMetric = m_linkDown;
1073 }
1074 RoutesI it;
1075 bool found = false;
1076 for (it = m_routes.begin(); it != m_routes.end(); it++)
1077 {
1078 if (it->first->GetDestNetwork() == rteAddr &&
1079 it->first->GetDestNetworkPrefix() == rtePrefix)
1080 {
1081 found = true;
1082 if (rteMetric < it->first->GetRouteMetric())
1083 {
1084 if (senderAddress != it->first->GetGateway())
1085 {
1086 auto route = new RipNgRoutingTableEntry(rteAddr,
1087 rtePrefix,
1088 senderAddress,
1089 incomingInterface,
1091 delete it->first;
1092 it->first = route;
1093 }
1094 it->first->SetRouteMetric(rteMetric);
1095 it->first->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_VALID);
1096 it->first->SetRouteTag(iter->GetRouteTag());
1097 it->first->SetRouteChanged(true);
1098 it->second.Cancel();
1101 this,
1102 it->first);
1103 changed = true;
1104 }
1105 else if (rteMetric == it->first->GetRouteMetric())
1106 {
1107 if (senderAddress == it->first->GetGateway())
1108 {
1109 it->second.Cancel();
1112 this,
1113 it->first);
1114 }
1115 else
1116 {
1117 if (Simulator::GetDelayLeft(it->second) < m_timeoutDelay / 2)
1118 {
1119 auto route = new RipNgRoutingTableEntry(rteAddr,
1120 rtePrefix,
1121 senderAddress,
1122 incomingInterface,
1124 route->SetRouteMetric(rteMetric);
1125 route->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_VALID);
1126 route->SetRouteTag(iter->GetRouteTag());
1127 route->SetRouteChanged(true);
1128 delete it->first;
1129 it->first = route;
1130 it->second.Cancel();
1133 this,
1134 route);
1135 changed = true;
1136 }
1137 }
1138 }
1139 else if (rteMetric > it->first->GetRouteMetric() &&
1140 senderAddress == it->first->GetGateway())
1141 {
1142 it->second.Cancel();
1143 if (rteMetric < m_linkDown)
1144 {
1145 it->first->SetRouteMetric(rteMetric);
1146 it->first->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_VALID);
1147 it->first->SetRouteTag(iter->GetRouteTag());
1148 it->first->SetRouteChanged(true);
1149 it->second.Cancel();
1152 this,
1153 it->first);
1154 }
1155 else
1156 {
1157 InvalidateRoute(it->first);
1158 }
1159 changed = true;
1160 }
1161 }
1162 }
1163 if (!found && rteMetric != m_linkDown)
1164 {
1165 NS_LOG_LOGIC("Received a RTE with new route, adding.");
1166
1167 auto route = new RipNgRoutingTableEntry(rteAddr,
1168 rtePrefix,
1169 senderAddress,
1170 incomingInterface,
1172 route->SetRouteMetric(rteMetric);
1173 route->SetRouteStatus(RipNgRoutingTableEntry::RIPNG_VALID);
1174 route->SetRouteChanged(true);
1175 m_routes.emplace_front(route, EventId());
1176 EventId invalidateEvent =
1178 (m_routes.begin())->second = invalidateEvent;
1179 changed = true;
1180 }
1181 }
1182
1183 if (changed)
1184 {
1186 }
1187}
1188
1189void
1191{
1192 NS_LOG_FUNCTION(this << (periodic ? " periodic" : " triggered"));
1193
1194 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end(); iter++)
1195 {
1196 uint32_t interface = iter->second;
1197
1198 if (m_interfaceExclusions.find(interface) == m_interfaceExclusions.end())
1199 {
1200 uint16_t mtu = m_ipv6->GetMtu(interface);
1201 uint16_t maxRte =
1205
1206 Ptr<Packet> p = Create<Packet>();
1208 tag.SetHopLimit(255);
1209 p->AddPacketTag(tag);
1210
1211 RipNgHeader hdr;
1213
1214 for (auto rtIter = m_routes.begin(); rtIter != m_routes.end(); rtIter++)
1215 {
1216 bool splitHorizoning = (rtIter->first->GetInterface() == interface);
1217 Ipv6InterfaceAddress rtDestAddr =
1218 Ipv6InterfaceAddress(rtIter->first->GetDestNetwork(),
1219 rtIter->first->GetDestNetworkPrefix());
1220
1221 NS_LOG_DEBUG("Processing RT " << rtDestAddr << " "
1222 << int(rtIter->first->IsRouteChanged()));
1223
1224 bool isGlobal = (rtDestAddr.GetScope() == Ipv6InterfaceAddress::GLOBAL);
1225 bool isDefaultRoute =
1226 ((rtIter->first->GetDestNetwork() == Ipv6Address::GetAny()) &&
1227 (rtIter->first->GetDestNetworkPrefix() == Ipv6Prefix::GetZero()) &&
1228 (rtIter->first->GetInterface() != interface));
1229
1230 if ((isGlobal || isDefaultRoute) && (periodic || rtIter->first->IsRouteChanged()))
1231 {
1232 RipNgRte rte;
1233 rte.SetPrefix(rtIter->first->GetDestNetwork());
1234 rte.SetPrefixLen(rtIter->first->GetDestNetworkPrefix().GetPrefixLength());
1235 if (m_splitHorizonStrategy == POISON_REVERSE && splitHorizoning)
1236 {
1238 }
1239 else
1240 {
1241 rte.SetRouteMetric(rtIter->first->GetRouteMetric());
1242 }
1243 rte.SetRouteTag(rtIter->first->GetRouteTag());
1244 if (m_splitHorizonStrategy == SPLIT_HORIZON && !splitHorizoning)
1245 {
1246 hdr.AddRte(rte);
1247 }
1249 {
1250 hdr.AddRte(rte);
1251 }
1252 }
1253 if (hdr.GetRteNumber() == maxRte)
1254 {
1255 p->AddHeader(hdr);
1256 NS_LOG_DEBUG("SendTo: " << *p);
1257 iter->first->SendTo(p, 0, Inet6SocketAddress(RIPNG_ALL_NODE, RIPNG_PORT));
1258 p->RemoveHeader(hdr);
1259 hdr.ClearRtes();
1260 }
1261 }
1262 if (hdr.GetRteNumber() > 0)
1263 {
1264 p->AddHeader(hdr);
1265 NS_LOG_DEBUG("SendTo: " << *p);
1266 iter->first->SendTo(p, 0, Inet6SocketAddress(RIPNG_ALL_NODE, RIPNG_PORT));
1267 }
1268 }
1269 }
1270 for (auto rtIter = m_routes.begin(); rtIter != m_routes.end(); rtIter++)
1271 {
1272 rtIter->first->SetRouteChanged(false);
1273 }
1274}
1275
1276void
1278{
1279 NS_LOG_FUNCTION(this);
1280
1282 {
1283 NS_LOG_LOGIC("Skipping Triggered Update due to cooldown");
1284 return;
1285 }
1286
1287 // DoSendRouteUpdate (false);
1288
1289 // note: The RFC states:
1290 // After a triggered
1291 // update is sent, a timer should be set for a random interval between 1
1292 // and 5 seconds. If other changes that would trigger updates occur
1293 // before the timer expires, a single update is triggered when the timer
1294 // expires. The timer is then reset to another random value between 1
1295 // and 5 seconds. Triggered updates may be suppressed if a regular
1296 // update is due by the time the triggered update would be sent.
1297 // Here we rely on this:
1298 // When an update occurs (either Triggered or Periodic) the "IsChanged ()"
1299 // route field will be cleared.
1300 // Hence, the following Triggered Update will be fired, but will not send
1301 // any route update.
1302
1306}
1307
1308void
1310{
1311 NS_LOG_FUNCTION(this);
1312
1314 {
1316 }
1317
1318 DoSendRouteUpdate(true);
1319
1320 Time delay =
1323}
1324
1325std::set<uint32_t>
1327{
1328 return m_interfaceExclusions;
1329}
1330
1331void
1332RipNg::SetInterfaceExclusions(std::set<uint32_t> exceptions)
1333{
1334 NS_LOG_FUNCTION(this);
1335
1336 m_interfaceExclusions = exceptions;
1337}
1338
1339uint8_t
1341{
1342 NS_LOG_FUNCTION(this << interface);
1343
1344 auto iter = m_interfaceMetrics.find(interface);
1345 if (iter != m_interfaceMetrics.end())
1346 {
1347 return iter->second;
1348 }
1349 return 1;
1350}
1351
1352void
1353RipNg::SetInterfaceMetric(uint32_t interface, uint8_t metric)
1354{
1355 NS_LOG_FUNCTION(this << interface << int(metric));
1356
1357 if (metric < m_linkDown)
1358 {
1359 m_interfaceMetrics[interface] = metric;
1360 }
1361}
1362
1363void
1365{
1366 NS_LOG_FUNCTION(this);
1367
1368 Ptr<Packet> p = Create<Packet>();
1370 p->RemovePacketTag(tag);
1371 tag.SetHopLimit(255);
1372 p->AddPacketTag(tag);
1373
1374 RipNgHeader hdr;
1376
1377 RipNgRte rte;
1379 rte.SetPrefixLen(0);
1381
1382 hdr.AddRte(rte);
1383 p->AddHeader(hdr);
1384
1385 for (auto iter = m_unicastSocketList.begin(); iter != m_unicastSocketList.end(); iter++)
1386 {
1387 uint32_t interface = iter->second;
1388
1389 if (m_interfaceExclusions.find(interface) == m_interfaceExclusions.end())
1390 {
1391 NS_LOG_DEBUG("SendTo: " << *p);
1392 iter->first->SendTo(p, 0, Inet6SocketAddress(RIPNG_ALL_NODE, RIPNG_PORT));
1393 }
1394 }
1395}
1396
1397void
1399{
1400 NS_LOG_FUNCTION(this << interface);
1401
1404 nextHop,
1405 interface,
1406 Ipv6Address("::"));
1407}
1408
1409/*
1410 * RipNgRoutingTableEntry
1411 */
1412
1414 : m_tag(0),
1415 m_metric(0),
1416 m_status(RIPNG_INVALID),
1417 m_changed(false)
1418{
1419}
1420
1422 Ipv6Prefix networkPrefix,
1423 Ipv6Address nextHop,
1424 uint32_t interface,
1425 Ipv6Address prefixToUse)
1426 : Ipv6RoutingTableEntry(RipNgRoutingTableEntry::CreateNetworkRouteTo(network,
1427 networkPrefix,
1428 nextHop,
1429 interface,
1430 prefixToUse)),
1431 m_tag(0),
1432 m_metric(0),
1433 m_status(RIPNG_INVALID),
1434 m_changed(false)
1435{
1436}
1437
1439 Ipv6Prefix networkPrefix,
1440 uint32_t interface)
1442 Ipv6RoutingTableEntry::CreateNetworkRouteTo(network, networkPrefix, interface)),
1443 m_tag(0),
1444 m_metric(0),
1445 m_status(RIPNG_INVALID),
1446 m_changed(false)
1447{
1448}
1449
1451{
1452}
1453
1454void
1456{
1457 if (m_tag != routeTag)
1458 {
1459 m_tag = routeTag;
1460 m_changed = true;
1461 }
1462}
1463
1464uint16_t
1466{
1467 return m_tag;
1468}
1469
1470void
1472{
1473 if (m_metric != routeMetric)
1474 {
1475 m_metric = routeMetric;
1476 m_changed = true;
1477 }
1478}
1479
1480uint8_t
1482{
1483 return m_metric;
1484}
1485
1486void
1488{
1489 if (m_status != status)
1490 {
1491 m_status = status;
1492 m_changed = true;
1493 }
1494}
1495
1498{
1499 return m_status;
1500}
1501
1502void
1504{
1505 m_changed = changed;
1506}
1507
1508bool
1510{
1511 return m_changed;
1512}
1513
1514std::ostream&
1515operator<<(std::ostream& os, const RipNgRoutingTableEntry& rte)
1516{
1517 os << static_cast<const Ipv6RoutingTableEntry&>(rte);
1518 os << ", metric: " << int(rte.GetRouteMetric()) << ", tag: " << int(rte.GetRouteTag());
1519
1520 return os;
1521}
1522
1523} // namespace ns3
a polymophic address class
Definition: address.h:101
bool IsNull() const
Check for null implementation.
Definition: callback.h:569
Hold variables of type enum.
Definition: enum.h:56
An identifier for simulation events.
Definition: event-id.h:55
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:76
An Inet6 address class.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
uint16_t GetPort() const
Get the port.
Ipv6Address GetIpv6() const
Get the IPv6 address.
Describes an IPv6 address.
Definition: ipv6-address.h:49
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
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:35
Ipv6Address GetDestination() const
Get the "Destination address" field.
Definition: ipv6-header.cc:124
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition: ipv6-header.cc:159
Ipv6Address GetSource() const
Get the "Source address" field.
Definition: ipv6-header.cc:112
IPv6 address associated with an interface.
Ipv6InterfaceAddress::Scope_e GetScope() const
Get address scope.
@ LINKLOCAL
Link-local address (fe80::/64)
@ GLOBAL
Global address (2000::/3)
This class implements a tag that carries socket ancillary data to the socket interface.
uint32_t GetRecvIf() const
Get the tag's receiving interface.
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
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.
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.
Ipv6Address GetGateway() const
Get the gateway.
bool IsGateway() const
Is it the gateway ?
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 DoInitialize()
Initialize() implementation.
Definition: object.cc:359
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
RipNgHeader - see RFC 2080
Definition: ripng-header.h:147
void SetCommand(Command_e command)
Set the command.
void ClearRtes()
Clear all the RTEs from the header.
uint16_t GetRteNumber() const
Get the number of RTE included in the message.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Command_e GetCommand() const
Get the command.
std::list< RipNgRte > GetRteList() const
Get the list of the RTEs included in the message.
void AddRte(RipNgRte rte)
Add a RTE to the message.
RIPng Routing Protocol, defined in RFC 2080.
Definition: ripng.h:178
Ptr< Socket > m_multicastRecvSocket
multicast receive socket
Definition: ripng.h:428
void NotifyInterfaceUp(uint32_t interface) override
Notify when specified interface goes UP.
Definition: ripng.cc:294
void NotifyAddAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
Definition: ripng.cc:404
void NotifyAddRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify a new route.
Definition: ripng.cc:466
void DoSendRouteUpdate(bool periodic)
Send Routing Updates on all interfaces.
Definition: ripng.cc:1190
Time m_startupDelay
Random delay before protocol startup.
Definition: ripng.h:410
void DoDispose() override
Dispose this object.
Definition: ripng.cc:575
SplitHorizonType_e m_splitHorizonStrategy
Split Horizon strategy.
Definition: ripng.h:438
@ SPLIT_HORIZON
Split Horizon.
Definition: ripng.h:226
@ POISON_REVERSE
Poison Reverse Split Horizon.
Definition: ripng.h:227
@ NO_SPLIT_HORIZON
No Split Horizon.
Definition: ripng.h:225
EventId m_nextTriggeredUpdate
Next Triggered Update event.
Definition: ripng.h:431
std::list< std::pair< RipNgRoutingTableEntry *, EventId > >::iterator RoutesI
Iterator for container for the network routes.
Definition: ripng.h:296
~RipNg() override
Definition: ripng.cc:57
void NotifyRemoveAddress(uint32_t interface, Ipv6InterfaceAddress address) override
Notify when specified interface add an address.
Definition: ripng.cc:430
Time m_minTriggeredUpdateDelay
Min cooldown delay after a Triggered Update.
Definition: ripng.h:411
void SetInterfaceExclusions(std::set< uint32_t > exceptions)
Set the set of interface excluded from the protocol.
Definition: ripng.cc:1332
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.
Definition: ripng.cc:200
EventId m_nextUnsolicitedUpdate
Next Unsolicited Update event.
Definition: ripng.h:430
uint8_t m_linkDown
Link down value.
Definition: ripng.h:441
Time m_maxTriggeredUpdateDelay
Max cooldown delay after a Triggered Update.
Definition: ripng.h:412
void DoInitialize() override
Start protocol operation.
Definition: ripng.cc:127
bool m_initialized
flag to allow socket's late-creation.
Definition: ripng.h:440
SocketList m_unicastSocketList
list of sockets for unicast messages (socket, interface index)
Definition: ripng.h:427
uint8_t GetInterfaceMetric(uint32_t interface) const
Get the metric for an interface.
Definition: ripng.cc:1340
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)
Definition: ripng.cc:234
Time m_unsolicitedUpdate
time between two Unsolicited Routing Updates
Definition: ripng.h:413
std::set< uint32_t > m_interfaceExclusions
Set of excluded interfaces.
Definition: ripng.h:435
void SetInterfaceMetric(uint32_t interface, uint8_t metric)
Set the metric for an interface.
Definition: ripng.cc:1353
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: ripng.cc:118
void DeleteRoute(RipNgRoutingTableEntry *route)
Delete a route.
Definition: ripng.cc:755
void AddNetworkRouteTo(Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse)
Add route to network.
Definition: ripng.cc:695
Time m_garbageCollectionDelay
Delay before deleting an INVALID route.
Definition: ripng.h:415
std::map< uint32_t, uint8_t > m_interfaceMetrics
Map of interface metrics.
Definition: ripng.h:436
RipNg()
Definition: ripng.cc:49
void SendRouteRequest()
Send Routing Request on all interfaces.
Definition: ripng.cc:1364
void NotifyInterfaceDown(uint32_t interface) override
Notify when specified interface goes DOWN.
Definition: ripng.cc:372
Ptr< Ipv6 > m_ipv6
IPv6 reference.
Definition: ripng.h:409
Routes m_routes
the forwarding table for network.
Definition: ripng.h:408
std::set< uint32_t > GetInterfaceExclusions() const
Get the set of interface excluded from the protocol.
Definition: ripng.cc:1326
void SendTriggeredRouteUpdate()
Send Triggered Routing Updates on all interfaces.
Definition: ripng.cc:1277
void HandleRequests(RipNgHeader hdr, Ipv6Address senderAddress, uint16_t senderPort, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng requests.
Definition: ripng.cc:826
Ptr< UniformRandomVariable > m_rng
Rng stream.
Definition: ripng.h:433
void HandleResponses(RipNgHeader hdr, Ipv6Address senderAddress, uint32_t incomingInterface, uint8_t hopLimit)
Handle RIPng responses.
Definition: ripng.cc:1004
void NotifyRemoveRoute(Ipv6Address dst, Ipv6Prefix mask, Ipv6Address nextHop, uint32_t interface, Ipv6Address prefixToUse=Ipv6Address::GetZero()) override
Notify route removing.
Definition: ripng.cc:477
static TypeId GetTypeId()
Get the type ID.
Definition: ripng.cc:62
void InvalidateRoute(RipNgRoutingTableEntry *route)
Invalidate a route.
Definition: ripng.cc:731
void SetIpv6(Ptr< Ipv6 > ipv6) override
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
Definition: ripng.cc:488
void Receive(Ptr< Socket > socket)
Receive RIPng packets.
Definition: ripng.cc:772
void AddDefaultRouteTo(Ipv6Address nextHop, uint32_t interface)
Add a default route to the router through the nextHop located on interface.
Definition: ripng.cc:1398
Time m_timeoutDelay
Delay before invalidating a route.
Definition: ripng.h:414
void SendUnsolicitedRouteUpdate()
Send Unsolicited Routing Updates on all interfaces.
Definition: ripng.cc:1309
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
Definition: ripng.cc:510
Ptr< Ipv6Route > Lookup(Ipv6Address dest, bool setSource, Ptr< NetDevice >=nullptr)
Lookup in the forwarding table for destination.
Definition: ripng.cc:605
RipNg Routing Table Entry.
Definition: ripng.h:65
bool IsRouteChanged() const
Get the route changed status.
Definition: ripng.cc:1509
RipNgRoutingTableEntry()
Definition: ripng.cc:1413
uint16_t GetRouteTag() const
Get the route tag.
Definition: ripng.cc:1465
bool m_changed
route has been updated
Definition: ripng.h:160
uint16_t m_tag
route tag
Definition: ripng.h:157
void SetRouteTag(uint16_t routeTag)
Set the route tag.
Definition: ripng.cc:1455
uint8_t GetRouteMetric() const
Get the route metric.
Definition: ripng.cc:1481
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
Definition: ripng.cc:1471
uint8_t m_metric
route metric
Definition: ripng.h:158
Status_e m_status
route status
Definition: ripng.h:159
Status_e GetRouteStatus() const
Get the route status.
Definition: ripng.cc:1497
void SetRouteChanged(bool changed)
Set the route as changed.
Definition: ripng.cc:1503
~RipNgRoutingTableEntry() override
Definition: ripng.cc:1450
Status_e
Route status.
Definition: ripng.h:71
@ RIPNG_INVALID
Definition: ripng.h:73
@ RIPNG_VALID
Definition: ripng.h:72
void SetRouteStatus(Status_e status)
Set the route status.
Definition: ripng.cc:1487
RipNg Routing Table Entry (RTE) - see RFC 2080
Definition: ripng-header.h:40
void SetPrefix(Ipv6Address prefix)
Set the prefix.
Definition: ripng-header.cc:97
void SetPrefixLen(uint8_t prefixLen)
Set the prefix length.
void SetRouteMetric(uint8_t routeMetric)
Set the route metric.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition: ripng-header.cc:64
void SetRouteTag(uint16_t routeTag)
Set the route tag.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:558
static Time GetDelayLeft(const EventId &id)
Get the remaining time until this event will execute.
Definition: simulator.cc:208
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:352
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:126
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:72
virtual int Close()=0
Close a socket.
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
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
void SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
Tells a socket to pass information about IPv6 Hop Limit up the stack.
Definition: socket.cc:546
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition: socket.h:1170
uint8_t GetHopLimit() const
Get the tag's Hop Limit.
Definition: socket.cc:672
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:666
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
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
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
AttributeValue implementation for Time.
Definition: nstime.h:1412
a unique identifier for an interface.
Definition: type-id.h:59
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:834
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:930
Packet header for UDP packets.
Definition: udp-header.h:41
uint32_t GetSerializedSize() const override
Definition: udp-header.cc:159
Hold an unsigned integer type.
Definition: uinteger.h:45
double GetValue(double min, double max)
Get the next random value drawn from the distribution.
#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
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:205
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1433
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1413
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1325
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:163
Definition: second.py:1
#define RIPNG_ALL_NODE
Definition: ripng.cc:39
#define RIPNG_PORT
Definition: ripng.cc:40