A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
90  m_allowBroadcast = false;
91 }
92 
94 {
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 {
141  m_node = node;
142 
143 }
144 void
146 {
148  m_udp = udp;
149 }
150 
151 
154 {
156  return m_errno;
157 }
158 
161 {
162  return NS3_SOCK_DGRAM;
163 }
164 
165 Ptr<Node>
167 {
169  return m_node;
170 }
171 
172 void
174 {
176  m_endPoint = 0;
177 }
178 
179 void
181 {
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 {
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 {
235  m_endPoint = m_udp->Allocate ();
236  return FinishBind ();
237 }
238 
239 int
241 {
243  m_endPoint6 = m_udp->Allocate6 ();
244  return FinishBind ();
245 }
246 
247 int
249 {
250  NS_LOG_FUNCTION (this << address);
251 
252  if (InetSocketAddress::IsMatchingType (address))
253  {
254  NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated (maybe you used BindToNetDevice before Bind).");
255 
257  Ipv4Address ipv4 = transport.GetIpv4 ();
258  uint16_t port = transport.GetPort ();
259  if (ipv4 == Ipv4Address::GetAny () && port == 0)
260  {
261  m_endPoint = m_udp->Allocate ();
262  }
263  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
264  {
265  m_endPoint = m_udp->Allocate (port);
266  }
267  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
268  {
269  m_endPoint = m_udp->Allocate (ipv4);
270  }
271  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
272  {
273  m_endPoint = m_udp->Allocate (ipv4, port);
274  }
275  if (0 == m_endPoint)
276  {
278  return -1;
279  }
280  }
281  else if (Inet6SocketAddress::IsMatchingType (address))
282  {
283  NS_ASSERT_MSG (m_endPoint == 0, "Endpoint already allocated (maybe you used BindToNetDevice before Bind).");
284 
286  Ipv6Address ipv6 = transport.GetIpv6 ();
287  uint16_t port = transport.GetPort ();
288  if (ipv6 == Ipv6Address::GetAny () && port == 0)
289  {
290  m_endPoint6 = m_udp->Allocate6 ();
291  }
292  else if (ipv6 == Ipv6Address::GetAny () && port != 0)
293  {
294  m_endPoint6 = m_udp->Allocate6 (port);
295  }
296  else if (ipv6 != Ipv6Address::GetAny () && port == 0)
297  {
298  m_endPoint6 = m_udp->Allocate6 (ipv6);
299  }
300  else if (ipv6 != Ipv6Address::GetAny () && port != 0)
301  {
302  m_endPoint6 = m_udp->Allocate6 (ipv6, port);
303  }
304  if (0 == m_endPoint6)
305  {
307  return -1;
308  }
309  if (ipv6.IsMulticast ())
310  {
312  if (ipv6l3)
313  {
314  ipv6l3->AddMulticastAddress (ipv6);
315  }
316  }
317  }
318  else
319  {
320  NS_LOG_ERROR ("Not IsMatchingType");
322  return -1;
323  }
324 
325  return FinishBind ();
326 }
327 
328 int
330 {
332  m_shutdownSend = true;
333  return 0;
334 }
335 
336 int
338 {
340  m_shutdownRecv = true;
341  if (m_endPoint)
342  {
343  m_endPoint->SetRxEnabled (false);
344  }
345  if (m_endPoint6)
346  {
347  m_endPoint6->SetRxEnabled (false);
348  }
349  return 0;
350 }
351 
352 int
354 {
356  if (m_shutdownRecv == true && m_shutdownSend == true)
357  {
359  return -1;
360  }
361  Ipv6LeaveGroup ();
362  m_shutdownRecv = true;
363  m_shutdownSend = true;
365  return 0;
366 }
367 
368 int
370 {
371  NS_LOG_FUNCTION (this << address);
372  if (InetSocketAddress::IsMatchingType(address) == true)
373  {
375  m_defaultAddress = Address(transport.GetIpv4 ());
376  m_defaultPort = transport.GetPort ();
377  m_connected = true;
379  }
380  else if (Inet6SocketAddress::IsMatchingType(address) == true)
381  {
383  m_defaultAddress = Address(transport.GetIpv6 ());
384  m_defaultPort = transport.GetPort ();
385  m_connected = true;
387  }
388  else
389  {
391  return -1;
392  }
393 
394  return 0;
395 }
396 
397 int
399 {
401  return -1;
402 }
403 
404 int
405 UdpSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
406 {
407  NS_LOG_FUNCTION (this << p << flags);
408 
409  if (!m_connected)
410  {
412  return -1;
413  }
414 
415  return DoSend (p);
416 }
417 
418 int
420 {
421  NS_LOG_FUNCTION (this << p);
423  {
424  if (Bind () == -1)
425  {
426  NS_ASSERT (m_endPoint == 0);
427  return -1;
428  }
429  NS_ASSERT (m_endPoint != 0);
430  }
432  {
433  if (Bind6 () == -1)
434  {
435  NS_ASSERT (m_endPoint6 == 0);
436  return -1;
437  }
438  NS_ASSERT (m_endPoint6 != 0);
439  }
440  if (m_shutdownSend)
441  {
443  return -1;
444  }
445 
447  {
449  }
451  {
453  }
454 
456  return(-1);
457 }
458 
459 int
461 {
462  NS_LOG_FUNCTION (this << p << dest << port);
463  if (m_boundnetdevice)
464  {
465  NS_LOG_LOGIC ("Bound interface number " << m_boundnetdevice->GetIfIndex ());
466  }
467  if (m_endPoint == 0)
468  {
469  if (Bind () == -1)
470  {
471  NS_ASSERT (m_endPoint == 0);
472  return -1;
473  }
474  NS_ASSERT (m_endPoint != 0);
475  }
476  if (m_shutdownSend)
477  {
479  return -1;
480  }
481 
482  if (p->GetSize () > GetTxAvailable () )
483  {
485  return -1;
486  }
487 
488  if (IsManualIpTos ())
489  {
490  SocketIpTosTag ipTosTag;
491  ipTosTag.SetTos (GetIpTos ());
492  // This packet may already have a SocketIpTosTag (see BUG 2440)
493  p->ReplacePacketTag (ipTosTag);
494  }
495 
496  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
497 
498  // Locally override the IP TTL for this socket
499  // We cannot directly modify the TTL at this stage, so we set a Packet tag
500  // The destination can be either multicast, unicast/anycast, or
501  // either all-hosts broadcast or limited (subnet-directed) broadcast.
502  // For the latter two broadcast types, the TTL will later be set to one
503  // irrespective of what is set in these socket options. So, this tagging
504  // may end up setting the TTL of a limited broadcast packet to be
505  // the same as a unicast, but it will be fixed further down the stack
506  if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
507  {
508  SocketIpTtlTag tag;
509  tag.SetTtl (m_ipMulticastTtl);
510  p->AddPacketTag (tag);
511  }
512  else if (IsManualIpTtl () && GetIpTtl () != 0 && !dest.IsMulticast () && !dest.IsBroadcast ())
513  {
514  SocketIpTtlTag tag;
515  tag.SetTtl (GetIpTtl ());
516  p->AddPacketTag (tag);
517  }
518  {
520  bool found = p->RemovePacketTag (tag);
521  if (!found)
522  {
523  if (m_mtuDiscover)
524  {
525  tag.Enable ();
526  }
527  else
528  {
529  tag.Disable ();
530  }
531  p->AddPacketTag (tag);
532  }
533  }
534  //
535  // If dest is set to the limited broadcast address (all ones),
536  // convert it to send a copy of the packet out of every
537  // interface as a subnet-directed broadcast.
538  // Exception: if the interface has a /32 address, there is no
539  // valid subnet-directed broadcast, so send it as limited broadcast
540  // Note also that some systems will only send limited broadcast packets
541  // out of the "default" interface; here we send it out all interfaces
542  //
543  if (dest.IsBroadcast ())
544  {
545  if (!m_allowBroadcast)
546  {
548  return -1;
549  }
550  NS_LOG_LOGIC ("Limited broadcast start.");
551  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
552  {
553  // Get the primary address
554  Ipv4InterfaceAddress iaddr = ipv4->GetAddress (i, 0);
555  Ipv4Address addri = iaddr.GetLocal ();
556  if (addri == Ipv4Address ("127.0.0.1"))
557  continue;
558  // Check if interface-bound socket
559  if (m_boundnetdevice)
560  {
561  if (ipv4->GetNetDevice (i) != m_boundnetdevice)
562  continue;
563  }
564  Ipv4Mask maski = iaddr.GetMask ();
565  if (maski == Ipv4Mask::GetOnes ())
566  {
567  // if the network mask is 255.255.255.255, do not convert dest
568  NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << dest
569  << " (mask is " << maski << ")");
570  m_udp->Send (p->Copy (), addri, dest,
572  NotifyDataSent (p->GetSize ());
574  }
575  else
576  {
577  // Convert to subnet-directed broadcast
578  Ipv4Address bcast = addri.GetSubnetDirectedBroadcast (maski);
579  NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << bcast
580  << " (mask is " << maski << ")");
581  m_udp->Send (p->Copy (), addri, bcast,
583  NotifyDataSent (p->GetSize ());
585  }
586  }
587  NS_LOG_LOGIC ("Limited broadcast end.");
588  return p->GetSize ();
589  }
591  {
592  m_udp->Send (p->Copy (), m_endPoint->GetLocalAddress (), dest,
593  m_endPoint->GetLocalPort (), port, 0);
594  NotifyDataSent (p->GetSize ());
596  return p->GetSize ();
597  }
598  else if (ipv4->GetRoutingProtocol () != 0)
599  {
600  Ipv4Header header;
601  header.SetDestination (dest);
603  Socket::SocketErrno errno_;
604  Ptr<Ipv4Route> route;
605  Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a specific device
606  // TBD-- we could cache the route and just check its validity
607  route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
608  if (route != 0)
609  {
610  NS_LOG_LOGIC ("Route exists");
611  if (!m_allowBroadcast)
612  {
613  uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->GetOutputDevice ());
614  uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
615  for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
616  {
617  Ipv4InterfaceAddress ifAddr = ipv4->GetAddress (outputIfIndex, addrI);
618  if (dest == ifAddr.GetBroadcast ())
619  {
621  return -1;
622  }
623  }
624  }
625 
626  header.SetSource (route->GetSource ());
627  m_udp->Send (p->Copy (), header.GetSource (), header.GetDestination (),
628  m_endPoint->GetLocalPort (), port, route);
629  NotifyDataSent (p->GetSize ());
630  return p->GetSize ();
631  }
632  else
633  {
634  NS_LOG_LOGIC ("No route to destination");
635  NS_LOG_ERROR (errno_);
636  m_errno = errno_;
637  return -1;
638  }
639  }
640  else
641  {
642  NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
644  return -1;
645  }
646 
647  return 0;
648 }
649 
650 int
652 {
653  NS_LOG_FUNCTION (this << p << dest << port);
654 
655  if (dest.IsIpv4MappedAddress ())
656  {
657  return (DoSendTo(p, dest.GetIpv4MappedAddress (), port));
658  }
659  if (m_boundnetdevice)
660  {
661  NS_LOG_LOGIC ("Bound interface number " << m_boundnetdevice->GetIfIndex ());
662  }
663  if (m_endPoint6 == 0)
664  {
665  if (Bind6 () == -1)
666  {
667  NS_ASSERT (m_endPoint6 == 0);
668  return -1;
669  }
670  NS_ASSERT (m_endPoint6 != 0);
671  }
672  if (m_shutdownSend)
673  {
675  return -1;
676  }
677 
678  if (p->GetSize () > GetTxAvailable () )
679  {
681  return -1;
682  }
683 
684  if (IsManualIpv6Tclass ())
685  {
686  SocketIpv6TclassTag ipTclassTag;
687  ipTclassTag.SetTclass (GetIpv6Tclass ());
688  p->AddPacketTag (ipTclassTag);
689  }
690 
691  Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
692 
693  // Locally override the IP TTL for this socket
694  // We cannot directly modify the TTL at this stage, so we set a Packet tag
695  // The destination can be either multicast, unicast/anycast, or
696  // either all-hosts broadcast or limited (subnet-directed) broadcast.
697  // For the latter two broadcast types, the TTL will later be set to one
698  // irrespective of what is set in these socket options. So, this tagging
699  // may end up setting the TTL of a limited broadcast packet to be
700  // the same as a unicast, but it will be fixed further down the stack
701  if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
702  {
705  p->AddPacketTag (tag);
706  }
707  else if (IsManualIpv6HopLimit () && GetIpv6HopLimit () != 0 && !dest.IsMulticast ())
708  {
710  tag.SetHopLimit (GetIpv6HopLimit ());
711  p->AddPacketTag (tag);
712  }
713  // There is no analgous to an IPv4 broadcast address in IPv6.
714  // Instead, we use a set of link-local, site-local, and global
715  // multicast addresses. The Ipv6 routing layers should all
716  // provide an interface-specific route to these addresses such
717  // that we can treat these multicast addresses as "not broadcast"
718 
720  {
721  m_udp->Send (p->Copy (), m_endPoint6->GetLocalAddress (), dest,
722  m_endPoint6->GetLocalPort (), port, 0);
723  NotifyDataSent (p->GetSize ());
725  return p->GetSize ();
726  }
727  else if (ipv6->GetRoutingProtocol () != 0)
728  {
729  Ipv6Header header;
730  header.SetDestinationAddress (dest);
732  Socket::SocketErrno errno_;
733  Ptr<Ipv6Route> route;
734  Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a specific device
735  // TBD-- we could cache the route and just check its validity
736  route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
737  if (route != 0)
738  {
739  NS_LOG_LOGIC ("Route exists");
740  header.SetSourceAddress (route->GetSource ());
741  m_udp->Send (p->Copy (), header.GetSourceAddress (), header.GetDestinationAddress (),
742  m_endPoint6->GetLocalPort (), port, route);
743  NotifyDataSent (p->GetSize ());
744  return p->GetSize ();
745  }
746  else
747  {
748  NS_LOG_LOGIC ("No route to destination");
749  NS_LOG_ERROR (errno_);
750  m_errno = errno_;
751  return -1;
752  }
753  }
754  else
755  {
756  NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
758  return -1;
759  }
760 
761  return 0;
762 }
763 
764 
765 // maximum message size for UDP broadcast is limited by MTU
766 // size of underlying link; we are not checking that now.
767 // \todo Check MTU size of underlying link
768 uint32_t
770 {
772  // No finite send buffer is modelled, but we must respect
773  // the maximum size of an IP datagram (65535 bytes - headers).
775 }
776 
777 int
779 {
780  NS_LOG_FUNCTION (this << p << flags << address);
781  if (InetSocketAddress::IsMatchingType (address))
782  {
784  Ipv4Address ipv4 = transport.GetIpv4 ();
785  uint16_t port = transport.GetPort ();
786  return DoSendTo (p, ipv4, port);
787  }
788  else if (Inet6SocketAddress::IsMatchingType (address))
789  {
791  Ipv6Address ipv6 = transport.GetIpv6 ();
792  uint16_t port = transport.GetPort ();
793  return DoSendTo (p, ipv6, port);
794  }
795  return -1;
796 }
797 
798 uint32_t
800 {
802  // We separately maintain this state to avoid walking the queue
803  // every time this might be called
804  return m_rxAvailable;
805 }
806 
808 UdpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
809 {
810  NS_LOG_FUNCTION (this << maxSize << flags);
811 
812  Address fromAddress;
813  Ptr<Packet> packet = RecvFrom (maxSize, flags, fromAddress);
814  return packet;
815 }
816 
818 UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
819  Address &fromAddress)
820 {
821  NS_LOG_FUNCTION (this << maxSize << flags);
822 
823  if (m_deliveryQueue.empty () )
824  {
826  return 0;
827  }
828  Ptr<Packet> p = m_deliveryQueue.front ().first;
829  fromAddress = m_deliveryQueue.front ().second;
830 
831  if (p->GetSize () <= maxSize)
832  {
833  m_deliveryQueue.pop ();
834  m_rxAvailable -= p->GetSize ();
835  }
836  else
837  {
838  p = 0;
839  }
840  return p;
841 }
842 
843 int
845 {
847  if (m_endPoint != 0)
848  {
850  }
851  else if (m_endPoint6 != 0)
852  {
854  }
855  else
856  { // It is possible to call this method on a socket without a name
857  // in which case, behavior is unspecified
858  // Should this return an InetSocketAddress or an Inet6SocketAddress?
859  address = InetSocketAddress (Ipv4Address::GetZero (), 0);
860  }
861  return 0;
862 }
863 
864 int
866 {
867  NS_LOG_FUNCTION (this << address);
868 
869  if (!m_connected)
870  {
872  return -1;
873  }
874 
876  {
878  address = InetSocketAddress (addr, m_defaultPort);
879  }
881  {
883  address = Inet6SocketAddress (addr, m_defaultPort);
884  }
885  else
886  {
887  NS_ASSERT_MSG (false, "unexpected address type");
888  }
889 
890  return 0;
891 }
892 
893 int
894 UdpSocketImpl::MulticastJoinGroup (uint32_t interface, const Address &groupAddress)
895 {
896  NS_LOG_FUNCTION (interface << groupAddress);
897  /*
898  1) sanity check interface
899  2) sanity check that it has not been called yet on this interface/group
900  3) determine address family of groupAddress
901  4) locally store a list of (interface, groupAddress)
902  5) call ipv4->MulticastJoinGroup () or Ipv6->MulticastJoinGroup ()
903  */
904  return 0;
905 }
906 
907 int
908 UdpSocketImpl::MulticastLeaveGroup (uint32_t interface, const Address &groupAddress)
909 {
910  NS_LOG_FUNCTION (interface << groupAddress);
911  /*
912  1) sanity check interface
913  2) determine address family of groupAddress
914  3) delete from local list of (interface, groupAddress); raise a LOG_WARN
915  if not already present (but return 0)
916  5) call ipv4->MulticastLeaveGroup () or Ipv6->MulticastLeaveGroup ()
917  */
918  return 0;
919 }
920 
921 void
923 {
924  NS_LOG_FUNCTION (netdevice);
925 
926  Socket::BindToNetDevice (netdevice); // Includes sanity check
927  if (m_endPoint == 0)
928  {
929  if (Bind () == -1)
930  {
931  NS_ASSERT (m_endPoint == 0);
932  return;
933  }
934  NS_ASSERT (m_endPoint != 0);
935  }
936  m_endPoint->BindToNetDevice (netdevice);
937 
938  if (m_endPoint6 == 0)
939  {
940  if (Bind6 () == -1)
941  {
942  NS_ASSERT (m_endPoint6 == 0);
943  return;
944  }
945  NS_ASSERT (m_endPoint6 != 0);
946  }
947  m_endPoint6->BindToNetDevice (netdevice);
948 
950  {
952  if (ipv6l3)
953  {
954  uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
955  ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ());
956  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
957  }
958  }
959 
960  return;
961 }
962 
963 void
965  Ptr<Ipv4Interface> incomingInterface)
966 {
967  NS_LOG_FUNCTION (this << packet << header << port);
968 
969  if (m_shutdownRecv)
970  {
971  return;
972  }
973 
974  // Should check via getsockopt ()..
975  if (IsRecvPktInfo ())
976  {
977  Ipv4PacketInfoTag tag;
978  packet->RemovePacketTag (tag);
979  tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
980  packet->AddPacketTag (tag);
981  }
982 
983  //Check only version 4 options
984  if (IsIpRecvTos ())
985  {
986  SocketIpTosTag ipTosTag;
987  ipTosTag.SetTos (header.GetTos ());
988  packet->AddPacketTag (ipTosTag);
989  }
990 
991  if (IsIpRecvTtl ())
992  {
993  SocketIpTtlTag ipTtlTag;
994  ipTtlTag.SetTtl (header.GetTtl ());
995  packet->AddPacketTag (ipTtlTag);
996  }
997 
998  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
999  {
1001  m_deliveryQueue.push (std::make_pair (packet, address));
1002  m_rxAvailable += packet->GetSize ();
1003  NotifyDataRecv ();
1004  }
1005  else
1006  {
1007  // In general, this case should not occur unless the
1008  // receiving application reads data from this socket slowly
1009  // in comparison to the arrival rate
1010  //
1011  // drop and trace packet
1012  NS_LOG_WARN ("No receive buffer space available. Drop.");
1013  m_dropTrace (packet);
1014  }
1015 }
1016 
1017 void
1018 UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface)
1019 {
1020  NS_LOG_FUNCTION (this << packet << header.GetSourceAddress () << port);
1021 
1022  if (m_shutdownRecv)
1023  {
1024  return;
1025  }
1026 
1027  // Should check via getsockopt ().
1028  if (IsRecvPktInfo ())
1029  {
1030  Ipv6PacketInfoTag tag;
1031  packet->RemovePacketTag (tag);
1032  tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
1033  packet->AddPacketTag (tag);
1034  }
1035 
1036  // Check only version 6 options
1037  if (IsIpv6RecvTclass ())
1038  {
1039  SocketIpv6TclassTag ipTclassTag;
1040  ipTclassTag.SetTclass (header.GetTrafficClass ());
1041  packet->AddPacketTag (ipTclassTag);
1042  }
1043 
1044  if (IsIpv6RecvHopLimit ())
1045  {
1046  SocketIpv6HopLimitTag ipHopLimitTag;
1047  ipHopLimitTag.SetHopLimit (header.GetHopLimit ());
1048  packet->AddPacketTag (ipHopLimitTag);
1049  }
1050 
1051  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
1052  {
1054  m_deliveryQueue.push (std::make_pair (packet, address));
1055  m_rxAvailable += packet->GetSize ();
1056  NotifyDataRecv ();
1057  }
1058  else
1059  {
1060  // In general, this case should not occur unless the
1061  // receiving application reads data from this socket slowly
1062  // in comparison to the arrival rate
1063  //
1064  // drop and trace packet
1065  NS_LOG_WARN ("No receive buffer space available. Drop.");
1066  m_dropTrace (packet);
1067  }
1068 }
1069 
1070 void
1071 UdpSocketImpl::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
1072  uint8_t icmpType, uint8_t icmpCode,
1073  uint32_t icmpInfo)
1074 {
1075  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1076  (uint32_t)icmpCode << icmpInfo);
1077  if (!m_icmpCallback.IsNull ())
1078  {
1079  m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1080  }
1081 }
1082 
1083 void
1084 UdpSocketImpl::ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
1085  uint8_t icmpType, uint8_t icmpCode,
1086  uint32_t icmpInfo)
1087 {
1088  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1089  (uint32_t)icmpCode << icmpInfo);
1090  if (!m_icmpCallback6.IsNull ())
1091  {
1092  m_icmpCallback6 (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1093  }
1094 }
1095 
1096 void
1098 {
1099  m_rcvBufSize = size;
1100 }
1101 
1102 uint32_t
1104 {
1105  return m_rcvBufSize;
1106 }
1107 
1108 void
1110 {
1111  m_ipMulticastTtl = ipTtl;
1112 }
1113 
1114 uint8_t
1116 {
1117  return m_ipMulticastTtl;
1118 }
1119 
1120 void
1122 {
1123  m_ipMulticastIf = ipIf;
1124 }
1125 
1126 int32_t
1128 {
1129  return m_ipMulticastIf;
1130 }
1131 
1132 void
1134 {
1135  m_ipMulticastLoop = loop;
1136 }
1137 
1138 bool
1140 {
1141  return m_ipMulticastLoop;
1142 }
1143 
1144 void
1146 {
1147  m_mtuDiscover = discover;
1148 }
1149 bool
1151 {
1152  return m_mtuDiscover;
1153 }
1154 
1155 bool
1157 {
1158  m_allowBroadcast = allowBroadcast;
1159  return true;
1160 }
1161 
1162 bool
1164 {
1165  return m_allowBroadcast;
1166 }
1167 
1168 void
1169 UdpSocketImpl::Ipv6JoinGroup (Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector<Ipv6Address> sourceAddresses)
1170 {
1171  NS_LOG_FUNCTION (this << address << &filterMode << &sourceAddresses);
1172 
1173  // We can join only one multicast group (or change its params)
1174  NS_ASSERT_MSG ((m_ipv6MulticastGroupAddress == address || m_ipv6MulticastGroupAddress.IsAny ()), "Can join only one IPv6 multicast group.");
1175 
1177 
1179  if (ipv6l3)
1180  {
1181  if (filterMode == INCLUDE && sourceAddresses.empty ())
1182  {
1183  // it is a leave
1184  if (m_boundnetdevice)
1185  {
1186  int32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
1187  NS_ASSERT_MSG (index >= 0, "Interface without a valid index");
1188  ipv6l3->RemoveMulticastAddress (address, index);
1189  }
1190  else
1191  {
1192  ipv6l3->RemoveMulticastAddress (address);
1193  }
1194  }
1195  else
1196  {
1197  // it is a join or a modification
1198  if (m_boundnetdevice)
1199  {
1200  int32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
1201  NS_ASSERT_MSG (index >= 0, "Interface without a valid index");
1202  ipv6l3->AddMulticastAddress (address, index);
1203  }
1204  else
1205  {
1206  ipv6l3->AddMulticastAddress (address);
1207  }
1208  }
1209  }
1210 }
1211 
1212 } // namespace ns3
static bool IsMatchingType(const Address &address)
If the Address matches the type.
bool IsAny() const
If the IPv6 address is the "Any" address.
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
Ipv6Address GetLocalAddress()
Get the local address.
(abstract) base class of all UdpSockets
Definition: udp-socket.h:46
uint8_t GetTrafficClass(void) const
Get the "Traffic class" field.
Definition: ipv6-header.cc:50
bool m_shutdownSend
Send no longer allowed.
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:793
static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE
Maximum UDP datagram size.
static Ipv4Mask GetOnes(void)
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:383
Introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
an Inet address class
Ipv4Address GetIpv4(void) const
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Definition: socket.cc:508
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
Ipv4Mask GetMask(void) const
Get the network mask.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:471
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:404
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Definition: socket.h:1053
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
enum SocketErrno m_errno
Socket error code.
virtual void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
Ipv4Address GetLocal(void) const
Get the local address.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
bool m_allowBroadcast
Allow send broadcast packets.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:305
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
IPv6 layer implementation.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:824
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error...
Definition: socket.cc:227
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
virtual int Close(void)
Close a socket.
#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
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:792
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:75
bool IsManualIpTos(void) const
Checks if the socket has a specific IPv4 ToS set.
Definition: socket.cc:371
uint32_t m_rxAvailable
Number of available bytes to be received.
bool IsMulticast(void) const
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:496
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:736
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
Definition: socket.h:1005
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
virtual void SetRcvBufSize(uint32_t size)
Set the receiving buffer size.
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
Definition: socket.h:969
virtual void Ipv6JoinGroup(Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
Joins a IPv6 multicast group.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition: socket.cc:364
A sockets interface to UDP.
bool m_connected
Connection established.
Ipv4Address GetSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
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.
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
AttributeValue implementation for Callback.
Definition: callback.h:1880
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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
Ptr< NetDevice > GetOutputDevice(void) const
Definition: ipv4-route.cc:84
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack...
Definition: socket.cc:416
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual int ShutdownRecv(void)
virtual int GetSockName(Address &address) const
Get socket address.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Definition: socket.h:122
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.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:555
int DoSend(Ptr< Packet > p)
Send a packet.
uint16_t GetLocalPort()
Get the local port.
void SetNode(Ptr< Node > node)
Set the associated node.
virtual uint32_t GetRcvBufSize(void) const
Get the receiving buffer size.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
UdpSocketImpl()
Create an unbound udp socket.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual int MulticastJoinGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_JOIN_GROUP.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Definition: packet.cc:838
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:1922
Ipv4Address GetLocalAddress(void)
Get the local address.
bool IsBroadcast(void) const
uint8_t m_ipMulticastTtl
Multicast TTL.
Address m_defaultAddress
Default address.
virtual enum SocketType GetSocketType(void) const
An Inet6 address class.
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
virtual int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Definition: socket.cc:377
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:285
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
Ipv4Address GetSource(void) const
Definition: ipv4-route.cc:56
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
static bool IsMatchingType(const Address &address)
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
int FinishBind(void)
Finish the binding process.
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:616
static TypeId GetTypeId(void)
Get the type ID.
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
Definition: socket.cc:217
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:122
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:389
virtual void SetIpMulticastLoop(bool loop)
Set the IP multicast loop capability.
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
Definition: ipv6-header.cc:90
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
bool m_shutdownRecv
Receive no longer allowed.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ptr< Node > m_node
the associated node
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1198
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:446
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
virtual void Ipv6LeaveGroup(void)
Leaves IPv6 multicast group this socket is joined to.
Definition: socket.cc:531
static Ipv4Address GetZero(void)
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack...
Definition: socket.cc:458
Ptr< const AttributeChecker > MakeCallbackChecker(void)
Definition: callback.cc:75
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
virtual int ShutdownSend(void)
#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:90
void SetSourceAddress(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:95
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
Definition: socket.cc:483
void Disable(void)
Disables the DF (Don't Fragment) flag.
Definition: socket.cc:677
Describes an IPv6 address.
Definition: ipv6-address.h:48
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.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition: socket.h:967
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
a class to store IPv4 address information on an interface
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
uint32_t m_rcvBufSize
Receive buffer size.
uint16_t GetLocalPort(void)
Get the local port.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
Ptr< NetDevice > GetDevice(void) const
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
void SetUdp(Ptr< UdpL4Protocol > udp)
Set the associated UDP L4 protocol.
bool m_ipMulticastLoop
Allow multicast loop.
virtual int Listen(void)
Listen for incoming connections.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:831
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:100
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
Definition: socket.h:1101
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
uint16_t m_defaultPort
Default port.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
static bool IsMatchingType(const Address &addr)
If the address match.
void Enable(void)
Enables the DF (Don't Fragment) flag.
Definition: socket.cc:671
uint16_t GetPort(void) const
Get the port.
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
int32_t m_ipMulticastIf
Multicast Interface.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
uint16_t GetPort(void) const
uint8_t GetTtl(void) const
Definition: ipv4-header.cc:265
uint8_t GetTos(void) const
Definition: ipv4-header.cc:194
This class implements a tag that carries socket ancillary data to the socket interface.
static Ipv4Address ConvertFrom(const Address &address)
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
tuple address
Definition: first.py:37
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Queue for incoming packets.
int DoSendTo(Ptr< Packet > p, Ipv4Address daddr, uint16_t dport)
Send a packet to a specific destination and port (IPv4)
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
indicates whether the socket has IP_TOS set.
Definition: socket.h:1151
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
a unique identifier for an interface.
Definition: type-id.h:58
static const uint8_t PROT_NUMBER
protocol number (0x11)
bool m_mtuDiscover
Allow MTU discovery.
void SetDestinationAddress(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:105
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:295
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:827
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
static bool IsMatchingType(const Address &address)
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:110
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
virtual bool GetMtuDiscover(void) const
Get the MTU discover capability.
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.