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 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::Socket")
40  .SetParent<Object> ();
41  return tid;
42 }
43 
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 
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
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
217 {
218  NS_LOG_FUNCTION (this);
219  if (!m_connectionSucceeded.IsNull ())
220  {
221  m_connectionSucceeded (this);
222  }
223 }
224 
225 void
227 {
228  NS_LOG_FUNCTION (this);
229  if (!m_connectionFailed.IsNull ())
230  {
231  m_connectionFailed (this);
232  }
233 }
234 
235 void
237 {
238  NS_LOG_FUNCTION (this);
239  if (!m_normalClose.IsNull ())
240  {
241  m_normalClose (this);
242  }
243 }
244 
245 void
247 {
248  NS_LOG_FUNCTION (this);
249  if (!m_errorClose.IsNull ())
250  {
251  m_errorClose (this);
252  }
253 }
254 
255 bool
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
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
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
371 {
372  return m_manualIpTos;
373 }
374 
375 bool
377 {
378  return m_manualIpv6Tclass;
379 }
380 
381 bool
383 {
384  return m_manualIpTtl;
385 }
386 
387 bool
389 {
390  return m_manualIpv6HopLimit;
391 }
392 
393 void
394 Socket::SetIpTos (uint8_t tos)
395 {
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
422 {
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
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
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 
517 {
518  NS_LOG_FUNCTION (this);
519 }
520 
521 void
523 {
524  NS_LOG_FUNCTION (this << addr);
525  m_address = addr;
526 }
527 
528 Address
530 {
531  NS_LOG_FUNCTION (this);
532  return m_address;
533 }
534 
536 
537 TypeId
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);
568 }
569 void
570 SocketAddressTag::Print (std::ostream &os) const
571 {
572  NS_LOG_FUNCTION (this << &os);
573  os << "address=" << m_address;
574 }
575 
577 {
578  NS_LOG_FUNCTION (this);
579 }
580 
581 void
583 {
584  NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
585  m_ttl = ttl;
586 }
587 
588 uint8_t
590 {
591  NS_LOG_FUNCTION (this);
592  return m_ttl;
593 }
594 
596 
597 TypeId
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 
638 {
639 }
640 
641 void
643 {
644  m_hopLimit = hopLimit;
645 }
646 
647 uint8_t
649 {
650  return m_hopLimit;
651 }
652 
654 
655 TypeId
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 
692 {
693  NS_LOG_FUNCTION (this);
694 }
695 void
697 {
698  NS_LOG_FUNCTION (this);
699  m_dontFragment = true;
700 }
701 void
703 {
704  NS_LOG_FUNCTION (this);
705  m_dontFragment = false;
706 }
707 bool
709 {
710  NS_LOG_FUNCTION (this);
711  return m_dontFragment;
712 }
713 
715 
716 TypeId
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 
756 {
757 }
758 
759 void
760 SocketIpTosTag::SetTos (uint8_t ipTos)
761 {
762  m_ipTos = ipTos;
763 }
764 
765 uint8_t
767 {
768  return m_ipTos;
769 }
770 
771 TypeId
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 
812 {
813 }
814 
815 void
817 {
818  m_ipv6Tclass = tclass;
819 }
820 
821 uint8_t
823 {
824  return m_ipv6Tclass;
825 }
826 
827 TypeId
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
uint8_t m_ipv6HopLimit
the socket IPv6 Hop Limit
Definition: socket.h:941
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:598
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:816
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:850
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:382
virtual void Print(std::ostream &os) const
Definition: socket.cc:861
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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
bool m_manualIpv6HopLimit
socket has IPv6 Hop Limit set
Definition: socket.h:936
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:564
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:470
Callback template class.
Definition: callback.h:924
void SetIpv6RecvTclass(bool ipv6RecvTclass)
Tells a socket to pass information about IPv6 Traffic Class up the stack.
Definition: socket.cc:451
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:403
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Definition: socket.h:1044
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
uint8_t m_hopLimit
the Hop Limit carried by the tag
Definition: socket.h:1085
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:304
uint8_t GetTos(void) const
Get the tag's TOS.
Definition: socket.cc:766
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
bool m_dontFragment
DF bit value for outgoing packets.
Definition: socket.h:1135
Socket(void)
Definition: socket.cc:44
void SetAddress(Address addr)
Set the tag's address.
Definition: socket.cc:522
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:558
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error...
Definition: socket.cc:226
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:717
Callback< bool, Ptr< Socket >, const Address & > m_connectionRequest
connection request callback
Definition: socket.h:919
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:856
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
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:409
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:547
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:828
bool IsManualIpTos(void) const
Checks if the socket has a specific IPv4 ToS set.
Definition: socket.cc:370
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
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:495
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
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:760
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:708
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:736
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:256
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: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:195
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: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
uint8_t GetTclass(void) const
Get the tag's Tclass.
Definition: socket.cc:822
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:582
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:538
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:772
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:134
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:376
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:284
virtual ~Socket(void)
Definition: socket.cc:64
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)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Definition: socket.cc:70
virtual void Print(std::ostream &os) const
Definition: socket.cc:748
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:642
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:216
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:142
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:388
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:613
void NotifyNormalClose(void)
Notify through the callback (if set) that the connection has been closed.
Definition: socket.cc:236
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:421
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:676
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Notify through the callback (if set) that a new connection has been created.
Definition: socket.cc:274
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:671
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:445
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:37
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:172
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:457
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:120
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: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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: socket.cc:314
#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:84
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
Definition: socket.cc:482
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:656
uint8_t GetHopLimit(void) const
Get the tag's Hop Limit.
Definition: socket.cc:648
void Disable(void)
Disables the DF (Don't Fragment) flag.
Definition: socket.cc:702
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:501
Callback< void, Ptr< Socket > > m_normalClose
connection closed callback
Definition: socket.h:917
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)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:203
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:529
virtual void Print(std::ostream &os) const
Definition: socket.cc:805
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:681
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:619
void SetIpRecvTtl(bool ipv4RecvTtl)
Tells a socket to pass information about IP_TTL up the stack.
Definition: socket.cc:476
void Enable(void)
Enables the DF (Don't Fragment) flag.
Definition: socket.cc:696
uint8_t m_ipv6Tclass
the Tclass carried by the tag
Definition: socket.h:1229
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:625
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: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
a base class which provides memory management and object aggregation
Definition: object.h:64
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:589
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:552
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:725
virtual void SetIpv6HopLimit(uint8_t ipHopLimit)
Manually set IPv6 Hop Limit.
Definition: socket.cc:488
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:788
Ptr< T > GetObject(void) const
Definition: object.h:362
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition: socket.cc:394
virtual TypeId GetInstanceTypeId(void) const
Definition: socket.cc:665
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:294
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
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:246
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
Definition: socket.cc:463
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