A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-l3-protocol.cc
Go to the documentation of this file.
1//
2// Copyright (c) 2006 Georgia Tech Research Corporation
3//
4// SPDX-License-Identifier: GPL-2.0-only
5//
6// Author: George F. Riley<riley@ece.gatech.edu>
7//
8
9#include "ipv4-l3-protocol.h"
10
11#include "arp-cache.h"
12#include "arp-l3-protocol.h"
13#include "icmpv4-l4-protocol.h"
14#include "ipv4-header.h"
15#include "ipv4-interface.h"
17#include "ipv4-route.h"
18#include "loopback-net-device.h"
19
20#include "ns3/boolean.h"
21#include "ns3/callback.h"
22#include "ns3/ipv4-address.h"
23#include "ns3/log.h"
24#include "ns3/net-device.h"
25#include "ns3/node.h"
26#include "ns3/object-vector.h"
27#include "ns3/packet.h"
28#include "ns3/socket.h"
29#include "ns3/string.h"
30#include "ns3/trace-source-accessor.h"
31#include "ns3/traffic-control-layer.h"
32#include "ns3/uinteger.h"
33
34namespace ns3
35{
36
37NS_LOG_COMPONENT_DEFINE("Ipv4L3Protocol");
38
39NS_OBJECT_ENSURE_REGISTERED(Ipv4L3Protocol);
40
41TypeId
43{
44 static TypeId tid =
45 TypeId("ns3::Ipv4L3Protocol")
46 .SetParent<Ipv4>()
47 .SetGroupName("Internet")
48 .AddConstructor<Ipv4L3Protocol>()
49 .AddAttribute("DefaultTtl",
50 "The TTL value set by default on "
51 "all outgoing packets generated on this node.",
52 UintegerValue(64),
55 .AddAttribute("FragmentExpirationTimeout",
56 "When this timeout expires, the fragments "
57 "will be cleared from the buffer.",
58 TimeValue(Seconds(30)),
61 .AddAttribute("EnableDuplicatePacketDetection",
62 "Enable multicast duplicate packet detection based on RFC 6621",
63 BooleanValue(false),
66 .AddAttribute("DuplicateExpire",
67 "Expiration delay for duplicate cache entries",
71 .AddAttribute("PurgeExpiredPeriod",
72 "Time between purges of expired duplicate packet entries, "
73 "0 means never purge",
77 .AddTraceSource("Tx",
78 "Send ipv4 packet to outgoing interface.",
80 "ns3::Ipv4L3Protocol::TxRxTracedCallback")
81 .AddTraceSource("Rx",
82 "Receive ipv4 packet from incoming interface.",
84 "ns3::Ipv4L3Protocol::TxRxTracedCallback")
85 .AddTraceSource("Drop",
86 "Drop ipv4 packet",
88 "ns3::Ipv4L3Protocol::DropTracedCallback")
89 .AddAttribute("InterfaceList",
90 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
94
95 .AddTraceSource("SendOutgoing",
96 "A newly-generated packet by this node is "
97 "about to be queued for transmission",
99 "ns3::Ipv4L3Protocol::SentTracedCallback")
100 .AddTraceSource("UnicastForward",
101 "A unicast IPv4 packet was received by this node "
102 "and is being forwarded to another node",
104 "ns3::Ipv4L3Protocol::SentTracedCallback")
105 .AddTraceSource("MulticastForward",
106 "A multicast IPv4 packet was received by this node "
107 "and is being forwarded to another node",
109 "ns3::Ipv4L3Protocol::SentTracedCallback")
110 .AddTraceSource("LocalDeliver",
111 "An IPv4 packet was received by/for this node, "
112 "and it is being forward up the stack",
114 "ns3::Ipv4L3Protocol::SentTracedCallback")
115
116 ;
117 return tid;
118}
119
128
133
134void
136{
137 NS_LOG_FUNCTION(this << protocol);
138 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
139 if (m_protocols.find(key) != m_protocols.end())
140 {
141 NS_LOG_WARN("Overwriting default protocol " << int(protocol->GetProtocolNumber()));
142 }
143 m_protocols[key] = protocol;
144}
145
146void
148{
149 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
150
151 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
152 if (m_protocols.find(key) != m_protocols.end())
153 {
154 NS_LOG_WARN("Overwriting protocol " << int(protocol->GetProtocolNumber())
155 << " on interface " << int(interfaceIndex));
156 }
157 m_protocols[key] = protocol;
158}
159
160void
162{
163 NS_LOG_FUNCTION(this << protocol);
164
165 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
166 auto iter = m_protocols.find(key);
167 if (iter == m_protocols.end())
168 {
169 NS_LOG_WARN("Trying to remove an non-existent default protocol "
170 << int(protocol->GetProtocolNumber()));
171 }
172 else
173 {
174 m_protocols.erase(key);
175 }
176}
177
178void
180{
181 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
182
183 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
184 auto iter = m_protocols.find(key);
185 if (iter == m_protocols.end())
186 {
187 NS_LOG_WARN("Trying to remove an non-existent protocol "
188 << int(protocol->GetProtocolNumber()) << " on interface "
189 << int(interfaceIndex));
190 }
191 else
192 {
193 m_protocols.erase(key);
194 }
195}
196
198Ipv4L3Protocol::GetProtocol(int protocolNumber) const
199{
200 return GetProtocol(protocolNumber, -1);
201}
202
204Ipv4L3Protocol::GetProtocol(int protocolNumber, int32_t interfaceIndex) const
205{
206 if (interfaceIndex >= 0)
207 {
208 // try the interface-specific protocol.
209 auto key = std::make_pair(protocolNumber, interfaceIndex);
210 auto i = m_protocols.find(key);
211 if (i != m_protocols.end())
212 {
213 return i->second;
214 }
215 }
216 // try the generic protocol.
217 auto key = std::make_pair(protocolNumber, -1);
218 auto i = m_protocols.find(key);
219 if (i != m_protocols.end())
220 {
221 return i->second;
222 }
223
224 return nullptr;
225}
226
227void
229{
230 NS_LOG_FUNCTION(this << node);
231 m_node = node;
232 // Add a LoopbackNetDevice if needed, and an Ipv4Interface on top of it
234}
235
238{
239 NS_LOG_FUNCTION(this);
241 socket->SetNode(m_node);
242 m_sockets.push_back(socket);
243 return socket;
244}
245
246void
248{
249 NS_LOG_FUNCTION(this << socket);
250 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
251 {
252 if ((*i) == socket)
253 {
254 m_sockets.erase(i);
255 return;
256 }
257 }
258}
259
260/*
261 * This method is called by AggregateObject and completes the aggregation
262 * by setting the node in the ipv4 stack
263 */
264void
266{
267 NS_LOG_FUNCTION(this);
268 if (!m_node)
269 {
270 Ptr<Node> node = this->GetObject<Node>();
271 // verify that it's a valid node and that
272 // the node has not been set before
273 if (node)
274 {
275 this->SetNode(node);
276 }
277 }
279}
280
281void
283{
284 NS_LOG_FUNCTION(this << routingProtocol);
285 m_routingProtocol = routingProtocol;
286 m_routingProtocol->SetIpv4(this);
287}
288
294
295void
297{
298 NS_LOG_FUNCTION(this);
299 for (auto i = m_protocols.begin(); i != m_protocols.end(); ++i)
300 {
301 i->second = nullptr;
302 }
303 m_protocols.clear();
304
305 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); ++i)
306 {
307 *i = nullptr;
308 }
309 m_interfaces.clear();
311
312 m_sockets.clear();
313 m_node = nullptr;
314 m_routingProtocol = nullptr;
315
316 for (auto it = m_fragments.begin(); it != m_fragments.end(); it++)
317 {
318 it->second = nullptr;
319 }
320
321 m_fragments.clear();
322 m_timeoutEventList.clear();
324 {
326 }
327
328 if (m_cleanDpd.IsPending())
329 {
331 }
332 m_dups.clear();
333
335}
336
337void
339{
340 NS_LOG_FUNCTION(this);
341
343 Ptr<LoopbackNetDevice> device = nullptr;
344 // First check whether an existing LoopbackNetDevice exists on the node
345 for (uint32_t i = 0; i < m_node->GetNDevices(); i++)
346 {
348 {
349 break;
350 }
351 }
352 if (!device)
353 {
355 m_node->AddDevice(device);
356 }
357 interface->SetDevice(device);
358 interface->SetNode(m_node);
359 Ipv4InterfaceAddress ifaceAddr =
361 interface->AddAddress(ifaceAddr);
362 uint32_t index = AddIpv4Interface(interface);
363 Ptr<Node> node = GetObject<Node>();
364 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3Protocol::Receive, this),
366 device);
367 interface->SetUp();
369 {
370 m_routingProtocol->NotifyInterfaceUp(index);
371 }
372}
373
374void
376{
377 NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
378 m_defaultTtl = ttl;
379}
380
383{
384 NS_LOG_FUNCTION(this << device);
386
388
389 NS_ASSERT(tc);
390
393 device);
396 device);
397
398 tc->RegisterProtocolHandler(MakeCallback(&Ipv4L3Protocol::Receive, this),
400 device);
401 tc->RegisterProtocolHandler(
404 device);
405
407 interface->SetNode(m_node);
408 interface->SetDevice(device);
409 interface->SetTrafficControl(tc);
410 interface->SetForwarding(m_ipForward);
411 return AddIpv4Interface(interface);
412}
413
416{
417 NS_LOG_FUNCTION(this << interface);
418 uint32_t index = m_interfaces.size();
419 m_interfaces.push_back(interface);
420 m_reverseInterfacesContainer[interface->GetDevice()] = index;
421 return index;
422}
423
426{
427 if (index < m_interfaces.size())
428 {
429 return m_interfaces[index];
430 }
431 return nullptr;
432}
433
436{
437 return m_interfaces.size();
438}
439
442{
443 int32_t interface = 0;
444 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
445 {
446 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
447 {
448 if ((*i)->GetAddress(j).GetLocal() == address)
449 {
450 return interface;
451 }
452 }
453 }
454
455 return -1;
456}
457
460{
461 int32_t interface = 0;
462 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
463 {
464 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
465 {
466 if ((*i)->GetAddress(j).GetLocal().CombineMask(mask) == address.CombineMask(mask))
467 {
468 return interface;
469 }
470 }
471 }
472
473 return -1;
474}
475
478{
479 auto iter = m_reverseInterfacesContainer.find(device);
480 if (iter != m_reverseInterfacesContainer.end())
481 {
482 return (*iter).second;
483 }
484
485 return -1;
486}
487
488bool
490{
491 // First check the incoming interface for a unicast address match
492 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
493 {
494 Ipv4InterfaceAddress iaddr = GetAddress(iif, i);
495 if (address == iaddr.GetLocal())
496 {
497 NS_LOG_LOGIC("For me (destination " << address << " match)");
498 return true;
499 }
500 if (address == iaddr.GetBroadcast())
501 {
502 NS_LOG_LOGIC("For me (interface broadcast address)");
503 return true;
504 }
505 }
506
507 if (address.IsMulticast())
508 {
509#ifdef NOTYET
510 if (MulticastCheckGroup(iif, address))
511#endif
512 {
513 NS_LOG_LOGIC("For me (Ipv4Addr multicast address)");
514 return true;
515 }
516 }
517
518 if (address.IsBroadcast())
519 {
520 NS_LOG_LOGIC("For me (Ipv4Addr broadcast address)");
521 return true;
522 }
523
524 if (!GetStrongEndSystemModel()) // Check other interfaces
525 {
526 for (uint32_t j = 0; j < GetNInterfaces(); j++)
527 {
528 if (j == uint32_t(iif))
529 {
530 continue;
531 }
532 for (uint32_t i = 0; i < GetNAddresses(j); i++)
533 {
534 Ipv4InterfaceAddress iaddr = GetAddress(j, i);
535 if (address == iaddr.GetLocal())
536 {
537 NS_LOG_LOGIC("For me (destination " << address
538 << " match) on another interface");
539 return true;
540 }
541 // This is a small corner case: match another interface's broadcast address
542 if (address == iaddr.GetBroadcast())
543 {
544 NS_LOG_LOGIC("For me (interface broadcast address on another interface)");
545 return true;
546 }
547 }
548 }
549 }
550 return false;
551}
552
553void
556 uint16_t protocol,
557 const Address& from,
558 const Address& to,
559 NetDevice::PacketType packetType)
560{
561 NS_LOG_FUNCTION(this << device << p << protocol << from << to << packetType);
562
563 NS_LOG_LOGIC("Packet from " << from << " received on node " << m_node->GetId());
564
565 int32_t interface = GetInterfaceForDevice(device);
566 NS_ASSERT_MSG(interface != -1, "Received a packet from an interface that is not known to IPv4");
567
568 Ptr<Packet> packet = p->Copy();
569
570 Ptr<Ipv4Interface> ipv4Interface = m_interfaces[interface];
571
572 if (ipv4Interface->IsUp())
573 {
574 m_rxTrace(packet, this, interface);
575 }
576 else
577 {
578 NS_LOG_LOGIC("Dropping received packet -- interface is down");
579 Ipv4Header ipHeader;
580 packet->RemoveHeader(ipHeader);
581 m_dropTrace(ipHeader, packet, DROP_INTERFACE_DOWN, this, interface);
582 return;
583 }
584
585 Ipv4Header ipHeader;
586 if (Node::ChecksumEnabled())
587 {
588 ipHeader.EnableChecksum();
589 }
590 packet->RemoveHeader(ipHeader);
591
592 // Trim any residual frame padding from underlying devices
593 if (ipHeader.GetPayloadSize() < packet->GetSize())
594 {
595 packet->RemoveAtEnd(packet->GetSize() - ipHeader.GetPayloadSize());
596 }
597
598 if (!ipHeader.IsChecksumOk())
599 {
600 NS_LOG_LOGIC("Dropping received packet -- checksum not ok");
601 m_dropTrace(ipHeader, packet, DROP_BAD_CHECKSUM, this, interface);
602 return;
603 }
604
605 // the packet is valid, we update the ARP cache entry (if present)
606 Ptr<ArpCache> arpCache = ipv4Interface->GetArpCache();
607 if (arpCache)
608 {
609 // case one, it's a a direct routing.
610 ArpCache::Entry* entry = arpCache->Lookup(ipHeader.GetSource());
611 if (entry)
612 {
613 if (entry->IsAlive())
614 {
615 entry->UpdateSeen();
616 }
617 }
618 else
619 {
620 // It's not in the direct routing, so it's the router, and it could have multiple IP
621 // addresses. In doubt, update all of them. Note: it's a confirmed behavior for Linux
622 // routers.
623 std::list<ArpCache::Entry*> entryList = arpCache->LookupInverse(from);
624 for (auto iter = entryList.begin(); iter != entryList.end(); iter++)
625 {
626 if ((*iter)->IsAlive())
627 {
628 (*iter)->UpdateSeen();
629 }
630 }
631 }
632 }
633
634 if (m_enableDpd && ipHeader.GetDestination().IsMulticast() && UpdateDuplicate(packet, ipHeader))
635 {
636 NS_LOG_LOGIC("Dropping received packet -- duplicate.");
637 m_dropTrace(ipHeader, packet, DROP_DUPLICATE, this, interface);
638 return;
639 }
640
641 NS_ASSERT_MSG(m_routingProtocol, "Need a routing protocol object to process packets");
642 if (!m_routingProtocol->RouteInput(packet, ipHeader, device, m_ucb, m_mcb, m_lcb, m_ecb))
643 {
644 NS_LOG_WARN("No route found for forwarding packet. Drop.");
645 m_dropTrace(ipHeader, packet, DROP_NO_ROUTE, this, interface);
646 }
647}
648
651{
653 if (prot)
654 {
655 return prot->GetObject<Icmpv4L4Protocol>();
656 }
657 else
658 {
659 return nullptr;
660 }
661}
662
663bool
665{
666 if (ad.IsBroadcast() || ad.IsMulticast())
667 {
668 return false;
669 }
670 else
671 {
672 // check for subnet-broadcast
673 for (uint32_t ifaceIndex = 0; ifaceIndex < GetNInterfaces(); ifaceIndex++)
674 {
675 for (uint32_t j = 0; j < GetNAddresses(ifaceIndex); j++)
676 {
677 Ipv4InterfaceAddress ifAddr = GetAddress(ifaceIndex, j);
678 NS_LOG_LOGIC("Testing address " << ad << " with subnet-directed broadcast "
679 << ifAddr.GetBroadcast());
680 if (ad == ifAddr.GetBroadcast())
681 {
682 return false;
683 }
684 }
685 }
686 }
687
688 return true;
689}
690
691bool
693{
694 return !ad.IsMulticast() && !ad.IsSubnetDirectedBroadcast(interfaceMask);
695}
696
697void
699{
700 NS_LOG_FUNCTION(this << packet << ipHeader << route);
702 {
703 ipHeader.EnableChecksum();
704 }
705 SendRealOut(route, packet, ipHeader);
706}
707
708void
710 Ptr<Packet> packet,
711 Ptr<Ipv4> ipv4,
712 uint32_t interface)
713{
714 if (!m_txTrace.IsEmpty())
715 {
716 Ptr<Packet> packetCopy = packet->Copy();
717 packetCopy->AddHeader(ipHeader);
718 m_txTrace(packetCopy, ipv4, interface);
719 }
720}
721
722void
724 Ipv4Address source,
725 Ipv4Address destination,
726 uint8_t protocol,
727 Ptr<Ipv4Route> route)
728{
729 NS_LOG_FUNCTION(this << packet << source << destination << uint32_t(protocol) << route);
730
731 bool mayFragment = true;
732
733 // we need a copy of the packet with its tags in case we need to invoke recursion.
734 Ptr<Packet> pktCopyWithTags = packet->Copy();
735
736 uint8_t ttl = m_defaultTtl;
737 SocketIpTtlTag ipTtlTag;
738 bool ipTtlTagFound = packet->RemovePacketTag(ipTtlTag);
739 if (ipTtlTagFound)
740 {
741 ttl = ipTtlTag.GetTtl();
742 }
743
744 uint8_t tos = 0;
745 SocketIpTosTag ipTosTag;
746 bool ipTosTagFound = packet->RemovePacketTag(ipTosTag);
747 if (ipTosTagFound)
748 {
749 tos = ipTosTag.GetTos();
750 }
751
752 // can construct the header here
753 Ipv4Header ipHeader =
754 BuildHeader(source, destination, protocol, packet->GetSize(), ttl, tos, mayFragment);
755
756 // Handle a few cases:
757 // 1) packet is passed in with a route entry
758 // 1a) packet is passed in with a route entry but route->GetGateway is not set (e.g., on-demand)
759 // 1b) packet is passed in with a route entry and valid gateway
760 // 2) packet is passed without a route and packet is destined to limited broadcast address
761 // 3) packet is passed without a route and packet is destined to a subnet-directed broadcast
762 // address 4) packet is passed without a route, packet is not broadcast (e.g., a raw socket
763 // call, or ICMP)
764
765 // 1) packet is passed in with route entry
766 if (route)
767 {
768 // 1a) route->GetGateway is not set (e.g., on-demand)
769 if (!route->GetGateway().IsInitialized())
770 {
771 // This could arise because the synchronous RouteOutput() call
772 // returned to the transport protocol with a source address but
773 // there was no next hop available yet (since a route may need
774 // to be queried).
775 NS_FATAL_ERROR("Ipv4L3Protocol::Send case 1a: packet passed with a route but the "
776 "Gateway address is uninitialized. This case not yet implemented.");
777 }
778
779 // 1b) with a valid gateway
780 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 1b: passed in with route and valid gateway");
781 int32_t interface = GetInterfaceForDevice(route->GetOutputDevice());
782 m_sendOutgoingTrace(ipHeader, packet, interface);
783 if (m_enableDpd && ipHeader.GetDestination().IsMulticast())
784 {
785 UpdateDuplicate(packet, ipHeader);
786 }
787 SendRealOut(route, packet->Copy(), ipHeader);
788 return;
789 }
790
791 // 2) packet is destined to limited broadcast address or link-local multicast address
792 if (destination.IsBroadcast() || destination.IsLocalMulticast())
793 {
794 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 2: limited broadcast - no route");
795 uint32_t ifaceIndex = 0;
796 for (auto ifaceIter = m_interfaces.begin(); ifaceIter != m_interfaces.end();
797 ifaceIter++, ifaceIndex++)
798 {
799 Ptr<Ipv4Interface> outInterface = *ifaceIter;
800 // ANY source matches any interface
801 bool sendIt = source.IsAny();
802 // check if some specific address on outInterface matches
803 for (uint32_t index = 0; !sendIt && index < outInterface->GetNAddresses(); index++)
804 {
805 if (outInterface->GetAddress(index).GetLocal() == source)
806 {
807 sendIt = true;
808 }
809 }
810
811 if (sendIt)
812 {
813 // create a proxy route for this interface
815 route->SetDestination(destination);
816 route->SetGateway(Ipv4Address::GetAny());
817 route->SetSource(source);
818 route->SetOutputDevice(outInterface->GetDevice());
819 DecreaseIdentification(source, destination, protocol);
820 Send(pktCopyWithTags, source, destination, protocol, route);
821 }
822 }
823 return;
824 }
825
826 // 3) check: packet is destined to a subnet-directed broadcast address
827 for (auto ifaceIter = m_interfaces.begin(); ifaceIter != m_interfaces.end(); ifaceIter++)
828 {
829 Ptr<Ipv4Interface> outInterface = *ifaceIter;
830 uint32_t ifaceIndex = GetInterfaceForDevice(outInterface->GetDevice());
831 for (uint32_t j = 0; j < GetNAddresses(ifaceIndex); j++)
832 {
833 Ipv4InterfaceAddress ifAddr = GetAddress(ifaceIndex, j);
834 NS_LOG_LOGIC("Testing address " << ifAddr.GetLocal() << " with mask "
835 << ifAddr.GetMask());
836 if (destination.IsSubnetDirectedBroadcast(ifAddr.GetMask()) &&
837 destination.CombineMask(ifAddr.GetMask()) ==
838 ifAddr.GetLocal().CombineMask(ifAddr.GetMask()))
839 {
840 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 3: subnet directed bcast to "
841 << ifAddr.GetLocal() << " - no route");
842 // create a proxy route for this interface
844 route->SetDestination(destination);
845 route->SetGateway(Ipv4Address::GetAny());
846 route->SetSource(source);
847 route->SetOutputDevice(outInterface->GetDevice());
848 DecreaseIdentification(source, destination, protocol);
849 Send(pktCopyWithTags, source, destination, protocol, route);
850 return;
851 }
852 }
853 }
854
855 // 4) packet is not broadcast, and route is NULL (e.g., a raw socket call)
856 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 4: not broadcast and passed in with no route "
857 << destination);
858 Socket::SocketErrno errno_;
859 Ptr<NetDevice> oif(nullptr); // unused for now
860 Ptr<Ipv4Route> newRoute;
862 {
863 newRoute = m_routingProtocol->RouteOutput(pktCopyWithTags, ipHeader, oif, errno_);
864 }
865 else
866 {
867 NS_LOG_ERROR("Ipv4L3Protocol::Send: m_routingProtocol == 0");
868 }
869 if (newRoute)
870 {
871 DecreaseIdentification(source, destination, protocol);
872 Send(pktCopyWithTags, source, destination, protocol, newRoute);
873 }
874 else
875 {
876 NS_LOG_WARN("No route to host. Drop.");
877 m_dropTrace(ipHeader, packet, DROP_NO_ROUTE, this, 0);
878 DecreaseIdentification(source, destination, protocol);
879 }
880}
881
882void
884 Ipv4Address destination,
885 uint8_t protocol)
886{
887 uint64_t src = source.Get();
888 uint64_t dst = destination.Get();
889 uint64_t srcDst = dst | (src << 32);
890 std::pair<uint64_t, uint8_t> key = std::make_pair(srcDst, protocol);
891 m_identification[key]--;
892}
893
896 Ipv4Address destination,
897 uint8_t protocol,
898 uint16_t payloadSize,
899 uint8_t ttl,
900 uint8_t tos,
901 bool mayFragment)
902{
903 NS_LOG_FUNCTION(this << source << destination << (uint16_t)protocol << payloadSize
904 << (uint16_t)ttl << (uint16_t)tos << mayFragment);
905 Ipv4Header ipHeader;
906 ipHeader.SetSource(source);
907 ipHeader.SetDestination(destination);
908 ipHeader.SetProtocol(protocol);
909 ipHeader.SetPayloadSize(payloadSize);
910 ipHeader.SetTtl(ttl);
911 ipHeader.SetTos(tos);
912
913 uint64_t src = source.Get();
914 uint64_t dst = destination.Get();
915 uint64_t srcDst = dst | (src << 32);
916 std::pair<uint64_t, uint8_t> key = std::make_pair(srcDst, protocol);
917
918 if (mayFragment)
919 {
920 ipHeader.SetMayFragment();
921 ipHeader.SetIdentification(m_identification[key]);
922 m_identification[key]++;
923 }
924 else
925 {
926 ipHeader.SetDontFragment();
927 // RFC 6864 does not state anything about atomic datagrams
928 // identification requirement:
929 // >> Originating sources MAY set the IPv4 ID field of atomic datagrams
930 // to any value.
931 ipHeader.SetIdentification(m_identification[key]);
932 m_identification[key]++;
933 }
935 {
936 ipHeader.EnableChecksum();
937 }
938 return ipHeader;
939}
940
941void
943{
944 NS_LOG_FUNCTION(this << route << packet << &ipHeader);
945 if (!route)
946 {
947 NS_LOG_WARN("No route to host. Drop.");
948 m_dropTrace(ipHeader, packet, DROP_NO_ROUTE, this, 0);
949 return;
950 }
951 Ptr<NetDevice> outDev = route->GetOutputDevice();
952 int32_t interface = GetInterfaceForDevice(outDev);
953 NS_ASSERT(interface >= 0);
954 Ptr<Ipv4Interface> outInterface = GetInterface(interface);
955 NS_LOG_LOGIC("Send via NetDevice ifIndex " << outDev->GetIfIndex() << " ipv4InterfaceIndex "
956 << interface);
957
958 Ipv4Address target;
959 std::string targetLabel;
960 if (route->GetGateway().IsAny())
961 {
962 target = ipHeader.GetDestination();
963 targetLabel = "destination";
964 }
965 else
966 {
967 target = route->GetGateway();
968 targetLabel = "gateway";
969 }
970
971 if (outInterface->IsUp())
972 {
973 NS_LOG_LOGIC("Send to " << targetLabel << " " << target);
974 if (packet->GetSize() + ipHeader.GetSerializedSize() > outInterface->GetDevice()->GetMtu())
975 {
976 std::list<Ipv4PayloadHeaderPair> listFragments;
977 DoFragmentation(packet, ipHeader, outInterface->GetDevice()->GetMtu(), listFragments);
978 for (auto it = listFragments.begin(); it != listFragments.end(); it++)
979 {
980 NS_LOG_LOGIC("Sending fragment " << *(it->first));
981 CallTxTrace(it->second, it->first, this, interface);
982 outInterface->Send(it->first, it->second, target);
983 }
984 }
985 else
986 {
987 CallTxTrace(ipHeader, packet, this, interface);
988 outInterface->Send(packet, ipHeader, target);
989 }
990 }
991}
992
993// This function analogous to Linux ip_mr_forward()
994void
997 const Ipv4Header& header)
998{
999 NS_LOG_FUNCTION(this << mrtentry << p << header);
1000 NS_LOG_LOGIC("Multicast forwarding logic for node: " << m_node->GetId());
1001
1002 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap();
1003
1004 for (auto mapIter = ttlMap.begin(); mapIter != ttlMap.end(); mapIter++)
1005 {
1006 uint32_t interface = mapIter->first;
1007 // uint32_t outputTtl = mapIter->second; // Unused for now
1008
1009 Ptr<Packet> packet = p->Copy();
1010 Ipv4Header ipHeader = header;
1011 if (ipHeader.GetTtl() <= 1)
1012 {
1013 NS_LOG_WARN("TTL exceeded. Drop.");
1014 m_dropTrace(header, packet, DROP_TTL_EXPIRED, this, interface);
1015 return;
1016 }
1017 ipHeader.SetTtl(header.GetTtl() - 1);
1018 NS_LOG_LOGIC("Forward multicast via interface " << interface);
1020 rtentry->SetSource(ipHeader.GetSource());
1021 rtentry->SetDestination(ipHeader.GetDestination());
1022 rtentry->SetGateway(Ipv4Address::GetAny());
1023 rtentry->SetOutputDevice(GetNetDevice(interface));
1024
1025 m_multicastForwardTrace(ipHeader, packet, interface);
1026 SendRealOut(rtentry, packet, ipHeader);
1027 }
1028}
1029
1030// This function analogous to Linux ip_forward()
1031void
1033{
1034 NS_LOG_FUNCTION(this << rtentry << p << header);
1035 NS_LOG_LOGIC("Forwarding logic for node: " << m_node->GetId());
1036 // Forwarding
1037 Ipv4Header ipHeader = header;
1038 Ptr<Packet> packet = p->Copy();
1039 int32_t interface = GetInterfaceForDevice(rtentry->GetOutputDevice());
1040 if (ipHeader.GetTtl() <= 1)
1041 {
1042 // Do not reply to multicast/broadcast IP address
1043 if (!ipHeader.GetDestination().IsBroadcast() && !ipHeader.GetDestination().IsMulticast())
1044 {
1046 icmp->SendTimeExceededTtl(ipHeader, packet, false);
1047 }
1048 NS_LOG_WARN("TTL exceeded. Drop.");
1049 m_dropTrace(header, packet, DROP_TTL_EXPIRED, this, interface);
1050 return;
1051 }
1052 ipHeader.SetTtl(ipHeader.GetTtl() - 1);
1053 // in case the packet still has a priority tag attached, remove it
1054 SocketPriorityTag priorityTag;
1055 packet->RemovePacketTag(priorityTag);
1056 uint8_t priority = Socket::IpTos2Priority(ipHeader.GetTos());
1057 // add a priority tag if the priority is not null
1058 if (priority)
1059 {
1060 priorityTag.SetPriority(priority);
1061 packet->AddPacketTag(priorityTag);
1062 }
1063
1064 m_unicastForwardTrace(ipHeader, packet, interface);
1065 SendRealOut(rtentry, packet, ipHeader);
1066}
1067
1068void
1070{
1071 NS_LOG_FUNCTION(this << packet << &ip << iif);
1072 Ptr<Packet> p = packet->Copy(); // need to pass a non-const packet up
1073 Ipv4Header ipHeader = ip;
1074
1075 if (!ipHeader.IsLastFragment() || ipHeader.GetFragmentOffset() != 0)
1076 {
1077 NS_LOG_LOGIC("Received a fragment, processing " << *p);
1078 bool isPacketComplete;
1079 isPacketComplete = ProcessFragment(p, ipHeader, iif);
1080 if (!isPacketComplete)
1081 {
1082 return;
1083 }
1084 NS_LOG_LOGIC("Got last fragment, Packet is complete " << *p);
1085 ipHeader.SetFragmentOffset(0);
1086 ipHeader.SetPayloadSize(p->GetSize());
1087 }
1088
1089 m_localDeliverTrace(ipHeader, p, iif);
1090
1091 Ptr<Ipv4Interface> ipv4Interface = GetInterface(iif);
1092
1093 for (auto& socket : m_sockets)
1094 {
1095 NS_LOG_INFO("Delivering to raw socket " << socket);
1096 socket->ForwardUp(p, ipHeader, ipv4Interface);
1097 }
1098
1099 Ptr<IpL4Protocol> protocol = GetProtocol(ipHeader.GetProtocol(), iif);
1100 if (protocol)
1101 {
1102 // we need to make a copy in the unlikely event we hit the
1103 // RX_ENDPOINT_UNREACH codepath
1104 Ptr<Packet> copy = p->Copy();
1105 IpL4Protocol::RxStatus status = protocol->Receive(p, ipHeader, GetInterface(iif));
1106 switch (status)
1107 {
1109 // fall through
1111 // fall through
1113 break;
1115 if (ipHeader.GetDestination().IsBroadcast() || ipHeader.GetDestination().IsMulticast())
1116 {
1117 break; // Do not reply to broadcast or multicast
1118 }
1119 // Another case to suppress ICMP is a subnet-directed broadcast
1120 bool subnetDirected = false;
1121 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
1122 {
1123 Ipv4InterfaceAddress addr = GetAddress(iif, i);
1124 if (addr.GetLocal().CombineMask(addr.GetMask()) ==
1125 ipHeader.GetDestination().CombineMask(addr.GetMask()) &&
1127 {
1128 subnetDirected = true;
1129 }
1130 }
1131 if (!subnetDirected)
1132 {
1133 GetIcmp()->SendDestUnreachPort(ipHeader, copy);
1134 }
1135 }
1136 }
1137}
1138
1139bool
1141{
1142 NS_LOG_FUNCTION(this << i << address);
1143 Ptr<Ipv4Interface> interface = GetInterface(i);
1144 bool retVal = interface->AddAddress(address);
1145 if (m_routingProtocol)
1146 {
1147 m_routingProtocol->NotifyAddAddress(i, address);
1148 }
1149 return retVal;
1150}
1151
1153Ipv4L3Protocol::GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
1154{
1155 Ptr<Ipv4Interface> interface = GetInterface(interfaceIndex);
1156 return interface->GetAddress(addressIndex);
1157}
1158
1161{
1162 Ptr<Ipv4Interface> iface = GetInterface(interface);
1163 return iface->GetNAddresses();
1164}
1165
1166bool
1168{
1169 NS_LOG_FUNCTION(this << i << addressIndex);
1170 Ptr<Ipv4Interface> interface = GetInterface(i);
1171 Ipv4InterfaceAddress address = interface->RemoveAddress(addressIndex);
1172 if (address != Ipv4InterfaceAddress())
1173 {
1174 if (m_routingProtocol)
1175 {
1176 m_routingProtocol->NotifyRemoveAddress(i, address);
1177 }
1178 return true;
1179 }
1180 return false;
1181}
1182
1183bool
1185{
1186 NS_LOG_FUNCTION(this << i << address);
1187
1188 if (address == Ipv4Address::GetLoopback())
1189 {
1190 NS_LOG_WARN("Cannot remove loopback address.");
1191 return false;
1192 }
1193 Ptr<Ipv4Interface> interface = GetInterface(i);
1194 Ipv4InterfaceAddress ifAddr = interface->RemoveAddress(address);
1195 if (ifAddr != Ipv4InterfaceAddress())
1196 {
1197 if (m_routingProtocol)
1198 {
1199 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
1200 }
1201 return true;
1202 }
1203 return false;
1204}
1205
1208{
1209 NS_LOG_FUNCTION(this << interfaceIdx << " " << dest);
1210 if (GetNAddresses(interfaceIdx) == 1) // common case
1211 {
1212 return GetAddress(interfaceIdx, 0).GetLocal();
1213 }
1214 // no way to determine the scope of the destination, so adopt the
1215 // following rule: pick the first available address (index 0) unless
1216 // a subsequent address is on link (in which case, pick the primary
1217 // address if there are multiple)
1218 Ipv4Address candidate = GetAddress(interfaceIdx, 0).GetLocal();
1219 for (uint32_t i = 0; i < GetNAddresses(interfaceIdx); i++)
1220 {
1221 Ipv4InterfaceAddress test = GetAddress(interfaceIdx, i);
1222 if (test.GetLocal().CombineMask(test.GetMask()) == dest.CombineMask(test.GetMask()))
1223 {
1224 if (!test.IsSecondary())
1225 {
1226 return test.GetLocal();
1227 }
1228 }
1229 }
1230 return candidate;
1231}
1232
1235 Ipv4Address dst,
1237{
1238 NS_LOG_FUNCTION(this << device << dst << scope);
1239 Ipv4Address addr("0.0.0.0");
1241 bool found = false;
1242
1243 if (device)
1244 {
1245 int32_t i = GetInterfaceForDevice(device);
1246 NS_ASSERT_MSG(i >= 0, "No device found on node");
1247 for (uint32_t j = 0; j < GetNAddresses(i); j++)
1248 {
1249 iaddr = GetAddress(i, j);
1250 if (iaddr.IsSecondary())
1251 {
1252 continue;
1253 }
1254 if (iaddr.GetScope() > scope)
1255 {
1256 continue;
1257 }
1258 if (dst.CombineMask(iaddr.GetMask()) == iaddr.GetLocal().CombineMask(iaddr.GetMask()))
1259 {
1260 return iaddr.GetLocal();
1261 }
1262 if (!found)
1263 {
1264 addr = iaddr.GetLocal();
1265 found = true;
1266 }
1267 }
1268 }
1269 if (found)
1270 {
1271 return addr;
1272 }
1273
1274 // Iterate among all interfaces
1275 for (uint32_t i = 0; i < GetNInterfaces(); i++)
1276 {
1277 for (uint32_t j = 0; j < GetNAddresses(i); j++)
1278 {
1279 iaddr = GetAddress(i, j);
1280 if (iaddr.IsSecondary())
1281 {
1282 continue;
1283 }
1284 if (iaddr.GetScope() != Ipv4InterfaceAddress::LINK && iaddr.GetScope() <= scope)
1285 {
1286 return iaddr.GetLocal();
1287 }
1288 }
1289 }
1290 NS_LOG_WARN("Could not find source address for " << dst << " and scope " << scope
1291 << ", returning 0");
1292 return addr;
1293}
1294
1295void
1297{
1298 NS_LOG_FUNCTION(this << i << metric);
1299 Ptr<Ipv4Interface> interface = GetInterface(i);
1300 interface->SetMetric(metric);
1301}
1302
1303uint16_t
1305{
1306 Ptr<Ipv4Interface> interface = GetInterface(i);
1307 return interface->GetMetric();
1308}
1309
1310uint16_t
1312{
1313 Ptr<Ipv4Interface> interface = GetInterface(i);
1314 return interface->GetDevice()->GetMtu();
1315}
1316
1317bool
1319{
1320 Ptr<Ipv4Interface> interface = GetInterface(i);
1321 return interface->IsUp();
1322}
1323
1324void
1326{
1327 NS_LOG_FUNCTION(this << i);
1328 Ptr<Ipv4Interface> interface = GetInterface(i);
1329
1330 // RFC 791, pg.25:
1331 // Every internet module must be able to forward a datagram of 68
1332 // octets without further fragmentation. This is because an internet
1333 // header may be up to 60 octets, and the minimum fragment is 8 octets.
1334 if (interface->GetDevice()->GetMtu() >= 68)
1335 {
1336 interface->SetUp();
1337
1338 if (m_routingProtocol)
1339 {
1340 m_routingProtocol->NotifyInterfaceUp(i);
1341 }
1342 }
1343 else
1344 {
1346 "Interface "
1347 << int(i)
1348 << " is set to be down for IPv4. Reason: not respecting minimum IPv4 MTU (68 octets)");
1349 }
1350}
1351
1352void
1354{
1355 NS_LOG_FUNCTION(this << ifaceIndex);
1356 Ptr<Ipv4Interface> interface = GetInterface(ifaceIndex);
1357 interface->SetDown();
1358
1359 if (m_routingProtocol)
1360 {
1361 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
1362 }
1363}
1364
1365bool
1367{
1368 Ptr<Ipv4Interface> interface = GetInterface(i);
1369 NS_LOG_LOGIC("Forwarding state: " << interface->IsForwarding());
1370 return interface->IsForwarding();
1371}
1372
1373void
1375{
1376 NS_LOG_FUNCTION(this << i);
1377 Ptr<Ipv4Interface> interface = GetInterface(i);
1378 interface->SetForwarding(val);
1379}
1380
1386
1387void
1389{
1390 NS_LOG_FUNCTION(this << forward);
1391 m_ipForward = forward;
1392 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++)
1393 {
1394 (*i)->SetForwarding(forward);
1395 }
1396}
1397
1398bool
1400{
1401 return m_ipForward;
1402}
1403
1404void
1406{
1407 NS_LOG_FUNCTION(this << model);
1408 m_strongEndSystemModel = model;
1409}
1410
1411bool
1416
1417void
1419 const Ipv4Header& ipHeader,
1420 Socket::SocketErrno sockErrno)
1421{
1422 NS_LOG_FUNCTION(this << p << ipHeader << sockErrno);
1423 NS_LOG_LOGIC("Route input failure-- dropping packet to " << ipHeader << " with errno "
1424 << sockErrno);
1425 m_dropTrace(ipHeader, p, DROP_ROUTE_ERROR, this, 0);
1426
1427 // \todo Send an ICMP no route.
1428}
1429
1430void
1432 const Ipv4Header& ipv4Header,
1433 uint32_t outIfaceMtu,
1434 std::list<Ipv4PayloadHeaderPair>& listFragments)
1435{
1436 // BEWARE: here we do assume that the header options are not present.
1437 // a much more complex handling is necessary in case there are options.
1438 // If (when) IPv4 option headers will be implemented, the following code shall be changed.
1439 // Of course also the reassembly code shall be changed as well.
1440
1441 NS_LOG_FUNCTION(this << *packet << outIfaceMtu << &listFragments);
1442
1443 Ptr<Packet> p = packet->Copy();
1444
1445 NS_ASSERT_MSG((ipv4Header.GetSerializedSize() == 5 * 4),
1446 "IPv4 fragmentation implementation only works without option headers.");
1447
1448 uint16_t offset = 0;
1449 bool moreFragment = true;
1450 uint16_t originalOffset = ipv4Header.GetFragmentOffset();
1451 bool isLastFragment = ipv4Header.IsLastFragment();
1452 uint32_t currentFragmentablePartSize = 0;
1453
1454 // IPv4 fragments are all 8 bytes aligned but the last.
1455 // The IP payload size is:
1456 // floor( ( outIfaceMtu - ipv4Header.GetSerializedSize() ) /8 ) *8
1457 uint32_t fragmentSize = (outIfaceMtu - ipv4Header.GetSerializedSize()) & ~uint32_t(0x7);
1458
1459 NS_LOG_LOGIC("Fragmenting - Target Size: " << fragmentSize);
1460
1461 do
1462 {
1463 Ipv4Header fragmentHeader = ipv4Header;
1464
1465 if (p->GetSize() > offset + fragmentSize)
1466 {
1467 moreFragment = true;
1468 currentFragmentablePartSize = fragmentSize;
1469 fragmentHeader.SetMoreFragments();
1470 }
1471 else
1472 {
1473 moreFragment = false;
1474 currentFragmentablePartSize = p->GetSize() - offset;
1475 if (!isLastFragment)
1476 {
1477 fragmentHeader.SetMoreFragments();
1478 }
1479 else
1480 {
1481 fragmentHeader.SetLastFragment();
1482 }
1483 }
1484
1485 NS_LOG_LOGIC("Fragment creation - " << offset << ", " << currentFragmentablePartSize);
1486 Ptr<Packet> fragment = p->CreateFragment(offset, currentFragmentablePartSize);
1487 NS_LOG_LOGIC("Fragment created - " << offset << ", " << fragment->GetSize());
1488
1489 fragmentHeader.SetFragmentOffset(offset + originalOffset);
1490 fragmentHeader.SetPayloadSize(currentFragmentablePartSize);
1491
1493 {
1494 fragmentHeader.EnableChecksum();
1495 }
1496
1497 NS_LOG_LOGIC("Fragment check - " << fragmentHeader.GetFragmentOffset());
1498
1499 NS_LOG_LOGIC("New fragment Header " << fragmentHeader);
1500
1501 std::ostringstream oss;
1502 oss << fragmentHeader;
1503 fragment->Print(oss);
1504
1505 NS_LOG_LOGIC("New fragment " << *fragment);
1506
1507 listFragments.emplace_back(fragment, fragmentHeader);
1508
1509 offset += currentFragmentablePartSize;
1510
1511 } while (moreFragment);
1512}
1513
1514bool
1516{
1517 NS_LOG_FUNCTION(this << packet << ipHeader << iif);
1518
1519 uint64_t addressCombination =
1520 uint64_t(ipHeader.GetSource().Get()) << 32 | uint64_t(ipHeader.GetDestination().Get());
1521 uint32_t idProto =
1522 uint32_t(ipHeader.GetIdentification()) << 16 | uint32_t(ipHeader.GetProtocol());
1523 FragmentKey_t key;
1524 bool ret = false;
1525 Ptr<Packet> p = packet->Copy();
1526
1527 key.first = addressCombination;
1528 key.second = idProto;
1529
1530 Ptr<Fragments> fragments;
1531
1532 auto it = m_fragments.find(key);
1533 if (it == m_fragments.end())
1534 {
1535 fragments = Create<Fragments>();
1536 m_fragments.insert(std::make_pair(key, fragments));
1537
1538 auto iter = SetTimeout(key, ipHeader, iif);
1539 fragments->SetTimeoutIter(iter);
1540 }
1541 else
1542 {
1543 fragments = it->second;
1544 }
1545
1546 NS_LOG_LOGIC("Adding fragment - Size: " << packet->GetSize()
1547 << " - Offset: " << (ipHeader.GetFragmentOffset()));
1548
1549 fragments->AddFragment(p, ipHeader.GetFragmentOffset(), !ipHeader.IsLastFragment());
1550
1551 if (fragments->IsEntire())
1552 {
1553 packet = fragments->GetPacket();
1554 m_timeoutEventList.erase(fragments->GetTimeoutIter());
1555 fragments = nullptr;
1556 m_fragments.erase(key);
1557 ret = true;
1558 }
1559
1560 return ret;
1561}
1562
1564 : m_moreFragment(false)
1565{
1566 NS_LOG_FUNCTION(this);
1567}
1568
1569void
1571 uint16_t fragmentOffset,
1572 bool moreFragment)
1573{
1574 NS_LOG_FUNCTION(this << fragment << fragmentOffset << moreFragment);
1575
1576 std::list<std::pair<Ptr<Packet>, uint16_t>>::iterator it;
1577
1578 for (it = m_fragments.begin(); it != m_fragments.end(); it++)
1579 {
1580 if (it->second > fragmentOffset)
1581 {
1582 break;
1583 }
1584 }
1585
1586 if (it == m_fragments.end())
1587 {
1588 m_moreFragment = moreFragment;
1589 }
1590
1591 m_fragments.insert(it, std::pair<Ptr<Packet>, uint16_t>(fragment, fragmentOffset));
1592}
1593
1594bool
1596{
1597 NS_LOG_FUNCTION(this);
1598
1599 bool ret = !m_moreFragment && !m_fragments.empty();
1600
1601 if (ret)
1602 {
1603 uint16_t lastEndOffset = 0;
1604
1605 for (auto it = m_fragments.begin(); it != m_fragments.end(); it++)
1606 {
1607 // overlapping fragments do exist
1608 NS_LOG_LOGIC("Checking overlaps " << lastEndOffset << " - " << it->second);
1609
1610 if (lastEndOffset < it->second)
1611 {
1612 ret = false;
1613 break;
1614 }
1615 // fragments might overlap in strange ways
1616 uint16_t fragmentEnd = it->first->GetSize() + it->second;
1617 lastEndOffset = std::max(lastEndOffset, fragmentEnd);
1618 }
1619 }
1620
1621 return ret;
1622}
1623
1626{
1627 NS_LOG_FUNCTION(this);
1628
1629 auto it = m_fragments.begin();
1630
1631 Ptr<Packet> p = it->first->Copy();
1632 uint16_t lastEndOffset = p->GetSize();
1633 it++;
1634
1635 for (; it != m_fragments.end(); it++)
1636 {
1637 if (lastEndOffset > it->second)
1638 {
1639 // The fragments are overlapping.
1640 // We do not overwrite the "old" with the "new" because we do not know when each
1641 // arrived. This is different from what Linux does. It is not possible to emulate a
1642 // fragmentation attack.
1643 uint32_t newStart = lastEndOffset - it->second;
1644 if (it->first->GetSize() > newStart)
1645 {
1646 uint32_t newSize = it->first->GetSize() - newStart;
1647 Ptr<Packet> tempFragment = it->first->CreateFragment(newStart, newSize);
1648 p->AddAtEnd(tempFragment);
1649 }
1650 }
1651 else
1652 {
1653 NS_LOG_LOGIC("Adding: " << *(it->first));
1654 p->AddAtEnd(it->first);
1655 }
1656 lastEndOffset = p->GetSize();
1657 }
1658
1659 return p;
1660}
1661
1664{
1665 NS_LOG_FUNCTION(this);
1666
1667 auto it = m_fragments.begin();
1668
1670 uint16_t lastEndOffset = 0;
1671
1672 if (m_fragments.begin()->second > 0)
1673 {
1674 return p;
1675 }
1676
1677 for (it = m_fragments.begin(); it != m_fragments.end(); it++)
1678 {
1679 if (lastEndOffset > it->second)
1680 {
1681 uint32_t newStart = lastEndOffset - it->second;
1682 uint32_t newSize = it->first->GetSize() - newStart;
1683 Ptr<Packet> tempFragment = it->first->CreateFragment(newStart, newSize);
1684 p->AddAtEnd(tempFragment);
1685 }
1686 else if (lastEndOffset == it->second)
1687 {
1688 NS_LOG_LOGIC("Adding: " << *(it->first));
1689 p->AddAtEnd(it->first);
1690 }
1691 lastEndOffset = p->GetSize();
1692 }
1693
1694 return p;
1695}
1696
1697void
1699{
1700 m_timeoutIter = iter;
1701}
1702
1705{
1706 return m_timeoutIter;
1707}
1708
1709void
1711{
1712 NS_LOG_FUNCTION(this << &key << &ipHeader << iif);
1713
1714 auto it = m_fragments.find(key);
1715 Ptr<Packet> packet = it->second->GetPartialPacket();
1716
1717 // if we have at least 8 bytes, we can send an ICMP.
1718 if (packet->GetSize() > 8)
1719 {
1721 icmp->SendTimeExceededTtl(ipHeader, packet, true);
1722 }
1723 m_dropTrace(ipHeader, packet, DROP_FRAGMENT_TIMEOUT, this, iif);
1724
1725 // clear the buffers
1726 it->second = nullptr;
1727
1728 m_fragments.erase(key);
1729}
1730
1731bool
1733{
1734 NS_LOG_FUNCTION(this << p << header);
1735
1736 // \todo RFC 6621 mandates SHA-1 hash. For now ns3 hash should be fine.
1737 uint8_t proto = header.GetProtocol();
1738 Ipv4Address src = header.GetSource();
1739 Ipv4Address dst = header.GetDestination();
1740 uint64_t id = header.GetIdentification();
1741
1742 // concat hash value onto id
1743 uint64_t hash = id << 32;
1744 if (header.GetFragmentOffset() || !header.IsLastFragment())
1745 {
1746 // use I-DPD (RFC 6621, Sec 6.2.1)
1747 hash |= header.GetFragmentOffset();
1748 }
1749 else
1750 {
1751 // use H-DPD (RFC 6621, Sec 6.2.2)
1752
1753 // serialize packet
1754 Ptr<Packet> pkt = p->Copy();
1755 pkt->AddHeader(header);
1756
1757 std::ostringstream oss(std::ios_base::binary);
1758 pkt->CopyData(&oss, pkt->GetSize());
1759 std::string bytes = oss.str();
1760
1761 NS_ASSERT_MSG(bytes.size() >= 20, "Degenerate header serialization");
1762
1763 // zero out mutable fields
1764 bytes[1] = 0; // DSCP / ECN
1765 bytes[6] = bytes[7] = 0; // Flags / Fragment offset
1766 bytes[8] = 0; // TTL
1767 bytes[10] = bytes[11] = 0; // Header checksum
1768 if (header.GetSerializedSize() > 20) // assume options should be 0'd
1769 {
1770 std::fill_n(bytes.begin() + 20, header.GetSerializedSize() - 20, 0);
1771 }
1772
1773 // concat hash onto ID
1774 hash |= (uint64_t)Hash32(bytes);
1775 }
1776
1777 // set cleanup job for new duplicate entries
1779 {
1781 }
1782
1783 // assume this is a new entry
1784 DupTuple_t key{hash, proto, src, dst};
1785 NS_LOG_DEBUG("Packet " << p->GetUid() << " key = (" << std::hex << std::get<0>(key) << ", "
1786 << std::dec << +std::get<1>(key) << ", " << std::get<2>(key) << ", "
1787 << std::get<3>(key) << ")");
1788
1789 // place a new entry, on collision the existing entry iterator is returned
1790 auto [iter, inserted] = m_dups.emplace(key, Seconds(0));
1791 bool isDup = !inserted && iter->second > Simulator::Now();
1792
1793 // set the expiration event
1794 iter->second = Simulator::Now() + m_expire;
1795 return isDup;
1796}
1797
1798void
1800{
1801 NS_LOG_FUNCTION(this);
1802
1803 DupMap_t::size_type n = 0;
1804 Time expire = Simulator::Now();
1805 auto iter = m_dups.cbegin();
1806 while (iter != m_dups.cend())
1807 {
1808 if (iter->second < expire)
1809 {
1810 NS_LOG_LOGIC("Remove key = (" << std::hex << std::get<0>(iter->first) << ", "
1811 << std::dec << +std::get<1>(iter->first) << ", "
1812 << std::get<2>(iter->first) << ", "
1813 << std::get<3>(iter->first) << ")");
1814 iter = m_dups.erase(iter);
1815 ++n;
1816 }
1817 else
1818 {
1819 ++iter;
1820 }
1821 }
1822
1823 NS_LOG_DEBUG("Purged " << n << " expired duplicate entries out of " << (n + m_dups.size()));
1824
1825 // keep cleaning up if necessary
1826 if (!m_dups.empty() && m_purge.IsStrictlyPositive())
1827 {
1829 }
1830}
1831
1834{
1836
1837 if (m_timeoutEventList.empty())
1838 {
1841 }
1842 m_timeoutEventList.emplace_back(now, key, ipHeader, iif);
1843
1844 auto iter = --m_timeoutEventList.end();
1845
1846 return iter;
1847}
1848
1849void
1851{
1852 Time now = Simulator::Now();
1853
1854 while (!m_timeoutEventList.empty() && std::get<0>(*m_timeoutEventList.begin()) == now)
1855 {
1856 HandleFragmentsTimeout(std::get<1>(*m_timeoutEventList.begin()),
1857 std::get<2>(*m_timeoutEventList.begin()),
1858 std::get<3>(*m_timeoutEventList.begin()));
1859 m_timeoutEventList.pop_front();
1860 }
1861
1862 if (m_timeoutEventList.empty())
1863 {
1864 return;
1865 }
1866
1867 Time difference = std::get<0>(*m_timeoutEventList.begin()) - now;
1869}
1870
1871} // namespace ns3
a polymophic address class
Definition address.h:90
A record that that holds information about an ArpCache entry.
Definition arp-cache.h:173
bool IsAlive()
Definition arp-cache.cc:386
void UpdateSeen()
Update the entry when seeing a packet.
Definition arp-cache.cc:569
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
AttributeValue implementation for Boolean.
Definition boolean.h:26
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
This is the implementation of the ICMP protocol as described in RFC 792 .
static uint16_t GetStaticProtocolNumber()
Get the protocol number.
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetLoopback()
bool IsMulticast() const
bool IsSubnetDirectedBroadcast(const Ipv4Mask &mask) const
Generate subnet-directed broadcast address corresponding to mask.
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
bool IsAny() const
uint32_t Get() const
Get the host-order 32-bit IP address.
bool IsBroadcast() const
static Ipv4Address GetAny()
bool IsLocalMulticast() const
Packet header for IPv4.
Definition ipv4-header.h:23
bool IsChecksumOk() const
void SetDestination(Ipv4Address destination)
Ipv4Address GetSource() const
void SetDontFragment()
Don't fragment this packet: if you need to anyway, drop it.
uint8_t GetTos() const
void SetLastFragment()
This packet is the last packet of a fragmented ipv4 packet.
void SetPayloadSize(uint16_t size)
uint16_t GetIdentification() const
uint8_t GetProtocol() const
void SetTtl(uint8_t ttl)
bool IsLastFragment() const
void SetMoreFragments()
This packet is not the last packet of a fragmented ipv4 packet.
Ipv4Address GetDestination() const
void SetMayFragment()
If you need to fragment this packet, you can do it.
uint16_t GetPayloadSize() const
uint32_t GetSerializedSize() const override
uint16_t GetFragmentOffset() const
void SetProtocol(uint8_t num)
void SetFragmentOffset(uint16_t offsetBytes)
The offset is measured in bytes for the packet start.
void SetIdentification(uint16_t identification)
uint8_t GetTtl() const
void EnableChecksum()
Enable checksum calculation for this header.
void SetTos(uint8_t tos)
void SetSource(Ipv4Address source)
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
a class to store IPv4 address information on an interface
Ipv4Mask GetMask() const
Get the network mask.
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope() const
Get address scope.
Ipv4Address GetLocal() const
Get the local address.
bool IsSecondary() const
Check if the address is a secondary address.
Ipv4Address GetBroadcast() const
Get the broadcast address.
The IPv4 representation of a network interface.
void SetNode(Ptr< Node > node)
Set node associated with interface.
Ptr< NetDevice > GetDevice() const
bool IsEntire() const
If all fragments have been added.
Ptr< Packet > GetPartialPacket() const
Get the complete part of the packet.
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
Ptr< Packet > GetPacket() const
Get the entire packet.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
Implement the IPv4 layer.
std::tuple< uint64_t, uint8_t, Ipv4Address, Ipv4Address > DupTuple_t
IETF RFC 6621, Section 6.2 de-duplication w/o IPSec RFC 6621 recommended duplicate packet tuple: {IPV...
void CallTxTrace(const Ipv4Header &ipHeader, Ptr< Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Make a copy of the packet, add the header and invoke the TX trace callback.
@ DROP_NO_ROUTE
No route to host.
@ DROP_TTL_EXPIRED
Packet TTL has expired.
@ DROP_ROUTE_ERROR
Route error.
@ DROP_FRAGMENT_TIMEOUT
Fragment timeout exceeded.
void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Decrease the identification value for a dropped or recursed packet.
Ipv4InterfaceList m_interfaces
List of IPv4 interfaces.
void DeleteRawSocket(Ptr< Socket > socket) override
Deletes a particular raw socket.
MapFragments_t m_fragments
Fragmented packets.
void LocalDeliver(Ptr< const Packet > p, const Ipv4Header &ip, uint32_t iif)
Deliver a packet.
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override
Determine whether address and interface corresponding to received packet can be accepted for local de...
std::pair< uint64_t, uint32_t > FragmentKey_t
Key identifying a fragmented packet.
Time m_expire
duplicate entry expiration delay
bool m_strongEndSystemModel
Strong End System Model state.
Ipv4RoutingProtocol::ErrorCallback m_ecb
Error callback.
bool m_ipForward
Forwarding packets (i.e.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Lower layer calls this method after calling L3Demux::Lookup The ARP subclass needs to know from which...
void SetUp(uint32_t i) override
uint32_t GetNInterfaces() const override
Ipv4Header BuildHeader(Ipv4Address source, Ipv4Address destination, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, uint8_t tos, bool mayFragment)
Construct an IPv4 header.
void RouteInputError(Ptr< const Packet > p, const Ipv4Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.
void SetMetric(uint32_t i, uint16_t metric) override
void DoDispose() override
Destructor implementation.
void Remove(Ptr< IpL4Protocol > protocol) override
void SetIpForward(bool forward) override
Set or unset the IP forwarding state.
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
bool IsUnicast(Ipv4Address ad) const
Check if an IPv4 address is unicast according to the node.
void HandleFragmentsTimeout(FragmentKey_t key, Ipv4Header &ipHeader, uint32_t iif)
Process the timeout for packet fragments.
uint16_t GetMtu(uint32_t i) const override
Ptr< Icmpv4L4Protocol > GetIcmp() const
Get ICMPv4 protocol.
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const override
static constexpr uint16_t PROT_NUMBER
Protocol number.
void RemoveDuplicates()
Remove expired duplicates packet entry.
void DoFragmentation(Ptr< Packet > packet, const Ipv4Header &ipv4Header, uint32_t outIfaceMtu, std::list< Ipv4PayloadHeaderPair > &listFragments)
Fragment a packet.
SocketList m_sockets
List of IPv4 raw sockets.
bool m_enableDpd
Enable multicast duplicate packet detection.
std::map< std::pair< uint64_t, uint8_t >, uint16_t > m_identification
Identification (for each {src, dst, proto} tuple)
bool IsUp(uint32_t i) const override
Time m_fragmentExpirationTimeout
Expiration timeout.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
EventId m_timeoutEvent
Event for the next scheduled timeout.
int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
Time m_purge
time between purging expired duplicate entries
void SetNode(Ptr< Node > node)
Set node associated with this stack.
void IpMulticastForward(Ptr< Ipv4MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a multicast packet.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_rxTrace
Trace of received packets.
uint16_t GetMetric(uint32_t i) const override
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_txTrace
Trace of transmitted packets.
Ptr< Socket > CreateRawSocket() override
Creates a raw socket.
bool ProcessFragment(Ptr< Packet > &packet, Ipv4Header &ipHeader, uint32_t iif)
Process a packet fragment.
static TypeId GetTypeId()
Get the type ID.
Ipv4RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
void HandleTimeout()
Handles a fragmented packet timeout.
Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override
Choose the source address to use with destination address.
void NotifyNewAggregate() override
This function will notify other components connected to the node that a new stack member is now conne...
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
uint32_t AddInterface(Ptr< NetDevice > device) override
EventId m_cleanDpd
event to cleanup expired duplicate entries
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route) override
bool IsForwarding(uint32_t i) const override
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route) override
Ptr< NetDevice > GetNetDevice(uint32_t i) override
L4List_t m_protocols
List of transport protocol.
uint32_t GetNAddresses(uint32_t interface) const override
void SetDown(uint32_t i) override
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol) override
Register a new routing protocol to be used by this Ipv4 stack.
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const override
Get the routing protocol to be used by this Ipv4 stack.
Ptr< Ipv4RoutingProtocol > m_routingProtocol
Routing protocol associated with the stack.
Ipv4RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_multicastForwardTrace
Trace of multicast forwarded packets.
bool GetStrongEndSystemModel() const override
Get the Strong End System Model status.
uint8_t m_defaultTtl
Default TTL.
DupMap_t m_dups
map of packet duplicate tuples to expiry event
void SendRealOut(Ptr< Ipv4Route > route, Ptr< Packet > packet, const Ipv4Header &ipHeader)
Send packet with route.
Ptr< Node > m_node
Node attached to stack.
bool UpdateDuplicate(Ptr< const Packet > p, const Ipv4Header &header)
Registers duplicate entry, return false if new.
Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope) override
Return the first primary source address with scope less than or equal to the requested scope,...
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override
Remove the address at addressIndex on named interface.
Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
int32_t GetInterfaceForAddress(Ipv4Address addr) const override
Return the interface number of the interface that has been assigned the specified IP address.
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get an interface.
void IpForward(Ptr< Ipv4Route > rtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a packet.
void SetForwarding(uint32_t i, bool val) override
std::list< std::tuple< Time, FragmentKey_t, Ipv4Header, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts..
void SetupLoopback()
Setup loopback interface.
void SetStrongEndSystemModel(bool model) override
Set or unset the Strong End System Model.
void SetDefaultTtl(uint8_t ttl)
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const override
Ipv4RoutingProtocol::LocalDeliverCallback m_lcb
Local delivery callback.
void Insert(Ptr< IpL4Protocol > protocol) override
TracedCallback< const Ipv4Header &, Ptr< const Packet >, DropReason, Ptr< Ipv4 >, uint32_t > m_dropTrace
Trace of dropped packets.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, Ipv4Header ipHeader, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
bool GetIpForward() const override
Get the IP forwarding state.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv4 L4 keys: protocol number, interface index.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Add an IPv4 interface to the stack.
a class to represent an Ipv4 address mask
static Ipv4Mask GetLoopback()
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition node.cc:124
uint32_t GetNDevices() const
Definition node.cc:147
uint32_t GetId() const
Definition node.cc:106
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition node.cc:138
static bool ChecksumEnabled()
Definition node.cc:267
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition node.cc:220
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition object.cc:412
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.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:561
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
Definition socket.cc:388
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
indicates whether the socket has IP_TOS set.
Definition socket.h:1260
uint8_t GetTos() const
Get the tag's TOS.
Definition socket.cc:793
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition socket.h:1113
uint8_t GetTtl() const
Get the tag's TTL.
Definition socket.cc:600
indicates whether the socket has a priority set.
Definition socket.h:1307
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition socket.cc:843
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
bool IsStrictlyPositive() const
Exactly equivalent to t > 0.
Definition nstime.h:342
AttributeValue implementation for Time.
Definition nstime.h:1456
The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructu...
virtual void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called by NetDevices, incoming packet.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#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
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition boolean.h:70
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition nstime.h:1457
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1477
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
uint32_t Hash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer, using the default hash function.
Definition hash.h:265
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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 Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1369
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1381
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:448
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:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585
-ns3 Test suite for the ns3 wrapper script