A Discrete-Event Network Simulator
API
udp-socket-impl.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/node.h"
23 #include "ns3/inet-socket-address.h"
24 #include "ns3/inet6-socket-address.h"
25 #include "ns3/ipv4-route.h"
26 #include "ns3/ipv6-route.h"
27 #include "ns3/ipv4.h"
28 #include "ns3/ipv6.h"
29 #include "ns3/ipv6-l3-protocol.h"
30 #include "ns3/ipv4-header.h"
31 #include "ns3/ipv4-routing-protocol.h"
32 #include "ns3/ipv6-routing-protocol.h"
33 #include "ns3/udp-socket-factory.h"
34 #include "ns3/trace-source-accessor.h"
35 #include "ns3/ipv4-packet-info-tag.h"
36 #include "ns3/ipv6-packet-info-tag.h"
37 #include "udp-socket-impl.h"
38 #include "udp-l4-protocol.h"
39 #include "ipv4-end-point.h"
40 #include "ipv6-end-point.h"
41 #include <limits>
42 
43 namespace ns3 {
44 
45 NS_LOG_COMPONENT_DEFINE ("UdpSocketImpl");
46 
47 NS_OBJECT_ENSURE_REGISTERED (UdpSocketImpl);
48 
49 // The correct maximum UDP message size is 65507, as determined by the following formula:
50 // 0xffff - (sizeof(IP Header) + sizeof(UDP Header)) = 65535-(20+8) = 65507
51 // \todo MAX_IPV4_UDP_DATAGRAM_SIZE is correct only for IPv4
52 static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE = 65507;
53 
54 // Add attributes generic to all UdpSockets to base class UdpSocket
55 TypeId
57 {
58  static TypeId tid = TypeId ("ns3::UdpSocketImpl")
59  .SetParent<UdpSocket> ()
60  .SetGroupName ("Internet")
61  .AddConstructor<UdpSocketImpl> ()
62  .AddTraceSource ("Drop",
63  "Drop UDP packet due to receive buffer overflow",
65  "ns3::Packet::TracedCallback")
66  .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is received on this socket.",
67  CallbackValue (),
70  .AddAttribute ("IcmpCallback6", "Callback invoked whenever an icmpv6 error is received on this socket.",
71  CallbackValue (),
74  ;
75  return tid;
76 }
77 
79  : m_endPoint (0),
80  m_endPoint6 (0),
81  m_node (0),
82  m_udp (0),
83  m_errno (ERROR_NOTERROR),
84  m_shutdownSend (false),
85  m_shutdownRecv (false),
86  m_connected (false),
87  m_rxAvailable (0)
88 {
89  NS_LOG_FUNCTION (this);
90  m_allowBroadcast = false;
91 }
92 
94 {
95  NS_LOG_FUNCTION (this);
96 
98  m_node = 0;
104  if (m_endPoint != 0)
105  {
106  NS_ASSERT (m_udp != 0);
115  NS_ASSERT (m_endPoint != 0);
116  m_udp->DeAllocate (m_endPoint);
117  NS_ASSERT (m_endPoint == 0);
118  }
119  if (m_endPoint6 != 0)
120  {
121  NS_ASSERT (m_udp != 0);
130  NS_ASSERT (m_endPoint6 != 0);
131  m_udp->DeAllocate (m_endPoint6);
132  NS_ASSERT (m_endPoint6 == 0);
133  }
134  m_udp = 0;
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION (this << node);
141  m_node = node;
142 
143 }
144 void
146 {
147  NS_LOG_FUNCTION (this << udp);
148  m_udp = udp;
149 }
150 
151 
153 UdpSocketImpl::GetErrno (void) const
154 {
155  NS_LOG_FUNCTION (this);
156  return m_errno;
157 }
158 
160 UdpSocketImpl::GetSocketType (void) const
161 {
162  return NS3_SOCK_DGRAM;
163 }
164 
165 Ptr<Node>
167 {
168  NS_LOG_FUNCTION (this);
169  return m_node;
170 }
171 
172 void
174 {
175  NS_LOG_FUNCTION (this);
176  m_endPoint = 0;
177 }
178 
179 void
181 {
182  NS_LOG_FUNCTION (this);
183  m_endPoint6 = 0;
184 }
185 
186 /* Deallocate the end point and cancel all the timers */
187 void
189 {
190  if (m_endPoint != 0)
191  {
192  m_endPoint->SetDestroyCallback (MakeNullCallback<void> ());
193  m_udp->DeAllocate (m_endPoint);
194  m_endPoint = 0;
195  }
196  if (m_endPoint6 != 0)
197  {
198  m_endPoint6->SetDestroyCallback (MakeNullCallback<void> ());
199  m_udp->DeAllocate (m_endPoint6);
200  m_endPoint6 = 0;
201  }
202 }
203 
204 
205 int
207 {
208  NS_LOG_FUNCTION (this);
209  bool done = false;
210  if (m_endPoint != 0)
211  {
215  done = true;
216  }
217  if (m_endPoint6 != 0)
218  {
222  done = true;
223  }
224  if (done)
225  {
226  return 0;
227  }
228  return -1;
229 }
230 
231 int
233 {
234  NS_LOG_FUNCTION (this);
235  m_endPoint = m_udp->Allocate ();
236  if (m_boundnetdevice)
237  {
239  }
240  return FinishBind ();
241 }
242 
243 int
245 {
246  NS_LOG_FUNCTION (this);
247  m_endPoint6 = m_udp->Allocate6 ();
248  if (m_boundnetdevice)
249  {
251  }
252  return FinishBind ();
253 }
254 
255 int
257 {
258  NS_LOG_FUNCTION (this << address);
259 
261  {
262  NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated.");
263 
265  Ipv4Address ipv4 = transport.GetIpv4 ();
266  uint16_t port = transport.GetPort ();
267  SetIpTos (transport.GetTos ());
268  if (ipv4 == Ipv4Address::GetAny () && port == 0)
269  {
270  m_endPoint = m_udp->Allocate ();
271  }
272  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
273  {
274  m_endPoint = m_udp->Allocate (GetBoundNetDevice (), port);
275  }
276  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
277  {
278  m_endPoint = m_udp->Allocate (ipv4);
279  }
280  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
281  {
282  m_endPoint = m_udp->Allocate (GetBoundNetDevice (), ipv4, port);
283  }
284  if (0 == m_endPoint)
285  {
287  return -1;
288  }
289  if (m_boundnetdevice)
290  {
292  }
293 
294  }
296  {
297  NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated.");
298 
300  Ipv6Address ipv6 = transport.GetIpv6 ();
301  uint16_t port = transport.GetPort ();
302  if (ipv6 == Ipv6Address::GetAny () && port == 0)
303  {
304  m_endPoint6 = m_udp->Allocate6 ();
305  }
306  else if (ipv6 == Ipv6Address::GetAny () && port != 0)
307  {
308  m_endPoint6 = m_udp->Allocate6 (GetBoundNetDevice (), port);
309  }
310  else if (ipv6 != Ipv6Address::GetAny () && port == 0)
311  {
312  m_endPoint6 = m_udp->Allocate6 (ipv6);
313  }
314  else if (ipv6 != Ipv6Address::GetAny () && port != 0)
315  {
316  m_endPoint6 = m_udp->Allocate6 (GetBoundNetDevice (), ipv6, port);
317  }
318  if (0 == m_endPoint6)
319  {
321  return -1;
322  }
323  if (m_boundnetdevice)
324  {
326  }
327 
328  if (ipv6.IsMulticast ())
329  {
331  if (ipv6l3)
332  {
333  if (m_boundnetdevice == 0)
334  {
335  ipv6l3->AddMulticastAddress (ipv6);
336  }
337  else
338  {
339  uint32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
340  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
341  }
342  }
343  }
344  }
345  else
346  {
347  NS_LOG_ERROR ("Not IsMatchingType");
349  return -1;
350  }
351 
352  return FinishBind ();
353 }
354 
355 int
357 {
358  NS_LOG_FUNCTION (this);
359  m_shutdownSend = true;
360  return 0;
361 }
362 
363 int
365 {
366  NS_LOG_FUNCTION (this);
367  m_shutdownRecv = true;
368  if (m_endPoint)
369  {
370  m_endPoint->SetRxEnabled (false);
371  }
372  if (m_endPoint6)
373  {
374  m_endPoint6->SetRxEnabled (false);
375  }
376  return 0;
377 }
378 
379 int
381 {
382  NS_LOG_FUNCTION (this);
383  if (m_shutdownRecv == true && m_shutdownSend == true)
384  {
386  return -1;
387  }
388  Ipv6LeaveGroup ();
389  m_shutdownRecv = true;
390  m_shutdownSend = true;
392  return 0;
393 }
394 
395 int
397 {
398  NS_LOG_FUNCTION (this << address);
400  {
402  m_defaultAddress = Address(transport.GetIpv4 ());
403  m_defaultPort = transport.GetPort ();
404  SetIpTos (transport.GetTos ());
405  m_connected = true;
407  }
409  {
411  m_defaultAddress = Address(transport.GetIpv6 ());
412  m_defaultPort = transport.GetPort ();
413  m_connected = true;
415  }
416  else
417  {
419  return -1;
420  }
421 
422  return 0;
423 }
424 
425 int
427 {
429  return -1;
430 }
431 
432 int
433 UdpSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
434 {
435  NS_LOG_FUNCTION (this << p << flags);
436 
437  if (!m_connected)
438  {
440  return -1;
441  }
442 
443  return DoSend (p);
444 }
445 
446 int
448 {
449  NS_LOG_FUNCTION (this << p);
451  {
452  if (Bind () == -1)
453  {
454  NS_ASSERT (m_endPoint == 0);
455  return -1;
456  }
457  NS_ASSERT (m_endPoint != 0);
458  }
459  else if ((m_endPoint6 == 0) && (Ipv6Address::IsMatchingType(m_defaultAddress) == true))
460  {
461  if (Bind6 () == -1)
462  {
463  NS_ASSERT (m_endPoint6 == 0);
464  return -1;
465  }
466  NS_ASSERT (m_endPoint6 != 0);
467  }
468  if (m_shutdownSend)
469  {
471  return -1;
472  }
473 
475  {
477  }
479  {
481  }
482 
484  return(-1);
485 }
486 
487 int
488 UdpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address dest, uint16_t port, uint8_t tos)
489 {
490  NS_LOG_FUNCTION (this << p << dest << port << (uint16_t) tos);
491  if (m_boundnetdevice)
492  {
493  NS_LOG_LOGIC ("Bound interface number " << m_boundnetdevice->GetIfIndex ());
494  }
495  if (m_endPoint == 0)
496  {
497  if (Bind () == -1)
498  {
499  NS_ASSERT (m_endPoint == 0);
500  return -1;
501  }
502  NS_ASSERT (m_endPoint != 0);
503  }
504  if (m_shutdownSend)
505  {
507  return -1;
508  }
509 
510  if (p->GetSize () > GetTxAvailable () )
511  {
513  return -1;
514  }
515 
516  uint8_t priority = GetPriority ();
517  if (tos)
518  {
519  SocketIpTosTag ipTosTag;
520  ipTosTag.SetTos (tos);
521  // This packet may already have a SocketIpTosTag (see BUG 2440)
522  p->ReplacePacketTag (ipTosTag);
523  priority = IpTos2Priority (tos);
524  }
525 
526  if (priority)
527  {
528  SocketPriorityTag priorityTag;
529  priorityTag.SetPriority (priority);
530  p->ReplacePacketTag (priorityTag);
531  }
532 
533  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
534 
535  // Locally override the IP TTL for this socket
536  // We cannot directly modify the TTL at this stage, so we set a Packet tag
537  // The destination can be either multicast, unicast/anycast, or
538  // either all-hosts broadcast or limited (subnet-directed) broadcast.
539  // For the latter two broadcast types, the TTL will later be set to one
540  // irrespective of what is set in these socket options. So, this tagging
541  // may end up setting the TTL of a limited broadcast packet to be
542  // the same as a unicast, but it will be fixed further down the stack
543  if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
544  {
545  SocketIpTtlTag tag;
546  tag.SetTtl (m_ipMulticastTtl);
547  p->AddPacketTag (tag);
548  }
549  else if (IsManualIpTtl () && GetIpTtl () != 0 && !dest.IsMulticast () && !dest.IsBroadcast ())
550  {
551  SocketIpTtlTag tag;
552  tag.SetTtl (GetIpTtl ());
553  p->AddPacketTag (tag);
554  }
555  {
557  bool found = p->RemovePacketTag (tag);
558  if (!found)
559  {
560  if (m_mtuDiscover)
561  {
562  tag.Enable ();
563  }
564  else
565  {
566  tag.Disable ();
567  }
568  p->AddPacketTag (tag);
569  }
570  }
571 
572  // Note that some systems will only send limited broadcast packets
573  // out of the "default" interface; here we send it out all interfaces
574  if (dest.IsBroadcast ())
575  {
576  if (!m_allowBroadcast)
577  {
579  return -1;
580  }
581  NS_LOG_LOGIC ("Limited broadcast start.");
582  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
583  {
584  // Get the primary address
585  Ipv4InterfaceAddress iaddr = ipv4->GetAddress (i, 0);
586  Ipv4Address addri = iaddr.GetLocal ();
587  if (addri == Ipv4Address ("127.0.0.1"))
588  continue;
589  // Check if interface-bound socket
590  if (m_boundnetdevice)
591  {
592  if (ipv4->GetNetDevice (i) != m_boundnetdevice)
593  continue;
594  }
595  NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << dest);
596  m_udp->Send (p->Copy (), addri, dest,
598  NotifyDataSent (p->GetSize ());
600  }
601  NS_LOG_LOGIC ("Limited broadcast end.");
602  return p->GetSize ();
603  }
605  {
606  m_udp->Send (p->Copy (), m_endPoint->GetLocalAddress (), dest,
607  m_endPoint->GetLocalPort (), port, 0);
608  NotifyDataSent (p->GetSize ());
610  return p->GetSize ();
611  }
612  else if (ipv4->GetRoutingProtocol () != 0)
613  {
614  Ipv4Header header;
615  header.SetDestination (dest);
617  Socket::SocketErrno errno_;
618  Ptr<Ipv4Route> route;
619  Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a specific device
620  // TBD-- we could cache the route and just check its validity
621  route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
622  if (route != 0)
623  {
624  NS_LOG_LOGIC ("Route exists");
625  if (!m_allowBroadcast)
626  {
627  // Here we try to route subnet-directed broadcasts
628  uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->GetOutputDevice ());
629  uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
630  for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
631  {
632  Ipv4InterfaceAddress ifAddr = ipv4->GetAddress (outputIfIndex, addrI);
633  if (dest == ifAddr.GetBroadcast ())
634  {
636  return -1;
637  }
638  }
639  }
640 
641  header.SetSource (route->GetSource ());
642  m_udp->Send (p->Copy (), header.GetSource (), header.GetDestination (),
643  m_endPoint->GetLocalPort (), port, route);
644  NotifyDataSent (p->GetSize ());
645  return p->GetSize ();
646  }
647  else
648  {
649  NS_LOG_LOGIC ("No route to destination");
650  NS_LOG_ERROR (errno_);
651  m_errno = errno_;
652  return -1;
653  }
654  }
655  else
656  {
657  NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
659  return -1;
660  }
661 
662  return 0;
663 }
664 
665 int
667 {
668  NS_LOG_FUNCTION (this << p << dest << port);
669 
670  if (dest.IsIpv4MappedAddress ())
671  {
672  return (DoSendTo(p, dest.GetIpv4MappedAddress (), port, 0));
673  }
674  if (m_boundnetdevice)
675  {
676  NS_LOG_LOGIC ("Bound interface number " << m_boundnetdevice->GetIfIndex ());
677  }
678  if (m_endPoint6 == 0)
679  {
680  if (Bind6 () == -1)
681  {
682  NS_ASSERT (m_endPoint6 == 0);
683  return -1;
684  }
685  NS_ASSERT (m_endPoint6 != 0);
686  }
687  if (m_shutdownSend)
688  {
690  return -1;
691  }
692 
693  if (p->GetSize () > GetTxAvailable () )
694  {
696  return -1;
697  }
698 
699  if (IsManualIpv6Tclass ())
700  {
701  SocketIpv6TclassTag ipTclassTag;
702  ipTclassTag.SetTclass (GetIpv6Tclass ());
703  p->AddPacketTag (ipTclassTag);
704  }
705 
706  uint8_t priority = GetPriority ();
707  if (priority)
708  {
709  SocketPriorityTag priorityTag;
710  priorityTag.SetPriority (priority);
711  p->ReplacePacketTag (priorityTag);
712  }
713 
714  Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
715 
716  // Locally override the IP TTL for this socket
717  // We cannot directly modify the TTL at this stage, so we set a Packet tag
718  // The destination can be either multicast, unicast/anycast, or
719  // either all-hosts broadcast or limited (subnet-directed) broadcast.
720  // For the latter two broadcast types, the TTL will later be set to one
721  // irrespective of what is set in these socket options. So, this tagging
722  // may end up setting the TTL of a limited broadcast packet to be
723  // the same as a unicast, but it will be fixed further down the stack
724  if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
725  {
728  p->AddPacketTag (tag);
729  }
730  else if (IsManualIpv6HopLimit () && GetIpv6HopLimit () != 0 && !dest.IsMulticast ())
731  {
733  tag.SetHopLimit (GetIpv6HopLimit ());
734  p->AddPacketTag (tag);
735  }
736  // There is no analgous to an IPv4 broadcast address in IPv6.
737  // Instead, we use a set of link-local, site-local, and global
738  // multicast addresses. The Ipv6 routing layers should all
739  // provide an interface-specific route to these addresses such
740  // that we can treat these multicast addresses as "not broadcast"
741 
743  {
744  m_udp->Send (p->Copy (), m_endPoint6->GetLocalAddress (), dest,
745  m_endPoint6->GetLocalPort (), port, 0);
746  NotifyDataSent (p->GetSize ());
748  return p->GetSize ();
749  }
750  else if (ipv6->GetRoutingProtocol () != 0)
751  {
752  Ipv6Header header;
753  header.SetDestination (dest);
755  Socket::SocketErrno errno_;
756  Ptr<Ipv6Route> route;
757  Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a specific device
758  // TBD-- we could cache the route and just check its validity
759  route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
760  if (route != 0)
761  {
762  NS_LOG_LOGIC ("Route exists");
763  header.SetSource (route->GetSource ());
764  m_udp->Send (p->Copy (), header.GetSource (), header.GetDestination (),
765  m_endPoint6->GetLocalPort (), port, route);
766  NotifyDataSent (p->GetSize ());
767  return p->GetSize ();
768  }
769  else
770  {
771  NS_LOG_LOGIC ("No route to destination");
772  NS_LOG_ERROR (errno_);
773  m_errno = errno_;
774  return -1;
775  }
776  }
777  else
778  {
779  NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
781  return -1;
782  }
783 
784  return 0;
785 }
786 
787 
788 // maximum message size for UDP broadcast is limited by MTU
789 // size of underlying link; we are not checking that now.
790 // \todo Check MTU size of underlying link
791 uint32_t
793 {
794  NS_LOG_FUNCTION (this);
795  // No finite send buffer is modelled, but we must respect
796  // the maximum size of an IP datagram (65535 bytes - headers).
798 }
799 
800 int
802 {
803  NS_LOG_FUNCTION (this << p << flags << address);
805  {
807  Ipv4Address ipv4 = transport.GetIpv4 ();
808  uint16_t port = transport.GetPort ();
809  uint8_t tos = transport.GetTos ();
810  return DoSendTo (p, ipv4, port, tos);
811  }
813  {
815  Ipv6Address ipv6 = transport.GetIpv6 ();
816  uint16_t port = transport.GetPort ();
817  return DoSendTo (p, ipv6, port);
818  }
819  return -1;
820 }
821 
822 uint32_t
824 {
825  NS_LOG_FUNCTION (this);
826  // We separately maintain this state to avoid walking the queue
827  // every time this might be called
828  return m_rxAvailable;
829 }
830 
832 UdpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
833 {
834  NS_LOG_FUNCTION (this << maxSize << flags);
835 
836  Address fromAddress;
837  Ptr<Packet> packet = RecvFrom (maxSize, flags, fromAddress);
838  return packet;
839 }
840 
842 UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
843  Address &fromAddress)
844 {
845  NS_LOG_FUNCTION (this << maxSize << flags);
846 
847  if (m_deliveryQueue.empty () )
848  {
850  return 0;
851  }
852  Ptr<Packet> p = m_deliveryQueue.front ().first;
853  fromAddress = m_deliveryQueue.front ().second;
854 
855  if (p->GetSize () <= maxSize)
856  {
857  m_deliveryQueue.pop ();
858  m_rxAvailable -= p->GetSize ();
859  }
860  else
861  {
862  p = 0;
863  }
864  return p;
865 }
866 
867 int
869 {
870  NS_LOG_FUNCTION (this << address);
871  if (m_endPoint != 0)
872  {
874  }
875  else if (m_endPoint6 != 0)
876  {
878  }
879  else
880  { // It is possible to call this method on a socket without a name
881  // in which case, behavior is unspecified
882  // Should this return an InetSocketAddress or an Inet6SocketAddress?
884  }
885  return 0;
886 }
887 
888 int
890 {
891  NS_LOG_FUNCTION (this << address);
892 
893  if (!m_connected)
894  {
896  return -1;
897  }
898 
900  {
902  InetSocketAddress inet (addr, m_defaultPort);
903  inet.SetTos (GetIpTos ());
904  address = inet;
905  }
907  {
910  }
911  else
912  {
913  NS_ASSERT_MSG (false, "unexpected address type");
914  }
915 
916  return 0;
917 }
918 
919 int
920 UdpSocketImpl::MulticastJoinGroup (uint32_t interface, const Address &groupAddress)
921 {
922  NS_LOG_FUNCTION (interface << groupAddress);
923  /*
924  1) sanity check interface
925  2) sanity check that it has not been called yet on this interface/group
926  3) determine address family of groupAddress
927  4) locally store a list of (interface, groupAddress)
928  5) call ipv4->MulticastJoinGroup () or Ipv6->MulticastJoinGroup ()
929  */
930  return 0;
931 }
932 
933 int
934 UdpSocketImpl::MulticastLeaveGroup (uint32_t interface, const Address &groupAddress)
935 {
936  NS_LOG_FUNCTION (interface << groupAddress);
937  /*
938  1) sanity check interface
939  2) determine address family of groupAddress
940  3) delete from local list of (interface, groupAddress); raise a LOG_WARN
941  if not already present (but return 0)
942  5) call ipv4->MulticastLeaveGroup () or Ipv6->MulticastLeaveGroup ()
943  */
944  return 0;
945 }
946 
947 void
949 {
950  NS_LOG_FUNCTION (netdevice);
951 
952  Ptr<NetDevice> oldBoundNetDevice = m_boundnetdevice;
953 
954  Socket::BindToNetDevice (netdevice); // Includes sanity check
955  if (m_endPoint != 0)
956  {
957  m_endPoint->BindToNetDevice (netdevice);
958  }
959 
960  if (m_endPoint6 != 0)
961  {
962  m_endPoint6->BindToNetDevice (netdevice);
963 
964  // The following is to fix the multicast distribution inside the node
965  // and to upgrade it to the actual bound NetDevice.
967  {
969  if (ipv6l3)
970  {
971  // Cleanup old one
972  if (oldBoundNetDevice)
973  {
974  uint32_t index = ipv6l3->GetInterfaceForDevice (oldBoundNetDevice);
975  ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress (), index);
976  }
977  else
978  {
979  ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ());
980  }
981  // add new one
982  if (netdevice)
983  {
984  uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
985  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
986  }
987  else
988  {
989  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress ());
990  }
991  }
992  }
993  }
994 
995  return;
996 }
997 
998 void
1000  Ptr<Ipv4Interface> incomingInterface)
1001 {
1002  NS_LOG_FUNCTION (this << packet << header << port);
1003 
1004  if (m_shutdownRecv)
1005  {
1006  return;
1007  }
1008 
1009  // Should check via getsockopt ()..
1010  if (IsRecvPktInfo ())
1011  {
1012  Ipv4PacketInfoTag tag;
1013  packet->RemovePacketTag (tag);
1014  tag.SetAddress (header.GetDestination ());
1015  tag.SetTtl (header.GetTtl ());
1016  tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
1017  packet->AddPacketTag (tag);
1018  }
1019 
1020  //Check only version 4 options
1021  if (IsIpRecvTos ())
1022  {
1023  SocketIpTosTag ipTosTag;
1024  ipTosTag.SetTos (header.GetTos ());
1025  packet->AddPacketTag (ipTosTag);
1026  }
1027 
1028  if (IsIpRecvTtl ())
1029  {
1030  SocketIpTtlTag ipTtlTag;
1031  ipTtlTag.SetTtl (header.GetTtl ());
1032  packet->AddPacketTag (ipTtlTag);
1033  }
1034 
1035  // in case the packet still has a priority tag attached, remove it
1036  SocketPriorityTag priorityTag;
1037  packet->RemovePacketTag (priorityTag);
1038 
1039  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
1040  {
1042  m_deliveryQueue.push (std::make_pair (packet, address));
1043  m_rxAvailable += packet->GetSize ();
1044  NotifyDataRecv ();
1045  }
1046  else
1047  {
1048  // In general, this case should not occur unless the
1049  // receiving application reads data from this socket slowly
1050  // in comparison to the arrival rate
1051  //
1052  // drop and trace packet
1053  NS_LOG_WARN ("No receive buffer space available. Drop.");
1054  m_dropTrace (packet);
1055  }
1056 }
1057 
1058 void
1059 UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface)
1060 {
1061  NS_LOG_FUNCTION (this << packet << header.GetSource () << port);
1062 
1063  if (m_shutdownRecv)
1064  {
1065  return;
1066  }
1067 
1068  // Should check via getsockopt ().
1069  if (IsRecvPktInfo ())
1070  {
1071  Ipv6PacketInfoTag tag;
1072  packet->RemovePacketTag (tag);
1073  tag.SetAddress (header.GetDestination ());
1074  tag.SetHoplimit (header.GetHopLimit ());
1075  tag.SetTrafficClass (header.GetTrafficClass ());
1076  tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
1077  packet->AddPacketTag (tag);
1078  }
1079 
1080  // Check only version 6 options
1081  if (IsIpv6RecvTclass ())
1082  {
1083  SocketIpv6TclassTag ipTclassTag;
1084  ipTclassTag.SetTclass (header.GetTrafficClass ());
1085  packet->AddPacketTag (ipTclassTag);
1086  }
1087 
1088  if (IsIpv6RecvHopLimit ())
1089  {
1090  SocketIpv6HopLimitTag ipHopLimitTag;
1091  ipHopLimitTag.SetHopLimit (header.GetHopLimit ());
1092  packet->AddPacketTag (ipHopLimitTag);
1093  }
1094 
1095  // in case the packet still has a priority tag attached, remove it
1096  SocketPriorityTag priorityTag;
1097  packet->RemovePacketTag (priorityTag);
1098 
1099  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
1100  {
1102  m_deliveryQueue.push (std::make_pair (packet, address));
1103  m_rxAvailable += packet->GetSize ();
1104  NotifyDataRecv ();
1105  }
1106  else
1107  {
1108  // In general, this case should not occur unless the
1109  // receiving application reads data from this socket slowly
1110  // in comparison to the arrival rate
1111  //
1112  // drop and trace packet
1113  NS_LOG_WARN ("No receive buffer space available. Drop.");
1114  m_dropTrace (packet);
1115  }
1116 }
1117 
1118 void
1119 UdpSocketImpl::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
1120  uint8_t icmpType, uint8_t icmpCode,
1121  uint32_t icmpInfo)
1122 {
1123  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1124  (uint32_t)icmpCode << icmpInfo);
1125  if (!m_icmpCallback.IsNull ())
1126  {
1127  m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1128  }
1129 }
1130 
1131 void
1132 UdpSocketImpl::ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
1133  uint8_t icmpType, uint8_t icmpCode,
1134  uint32_t icmpInfo)
1135 {
1136  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1137  (uint32_t)icmpCode << icmpInfo);
1138  if (!m_icmpCallback6.IsNull ())
1139  {
1140  m_icmpCallback6 (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1141  }
1142 }
1143 
1144 void
1146 {
1147  m_rcvBufSize = size;
1148 }
1149 
1150 uint32_t
1152 {
1153  return m_rcvBufSize;
1154 }
1155 
1156 void
1158 {
1159  m_ipMulticastTtl = ipTtl;
1160 }
1161 
1162 uint8_t
1164 {
1165  return m_ipMulticastTtl;
1166 }
1167 
1168 void
1170 {
1171  m_ipMulticastIf = ipIf;
1172 }
1173 
1174 int32_t
1176 {
1177  return m_ipMulticastIf;
1178 }
1179 
1180 void
1182 {
1183  m_ipMulticastLoop = loop;
1184 }
1185 
1186 bool
1188 {
1189  return m_ipMulticastLoop;
1190 }
1191 
1192 void
1194 {
1195  m_mtuDiscover = discover;
1196 }
1197 bool
1199 {
1200  return m_mtuDiscover;
1201 }
1202 
1203 bool
1205 {
1206  m_allowBroadcast = allowBroadcast;
1207  return true;
1208 }
1209 
1210 bool
1212 {
1213  return m_allowBroadcast;
1214 }
1215 
1216 void
1217 UdpSocketImpl::Ipv6JoinGroup (Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector<Ipv6Address> sourceAddresses)
1218 {
1219  NS_LOG_FUNCTION (this << address << &filterMode << &sourceAddresses);
1220 
1221  // We can join only one multicast group (or change its params)
1222  NS_ASSERT_MSG ((m_ipv6MulticastGroupAddress == address || m_ipv6MulticastGroupAddress.IsAny ()), "Can join only one IPv6 multicast group.");
1223 
1225 
1227  if (ipv6l3)
1228  {
1229  if (filterMode == INCLUDE && sourceAddresses.empty ())
1230  {
1231  // it is a leave
1232  if (m_boundnetdevice)
1233  {
1234  int32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
1235  NS_ASSERT_MSG (index >= 0, "Interface without a valid index");
1236  ipv6l3->RemoveMulticastAddress (address, index);
1237  }
1238  else
1239  {
1240  ipv6l3->RemoveMulticastAddress (address);
1241  }
1242  }
1243  else
1244  {
1245  // it is a join or a modification
1246  if (m_boundnetdevice)
1247  {
1248  int32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
1249  NS_ASSERT_MSG (index >= 0, "Interface without a valid index");
1250  ipv6l3->AddMulticastAddress (address, index);
1251  }
1252  else
1253  {
1254  ipv6l3->AddMulticastAddress (address);
1255  }
1256  }
1257  }
1258 }
1259 
1260 } // namespace ns3
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::Socket::NotifyConnectionSucceeded
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
Definition: socket.cc:217
ns3::UdpSocketImpl::UdpSocketImpl
UdpSocketImpl()
Create an unbound udp socket.
Definition: udp-socket-impl.cc:78
ns3::Ipv4Header
Packet header for IPv4.
Definition: ipv4-header.h:34
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::Packet::ReplacePacketTag
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:970
ns3::Socket::ERROR_MSGSIZE
@ ERROR_MSGSIZE
Definition: socket.h:86
ns3::Ipv4EndPoint::SetRxEnabled
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
Definition: ipv4-end-point.cc:157
ns3::Inet6SocketAddress::IsMatchingType
static bool IsMatchingType(const Address &addr)
If the address match.
Definition: inet6-socket-address.cc:89
ns3::UdpSocketImpl::SetIpMulticastLoop
virtual void SetIpMulticastLoop(bool loop)
Set the IP multicast loop capability.
Definition: udp-socket-impl.cc:1181
ns3::UdpSocketImpl::m_endPoint6
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
Definition: udp-socket-impl.h:237
ns3::UdpSocketImpl::m_ipMulticastIf
int32_t m_ipMulticastIf
Multicast Interface.
Definition: udp-socket-impl.h:259
udp-l4-protocol.h
ns3::Socket::NS3_SOCK_DGRAM
@ NS3_SOCK_DGRAM
Definition: socket.h:107
ns3::Ipv6Address::IsMatchingType
static bool IsMatchingType(const Address &address)
If the Address matches the type.
Definition: ipv6-address.cc:827
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::InetSocketAddress::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition: inet-socket-address.cc:103
ns3::Socket::SetIpTos
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition: socket.cc:437
ns3::UdpSocketImpl::SetRcvBufSize
virtual void SetRcvBufSize(uint32_t size)
Set the receiving buffer size.
Definition: udp-socket-impl.cc:1145
ns3::UdpSocketImpl::GetSockName
virtual int GetSockName(Address &address) const
Get socket address.
Definition: udp-socket-impl.cc:868
ns3::UdpSocketImpl::ForwardIcmp6
void ForwardIcmp6(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP.
Definition: udp-socket-impl.cc:1132
ns3::UdpSocketImpl::m_dropTrace
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
Definition: udp-socket-impl.h:245
ns3::Ipv4Address::IsMatchingType
static bool IsMatchingType(const Address &address)
Definition: ipv4-address.cc:350
ns3::Socket::IsIpRecvTtl
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
Definition: socket.cc:532
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::Socket::SocketErrno
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
ns3::InetSocketAddress::GetPort
uint16_t GetPort(void) const
Definition: inet-socket-address.cc:65
ns3::UdpSocketImpl::GetTxAvailable
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Definition: udp-socket-impl.cc:792
ns3::Ipv6Address::IsIpv4MappedAddress
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
Definition: ipv6-address.cc:734
ns3::UdpSocketImpl::m_ipMulticastLoop
bool m_ipMulticastLoop
Allow multicast loop.
Definition: udp-socket-impl.h:260
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::UdpSocketImpl::m_icmpCallback
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
Definition: udp-socket-impl.h:240
ns3::UdpSocketImpl::m_rcvBufSize
uint32_t m_rcvBufSize
Receive buffer size.
Definition: udp-socket-impl.h:257
ns3::Socket::Recv
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
ns3::UdpSocketImpl::RecvFrom
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
Definition: udp-socket-impl.cc:842
ns3::Socket::ERROR_BADF
@ ERROR_BADF
Definition: socket.h:92
ns3::UdpSocketImpl::m_shutdownRecv
bool m_shutdownRecv
Receive no longer allowed.
Definition: udp-socket-impl.h:249
ns3::UdpSocketImpl::m_connected
bool m_connected
Connection established.
Definition: udp-socket-impl.h:250
ns3::Socket::ERROR_AGAIN
@ ERROR_AGAIN
Definition: socket.h:87
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::Ipv4Interface::GetDevice
Ptr< NetDevice > GetDevice(void) const
Definition: ipv4-interface.cc:131
ns3::Ipv6EndPoint::GetLocalAddress
Ipv6Address GetLocalAddress()
Get the local address.
Definition: ipv6-end-point.cc:52
ns3::Ipv6PacketInfoTag::SetAddress
void SetAddress(Ipv6Address addr)
Set the tag's address.
Definition: ipv6-packet-info-tag.cc:37
ns3::UdpSocketImpl::SetMtuDiscover
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
Definition: udp-socket-impl.cc:1193
ns3::Ipv6L3Protocol
IPv6 layer implementation.
Definition: ipv6-l3-protocol.h:63
ns3::Socket::ERROR_SHUTDOWN
@ ERROR_SHUTDOWN
Definition: socket.h:88
ns3::Ipv4EndPoint::BindToNetDevice
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: ipv4-end-point.cc:96
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
ns3::UdpSocketImpl::GetPeerName
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
Definition: udp-socket-impl.cc:889
ns3::UdpSocketImpl::GetIpMulticastLoop
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
Definition: udp-socket-impl.cc:1187
ns3::UdpSocketImpl::Close
virtual int Close(void)
Close a socket.
Definition: udp-socket-impl.cc:380
ns3::UdpSocketImpl::m_shutdownSend
bool m_shutdownSend
Send no longer allowed.
Definition: udp-socket-impl.h:248
ns3::Ipv6PacketInfoTag::SetHoplimit
void SetHoplimit(uint8_t ttl)
Set the tag's Hop Limit.
Definition: ipv6-packet-info-tag.cc:61
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::Socket::IsIpv6RecvHopLimit
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Definition: socket.cc:557
ns3::UdpSocketImpl::ForwardUp
void ForwardUp(Ptr< Packet > packet, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
Definition: udp-socket-impl.cc:999
ns3::Ipv6EndPoint::BindToNetDevice
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: ipv6-end-point.cc:82
ns3::SocketIpTtlTag::SetTtl
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:604
ns3::UdpSocketImpl::m_allowBroadcast
bool m_allowBroadcast
Allow send broadcast packets.
Definition: udp-socket-impl.h:251
ns3::UdpSocketImpl::m_endPoint
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
Definition: udp-socket-impl.h:236
ns3::UdpSocketImpl::GetSocketType
virtual enum SocketType GetSocketType(void) const
Definition: udp-socket-impl.cc:160
ns3::Ipv4PacketInfoTag::SetTtl
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
Definition: ipv4-packet-info-tag.cc:68
ns3::UdpSocketImpl::m_udp
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
Definition: udp-socket-impl.h:239
ns3::Socket::IsIpv6RecvTclass
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack.
Definition: socket.cc:507
ns3::InetSocketAddress::ConvertFrom
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Definition: inet-socket-address.cc:126
ns3::Ipv6Header
Packet header for IPv6.
Definition: ipv6-header.h:36
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::Socket::GetIpTtl
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:520
ns3::Socket::ERROR_AFNOSUPPORT
@ ERROR_AFNOSUPPORT
Definition: socket.h:90
ns3::UdpSocketImpl::Bind
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
Definition: udp-socket-impl.cc:232
ns3::Socket::Ipv6MulticastFilterMode
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Definition: socket.h:139
ns3::UdpSocketImpl::MulticastJoinGroup
virtual int MulticastJoinGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_JOIN_GROUP.
Definition: udp-socket-impl.cc:920
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::Inet6SocketAddress::GetPort
uint16_t GetPort(void) const
Get the port.
Definition: inet6-socket-address.cc:65
ns3::UdpSocketImpl::m_defaultPort
uint16_t m_defaultPort
Default port.
Definition: udp-socket-impl.h:244
ns3::UdpSocketImpl::Listen
virtual int Listen(void)
Listen for incoming connections.
Definition: udp-socket-impl.cc:426
ns3::Inet6SocketAddress::ConvertFrom
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
Definition: inet6-socket-address.cc:110
ns3::Socket::INCLUDE
@ INCLUDE
Definition: socket.h:140
ns3::Socket::GetIpv6HopLimit
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:545
ns3::UdpSocketImpl::GetAllowBroadcast
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
Definition: udp-socket-impl.cc:1211
ns3::UdpSocketImpl::m_node
Ptr< Node > m_node
the associated node
Definition: udp-socket-impl.h:238
ns3::UdpSocketImpl::SetNode
void SetNode(Ptr< Node > node)
Set the associated node.
Definition: udp-socket-impl.cc:138
ns3::Ipv4
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
ns3::UdpSocketImpl::m_defaultAddress
Address m_defaultAddress
Default address.
Definition: udp-socket-impl.h:243
ns3::Ipv6Header::SetDestination
void SetDestination(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:115
ns3::Ipv4Address::IsMulticast
bool IsMulticast(void) const
Definition: ipv4-address.cc:294
ns3::SocketPriorityTag::SetPriority
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition: socket.cc:842
ns3::Ptr< Node >
ns3::Ipv6Header::GetTrafficClass
uint8_t GetTrafficClass(void) const
Get the "Traffic class" field.
Definition: ipv6-header.cc:50
ns3::Socket::ERROR_INVAL
@ ERROR_INVAL
Definition: socket.h:91
ns3::Ipv4Address::GetZero
static Ipv4Address GetZero(void)
Definition: ipv4-address.cc:388
ns3::MakeCallbackChecker
Ptr< const AttributeChecker > MakeCallbackChecker(void)
Definition: callback.cc:74
ns3::Ipv4EndPoint::GetLocalPort
uint16_t GetLocalPort(void)
Get the local port.
Definition: ipv4-end-point.cc:67
ns3::UdpSocket
(abstract) base class of all UdpSockets
Definition: udp-socket.h:48
ns3::SocketSetDontFragmentTag::Enable
void Enable(void)
Enables the DF (Don't Fragment) flag.
Definition: socket.cc:720
ipv4-end-point.h
ns3::Ipv6PacketInfoTag
This class implements a tag that carries socket ancillary data to the socket interface.
Definition: ipv6-packet-info-tag.h:49
ns3::UdpSocketImpl::BindToNetDevice
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: udp-socket-impl.cc:948
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::UdpSocketImpl::GetMtuDiscover
virtual bool GetMtuDiscover(void) const
Get the MTU discover capability.
Definition: udp-socket-impl.cc:1198
ns3::Ipv4InterfaceAddress
a class to store IPv4 address information on an interface
Definition: ipv4-interface-address.h:44
ns3::UdpSocketImpl::Ipv6JoinGroup
virtual void Ipv6JoinGroup(Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
Joins a IPv6 multicast group.
Definition: udp-socket-impl.cc:1217
ns3::UdpSocketImpl::ForwardIcmp
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMP packet to pass on to TCP.
Definition: udp-socket-impl.cc:1119
ns3::Socket::ERROR_ADDRNOTAVAIL
@ ERROR_ADDRNOTAVAIL
Definition: socket.h:95
ns3::UdpSocketImpl::Bind6
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
Definition: udp-socket-impl.cc:244
ns3::MakeCallbackAccessor
Ptr< const AttributeAccessor > MakeCallbackAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: callback.h:1981
ns3::Socket::ERROR_ADDRINUSE
@ ERROR_ADDRINUSE
Definition: socket.h:96
ns3::InetSocketAddress::GetIpv4
Ipv4Address GetIpv4(void) const
Definition: inet-socket-address.cc:71
ns3::SocketIpv6HopLimitTag
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition: socket.h:1165
ns3::UdpSocketImpl::Destroy6
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
Definition: udp-socket-impl.cc:180
ns3::Ipv6Address::GetIpv4MappedAddress
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
Definition: ipv6-address.cc:361
ns3::Ipv6EndPoint::GetLocalPort
uint16_t GetLocalPort()
Get the local port.
Definition: ipv6-end-point.cc:62
ns3::Ipv6Address::ConvertFrom
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Definition: ipv6-address.cc:846
ns3::Socket::NotifyConnectionFailed
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error.
Definition: socket.cc:227
ns3::Socket::SocketType
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
ns3::UdpSocketImpl::GetErrno
virtual enum SocketErrno GetErrno(void) const
Get last error number.
Definition: udp-socket-impl.cc:153
ns3::Socket::ERROR_NOTCONN
@ ERROR_NOTCONN
Definition: socket.h:85
ns3::Ipv6PacketInfoTag::SetRecvIf
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
Definition: ipv6-packet-info-tag.cc:49
ns3::UdpSocketImpl::~UdpSocketImpl
virtual ~UdpSocketImpl()
Definition: udp-socket-impl.cc:93
ns3::Socket::GetBoundNetDevice
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
Definition: socket.cc:351
ipv6-end-point.h
ns3::CallbackValue
AttributeValue implementation for Callback.
Definition: callback.h:1938
first.address
address
Definition: first.py:44
ns3::Ipv4EndPoint::GetLocalAddress
Ipv4Address GetLocalAddress(void)
Get the local address.
Definition: ipv4-end-point.cc:53
ns3::Socket::IsManualIpv6HopLimit
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:383
ns3::SocketIpv6TclassTag
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1356
ns3::UdpSocketImpl::ShutdownRecv
virtual int ShutdownRecv(void)
Definition: udp-socket-impl.cc:364
ns3::Ipv4Header::GetTtl
uint8_t GetTtl(void) const
Definition: ipv4-header.cc:265
ns3::UdpSocketImpl::m_mtuDiscover
bool m_mtuDiscover
Allow MTU discovery.
Definition: udp-socket-impl.h:261
ns3::UdpSocketImpl::SetIpMulticastTtl
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
Definition: udp-socket-impl.cc:1157
ns3::Ipv4Address::IsBroadcast
bool IsBroadcast(void) const
Definition: ipv4-address.cc:287
ns3::UdpSocketImpl::SetUdp
void SetUdp(Ptr< UdpL4Protocol > udp)
Set the associated UDP L4 protocol.
Definition: udp-socket-impl.cc:145
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::Socket::Ipv6LeaveGroup
virtual void Ipv6LeaveGroup(void)
Leaves IPv6 multicast group this socket is joined to.
Definition: socket.cc:580
ns3::UdpSocketImpl::m_deliveryQueue
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Queue for incoming packets.
Definition: udp-socket-impl.h:253
ns3::UdpSocketImpl::DeallocateEndPoint
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
Definition: udp-socket-impl.cc:188
ns3::UdpL4Protocol::PROT_NUMBER
static const uint8_t PROT_NUMBER
protocol number (0x11)
Definition: udp-l4-protocol.h:68
ns3::Ipv4Header::SetSource
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
ns3::UdpSocketImpl::SendTo
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
Definition: udp-socket-impl.cc:801
ns3::Ipv4PacketInfoTag
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Definition: ipv4-packet-info-tag.h:50
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
ns3::Inet6SocketAddress::GetIpv6
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
Definition: inet6-socket-address.cc:77
ns3::UdpSocketImpl
A sockets interface to UDP.
Definition: udp-socket-impl.h:70
NS_LOG_ERROR
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
ns3::Packet::AddPacketTag
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
ns3::UdpSocketImpl::m_ipMulticastTtl
uint8_t m_ipMulticastTtl
Multicast TTL.
Definition: udp-socket-impl.h:258
ns3::UdpSocketImpl::DoSendTo
int DoSendTo(Ptr< Packet > p, Ipv4Address daddr, uint16_t dport, uint8_t tos)
Send a packet to a specific destination and port (IPv4)
Definition: udp-socket-impl.cc:488
ns3::Ipv6Address::IsMulticast
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
Definition: ipv6-address.cc:714
ns3::Ipv6Interface::GetDevice
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
Definition: ipv6-interface.cc:132
ns3::UdpSocketImpl::Connect
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
Definition: udp-socket-impl.cc:396
ns3::SocketPriorityTag
indicates whether the socket has a priority set.
Definition: socket.h:1309
ns3::Socket::IsManualIpv6Tclass
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Definition: socket.cc:371
ns3::Ipv6Header::GetHopLimit
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
Definition: ipv6-header.cc:90
ns3::Socket::NotifyDataRecv
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:305
ns3::Ipv4Address::GetAny
static Ipv4Address GetAny(void)
Definition: ipv4-address.cc:395
ns3::UdpSocketImpl::SetAllowBroadcast
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Definition: udp-socket-impl.cc:1204
ns3::UdpSocketImpl::m_errno
enum SocketErrno m_errno
Socket error code.
Definition: udp-socket-impl.h:247
ns3::SocketIpv6TclassTag::SetTclass
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:900
ns3::Socket::ERROR_OPNOTSUPP
@ ERROR_OPNOTSUPP
Definition: socket.h:89
ns3::SocketIpTosTag
indicates whether the socket has IP_TOS set.
Definition: socket.h:1263
ns3::SocketIpTosTag::SetTos
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:785
ns3::UdpSocketImpl::GetIpMulticastIf
virtual int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
Definition: udp-socket-impl.cc:1175
ns3::Inet6SocketAddress
An Inet6 address class.
Definition: inet6-socket-address.h:37
ns3::Ipv6Header::SetNextHeader
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:75
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::Ipv6Address::GetAny
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Definition: ipv6-address.cc:897
ns3::Socket::GetPriority
uint8_t GetPriority(void) const
Query the priority value of this socket.
Definition: socket.cc:396
ns3::Socket::BindToNetDevice
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
ns3::Packet::RemovePacketTag
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:963
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::Ipv6Header::GetSource
Ipv6Address GetSource(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:105
ns3::InetSocketAddress::GetTos
uint8_t GetTos(void) const
Definition: inet-socket-address.cc:77
ns3::UdpSocketImpl::m_icmpCallback6
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
Definition: udp-socket-impl.h:241
ns3::Ipv4EndPoint::SetDestroyCallback
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Definition: ipv4-end-point.cc:125
ns3::Ipv4InterfaceAddress::GetLocal
Ipv4Address GetLocal(void) const
Get the local address.
Definition: ipv4-interface-address.cc:74
ns3::Ipv6
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
ns3::Ipv4Header::SetProtocol
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
ns3::SocketSetDontFragmentTag::Disable
void Disable(void)
Disables the DF (Don't Fragment) flag.
Definition: socket.cc:726
ns3::Ipv6Header::SetSource
void SetSource(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:95
ns3::Ipv6Header::GetDestination
Ipv6Address GetDestination(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:125
ns3::UdpSocketImpl::GetRcvBufSize
virtual uint32_t GetRcvBufSize(void) const
Get the receiving buffer size.
Definition: udp-socket-impl.cc:1151
ns3::UdpSocketImpl::DoSend
int DoSend(Ptr< Packet > p)
Send a packet.
Definition: udp-socket-impl.cc:447
ns3::Ipv6EndPoint::SetRxCallback
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
Definition: ipv6-end-point.cc:99
ns3::UdpSocketImpl::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: udp-socket-impl.cc:56
ns3::Ipv4EndPoint::SetRxCallback
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Definition: ipv4-end-point.cc:111
ns3::Socket::m_boundnetdevice
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition: socket.h:1077
ns3::UdpSocketImpl::ForwardUp6
void ForwardUp6(Ptr< Packet > packet, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
Definition: udp-socket-impl.cc:1059
ns3::UdpSocketImpl::SetIpMulticastIf
virtual void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
Definition: udp-socket-impl.cc:1169
ns3::Ipv6EndPoint::SetIcmpCallback
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
Definition: ipv6-end-point.cc:104
ns3::Ipv6Address::IsAny
bool IsAny() const
If the IPv6 address is the "Any" address.
Definition: ipv6-address.cc:797
ns3::UdpSocketImpl::FinishBind
int FinishBind(void)
Finish the binding process.
Definition: udp-socket-impl.cc:206
ns3::UdpSocketImpl::Destroy
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
Definition: udp-socket-impl.cc:173
ns3::Ipv4PacketInfoTag::SetAddress
void SetAddress(Ipv4Address addr)
Set the tag's address.
Definition: ipv4-packet-info-tag.cc:40
ns3::Socket::IpTos2Priority
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
Definition: socket.cc:402
ns3::Ipv6EndPoint::SetRxEnabled
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
Definition: ipv6-end-point.cc:131
ns3::Ipv4PacketInfoTag::SetRecvIf
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
Definition: ipv4-packet-info-tag.cc:54
ns3::Ipv4EndPoint::SetIcmpCallback
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
Definition: ipv4-end-point.cc:118
ns3::Socket::NotifySend
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:295
ns3::Ipv4Header::SetDestination
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
ns3::Socket::m_ipv6MulticastGroupAddress
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
Definition: socket.h:1079
ns3::InetSocketAddress::SetTos
void SetTos(uint8_t tos)
Definition: inet-socket-address.cc:96
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::Socket::NotifyDataSent
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:285
ns3::Socket::IsManualIpTtl
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:377
ns3::Socket::GetIpTos
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:453
ns3::NetDevice::GetIfIndex
virtual uint32_t GetIfIndex(void) const =0
ns3::UdpSocketImpl::Send
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
Definition: udp-socket-impl.cc:433
ns3::UdpSocketImpl::MulticastLeaveGroup
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
Definition: udp-socket-impl.cc:934
ns3::Socket::ERROR_NOROUTETOHOST
@ ERROR_NOROUTETOHOST
Definition: socket.h:93
ns3::Socket::GetIpv6Tclass
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:495
ns3::SocketSetDontFragmentTag
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
Definition: socket.h:1213
ns3::UdpSocketImpl::GetRxAvailable
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
Definition: udp-socket-impl.cc:823
ns3::Ipv4Address::ConvertFrom
static Ipv4Address ConvertFrom(const Address &address)
Definition: ipv4-address.cc:370
ns3::SocketIpv6HopLimitTag::SetHopLimit
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:665
ns3::Socket::IsIpRecvTos
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack.
Definition: socket.cc:465
ns3::UdpSocketImpl::ShutdownSend
virtual int ShutdownSend(void)
Definition: udp-socket-impl.cc:356
ns3::Ipv6EndPoint::SetDestroyCallback
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Definition: ipv6-end-point.cc:109
ns3::Ipv6PacketInfoTag::SetTrafficClass
void SetTrafficClass(uint8_t tclass)
Set the tag's Traffic Class.
Definition: ipv6-packet-info-tag.cc:73
udp-socket-impl.h
ns3::UdpSocketImpl::GetNode
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
Definition: udp-socket-impl.cc:166
ns3::MAX_IPV4_UDP_DATAGRAM_SIZE
static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE
Maximum UDP datagram size.
Definition: udp-socket-impl.cc:52
port
uint16_t port
Definition: dsdv-manet.cc:45
ns3::UdpSocketImpl::m_rxAvailable
uint32_t m_rxAvailable
Number of available bytes to be received.
Definition: udp-socket-impl.h:254
ns3::UdpSocketImpl::GetIpMulticastTtl
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
Definition: udp-socket-impl.cc:1163
ns3::Socket::IsRecvPktInfo
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition: socket.cc:364