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
288void
293
294bool
299
306
307void
313
314void
316{
318
320 Ptr<LoopbackNetDevice> device = nullptr;
321 // First check whether an existing LoopbackNetDevice exists on the node
322 for (uint32_t i = 0; i < m_node->GetNDevices(); i++)
323 {
325 {
326 break;
327 }
328 }
329 if (!device)
330 {
332 m_node->AddDevice(device);
333 }
334 interface->SetDevice(device);
335 interface->SetNode(m_node);
336 Ipv4InterfaceAddress ifaceAddr =
338 interface->AddAddress(ifaceAddr);
339 uint32_t index = AddIpv4Interface(interface);
340 Ptr<Node> node = GetObject<Node>();
341 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
343 device);
344 interface->SetUp();
346 {
347 m_routingProtocol->NotifyInterfaceUp(index);
348 }
349}
350
353{
354 NS_LOG_FUNCTION(this);
356 socket->SetNode(m_node);
357 m_sockets.push_back(socket);
358 return socket;
359}
360
361void
363{
364 NS_LOG_FUNCTION(this << socket);
365 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
366 {
367 if ((*i) == socket)
368 {
369 m_sockets.erase(i);
370 return;
371 }
372 }
373}
374
375void
377{
378 m_node = node;
379 // Add a LoopbackNetDevice if needed, and an Ipv4Interface on top of it
381}
382
383bool
385{
386 NS_LOG_FUNCTION(this << i << address);
387 Ptr<Ipv4Interface> interface = GetInterface(i);
388 bool retVal = interface->AddAddress(address);
389 if (m_routingProtocol)
390 {
391 m_routingProtocol->NotifyAddAddress(i, address);
392 }
393 return retVal;
394}
395
397Ipv4L3ClickProtocol::GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
398{
399 NS_LOG_FUNCTION(this << interfaceIndex << addressIndex);
400 Ptr<Ipv4Interface> interface = GetInterface(interfaceIndex);
401 return interface->GetAddress(addressIndex);
402}
403
406{
407 NS_LOG_FUNCTION(this << interface);
408 Ptr<Ipv4Interface> iface = GetInterface(interface);
409 return iface->GetNAddresses();
410}
411
412bool
414{
415 NS_LOG_FUNCTION(this << i << addressIndex);
416 Ptr<Ipv4Interface> interface = GetInterface(i);
417 Ipv4InterfaceAddress address = interface->RemoveAddress(addressIndex);
418 if (address != Ipv4InterfaceAddress())
419 {
420 if (m_routingProtocol)
421 {
422 m_routingProtocol->NotifyRemoveAddress(i, address);
423 }
424 return true;
425 }
426 return false;
427}
428
429bool
431{
432 NS_LOG_FUNCTION(this << i << address);
433
434 if (address == Ipv4Address::GetLoopback())
435 {
436 NS_LOG_WARN("Cannot remove loopback address.");
437 return false;
438 }
439 Ptr<Ipv4Interface> interface = GetInterface(i);
440 Ipv4InterfaceAddress ifAddr = interface->RemoveAddress(address);
441 if (ifAddr != Ipv4InterfaceAddress())
442 {
443 if (m_routingProtocol)
444 {
445 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
446 }
447 return true;
448 }
449 return false;
450}
451
454{
455 NS_LOG_FUNCTION(this << interfaceIdx << " " << dest);
456 if (GetNAddresses(interfaceIdx) == 1) // common case
457 {
458 return GetAddress(interfaceIdx, 0).GetLocal();
459 }
460 // no way to determine the scope of the destination, so adopt the
461 // following rule: pick the first available address (index 0) unless
462 // a subsequent address is on link (in which case, pick the primary
463 // address if there are multiple)
464 Ipv4Address candidate = GetAddress(interfaceIdx, 0).GetLocal();
465 for (uint32_t i = 0; i < GetNAddresses(interfaceIdx); i++)
466 {
467 Ipv4InterfaceAddress test = GetAddress(interfaceIdx, i);
468 if (test.GetLocal().CombineMask(test.GetMask()) == dest.CombineMask(test.GetMask()))
469 {
470 if (!test.IsSecondary())
471 {
472 return test.GetLocal();
473 }
474 }
475 }
476 return candidate;
477}
478
481 Ipv4Address dst,
483{
484 NS_LOG_FUNCTION(device << dst << scope);
485 Ipv4Address addr("0.0.0.0");
487 bool found = false;
488
489 if (device)
490 {
491 int32_t i = GetInterfaceForDevice(device);
492 NS_ASSERT_MSG(i >= 0, "No device found on node");
493 for (uint32_t j = 0; j < GetNAddresses(i); j++)
494 {
495 iaddr = GetAddress(i, j);
496 if (iaddr.IsSecondary())
497 {
498 continue;
499 }
500 if (iaddr.GetScope() > scope)
501 {
502 continue;
503 }
504 if (dst.CombineMask(iaddr.GetMask()) == iaddr.GetLocal().CombineMask(iaddr.GetMask()))
505 {
506 return iaddr.GetLocal();
507 }
508 if (!found)
509 {
510 addr = iaddr.GetLocal();
511 found = true;
512 }
513 }
514 }
515 if (found)
516 {
517 return addr;
518 }
519
520 // Iterate among all interfaces
521 for (uint32_t i = 0; i < GetNInterfaces(); i++)
522 {
523 for (uint32_t j = 0; j < GetNAddresses(i); j++)
524 {
525 iaddr = GetAddress(i, j);
526 if (iaddr.IsSecondary())
527 {
528 continue;
529 }
530 if (iaddr.GetScope() != Ipv4InterfaceAddress::LINK && iaddr.GetScope() <= scope)
531 {
532 return iaddr.GetLocal();
533 }
534 }
535 }
536 NS_LOG_WARN("Could not find source address for " << dst << " and scope " << scope
537 << ", returning 0");
538 return addr;
539}
540
541void
543{
544 NS_LOG_FUNCTION(i << metric);
545 Ptr<Ipv4Interface> interface = GetInterface(i);
546 interface->SetMetric(metric);
547}
548
549uint16_t
551{
553 Ptr<Ipv4Interface> interface = GetInterface(i);
554 return interface->GetMetric();
555}
556
557uint16_t
559{
560 NS_LOG_FUNCTION(this << i);
561 Ptr<Ipv4Interface> interface = GetInterface(i);
562 return interface->GetDevice()->GetMtu();
563}
564
565bool
567{
568 NS_LOG_FUNCTION(this << i);
569 Ptr<Ipv4Interface> interface = GetInterface(i);
570 return interface->IsUp();
571}
572
573void
575{
576 NS_LOG_FUNCTION(this << i);
577 Ptr<Ipv4Interface> interface = GetInterface(i);
578 interface->SetUp();
579
580 if (m_routingProtocol)
581 {
582 m_routingProtocol->NotifyInterfaceUp(i);
583 }
584}
585
586void
588{
589 NS_LOG_FUNCTION(this << ifaceIndex);
590 Ptr<Ipv4Interface> interface = GetInterface(ifaceIndex);
591 interface->SetDown();
592
593 if (m_routingProtocol)
594 {
595 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
596 }
597}
598
599bool
601{
602 NS_LOG_FUNCTION(this << i);
603 Ptr<Ipv4Interface> interface = GetInterface(i);
604 NS_LOG_LOGIC("Forwarding state: " << interface->IsForwarding());
605 return interface->IsForwarding();
606}
607
608void
610{
611 NS_LOG_FUNCTION(this << i);
612 Ptr<Ipv4Interface> interface = GetInterface(i);
613 interface->SetForwarding(val);
614}
615
616void
618{
619 NS_ASSERT(i <= m_node->GetNDevices());
620 Ptr<NetDevice> netdev = GetNetDevice(i);
621 NS_ASSERT(netdev);
622 Ptr<Node> node = GetObject<Node>();
623 NS_ASSERT(node);
624 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
625 0,
626 netdev,
627 true);
628}
629
632{
633 NS_LOG_FUNCTION(this << &device);
634 Ptr<Node> node = GetObject<Node>();
635 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
637 device);
638 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
640 device);
641
643 interface->SetNode(m_node);
644 interface->SetDevice(device);
645 interface->SetForwarding(m_ipForward);
646 return AddIpv4Interface(interface);
647}
648
651{
652 NS_LOG_FUNCTION(this << interface);
653 uint32_t index = m_interfaces.size();
654 m_interfaces.push_back(interface);
655 m_reverseInterfacesContainer[interface->GetDevice()] = index;
656 return index;
657}
658
659/// \todo when should we set ip_id? check whether we are incrementing
660/// m_identification on packets that may later be dropped in this stack
661/// and whether that deviates from Linux
664 Ipv4Address destination,
665 uint8_t protocol,
666 uint16_t payloadSize,
667 uint8_t ttl,
668 bool mayFragment)
669{
671 Ipv4Header ipHeader;
672 ipHeader.SetSource(source);
673 ipHeader.SetDestination(destination);
674 ipHeader.SetProtocol(protocol);
675 ipHeader.SetPayloadSize(payloadSize);
676 ipHeader.SetTtl(ttl);
677 if (mayFragment)
678 {
679 ipHeader.SetMayFragment();
682 }
683 else
684 {
685 ipHeader.SetDontFragment();
686 // TBD: set to zero here; will cause traces to change
689 }
691 {
692 ipHeader.EnableChecksum();
693 }
694 return ipHeader;
695}
696
697void
699 Ipv4Address source,
700 Ipv4Address destination,
701 uint8_t protocol,
702 Ptr<Ipv4Route> route)
703{
704 NS_LOG_FUNCTION(this << packet << source << destination << uint32_t(protocol) << route);
705
706 Ipv4Header ipHeader;
707 bool mayFragment = true;
708 uint8_t ttl = m_defaultTtl;
709 SocketIpTtlTag tag;
710 bool found = packet->RemovePacketTag(tag);
711 if (found)
712 {
713 ttl = tag.GetTtl();
714 }
715
716 ipHeader = BuildHeader(source, destination, protocol, packet->GetSize(), ttl, mayFragment);
719 {
720 ipHeader.EnableChecksum();
721 }
722 packet->AddHeader(ipHeader);
723 click->Send(packet->Copy(), source, destination);
724}
725
726void
728{
729 NS_LOG_FUNCTION(this << packet << ipHeader << route);
730
733 {
734 ipHeader.EnableChecksum();
735 }
736 packet->AddHeader(ipHeader);
737 click->Send(packet->Copy(), ipHeader.GetSource(), ipHeader.GetDestination());
738}
739
740void
742{
743 // Called by Ipv4ClickRouting.
744
745 // NetDevice::Send () attaches ethernet headers,
746 // so the one that Click attaches isn't required
747 // but we need the destination address and
748 // protocol values from the header.
749
750 Ptr<NetDevice> netdev = GetNetDevice(ifid);
751
752 EthernetHeader header;
753 p->RemoveHeader(header);
754
755 uint16_t protocol;
756
757 if (header.GetLengthType() <= 1500)
758 {
759 LlcSnapHeader llc;
760 p->RemoveHeader(llc);
761 protocol = llc.GetType();
762 }
763 else
764 {
765 protocol = header.GetLengthType();
766 }
767
768 // Use the destination address and protocol obtained
769 // from above to send the packet.
770 netdev->Send(p, header.GetDestination(), protocol);
771}
772
773void
776 uint16_t protocol,
777 const Address& from,
778 const Address& to,
779 NetDevice::PacketType packetType)
780{
781 NS_LOG_FUNCTION(this << device << p << from << to);
782
783 NS_LOG_LOGIC("Packet from " << from << " received on node " << m_node->GetId());
784
785 // Forward packet to raw sockets, if any
786 if (protocol == Ipv4L3ClickProtocol::PROT_NUMBER && !m_sockets.empty())
787 {
788 Ptr<Packet> packetForRawSocket = p->Copy();
789 int32_t interface = GetInterfaceForDevice(device);
790 NS_ASSERT_MSG(interface != -1,
791 "Received a packet from an interface that is not known to IPv4");
792 Ptr<Ipv4Interface> ipv4Interface = m_interfaces[interface];
793 if (!ipv4Interface->IsUp())
794 {
795 NS_LOG_LOGIC("Dropping received packet -- interface is down");
796 return;
797 }
798
799 Ipv4Header ipHeader;
800 if (Node::ChecksumEnabled())
801 {
802 ipHeader.EnableChecksum();
803 }
804 packetForRawSocket->RemoveHeader(ipHeader);
805
806 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
807 {
808 NS_LOG_LOGIC("Forwarding to raw socket");
809 Ptr<Ipv4RawSocketImpl> socket = *i;
810 socket->ForwardUp(packetForRawSocket, ipHeader, ipv4Interface);
811 }
812 }
813
814 Ptr<Packet> packet = p->Copy();
815
816 // Add an ethernet frame. This allows
817 // Click to work with csma and wifi
818 EthernetHeader hdr;
821 hdr.SetLengthType(protocol);
822 packet->AddHeader(hdr);
823
825 click->Receive(packet->Copy(),
826 Mac48Address::ConvertFrom(device->GetAddress()),
828}
829
830void
832{
833 NS_LOG_FUNCTION(this << packet << &ip);
834 Ptr<Packet> p = packet->Copy(); // need to pass a non-const packet up
835
836 m_localDeliverTrace(ip, packet, iif);
837
839 if (protocol)
840 {
841 // we need to make a copy in the unlikely event we hit the
842 // RX_ENDPOINT_UNREACH codepath
843 Ptr<Packet> copy = p->Copy();
844 IpL4Protocol::RxStatus status = protocol->Receive(p, ip, GetInterface(iif));
845 switch (status)
846 {
848 // fall through
850 // fall through
852 break;
855 {
856 break; // Do not reply to broadcast or multicast
857 }
858 // Another case to suppress ICMP is a subnet-directed broadcast
859 bool subnetDirected = false;
860 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
861 {
862 Ipv4InterfaceAddress addr = GetAddress(iif, i);
863 if (addr.GetLocal().CombineMask(addr.GetMask()) ==
864 ip.GetDestination().CombineMask(addr.GetMask()) &&
866 {
867 subnetDirected = true;
868 }
869 }
870 if (!subnetDirected)
871 {
872 GetIcmp()->SendDestUnreachPort(ip, copy);
873 }
874 }
875 }
876}
877
880{
882 if (prot)
883 {
884 return prot->GetObject<Icmpv4L4Protocol>();
885 }
886 else
887 {
888 return nullptr;
889 }
890}
891
892void
894{
895 NS_LOG_FUNCTION(this << protocol);
896 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
897 if (m_protocols.find(key) != m_protocols.end())
898 {
899 NS_LOG_WARN("Overwriting default protocol " << int(protocol->GetProtocolNumber()));
900 }
901 m_protocols[key] = protocol;
902}
903
904void
906{
907 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
908
909 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
910 if (m_protocols.find(key) != m_protocols.end())
911 {
912 NS_LOG_WARN("Overwriting protocol " << int(protocol->GetProtocolNumber())
913 << " on interface " << int(interfaceIndex));
914 }
915 m_protocols[key] = protocol;
916}
917
918void
920{
921 NS_LOG_FUNCTION(this << protocol);
922
923 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
924 auto iter = m_protocols.find(key);
925 if (iter == m_protocols.end())
926 {
927 NS_LOG_WARN("Trying to remove an non-existent default protocol "
928 << int(protocol->GetProtocolNumber()));
929 }
930 else
931 {
932 m_protocols.erase(key);
933 }
934}
935
936void
938{
939 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
940
941 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
942 auto iter = m_protocols.find(key);
943 if (iter == m_protocols.end())
944 {
945 NS_LOG_WARN("Trying to remove an non-existent protocol "
946 << int(protocol->GetProtocolNumber()) << " on interface "
947 << int(interfaceIndex));
948 }
949 else
950 {
951 m_protocols.erase(key);
952 }
953}
954
956Ipv4L3ClickProtocol::GetProtocol(int protocolNumber) const
957{
958 NS_LOG_FUNCTION(this << protocolNumber);
959
960 return GetProtocol(protocolNumber, -1);
961}
962
964Ipv4L3ClickProtocol::GetProtocol(int protocolNumber, int32_t interfaceIndex) const
965{
966 NS_LOG_FUNCTION(this << protocolNumber << interfaceIndex);
967
968 L4ListKey_t key;
969 if (interfaceIndex >= 0)
970 {
971 // try the interface-specific protocol.
972 key = std::make_pair(protocolNumber, interfaceIndex);
973 auto i = m_protocols.find(key);
974 if (i != m_protocols.end())
975 {
976 return i->second;
977 }
978 }
979 // try the generic protocol.
980 key = std::make_pair(protocolNumber, -1);
981 auto i = m_protocols.find(key);
982 if (i != m_protocols.end())
983 {
984 return i->second;
985 }
986
987 return nullptr;
988}
989
990} // 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
void SetWeakEsModel(bool model) override
Set or unset the Weak Es Model.
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.
bool GetWeakEsModel() const override
Get the Weak Es Model status.
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:48
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
#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.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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< 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:580
-ns3 Test suite for the ns3 wrapper script