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