A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
socket.cc
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 
34 NS_OBJECT_ENSURE_REGISTERED (Socket);
35 
36 TypeId
37 Socket::GetTypeId (void)
38 {
39  static TypeId tid = TypeId ("ns3::Socket")
40  .SetParent<Object> ();
41  return tid;
42 }
43 
44 Socket::Socket (void)
45  : m_manualIpTos (false),
46  m_manualIpTtl (false),
47  m_ipRecvTos (false),
48  m_ipRecvTtl (false),
49  m_manualIpv6Tclass (false),
50  m_manualIpv6HopLimit (false),
51  m_ipv6RecvTclass (false),
52  m_ipv6RecvHopLimit (false)
53 {
55  m_boundnetdevice = 0;
56  m_recvPktInfo = false;
57 
58  m_ipTos = 0;
59  m_ipTtl = 0;
60  m_ipv6Tclass = 0;
61  m_ipv6HopLimit = 0;
62 }
63 
64 Socket::~Socket ()
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
69 Ptr<Socket>
71 {
72  NS_LOG_FUNCTION (node << tid);
73  Ptr<Socket> s;
74  NS_ASSERT (node != 0);
75  Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
76  NS_ASSERT (socketFactory != 0);
77  s = socketFactory->CreateSocket ();
78  NS_ASSERT (s != 0);
79  return s;
80 }
81 
82 void
84  Callback<void, Ptr<Socket> > connectionSucceeded,
85  Callback<void, Ptr<Socket> > connectionFailed)
86 {
87  NS_LOG_FUNCTION (this << &connectionSucceeded << &connectionFailed);
88  m_connectionSucceeded = connectionSucceeded;
89  m_connectionFailed = connectionFailed;
90 }
91 
92 void
94  Callback<void, Ptr<Socket> > normalClose,
95  Callback<void, Ptr<Socket> > errorClose)
96 {
97  NS_LOG_FUNCTION (this << &normalClose << &errorClose);
98  m_normalClose = normalClose;
99  m_errorClose = errorClose;
100 }
101 
102 void
104  Callback<bool, Ptr<Socket>, const Address &> connectionRequest,
105  Callback<void, Ptr<Socket>, const Address&> newConnectionCreated)
106 {
107  NS_LOG_FUNCTION (this << &connectionRequest << &newConnectionCreated);
108  m_connectionRequest = connectionRequest;
109  m_newConnectionCreated = newConnectionCreated;
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION (this << &dataSent);
116  m_dataSent = dataSent;
117 }
118 
119 void
121 {
122  NS_LOG_FUNCTION (this << &sendCb);
123  m_sendCb = sendCb;
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << &receivedData);
130  m_receivedData = receivedData;
131 }
132 
133 int
135 {
136  NS_LOG_FUNCTION (this << p);
137  return Send (p, 0);
138 }
139 
140 int
141 Socket::Send (const uint8_t* buf, uint32_t size, uint32_t flags)
142 {
143  NS_LOG_FUNCTION (this << &buf << size << flags);
144  Ptr<Packet> p;
145  if (buf)
146  {
147  p = Create<Packet> (buf, size);
148  }
149  else
150  {
151  p = Create<Packet> (size);
152  }
153  return Send (p, flags);
154 }
155 
156 int
157 Socket::SendTo (const uint8_t* buf, uint32_t size, uint32_t flags,
158  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);
177  return Recv (std::numeric_limits<uint32_t>::max (), 0);
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 == 0)
186  {
187  return 0;
188  }
189  p->CopyData (buf, p->GetSize ());
190  return p->GetSize ();
191 }
192 
194 Socket::RecvFrom (Address &fromAddress)
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,
202  Address &fromAddress)
203 {
204  NS_LOG_FUNCTION (this << &buf << size << flags << &fromAddress);
205  Ptr<Packet> p = RecvFrom (size, flags, fromAddress);
206  if (p == 0)
207  {
208  return 0;
209  }
210  p->CopyData (buf, p->GetSize ());
211  return p->GetSize ();
212 }
213 
214 
215 void
216 Socket::NotifyConnectionSucceeded (void)
217 {
218  NS_LOG_FUNCTION (this);
219  if (!m_connectionSucceeded.IsNull ())
220  {
221  m_connectionSucceeded (this);
222  }
223 }
224 
225 void
226 Socket::NotifyConnectionFailed (void)
227 {
228  NS_LOG_FUNCTION (this);
229  if (!m_connectionFailed.IsNull ())
230  {
231  m_connectionFailed (this);
232  }
233 }
234 
235 void
236 Socket::NotifyNormalClose (void)
237 {
238  NS_LOG_FUNCTION (this);
239  if (!m_normalClose.IsNull ())
240  {
241  m_normalClose (this);
242  }
243 }
244 
245 void
246 Socket::NotifyErrorClose (void)
247 {
248  NS_LOG_FUNCTION (this);
249  if (!m_errorClose.IsNull ())
250  {
251  m_errorClose (this);
252  }
253 }
254 
255 bool
256 Socket::NotifyConnectionRequest (const Address &from)
257 {
258  NS_LOG_FUNCTION (this << &from);
259  if (!m_connectionRequest.IsNull ())
260  {
261  return m_connectionRequest (this, from);
262  }
263  else
264  {
265  // accept all incoming connections by default.
266  // this way people writing code don't have to do anything
267  // special like register a callback that returns true
268  // just to get incoming connections
269  return true;
270  }
271 }
272 
273 void
274 Socket::NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from)
275 {
276  NS_LOG_FUNCTION (this << socket << from);
277  if (!m_newConnectionCreated.IsNull ())
278  {
279  m_newConnectionCreated (socket, from);
280  }
281 }
282 
283 void
284 Socket::NotifyDataSent (uint32_t size)
285 {
286  NS_LOG_FUNCTION (this << size);
287  if (!m_dataSent.IsNull ())
288  {
289  m_dataSent (this, size);
290  }
291 }
292 
293 void
294 Socket::NotifySend (uint32_t spaceAvailable)
295 {
296  NS_LOG_FUNCTION (this << spaceAvailable);
297  if (!m_sendCb.IsNull ())
298  {
299  m_sendCb (this, spaceAvailable);
300  }
301 }
302 
303 void
304 Socket::NotifyDataRecv (void)
305 {
306  NS_LOG_FUNCTION (this);
307  if (!m_receivedData.IsNull ())
308  {
309  m_receivedData (this);
310  }
311 }
312 
313 void
315 {
316  NS_LOG_FUNCTION (this);
317  m_connectionSucceeded = MakeNullCallback<void,Ptr<Socket> > ();
318  m_connectionFailed = MakeNullCallback<void,Ptr<Socket> > ();
319  m_normalClose = MakeNullCallback<void,Ptr<Socket> > ();
320  m_errorClose = MakeNullCallback<void,Ptr<Socket> > ();
321  m_connectionRequest = MakeNullCallback<bool,Ptr<Socket>, const Address &> ();
322  m_newConnectionCreated = MakeNullCallback<void,Ptr<Socket>, const Address &> ();
323  m_dataSent = MakeNullCallback<void,Ptr<Socket>, uint32_t> ();
324  m_sendCb = MakeNullCallback<void,Ptr<Socket>, uint32_t> ();
325  m_receivedData = MakeNullCallback<void,Ptr<Socket> > ();
326 }
327 
328 void
330 {
331  NS_LOG_FUNCTION (this << netdevice);
332  if (netdevice != 0)
333  {
334  bool found = false;
335  for (uint32_t i = 0; i < GetNode ()->GetNDevices (); i++)
336  {
337  if (GetNode ()->GetDevice (i) == netdevice)
338  {
339  found = true;
340  break;
341  }
342  }
343  NS_ASSERT_MSG (found, "Socket cannot be bound to a NetDevice not existing on the Node");
344  }
345  m_boundnetdevice = netdevice;
346  return;
347 }
348 
351 {
352  NS_LOG_FUNCTION (this);
353  return m_boundnetdevice;
354 }
355 
356 void
358 {
359  NS_LOG_FUNCTION (this << flag);
360  m_recvPktInfo = flag;
361 }
362 
364 {
365  NS_LOG_FUNCTION (this);
366  return m_recvPktInfo;
367 }
368 
369 bool
370 Socket::IsManualIpTos (void) const
371 {
372  return m_manualIpTos;
373 }
374 
375 bool
376 Socket::IsManualIpv6Tclass (void) const
377 {
378  return m_manualIpv6Tclass;
379 }
380 
381 bool
382 Socket::IsManualIpTtl (void) const
383 {
384  return m_manualIpTtl;
385 }
386 
387 bool
388 Socket::IsManualIpv6HopLimit (void) const
389 {
390  return m_manualIpv6HopLimit;
391 }
392 
393 void
394 Socket::SetIpTos (uint8_t tos)
395 {
396  Address address;
397  GetSockName (address);
398  m_manualIpTos = true;
399  m_ipTos = tos;
400 }
401 
402 uint8_t
403 Socket::GetIpTos (void) const
404 {
405  return m_ipTos;
406 }
407 
408 void
409 Socket::SetIpRecvTos (bool ipv4RecvTos)
410 {
411  m_ipRecvTos = ipv4RecvTos;
412 }
413 
414 bool
416 {
417  return m_ipRecvTos;
418 }
419 
420 void
421 Socket::SetIpv6Tclass (int tclass)
422 {
423  Address address;
424  GetSockName (address);
425 
426  //If -1 or invalid values, use default
427  if (tclass == -1 || tclass < -1 || tclass > 0xff)
428  {
429  //Print a warning
430  if (tclass < -1 || tclass > 0xff)
431  {
432  NS_LOG_WARN ("Invalid IPV6_TCLASS value. Using default.");
433  }
434  m_manualIpv6Tclass = false;
435  m_ipv6Tclass = 0;
436  }
437  else
438  {
439  m_manualIpv6Tclass = true;
440  m_ipv6Tclass = tclass;
441  }
442 }
443 
444 uint8_t
445 Socket::GetIpv6Tclass (void) const
446 {
447  return m_ipv6Tclass;
448 }
449 
450 void
451 Socket::SetIpv6RecvTclass (bool ipv6RecvTclass)
452 {
453  m_ipv6RecvTclass = ipv6RecvTclass;
454 }
455 
456 bool
458 {
459  return m_ipv6RecvTclass;
460 }
461 
462 void
463 Socket::SetIpTtl (uint8_t ttl)
464 {
465  m_manualIpTtl = true;
466  m_ipTtl = ttl;
467 }
468 
469 uint8_t
470 Socket::GetIpTtl (void) const
471 {
472  return m_ipTtl;
473 }
474 
475 void
476 Socket::SetIpRecvTtl (bool ipv4RecvTtl)
477 {
478  m_ipRecvTtl = ipv4RecvTtl;
479 }
480 
481 bool
483 {
484  return m_ipRecvTtl;
485 }
486 
487 void
488 Socket::SetIpv6HopLimit (uint8_t ipHopLimit)
489 {
490  m_manualIpv6HopLimit = true;
491  m_ipv6HopLimit = ipHopLimit;
492 }
493 
494 uint8_t
495 Socket::GetIpv6HopLimit (void) const
496 {
497  return m_ipv6HopLimit;
498 }
499 
500 void
501 Socket::SetIpv6RecvHopLimit (bool ipv6RecvHopLimit)
502 {
503  m_ipv6RecvHopLimit = ipv6RecvHopLimit;
504 }
505 
506 bool
508 {
509  return m_ipv6RecvHopLimit;
510 }
511 
512 /***************************************************************
513  * Socket Tags
514  ***************************************************************/
515 
516 SocketAddressTag::SocketAddressTag ()
517 {
518  NS_LOG_FUNCTION (this);
519 }
520 
521 void
522 SocketAddressTag::SetAddress (Address addr)
523 {
524  NS_LOG_FUNCTION (this << addr);
525  m_address = addr;
526 }
527 
528 Address
529 SocketAddressTag::GetAddress (void) const
530 {
531  NS_LOG_FUNCTION (this);
532  return m_address;
533 }
534 
535 NS_OBJECT_ENSURE_REGISTERED (SocketAddressTag);
536 
537 TypeId
538 SocketAddressTag::GetTypeId (void)
539 {
540  static TypeId tid = TypeId ("ns3::SocketAddressTag")
541  .SetParent<Tag> ()
542  .AddConstructor<SocketAddressTag> ()
543  ;
544  return tid;
545 }
546 TypeId
548 {
549  return GetTypeId ();
550 }
551 uint32_t
553 {
554  NS_LOG_FUNCTION (this);
555  return m_address.GetSerializedSize ();
556 }
557 void
559 {
560  NS_LOG_FUNCTION (this << &i);
561  m_address.Serialize (i);
562 }
563 void
565 {
566  NS_LOG_FUNCTION (this << &i);
567  m_address.Deserialize (i);
568 }
569 void
570 SocketAddressTag::Print (std::ostream &os) const
571 {
572  NS_LOG_FUNCTION (this << &os);
573  os << "address=" << m_address;
574 }
575 
576 SocketIpTtlTag::SocketIpTtlTag ()
577 {
578  NS_LOG_FUNCTION (this);
579 }
580 
581 void
582 SocketIpTtlTag::SetTtl (uint8_t ttl)
583 {
584  NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
585  m_ttl = ttl;
586 }
587 
588 uint8_t
589 SocketIpTtlTag::GetTtl (void) const
590 {
591  NS_LOG_FUNCTION (this);
592  return m_ttl;
593 }
594 
595 NS_OBJECT_ENSURE_REGISTERED (SocketIpTtlTag);
596 
597 TypeId
598 SocketIpTtlTag::GetTypeId (void)
599 {
600  static TypeId tid = TypeId ("ns3::SocketIpTtlTag")
601  .SetParent<Tag> ()
602  .AddConstructor<SocketIpTtlTag> ()
603  ;
604  return tid;
605 }
606 TypeId
608 {
609  return GetTypeId ();
610 }
611 
612 uint32_t
614 {
615  NS_LOG_FUNCTION (this);
616  return 1;
617 }
618 void
620 {
621  NS_LOG_FUNCTION (this << &i);
622  i.WriteU8 (m_ttl);
623 }
624 void
626 {
627  NS_LOG_FUNCTION (this << &i);
628  m_ttl = i.ReadU8 ();
629 }
630 void
631 SocketIpTtlTag::Print (std::ostream &os) const
632 {
633  NS_LOG_FUNCTION (this << &os);
634  os << "Ttl=" << (uint32_t) m_ttl;
635 }
636 
637 SocketIpv6HopLimitTag::SocketIpv6HopLimitTag ()
638 {
639 }
640 
641 void
642 SocketIpv6HopLimitTag::SetHopLimit (uint8_t hopLimit)
643 {
644  m_hopLimit = hopLimit;
645 }
646 
647 uint8_t
648 SocketIpv6HopLimitTag::GetHopLimit (void) const
649 {
650  return m_hopLimit;
651 }
652 
653 NS_OBJECT_ENSURE_REGISTERED (SocketIpv6HopLimitTag);
654 
655 TypeId
656 SocketIpv6HopLimitTag::GetTypeId (void)
657 {
658  static TypeId tid = TypeId ("ns3::SocketIpv6HopLimitTag")
659  .SetParent<Tag> ()
660  .AddConstructor<SocketIpv6HopLimitTag> ()
661  ;
662  return tid;
663 }
664 TypeId
666 {
667  return GetTypeId ();
668 }
669 
670 uint32_t
672 {
673  return 1;
674 }
675 void
677 {
678  i.WriteU8 (m_hopLimit);
679 }
680 void
682 {
683  m_hopLimit = i.ReadU8 ();
684 }
685 void
686 SocketIpv6HopLimitTag::Print (std::ostream &os) const
687 {
688  os << "HopLimit=" << (uint32_t) m_hopLimit;
689 }
690 
691 SocketSetDontFragmentTag::SocketSetDontFragmentTag ()
692 {
693  NS_LOG_FUNCTION (this);
694 }
695 void
696 SocketSetDontFragmentTag::Enable (void)
697 {
698  NS_LOG_FUNCTION (this);
699  m_dontFragment = true;
700 }
701 void
702 SocketSetDontFragmentTag::Disable (void)
703 {
704  NS_LOG_FUNCTION (this);
705  m_dontFragment = false;
706 }
707 bool
708 SocketSetDontFragmentTag::IsEnabled (void) const
709 {
710  NS_LOG_FUNCTION (this);
711  return m_dontFragment;
712 }
713 
714 NS_OBJECT_ENSURE_REGISTERED (SocketSetDontFragmentTag);
715 
716 TypeId
717 SocketSetDontFragmentTag::GetTypeId (void)
718 {
719  static TypeId tid = TypeId ("ns3::SocketSetDontFragmentTag")
720  .SetParent<Tag> ()
721  .AddConstructor<SocketSetDontFragmentTag> ();
722  return tid;
723 }
724 TypeId
726 {
727  return GetTypeId ();
728 }
729 uint32_t
731 {
732  NS_LOG_FUNCTION (this);
733  return 1;
734 }
735 void
737 {
738  NS_LOG_FUNCTION (this << &i);
739  i.WriteU8 (m_dontFragment ? 1 : 0);
740 }
741 void
743 {
744  NS_LOG_FUNCTION (this << &i);
745  m_dontFragment = (i.ReadU8 () == 1) ? true : false;
746 }
747 void
748 SocketSetDontFragmentTag::Print (std::ostream &os) const
749 {
750  NS_LOG_FUNCTION (this << &os);
751  os << (m_dontFragment ? "true" : "false");
752 }
753 
754 
755 SocketIpTosTag::SocketIpTosTag ()
756 {
757 }
758 
759 void
760 SocketIpTosTag::SetTos (uint8_t ipTos)
761 {
762  m_ipTos = ipTos;
763 }
764 
765 uint8_t
766 SocketIpTosTag::GetTos (void) const
767 {
768  return m_ipTos;
769 }
770 
771 TypeId
772 SocketIpTosTag::GetTypeId (void)
773 {
774  static TypeId tid = TypeId ("ns3::SocketIpTosTag")
775  .SetParent<Tag> ()
776  .AddConstructor<SocketIpTosTag> ()
777  ;
778  return tid;
779 }
780 
781 TypeId
783 {
784  return GetTypeId ();
785 }
786 
787 uint32_t
789 {
790  return sizeof (uint8_t);
791 }
792 
793 void
795 {
796  i.WriteU8 (m_ipTos);
797 }
798 
799 void
801 {
802  m_ipTos = i.ReadU8();
803 }
804 void
805 SocketIpTosTag::Print (std::ostream &os) const
806 {
807  os << "IP_TOS = " << m_ipTos;
808 }
809 
810 
811 SocketIpv6TclassTag::SocketIpv6TclassTag ()
812 {
813 }
814 
815 void
816 SocketIpv6TclassTag::SetTclass (uint8_t tclass)
817 {
818  m_ipv6Tclass = tclass;
819 }
820 
821 uint8_t
822 SocketIpv6TclassTag::GetTclass (void) const
823 {
824  return m_ipv6Tclass;
825 }
826 
827 TypeId
828 SocketIpv6TclassTag::GetTypeId (void)
829 {
830  static TypeId tid = TypeId ("ns3::SocketIpv6TclassTag")
831  .SetParent<Tag> ()
832  .AddConstructor<SocketIpv6TclassTag> ()
833  ;
834  return tid;
835 }
836 
837 TypeId
839 {
840  return GetTypeId ();
841 }
842 
843 uint32_t
845 {
846  return sizeof (uint8_t);
847 }
848 
849 void
851 {
852  i.WriteU8 (m_ipv6Tclass);
853 }
854 
855 void
857 {
858  m_ipv6Tclass = i.ReadU8();
859 }
860 void
861 SocketIpv6TclassTag::Print (std::ostream &os) const
862 {
863  os << "IPV6_TCLASS = " << m_ipv6Tclass;
864 }
865 
866 } // namespace ns3
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:850
virtual void Print(std::ostream &os) const
Definition: socket.cc:861
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual void Print(std::ostream &os) const
Definition: socket.cc:631
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Definition: socket.cc:507
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:564
Callback template class.
Definition: callback.h:369
void SetIpv6RecvTclass(bool ipv6RecvTclass)
Tells a socket to pass information about IPv6 Traffic Class up the stack.
Definition: socket.cc:451
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:730
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:174
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:558
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:856
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
virtual int GetSockName(Address &address) const =0
void SetIpRecvTos(bool ipv4RecvTos)
Tells a socket to pass information about IP Type of Service up the stack.
Definition: socket.cc:409
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:547
uint32_t GetSize(void) const
Definition: packet.h:620
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:782
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:93
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:736
Object to create transport layer instances that provide a socket API to applications.
virtual void Print(std::ostream &os) const
Definition: socket.cc:570
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition: socket.cc:363
TAG_BUFFER_INLINE uint8_t ReadU8(void)
Definition: tag-buffer.h:179
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:415
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:357
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound netdevice, if any.
Definition: socket.cc:350
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:133
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:127
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
Definition: socket.cc:70
virtual void Print(std::ostream &os) const
Definition: socket.cc:748
void Deserialize(TagBuffer buffer)
Definition: address.cc:162
uint32_t GetSerializedSize(void) const
Definition: address.cc:146
uint32_t GetNDevices(void) const
Definition: node.cc:141
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:613
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:676
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:671
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:838
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:742
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition: tag-buffer.h:156
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack...
Definition: socket.cc:457
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
Definition: socket.cc:120
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:103
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:329
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:113
virtual void DoDispose(void)
Definition: socket.cc:314
#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:482
read and write tag data
Definition: tag-buffer.h:51
void Serialize(TagBuffer buffer) const
Definition: address.cc:153
void SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
Tells a socket to pass information about IPv6 Hop Limit up the stack.
Definition: socket.cc:501
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:844
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:607
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:794
#define NS_LOG_WARN(msg)
Definition: log.h:246
virtual Ptr< Node > GetNode(void) const =0
virtual void Print(std::ostream &os) const
Definition: socket.cc:805
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:681
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:619
void SetIpRecvTtl(bool ipv4RecvTtl)
Tells a socket to pass information about IP_TTL up the stack.
Definition: socket.cc:476
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:625
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Definition: packet.cc:398
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:800
virtual void Print(std::ostream &os) const
Definition: socket.cc:686
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:83
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.
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:552
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:725
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:788
Ptr< T > GetObject(void) const
Definition: object.h:332
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:665
a unique identifier for an interface.
Definition: type-id.h:44