A Discrete-Event Network Simulator
API
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
30namespace ns3 {
31
33
35
36TypeId
38{
39 static TypeId tid = TypeId ("ns3::Socket")
40 .SetParent<Object> ()
41 .SetGroupName("Network");
42 return tid;
43}
44
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{
56 m_recvPktInfo = false;
57
58 m_priority = 0;
59 m_ipTos = 0;
60 m_ipTtl = 0;
61 m_ipv6Tclass = 0;
63}
64
66{
67 NS_LOG_FUNCTION (this);
68}
69
72{
73 NS_LOG_FUNCTION (node << tid);
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
83void
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
93void
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
103void
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
113void
115{
116 NS_LOG_FUNCTION (this << &dataSent);
117 m_dataSent = dataSent;
118}
119
120void
122{
123 NS_LOG_FUNCTION (this << &sendCb);
124 m_sendCb = sendCb;
125}
126
127void
129{
130 NS_LOG_FUNCTION (this << &receivedData);
131 m_receivedData = receivedData;
132}
133
134int
136{
137 NS_LOG_FUNCTION (this << p);
138 return Send (p, 0);
139}
140
141int
142Socket::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
157int
158Socket::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);
179}
180
181int
182Socket::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
196{
197 NS_LOG_FUNCTION (this << &fromAddress);
198 return RecvFrom (std::numeric_limits<uint32_t>::max (), 0, fromAddress);
199}
200
201int
202Socket::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
216void
218{
219 NS_LOG_FUNCTION (this);
220 if (!m_connectionSucceeded.IsNull ())
221 {
223 }
224}
225
226void
228{
229 NS_LOG_FUNCTION (this);
230 if (!m_connectionFailed.IsNull ())
231 {
232 m_connectionFailed (this);
233 }
234}
235
236void
238{
239 NS_LOG_FUNCTION (this);
240 if (!m_normalClose.IsNull ())
241 {
242 m_normalClose (this);
243 }
244}
245
246void
248{
249 NS_LOG_FUNCTION (this);
250 if (!m_errorClose.IsNull ())
251 {
252 m_errorClose (this);
253 }
254}
255
256bool
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
274void
276{
277 NS_LOG_FUNCTION (this << socket << from);
278 if (!m_newConnectionCreated.IsNull ())
279 {
280 m_newConnectionCreated (socket, from);
281 }
282}
283
284void
286{
287 NS_LOG_FUNCTION (this << size);
288 if (!m_dataSent.IsNull ())
289 {
290 m_dataSent (this, size);
291 }
292}
293
294void
296{
297 NS_LOG_FUNCTION (this << spaceAvailable);
298 if (!m_sendCb.IsNull ())
299 {
300 m_sendCb (this, spaceAvailable);
301 }
302}
303
304void
306{
307 NS_LOG_FUNCTION (this);
308 if (!m_receivedData.IsNull ())
309 {
310 m_receivedData (this);
311 }
312}
313
314void
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
329void
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
357void
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
370bool
372{
373 return m_manualIpv6Tclass;
374}
375
376bool
378{
379 return m_manualIpTtl;
380}
381
382bool
384{
386}
387
388void
389Socket::SetPriority (uint8_t priority)
390{
391 NS_LOG_FUNCTION (this << priority);
392 m_priority = priority;
393}
394
395uint8_t
397{
398 return m_priority;
399}
400
401uint8_t
403{
404 uint8_t prio = NS3_PRIO_BESTEFFORT;
405 ipTos &= 0x1e;
406 switch (ipTos >> 1)
407 {
408 case 0:
409 case 1:
410 case 2:
411 case 3:
412 prio = NS3_PRIO_BESTEFFORT;
413 break;
414 case 4:
415 case 5:
416 case 6:
417 case 7:
418 prio = NS3_PRIO_BULK;
419 break;
420 case 8:
421 case 9:
422 case 10:
423 case 11:
425 break;
426 case 12:
427 case 13:
428 case 14:
429 case 15:
431 break;
432 }
433 return prio;
434}
435
436void
437Socket::SetIpTos (uint8_t tos)
438{
442 {
443 // preserve the least two significant bits of the current TOS
444 // value, which are used for ECN
445 tos &= 0xfc;
446 tos |= m_ipTos & 0x3;
447 }
448 m_ipTos = tos;
450}
451
452uint8_t
454{
455 return m_ipTos;
456}
457
458void
459Socket::SetIpRecvTos (bool ipv4RecvTos)
460{
461 m_ipRecvTos = ipv4RecvTos;
462}
463
464bool
466{
467 return m_ipRecvTos;
468}
469
470void
472{
475
476 //If -1 or invalid values, use default
477 if (tclass == -1 || tclass < -1 || tclass > 0xff)
478 {
479 //Print a warning
480 if (tclass < -1 || tclass > 0xff)
481 {
482 NS_LOG_WARN ("Invalid IPV6_TCLASS value. Using default.");
483 }
484 m_manualIpv6Tclass = false;
485 m_ipv6Tclass = 0;
486 }
487 else
488 {
489 m_manualIpv6Tclass = true;
490 m_ipv6Tclass = tclass;
491 }
492}
493
494uint8_t
496{
497 return m_ipv6Tclass;
498}
499
500void
501Socket::SetIpv6RecvTclass (bool ipv6RecvTclass)
502{
503 m_ipv6RecvTclass = ipv6RecvTclass;
504}
505
506bool
508{
509 return m_ipv6RecvTclass;
510}
511
512void
513Socket::SetIpTtl (uint8_t ttl)
514{
515 m_manualIpTtl = true;
516 m_ipTtl = ttl;
517}
518
519uint8_t
521{
522 return m_ipTtl;
523}
524
525void
526Socket::SetIpRecvTtl (bool ipv4RecvTtl)
527{
528 m_ipRecvTtl = ipv4RecvTtl;
529}
530
531bool
533{
534 return m_ipRecvTtl;
535}
536
537void
538Socket::SetIpv6HopLimit (uint8_t ipHopLimit)
539{
541 m_ipv6HopLimit = ipHopLimit;
542}
543
544uint8_t
546{
547 return m_ipv6HopLimit;
548}
549
550void
551Socket::SetIpv6RecvHopLimit (bool ipv6RecvHopLimit)
552{
553 m_ipv6RecvHopLimit = ipv6RecvHopLimit;
554}
555
556bool
558{
559 return m_ipv6RecvHopLimit;
560}
561
562void
563Socket::Ipv6JoinGroup (Ipv6Address address, Ipv6MulticastFilterMode filterMode, std::vector<Ipv6Address> sourceAddresses)
564{
565 NS_LOG_FUNCTION (this<<address<<&filterMode<<&sourceAddresses);
566 NS_ASSERT_MSG (false,"Ipv6JoinGroup not implemented on this socket");
567}
568
569void
571{
572 NS_LOG_FUNCTION (this<<address);
573
574 // Join Group. Note that joining a group with no sources means joining without source restrictions.
575 std::vector<Ipv6Address> sourceAddresses;
576 Ipv6JoinGroup (address, EXCLUDE, sourceAddresses);
577}
578
579void
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
603void
605{
606 NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
607 m_ttl = ttl;
608}
609
610uint8_t
612{
613 NS_LOG_FUNCTION (this);
614 return m_ttl;
615}
616
618
619TypeId
621{
622 static TypeId tid = TypeId ("ns3::SocketIpTtlTag")
623 .SetParent<Tag> ()
624 .SetGroupName("Network")
625 .AddConstructor<SocketIpTtlTag> ()
626 ;
627 return tid;
628}
629TypeId
631{
632 return GetTypeId ();
633}
634
637{
638 NS_LOG_FUNCTION (this);
639 return 1;
640}
641void
643{
644 NS_LOG_FUNCTION (this << &i);
645 i.WriteU8 (m_ttl);
646}
647void
649{
650 NS_LOG_FUNCTION (this << &i);
651 m_ttl = i.ReadU8 ();
652}
653void
654SocketIpTtlTag::Print (std::ostream &os) const
655{
656 NS_LOG_FUNCTION (this << &os);
657 os << "Ttl=" << (uint32_t) m_ttl;
658}
659
661{
662}
663
664void
666{
667 m_hopLimit = hopLimit;
668}
669
670uint8_t
672{
673 return m_hopLimit;
674}
675
677
678TypeId
680{
681 static TypeId tid = TypeId ("ns3::SocketIpv6HopLimitTag")
682 .SetParent<Tag> ()
683 .SetGroupName("Network")
684 .AddConstructor<SocketIpv6HopLimitTag> ()
685 ;
686 return tid;
687}
688TypeId
690{
691 return GetTypeId ();
692}
693
696{
697 return 1;
698}
699void
701{
703}
704void
706{
707 m_hopLimit = i.ReadU8 ();
708}
709void
710SocketIpv6HopLimitTag::Print (std::ostream &os) const
711{
712 os << "HopLimit=" << (uint32_t) m_hopLimit;
713}
714
716{
717 NS_LOG_FUNCTION (this);
718}
719void
721{
722 NS_LOG_FUNCTION (this);
723 m_dontFragment = true;
724}
725void
727{
728 NS_LOG_FUNCTION (this);
729 m_dontFragment = false;
730}
731bool
733{
734 NS_LOG_FUNCTION (this);
735 return m_dontFragment;
736}
737
739
740TypeId
742{
743 static TypeId tid = TypeId ("ns3::SocketSetDontFragmentTag")
744 .SetParent<Tag> ()
745 .SetGroupName("Network")
746 .AddConstructor<SocketSetDontFragmentTag> ();
747 return tid;
748}
749TypeId
751{
752 return GetTypeId ();
753}
756{
757 NS_LOG_FUNCTION (this);
758 return 1;
759}
760void
762{
763 NS_LOG_FUNCTION (this << &i);
764 i.WriteU8 (m_dontFragment ? 1 : 0);
765}
766void
768{
769 NS_LOG_FUNCTION (this << &i);
770 m_dontFragment = (i.ReadU8 () == 1);
771}
772void
773SocketSetDontFragmentTag::Print (std::ostream &os) const
774{
775 NS_LOG_FUNCTION (this << &os);
776 os << (m_dontFragment ? "true" : "false");
777}
778
779
781{
782}
783
784void
786{
787 m_ipTos = ipTos;
788}
789
790uint8_t
792{
793 return m_ipTos;
794}
795
796TypeId
798{
799 static TypeId tid = TypeId ("ns3::SocketIpTosTag")
800 .SetParent<Tag> ()
801 .SetGroupName("Network")
802 .AddConstructor<SocketIpTosTag> ()
803 ;
804 return tid;
805}
806
807TypeId
809{
810 return GetTypeId ();
811}
812
815{
816 return sizeof (uint8_t);
817}
818
819void
821{
822 i.WriteU8 (m_ipTos);
823}
824
825void
827{
828 m_ipTos = i.ReadU8();
829}
830void
831SocketIpTosTag::Print (std::ostream &os) const
832{
833 os << "IP_TOS = " << m_ipTos;
834}
835
836
838{
839}
840
841void
843{
844 m_priority = priority;
845}
846
847uint8_t
849{
850 return m_priority;
851}
852
853TypeId
855{
856 static TypeId tid = TypeId ("ns3::SocketPriorityTag")
857 .SetParent<Tag> ()
858 .SetGroupName("Network")
859 .AddConstructor<SocketPriorityTag> ()
860 ;
861 return tid;
862}
863
864TypeId
866{
867 return GetTypeId ();
868}
869
872{
873 return sizeof (uint8_t);
874}
875
876void
878{
880}
881
882void
884{
885 m_priority = i.ReadU8();
886}
887
888void
889SocketPriorityTag::Print (std::ostream &os) const
890{
891 os << "SO_PRIORITY = " << m_priority;
892}
893
894
896{
897}
898
899void
901{
902 m_ipv6Tclass = tclass;
903}
904
905uint8_t
907{
908 return m_ipv6Tclass;
909}
910
911TypeId
913{
914 static TypeId tid = TypeId ("ns3::SocketIpv6TclassTag")
915 .SetParent<Tag> ()
916 .SetGroupName("Network")
917 .AddConstructor<SocketIpv6TclassTag> ()
918 ;
919 return tid;
920}
921
922TypeId
924{
925 return GetTypeId ();
926}
927
930{
931 return sizeof (uint8_t);
932}
933
934void
936{
938}
939
940void
942{
943 m_ipv6Tclass = i.ReadU8();
944}
945void
946SocketIpv6TclassTag::Print (std::ostream &os) const
947{
948 os << "IPV6_TCLASS = " << m_ipv6Tclass;
949}
950
951} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
a polymophic address class
Definition: address.h:91
Callback template class.
Definition: callback.h:1279
Describes an IPv6 address.
Definition: ipv6-address.h:50
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsAny() const
If the IPv6 address is the "Any" address.
uint32_t GetNDevices(void) const
Definition: node.cc:152
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
A base class which provides memory management and object aggregation.
Definition: object.h:88
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
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:351
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
Definition: socket.cc:513
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition: socket.cc:383
Callback< void, Ptr< Socket > > m_normalClose
connection closed callback
Definition: socket.h:1084
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
Definition: socket.cc:495
uint8_t GetPriority(void) const
Query the priority value of this socket.
Definition: socket.cc:396
bool m_ipv6RecvHopLimit
socket forwards IPv6 Hop Limit tag to L4
Definition: socket.h:1106
uint8_t m_ipTos
the socket IPv4 TOS
Definition: socket.h:1099
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
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
Definition: socket.cc:532
uint8_t m_priority
the socket priority
Definition: socket.h:1092
Socket(void)
Definition: socket.cc:45
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition: socket.cc:437
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.
bool m_manualIpv6HopLimit
socket has IPv6 Hop Limit set
Definition: socket.h:1104
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
Definition: socket.cc:217
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition: socket.cc:358
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:295
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error.
Definition: socket.cc:227
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
Callback< void, Ptr< Socket > > m_connectionFailed
connection failed callback
Definition: socket.h:1083
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
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition: socket.cc:364
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
uint8_t m_ipTtl
the socket IPv4 TTL
Definition: socket.h:1100
uint8_t m_ipv6HopLimit
the socket IPv6 Hop Limit
Definition: socket.h:1109
virtual void DoDispose(void)
Destructor implementation.
Definition: socket.cc:315
void SetIpRecvTos(bool ipv4RecvTos)
Tells a socket to pass information about IP Type of Service up the stack.
Definition: socket.cc:459
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Definition: socket.cc:557
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
Definition: socket.h:1079
bool m_ipRecvTos
socket forwards IPv4 TOS tag to L4
Definition: socket.h:1096
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack.
Definition: socket.cc:507
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:37
@ NS3_SOCK_STREAM
Definition: socket.h:105
void NotifyNormalClose(void)
Notify through the callback (if set) that the connection has been closed.
Definition: socket.cc:237
virtual void SetIpv6HopLimit(uint8_t ipHopLimit)
Manually set IPv6 Hop Limit.
Definition: socket.cc:538
uint8_t m_ipv6Tclass
the socket IPv6 Tclass
Definition: socket.h:1108
bool m_recvPktInfo
if the socket should add packet info tags to the packet forwarded to L4.
Definition: socket.h:1078
Callback< void, Ptr< Socket > > m_connectionSucceeded
connection succeeded callback
Definition: socket.h:1082
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:402
virtual ~Socket(void)
Definition: socket.cc:65
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
Definition: socket.cc:121
virtual Ptr< Node > GetNode(void) const =0
Return the node this socket is associated with.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Definition: socket.cc:377
void SetPriority(uint8_t priority)
Manually set the socket priority.
Definition: socket.cc:389
bool m_ipv6RecvTclass
socket forwards IPv6 Tclass tag to L4
Definition: socket.h:1105
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack.
Definition: socket.cc:465
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:305
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Definition: socket.h:139
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition: socket.h:1077
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition: socket.cc:330
@ NS3_PRIO_BULK
Definition: socket.h:121
@ NS3_PRIO_BESTEFFORT
Definition: socket.h:119
@ NS3_PRIO_INTERACTIVE
Definition: socket.h:123
@ NS3_PRIO_INTERACTIVE_BULK
Definition: socket.h:122
void NotifyErrorClose(void)
Notify through the callback (if set) that the connection has been closed due to an error.
Definition: socket.cc:247
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Definition: socket.cc:520
bool m_ipRecvTtl
socket forwards IPv4 TTL tag to L4
Definition: socket.h:1097
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:563
Callback< void, Ptr< Socket > > m_receivedData
data received callback
Definition: socket.h:1090
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
Definition: socket.cc:545
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
Callback< void, Ptr< Socket >, uint32_t > m_sendCb
packet sent callback
Definition: socket.h:1089
bool m_manualIpv6Tclass
socket has IPv6 Tclass set
Definition: socket.h:1103
Callback< void, Ptr< Socket >, const Address & > m_newConnectionCreated
connection created callback
Definition: socket.h:1087
bool m_manualIpTtl
socket has IPv4 TTL set
Definition: socket.h:1095
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition: socket.cc:128
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Definition: socket.cc:371
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
Callback< void, Ptr< Socket >, uint32_t > m_dataSent
data sent callback
Definition: socket.h:1088
void SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
Tells a socket to pass information about IPv6 Hop Limit up the stack.
Definition: socket.cc:551
void SetIpv6Tclass(int ipTclass)
Manually set IPv6 Traffic Class field.
Definition: socket.cc:471
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:285
void SetIpRecvTtl(bool ipv4RecvTtl)
Tells a socket to pass information about IP_TTL up the stack.
Definition: socket.cc:526
void SetIpv6RecvTclass(bool ipv6RecvTclass)
Tells a socket to pass information about IPv6 Traffic Class up the stack.
Definition: socket.cc:501
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Definition: socket.cc:453
virtual void Ipv6LeaveGroup(void)
Leaves IPv6 multicast group this socket is joined to.
Definition: socket.cc:580
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
virtual enum Socket::SocketType GetSocketType(void) const =0
Callback< bool, Ptr< Socket >, const Address & > m_connectionRequest
connection request callback
Definition: socket.h:1086
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
Callback< void, Ptr< Socket > > m_errorClose
connection closed due to errors callback
Definition: socket.h:1085
indicates whether the socket has IP_TOS set.
Definition: socket.h:1263
uint8_t m_ipTos
the TOS carried by the tag
Definition: socket.h:1302
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:814
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:820
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition: socket.cc:785
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:797
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:826
uint8_t GetTos(void) const
Get the tag's TOS.
Definition: socket.cc:791
virtual void Print(std::ostream &os) const
Definition: socket.cc:831
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: socket.cc:808
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition: socket.h:1117
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:620
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:648
uint8_t GetTtl(void) const
Get the tag's TTL.
Definition: socket.cc:611
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition: socket.cc:604
virtual void Print(std::ostream &os) const
Definition: socket.cc:654
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:636
uint8_t m_ttl
the ttl carried by the tag
Definition: socket.h:1157
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:642
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: socket.cc:630
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition: socket.h:1165
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:705
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:679
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:700
virtual void Print(std::ostream &os) const
Definition: socket.cc:710
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition: socket.cc:665
uint8_t GetHopLimit(void) const
Get the tag's Hop Limit.
Definition: socket.cc:671
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:695
uint8_t m_hopLimit
the Hop Limit carried by the tag
Definition: socket.h:1205
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: socket.cc:689
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1356
uint8_t GetTclass(void) const
Get the tag's Tclass.
Definition: socket.cc:906
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: socket.cc:923
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:929
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:941
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:912
uint8_t m_ipv6Tclass
the Tclass carried by the tag
Definition: socket.h:1395
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:935
virtual void Print(std::ostream &os) const
Definition: socket.cc:946
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition: socket.cc:900
indicates whether the socket has a priority set.
Definition: socket.h:1309
uint8_t m_priority
the priority carried by the tag
Definition: socket.h:1348
uint8_t GetPriority(void) const
Get the tag's priority.
Definition: socket.cc:848
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:877
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:883
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:871
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:854
virtual void Print(std::ostream &os) const
Definition: socket.cc:889
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition: socket.cc:842
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: socket.cc:865
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
Definition: socket.h:1213
bool IsEnabled(void) const
Checks if the DF (Don't Fragment) flag is set.
Definition: socket.cc:732
virtual void Serialize(TagBuffer i) const
Definition: socket.cc:761
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: socket.cc:750
void Disable(void)
Disables the DF (Don't Fragment) flag.
Definition: socket.cc:726
virtual void Print(std::ostream &os) const
Definition: socket.cc:773
static TypeId GetTypeId(void)
Get the type ID.
Definition: socket.cc:741
virtual void Deserialize(TagBuffer i)
Definition: socket.cc:767
bool m_dontFragment
DF bit value for outgoing packets.
Definition: socket.h:1255
void Enable(void)
Enables the DF (Don't Fragment) flag.
Definition: socket.cc:720
virtual uint32_t GetSerializedSize(void) const
Definition: socket.cc:755
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(void)
Definition: tag-buffer.h:195
tag a set of bytes in a packet
Definition: tag.h:37
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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:265
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.