A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-l3-click-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// Author: Lalith Suresh <suresh.lalith@gmail.com>
8//
9
11
12#include "ipv4-click-routing.h"
13
14#include "ns3/arp-l3-protocol.h"
15#include "ns3/ethernet-header.h"
16#include "ns3/icmpv4-l4-protocol.h"
17#include "ns3/ip-l4-protocol.h"
18#include "ns3/ipv4-raw-socket-impl.h"
19#include "ns3/llc-snap-header.h"
20#include "ns3/loopback-net-device.h"
21#include "ns3/net-device.h"
22#include "ns3/node.h"
23#include "ns3/object-vector.h"
24#include "ns3/socket.h"
25#include "ns3/uinteger.h"
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("Ipv4L3ClickProtocol");
31
32const uint16_t Ipv4L3ClickProtocol::PROT_NUMBER = 0x0800;
33
34NS_OBJECT_ENSURE_REGISTERED(Ipv4L3ClickProtocol);
35
36TypeId
38{
39 static TypeId tid =
40 TypeId("ns3::Ipv4L3ClickProtocol")
41 .SetParent<Ipv4>()
42 .AddConstructor<Ipv4L3ClickProtocol>()
43 .SetGroupName("Click")
44 .AddAttribute(
45 "DefaultTtl",
46 "The TTL value set by default on all outgoing packets generated on this node.",
47 UintegerValue(64),
50 .AddAttribute("InterfaceList",
51 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
55 return tid;
56}
57
59 : m_identification(0)
60{
61}
62
66
67void
69{
70 NS_LOG_FUNCTION(this);
71 for (auto i = m_protocols.begin(); i != m_protocols.end(); ++i)
72 {
73 i->second = nullptr;
74 }
75 m_protocols.clear();
76
77 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); ++i)
78 {
79 *i = nullptr;
80 }
81 m_interfaces.clear();
83
84 m_sockets.clear();
85 m_node = nullptr;
86 m_routingProtocol = nullptr;
88}
89
90void
92{
93 if (!m_node)
94 {
95 Ptr<Node> node = this->GetObject<Node>();
96 // verify that it's a valid node and that
97 // the node has not been set before
98 if (node)
99 {
100 this->SetNode(node);
101 }
102 }
104}
105
106void
108{
109 NS_LOG_FUNCTION(this);
110 m_routingProtocol = routingProtocol;
111 m_routingProtocol->SetIpv4(this);
112}
113
119
122{
123 NS_LOG_FUNCTION(this << index);
124 if (index < m_interfaces.size())
125 {
126 return m_interfaces[index];
127 }
128 return nullptr;
129}
130
137
140{
141 NS_LOG_FUNCTION(this << address);
142
143 int32_t interface = 0;
144 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
145 {
146 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
147 {
148 if ((*i)->GetAddress(j).GetLocal() == address)
149 {
150 return interface;
151 }
152 }
153 }
154
155 return -1;
156}
157
160{
161 NS_LOG_FUNCTION(this << address << mask);
162
163 int32_t interface = 0;
164 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
165 {
166 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
167 {
168 if ((*i)->GetAddress(j).GetLocal().CombineMask(mask) == address.CombineMask(mask))
169 {
170 return interface;
171 }
172 }
173 }
174
175 return -1;
176}
177
180{
181 NS_LOG_FUNCTION(this << device->GetIfIndex());
182
183 auto iter = m_reverseInterfacesContainer.find(device);
184 if (iter != m_reverseInterfacesContainer.end())
185 {
186 return (*iter).second;
187 }
188
189 return -1;
190}
191
192bool
194{
195 NS_LOG_FUNCTION(this << address << " " << iif);
196
197 // First check the incoming interface for a unicast address match
198 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
199 {
200 Ipv4InterfaceAddress iaddr = GetAddress(iif, i);
201 if (address == iaddr.GetLocal())
202 {
203 NS_LOG_LOGIC("For me (destination " << address << " match)");
204 return true;
205 }
206 if (address == iaddr.GetBroadcast())
207 {
208 NS_LOG_LOGIC("For me (interface broadcast address)");
209 return true;
210 }
211 }
212
213 if (address.IsMulticast())
214 {
215#ifdef NOTYET
216 if (MulticastCheckGroup(iif, address))
217#endif
218 {
219 NS_LOG_LOGIC("For me (Ipv4Addr multicast address");
220 return true;
221 }
222 }
223
224 if (address.IsBroadcast())
225 {
226 NS_LOG_LOGIC("For me (Ipv4Addr broadcast address)");
227 return true;
228 }
229
230 if (!GetStrongEndSystemModel()) // Check other interfaces
231 {
232 for (uint32_t j = 0; j < GetNInterfaces(); j++)
233 {
234 if (j == uint32_t(iif))
235 {
236 continue;
237 }
238 for (uint32_t i = 0; i < GetNAddresses(j); i++)
239 {
240 Ipv4InterfaceAddress iaddr = GetAddress(j, i);
241 if (address == iaddr.GetLocal())
242 {
243 NS_LOG_LOGIC("For me (destination " << address
244 << " match) on another interface");
245 return true;
246 }
247 // This is a small corner case: match another interface's broadcast address
248 if (address == iaddr.GetBroadcast())
249 {
250 NS_LOG_LOGIC("For me (interface broadcast address on another interface)");
251 return true;
252 }
253 }
254 }
255 }
256 return false;
257}
258
259void
261{
262 NS_LOG_FUNCTION(this << forward);
263 m_ipForward = forward;
264 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++)
265 {
266 (*i)->SetForwarding(forward);
267 }
268}
269
270bool
272{
273 return m_ipForward;
274}
275
276void
281
282bool
287
294
295void
301
302void
304{
306
308 Ptr<LoopbackNetDevice> device = nullptr;
309 // First check whether an existing LoopbackNetDevice exists on the node
310 for (uint32_t i = 0; i < m_node->GetNDevices(); i++)
311 {
313 {
314 break;
315 }
316 }
317 if (!device)
318 {
320 m_node->AddDevice(device);
321 }
322 interface->SetDevice(device);
323 interface->SetNode(m_node);
324 Ipv4InterfaceAddress ifaceAddr =
326 interface->AddAddress(ifaceAddr);
327 uint32_t index = AddIpv4Interface(interface);
328 Ptr<Node> node = GetObject<Node>();
329 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
331 device);
332 interface->SetUp();
334 {
335 m_routingProtocol->NotifyInterfaceUp(index);
336 }
337}
338
341{
342 NS_LOG_FUNCTION(this);
344 socket->SetNode(m_node);
345 m_sockets.push_back(socket);
346 return socket;
347}
348
349void
351{
352 NS_LOG_FUNCTION(this << socket);
353 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
354 {
355 if ((*i) == socket)
356 {
357 m_sockets.erase(i);
358 return;
359 }
360 }
361}
362
363void
365{
366 m_node = node;
367 // Add a LoopbackNetDevice if needed, and an Ipv4Interface on top of it
369}
370
371bool
373{
374 NS_LOG_FUNCTION(this << i << address);
375 Ptr<Ipv4Interface> interface = GetInterface(i);
376 bool retVal = interface->AddAddress(address);
377 if (m_routingProtocol)
378 {
379 m_routingProtocol->NotifyAddAddress(i, address);
380 }
381 return retVal;
382}
383
385Ipv4L3ClickProtocol::GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
386{
387 NS_LOG_FUNCTION(this << interfaceIndex << addressIndex);
388 Ptr<Ipv4Interface> interface = GetInterface(interfaceIndex);
389 return interface->GetAddress(addressIndex);
390}
391
394{
395 NS_LOG_FUNCTION(this << interface);
396 Ptr<Ipv4Interface> iface = GetInterface(interface);
397 return iface->GetNAddresses();
398}
399
400bool
402{
403 NS_LOG_FUNCTION(this << i << addressIndex);
404 Ptr<Ipv4Interface> interface = GetInterface(i);
405 Ipv4InterfaceAddress address = interface->RemoveAddress(addressIndex);
406 if (address != Ipv4InterfaceAddress())
407 {
408 if (m_routingProtocol)
409 {
410 m_routingProtocol->NotifyRemoveAddress(i, address);
411 }
412 return true;
413 }
414 return false;
415}
416
417bool
419{
420 NS_LOG_FUNCTION(this << i << address);
421
422 if (address == Ipv4Address::GetLoopback())
423 {
424 NS_LOG_WARN("Cannot remove loopback address.");
425 return false;
426 }
427 Ptr<Ipv4Interface> interface = GetInterface(i);
428 Ipv4InterfaceAddress ifAddr = interface->RemoveAddress(address);
429 if (ifAddr != Ipv4InterfaceAddress())
430 {
431 if (m_routingProtocol)
432 {
433 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
434 }
435 return true;
436 }
437 return false;
438}
439
442{
443 NS_LOG_FUNCTION(this << interfaceIdx << " " << dest);
444 if (GetNAddresses(interfaceIdx) == 1) // common case
445 {
446 return GetAddress(interfaceIdx, 0).GetLocal();
447 }
448 // no way to determine the scope of the destination, so adopt the
449 // following rule: pick the first available address (index 0) unless
450 // a subsequent address is on link (in which case, pick the primary
451 // address if there are multiple)
452 Ipv4Address candidate = GetAddress(interfaceIdx, 0).GetLocal();
453 for (uint32_t i = 0; i < GetNAddresses(interfaceIdx); i++)
454 {
455 Ipv4InterfaceAddress test = GetAddress(interfaceIdx, i);
456 if (test.GetLocal().CombineMask(test.GetMask()) == dest.CombineMask(test.GetMask()))
457 {
458 if (!test.IsSecondary())
459 {
460 return test.GetLocal();
461 }
462 }
463 }
464 return candidate;
465}
466
469 Ipv4Address dst,
471{
472 NS_LOG_FUNCTION(device << dst << scope);
473 Ipv4Address addr("0.0.0.0");
475 bool found = false;
476
477 if (device)
478 {
479 int32_t i = GetInterfaceForDevice(device);
480 NS_ASSERT_MSG(i >= 0, "No device found on node");
481 for (uint32_t j = 0; j < GetNAddresses(i); j++)
482 {
483 iaddr = GetAddress(i, j);
484 if (iaddr.IsSecondary())
485 {
486 continue;
487 }
488 if (iaddr.GetScope() > scope)
489 {
490 continue;
491 }
492 if (dst.CombineMask(iaddr.GetMask()) == iaddr.GetLocal().CombineMask(iaddr.GetMask()))
493 {
494 return iaddr.GetLocal();
495 }
496 if (!found)
497 {
498 addr = iaddr.GetLocal();
499 found = true;
500 }
501 }
502 }
503 if (found)
504 {
505 return addr;
506 }
507
508 // Iterate among all interfaces
509 for (uint32_t i = 0; i < GetNInterfaces(); i++)
510 {
511 for (uint32_t j = 0; j < GetNAddresses(i); j++)
512 {
513 iaddr = GetAddress(i, j);
514 if (iaddr.IsSecondary())
515 {
516 continue;
517 }
518 if (iaddr.GetScope() != Ipv4InterfaceAddress::LINK && iaddr.GetScope() <= scope)
519 {
520 return iaddr.GetLocal();
521 }
522 }
523 }
524 NS_LOG_WARN("Could not find source address for " << dst << " and scope " << scope
525 << ", returning 0");
526 return addr;
527}
528
529void
531{
532 NS_LOG_FUNCTION(i << metric);
533 Ptr<Ipv4Interface> interface = GetInterface(i);
534 interface->SetMetric(metric);
535}
536
537uint16_t
539{
541 Ptr<Ipv4Interface> interface = GetInterface(i);
542 return interface->GetMetric();
543}
544
545uint16_t
547{
548 NS_LOG_FUNCTION(this << i);
549 Ptr<Ipv4Interface> interface = GetInterface(i);
550 return interface->GetDevice()->GetMtu();
551}
552
553bool
555{
556 NS_LOG_FUNCTION(this << i);
557 Ptr<Ipv4Interface> interface = GetInterface(i);
558 return interface->IsUp();
559}
560
561void
563{
564 NS_LOG_FUNCTION(this << i);
565 Ptr<Ipv4Interface> interface = GetInterface(i);
566 interface->SetUp();
567
568 if (m_routingProtocol)
569 {
570 m_routingProtocol->NotifyInterfaceUp(i);
571 }
572}
573
574void
576{
577 NS_LOG_FUNCTION(this << ifaceIndex);
578 Ptr<Ipv4Interface> interface = GetInterface(ifaceIndex);
579 interface->SetDown();
580
581 if (m_routingProtocol)
582 {
583 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
584 }
585}
586
587bool
589{
590 NS_LOG_FUNCTION(this << i);
591 Ptr<Ipv4Interface> interface = GetInterface(i);
592 NS_LOG_LOGIC("Forwarding state: " << interface->IsForwarding());
593 return interface->IsForwarding();
594}
595
596void
598{
599 NS_LOG_FUNCTION(this << i);
600 Ptr<Ipv4Interface> interface = GetInterface(i);
601 interface->SetForwarding(val);
602}
603
604void
606{
607 NS_ASSERT(i <= m_node->GetNDevices());
608 Ptr<NetDevice> netdev = GetNetDevice(i);
609 NS_ASSERT(netdev);
610 Ptr<Node> node = GetObject<Node>();
611 NS_ASSERT(node);
612 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
613 0,
614 netdev,
615 true);
616}
617
620{
621 NS_LOG_FUNCTION(this << &device);
622 Ptr<Node> node = GetObject<Node>();
623 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
625 device);
626 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
628 device);
629
631 interface->SetNode(m_node);
632 interface->SetDevice(device);
633 interface->SetForwarding(m_ipForward);
634 return AddIpv4Interface(interface);
635}
636
639{
640 NS_LOG_FUNCTION(this << interface);
641 uint32_t index = m_interfaces.size();
642 m_interfaces.push_back(interface);
643 m_reverseInterfacesContainer[interface->GetDevice()] = index;
644 return index;
645}
646
647/// @todo when should we set ip_id? check whether we are incrementing
648/// m_identification on packets that may later be dropped in this stack
649/// and whether that deviates from Linux
652 Ipv4Address destination,
653 uint8_t protocol,
654 uint16_t payloadSize,
655 uint8_t ttl,
656 bool mayFragment)
657{
659 Ipv4Header ipHeader;
660 ipHeader.SetSource(source);
661 ipHeader.SetDestination(destination);
662 ipHeader.SetProtocol(protocol);
663 ipHeader.SetPayloadSize(payloadSize);
664 ipHeader.SetTtl(ttl);
665 if (mayFragment)
666 {
667 ipHeader.SetMayFragment();
670 }
671 else
672 {
673 ipHeader.SetDontFragment();
674 // TBD: set to zero here; will cause traces to change
677 }
679 {
680 ipHeader.EnableChecksum();
681 }
682 return ipHeader;
683}
684
685void
687 Ipv4Address source,
688 Ipv4Address destination,
689 uint8_t protocol,
690 Ptr<Ipv4Route> route)
691{
692 NS_LOG_FUNCTION(this << packet << source << destination << uint32_t(protocol) << route);
693
694 Ipv4Header ipHeader;
695 bool mayFragment = true;
696 uint8_t ttl = m_defaultTtl;
697 SocketIpTtlTag tag;
698 bool found = packet->RemovePacketTag(tag);
699 if (found)
700 {
701 ttl = tag.GetTtl();
702 }
703
704 ipHeader = BuildHeader(source, destination, protocol, packet->GetSize(), ttl, mayFragment);
707 {
708 ipHeader.EnableChecksum();
709 }
710 packet->AddHeader(ipHeader);
711 click->Send(packet->Copy(), source, destination);
712}
713
714void
716{
717 NS_LOG_FUNCTION(this << packet << ipHeader << route);
718
721 {
722 ipHeader.EnableChecksum();
723 }
724 packet->AddHeader(ipHeader);
725 click->Send(packet->Copy(), ipHeader.GetSource(), ipHeader.GetDestination());
726}
727
728void
730{
731 // Called by Ipv4ClickRouting.
732
733 // NetDevice::Send () attaches ethernet headers,
734 // so the one that Click attaches isn't required
735 // but we need the destination address and
736 // protocol values from the header.
737
738 Ptr<NetDevice> netdev = GetNetDevice(ifid);
739
740 EthernetHeader header;
741 p->RemoveHeader(header);
742
743 uint16_t protocol;
744
745 if (header.GetLengthType() <= 1500)
746 {
747 LlcSnapHeader llc;
748 p->RemoveHeader(llc);
749 protocol = llc.GetType();
750 }
751 else
752 {
753 protocol = header.GetLengthType();
754 }
755
756 // Use the destination address and protocol obtained
757 // from above to send the packet.
758 netdev->Send(p, header.GetDestination(), protocol);
759}
760
761void
764 uint16_t protocol,
765 const Address& from,
766 const Address& to,
767 NetDevice::PacketType packetType)
768{
769 NS_LOG_FUNCTION(this << device << p << from << to);
770
771 NS_LOG_LOGIC("Packet from " << from << " received on node " << m_node->GetId());
772
773 // Forward packet to raw sockets, if any
774 if (protocol == Ipv4L3ClickProtocol::PROT_NUMBER && !m_sockets.empty())
775 {
776 Ptr<Packet> packetForRawSocket = p->Copy();
777 int32_t interface = GetInterfaceForDevice(device);
778 NS_ASSERT_MSG(interface != -1,
779 "Received a packet from an interface that is not known to IPv4");
780 Ptr<Ipv4Interface> ipv4Interface = m_interfaces[interface];
781 if (!ipv4Interface->IsUp())
782 {
783 NS_LOG_LOGIC("Dropping received packet -- interface is down");
784 return;
785 }
786
787 Ipv4Header ipHeader;
788 if (Node::ChecksumEnabled())
789 {
790 ipHeader.EnableChecksum();
791 }
792 packetForRawSocket->RemoveHeader(ipHeader);
793
794 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
795 {
796 NS_LOG_LOGIC("Forwarding to raw socket");
797 Ptr<Ipv4RawSocketImpl> socket = *i;
798 socket->ForwardUp(packetForRawSocket, ipHeader, ipv4Interface);
799 }
800 }
801
802 Ptr<Packet> packet = p->Copy();
803
804 // Add an ethernet frame. This allows
805 // Click to work with csma and wifi
806 EthernetHeader hdr;
809 hdr.SetLengthType(protocol);
810 packet->AddHeader(hdr);
811
813 click->Receive(packet->Copy(),
814 Mac48Address::ConvertFrom(device->GetAddress()),
816}
817
818void
820{
821 NS_LOG_FUNCTION(this << packet << &ip);
822 Ptr<Packet> p = packet->Copy(); // need to pass a non-const packet up
823
824 m_localDeliverTrace(ip, packet, iif);
825
827 if (protocol)
828 {
829 // we need to make a copy in the unlikely event we hit the
830 // RX_ENDPOINT_UNREACH codepath
831 Ptr<Packet> copy = p->Copy();
832 IpL4Protocol::RxStatus status = protocol->Receive(p, ip, GetInterface(iif));
833 switch (status)
834 {
836 // fall through
838 // fall through
840 break;
843 {
844 break; // Do not reply to broadcast or multicast
845 }
846 // Another case to suppress ICMP is a subnet-directed broadcast
847 bool subnetDirected = false;
848 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
849 {
850 Ipv4InterfaceAddress addr = GetAddress(iif, i);
851 if (addr.GetLocal().CombineMask(addr.GetMask()) ==
852 ip.GetDestination().CombineMask(addr.GetMask()) &&
854 {
855 subnetDirected = true;
856 }
857 }
858 if (!subnetDirected)
859 {
860 GetIcmp()->SendDestUnreachPort(ip, copy);
861 }
862 }
863 }
864}
865
868{
870 if (prot)
871 {
872 return prot->GetObject<Icmpv4L4Protocol>();
873 }
874 else
875 {
876 return nullptr;
877 }
878}
879
880void
882{
883 NS_LOG_FUNCTION(this << protocol);
884 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
885 if (m_protocols.find(key) != m_protocols.end())
886 {
887 NS_LOG_WARN("Overwriting default protocol " << int(protocol->GetProtocolNumber()));
888 }
889 m_protocols[key] = protocol;
890}
891
892void
894{
895 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
896
897 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
898 if (m_protocols.find(key) != m_protocols.end())
899 {
900 NS_LOG_WARN("Overwriting protocol " << int(protocol->GetProtocolNumber())
901 << " on interface " << int(interfaceIndex));
902 }
903 m_protocols[key] = protocol;
904}
905
906void
908{
909 NS_LOG_FUNCTION(this << protocol);
910
911 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
912 auto iter = m_protocols.find(key);
913 if (iter == m_protocols.end())
914 {
915 NS_LOG_WARN("Trying to remove an non-existent default protocol "
916 << int(protocol->GetProtocolNumber()));
917 }
918 else
919 {
920 m_protocols.erase(key);
921 }
922}
923
924void
926{
927 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
928
929 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
930 auto iter = m_protocols.find(key);
931 if (iter == m_protocols.end())
932 {
933 NS_LOG_WARN("Trying to remove an non-existent protocol "
934 << int(protocol->GetProtocolNumber()) << " on interface "
935 << int(interfaceIndex));
936 }
937 else
938 {
939 m_protocols.erase(key);
940 }
941}
942
944Ipv4L3ClickProtocol::GetProtocol(int protocolNumber) const
945{
946 NS_LOG_FUNCTION(this << protocolNumber);
947
948 return GetProtocol(protocolNumber, -1);
949}
950
952Ipv4L3ClickProtocol::GetProtocol(int protocolNumber, int32_t interfaceIndex) const
953{
954 NS_LOG_FUNCTION(this << protocolNumber << interfaceIndex);
955
956 L4ListKey_t key;
957 if (interfaceIndex >= 0)
958 {
959 // try the interface-specific protocol.
960 key = std::make_pair(protocolNumber, interfaceIndex);
961 auto i = m_protocols.find(key);
962 if (i != m_protocols.end())
963 {
964 return i->second;
965 }
966 }
967 // try the generic protocol.
968 key = std::make_pair(protocolNumber, -1);
969 auto i = m_protocols.find(key);
970 if (i != m_protocols.end())
971 {
972 return i->second;
973 }
974
975 return nullptr;
976}
977
978} // namespace ns3
a polymophic address class
Definition address.h:90
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
Packet header for Ethernet.
uint16_t GetLengthType() const
void SetDestination(Mac48Address destination)
Mac48Address GetDestination() const
void SetLengthType(uint16_t size)
void SetSource(Mac48Address source)
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 IsBroadcast() const
Packet header for IPv4.
Definition ipv4-header.h:23
void SetDestination(Ipv4Address destination)
Ipv4Address GetSource() const
void SetDontFragment()
Don't fragment this packet: if you need to anyway, drop it.
void SetPayloadSize(uint16_t size)
uint8_t GetProtocol() const
void SetTtl(uint8_t ttl)
Ipv4Address GetDestination() const
void SetMayFragment()
If you need to fragment this packet, you can do it.
void SetProtocol(uint8_t num)
void SetIdentification(uint16_t identification)
void EnableChecksum()
Enable checksum calculation for this header.
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
L4List_t m_protocols
List of IPv4 L4 protocols.
void SetPromisc(uint32_t i)
Sets an interface to run on promiscuous mode.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Adds an Ipv4Interface to the interfaces list.
Ipv4Header BuildHeader(Ipv4Address source, Ipv4Address destination, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, bool mayFragment)
Build IPv4 header.
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.
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get a pointer to the i'th Ipv4Interface.
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
void LocalDeliver(Ptr< const Packet > p, const Ipv4Header &ip, uint32_t iif)
Ipv4ClickRouting calls this to locally deliver a packet.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override
Remove the address at addressIndex on named interface.
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 to send a packet to Click.
SocketList m_sockets
List of sockets.
bool IsForwarding(uint32_t i) const override
uint32_t GetNAddresses(uint32_t interface) const override
uint16_t GetMtu(uint32_t i) const override
Ptr< Ipv4RoutingProtocol > m_routingProtocol
IPv4 routing protocol.
Ptr< Socket > CreateRawSocket() override
Creates a raw-socket.
static TypeId GetTypeId()
Get Type ID.
void Remove(Ptr< IpL4Protocol > protocol) override
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const override
void SetIpForward(bool forward) override
Set or unset the IP forwarding state.
void SetStrongEndSystemModel(bool model) override
Set or unset the Strong End System Model.
void SetUp(uint32_t i) override
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const override
Get the routing protocol to be used by this Ipv4 stack.
void SetupLoopback()
Sets up a Loopback device.
void SetMetric(uint32_t i, uint16_t metric) override
Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override
Choose the source address to use with destination address.
Ipv4InterfaceList m_interfaces
List of interfaces.
void NotifyNewAggregate() override
This function will notify other components connected to the node that a new stack member is now conne...
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...
uint32_t GetNInterfaces() const override
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route) override
bool IsUp(uint32_t i) const override
Ptr< NetDevice > GetNetDevice(uint32_t i) override
int32_t GetInterfaceForAddress(Ipv4Address addr) const override
Return the interface number of the interface that has been assigned the specified IP address.
void Insert(Ptr< IpL4Protocol > protocol) override
void SetDown(uint32_t i) override
bool m_strongEndSystemModel
Whether to use Strong End System Model.
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const override
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override
uint32_t AddInterface(Ptr< NetDevice > device) override
void SetNode(Ptr< Node > node)
Calls m_node = node and sets up Loopback if needed.
void DoDispose() override
Destructor implementation.
void DeleteRawSocket(Ptr< Socket > socket) override
Deletes a particular raw socket.
static const uint16_t PROT_NUMBER
Protocol number for Ipv4 L3 (0x0800).
uint16_t m_identification
Identification.
uint16_t GetMetric(uint32_t i) const override
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override
Determine whether address and interface corresponding to received packet can be accepted for local de...
void SendDown(Ptr< Packet > packet, int ifid)
Ptr< Icmpv4L4Protocol > GetIcmp() const
Returns the Icmpv4L4Protocol for the node.
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route) override
bool GetStrongEndSystemModel() const override
Get the Strong End System Model status.
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol) override
Register a new routing protocol to be used by this Ipv4 stack.
bool m_ipForward
Whether IP forwarding is enabled.
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...
void SetForwarding(uint32_t i, bool val) override
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,...
a class to represent an Ipv4 address mask
static Ipv4Mask GetLoopback()
Header for the LLC/SNAP encapsulation.
uint16_t GetType()
Return the Ethertype.
static Mac48Address ConvertFrom(const Address &address)
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
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.
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
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 > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585
-ns3 Test suite for the ns3 wrapper script