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// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License version 2 as
6// published by the Free Software Foundation;
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// Author: George F. Riley <riley@ece.gatech.edu>
18// Author: Lalith Suresh <suresh.lalith@gmail.com>
19//
20
22
23#include "ipv4-click-routing.h"
24
25#include "ns3/arp-l3-protocol.h"
26#include "ns3/ethernet-header.h"
27#include "ns3/icmpv4-l4-protocol.h"
28#include "ns3/ip-l4-protocol.h"
29#include "ns3/ipv4-raw-socket-impl.h"
30#include "ns3/llc-snap-header.h"
31#include "ns3/loopback-net-device.h"
32#include "ns3/net-device.h"
33#include "ns3/node.h"
34#include "ns3/object-vector.h"
35#include "ns3/socket.h"
36#include "ns3/uinteger.h"
37
38namespace ns3
39{
40
41NS_LOG_COMPONENT_DEFINE("Ipv4L3ClickProtocol");
42
43const uint16_t Ipv4L3ClickProtocol::PROT_NUMBER = 0x0800;
44
45NS_OBJECT_ENSURE_REGISTERED(Ipv4L3ClickProtocol);
46
47TypeId
49{
50 static TypeId tid =
51 TypeId("ns3::Ipv4L3ClickProtocol")
52 .SetParent<Ipv4>()
53 .AddConstructor<Ipv4L3ClickProtocol>()
54 .SetGroupName("Click")
55 .AddAttribute(
56 "DefaultTtl",
57 "The TTL value set by default on all outgoing packets generated on this node.",
58 UintegerValue(64),
60 MakeUintegerChecker<uint8_t>())
61 .AddAttribute("InterfaceList",
62 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
65 MakeObjectVectorChecker<Ipv4Interface>());
66 return tid;
67}
68
70 : m_identification(0)
71{
72}
73
75{
76}
77
78void
80{
81 NS_LOG_FUNCTION(this);
82 for (auto i = m_protocols.begin(); i != m_protocols.end(); ++i)
83 {
84 i->second = nullptr;
85 }
86 m_protocols.clear();
87
88 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); ++i)
89 {
90 *i = nullptr;
91 }
92 m_interfaces.clear();
94
95 m_sockets.clear();
96 m_node = nullptr;
97 m_routingProtocol = nullptr;
99}
100
101void
103{
104 if (!m_node)
105 {
106 Ptr<Node> node = this->GetObject<Node>();
107 // verify that it's a valid node and that
108 // the node has not been set before
109 if (node)
110 {
111 this->SetNode(node);
112 }
113 }
115}
116
117void
119{
120 NS_LOG_FUNCTION(this);
121 m_routingProtocol = routingProtocol;
122 m_routingProtocol->SetIpv4(this);
123}
124
127{
128 return m_routingProtocol;
129}
130
133{
134 NS_LOG_FUNCTION(this << index);
135 if (index < m_interfaces.size())
136 {
137 return m_interfaces[index];
138 }
139 return nullptr;
140}
141
144{
146 return m_interfaces.size();
147}
148
151{
152 NS_LOG_FUNCTION(this << address);
153
154 int32_t interface = 0;
155 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
156 {
157 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
158 {
159 if ((*i)->GetAddress(j).GetLocal() == address)
160 {
161 return interface;
162 }
163 }
164 }
165
166 return -1;
167}
168
171{
172 NS_LOG_FUNCTION(this << address << mask);
173
174 int32_t interface = 0;
175 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++, interface++)
176 {
177 for (uint32_t j = 0; j < (*i)->GetNAddresses(); j++)
178 {
179 if ((*i)->GetAddress(j).GetLocal().CombineMask(mask) == address.CombineMask(mask))
180 {
181 return interface;
182 }
183 }
184 }
185
186 return -1;
187}
188
191{
192 NS_LOG_FUNCTION(this << device->GetIfIndex());
193
194 auto iter = m_reverseInterfacesContainer.find(device);
195 if (iter != m_reverseInterfacesContainer.end())
196 {
197 return (*iter).second;
198 }
199
200 return -1;
201}
202
203bool
205{
206 NS_LOG_FUNCTION(this << address << " " << iif);
207
208 // First check the incoming interface for a unicast address match
209 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
210 {
211 Ipv4InterfaceAddress iaddr = GetAddress(iif, i);
212 if (address == iaddr.GetLocal())
213 {
214 NS_LOG_LOGIC("For me (destination " << address << " match)");
215 return true;
216 }
217 if (address == iaddr.GetBroadcast())
218 {
219 NS_LOG_LOGIC("For me (interface broadcast address)");
220 return true;
221 }
222 }
223
224 if (address.IsMulticast())
225 {
226#ifdef NOTYET
227 if (MulticastCheckGroup(iif, address))
228#endif
229 {
230 NS_LOG_LOGIC("For me (Ipv4Addr multicast address");
231 return true;
232 }
233 }
234
235 if (address.IsBroadcast())
236 {
237 NS_LOG_LOGIC("For me (Ipv4Addr broadcast address)");
238 return true;
239 }
240
241 if (GetWeakEsModel()) // Check other interfaces
242 {
243 for (uint32_t j = 0; j < GetNInterfaces(); j++)
244 {
245 if (j == uint32_t(iif))
246 {
247 continue;
248 }
249 for (uint32_t i = 0; i < GetNAddresses(j); i++)
250 {
251 Ipv4InterfaceAddress iaddr = GetAddress(j, i);
252 if (address == iaddr.GetLocal())
253 {
254 NS_LOG_LOGIC("For me (destination " << address
255 << " match) on another interface");
256 return true;
257 }
258 // This is a small corner case: match another interface's broadcast address
259 if (address == iaddr.GetBroadcast())
260 {
261 NS_LOG_LOGIC("For me (interface broadcast address on another interface)");
262 return true;
263 }
264 }
265 }
266 }
267 return false;
268}
269
270void
272{
273 NS_LOG_FUNCTION(this << forward);
274 m_ipForward = forward;
275 for (auto i = m_interfaces.begin(); i != m_interfaces.end(); i++)
276 {
277 (*i)->SetForwarding(forward);
278 }
279}
280
281bool
283{
284 return m_ipForward;
285}
286
287void
289{
290 m_weakEsModel = model;
291}
292
293bool
295{
296 return m_weakEsModel;
297}
298
301{
302 NS_LOG_FUNCTION(this << i);
303 return GetInterface(i)->GetDevice();
304}
305
306void
308{
310 m_defaultTtl = ttl;
311}
312
313void
315{
317
319 Ptr<LoopbackNetDevice> device = nullptr;
320 // First check whether an existing LoopbackNetDevice exists on the node
321 for (uint32_t i = 0; i < m_node->GetNDevices(); i++)
322 {
323 if ((device = DynamicCast<LoopbackNetDevice>(m_node->GetDevice(i))))
324 {
325 break;
326 }
327 }
328 if (!device)
329 {
330 device = CreateObject<LoopbackNetDevice>();
331 m_node->AddDevice(device);
332 }
333 interface->SetDevice(device);
334 interface->SetNode(m_node);
335 Ipv4InterfaceAddress ifaceAddr =
337 interface->AddAddress(ifaceAddr);
338 uint32_t index = AddIpv4Interface(interface);
339 Ptr<Node> node = GetObject<Node>();
340 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
342 device);
343 interface->SetUp();
345 {
346 m_routingProtocol->NotifyInterfaceUp(index);
347 }
348}
349
352{
353 NS_LOG_FUNCTION(this);
354 Ptr<Ipv4RawSocketImpl> socket = CreateObject<Ipv4RawSocketImpl>();
355 socket->SetNode(m_node);
356 m_sockets.push_back(socket);
357 return socket;
358}
359
360void
362{
363 NS_LOG_FUNCTION(this << socket);
364 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
365 {
366 if ((*i) == socket)
367 {
368 m_sockets.erase(i);
369 return;
370 }
371 }
372}
373
374void
376{
377 m_node = node;
378 // Add a LoopbackNetDevice if needed, and an Ipv4Interface on top of it
380}
381
382bool
384{
385 NS_LOG_FUNCTION(this << i << address);
386 Ptr<Ipv4Interface> interface = GetInterface(i);
387 bool retVal = interface->AddAddress(address);
388 if (m_routingProtocol)
389 {
390 m_routingProtocol->NotifyAddAddress(i, address);
391 }
392 return retVal;
393}
394
396Ipv4L3ClickProtocol::GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
397{
398 NS_LOG_FUNCTION(this << interfaceIndex << addressIndex);
399 Ptr<Ipv4Interface> interface = GetInterface(interfaceIndex);
400 return interface->GetAddress(addressIndex);
401}
402
405{
406 NS_LOG_FUNCTION(this << interface);
407 Ptr<Ipv4Interface> iface = GetInterface(interface);
408 return iface->GetNAddresses();
409}
410
411bool
413{
414 NS_LOG_FUNCTION(this << i << addressIndex);
415 Ptr<Ipv4Interface> interface = GetInterface(i);
416 Ipv4InterfaceAddress address = interface->RemoveAddress(addressIndex);
417 if (address != Ipv4InterfaceAddress())
418 {
419 if (m_routingProtocol)
420 {
421 m_routingProtocol->NotifyRemoveAddress(i, address);
422 }
423 return true;
424 }
425 return false;
426}
427
428bool
430{
431 NS_LOG_FUNCTION(this << i << address);
432
433 if (address == Ipv4Address::GetLoopback())
434 {
435 NS_LOG_WARN("Cannot remove loopback address.");
436 return false;
437 }
438 Ptr<Ipv4Interface> interface = GetInterface(i);
439 Ipv4InterfaceAddress ifAddr = interface->RemoveAddress(address);
440 if (ifAddr != Ipv4InterfaceAddress())
441 {
442 if (m_routingProtocol)
443 {
444 m_routingProtocol->NotifyRemoveAddress(i, ifAddr);
445 }
446 return true;
447 }
448 return false;
449}
450
453{
454 NS_LOG_FUNCTION(this << interfaceIdx << " " << dest);
455 if (GetNAddresses(interfaceIdx) == 1) // common case
456 {
457 return GetAddress(interfaceIdx, 0).GetLocal();
458 }
459 // no way to determine the scope of the destination, so adopt the
460 // following rule: pick the first available address (index 0) unless
461 // a subsequent address is on link (in which case, pick the primary
462 // address if there are multiple)
463 Ipv4Address candidate = GetAddress(interfaceIdx, 0).GetLocal();
464 for (uint32_t i = 0; i < GetNAddresses(interfaceIdx); i++)
465 {
466 Ipv4InterfaceAddress test = GetAddress(interfaceIdx, i);
467 if (test.GetLocal().CombineMask(test.GetMask()) == dest.CombineMask(test.GetMask()))
468 {
469 if (!test.IsSecondary())
470 {
471 return test.GetLocal();
472 }
473 }
474 }
475 return candidate;
476}
477
480 Ipv4Address dst,
482{
483 NS_LOG_FUNCTION(device << dst << scope);
484 Ipv4Address addr("0.0.0.0");
486 bool found = false;
487
488 if (device)
489 {
490 int32_t i = GetInterfaceForDevice(device);
491 NS_ASSERT_MSG(i >= 0, "No device found on node");
492 for (uint32_t j = 0; j < GetNAddresses(i); j++)
493 {
494 iaddr = GetAddress(i, j);
495 if (iaddr.IsSecondary())
496 {
497 continue;
498 }
499 if (iaddr.GetScope() > scope)
500 {
501 continue;
502 }
503 if (dst.CombineMask(iaddr.GetMask()) == iaddr.GetLocal().CombineMask(iaddr.GetMask()))
504 {
505 return iaddr.GetLocal();
506 }
507 if (!found)
508 {
509 addr = iaddr.GetLocal();
510 found = true;
511 }
512 }
513 }
514 if (found)
515 {
516 return addr;
517 }
518
519 // Iterate among all interfaces
520 for (uint32_t i = 0; i < GetNInterfaces(); i++)
521 {
522 for (uint32_t j = 0; j < GetNAddresses(i); j++)
523 {
524 iaddr = GetAddress(i, j);
525 if (iaddr.IsSecondary())
526 {
527 continue;
528 }
529 if (iaddr.GetScope() != Ipv4InterfaceAddress::LINK && iaddr.GetScope() <= scope)
530 {
531 return iaddr.GetLocal();
532 }
533 }
534 }
535 NS_LOG_WARN("Could not find source address for " << dst << " and scope " << scope
536 << ", returning 0");
537 return addr;
538}
539
540void
542{
543 NS_LOG_FUNCTION(i << metric);
544 Ptr<Ipv4Interface> interface = GetInterface(i);
545 interface->SetMetric(metric);
546}
547
548uint16_t
550{
552 Ptr<Ipv4Interface> interface = GetInterface(i);
553 return interface->GetMetric();
554}
555
556uint16_t
558{
559 NS_LOG_FUNCTION(this << i);
560 Ptr<Ipv4Interface> interface = GetInterface(i);
561 return interface->GetDevice()->GetMtu();
562}
563
564bool
566{
567 NS_LOG_FUNCTION(this << i);
568 Ptr<Ipv4Interface> interface = GetInterface(i);
569 return interface->IsUp();
570}
571
572void
574{
575 NS_LOG_FUNCTION(this << i);
576 Ptr<Ipv4Interface> interface = GetInterface(i);
577 interface->SetUp();
578
579 if (m_routingProtocol)
580 {
581 m_routingProtocol->NotifyInterfaceUp(i);
582 }
583}
584
585void
587{
588 NS_LOG_FUNCTION(this << ifaceIndex);
589 Ptr<Ipv4Interface> interface = GetInterface(ifaceIndex);
590 interface->SetDown();
591
592 if (m_routingProtocol)
593 {
594 m_routingProtocol->NotifyInterfaceDown(ifaceIndex);
595 }
596}
597
598bool
600{
601 NS_LOG_FUNCTION(this << i);
602 Ptr<Ipv4Interface> interface = GetInterface(i);
603 NS_LOG_LOGIC("Forwarding state: " << interface->IsForwarding());
604 return interface->IsForwarding();
605}
606
607void
609{
610 NS_LOG_FUNCTION(this << i);
611 Ptr<Ipv4Interface> interface = GetInterface(i);
612 interface->SetForwarding(val);
613}
614
615void
617{
618 NS_ASSERT(i <= m_node->GetNDevices());
619 Ptr<NetDevice> netdev = GetNetDevice(i);
620 NS_ASSERT(netdev);
621 Ptr<Node> node = GetObject<Node>();
622 NS_ASSERT(node);
623 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
624 0,
625 netdev,
626 true);
627}
628
631{
632 NS_LOG_FUNCTION(this << &device);
633 Ptr<Node> node = GetObject<Node>();
634 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
636 device);
637 node->RegisterProtocolHandler(MakeCallback(&Ipv4L3ClickProtocol::Receive, this),
639 device);
640
642 interface->SetNode(m_node);
643 interface->SetDevice(device);
644 interface->SetForwarding(m_ipForward);
645 return AddIpv4Interface(interface);
646}
647
650{
651 NS_LOG_FUNCTION(this << interface);
652 uint32_t index = m_interfaces.size();
653 m_interfaces.push_back(interface);
654 m_reverseInterfacesContainer[interface->GetDevice()] = index;
655 return index;
656}
657
663 Ipv4Address destination,
664 uint8_t protocol,
665 uint16_t payloadSize,
666 uint8_t ttl,
667 bool mayFragment)
668{
670 Ipv4Header ipHeader;
671 ipHeader.SetSource(source);
672 ipHeader.SetDestination(destination);
673 ipHeader.SetProtocol(protocol);
674 ipHeader.SetPayloadSize(payloadSize);
675 ipHeader.SetTtl(ttl);
676 if (mayFragment)
677 {
678 ipHeader.SetMayFragment();
681 }
682 else
683 {
684 ipHeader.SetDontFragment();
685 // TBD: set to zero here; will cause traces to change
688 }
690 {
691 ipHeader.EnableChecksum();
692 }
693 return ipHeader;
694}
695
696void
698 Ipv4Address source,
699 Ipv4Address destination,
700 uint8_t protocol,
701 Ptr<Ipv4Route> route)
702{
703 NS_LOG_FUNCTION(this << packet << source << destination << uint32_t(protocol) << route);
704
705 Ipv4Header ipHeader;
706 bool mayFragment = true;
707 uint8_t ttl = m_defaultTtl;
708 SocketIpTtlTag tag;
709 bool found = packet->RemovePacketTag(tag);
710 if (found)
711 {
712 ttl = tag.GetTtl();
713 }
714
715 ipHeader = BuildHeader(source, destination, protocol, packet->GetSize(), ttl, mayFragment);
716 Ptr<Ipv4ClickRouting> click = DynamicCast<Ipv4ClickRouting>(m_routingProtocol);
718 {
719 ipHeader.EnableChecksum();
720 }
721 packet->AddHeader(ipHeader);
722 click->Send(packet->Copy(), source, destination);
723}
724
725void
727{
728 NS_LOG_FUNCTION(this << packet << ipHeader << route);
729
730 Ptr<Ipv4ClickRouting> click = DynamicCast<Ipv4ClickRouting>(m_routingProtocol);
732 {
733 ipHeader.EnableChecksum();
734 }
735 packet->AddHeader(ipHeader);
736 click->Send(packet->Copy(), ipHeader.GetSource(), ipHeader.GetDestination());
737}
738
739void
741{
742 // Called by Ipv4ClickRouting.
743
744 // NetDevice::Send () attaches ethernet headers,
745 // so the one that Click attaches isn't required
746 // but we need the destination address and
747 // protocol values from the header.
748
749 Ptr<NetDevice> netdev = GetNetDevice(ifid);
750
751 EthernetHeader header;
752 p->RemoveHeader(header);
753
754 uint16_t protocol;
755
756 if (header.GetLengthType() <= 1500)
757 {
758 LlcSnapHeader llc;
759 p->RemoveHeader(llc);
760 protocol = llc.GetType();
761 }
762 else
763 {
764 protocol = header.GetLengthType();
765 }
766
767 // Use the destination address and protocol obtained
768 // from above to send the packet.
769 netdev->Send(p, header.GetDestination(), protocol);
770}
771
772void
775 uint16_t protocol,
776 const Address& from,
777 const Address& to,
778 NetDevice::PacketType packetType)
779{
780 NS_LOG_FUNCTION(this << device << p << from << to);
781
782 NS_LOG_LOGIC("Packet from " << from << " received on node " << m_node->GetId());
783
784 // Forward packet to raw sockets, if any
785 if (protocol == Ipv4L3ClickProtocol::PROT_NUMBER && !m_sockets.empty())
786 {
787 Ptr<Packet> packetForRawSocket = p->Copy();
788 int32_t interface = GetInterfaceForDevice(device);
789 NS_ASSERT_MSG(interface != -1,
790 "Received a packet from an interface that is not known to IPv4");
791 Ptr<Ipv4Interface> ipv4Interface = m_interfaces[interface];
792 if (!ipv4Interface->IsUp())
793 {
794 NS_LOG_LOGIC("Dropping received packet -- interface is down");
795 return;
796 }
797
798 Ipv4Header ipHeader;
799 if (Node::ChecksumEnabled())
800 {
801 ipHeader.EnableChecksum();
802 }
803 packetForRawSocket->RemoveHeader(ipHeader);
804
805 for (auto i = m_sockets.begin(); i != m_sockets.end(); ++i)
806 {
807 NS_LOG_LOGIC("Forwarding to raw socket");
808 Ptr<Ipv4RawSocketImpl> socket = *i;
809 socket->ForwardUp(packetForRawSocket, ipHeader, ipv4Interface);
810 }
811 }
812
813 Ptr<Packet> packet = p->Copy();
814
815 // Add an ethernet frame. This allows
816 // Click to work with csma and wifi
817 EthernetHeader hdr;
820 hdr.SetLengthType(protocol);
821 packet->AddHeader(hdr);
822
823 Ptr<Ipv4ClickRouting> click = DynamicCast<Ipv4ClickRouting>(GetRoutingProtocol());
824 click->Receive(packet->Copy(),
825 Mac48Address::ConvertFrom(device->GetAddress()),
827}
828
829void
831{
832 NS_LOG_FUNCTION(this << packet << &ip);
833 Ptr<Packet> p = packet->Copy(); // need to pass a non-const packet up
834
835 m_localDeliverTrace(ip, packet, iif);
836
838 if (protocol)
839 {
840 // we need to make a copy in the unlikely event we hit the
841 // RX_ENDPOINT_UNREACH codepath
842 Ptr<Packet> copy = p->Copy();
843 IpL4Protocol::RxStatus status = protocol->Receive(p, ip, GetInterface(iif));
844 switch (status)
845 {
847 // fall through
849 // fall through
851 break;
854 {
855 break; // Do not reply to broadcast or multicast
856 }
857 // Another case to suppress ICMP is a subnet-directed broadcast
858 bool subnetDirected = false;
859 for (uint32_t i = 0; i < GetNAddresses(iif); i++)
860 {
861 Ipv4InterfaceAddress addr = GetAddress(iif, i);
862 if (addr.GetLocal().CombineMask(addr.GetMask()) ==
863 ip.GetDestination().CombineMask(addr.GetMask()) &&
865 {
866 subnetDirected = true;
867 }
868 }
869 if (!subnetDirected)
870 {
871 GetIcmp()->SendDestUnreachPort(ip, copy);
872 }
873 }
874 }
875}
876
879{
881 if (prot)
882 {
883 return prot->GetObject<Icmpv4L4Protocol>();
884 }
885 else
886 {
887 return nullptr;
888 }
889}
890
891void
893{
894 NS_LOG_FUNCTION(this << protocol);
895 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
896 if (m_protocols.find(key) != m_protocols.end())
897 {
898 NS_LOG_WARN("Overwriting default protocol " << int(protocol->GetProtocolNumber()));
899 }
900 m_protocols[key] = protocol;
901}
902
903void
905{
906 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
907
908 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
909 if (m_protocols.find(key) != m_protocols.end())
910 {
911 NS_LOG_WARN("Overwriting protocol " << int(protocol->GetProtocolNumber())
912 << " on interface " << int(interfaceIndex));
913 }
914 m_protocols[key] = protocol;
915}
916
917void
919{
920 NS_LOG_FUNCTION(this << protocol);
921
922 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), -1);
923 auto iter = m_protocols.find(key);
924 if (iter == m_protocols.end())
925 {
926 NS_LOG_WARN("Trying to remove an non-existent default protocol "
927 << int(protocol->GetProtocolNumber()));
928 }
929 else
930 {
931 m_protocols.erase(key);
932 }
933}
934
935void
937{
938 NS_LOG_FUNCTION(this << protocol << interfaceIndex);
939
940 L4ListKey_t key = std::make_pair(protocol->GetProtocolNumber(), interfaceIndex);
941 auto iter = m_protocols.find(key);
942 if (iter == m_protocols.end())
943 {
944 NS_LOG_WARN("Trying to remove an non-existent protocol "
945 << int(protocol->GetProtocolNumber()) << " on interface "
946 << int(interfaceIndex));
947 }
948 else
949 {
950 m_protocols.erase(key);
951 }
952}
953
955Ipv4L3ClickProtocol::GetProtocol(int protocolNumber) const
956{
957 NS_LOG_FUNCTION(this << protocolNumber);
958
959 return GetProtocol(protocolNumber, -1);
960}
961
963Ipv4L3ClickProtocol::GetProtocol(int protocolNumber, int32_t interfaceIndex) const
964{
965 NS_LOG_FUNCTION(this << protocolNumber << interfaceIndex);
966
967 L4ListKey_t key;
968 if (interfaceIndex >= 0)
969 {
970 // try the interface-specific protocol.
971 key = std::make_pair(protocolNumber, interfaceIndex);
972 auto i = m_protocols.find(key);
973 if (i != m_protocols.end())
974 {
975 return i->second;
976 }
977 }
978 // try the generic protocol.
979 key = std::make_pair(protocolNumber, -1);
980 auto i = m_protocols.find(key);
981 if (i != m_protocols.end())
982 {
983 return i->second;
984 }
985
986 return nullptr;
987}
988
989} // namespace ns3
a polymophic address class
Definition: address.h:101
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.
Definition: ipv4-address.h:42
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:34
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:309
Ipv4Address GetSource() const
Definition: ipv4-header.cc:302
void SetDontFragment()
Don't fragment this packet: if you need to anyway, drop it.
Definition: ipv4-header.cc:224
void SetPayloadSize(uint16_t size)
Definition: ipv4-header.cc:57
uint8_t GetProtocol() const
Definition: ipv4-header.cc:281
void SetTtl(uint8_t ttl)
Definition: ipv4-header.cc:267
Ipv4Address GetDestination() const
Definition: ipv4-header.cc:316
void SetMayFragment()
If you need to fragment this packet, you can do it.
Definition: ipv4-header.cc:231
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:288
void SetIdentification(uint16_t identification)
Definition: ipv4-header.cc:78
void EnableChecksum()
Enable checksum calculation for this header.
Definition: ipv4-header.cc:50
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:295
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:79
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.
bool m_weakEsModel
Whether to use weak Es model.
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 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
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
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.
uint8_t m_defaultTtl
Default TTL.
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
Definition: ipv4-address.h:257
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:300
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:138
uint32_t GetNDevices() const
Definition: node.cc:162
uint32_t GetId() const
Definition: node.cc:117
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:152
static bool ChecksumEnabled()
Definition: node.cc:285
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:331
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition: socket.h:1122
uint8_t GetTtl() const
Get the tag's TTL.
Definition: socket.cc:609
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:930
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Definition: object-vector.h:40
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:76
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:261
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:579
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704
-ns3 Test suite for the ns3 wrapper script