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