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 {
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  {
390  return -1;
391  }
392 
393  return 0;
394 }
395 
396 int
398 {
400  return -1;
401 }
402 
403 int
404 UdpSocketImpl::Send (Ptr<Packet> p, uint32_t flags)
405 {
406  NS_LOG_FUNCTION (this << p << flags);
407 
408  if (!m_connected)
409  {
411  return -1;
412  }
413 
414  return DoSend (p);
415 }
416 
417 int
419 {
420  NS_LOG_FUNCTION (this << p);
422  {
423  if (Bind () == -1)
424  {
425  NS_ASSERT (m_endPoint == 0);
426  return -1;
427  }
428  NS_ASSERT (m_endPoint != 0);
429  }
431  {
432  if (Bind6 () == -1)
433  {
434  NS_ASSERT (m_endPoint6 == 0);
435  return -1;
436  }
437  NS_ASSERT (m_endPoint6 != 0);
438  }
439  if (m_shutdownSend)
440  {
442  return -1;
443  }
444 
445  return DoSendTo (p, (const Address)m_defaultAddress);
446 }
447 
448 int
450 {
451  NS_LOG_FUNCTION (this << p << address);
452 
453  if (!m_connected)
454  {
455  NS_LOG_LOGIC ("Not connected");
456  if (InetSocketAddress::IsMatchingType(address) == true)
457  {
459  Ipv4Address ipv4 = transport.GetIpv4 ();
460  uint16_t port = transport.GetPort ();
461  return DoSendTo (p, ipv4, port);
462  }
463  else if (Inet6SocketAddress::IsMatchingType(address) == true)
464  {
466  Ipv6Address ipv6 = transport.GetIpv6 ();
467  uint16_t port = transport.GetPort ();
468  return DoSendTo (p, ipv6, port);
469  }
470  else
471  {
472  return -1;
473  }
474  }
475  else
476  {
477  // connected UDP socket must use default addresses
478  NS_LOG_LOGIC ("Connected");
480  {
482  }
484  {
486  }
487  }
489  return(-1);
490 }
491 
492 int
494 {
495  NS_LOG_FUNCTION (this << p << dest << port);
496  if (m_boundnetdevice)
497  {
498  NS_LOG_LOGIC ("Bound interface number " << m_boundnetdevice->GetIfIndex ());
499  }
500  if (m_endPoint == 0)
501  {
502  if (Bind () == -1)
503  {
504  NS_ASSERT (m_endPoint == 0);
505  return -1;
506  }
507  NS_ASSERT (m_endPoint != 0);
508  }
509  if (m_shutdownSend)
510  {
512  return -1;
513  }
514 
515  if (p->GetSize () > GetTxAvailable () )
516  {
518  return -1;
519  }
520 
521  if (IsManualIpTos ())
522  {
523  SocketIpTosTag ipTosTag;
524  ipTosTag.SetTos (GetIpTos ());
525  p->AddPacketTag (ipTosTag);
526  }
527 
528  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
529 
530  // Locally override the IP TTL for this socket
531  // We cannot directly modify the TTL at this stage, so we set a Packet tag
532  // The destination can be either multicast, unicast/anycast, or
533  // either all-hosts broadcast or limited (subnet-directed) broadcast.
534  // For the latter two broadcast types, the TTL will later be set to one
535  // irrespective of what is set in these socket options. So, this tagging
536  // may end up setting the TTL of a limited broadcast packet to be
537  // the same as a unicast, but it will be fixed further down the stack
538  if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
539  {
540  SocketIpTtlTag tag;
541  tag.SetTtl (m_ipMulticastTtl);
542  p->AddPacketTag (tag);
543  }
544  else if (IsManualIpTtl () && GetIpTtl () != 0 && !dest.IsMulticast () && !dest.IsBroadcast ())
545  {
546  SocketIpTtlTag tag;
547  tag.SetTtl (GetIpTtl ());
548  p->AddPacketTag (tag);
549  }
550  {
552  bool found = p->RemovePacketTag (tag);
553  if (!found)
554  {
555  if (m_mtuDiscover)
556  {
557  tag.Enable ();
558  }
559  else
560  {
561  tag.Disable ();
562  }
563  p->AddPacketTag (tag);
564  }
565  }
566  //
567  // If dest is set to the limited broadcast address (all ones),
568  // convert it to send a copy of the packet out of every
569  // interface as a subnet-directed broadcast.
570  // Exception: if the interface has a /32 address, there is no
571  // valid subnet-directed broadcast, so send it as limited broadcast
572  // Note also that some systems will only send limited broadcast packets
573  // out of the "default" interface; here we send it out all interfaces
574  //
575  if (dest.IsBroadcast ())
576  {
577  if (!m_allowBroadcast)
578  {
580  return -1;
581  }
582  NS_LOG_LOGIC ("Limited broadcast start.");
583  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
584  {
585  // Get the primary address
586  Ipv4InterfaceAddress iaddr = ipv4->GetAddress (i, 0);
587  Ipv4Address addri = iaddr.GetLocal ();
588  if (addri == Ipv4Address ("127.0.0.1"))
589  continue;
590  // Check if interface-bound socket
591  if (m_boundnetdevice)
592  {
593  if (ipv4->GetNetDevice (i) != m_boundnetdevice)
594  continue;
595  }
596  Ipv4Mask maski = iaddr.GetMask ();
597  if (maski == Ipv4Mask::GetOnes ())
598  {
599  // if the network mask is 255.255.255.255, do not convert dest
600  NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << dest
601  << " (mask is " << maski << ")");
602  m_udp->Send (p->Copy (), addri, dest,
604  NotifyDataSent (p->GetSize ());
606  }
607  else
608  {
609  // Convert to subnet-directed broadcast
610  Ipv4Address bcast = addri.GetSubnetDirectedBroadcast (maski);
611  NS_LOG_LOGIC ("Sending one copy from " << addri << " to " << bcast
612  << " (mask is " << maski << ")");
613  m_udp->Send (p->Copy (), addri, bcast,
615  NotifyDataSent (p->GetSize ());
617  }
618  }
619  NS_LOG_LOGIC ("Limited broadcast end.");
620  return p->GetSize ();
621  }
623  {
624  m_udp->Send (p->Copy (), m_endPoint->GetLocalAddress (), dest,
625  m_endPoint->GetLocalPort (), port, 0);
626  NotifyDataSent (p->GetSize ());
628  return p->GetSize ();
629  }
630  else if (ipv4->GetRoutingProtocol () != 0)
631  {
632  Ipv4Header header;
633  header.SetDestination (dest);
635  Socket::SocketErrno errno_;
636  Ptr<Ipv4Route> route;
637  Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a specific device
638  // TBD-- we could cache the route and just check its validity
639  route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
640  if (route != 0)
641  {
642  NS_LOG_LOGIC ("Route exists");
643  if (!m_allowBroadcast)
644  {
645  uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->GetOutputDevice ());
646  uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
647  for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
648  {
649  Ipv4InterfaceAddress ifAddr = ipv4->GetAddress (outputIfIndex, addrI);
650  if (dest == ifAddr.GetBroadcast ())
651  {
653  return -1;
654  }
655  }
656  }
657 
658  header.SetSource (route->GetSource ());
659  m_udp->Send (p->Copy (), header.GetSource (), header.GetDestination (),
660  m_endPoint->GetLocalPort (), port, route);
661  NotifyDataSent (p->GetSize ());
662  return p->GetSize ();
663  }
664  else
665  {
666  NS_LOG_LOGIC ("No route to destination");
667  NS_LOG_ERROR (errno_);
668  m_errno = errno_;
669  return -1;
670  }
671  }
672  else
673  {
674  NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
676  return -1;
677  }
678 
679  return 0;
680 }
681 
682 int
684 {
685  NS_LOG_FUNCTION (this << p << dest << port);
686 
687  if (dest.IsIpv4MappedAddress ())
688  {
689  return (DoSendTo(p, dest.GetIpv4MappedAddress (), port));
690  }
691  if (m_boundnetdevice)
692  {
693  NS_LOG_LOGIC ("Bound interface number " << m_boundnetdevice->GetIfIndex ());
694  }
695  if (m_endPoint6 == 0)
696  {
697  if (Bind6 () == -1)
698  {
699  NS_ASSERT (m_endPoint6 == 0);
700  return -1;
701  }
702  NS_ASSERT (m_endPoint6 != 0);
703  }
704  if (m_shutdownSend)
705  {
707  return -1;
708  }
709 
710  if (p->GetSize () > GetTxAvailable () )
711  {
713  return -1;
714  }
715 
716  if (IsManualIpv6Tclass ())
717  {
718  SocketIpv6TclassTag ipTclassTag;
719  ipTclassTag.SetTclass (GetIpv6Tclass ());
720  p->AddPacketTag (ipTclassTag);
721  }
722 
723  Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6> ();
724 
725  // Locally override the IP TTL for this socket
726  // We cannot directly modify the TTL at this stage, so we set a Packet tag
727  // The destination can be either multicast, unicast/anycast, or
728  // either all-hosts broadcast or limited (subnet-directed) broadcast.
729  // For the latter two broadcast types, the TTL will later be set to one
730  // irrespective of what is set in these socket options. So, this tagging
731  // may end up setting the TTL of a limited broadcast packet to be
732  // the same as a unicast, but it will be fixed further down the stack
733  if (m_ipMulticastTtl != 0 && dest.IsMulticast ())
734  {
737  p->AddPacketTag (tag);
738  }
739  else if (IsManualIpv6HopLimit () && GetIpv6HopLimit () != 0 && !dest.IsMulticast ())
740  {
742  tag.SetHopLimit (GetIpv6HopLimit ());
743  p->AddPacketTag (tag);
744  }
745  // There is no analgous to an IPv4 broadcast address in IPv6.
746  // Instead, we use a set of link-local, site-local, and global
747  // multicast addresses. The Ipv6 routing layers should all
748  // provide an interface-specific route to these addresses such
749  // that we can treat these multicast addresses as "not broadcast"
750 
752  {
753  m_udp->Send (p->Copy (), m_endPoint6->GetLocalAddress (), dest,
754  m_endPoint6->GetLocalPort (), port, 0);
755  NotifyDataSent (p->GetSize ());
757  return p->GetSize ();
758  }
759  else if (ipv6->GetRoutingProtocol () != 0)
760  {
761  Ipv6Header header;
762  header.SetDestinationAddress (dest);
764  Socket::SocketErrno errno_;
765  Ptr<Ipv6Route> route;
766  Ptr<NetDevice> oif = m_boundnetdevice; //specify non-zero if bound to a specific device
767  // TBD-- we could cache the route and just check its validity
768  route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
769  if (route != 0)
770  {
771  NS_LOG_LOGIC ("Route exists");
772  header.SetSourceAddress (route->GetSource ());
773  m_udp->Send (p->Copy (), header.GetSourceAddress (), header.GetDestinationAddress (),
774  m_endPoint6->GetLocalPort (), port, route);
775  NotifyDataSent (p->GetSize ());
776  return p->GetSize ();
777  }
778  else
779  {
780  NS_LOG_LOGIC ("No route to destination");
781  NS_LOG_ERROR (errno_);
782  m_errno = errno_;
783  return -1;
784  }
785  }
786  else
787  {
788  NS_LOG_ERROR ("ERROR_NOROUTETOHOST");
790  return -1;
791  }
792 
793  return 0;
794 }
795 
796 
797 // maximum message size for UDP broadcast is limited by MTU
798 // size of underlying link; we are not checking that now.
799 // \todo Check MTU size of underlying link
800 uint32_t
802 {
804  // No finite send buffer is modelled, but we must respect
805  // the maximum size of an IP datagram (65535 bytes - headers).
807 }
808 
809 int
811 {
812  NS_LOG_FUNCTION (this << p << flags << address);
813  if (InetSocketAddress::IsMatchingType (address))
814  {
815  if (IsManualIpTos ())
816  {
817  SocketIpTosTag ipTosTag;
818  ipTosTag.SetTos (GetIpTos ());
819  p->AddPacketTag (ipTosTag);
820  }
821 
823  Ipv4Address ipv4 = transport.GetIpv4 ();
824  uint16_t port = transport.GetPort ();
825  return DoSendTo (p, ipv4, port);
826  }
827  else if (Inet6SocketAddress::IsMatchingType (address))
828  {
829  if (IsManualIpv6Tclass ())
830  {
831  SocketIpv6TclassTag ipTclassTag;
832  ipTclassTag.SetTclass (GetIpv6Tclass ());
833  p->AddPacketTag (ipTclassTag);
834  }
835 
837  Ipv6Address ipv6 = transport.GetIpv6 ();
838  uint16_t port = transport.GetPort ();
839  return DoSendTo (p, ipv6, port);
840  }
841  return -1;
842 }
843 
844 uint32_t
846 {
848  // We separately maintain this state to avoid walking the queue
849  // every time this might be called
850  return m_rxAvailable;
851 }
852 
854 UdpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
855 {
856  NS_LOG_FUNCTION (this << maxSize << flags);
857  if (m_deliveryQueue.empty () )
858  {
860  return 0;
861  }
862  Ptr<Packet> p = m_deliveryQueue.front ();
863  if (p->GetSize () <= maxSize)
864  {
865  m_deliveryQueue.pop ();
866  m_rxAvailable -= p->GetSize ();
867  }
868  else
869  {
870  p = 0;
871  }
872  return p;
873 }
874 
876 UdpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
877  Address &fromAddress)
878 {
879  NS_LOG_FUNCTION (this << maxSize << flags);
880  Ptr<Packet> packet = Recv (maxSize, flags);
881  if (packet != 0)
882  {
883  SocketAddressTag tag;
884  bool found;
885  found = packet->PeekPacketTag (tag);
886  NS_ASSERT (found);
887  fromAddress = tag.GetAddress ();
888  }
889  return packet;
890 }
891 
892 int
894 {
896  if (m_endPoint != 0)
897  {
899  }
900  else if (m_endPoint6 != 0)
901  {
903  }
904  else
905  { // It is possible to call this method on a socket without a name
906  // in which case, behavior is unspecified
907  // Should this return an InetSocketAddress or an Inet6SocketAddress?
908  address = InetSocketAddress (Ipv4Address::GetZero (), 0);
909  }
910  return 0;
911 }
912 
913 int
915 {
916  NS_LOG_FUNCTION (this << address);
917 
918  if (!m_connected)
919  {
921  return -1;
922  }
923 
925  {
927  address = InetSocketAddress (addr, m_defaultPort);
928  }
930  {
932  address = Inet6SocketAddress (addr, m_defaultPort);
933  }
934  else
935  {
936  NS_ASSERT_MSG (false, "unexpected address type");
937  }
938 
939  return 0;
940 }
941 
942 int
943 UdpSocketImpl::MulticastJoinGroup (uint32_t interface, const Address &groupAddress)
944 {
945  NS_LOG_FUNCTION (interface << groupAddress);
946  /*
947  1) sanity check interface
948  2) sanity check that it has not been called yet on this interface/group
949  3) determine address family of groupAddress
950  4) locally store a list of (interface, groupAddress)
951  5) call ipv4->MulticastJoinGroup () or Ipv6->MulticastJoinGroup ()
952  */
953  return 0;
954 }
955 
956 int
957 UdpSocketImpl::MulticastLeaveGroup (uint32_t interface, const Address &groupAddress)
958 {
959  NS_LOG_FUNCTION (interface << groupAddress);
960  /*
961  1) sanity check interface
962  2) determine address family of groupAddress
963  3) delete from local list of (interface, groupAddress); raise a LOG_WARN
964  if not already present (but return 0)
965  5) call ipv4->MulticastLeaveGroup () or Ipv6->MulticastLeaveGroup ()
966  */
967  return 0;
968 }
969 
970 void
972 {
973  NS_LOG_FUNCTION (netdevice);
974 
975  Socket::BindToNetDevice (netdevice); // Includes sanity check
976  if (m_endPoint == 0)
977  {
978  if (Bind () == -1)
979  {
980  NS_ASSERT (m_endPoint == 0);
981  return;
982  }
983  NS_ASSERT (m_endPoint != 0);
984  }
985  m_endPoint->BindToNetDevice (netdevice);
986 
987  if (m_endPoint6 == 0)
988  {
989  if (Bind6 () == -1)
990  {
991  NS_ASSERT (m_endPoint6 == 0);
992  return;
993  }
994  NS_ASSERT (m_endPoint6 != 0);
995  }
996  m_endPoint6->BindToNetDevice (netdevice);
997 
999  {
1001  if (ipv6l3)
1002  {
1003  uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
1004  ipv6l3->RemoveMulticastAddress (m_endPoint6->GetLocalAddress ());
1005  ipv6l3->AddMulticastAddress (m_endPoint6->GetLocalAddress (), index);
1006  }
1007  }
1008 
1009  return;
1010 }
1011 
1012 void
1014  Ptr<Ipv4Interface> incomingInterface)
1015 {
1016  NS_LOG_FUNCTION (this << packet << header << port);
1017 
1018  if (m_shutdownRecv)
1019  {
1020  return;
1021  }
1022 
1023  // Should check via getsockopt ()..
1024  if (IsRecvPktInfo ())
1025  {
1026  Ipv4PacketInfoTag tag;
1027  packet->RemovePacketTag (tag);
1028  tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
1029  packet->AddPacketTag (tag);
1030  }
1031 
1032  //Check only version 4 options
1033  if (IsIpRecvTos ())
1034  {
1035  SocketIpTosTag ipTosTag;
1036  ipTosTag.SetTos (header.GetTos ());
1037  packet->AddPacketTag (ipTosTag);
1038  }
1039 
1040  if (IsIpRecvTtl ())
1041  {
1042  SocketIpTtlTag ipTtlTag;
1043  ipTtlTag.SetTtl (header.GetTtl ());
1044  packet->AddPacketTag (ipTtlTag);
1045  }
1046 
1047  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
1048  {
1050  SocketAddressTag tag;
1051  tag.SetAddress (address);
1052  packet->AddPacketTag (tag);
1053  m_deliveryQueue.push (packet);
1054  m_rxAvailable += packet->GetSize ();
1055  NotifyDataRecv ();
1056  }
1057  else
1058  {
1059  // In general, this case should not occur unless the
1060  // receiving application reads data from this socket slowly
1061  // in comparison to the arrival rate
1062  //
1063  // drop and trace packet
1064  NS_LOG_WARN ("No receive buffer space available. Drop.");
1065  m_dropTrace (packet);
1066  }
1067 }
1068 
1069 void
1070 UdpSocketImpl::ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface)
1071 {
1072  NS_LOG_FUNCTION (this << packet << header.GetSourceAddress () << port);
1073 
1074  if (m_shutdownRecv)
1075  {
1076  return;
1077  }
1078 
1079  // Should check via getsockopt ()..
1080  if (IsRecvPktInfo ())
1081  {
1082  Ipv6PacketInfoTag tag;
1083  packet->RemovePacketTag (tag);
1084  tag.SetRecvIf (incomingInterface->GetDevice ()->GetIfIndex ());
1085  packet->AddPacketTag (tag);
1086  }
1087 
1088  //Check only version 6 options
1089  if (IsIpv6RecvTclass ())
1090  {
1091  SocketIpv6TclassTag ipTclassTag;
1092  ipTclassTag.SetTclass (header.GetTrafficClass ());
1093  packet->AddPacketTag (ipTclassTag);
1094  }
1095 
1096  if (IsIpv6RecvHopLimit ())
1097  {
1098  SocketIpv6HopLimitTag ipHopLimitTag;
1099  ipHopLimitTag.SetHopLimit (header.GetHopLimit ());
1100  packet->AddPacketTag (ipHopLimitTag);
1101  }
1102 
1103  if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize)
1104  {
1106  SocketAddressTag tag;
1107  tag.SetAddress (address);
1108  packet->AddPacketTag (tag);
1109  m_deliveryQueue.push (packet);
1110  m_rxAvailable += packet->GetSize ();
1111  NotifyDataRecv ();
1112  }
1113  else
1114  {
1115  // In general, this case should not occur unless the
1116  // receiving application reads data from this socket slowly
1117  // in comparison to the arrival rate
1118  //
1119  // drop and trace packet
1120  NS_LOG_WARN ("No receive buffer space available. Drop.");
1121  m_dropTrace (packet);
1122  }
1123 }
1124 
1125 void
1126 UdpSocketImpl::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
1127  uint8_t icmpType, uint8_t icmpCode,
1128  uint32_t icmpInfo)
1129 {
1130  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1131  (uint32_t)icmpCode << icmpInfo);
1132  if (!m_icmpCallback.IsNull ())
1133  {
1134  m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1135  }
1136 }
1137 
1138 void
1139 UdpSocketImpl::ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
1140  uint8_t icmpType, uint8_t icmpCode,
1141  uint32_t icmpInfo)
1142 {
1143  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1144  (uint32_t)icmpCode << icmpInfo);
1145  if (!m_icmpCallback6.IsNull ())
1146  {
1147  m_icmpCallback6 (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1148  }
1149 }
1150 
1151 void
1153 {
1154  m_rcvBufSize = size;
1155 }
1156 
1157 uint32_t
1159 {
1160  return m_rcvBufSize;
1161 }
1162 
1163 void
1165 {
1166  m_ipMulticastTtl = ipTtl;
1167 }
1168 
1169 uint8_t
1171 {
1172  return m_ipMulticastTtl;
1173 }
1174 
1175 void
1177 {
1178  m_ipMulticastIf = ipIf;
1179 }
1180 
1181 int32_t
1183 {
1184  return m_ipMulticastIf;
1185 }
1186 
1187 void
1189 {
1190  m_ipMulticastLoop = loop;
1191 }
1192 
1193 bool
1195 {
1196  return m_ipMulticastLoop;
1197 }
1198 
1199 void
1201 {
1202  m_mtuDiscover = discover;
1203 }
1204 bool
1206 {
1207  return m_mtuDiscover;
1208 }
1209 
1210 bool
1212 {
1213  m_allowBroadcast = allowBroadcast;
1214  return true;
1215 }
1216 
1217 bool
1219 {
1220  return m_allowBroadcast;
1221 }
1222 
1223 void
1224 UdpSocketImpl::Ipv6JoinGroup (Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector<Ipv6Address> sourceAddresses)
1225 {
1226  NS_LOG_FUNCTION (this << address << &filterMode << &sourceAddresses);
1227 
1228  // We can join only one multicast group (or change its params)
1229  NS_ASSERT_MSG ((m_ipv6MulticastGroupAddress == address || m_ipv6MulticastGroupAddress.IsAny ()), "Can join only one IPv6 multicast group.");
1230 
1232 
1234  if (ipv6l3)
1235  {
1236  if (filterMode == INCLUDE && sourceAddresses.empty ())
1237  {
1238  // it is a leave
1239  if (m_boundnetdevice)
1240  {
1241  int32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
1242  NS_ASSERT_MSG (index >= 0, "Interface without a valid index");
1243  ipv6l3->RemoveMulticastAddress (address, index);
1244  }
1245  else
1246  {
1247  ipv6l3->RemoveMulticastAddress (address);
1248  }
1249  }
1250  else
1251  {
1252  // it is a join or a modification
1253  if (m_boundnetdevice)
1254  {
1255  int32_t index = ipv6l3->GetInterfaceForDevice (m_boundnetdevice);
1256  NS_ASSERT_MSG (index >= 0, "Interface without a valid index");
1257  ipv6l3->AddMulticastAddress (address, index);
1258  }
1259  else
1260  {
1261  ipv6l3->AddMulticastAddress (address);
1262  }
1263  }
1264  }
1265 }
1266 
1267 } // 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:854
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
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
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:1101
#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:234
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.
std::queue< Ptr< Packet > > m_deliveryQueue
Queue for incoming packets.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:824
void SetAddress(Address addr)
Set the tag's address.
Definition: socket.cc:555
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:786
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.
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:797
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:1053
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:1871
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.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:846
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.
int DoSendTo(Ptr< Packet > p, const Address &daddr)
Send a packet to a specific destination.
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:616
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.
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:1913
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.
This class implements a tag that carries an address of a packet across the socket interface...
Definition: socket.h:1005
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
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:677
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:1246
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:738
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
Address GetAddress(void) const
Get the tag's address.
Definition: socket.cc:562
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:1149
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:732
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.
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Definition: socket.h:122
#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
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
indicates whether the socket has IP_TOS set.
Definition: socket.h:1199
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
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:826
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.