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