A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
socket.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Georgia Tech Research Corporation
3  * 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  * Authors: George F. Riley<riley@ece.gatech.edu>
19  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  */
21 
22 #include "socket.h"
23 
24 #include "node.h"
25 #include "packet.h"
26 #include "socket-factory.h"
27 
28 #include "ns3/log.h"
29 
30 #include <limits>
31 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("Socket");
36 
38 
39 TypeId
41 {
42  static TypeId tid = TypeId("ns3::Socket").SetParent<Object>().SetGroupName("Network");
43  return tid;
44 }
45 
47  : m_manualIpTtl(false),
48  m_ipRecvTos(false),
49  m_ipRecvTtl(false),
50  m_manualIpv6Tclass(false),
51  m_manualIpv6HopLimit(false),
52  m_ipv6RecvTclass(false),
53  m_ipv6RecvHopLimit(false)
54 {
56  m_boundnetdevice = nullptr;
57  m_recvPktInfo = false;
58 
59  m_priority = 0;
60  m_ipTos = 0;
61  m_ipTtl = 0;
62  m_ipv6Tclass = 0;
63  m_ipv6HopLimit = 0;
64 }
65 
67 {
68  NS_LOG_FUNCTION(this);
69 }
70 
73 {
74  NS_LOG_FUNCTION(node << tid);
75  Ptr<Socket> s;
76  NS_ASSERT_MSG(node, "CreateSocket: node is null.");
77  Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory>(tid);
78  NS_ASSERT_MSG(socketFactory,
79  "CreateSocket: can not create a "
80  << tid.GetName() << " - perhaps the node is missing the required protocol.");
81  s = socketFactory->CreateSocket();
82  NS_ASSERT(s);
83  return s;
84 }
85 
86 void
87 Socket::SetConnectCallback(Callback<void, Ptr<Socket>> connectionSucceeded,
88  Callback<void, Ptr<Socket>> connectionFailed)
89 {
90  NS_LOG_FUNCTION(this << &connectionSucceeded << &connectionFailed);
91  m_connectionSucceeded = connectionSucceeded;
92  m_connectionFailed = connectionFailed;
93 }
94 
95 void
97  Callback<void, Ptr<Socket>> errorClose)
98 {
99  NS_LOG_FUNCTION(this << &normalClose << &errorClose);
100  m_normalClose = normalClose;
101  m_errorClose = errorClose;
102 }
103 
104 void
105 Socket::SetAcceptCallback(Callback<bool, Ptr<Socket>, const Address&> connectionRequest,
106  Callback<void, Ptr<Socket>, const Address&> newConnectionCreated)
107 {
108  NS_LOG_FUNCTION(this << &connectionRequest << &newConnectionCreated);
109  m_connectionRequest = connectionRequest;
110  m_newConnectionCreated = newConnectionCreated;
111 }
112 
113 void
115 {
116  NS_LOG_FUNCTION(this << &dataSent);
117  m_dataSent = dataSent;
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION(this << &sendCb);
124  m_sendCb = sendCb;
125 }
126 
127 void
129 {
130  NS_LOG_FUNCTION(this << &receivedData);
131  m_receivedData = receivedData;
132 }
133 
134 int
136 {
137  NS_LOG_FUNCTION(this << p);
138  return Send(p, 0);
139 }
140 
141 int
142 Socket::Send(const uint8_t* buf, uint32_t size, uint32_t flags)
143 {
144  NS_LOG_FUNCTION(this << &buf << size << flags);
145  Ptr<Packet> p;
146  if (buf)
147  {
148  p = Create<Packet>(buf, size);
149  }
150  else
151  {
152  p = Create<Packet>(size);
153  }
154  return Send(p, flags);
155 }
156 
157 int
158 Socket::SendTo(const uint8_t* buf, uint32_t size, uint32_t flags, const Address& toAddress)
159 {
160  NS_LOG_FUNCTION(this << &buf << size << flags << &toAddress);
161  Ptr<Packet> p;
162  if (buf)
163  {
164  p = Create<Packet>(buf, size);
165  }
166  else
167  {
168  p = Create<Packet>(size);
169  }
170  return SendTo(p, flags, toAddress);
171 }
172 
175 {
176  NS_LOG_FUNCTION(this);
178 }
179 
180 int
181 Socket::Recv(uint8_t* buf, uint32_t size, uint32_t flags)
182 {
183  NS_LOG_FUNCTION(this << &buf << size << flags);
184  Ptr<Packet> p = Recv(size, flags); // read up to "size" bytes
185  if (!p)
186  {
187  return 0;
188  }
189  p->CopyData(buf, p->GetSize());
190  return p->GetSize();
191 }
192 
195 {
196  NS_LOG_FUNCTION(this << &fromAddress);
197  return RecvFrom(std::numeric_limits<uint32_t>::max(), 0, fromAddress);
198 }
199 
200 int
201 Socket::RecvFrom(uint8_t* buf, uint32_t size, uint32_t flags, Address& fromAddress)
202 {
203  NS_LOG_FUNCTION(this << &buf << size << flags << &fromAddress);
204  Ptr<Packet> p = RecvFrom(size, flags, fromAddress);
205  if (!p)
206  {
207  return 0;
208  }
209  p->CopyData(buf, p->GetSize());
210  return p->GetSize();
211 }
212 
213 void
215 {
216  NS_LOG_FUNCTION(this);
217  if (!m_connectionSucceeded.IsNull())
218  {
219  m_connectionSucceeded(this);
220  }
221 }
222 
223 void
225 {
226  NS_LOG_FUNCTION(this);
227  if (!m_connectionFailed.IsNull())
228  {
229  m_connectionFailed(this);
230  }
231 }
232 
233 void
235 {
236  NS_LOG_FUNCTION(this);
237  if (!m_normalClose.IsNull())
238  {
239  m_normalClose(this);
240  }
241 }
242 
243 void
245 {
246  NS_LOG_FUNCTION(this);
247  if (!m_errorClose.IsNull())
248  {
249  m_errorClose(this);
250  }
251 }
252 
253 bool
255 {
256  NS_LOG_FUNCTION(this << &from);
257  if (!m_connectionRequest.IsNull())
258  {
259  return m_connectionRequest(this, from);
260  }
261  else
262  {
263  // accept all incoming connections by default.
264  // this way people writing code don't have to do anything
265  // special like register a callback that returns true
266  // just to get incoming connections
267  return true;
268  }
269 }
270 
271 void
273 {
274  NS_LOG_FUNCTION(this << socket << from);
275  if (!m_newConnectionCreated.IsNull())
276  {
277  m_newConnectionCreated(socket, from);
278  }
279 }
280 
281 void
283 {
284  NS_LOG_FUNCTION(this << size);
285  if (!m_dataSent.IsNull())
286  {
287  m_dataSent(this, size);
288  }
289 }
290 
291 void
292 Socket::NotifySend(uint32_t spaceAvailable)
293 {
294  NS_LOG_FUNCTION(this << spaceAvailable);
295  if (!m_sendCb.IsNull())
296  {
297  m_sendCb(this, spaceAvailable);
298  }
299 }
300 
301 void
303 {
304  NS_LOG_FUNCTION(this);
305  if (!m_receivedData.IsNull())
306  {
307  m_receivedData(this);
308  }
309 }
310 
311 void
313 {
314  NS_LOG_FUNCTION(this);
315  m_connectionSucceeded = MakeNullCallback<void, Ptr<Socket>>();
316  m_connectionFailed = MakeNullCallback<void, Ptr<Socket>>();
317  m_normalClose = MakeNullCallback<void, Ptr<Socket>>();
318  m_errorClose = MakeNullCallback<void, Ptr<Socket>>();
319  m_connectionRequest = MakeNullCallback<bool, Ptr<Socket>, const Address&>();
320  m_newConnectionCreated = MakeNullCallback<void, Ptr<Socket>, const Address&>();
321  m_dataSent = MakeNullCallback<void, Ptr<Socket>, uint32_t>();
322  m_sendCb = MakeNullCallback<void, Ptr<Socket>, uint32_t>();
323  m_receivedData = MakeNullCallback<void, Ptr<Socket>>();
324 }
325 
326 void
328 {
329  NS_LOG_FUNCTION(this << netdevice);
330  if (netdevice)
331  {
332  bool found = false;
333  for (uint32_t i = 0; i < GetNode()->GetNDevices(); i++)
334  {
335  if (GetNode()->GetDevice(i) == netdevice)
336  {
337  found = true;
338  break;
339  }
340  }
341  NS_ASSERT_MSG(found, "Socket cannot be bound to a NetDevice not existing on the Node");
342  }
343  m_boundnetdevice = netdevice;
344 }
345 
348 {
349  NS_LOG_FUNCTION(this);
350  return m_boundnetdevice;
351 }
352 
353 void
355 {
356  NS_LOG_FUNCTION(this << flag);
357  m_recvPktInfo = flag;
358 }
359 
360 bool
362 {
363  NS_LOG_FUNCTION(this);
364  return m_recvPktInfo;
365 }
366 
367 bool
369 {
370  return m_manualIpv6Tclass;
371 }
372 
373 bool
375 {
376  return m_manualIpTtl;
377 }
378 
379 bool
381 {
382  return m_manualIpv6HopLimit;
383 }
384 
385 void
386 Socket::SetPriority(uint8_t priority)
387 {
388  NS_LOG_FUNCTION(this << priority);
389  m_priority = priority;
390 }
391 
392 uint8_t
394 {
395  return m_priority;
396 }
397 
398 uint8_t
400 {
401  uint8_t prio = NS3_PRIO_BESTEFFORT;
402  ipTos &= 0x1e;
403  switch (ipTos >> 1)
404  {
405  case 0:
406  case 1:
407  case 2:
408  case 3:
409  prio = NS3_PRIO_BESTEFFORT;
410  break;
411  case 4:
412  case 5:
413  case 6:
414  case 7:
415  prio = NS3_PRIO_BULK;
416  break;
417  case 8:
418  case 9:
419  case 10:
420  case 11:
421  prio = NS3_PRIO_INTERACTIVE;
422  break;
423  case 12:
424  case 13:
425  case 14:
426  case 15:
428  break;
429  }
430  return prio;
431 }
432 
433 void
434 Socket::SetIpTos(uint8_t tos)
435 {
439  {
440  // preserve the least two significant bits of the current TOS
441  // value, which are used for ECN
442  tos &= 0xfc;
443  tos |= m_ipTos & 0x3;
444  }
445  m_ipTos = tos;
446  m_priority = IpTos2Priority(tos);
447 }
448 
449 uint8_t
451 {
452  return m_ipTos;
453 }
454 
455 void
456 Socket::SetIpRecvTos(bool ipv4RecvTos)
457 {
458  m_ipRecvTos = ipv4RecvTos;
459 }
460 
461 bool
463 {
464  return m_ipRecvTos;
465 }
466 
467 void
469 {
472 
473  // If -1 or invalid values, use default
474  if (tclass == -1 || tclass < -1 || tclass > 0xff)
475  {
476  // Print a warning
477  if (tclass < -1 || tclass > 0xff)
478  {
479  NS_LOG_WARN("Invalid IPV6_TCLASS value. Using default.");
480  }
481  m_manualIpv6Tclass = false;
482  m_ipv6Tclass = 0;
483  }
484  else
485  {
486  m_manualIpv6Tclass = true;
487  m_ipv6Tclass = tclass;
488  }
489 }
490 
491 uint8_t
493 {
494  return m_ipv6Tclass;
495 }
496 
497 void
498 Socket::SetIpv6RecvTclass(bool ipv6RecvTclass)
499 {
500  m_ipv6RecvTclass = ipv6RecvTclass;
501 }
502 
503 bool
505 {
506  return m_ipv6RecvTclass;
507 }
508 
509 void
510 Socket::SetIpTtl(uint8_t ttl)
511 {
512  m_manualIpTtl = true;
513  m_ipTtl = ttl;
514 }
515 
516 uint8_t
518 {
519  return m_ipTtl;
520 }
521 
522 void
523 Socket::SetIpRecvTtl(bool ipv4RecvTtl)
524 {
525  m_ipRecvTtl = ipv4RecvTtl;
526 }
527 
528 bool
530 {
531  return m_ipRecvTtl;
532 }
533 
534 void
535 Socket::SetIpv6HopLimit(uint8_t ipHopLimit)
536 {
537  m_manualIpv6HopLimit = true;
538  m_ipv6HopLimit = ipHopLimit;
539 }
540 
541 uint8_t
543 {
544  return m_ipv6HopLimit;
545 }
546 
547 void
548 Socket::SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
549 {
550  m_ipv6RecvHopLimit = ipv6RecvHopLimit;
551 }
552 
553 bool
555 {
556  return m_ipv6RecvHopLimit;
557 }
558 
559 void
561  Ipv6MulticastFilterMode filterMode,
562  std::vector<Ipv6Address> sourceAddresses)
563 {
564  NS_LOG_FUNCTION(this << address << &filterMode << &sourceAddresses);
565  NS_ASSERT_MSG(false, "Ipv6JoinGroup not implemented on this socket");
566 }
567 
568 void
570 {
571  NS_LOG_FUNCTION(this << address);
572 
573  // Join Group. Note that joining a group with no sources means joining without source
574  // restrictions.
575  std::vector<Ipv6Address> sourceAddresses;
576  Ipv6JoinGroup(address, EXCLUDE, sourceAddresses);
577 }
578 
579 void
581 {
582  NS_LOG_FUNCTION(this);
584  {
585  NS_LOG_INFO(" The socket was not bound to any group.");
586  return;
587  }
588  // Leave Group. Note that joining a group with no sources means leaving it.
589  std::vector<Ipv6Address> sourceAddresses;
592 }
593 
594 /***************************************************************
595  * Socket Tags
596  ***************************************************************/
597 
599 {
600  NS_LOG_FUNCTION(this);
601 }
602 
603 void
605 {
606  NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
607  m_ttl = ttl;
608 }
609 
610 uint8_t
612 {
613  NS_LOG_FUNCTION(this);
614  return m_ttl;
615 }
616 
618 
619 TypeId
621 {
622  static TypeId tid = TypeId("ns3::SocketIpTtlTag")
623  .SetParent<Tag>()
624  .SetGroupName("Network")
625  .AddConstructor<SocketIpTtlTag>();
626  return tid;
627 }
628 
629 TypeId
631 {
632  return GetTypeId();
633 }
634 
635 uint32_t
637 {
638  NS_LOG_FUNCTION(this);
639  return 1;
640 }
641 
642 void
644 {
645  NS_LOG_FUNCTION(this << &i);
646  i.WriteU8(m_ttl);
647 }
648 
649 void
651 {
652  NS_LOG_FUNCTION(this << &i);
653  m_ttl = i.ReadU8();
654 }
655 
656 void
657 SocketIpTtlTag::Print(std::ostream& os) const
658 {
659  NS_LOG_FUNCTION(this << &os);
660  os << "Ttl=" << (uint32_t)m_ttl;
661 }
662 
664 {
665 }
666 
667 void
669 {
670  m_hopLimit = hopLimit;
671 }
672 
673 uint8_t
675 {
676  return m_hopLimit;
677 }
678 
680 
681 TypeId
683 {
684  static TypeId tid = TypeId("ns3::SocketIpv6HopLimitTag")
685  .SetParent<Tag>()
686  .SetGroupName("Network")
687  .AddConstructor<SocketIpv6HopLimitTag>();
688  return tid;
689 }
690 
691 TypeId
693 {
694  return GetTypeId();
695 }
696 
697 uint32_t
699 {
700  return 1;
701 }
702 
703 void
705 {
706  i.WriteU8(m_hopLimit);
707 }
708 
709 void
711 {
712  m_hopLimit = i.ReadU8();
713 }
714 
715 void
716 SocketIpv6HopLimitTag::Print(std::ostream& os) const
717 {
718  os << "HopLimit=" << (uint32_t)m_hopLimit;
719 }
720 
722 {
723  NS_LOG_FUNCTION(this);
724 }
725 
726 void
728 {
729  NS_LOG_FUNCTION(this);
730  m_dontFragment = true;
731 }
732 
733 void
735 {
736  NS_LOG_FUNCTION(this);
737  m_dontFragment = false;
738 }
739 
740 bool
742 {
743  NS_LOG_FUNCTION(this);
744  return m_dontFragment;
745 }
746 
748 
749 TypeId
751 {
752  static TypeId tid = TypeId("ns3::SocketSetDontFragmentTag")
753  .SetParent<Tag>()
754  .SetGroupName("Network")
755  .AddConstructor<SocketSetDontFragmentTag>();
756  return tid;
757 }
758 
759 TypeId
761 {
762  return GetTypeId();
763 }
764 
765 uint32_t
767 {
768  NS_LOG_FUNCTION(this);
769  return 1;
770 }
771 
772 void
774 {
775  NS_LOG_FUNCTION(this << &i);
776  i.WriteU8(m_dontFragment ? 1 : 0);
777 }
778 
779 void
781 {
782  NS_LOG_FUNCTION(this << &i);
783  m_dontFragment = (i.ReadU8() == 1);
784 }
785 
786 void
787 SocketSetDontFragmentTag::Print(std::ostream& os) const
788 {
789  NS_LOG_FUNCTION(this << &os);
790  os << (m_dontFragment ? "true" : "false");
791 }
792 
794 {
795 }
796 
797 void
799 {
800  m_ipTos = ipTos;
801 }
802 
803 uint8_t
805 {
806  return m_ipTos;
807 }
808 
809 TypeId
811 {
812  static TypeId tid = TypeId("ns3::SocketIpTosTag")
813  .SetParent<Tag>()
814  .SetGroupName("Network")
815  .AddConstructor<SocketIpTosTag>();
816  return tid;
817 }
818 
819 TypeId
821 {
822  return GetTypeId();
823 }
824 
825 uint32_t
827 {
828  return sizeof(uint8_t);
829 }
830 
831 void
833 {
834  i.WriteU8(m_ipTos);
835 }
836 
837 void
839 {
840  m_ipTos = i.ReadU8();
841 }
842 
843 void
844 SocketIpTosTag::Print(std::ostream& os) const
845 {
846  os << "IP_TOS = " << m_ipTos;
847 }
848 
850 {
851 }
852 
853 void
855 {
856  m_priority = priority;
857 }
858 
859 uint8_t
861 {
862  return m_priority;
863 }
864 
865 TypeId
867 {
868  static TypeId tid = TypeId("ns3::SocketPriorityTag")
869  .SetParent<Tag>()
870  .SetGroupName("Network")
871  .AddConstructor<SocketPriorityTag>();
872  return tid;
873 }
874 
875 TypeId
877 {
878  return GetTypeId();
879 }
880 
881 uint32_t
883 {
884  return sizeof(uint8_t);
885 }
886 
887 void
889 {
890  i.WriteU8(m_priority);
891 }
892 
893 void
895 {
896  m_priority = i.ReadU8();
897 }
898 
899 void
900 SocketPriorityTag::Print(std::ostream& os) const
901 {
902  os << "SO_PRIORITY = " << m_priority;
903 }
904 
906 {
907 }
908 
909 void
911 {
912  m_ipv6Tclass = tclass;
913 }
914 
915 uint8_t
917 {
918  return m_ipv6Tclass;
919 }
920 
921 TypeId
923 {
924  static TypeId tid = TypeId("ns3::SocketIpv6TclassTag")
925  .SetParent<Tag>()
926  .SetGroupName("Network")
927  .AddConstructor<SocketIpv6TclassTag>();
928  return tid;
929 }
930 
931 TypeId
933 {
934  return GetTypeId();
935 }
936 
937 uint32_t
939 {
940  return sizeof(uint8_t);
941 }
942 
943 void
945 {
947 }
948 
949 void
951 {
952  m_ipv6Tclass = i.ReadU8();
953 }
954 
955 void
956 SocketIpv6TclassTag::Print(std::ostream& os) const
957 {
958  os << "IPV6_TCLASS = " << m_ipv6Tclass;
959 }
960 
961 } // namespace ns3
#define max(a, b)
Definition: 80211b.c:42
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
Describes an IPv6 address.
Definition: ipv6-address.h:49
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsAny() const
If the IPv6 address is the "Any" address.
uint32_t GetNDevices() const
Definition: node.cc:162
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:152
A base class which provides memory management and object aggregation.
Definition: object.h:89
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:861
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:400
Object to create transport layer instances that provide a socket API to applications.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
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
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
Definition: socket.cc:510
virtual Socket::SocketType GetSocketType() const =0
Ptr< Packet > Recv()
Read a single packet from the socket.
Definition: socket.cc:174
Callback< void, Ptr< Socket > > m_normalClose
connection closed callback
Definition: socket.h:1087
virtual void Ipv6LeaveGroup()
Leaves IPv6 multicast group this socket is joined to.
Definition: socket.cc:580
bool m_ipv6RecvHopLimit
socket forwards IPv6 Hop Limit tag to L4
Definition: socket.h:1111
uint8_t m_ipTos
the socket IPv4 TOS
Definition: socket.h:1104
uint8_t m_priority
the socket priority
Definition: socket.h:1097
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
bool m_manualIpv6HopLimit
socket has IPv6 Hop Limit set
Definition: socket.h:1109
Callback< bool, Ptr< Socket >, const Address & > m_connectionRequest
connection request callback
Definition: socket.h:1090
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:354
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:292
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Notify through the callback (if set) that a new connection has been created.
Definition: socket.cc:272
virtual uint8_t GetIpTtl() const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:517
Callback< void, Ptr< Socket > > m_connectionFailed
connection failed callback
Definition: socket.h:1086
void SetCloseCallbacks(Callback< void, Ptr< Socket >> normalClose, Callback< void, Ptr< Socket >> errorClose)
Detect socket recv() events such as graceful shutdown or error.
Definition: socket.cc:96
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:40
void SetAcceptCallback(Callback< bool, Ptr< Socket >, const Address & > connectionRequest, Callback< void, Ptr< Socket >, const Address & > newConnectionCreated)
Accept connection requests from remote hosts.
Definition: socket.cc:105
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition: socket.cc:361
bool NotifyConnectionRequest(const Address &from)
Notify through the callback (if set) that an incoming connection is being requested by a remote host.
Definition: socket.cc:254
uint8_t m_ipTtl
the socket IPv4 TTL
Definition: socket.h:1105
uint8_t m_ipv6HopLimit
the socket IPv6 Hop Limit
Definition: socket.h:1114
uint8_t GetIpTos() const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:450
~Socket() override
Definition: socket.cc:66
void SetIpRecvTos(bool ipv4RecvTos)
Tells a socket to pass information about IP Type of Service up the stack.
Definition: socket.cc:456
void SetRecvCallback(Callback< void, Ptr< Socket >> receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
Definition: socket.h:1082
bool m_ipRecvTos
socket forwards IPv4 TOS tag to L4
Definition: socket.h:1101
@ NS3_SOCK_STREAM
Definition: socket.h:108
virtual void SetIpv6HopLimit(uint8_t ipHopLimit)
Manually set IPv6 Hop Limit.
Definition: socket.cc:535
uint8_t m_ipv6Tclass
the socket IPv6 Tclass
Definition: socket.h:1113
bool m_recvPktInfo
if the socket should add packet info tags to the packet forwarded to L4.
Definition: socket.h:1081
Callback< void, Ptr< Socket > > m_connectionSucceeded
connection succeeded callback
Definition: socket.h:1085
void SetDataSentCallback(Callback< void, Ptr< Socket >, uint32_t > dataSent)
Notify application when a packet has been sent from transport protocol (non-standard socket call)
Definition: socket.cc:114
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
Definition: socket.cc:399
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
Definition: socket.cc:121
void NotifyErrorClose()
Notify through the callback (if set) that the connection has been closed due to an error.
Definition: socket.cc:244
void NotifyDataRecv()
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:302
void SetPriority(uint8_t priority)
Manually set the socket priority.
Definition: socket.cc:386
bool m_ipv6RecvTclass
socket forwards IPv6 Tclass tag to L4
Definition: socket.h:1110
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 Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:327
@ NS3_PRIO_BULK
Definition: socket.h:125
@ NS3_PRIO_BESTEFFORT
Definition: socket.h:123
@ NS3_PRIO_INTERACTIVE
Definition: socket.h:127
@ NS3_PRIO_INTERACTIVE_BULK
Definition: socket.h:126
bool m_ipRecvTtl
socket forwards IPv4 TTL tag to L4
Definition: socket.h:1102
virtual int GetSockName(Address &address) const =0
Get socket address.
virtual void Ipv6JoinGroup(Ipv6Address address, Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
Joins a IPv6 multicast group.
Definition: socket.cc:560
Callback< void, Ptr< Socket > > m_receivedData
data received callback
Definition: socket.h:1095
void NotifyNormalClose()
Notify through the callback (if set) that the connection has been closed.
Definition: socket.cc:234
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
bool m_manualIpv6Tclass
socket has IPv6 Tclass set
Definition: socket.h:1108
Callback< void, Ptr< Socket >, const Address & > m_newConnectionCreated
connection created callback
Definition: socket.h:1092
bool m_manualIpTtl
socket has IPv4 TTL set
Definition: socket.h:1100
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:72
Callback< void, Ptr< Socket >, uint32_t > m_dataSent
data sent callback
Definition: socket.h:1093
bool IsIpRecvTos() const
Ask if the socket is currently passing information about IP Type of Service up the stack.
Definition: socket.cc:462
Callback< void, Ptr< Socket >, uint32_t > m_sendCb
packet sent callback
Definition: socket.h:1094
void SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
Tells a socket to pass information about IPv6 Hop Limit up the stack.
Definition: socket.cc:548
void SetIpv6Tclass(int ipTclass)
Manually set IPv6 Traffic Class field.
Definition: socket.cc:468
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:282
void SetConnectCallback(Callback< void, Ptr< Socket >> connectionSucceeded, Callback< void, Ptr< Socket >> connectionFailed)
Specify callbacks to allow the caller to determine if the connection succeeds of fails.
Definition: socket.cc:87
void NotifyConnectionSucceeded()
Notify through the callback (if set) that the connection has been established.
Definition: socket.cc:214
void SetIpRecvTtl(bool ipv4RecvTtl)
Tells a socket to pass information about IP_TTL up the stack.
Definition: socket.cc:523
uint8_t GetPriority() const
Query the priority value of this socket.
Definition: socket.cc:393
void SetIpv6RecvTclass(bool ipv6RecvTclass)
Tells a socket to pass information about IPv6 Traffic Class up the stack.
Definition: socket.cc:498
void DoDispose() override
Destructor implementation.
Definition: socket.cc:312
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
uint8_t GetIpv6Tclass() const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:492
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
bool IsManualIpv6HopLimit() const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:380
Callback< void, Ptr< Socket > > m_errorClose
connection closed due to errors callback
Definition: socket.h:1088
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
uint8_t m_ipTos
the TOS carried by the tag
Definition: socket.h:1309
void Serialize(TagBuffer i) const override
Definition: socket.cc:832
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:810
uint32_t GetSerializedSize() const override
Definition: socket.cc:826
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:798
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: socket.cc:820
uint8_t GetTos() const
Get the tag's TOS.
Definition: socket.cc:804
void Print(std::ostream &os) const override
Definition: socket.cc:844
void Deserialize(TagBuffer i) override
Definition: socket.cc:838
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
void Deserialize(TagBuffer i) override
Definition: socket.cc:650
uint32_t GetSerializedSize() const override
Definition: socket.cc:636
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: socket.cc:630
void Serialize(TagBuffer i) const override
Definition: socket.cc:643
uint8_t GetTtl() const
Get the tag's TTL.
Definition: socket.cc:611
uint8_t m_ttl
the ttl carried by the tag
Definition: socket.h:1162
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:620
void Print(std::ostream &os) const override
Definition: socket.cc:657
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition: socket.h:1170
uint32_t GetSerializedSize() const override
Definition: socket.cc:698
uint8_t GetHopLimit() const
Get the tag's Hop Limit.
Definition: socket.cc:674
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:682
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: socket.cc:692
void Serialize(TagBuffer i) const override
Definition: socket.cc:704
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:668
void Print(std::ostream &os) const override
Definition: socket.cc:716
uint8_t m_hopLimit
the Hop Limit carried by the tag
Definition: socket.h:1210
void Deserialize(TagBuffer i) override
Definition: socket.cc:710
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1364
void Serialize(TagBuffer i) const override
Definition: socket.cc:944
void Print(std::ostream &os) const override
Definition: socket.cc:956
uint8_t GetTclass() const
Get the tag's Tclass.
Definition: socket.cc:916
uint32_t GetSerializedSize() const override
Definition: socket.cc:938
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:922
uint8_t m_ipv6Tclass
the Tclass carried by the tag
Definition: socket.h:1404
void Deserialize(TagBuffer i) override
Definition: socket.cc:950
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: socket.cc:932
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
uint8_t m_priority
the priority carried by the tag
Definition: socket.h:1356
void Print(std::ostream &os) const override
Definition: socket.cc:900
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: socket.cc:876
uint32_t GetSerializedSize() const override
Definition: socket.cc:882
void Deserialize(TagBuffer i) override
Definition: socket.cc:894
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:866
uint8_t GetPriority() const
Get the tag's priority.
Definition: socket.cc:860
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition: socket.cc:854
void Serialize(TagBuffer i) const override
Definition: socket.cc:888
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
Definition: socket.h:1218
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: socket.cc:760
static TypeId GetTypeId()
Get the type ID.
Definition: socket.cc:750
void Enable()
Enables the DF (Don't Fragment) flag.
Definition: socket.cc:727
void Deserialize(TagBuffer i) override
Definition: socket.cc:780
uint32_t GetSerializedSize() const override
Definition: socket.cc:766
void Print(std::ostream &os) const override
Definition: socket.cc:787
void Serialize(TagBuffer i) const override
Definition: socket.cc:773
bool m_dontFragment
DF bit value for outgoing packets.
Definition: socket.h:1261
bool IsEnabled() const
Checks if the DF (Don't Fragment) flag is set.
Definition: socket.cc:741
void Disable()
Disables the DF (Don't Fragment) flag.
Definition: socket.cc:734
read and write tag data
Definition: tag-buffer.h:52
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:172
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition: tag-buffer.h:196
tag a set of bytes in a packet
Definition: tag.h:39
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
std::string GetName() const
Get the name.
Definition: type-id.cc:991
#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_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.