A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
socket.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2006 Georgia Tech Research Corporation
4  * 2007 INRIA
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: George F. Riley<riley@ece.gatech.edu>
20  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
21  */
22 
23 #include "ns3/log.h"
24 #include "ns3/packet.h"
25 #include "node.h"
26 #include "socket.h"
27 #include "socket-factory.h"
28 #include <limits>
29 
30 NS_LOG_COMPONENT_DEFINE ("Socket");
31 
32 namespace ns3 {
33 
35  ;
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::Socket")
41  .SetParent<Object> ();
42  return tid;
43 }
44 
46  : m_manualIpTos (false),
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 = 0;
57  m_recvPktInfo = false;
58 
59  m_ipTos = 0;
60  m_ipTtl = 0;
61  m_ipv6Tclass = 0;
62  m_ipv6HopLimit = 0;
63 }
64 
66 {
67  NS_LOG_FUNCTION (this);
68 }
69 
72 {
73  NS_LOG_FUNCTION (node << tid);
74  Ptr<Socket> s;
75  NS_ASSERT (node != 0);
76  Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
77  NS_ASSERT (socketFactory != 0);
78  s = socketFactory->CreateSocket ();
79  NS_ASSERT (s != 0);
80  return s;
81 }
82 
83 void
85  Callback<void, Ptr<Socket> > connectionSucceeded,
86  Callback<void, Ptr<Socket> > connectionFailed)
87 {
88  NS_LOG_FUNCTION (this << &connectionSucceeded << &connectionFailed);
89  m_connectionSucceeded = connectionSucceeded;
90  m_connectionFailed = connectionFailed;
91 }
92 
93 void
95  Callback<void, Ptr<Socket> > normalClose,
96  Callback<void, Ptr<Socket> > errorClose)
97 {
98  NS_LOG_FUNCTION (this << &normalClose << &errorClose);
99  m_normalClose = normalClose;
100  m_errorClose = errorClose;
101 }
102 
103 void
105  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,
159  const Address &toAddress)
160 {
161  NS_LOG_FUNCTION (this << &buf << size << flags << &toAddress);
162  Ptr<Packet> p;
163  if(buf)
164  {
165  p = Create<Packet> (buf, size);
166  }
167  else
168  {
169  p = Create<Packet> (size);
170  }
171  return SendTo (p, flags, toAddress);
172 }
173 
176 {
177  NS_LOG_FUNCTION (this);
178  return Recv (std::numeric_limits<uint32_t>::max (), 0);
179 }
180 
181 int
182 Socket::Recv (uint8_t* buf, uint32_t size, uint32_t flags)
183 {
184  NS_LOG_FUNCTION (this << &buf << size << flags);
185  Ptr<Packet> p = Recv (size, flags); // read up to "size" bytes
186  if (p == 0)
187  {
188  return 0;
189  }
190  p->CopyData (buf, p->GetSize ());
191  return p->GetSize ();
192 }
193 
195 Socket::RecvFrom (Address &fromAddress)
196 {
197  NS_LOG_FUNCTION (this << &fromAddress);
198  return RecvFrom (std::numeric_limits<uint32_t>::max (), 0, fromAddress);
199 }
200 
201 int
202 Socket::RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags,
203  Address &fromAddress)
204 {
205  NS_LOG_FUNCTION (this << &buf << size << flags << &fromAddress);
206  Ptr<Packet> p = RecvFrom (size, flags, fromAddress);
207  if (p == 0)
208  {
209  return 0;
210  }
211  p->CopyData (buf, p->GetSize ());
212  return p->GetSize ();
213 }
214 
215 
216 void
218 {
219  NS_LOG_FUNCTION (this);
220  if (!m_connectionSucceeded.IsNull ())
221  {
222  m_connectionSucceeded (this);
223  }
224 }
225 
226 void
228 {
229  NS_LOG_FUNCTION (this);
230  if (!m_connectionFailed.IsNull ())
231  {
232  m_connectionFailed (this);
233  }
234 }
235 
236 void
238 {
239  NS_LOG_FUNCTION (this);
240  if (!m_normalClose.IsNull ())
241  {
242  m_normalClose (this);
243  }
244 }
245 
246 void
248 {
249  NS_LOG_FUNCTION (this);
250  if (!m_errorClose.IsNull ())
251  {
252  m_errorClose (this);
253  }
254 }
255 
256 bool
258 {
259  NS_LOG_FUNCTION (this << &from);
260  if (!m_connectionRequest.IsNull ())
261  {
262  return m_connectionRequest (this, from);
263  }
264  else
265  {
266  // accept all incoming connections by default.
267  // this way people writing code don't have to do anything
268  // special like register a callback that returns true
269  // just to get incoming connections
270  return true;
271  }
272 }
273 
274 void
276 {
277  NS_LOG_FUNCTION (this << socket << from);
278  if (!m_newConnectionCreated.IsNull ())
279  {
280  m_newConnectionCreated (socket, from);
281  }
282 }
283 
284 void
285 Socket::NotifyDataSent (uint32_t size)
286 {
287  NS_LOG_FUNCTION (this << size);
288  if (!m_dataSent.IsNull ())
289  {
290  m_dataSent (this, size);
291  }
292 }
293 
294 void
295 Socket::NotifySend (uint32_t spaceAvailable)
296 {
297  NS_LOG_FUNCTION (this << spaceAvailable);
298  if (!m_sendCb.IsNull ())
299  {
300  m_sendCb (this, spaceAvailable);
301  }
302 }
303 
304 void
306 {
307  NS_LOG_FUNCTION (this);
308  if (!m_receivedData.IsNull ())
309  {
310  m_receivedData (this);
311  }
312 }
313 
314 void
316 {
317  NS_LOG_FUNCTION (this);
318  m_connectionSucceeded = MakeNullCallback<void,Ptr<Socket> > ();
319  m_connectionFailed = MakeNullCallback<void,Ptr<Socket> > ();
320  m_normalClose = MakeNullCallback<void,Ptr<Socket> > ();
321  m_errorClose = MakeNullCallback<void,Ptr<Socket> > ();
322  m_connectionRequest = MakeNullCallback<bool,Ptr<Socket>, const Address &> ();
323  m_newConnectionCreated = MakeNullCallback<void,Ptr<Socket>, const Address &> ();
324  m_dataSent = MakeNullCallback<void,Ptr<Socket>, uint32_t> ();
325  m_sendCb = MakeNullCallback<void,Ptr<Socket>, uint32_t> ();
326  m_receivedData = MakeNullCallback<void,Ptr<Socket> > ();
327 }
328 
329 void
331 {
332  NS_LOG_FUNCTION (this << netdevice);
333  if (netdevice != 0)
334  {
335  bool found = false;
336  for (uint32_t i = 0; i < GetNode ()->GetNDevices (); i++)
337  {
338  if (GetNode ()->GetDevice (i) == netdevice)
339  {
340  found = true;
341  break;
342  }
343  }
344  NS_ASSERT_MSG (found, "Socket cannot be bound to a NetDevice not existing on the Node");
345  }
346  m_boundnetdevice = netdevice;
347  return;
348 }
349 
352 {
353  NS_LOG_FUNCTION (this);
354  return m_boundnetdevice;
355 }
356 
357 void
359 {
360  NS_LOG_FUNCTION (this << flag);
361  m_recvPktInfo = flag;
362 }
363 
365 {
366  NS_LOG_FUNCTION (this);
367  return m_recvPktInfo;
368 }
369 
370 bool
372 {
373  return m_manualIpTos;
374 }
375 
376 bool
378 {
379  return m_manualIpv6Tclass;
380 }
381 
382 bool
384 {
385  return m_manualIpTtl;
386 }
387 
388 bool
390 {
391  return m_manualIpv6HopLimit;
392 }
393 
394 void
395 Socket::SetIpTos (uint8_t tos)
396 {
398  GetSockName (address);
399  m_manualIpTos = true;
400  m_ipTos = tos;
401 }
402 
403 uint8_t
404 Socket::GetIpTos (void) const
405 {
406  return m_ipTos;
407 }
408 
409 void
410 Socket::SetIpRecvTos (bool ipv4RecvTos)
411 {
412  m_ipRecvTos = ipv4RecvTos;
413 }
414 
415 bool
417 {
418  return m_ipRecvTos;
419 }
420 
421 void
423 {
425  GetSockName (address);
426 
427  //If -1 or invalid values, use default
428  if (tclass == -1 || tclass < -1 || tclass > 0xff)
429  {
430  //Print a warning
431  if (tclass < -1 || tclass > 0xff)
432  {
433  NS_LOG_WARN ("Invalid IPV6_TCLASS value. Using default.");
434  }
435  m_manualIpv6Tclass = false;
436  m_ipv6Tclass = 0;
437  }
438  else
439  {
440  m_manualIpv6Tclass = true;
441  m_ipv6Tclass = tclass;
442  }
443 }
444 
445 uint8_t
447 {
448  return m_ipv6Tclass;
449 }
450 
451 void
452 Socket::SetIpv6RecvTclass (bool ipv6RecvTclass)
453 {
454  m_ipv6RecvTclass = ipv6RecvTclass;
455 }
456 
457 bool
459 {
460  return m_ipv6RecvTclass;
461 }
462 
463 void
464 Socket::SetIpTtl (uint8_t ttl)
465 {
466  m_manualIpTtl = true;
467  m_ipTtl = ttl;
468 }
469 
470 uint8_t
471 Socket::GetIpTtl (void) const
472 {
473  return m_ipTtl;
474 }
475 
476 void
477 Socket::SetIpRecvTtl (bool ipv4RecvTtl)
478 {
479  m_ipRecvTtl = ipv4RecvTtl;
480 }
481 
482 bool
484 {
485  return m_ipRecvTtl;
486 }
487 
488 void
489 Socket::SetIpv6HopLimit (uint8_t ipHopLimit)
490 {
491  m_manualIpv6HopLimit = true;
492  m_ipv6HopLimit = ipHopLimit;
493 }
494 
495 uint8_t
497 {
498  return m_ipv6HopLimit;
499 }
500 
501 void
502 Socket::SetIpv6RecvHopLimit (bool ipv6RecvHopLimit)
503 {
504  m_ipv6RecvHopLimit = ipv6RecvHopLimit;
505 }
506 
507 bool
509 {
510  return m_ipv6RecvHopLimit;
511 }
512 
513 /***************************************************************
514  * Socket Tags
515  ***************************************************************/
516 
518 {
519  NS_LOG_FUNCTION (this);
520 }
521 
522 void
524 {
525  NS_LOG_FUNCTION (this << addr);
526  m_address = addr;
527 }
528 
529 Address
531 {
532  NS_LOG_FUNCTION (this);
533  return m_address;
534 }
535 
537  ;
538 
539 TypeId
541 {
542  static TypeId tid = TypeId ("ns3::SocketAddressTag")
543  .SetParent<Tag> ()
544  .AddConstructor<SocketAddressTag> ()
545  ;
546  return tid;
547 }
548 TypeId
550 {
551  return GetTypeId ();
552 }
553 uint32_t
555 {
556  NS_LOG_FUNCTION (this);
557  return m_address.GetSerializedSize ();
558 }
559 void
561 {
562  NS_LOG_FUNCTION (this << &i);
563  m_address.Serialize (i);
564 }
565 void
567 {
568  NS_LOG_FUNCTION (this << &i);
570 }
571 void
572 SocketAddressTag::Print (std::ostream &os) const
573 {
574  NS_LOG_FUNCTION (this << &os);
575  os << "address=" << m_address;
576 }
577 
579 {
580  NS_LOG_FUNCTION (this);
581 }
582 
583 void
585 {
586  NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
587  m_ttl = ttl;
588 }
589 
590 uint8_t
592 {
593  NS_LOG_FUNCTION (this);
594  return m_ttl;
595 }
596 
598  ;
599 
600 TypeId
602 {
603  static TypeId tid = TypeId ("ns3::SocketIpTtlTag")
604  .SetParent<Tag> ()
605  .AddConstructor<SocketIpTtlTag> ()
606  ;
607  return tid;
608 }
609 TypeId
611 {
612  return GetTypeId ();
613 }
614 
615 uint32_t
617 {
618  NS_LOG_FUNCTION (this);
619  return 1;
620 }
621 void
623 {
624  NS_LOG_FUNCTION (this << &i);
625  i.WriteU8 (m_ttl);
626 }
627 void
629 {
630  NS_LOG_FUNCTION (this << &i);
631  m_ttl = i.ReadU8 ();
632 }
633 void
634 SocketIpTtlTag::Print (std::ostream &os) const
635 {
636  NS_LOG_FUNCTION (this << &os);
637  os << "Ttl=" << (uint32_t) m_ttl;
638 }
639 
641 {
642 }
643 
644 void
646 {
647  m_hopLimit = hopLimit;
648 }
649 
650 uint8_t
652 {
653  return m_hopLimit;
654 }
655 
657  ;
658 
659 TypeId
661 {
662  static TypeId tid = TypeId ("ns3::SocketIpv6HopLimitTag")
663  .SetParent<Tag> ()
664  .AddConstructor<SocketIpv6HopLimitTag> ()
665  ;
666  return tid;
667 }
668 TypeId
670 {
671  return GetTypeId ();
672 }
673 
674 uint32_t
676 {
677  return 1;
678 }
679 void
681 {
682  i.WriteU8 (m_hopLimit);
683 }
684 void
686 {
687  m_hopLimit = i.ReadU8 ();
688 }
689 void
690 SocketIpv6HopLimitTag::Print (std::ostream &os) const
691 {
692  os << "HopLimit=" << (uint32_t) m_hopLimit;
693 }
694 
696 {
697  NS_LOG_FUNCTION (this);
698 }
699 void
701 {
702  NS_LOG_FUNCTION (this);
703  m_dontFragment = true;
704 }
705 void
707 {
708  NS_LOG_FUNCTION (this);
709  m_dontFragment = false;
710 }
711 bool
713 {
714  NS_LOG_FUNCTION (this);
715  return m_dontFragment;
716 }
717 
719  ;
720 
721 TypeId
723 {
724  static TypeId tid = TypeId ("ns3::SocketSetDontFragmentTag")
725  .SetParent<Tag> ()
726  .AddConstructor<SocketSetDontFragmentTag> ();
727  return tid;
728 }
729 TypeId
731 {
732  return GetTypeId ();
733 }
734 uint32_t
736 {
737  NS_LOG_FUNCTION (this);
738  return 1;
739 }
740 void
742 {
743  NS_LOG_FUNCTION (this << &i);
744  i.WriteU8 (m_dontFragment ? 1 : 0);
745 }
746 void
748 {
749  NS_LOG_FUNCTION (this << &i);
750  m_dontFragment = (i.ReadU8 () == 1) ? true : false;
751 }
752 void
753 SocketSetDontFragmentTag::Print (std::ostream &os) const
754 {
755  NS_LOG_FUNCTION (this << &os);
756  os << (m_dontFragment ? "true" : "false");
757 }
758 
759 
761 {
762 }
763 
764 void
765 SocketIpTosTag::SetTos (uint8_t ipTos)
766 {
767  m_ipTos = ipTos;
768 }
769 
770 uint8_t
772 {
773  return m_ipTos;
774 }
775 
776 TypeId
778 {
779  static TypeId tid = TypeId ("ns3::SocketIpTosTag")
780  .SetParent<Tag> ()
781  .AddConstructor<SocketIpTosTag> ()
782  ;
783  return tid;
784 }
785 
786 TypeId
788 {
789  return GetTypeId ();
790 }
791 
792 uint32_t
794 {
795  return sizeof (uint8_t);
796 }
797 
798 void
800 {
801  i.WriteU8 (m_ipTos);
802 }
803 
804 void
806 {
807  m_ipTos = i.ReadU8();
808 }
809 void
810 SocketIpTosTag::Print (std::ostream &os) const
811 {
812  os << "IP_TOS = " << m_ipTos;
813 }
814 
815 
817 {
818 }
819 
820 void
822 {
823  m_ipv6Tclass = tclass;
824 }
825 
826 uint8_t
828 {
829  return m_ipv6Tclass;
830 }
831 
832 TypeId
834 {
835  static TypeId tid = TypeId ("ns3::SocketIpv6TclassTag")
836  .SetParent<Tag> ()
837  .AddConstructor<SocketIpv6TclassTag> ()
838  ;
839  return tid;
840 }
841 
842 TypeId
844 {
845  return GetTypeId ();
846 }
847 
848 uint32_t
850 {
851  return sizeof (uint8_t);
852 }
853 
854 void
856 {
857  i.WriteU8 (m_ipv6Tclass);
858 }
859 
860 void
862 {
863  m_ipv6Tclass = i.ReadU8();
864 }
865 void
866 SocketIpv6TclassTag::Print (std::ostream &os) const
867 {
868  os << "IPV6_TCLASS = " << m_ipv6Tclass;
869 }
870 
871 } // namespace ns3
uint8_t m_ipv6HopLimit
the socket IPv6 Hop Limit
Definition: socket.h:941
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:601
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:821
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:855
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:383
virtual void Print(std::ostream &os) const
Definition: socket.cc:866
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
virtual void Print(std::ostream &os) const
Definition: socket.cc:634
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Definition: socket.cc:508
bool m_manualIpv6HopLimit
socket has IPv6 Hop Limit set
Definition: socket.h:936
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:566
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:471
Callback template class.
Definition: callback.h:920
void SetIpv6RecvTclass(bool ipv6RecvTclass)
Tells a socket to pass information about IPv6 Traffic Class up the stack.
Definition: socket.cc:452
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:404
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Definition: socket.h:1044
uint8_t m_hopLimit
the Hop Limit carried by the tag
Definition: socket.h:1085
NS_LOG_COMPONENT_DEFINE("Socket")
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:305
uint8_t GetTos(void) const
Get the tag's TOS.
Definition: socket.cc:771
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:735
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
bool m_dontFragment
DF bit value for outgoing packets.
Definition: socket.h:1135
Socket(void)
Definition: socket.cc:45
void SetAddress(Address addr)
Set the tag's address.
Definition: socket.cc:523
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:560
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error...
Definition: socket.cc:227
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:722
Callback< bool, Ptr< Socket >, const Address & > m_connectionRequest
connection request callback
Definition: socket.h:919
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:861
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual int GetSockName(Address &address) const =0
Get socket address.
void SetIpRecvTos(bool ipv4RecvTos)
Tells a socket to pass information about IP Type of Service up the stack.
Definition: socket.cc:410
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:549
uint32_t GetSize(void) const
Definition: packet.h:650
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:833
bool IsManualIpTos(void) const
Checks if the socket has a specific IPv4 ToS set.
Definition: socket.cc:371
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:787
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:94
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:496
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
Callback< void, Ptr< Socket > > m_connectionSucceeded
connection succeeded callback
Definition: socket.h:915
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:765
bool m_recvPktInfo
if the socket should add packet info tags to the packet forwarded to L4.
Definition: socket.h:912
bool IsEnabled(void) const
Checks if the DF (Don't Fragment) flag is set.
Definition: socket.cc:712
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:741
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
Definition: socket.h:996
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:257
bool m_ipRecvTos
socket forwards IPv4 TOS tag to L4
Definition: socket.h:928
Object to create transport layer instances that provide a socket API to applications.
virtual void Print(std::ostream &os) const
Definition: socket.cc:572
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition: socket.cc:364
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition: tag-buffer.h:179
uint8_t m_ipv6Tclass
the socket IPv6 Tclass
Definition: socket.h:940
a polymophic address class
Definition: address.h:86
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack...
Definition: socket.cc:416
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:358
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound netdevice, if any.
Definition: socket.cc:351
uint8_t GetTclass(void) const
Get the tag's Tclass.
Definition: socket.cc:827
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:584
uint8_t m_ipTos
the socket IPv4 TOS
Definition: socket.h:931
Ptr< SampleEmitter > s
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:540
Callback< void, Ptr< Socket > > m_receivedData
data received callback
Definition: socket.h:923
Callback< void, Ptr< Socket >, const Address & > m_newConnectionCreated
connection created callback
Definition: socket.h:920
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:777
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:132
This class implements a tag that carries an address of a packet across the socket interface...
Definition: socket.h:948
Callback< void, Ptr< Socket > > m_connectionFailed
connection failed callback
Definition: socket.h:916
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Definition: socket.cc:377
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:285
virtual ~Socket(void)
Definition: socket.cc:65
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
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:71
virtual void Print(std::ostream &os) const
Definition: socket.cc:753
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:645
uint8_t m_ipTos
the TOS carried by the tag
Definition: socket.h:1182
void Deserialize(TagBuffer buffer)
Definition: address.cc:163
bool m_manualIpTos
socket has IPv4 TOS set
Definition: socket.h:926
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
Definition: socket.cc:217
uint32_t GetSerializedSize(void) const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
Definition: address.cc:147
Callback< void, Ptr< Socket > > m_errorClose
connection closed due to errors callback
Definition: socket.h:918
uint32_t GetNDevices(void) const
Definition: node.cc:140
Callback< void, Ptr< Socket >, uint32_t > m_dataSent
data sent callback
Definition: socket.h:921
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:389
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:616
void NotifyNormalClose(void)
Notify through the callback (if set) that the connection has been closed.
Definition: socket.cc:237
tag a set of bytes in a packet
Definition: tag.h:36
uint8_t m_ipTtl
the socket IPv4 TTL
Definition: socket.h:932
void SetIpv6Tclass(int ipTclass)
Manually set IPv6 Traffic Class field.
Definition: socket.cc:422
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:680
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Notify through the callback (if set) that a new connection has been created.
Definition: socket.cc:275
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:675
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:446
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:38
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:843
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:747
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:156
Address m_address
the address carried by the tag
Definition: socket.h:989
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack...
Definition: socket.cc:458
uint8_t m_ttl
the ttl carried by the tag
Definition: socket.h:1037
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
Definition: socket.cc:121
bool m_ipRecvTtl
socket forwards IPv4 TTL tag to L4
Definition: socket.h:929
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:104
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
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
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: socket.cc:315
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
Definition: socket.cc:483
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:660
uint8_t GetHopLimit(void) const
Get the tag's Hop Limit.
Definition: socket.cc:651
void Disable(void)
Disables the DF (Don't Fragment) flag.
Definition: socket.cc:706
read and write tag data
Definition: tag-buffer.h:51
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition: socket.h:911
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
Definition: address.cc:154
void SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
Tells a socket to pass information about IPv6 Hop Limit up the stack.
Definition: socket.cc:502
Callback< void, Ptr< Socket > > m_normalClose
connection closed callback
Definition: socket.h:917
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:849
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:610
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:799
#define NS_LOG_WARN(msg)
Definition: log.h:280
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
Address GetAddress(void) const
Get the tag's address.
Definition: socket.cc:530
virtual void Print(std::ostream &os) const
Definition: socket.cc:810
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:685
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
Definition: socket.h:1092
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:622
void SetIpRecvTtl(bool ipv4RecvTtl)
Tells a socket to pass information about IP_TTL up the stack.
Definition: socket.cc:477
void Enable(void)
Enables the DF (Don't Fragment) flag.
Definition: socket.cc:700
uint8_t m_ipv6Tclass
the Tclass carried by the tag
Definition: socket.h:1229
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:628
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:381
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:805
virtual void Print(std::ostream &os) const
Definition: socket.cc:690
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:84
a base class which provides memory management and object aggregation
Definition: object.h:63
tuple address
Definition: first.py:37
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 GetTtl(void) const
Get the tag's TTL.
Definition: socket.cc:591
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:554
Callback< void, Ptr< Socket >, uint32_t > m_sendCb
packet sent callback
Definition: socket.h:922
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:730
virtual void SetIpv6HopLimit(uint8_t ipHopLimit)
Manually set IPv6 Hop Limit.
Definition: socket.cc:489
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:793
Ptr< T > GetObject(void) const
Definition: object.h:361
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition: socket.cc:395
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:669
a unique identifier for an interface.
Definition: type-id.h:49
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)
Definition: type-id.cc:611
bool m_manualIpTtl
socket has IPv4 TTL set
Definition: socket.h:927
void NotifyErrorClose(void)
Notify through the callback (if set) that the connection has been closed due to an error...
Definition: socket.cc:247
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
Definition: socket.cc:464
bool m_ipv6RecvHopLimit
socket forwards IPv6 Hop Limit tag to L4
Definition: socket.h:938
bool m_manualIpv6Tclass
socket has IPv6 Tclass set
Definition: socket.h:935
bool m_ipv6RecvTclass
socket forwards IPv6 Tclass tag to L4
Definition: socket.h:937