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/iana-ieee802-numbers.h"
23#include "ns3/ipv4-address.h"
24#include "ns3/log.h"
25#include "ns3/net-device.h"
26#include "ns3/node.h"
27#include "ns3/object-vector.h"
28#include "ns3/packet.h"
29#include "ns3/socket.h"
30#include "ns3/string.h"
31#include "ns3/trace-source-accessor.h"
32#include "ns3/traffic-control-layer.h"
33#include "ns3/uinteger.h"
34
35namespace ns3
36{
37
38NS_LOG_COMPONENT_DEFINE("Ipv4L3Protocol");
39
41
44{
45 static TypeId tid =
46 TypeId("ns3::Ipv4L3Protocol")
47 .SetParent<Ipv4>()
48 .SetGroupName("Internet")
49 .AddConstructor<Ipv4L3Protocol>()
50 .AddAttribute("DefaultTtl",
51 "The TTL value set by default on "
52 "all outgoing packets generated on this node.",
53 UintegerValue(64),
56 .AddAttribute("FragmentExpirationTimeout",
57 "When this timeout expires, the fragments "
58 "will be cleared from the buffer.",
59 TimeValue(Seconds(30)),
62 .AddAttribute("EnableDuplicatePacketDetection",
63 "Enable multicast duplicate packet detection based on RFC 6621",
64 BooleanValue(false),
67 .AddAttribute("DuplicateExpire",
68 "Expiration delay for duplicate cache entries",
72 .AddAttribute("PurgeExpiredPeriod",
73 "Time between purges of expired duplicate packet entries, "
74 "0 means never purge",
78 .AddTraceSource("Tx",
79 "Send ipv4 packet to outgoing interface.",
81 "ns3::Ipv4L3Protocol::TxRxTracedCallback")
82 .AddTraceSource("Rx",
83 "Receive ipv4 packet from incoming interface.",
85 "ns3::Ipv4L3Protocol::TxRxTracedCallback")
86 .AddTraceSource("Drop",
87 "Drop ipv4 packet",
89 "ns3::Ipv4L3Protocol::DropTracedCallback")
90 .AddAttribute("InterfaceList",
91 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
95
96 .AddTraceSource("SendOutgoing",
97 "A newly-generated packet by this node is "
98 "about to be queued for transmission",
100 "ns3::Ipv4L3Protocol::SentTracedCallback")
101 .AddTraceSource("UnicastForward",
102 "A unicast IPv4 packet was received by this node "
103 "and is being forwarded to another node",
105 "ns3::Ipv4L3Protocol::SentTracedCallback")
106 .AddTraceSource("MulticastForward",
107 "A multicast IPv4 packet was received by this node "
108 "and is being forwarded to another node",
110 "ns3::Ipv4L3Protocol::SentTracedCallback")
111 .AddTraceSource("LocalDeliver",
112 "An IPv4 packet was received by/for this node, "
113 "and it is being forward up the stack",
115 "ns3::Ipv4L3Protocol::SentTracedCallback")
116
117 ;
118 return tid;
119}
120
129
134
135void
137{
138 NS_LOG_FUNCTION(this << protocol);
139 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
140 if (m_protocols.find(key) != m_protocols.end())
141 {
142 NS_LOG_WARN("Overwriting default protocol " << int(protocol->GetProtocolNumber()));
143 }
144 m_protocols[key] = protocol;
145}
146
147void
149{
150 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
151
152 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
153 if (m_protocols.find(key) != m_protocols.end())
154 {
155 NS_LOG_WARN("Overwriting protocol " << int(protocol->GetProtocolNumber())
156 << " on interface " << int(interfaceIndex));
157 }
158 m_protocols[key] = protocol;
159}
160
161void
163{
164 NS_LOG_FUNCTION(this << protocol);
165
166 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
167 auto iter = m_protocols.find(key);
168 if (iter == m_protocols.end())
169 {
170 NS_LOG_WARN("Trying to remove an non-existent default protocol "
171 << int(protocol->GetProtocolNumber()));
172 }
173 else
174 {
175 m_protocols.erase(key);
176 }
177}
178
179void
181{
182 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
183
184 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
185 auto iter = m_protocols.find(key);
186 if (iter == m_protocols.end())
187 {
188 NS_LOG_WARN("Trying to remove an non-existent protocol "
189 << int(protocol->GetProtocolNumber()) << " on interface "
190 << int(interfaceIndex));
191 }
192 else
193 {
194 m_protocols.erase(key);
195 }
196}
197
199Ipv4L3Protocol::GetProtocol(int protocolNumber) const
200{
201 return GetProtocol(protocolNumber, -1);
202}
203
205Ipv4L3Protocol::GetProtocol(int protocolNumber, int32_t interfaceIndex) const
206{
207 if (interfaceIndex >= 0)
208 {
209 // try the interface-specific protocol.
210 auto key = std::make_pair(protocolNumber, interfaceIndex);
211 auto i = m_protocols.find(key);
212 if (i != m_protocols.end())
213 {
214 return i->second;
215 }
216 }
217 // try the generic protocol.
218 auto key = std::make_pair(protocolNumber, -1);
219 auto i = m_protocols.find(key);
220 if (i != m_protocols.end())
221 {
222 return i->second;
223 }
224
225 return nullptr;
226}
227
228void
230{
231 NS_LOG_FUNCTION(this << node);
232 m_node = node;
233 // Add a LoopbackNetDevice if needed, and an Ipv4Interface on top of it
235}
236
239{
240 NS_LOG_FUNCTION(this);
242 socket->SetNode(m_node);
243 m_sockets.push_back(socket);
244 return socket;
245}
246
247void
249{
250 NS_LOG_FUNCTION(this << socket);
251 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
252 {
253 if ((*i) == socket)
254 {
255 m_sockets.erase(i);
256 return;
257 }
258 }
259}
260
261/*
262 * This method is called by AggregateObject and completes the aggregation
263 * by setting the node in the ipv4 stack
264 */
265void
267{
268 NS_LOG_FUNCTION(this);
269 if (!m_node)
270 {
271 Ptr<Node> node = this->GetObject<Node>();
272 // verify that it's a valid node and that
273 // the node has not been set before
274 if (node)
275 {
276 this->SetNode(node);
277 }
278 }
280}
281
282void
284{
285 NS_LOG_FUNCTION(this << routingProtocol);
286 m_routingProtocol = routingProtocol;
287 m_routingProtocol->SetIpv4(this);
288}
289
295
296void
298{
299 NS_LOG_FUNCTION(this);
300 for (auto i = m_protocols.begin(); i != m_protocols.end(); ++i)
301 {
302 i->second = nullptr;
303 }
304 m_protocols.clear();
305
306 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); ++i)
307 {
308 *i = nullptr;
309 }
310 m_interfaces.clear();
312
313 m_sockets.clear();
314 m_node = nullptr;
315 m_routingProtocol = nullptr;
316
317 for (auto it = m_fragments.begin(); it != m_fragments.end(); it++)
318 {
319 it->second = nullptr;
320 }
321
322 m_fragments.clear();
323 m_timeoutEventList.clear();
324 if (m_timeoutEvent.IsPending())
325 {
326 m_timeoutEvent.Cancel();
327 }
328
329 if (m_cleanDpd.IsPending())
330 {
331 m_cleanDpd.Cancel();
332 }
333 m_dups.clear();
334
336}
337
338void
340{
341 NS_LOG_FUNCTION(this);
342
344 Ptr<LoopbackNetDevice> device = nullptr;
345 // First check whether an existing LoopbackNetDevice exists on the node
346 for (uint32_t i = 0; i < m_node->GetNDevices(); i++)
347 {
348 if ((device = DynamicCast<LoopbackNetDevice>(m_node->GetDevice(i))))
349 {
350 break;
351 }
352 }
353 if (!device)
354 {
356 m_node->AddDevice(device);
357 }
358 interface->SetDevice(device);
359 interface->SetNode(m_node);
360 Ipv4InterfaceAddress ifaceAddr =
362 interface->AddAddress(ifaceAddr);
363 uint32_t index = AddIpv4Interface(interface);
364 Ptr<Node> node = GetObject<Node>();
365 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3Protocol::Receive, this),
367 device);
368 interface->SetUp();
370 {
371 m_routingProtocol->NotifyInterfaceUp(index);
372 }
373}
374
375void
377{
378 NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
379 m_defaultTtl = ttl;
380}
381
384{
385 NS_LOG_FUNCTION(this << device);
387
389
390 NS_ASSERT(tc);
391
392 m_node->RegisterProtocolHandler(MakeCallback(&TrafficControlLayer::Receive, tc),
394 device);
395 m_node->RegisterProtocolHandler(MakeCallback(&TrafficControlLayer::Receive, tc),
397 device);
398
399 tc->RegisterProtocolHandler(MakeCallback(&Ipv4L3Protocol::Receive, this),
401 device);
402 tc->RegisterProtocolHandler(
405 device);
406
408 interface->SetNode(m_node);
409 interface->SetDevice(device);
410 interface->SetTrafficControl(tc);
411 interface->SetForwarding(m_ipForward);
412 return AddIpv4Interface(interface);
413}
414
417{
418 NS_LOG_FUNCTION(this << interface);
419 uint32_t index = m_interfaces.size();
420 m_interfaces.push_back(interface);
421 m_reverseInterfacesContainer[interface->GetDevice()] = index;
422 return index;
423}
424
427{
428 if (index < m_interfaces.size())
429 {
430 return m_interfaces[index];
431 }
432 return nullptr;
433}
434
437{
438 return m_interfaces.size();
439}
440
443{
444 int32_t interface = 0;
445 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
446 {
447 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
448 {
449 if ((*i)->GetAddress(j).GetLocal() == address)
450 {
451 return interface;
452 }
453 }
454 }
455
456 return -1;
457}
458
461{
462 int32_t interface = 0;
463 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
464 {
465 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
466 {
467 if ((*i)->GetAddress(j).GetLocal().CombineMask(mask) == address.CombineMask(mask))
468 {
469 return interface;
470 }
471 }
472 }
473
474 return -1;
475}
476
479{
480 auto iter = m_reverseInterfacesContainer.find(device);
481 if (iter != m_reverseInterfacesContainer.end())
482 {
483 return (*iter).second;
484 }
485
486 return -1;
487}
488
489bool
491{
492 // First check the incoming interface for a unicast address match
493 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
494 {
495 Ipv4InterfaceAddress iaddr = GetAddress(iif, i);
496 if (address == iaddr.GetLocal())
497 {
498 NS_LOG_LOGIC("For me (destination " << address << " match)");
499 return true;
500 }
501 if (address == iaddr.GetBroadcast())
502 {
503 NS_LOG_LOGIC("For me (interface broadcast address)");
504 return true;
505 }
506 }
507
508 if (address.IsMulticast())
509 {
510#ifdef NOTYET
511 if (MulticastCheckGroup(iif, address))
512#endif
513 {
514 NS_LOG_LOGIC("For me (Ipv4Addr multicast address)");
515 return true;
516 }
517 }
518
519 if (address.IsBroadcast())
520 {
521 NS_LOG_LOGIC("For me (Ipv4Addr broadcast address)");
522 return true;
523 }
524
525 if (!GetStrongEndSystemModel()) // Check other interfaces
526 {
527 for (uint32_t j = 0; j < GetNInterfaces(); j++)
528 {
529 if (j == uint32_t(iif))
530 {
531 continue;
532 }
533 for (uint32_t i = 0; i < GetNAddresses(j); i++)
534 {
535 Ipv4InterfaceAddress iaddr = GetAddress(j, i);
536 if (address == iaddr.GetLocal())
537 {
538 NS_LOG_LOGIC("For me (destination " << address
539 << " match) on another interface");
540 return true;
541 }
542 // This is a small corner case: match another interface's broadcast address
543 if (address == iaddr.GetBroadcast())
544 {
545 NS_LOG_LOGIC("For me (interface broadcast address on another interface)");
546 return true;
547 }
548 }
549 }
550 }
551 return false;
552}
553
554void
557 uint16_t protocol,
558 const Address& from,
559 const Address& to,
560 NetDevice::PacketType packetType)
561{
562 NS_LOG_FUNCTION(this << device << p << protocol << from << to << packetType);
563
564 NS_LOG_LOGIC("Packet from " << from << " received on node " << m_node->GetId());
565
566 int32_t interface = GetInterfaceForDevice(device);
567 NS_ASSERT_MSG(interface != -1, "Received a packet from an interface that is not known to IPv4");
568
569 Ptr<Packet> packet = p->Copy();
570
571 Ptr<Ipv4Interface> ipv4Interface = m_interfaces[interface];
572
573 if (ipv4Interface->IsUp())
574 {
575 m_rxTrace(packet, this, interface);
576 }
577 else
578 {
579 NS_LOG_LOGIC("Dropping received packet -- interface is down");
580 Ipv4Header ipHeader;
581 packet->RemoveHeader(ipHeader);
582 m_dropTrace(ipHeader, packet, DROP_INTERFACE_DOWN, this, interface);
583 return;
584 }
585
586 Ipv4Header ipHeader;
588 {
589 ipHeader.EnableChecksum();
590 }
591 packet->RemoveHeader(ipHeader);
592
593 // Trim any residual frame padding from underlying devices
594 if (ipHeader.GetPayloadSize() < packet->GetSize())
595 {
596 packet->RemoveAtEnd(packet->GetSize() - ipHeader.GetPayloadSize());
597 }
598
599 if (!ipHeader.IsChecksumOk())
600 {
601 NS_LOG_LOGIC("Dropping received packet -- checksum not ok");
602 m_dropTrace(ipHeader, packet, DROP_BAD_CHECKSUM, this, interface);
603 return;
604 }
605
606 // the packet is valid, we update the ARP cache entry (if present)
607 Ptr<ArpCache> arpCache = ipv4Interface->GetArpCache();
608 if (arpCache)
609 {
610 // case one, it's a a direct routing.
611 ArpCache::Entry* entry = arpCache->Lookup(ipHeader.GetSource());
612 if (entry)
613 {
614 if (entry->IsAlive())
615 {
616 entry->UpdateSeen();
617 }
618 }
619 else
620 {
621 // It's not in the direct routing, so it's the router, and it could have multiple IP
622 // addresses. In doubt, update all of them. Note: it's a confirmed behavior for Linux
623 // routers.
624 std::list<ArpCache::Entry*> entryList = arpCache->LookupInverse(from);
625 for (auto iter = entryList.begin(); iter != entryList.end(); iter++)
626 {
627 if ((*iter)->IsAlive())
628 {
629 (*iter)->UpdateSeen();
630 }
631 }
632 }
633 }
634
635 if (m_enableDpd && ipHeader.GetDestination().IsMulticast() && UpdateDuplicate(packet, ipHeader))
636 {
637 NS_LOG_LOGIC("Dropping received packet -- duplicate.");
638 m_dropTrace(ipHeader, packet, DROP_DUPLICATE, this, interface);
639 return;
640 }
641
642 NS_ASSERT_MSG(m_routingProtocol, "Need a routing protocol object to process packets");
643 if (!m_routingProtocol->RouteInput(packet, ipHeader, device, m_ucb, m_mcb, m_lcb, m_ecb))
644 {
645 NS_LOG_WARN("No route found for forwarding packet. Drop.");
646 m_dropTrace(ipHeader, packet, DROP_NO_ROUTE, this, interface);
647 SendIcmpNoRoute(ipHeader, packet);
648 }
649}
650
651void
653{
654 NS_LOG_FUNCTION(this << ipHeader << packet);
655 // @RFC{1812} sec 4.3.2.7 / 5.2.7.1: a router that cannot forward a datagram
656 // because it has no route to the destination network must return an ICMP
657 // Destination Unreachable (net unreachable) message to the source (see @issueid{825}).
658 // Only a node configured as a forwarder (router) generates this message, and
659 // never in response to a datagram with a multicast or broadcast destination.
660 if (!m_ipForward || ipHeader.GetDestination().IsMulticast() ||
662 {
663 return;
664 }
666 if (icmp)
667 {
668 icmp->SendDestUnreachNetwork(ipHeader, packet);
669 }
670}
671
674{
676 if (prot)
677 {
678 return prot->GetObject<Icmpv4L4Protocol>();
679 }
680 else
681 {
682 return nullptr;
683 }
684}
685
686bool
688{
689 if (ad.IsBroadcast() || ad.IsMulticast())
690 {
691 return false;
692 }
693 else
694 {
695 // check for subnet-broadcast
696 for (uint32_t ifaceIndex = 0; ifaceIndex < GetNInterfaces(); ifaceIndex++)
697 {
698 for (uint32_t j = 0; j < GetNAddresses(ifaceIndex); j++)
699 {
700 Ipv4InterfaceAddress ifAddr = GetAddress(ifaceIndex, j);
701 NS_LOG_LOGIC("Testing address " << ad << " with subnet-directed broadcast "
702 << ifAddr.GetBroadcast());
703 if (ad == ifAddr.GetBroadcast())
704 {
705 return false;
706 }
707 }
708 }
709 }
710
711 return true;
712}
713
714bool
716{
717 return !ad.IsMulticast() && !ad.IsSubnetDirectedBroadcast(interfaceMask);
718}
719
720void
722{
723 NS_LOG_FUNCTION(this << packet << ipHeader << route);
725 {
726 ipHeader.EnableChecksum();
727 }
728 SendRealOut(route, packet, ipHeader);
729}
730
731void
733 Ptr<Packet> packet,
734 Ptr<Ipv4> ipv4,
735 uint32_t interface)
736{
737 if (!m_txTrace.IsEmpty())
738 {
739 Ptr<Packet> packetCopy = packet->Copy();
740 packetCopy->AddHeader(ipHeader);
741 m_txTrace(packetCopy, ipv4, interface);
742 }
743}
744
745void
747 Ipv4Address source,
748 Ipv4Address destination,
749 uint8_t protocol,
750 Ptr<Ipv4Route> route)
751{
752 NS_LOG_FUNCTION(this << packet << source << destination << uint32_t(protocol) << route);
753
754 bool mayFragment = true;
755
756 // we need a copy of the packet with its tags in case we need to invoke recursion.
757 Ptr<Packet> pktCopyWithTags = packet->Copy();
758
759 uint8_t ttl = m_defaultTtl;
760 SocketIpTtlTag ipTtlTag;
761 bool ipTtlTagFound = packet->RemovePacketTag(ipTtlTag);
762 if (ipTtlTagFound)
763 {
764 ttl = ipTtlTag.GetTtl();
765 }
766
767 uint8_t tos = 0;
768 SocketIpTosTag ipTosTag;
769 bool ipTosTagFound = packet->RemovePacketTag(ipTosTag);
770 if (ipTosTagFound)
771 {
772 tos = ipTosTag.GetTos();
773 }
774
775 // can construct the header here
776 Ipv4Header ipHeader =
777 BuildHeader(source, destination, protocol, packet->GetSize(), ttl, tos, mayFragment);
778
779 // Handle a few cases:
780 // 1) packet is passed in with a route entry
781 // 2) packet is passed without a route and packet is destined to limited broadcast address
782 // 3) packet is passed without a route and packet is destined to a subnet-directed broadcast
783 // address 4) packet is passed without a route, packet is not broadcast (e.g., a raw socket
784 // call, or ICMP)
785
786 // 1) packet is passed in with route entry
787 if (route)
788 {
789 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 1b: passed in with route and valid gateway");
790 int32_t interface = GetInterfaceForDevice(route->GetOutputDevice());
791 m_sendOutgoingTrace(ipHeader, packet, interface);
792 if (m_enableDpd && ipHeader.GetDestination().IsMulticast())
793 {
794 UpdateDuplicate(packet, ipHeader);
795 }
796 SendRealOut(route, packet->Copy(), ipHeader);
797 return;
798 }
799
800 // 2) packet is destined to limited broadcast address or link-local multicast address
801 if (destination.IsBroadcast() || destination.IsLocalMulticast())
802 {
803 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 2: limited broadcast - no route");
804 for (auto ifaceIter = m_interfaces.begin(); ifaceIter != m_interfaces.end(); ++ifaceIter)
805 {
806 Ptr<Ipv4Interface> outInterface = *ifaceIter;
807 // ANY source matches any interface
808 bool sendIt = source.IsAny();
809 // check if some specific address on outInterface matches
810 for (uint32_t index = 0; !sendIt && index < outInterface->GetNAddresses(); index++)
811 {
812 if (outInterface->GetAddress(index).GetLocal() == source)
813 {
814 sendIt = true;
815 }
816 }
817
818 if (sendIt)
819 {
820 // create a proxy route for this interface
822 route->SetDestination(destination);
823 route->SetGateway(Ipv4Address::GetAny());
824 route->SetSource(source);
825 route->SetOutputDevice(outInterface->GetDevice());
826 DecreaseIdentification(source, destination, protocol);
827 Send(pktCopyWithTags, source, destination, protocol, route);
828 }
829 }
830 return;
831 }
832
833 // 3) check: packet is destined to a subnet-directed broadcast address
834 for (auto ifaceIter = m_interfaces.begin(); ifaceIter != m_interfaces.end(); ifaceIter++)
835 {
836 Ptr<Ipv4Interface> outInterface = *ifaceIter;
837 uint32_t ifaceIndex = GetInterfaceForDevice(outInterface->GetDevice());
838 for (uint32_t j = 0; j < GetNAddresses(ifaceIndex); j++)
839 {
840 Ipv4InterfaceAddress ifAddr = GetAddress(ifaceIndex, j);
841 NS_LOG_LOGIC("Testing address " << ifAddr.GetLocal() << " with mask "
842 << ifAddr.GetMask());
843 if (destination.IsSubnetDirectedBroadcast(ifAddr.GetMask()) &&
844 destination.CombineMask(ifAddr.GetMask()) ==
845 ifAddr.GetLocal().CombineMask(ifAddr.GetMask()))
846 {
847 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 3: subnet directed bcast to "
848 << ifAddr.GetLocal() << " - no route");
849 // create a proxy route for this interface
851 route->SetDestination(destination);
852 route->SetGateway(Ipv4Address::GetAny());
853 route->SetSource(source);
854 route->SetOutputDevice(outInterface->GetDevice());
855 DecreaseIdentification(source, destination, protocol);
856 Send(pktCopyWithTags, source, destination, protocol, route);
857 return;
858 }
859 }
860 }
861
862 // 4) packet is not broadcast, and route is NULL (e.g., a raw socket call)
863 NS_LOG_LOGIC("Ipv4L3Protocol::Send case 4: not broadcast and passed in with no route "
864 << destination);
865 Socket::SocketErrno errno_;
866 Ptr<NetDevice> oif(nullptr); // unused for now
867 Ptr<Ipv4Route> newRoute;
869 {
870 newRoute = m_routingProtocol->RouteOutput(pktCopyWithTags, ipHeader, oif, errno_);
871 }
872 else
873 {
874 NS_LOG_ERROR("Ipv4L3Protocol::Send: m_routingProtocol == 0");
875 }
876 if (newRoute)
877 {
878 DecreaseIdentification(source, destination, protocol);
879 Send(pktCopyWithTags, source, destination, protocol, newRoute);
880 }
881 else
882 {
883 NS_LOG_WARN("No route to host. Drop.");
884 m_dropTrace(ipHeader, packet, DROP_NO_ROUTE, this, 0);
885 DecreaseIdentification(source, destination, protocol);
886 }
887}
888
889void
891 Ipv4Address destination,
892 uint8_t protocol)
893{
894 uint64_t src = source.Get();
895 uint64_t dst = destination.Get();
896 uint64_t srcDst = dst | (src << 32);
897 std::pair<uint64_t, uint8_t> key = std::make_pair(srcDst, protocol);
898 m_identification[key]--;
899}
900
903 Ipv4Address destination,
904 uint8_t protocol,
905 uint16_t payloadSize,
906 uint8_t ttl,
907 uint8_t tos,
908 bool mayFragment)
909{
910 NS_LOG_FUNCTION(this << source << destination << (uint16_t)protocol << payloadSize
911 << (uint16_t)ttl << (uint16_t)tos << mayFragment);
912 Ipv4Header ipHeader;
913 ipHeader.SetSource(source);
914 ipHeader.SetDestination(destination);
915 ipHeader.SetProtocol(protocol);
916 ipHeader.SetPayloadSize(payloadSize);
917 ipHeader.SetTtl(ttl);
918 ipHeader.SetTos(tos);
919
920 uint64_t src = source.Get();
921 uint64_t dst = destination.Get();
922 uint64_t srcDst = dst | (src << 32);
923 std::pair<uint64_t, uint8_t> key = std::make_pair(srcDst, protocol);
924
925 if (mayFragment)
926 {
927 ipHeader.SetMayFragment();
928 ipHeader.SetIdentification(m_identification[key]);
929 m_identification[key]++;
930 }
931 else
932 {
933 ipHeader.SetDontFragment();
934 // RFC 6864 does not state anything about atomic datagrams
935 // identification requirement:
936 // >> Originating sources MAY set the IPv4 ID field of atomic datagrams
937 // to any value.
938 ipHeader.SetIdentification(m_identification[key]);
939 m_identification[key]++;
940 }
942 {
943 ipHeader.EnableChecksum();
944 }
945 return ipHeader;
946}
947
948void
950{
951 NS_LOG_FUNCTION(this << route << packet << &ipHeader);
952 if (!route)
953 {
954 NS_LOG_WARN("No route to host. Drop.");
955 m_dropTrace(ipHeader, packet, DROP_NO_ROUTE, this, 0);
956 return;
957 }
958 Ptr<NetDevice> outDev = route->GetOutputDevice();
959 int32_t interface = GetInterfaceForDevice(outDev);
960 NS_ASSERT(interface >= 0);
961 Ptr<Ipv4Interface> outInterface = GetInterface(interface);
962 NS_LOG_LOGIC("Send via NetDevice ifIndex " << outDev->GetIfIndex() << " ipv4InterfaceIndex "
963 << interface);
964
965 Ipv4Address target;
966 std::string targetLabel;
967 if (route->GetGateway().IsAny())
968 {
969 target = ipHeader.GetDestination();
970 targetLabel = "destination";
971 }
972 else
973 {
974 target = route->GetGateway();
975 targetLabel = "gateway";
976 }
977
978 if (outInterface->IsUp())
979 {
980 NS_LOG_LOGIC("Send to " << targetLabel << " " << target);
981 if (packet->GetSize() + ipHeader.GetSerializedSize() > outInterface->GetDevice()->GetMtu())
982 {
983 std::list<Ipv4PayloadHeaderPair> listFragments;
984 DoFragmentation(packet, ipHeader, outInterface->GetDevice()->GetMtu(), listFragments);
985 for (auto it = listFragments.begin(); it != listFragments.end(); it++)
986 {
987 NS_LOG_LOGIC("Sending fragment " << *(it->first));
988 CallTxTrace(it->second, it->first, this, interface);
989 outInterface->Send(it->first, it->second, target);
990 }
991 }
992 else
993 {
994 CallTxTrace(ipHeader, packet, this, interface);
995 outInterface->Send(packet, ipHeader, target);
996 }
997 }
998}
999
1000// This function analogous to Linux ip_mr_forward()
1001void
1004 const Ipv4Header& header)
1005{
1006 NS_LOG_FUNCTION(this << mrtentry << p << header);
1007 NS_LOG_LOGIC("Multicast forwarding logic for node: " << m_node->GetId());
1008
1009 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap();
1010
1011 for (auto mapIter = ttlMap.begin(); mapIter != ttlMap.end(); mapIter++)
1012 {
1013 uint32_t interface = mapIter->first;
1014 // uint32_t outputTtl = mapIter->second; // Unused for now
1015
1016 Ptr<Packet> packet = p->Copy();
1017 Ipv4Header ipHeader = header;
1018 if (ipHeader.GetTtl() <= 1)
1019 {
1020 NS_LOG_WARN("TTL exceeded. Drop.");
1021 m_dropTrace(header, packet, DROP_TTL_EXPIRED, this, interface);
1022 return;
1023 }
1024 ipHeader.SetTtl(header.GetTtl() - 1);
1025 NS_LOG_LOGIC("Forward multicast via interface " << interface);
1027 rtentry->SetSource(ipHeader.GetSource());
1028 rtentry->SetDestination(ipHeader.GetDestination());
1029 rtentry->SetGateway(Ipv4Address::GetAny());
1030 rtentry->SetOutputDevice(GetNetDevice(interface));
1031
1032 m_multicastForwardTrace(ipHeader, packet, interface);
1033 SendRealOut(rtentry, packet, ipHeader);
1034 }
1035}
1036
1037// This function analogous to Linux ip_forward()
1038void
1040{
1041 NS_LOG_FUNCTION(this << rtentry << p << header);
1042 NS_LOG_LOGIC("Forwarding logic for node: " << m_node->GetId());
1043 // Forwarding
1044 Ipv4Header ipHeader = header;
1045 Ptr<Packet> packet = p->Copy();
1046 int32_t interface = GetInterfaceForDevice(rtentry->GetOutputDevice());
1047 if (ipHeader.GetTtl() <= 1)
1048 {
1049 // Do not reply to multicast/broadcast IP address
1050 if (!ipHeader.GetDestination().IsBroadcast() && !ipHeader.GetDestination().IsMulticast())
1051 {
1052 Ptr<Icmpv4L4Protocol> icmp = GetIcmp();
1053 icmp->SendTimeExceededTtl(ipHeader, packet, false);
1054 }
1055 NS_LOG_WARN("TTL exceeded. Drop.");
1056 m_dropTrace(header, packet, DROP_TTL_EXPIRED, this, interface);
1057 return;
1058 }
1059 ipHeader.SetTtl(ipHeader.GetTtl() - 1);
1060 // in case the packet still has a priority tag attached, remove it
1061 SocketPriorityTag priorityTag;
1062 packet->RemovePacketTag(priorityTag);
1063 uint8_t priority = Socket::IpTos2Priority(ipHeader.GetTos());
1064 // add a priority tag if the priority is not null
1065 if (priority)
1066 {
1067 priorityTag.SetPriority(priority);
1068 packet->AddPacketTag(priorityTag);
1069 }
1070
1071 m_unicastForwardTrace(ipHeader, packet, interface);
1072 SendRealOut(rtentry, packet, ipHeader);
1073}
1074
1075void
1077{
1078 NS_LOG_FUNCTION(this << packet << &ip << iif);
1079 Ptr<Packet> p = packet->Copy(); // need to pass a non-const packet up
1080 Ipv4Header ipHeader = ip;
1081
1082 if (!ipHeader.IsLastFragment() || ipHeader.GetFragmentOffset() != 0)
1083 {
1084 NS_LOG_LOGIC("Received a fragment, processing " << *p);
1085 bool isPacketComplete;
1086 isPacketComplete = ProcessFragment(p, ipHeader, iif);
1087 if (!isPacketComplete)
1088 {
1089 return;
1090 }
1091 NS_LOG_LOGIC("Got last fragment, Packet is complete " << *p);
1092 ipHeader.SetFragmentOffset(0);
1093 ipHeader.SetPayloadSize(p->GetSize());
1094 }
1095
1096 m_localDeliverTrace(ipHeader, p, iif);
1097
1098 Ptr<Ipv4Interface> ipv4Interface = GetInterface(iif);
1099
1100 for (auto& socket : m_sockets)
1101 {
1102 NS_LOG_INFO("Delivering to raw socket " << socket);
1103 socket->ForwardUp(p, ipHeader, ipv4Interface);
1104 }
1105
1106 Ptr<IpL4Protocol> protocol = GetProtocol(ipHeader.GetProtocol(), iif);
1107 if (protocol)
1108 {
1109 // we need to make a copy in the unlikely event we hit the
1110 // RX_ENDPOINT_UNREACH codepath
1111 Ptr<Packet> copy = p->Copy();
1112 IpL4Protocol::RxStatus status = protocol->Receive(p, ipHeader, GetInterface(iif));
1113 switch (status)
1114 {
1116 // fall through
1118 // fall through
1120 break;
1122 if (ipHeader.GetDestination().IsBroadcast() || ipHeader.GetDestination().IsMulticast())
1123 {
1124 break; // Do not reply to broadcast or multicast
1125 }
1126 // Another case to suppress ICMP is a subnet-directed broadcast
1127 bool subnetDirected = false;
1128 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
1129 {
1130 Ipv4InterfaceAddress addr = GetAddress(iif, i);
1131 if (addr.GetLocal().CombineMask(addr.GetMask()) ==
1132 ipHeader.GetDestination().CombineMask(addr.GetMask()) &&
1134 {
1135 subnetDirected = true;
1136 }
1137 }
1138 if (!subnetDirected)
1139 {
1140 GetIcmp()->SendDestUnreachPort(ipHeader, copy);
1141 }
1142 }
1143 }
1144}
1145
1146bool
1148{
1149 NS_LOG_FUNCTION(this << i << address);
1150 Ptr<Ipv4Interface> interface = GetInterface(i);
1151 bool retVal = interface->AddAddress(address);
1153 {
1154 m_routingProtocol->NotifyAddAddress(i, address);
1155 }
1156 return retVal;
1157}
1158
1160Ipv4L3Protocol::GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
1161{
1162 Ptr<Ipv4Interface> interface = GetInterface(interfaceIndex);
1163 return interface->GetAddress(addressIndex);
1164}
1165
1168{
1169 Ptr<Ipv4Interface> iface = GetInterface(interface);
1170 return iface->GetNAddresses();
1171}
1172
1173bool
1175{
1176 NS_LOG_FUNCTION(this << i << addressIndex);
1177 Ptr<Ipv4Interface> interface = GetInterface(i);
1178 Ipv4InterfaceAddress address = interface->RemoveAddress(addressIndex);
1179 if (address != Ipv4InterfaceAddress())
1180 {
1182 {
1183 m_routingProtocol->NotifyRemoveAddress(i, address);
1184 }
1185 return true;
1186 }
1187 return false;
1188}
1189
1190bool
1192{
1193 NS_LOG_FUNCTION(this << i << address);
1194
1195 if (address == Ipv4Address::GetLoopback())
1196 {
1197 NS_LOG_WARN("Cannot remove loopback address.");
1198 return false;
1199 }
1200 Ptr<Ipv4Interface> interface = GetInterface(i);
1201 Ipv4InterfaceAddress ifAddr = interface->RemoveAddress(address);
1202 if (ifAddr != Ipv4InterfaceAddress())
1203 {
1205 {
1206 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
1207 }
1208 return true;
1209 }
1210 return false;
1211}
1212
1215{
1216 NS_LOG_FUNCTION(this << interfaceIdx << " " << dest);
1217 if (GetNAddresses(interfaceIdx) == 1) // common case
1218 {
1219 return GetAddress(interfaceIdx, 0).GetLocal();
1220 }
1221 // no way to determine the scope of the destination, so adopt the
1222 // following rule: pick the first available address (index 0) unless
1223 // a subsequent address is on link (in which case, pick the primary
1224 // address if there are multiple)
1225 Ipv4Address candidate = GetAddress(interfaceIdx, 0).GetLocal();
1226 for (uint32_t i = 0; i < GetNAddresses(interfaceIdx); i++)
1227 {
1228 Ipv4InterfaceAddress test = GetAddress(interfaceIdx, i);
1229 if (test.GetLocal().CombineMask(test.GetMask()) == dest.CombineMask(test.GetMask()))
1230 {
1231 return test.GetLocal();
1232 }
1233 }
1234 return candidate;
1235}
1236
1239 Ipv4Address dst,
1241{
1242 NS_LOG_FUNCTION(this << device << dst << scope);
1243 Ipv4Address addr("0.0.0.0");
1245 bool found = false;
1246
1247 if (device)
1248 {
1249 int32_t i = GetInterfaceForDevice(device);
1250 NS_ASSERT_MSG(i >= 0, "No device found on node");
1251 for (uint32_t j = 0; j < GetNAddresses(i); j++)
1252 {
1253 iaddr = GetAddress(i, j);
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.GetScope() != Ipv4InterfaceAddress::LINK && iaddr.GetScope() <= scope)
1281 {
1282 return iaddr.GetLocal();
1283 }
1284 }
1285 }
1286 NS_LOG_WARN("Could not find source address for " << dst << " and scope " << scope
1287 << ", returning 0");
1288 return addr;
1289}
1290
1291void
1293{
1294 NS_LOG_FUNCTION(this << i << metric);
1295 Ptr<Ipv4Interface> interface = GetInterface(i);
1296 interface->SetMetric(metric);
1297}
1298
1299uint16_t
1301{
1302 Ptr<Ipv4Interface> interface = GetInterface(i);
1303 return interface->GetMetric();
1304}
1305
1306uint16_t
1308{
1309 Ptr<Ipv4Interface> interface = GetInterface(i);
1310 return interface->GetDevice()->GetMtu();
1311}
1312
1313bool
1315{
1316 Ptr<Ipv4Interface> interface = GetInterface(i);
1317 return interface->IsUp();
1318}
1319
1320void
1322{
1323 NS_LOG_FUNCTION(this << i);
1324 Ptr<Ipv4Interface> interface = GetInterface(i);
1325
1326 // RFC 791, pg.25:
1327 // Every internet module must be able to forward a datagram of 68
1328 // octets without further fragmentation. This is because an internet
1329 // header may be up to 60 octets, and the minimum fragment is 8 octets.
1330 if (interface->GetDevice()->GetMtu() >= 68)
1331 {
1332 interface->SetUp();
1333
1335 {
1336 m_routingProtocol->NotifyInterfaceUp(i);
1337 }
1338 }
1339 else
1340 {
1342 "Interface "
1343 << int(i)
1344 << " is set to be down for IPv4. Reason: not respecting minimum IPv4 MTU (68 octets)");
1345 }
1346}
1347
1348void
1350{
1351 NS_LOG_FUNCTION(this << ifaceIndex);
1352 Ptr<Ipv4Interface> interface = GetInterface(ifaceIndex);
1353 interface->SetDown();
1354
1356 {
1357 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
1358 }
1359}
1360
1361bool
1363{
1364 Ptr<Ipv4Interface> interface = GetInterface(i);
1365 NS_LOG_LOGIC("Forwarding state: " << interface->IsForwarding());
1366 return interface->IsForwarding();
1367}
1368
1369void
1371{
1372 NS_LOG_FUNCTION(this << i);
1373 Ptr<Ipv4Interface> interface = GetInterface(i);
1374 interface->SetForwarding(val);
1375}
1376
1379{
1380 return GetInterface(i)->GetDevice();
1381}
1382
1383void
1385{
1386 NS_LOG_FUNCTION(this << forward);
1387 m_ipForward = forward;
1388 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++)
1389 {
1390 (*i)->SetForwarding(forward);
1391 }
1392}
1393
1394bool
1396{
1397 return m_ipForward;
1398}
1399
1400void
1402{
1403 NS_LOG_FUNCTION(this << model);
1404 m_strongEndSystemModel = model;
1405}
1406
1407bool
1412
1413void
1415 const Ipv4Header& ipHeader,
1416 Socket::SocketErrno sockErrno)
1417{
1418 NS_LOG_FUNCTION(this << p << ipHeader << sockErrno);
1419 NS_LOG_LOGIC("Route input failure-- dropping packet to " << ipHeader << " with errno "
1420 << sockErrno);
1421 m_dropTrace(ipHeader, p, DROP_ROUTE_ERROR, this, 0);
1422
1423 // Return an ICMP net-unreachable to the source on a routing failure (see @issueid{825}).
1424 SendIcmpNoRoute(ipHeader, p);
1425}
1426
1427void
1429 const Ipv4Header& ipv4Header,
1430 uint32_t outIfaceMtu,
1431 std::list<Ipv4PayloadHeaderPair>& listFragments)
1432{
1433 // BEWARE: here we do assume that the header options are not present.
1434 // a much more complex handling is necessary in case there are options.
1435 // If (when) IPv4 option headers will be implemented, the following code shall be changed.
1436 // Of course also the reassembly code shall be changed as well.
1437
1438 NS_LOG_FUNCTION(this << *packet << outIfaceMtu << &listFragments);
1439
1440 Ptr<Packet> p = packet->Copy();
1441
1442 NS_ASSERT_MSG((ipv4Header.GetSerializedSize() == 5 * 4),
1443 "IPv4 fragmentation implementation only works without option headers.");
1444
1445 uint16_t offset = 0;
1446 bool moreFragment = true;
1447 uint16_t originalOffset = ipv4Header.GetFragmentOffset();
1448 bool isLastFragment = ipv4Header.IsLastFragment();
1449 uint32_t currentFragmentablePartSize = 0;
1450
1451 // IPv4 fragments are all 8 bytes aligned but the last.
1452 // The IP payload size is:
1453 // floor( ( outIfaceMtu - ipv4Header.GetSerializedSize() ) /8 ) *8
1454 uint32_t fragmentSize = (outIfaceMtu - ipv4Header.GetSerializedSize()) & ~uint32_t(0x7);
1455
1456 NS_LOG_LOGIC("Fragmenting - Target Size: " << fragmentSize);
1457
1458 do
1459 {
1460 Ipv4Header fragmentHeader = ipv4Header;
1461
1462 if (p->GetSize() > offset + fragmentSize)
1463 {
1464 moreFragment = true;
1465 currentFragmentablePartSize = fragmentSize;
1466 fragmentHeader.SetMoreFragments();
1467 }
1468 else
1469 {
1470 moreFragment = false;
1471 currentFragmentablePartSize = p->GetSize() - offset;
1472 if (!isLastFragment)
1473 {
1474 fragmentHeader.SetMoreFragments();
1475 }
1476 else
1477 {
1478 fragmentHeader.SetLastFragment();
1479 }
1480 }
1481
1482 NS_LOG_LOGIC("Fragment creation - " << offset << ", " << currentFragmentablePartSize);
1483 Ptr<Packet> fragment = p->CreateFragment(offset, currentFragmentablePartSize);
1484 NS_LOG_LOGIC("Fragment created - " << offset << ", " << fragment->GetSize());
1485
1486 fragmentHeader.SetFragmentOffset(offset + originalOffset);
1487 fragmentHeader.SetPayloadSize(currentFragmentablePartSize);
1488
1490 {
1491 fragmentHeader.EnableChecksum();
1492 }
1493
1494 NS_LOG_LOGIC("Fragment check - " << fragmentHeader.GetFragmentOffset());
1495
1496 NS_LOG_LOGIC("New fragment Header " << fragmentHeader);
1497
1498 std::ostringstream oss;
1499 oss << fragmentHeader;
1500 fragment->Print(oss);
1501
1502 NS_LOG_LOGIC("New fragment " << *fragment);
1503
1504 listFragments.emplace_back(fragment, fragmentHeader);
1505
1506 offset += currentFragmentablePartSize;
1507
1508 } while (moreFragment);
1509}
1510
1511bool
1513{
1514 NS_LOG_FUNCTION(this << packet << ipHeader << iif);
1515
1516 uint64_t addressCombination =
1517 uint64_t(ipHeader.GetSource().Get()) << 32 | uint64_t(ipHeader.GetDestination().Get());
1518 uint32_t idProto =
1519 uint32_t(ipHeader.GetIdentification()) << 16 | uint32_t(ipHeader.GetProtocol());
1520 FragmentKey_t key;
1521 bool ret = false;
1522 Ptr<Packet> p = packet->Copy();
1523
1524 key.first = addressCombination;
1525 key.second = idProto;
1526
1527 std::shared_ptr<Fragments> fragments;
1528
1529 auto it = m_fragments.find(key);
1530 if (it == m_fragments.end())
1531 {
1532 fragments = std::make_shared<Fragments>();
1533 m_fragments.insert(std::make_pair(key, fragments));
1534
1535 auto iter = SetTimeout(key, ipHeader, iif);
1536 fragments->SetTimeoutIter(iter);
1537 }
1538 else
1539 {
1540 fragments = it->second;
1541 }
1542
1543 NS_LOG_LOGIC("Adding fragment - Size: " << packet->GetSize()
1544 << " - Offset: " << (ipHeader.GetFragmentOffset()));
1545
1546 fragments->AddFragment(p, ipHeader.GetFragmentOffset(), !ipHeader.IsLastFragment());
1547
1548 if (fragments->IsEntire())
1549 {
1550 packet = fragments->GetPacket();
1551 m_timeoutEventList.erase(fragments->GetTimeoutIter());
1552 fragments = nullptr;
1553 m_fragments.erase(key);
1554 ret = true;
1555 }
1556
1557 return ret;
1558}
1559
1565
1566void
1568 uint16_t fragmentOffset,
1569 bool moreFragment)
1570{
1571 NS_LOG_FUNCTION(this << fragment << fragmentOffset << moreFragment);
1572
1573 std::list<std::pair<Ptr<Packet>, uint16_t>>::iterator it;
1574
1575 for (it = m_fragments.begin(); it != m_fragments.end(); it++)
1576 {
1577 if (it->second > fragmentOffset)
1578 {
1579 break;
1580 }
1581 }
1582
1583 if (it == m_fragments.end())
1584 {
1585 m_moreFragment = moreFragment;
1586 }
1587
1588 m_fragments.insert(it, std::pair<Ptr<Packet>, uint16_t>(fragment, fragmentOffset));
1589}
1590
1591bool
1593{
1594 NS_LOG_FUNCTION(this);
1595
1596 bool ret = !m_moreFragment && !m_fragments.empty();
1597
1598 if (ret)
1599 {
1600 uint16_t lastEndOffset = 0;
1601
1602 for (auto it = m_fragments.begin(); it != m_fragments.end(); it++)
1603 {
1604 // overlapping fragments do exist
1605 NS_LOG_LOGIC("Checking overlaps " << lastEndOffset << " - " << it->second);
1606
1607 if (lastEndOffset < it->second)
1608 {
1609 ret = false;
1610 break;
1611 }
1612 // fragments might overlap in strange ways
1613 uint16_t fragmentEnd = it->first->GetSize() + it->second;
1614 lastEndOffset = std::max(lastEndOffset, fragmentEnd);
1615 }
1616 }
1617
1618 return ret;
1619}
1620
1623{
1624 NS_LOG_FUNCTION(this);
1625
1626 auto it = m_fragments.begin();
1627
1628 Ptr<Packet> p = it->first->Copy();
1629 uint16_t lastEndOffset = p->GetSize();
1630 it++;
1631
1632 for (; it != m_fragments.end(); it++)
1633 {
1634 if (lastEndOffset > it->second)
1635 {
1636 // The fragments are overlapping.
1637 // We do not overwrite the "old" with the "new" because we do not know when each
1638 // arrived. This is different from what Linux does. It is not possible to emulate a
1639 // fragmentation attack.
1640 uint32_t newStart = lastEndOffset - it->second;
1641 if (it->first->GetSize() > newStart)
1642 {
1643 uint32_t newSize = it->first->GetSize() - newStart;
1644 Ptr<Packet> tempFragment = it->first->CreateFragment(newStart, newSize);
1645 p->AddAtEnd(tempFragment);
1646 }
1647 }
1648 else
1649 {
1650 NS_LOG_LOGIC("Adding: " << *(it->first));
1651 p->AddAtEnd(it->first);
1652 }
1653 lastEndOffset = p->GetSize();
1654 }
1655
1656 return p;
1657}
1658
1661{
1662 NS_LOG_FUNCTION(this);
1663
1664 auto it = m_fragments.begin();
1665
1667 uint16_t lastEndOffset = 0;
1668
1669 if (m_fragments.begin()->second > 0)
1670 {
1671 return p;
1672 }
1673
1674 for (it = m_fragments.begin(); it != m_fragments.end(); it++)
1675 {
1676 if (lastEndOffset > it->second)
1677 {
1678 uint32_t newStart = lastEndOffset - it->second;
1679 uint32_t newSize = it->first->GetSize() - newStart;
1680 Ptr<Packet> tempFragment = it->first->CreateFragment(newStart, newSize);
1681 p->AddAtEnd(tempFragment);
1682 }
1683 else if (lastEndOffset == it->second)
1684 {
1685 NS_LOG_LOGIC("Adding: " << *(it->first));
1686 p->AddAtEnd(it->first);
1687 }
1688 lastEndOffset = p->GetSize();
1689 }
1690
1691 return p;
1692}
1693
1694void
1699
1705
1706void
1708{
1709 NS_LOG_FUNCTION(this << &key << &ipHeader << iif);
1710
1711 auto it = m_fragments.find(key);
1712 Ptr<Packet> packet = it->second->GetPartialPacket();
1713
1714 // if we have at least 8 bytes, we can send an ICMP.
1715 if (packet->GetSize() > 8)
1716 {
1718 icmp->SendTimeExceededTtl(ipHeader, packet, true);
1719 }
1720 m_dropTrace(ipHeader, packet, DROP_FRAGMENT_TIMEOUT, this, iif);
1721
1722 // clear the buffers
1723 it->second = nullptr;
1724
1725 m_fragments.erase(key);
1726}
1727
1728bool
1730{
1731 NS_LOG_FUNCTION(this << p << header);
1732
1733 // \todo RFC 6621 mandates SHA-1 hash. For now ns3 hash should be fine.
1734 uint8_t proto = header.GetProtocol();
1735 Ipv4Address src = header.GetSource();
1736 Ipv4Address dst = header.GetDestination();
1737 uint64_t id = header.GetIdentification();
1738
1739 // concat hash value onto id
1740 uint64_t hash = id << 32;
1741 if (header.GetFragmentOffset() || !header.IsLastFragment())
1742 {
1743 // use I-DPD (RFC 6621, Sec 6.2.1)
1744 hash |= header.GetFragmentOffset();
1745 }
1746 else
1747 {
1748 // use H-DPD (RFC 6621, Sec 6.2.2)
1749
1750 // serialize packet
1751 Ptr<Packet> pkt = p->Copy();
1752 pkt->AddHeader(header);
1753
1754 std::ostringstream oss(std::ios_base::binary);
1755 pkt->CopyData(&oss, pkt->GetSize());
1756 std::string bytes = oss.str();
1757
1758 NS_ASSERT_MSG(bytes.size() >= 20, "Degenerate header serialization");
1759
1760 // zero out mutable fields
1761 bytes[1] = 0; // DSCP / ECN
1762 bytes[6] = bytes[7] = 0; // Flags / Fragment offset
1763 bytes[8] = 0; // TTL
1764 bytes[10] = bytes[11] = 0; // Header checksum
1765 if (header.GetSerializedSize() > 20) // assume options should be 0'd
1766 {
1767 std::fill_n(bytes.begin() + 20, header.GetSerializedSize() - 20, 0);
1768 }
1769
1770 // concat hash onto ID
1771 hash |= (uint64_t)Hash32(bytes);
1772 }
1773
1774 // set cleanup job for new duplicate entries
1775 if (!m_cleanDpd.IsPending() && m_purge.IsStrictlyPositive())
1776 {
1778 }
1779
1780 // assume this is a new entry
1781 DupTuple_t key{hash, proto, src, dst};
1782 NS_LOG_DEBUG("Packet " << p->GetUid() << " key = (" << std::hex << std::get<0>(key) << ", "
1783 << std::dec << +std::get<1>(key) << ", " << std::get<2>(key) << ", "
1784 << std::get<3>(key) << ")");
1785
1786 // place a new entry, on collision the existing entry iterator is returned
1787 auto [iter, inserted] = m_dups.emplace(key, Seconds(0));
1788 bool isDup = !inserted && iter->second > Simulator::Now();
1789
1790 // set the expiration event
1791 iter->second = Simulator::Now() + m_expire;
1792 return isDup;
1793}
1794
1795void
1797{
1798 NS_LOG_FUNCTION(this);
1799
1800 DupMap_t::size_type n = 0;
1801 Time expire = Simulator::Now();
1802 auto iter = m_dups.cbegin();
1803 while (iter != m_dups.cend())
1804 {
1805 if (iter->second < expire)
1806 {
1807 NS_LOG_LOGIC("Remove key = (" << std::hex << std::get<0>(iter->first) << ", "
1808 << std::dec << +std::get<1>(iter->first) << ", "
1809 << std::get<2>(iter->first) << ", "
1810 << std::get<3>(iter->first) << ")");
1811 iter = m_dups.erase(iter);
1812 ++n;
1813 }
1814 else
1815 {
1816 ++iter;
1817 }
1818 }
1819
1820 NS_LOG_DEBUG("Purged " << n << " expired duplicate entries out of " << (n + m_dups.size()));
1821
1822 // keep cleaning up if necessary
1823 if (!m_dups.empty() && m_purge.IsStrictlyPositive())
1824 {
1826 }
1827}
1828
1831{
1833
1834 if (m_timeoutEventList.empty())
1835 {
1838 }
1839 m_timeoutEventList.emplace_back(now, key, ipHeader, iif);
1840
1841 auto iter = --m_timeoutEventList.end();
1842
1843 return iter;
1844}
1845
1846void
1848{
1849 Time now = Simulator::Now();
1850
1851 while (!m_timeoutEventList.empty() && std::get<0>(*m_timeoutEventList.begin()) == now)
1852 {
1853 HandleFragmentsTimeout(std::get<1>(*m_timeoutEventList.begin()),
1854 std::get<2>(*m_timeoutEventList.begin()),
1855 std::get<3>(*m_timeoutEventList.begin()));
1856 m_timeoutEventList.pop_front();
1857 }
1858
1859 if (m_timeoutEventList.empty())
1860 {
1861 return;
1862 }
1863
1864 Time difference = std::get<0>(*m_timeoutEventList.begin()) - now;
1866}
1867
1868} // namespace ns3
a polymophic address class
Definition address.h:114
A record that that holds information about an ArpCache entry.
Definition arp-cache.h:178
bool IsAlive()
Definition arp-cache.cc:400
void UpdateSeen()
Update the entry when seeing a packet.
Definition arp-cache.cc:583
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
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.
static Ipv4Address GetBroadcast()
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.
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)
Ipv4()
Definition ipv4.cc:57
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.
Ipv4Address GetBroadcast() const
Get the broadcast address.
The IPv4 representation of a network interface.
void SetNode(Ptr< Node > node)
Set node associated with interface.
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.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current fragments.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
bool m_moreFragment
True if other fragments will be sent.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
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_BAD_CHECKSUM
Bad checksum.
@ DROP_NO_ROUTE
No route to host.
@ DROP_INTERFACE_DOWN
Interface is down so can not send packet.
@ DROP_DUPLICATE
Duplicate packet received.
@ 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
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.
void SendIcmpNoRoute(const Ipv4Header &ipHeader, Ptr< const Packet > packet)
Return an ICMP Destination Unreachable (net unreachable) to the source of a datagram that this router...
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:314
static bool ChecksumEnabled()
Definition node.cc:267
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition object.cc:410
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:518
virtual void DoDispose()
Destructor implementation.
Definition object.cc:431
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
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:1261
uint8_t GetTos() const
Get the tag's TOS.
Definition socket.cc:795
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition socket.h:1114
uint8_t GetTtl() const
Get the tag's TTL.
Definition socket.cc:601
indicates whether the socket has a priority set.
Definition socket.h:1308
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition socket.cc:845
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
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:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
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:76
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:690
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:253
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:281
#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:260
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:274
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#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:492
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition first.py:1
constexpr uint16_t ARP
ARP EtherType [RFC1700].
constexpr uint16_t IPV4
IPv4 EtherType [RFC894].
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:501
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1416
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1436
-ns3 Test suite for the ns3 wrapper script