A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
socket.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation
3 * 2007 INRIA
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: George F. Riley<riley@ece.gatech.edu>
8 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
9 */
10
11#include "socket.h"
12
13#include "node.h"
14#include "packet.h"
15#include "socket-factory.h"
16
17#include "ns3/log.h"
18
19#include <limits>
20
21namespace ns3
22{
23
25
27
28TypeId
30{
31 static TypeId tid = TypeId("ns3::Socket").SetParent<Object>().SetGroupName("Network");
32 return tid;
33}
34
36 : m_manualIpTtl(false),
37 m_ipRecvTos(false),
38 m_ipRecvTtl(false),
39 m_manualIpv6Tclass(false),
40 m_manualIpv6HopLimit(false),
41 m_ipv6RecvTclass(false),
42 m_ipv6RecvHopLimit(false)
43{
45 m_boundnetdevice = nullptr;
46 m_recvPktInfo = false;
47
48 m_priority = 0;
49 m_ipTos = 0;
50 m_ipTtl = 0;
51 m_ipv6Tclass = 0;
53}
54
56{
57 NS_LOG_FUNCTION(this);
58}
59
62{
63 NS_LOG_FUNCTION(node << tid);
65 NS_ASSERT_MSG(node, "CreateSocket: node is null.");
66 Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory>(tid);
67 NS_ASSERT_MSG(socketFactory,
68 "CreateSocket: can not create a "
69 << tid.GetName() << " - perhaps the node is missing the required protocol.");
70 s = socketFactory->CreateSocket();
71 NS_ASSERT(s);
72 return s;
73}
74
75void
77 Callback<void, Ptr<Socket>> connectionFailed)
78{
79 NS_LOG_FUNCTION(this << &connectionSucceeded << &connectionFailed);
80 m_connectionSucceeded = connectionSucceeded;
81 m_connectionFailed = connectionFailed;
82}
83
84void
86 Callback<void, Ptr<Socket>> errorClose)
87{
88 NS_LOG_FUNCTION(this << &normalClose << &errorClose);
89 m_normalClose = normalClose;
90 m_errorClose = errorClose;
91}
92
93void
94Socket::SetAcceptCallback(Callback<bool, Ptr<Socket>, const Address&> connectionRequest,
95 Callback<void, Ptr<Socket>, const Address&> newConnectionCreated)
96{
97 NS_LOG_FUNCTION(this << &connectionRequest << &newConnectionCreated);
98 m_connectionRequest = connectionRequest;
99 m_newConnectionCreated = newConnectionCreated;
100}
101
102void
104{
105 NS_LOG_FUNCTION(this << &dataSent);
106 m_dataSent = dataSent;
107}
108
109void
111{
112 NS_LOG_FUNCTION(this << &sendCb);
113 m_sendCb = sendCb;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << &receivedData);
120 m_receivedData = receivedData;
121}
122
123int
125{
126 NS_LOG_FUNCTION(this << p);
127 return Send(p, 0);
128}
129
130int
131Socket::Send(const uint8_t* buf, uint32_t size, uint32_t flags)
132{
133 NS_LOG_FUNCTION(this << &buf << size << flags);
134 Ptr<Packet> p;
135 if (buf)
136 {
137 p = Create<Packet>(buf, size);
138 }
139 else
140 {
141 p = Create<Packet>(size);
142 }
143 return Send(p, flags);
144}
145
146int
147Socket::SendTo(const uint8_t* buf, uint32_t size, uint32_t flags, const Address& toAddress)
148{
149 NS_LOG_FUNCTION(this << &buf << size << flags << &toAddress);
150 Ptr<Packet> p;
151 if (buf)
152 {
153 p = Create<Packet>(buf, size);
154 }
155 else
156 {
157 p = Create<Packet>(size);
158 }
159 return SendTo(p, flags, toAddress);
160}
161
164{
165 NS_LOG_FUNCTION(this);
166 return Recv(std::numeric_limits<uint32_t>::max(), 0);
167}
168
169int
170Socket::Recv(uint8_t* buf, uint32_t size, uint32_t flags)
171{
172 NS_LOG_FUNCTION(this << &buf << size << flags);
173 Ptr<Packet> p = Recv(size, flags); // read up to "size" bytes
174 if (!p)
175 {
176 return 0;
177 }
178 p->CopyData(buf, p->GetSize());
179 return p->GetSize();
180}
181
184{
185 NS_LOG_FUNCTION(this << &fromAddress);
186 return RecvFrom(std::numeric_limits<uint32_t>::max(), 0, fromAddress);
187}
188
189int
190Socket::RecvFrom(uint8_t* buf, uint32_t size, uint32_t flags, Address& fromAddress)
191{
192 NS_LOG_FUNCTION(this << &buf << size << flags << &fromAddress);
193 Ptr<Packet> p = RecvFrom(size, flags, fromAddress);
194 if (!p)
195 {
196 return 0;
197 }
198 p->CopyData(buf, p->GetSize());
199 return p->GetSize();
200}
201
202void
204{
205 NS_LOG_FUNCTION(this);
206 if (!m_connectionSucceeded.IsNull())
207 {
209 }
210}
211
212void
214{
215 NS_LOG_FUNCTION(this);
216 if (!m_connectionFailed.IsNull())
217 {
218 m_connectionFailed(this);
219 }
220}
221
222void
224{
225 NS_LOG_FUNCTION(this);
226 if (!m_normalClose.IsNull())
227 {
228 m_normalClose(this);
229 }
230}
231
232void
234{
235 NS_LOG_FUNCTION(this);
236 if (!m_errorClose.IsNull())
237 {
238 m_errorClose(this);
239 }
240}
241
242bool
244{
245 NS_LOG_FUNCTION(this << &from);
246 if (!m_connectionRequest.IsNull())
247 {
248 return m_connectionRequest(this, from);
249 }
250 else
251 {
252 // accept all incoming connections by default.
253 // this way people writing code don't have to do anything
254 // special like register a callback that returns true
255 // just to get incoming connections
256 return true;
257 }
258}
259
260void
262{
263 NS_LOG_FUNCTION(this << socket << from);
264 if (!m_newConnectionCreated.IsNull())
265 {
266 m_newConnectionCreated(socket, from);
267 }
268}
269
270void
272{
273 NS_LOG_FUNCTION(this << size);
274 if (!m_dataSent.IsNull())
275 {
276 m_dataSent(this, size);
277 }
278}
279
280void
282{
283 NS_LOG_FUNCTION(this << spaceAvailable);
284 if (!m_sendCb.IsNull())
285 {
286 m_sendCb(this, spaceAvailable);
287 }
288}
289
290void
292{
293 NS_LOG_FUNCTION(this);
294 if (!m_receivedData.IsNull())
295 {
296 m_receivedData(this);
297 }
298}
299
300void
314
315void
317{
318 NS_LOG_FUNCTION(this << netdevice);
319 if (netdevice)
320 {
321 bool found = false;
322 for (uint32_t i = 0; i < GetNode()->GetNDevices(); i++)
323 {
324 if (GetNode()->GetDevice(i) == netdevice)
325 {
326 found = true;
327 break;
328 }
329 }
330 NS_ASSERT_MSG(found, "Socket cannot be bound to a NetDevice not existing on the Node");
331 }
332 m_boundnetdevice = netdevice;
333}
334
341
342void
344{
345 NS_LOG_FUNCTION(this << flag);
346 m_recvPktInfo = flag;
347}
348
349bool
351{
352 NS_LOG_FUNCTION(this);
353 return m_recvPktInfo;
354}
355
356bool
358{
359 return m_manualIpv6Tclass;
360}
361
362bool
364{
365 return m_manualIpTtl;
366}
367
368bool
373
374void
375Socket::SetPriority(uint8_t priority)
376{
377 NS_LOG_FUNCTION(this << priority);
378 m_priority = priority;
379}
380
381uint8_t
383{
384 return m_priority;
385}
386
387uint8_t
389{
390 uint8_t prio = NS3_PRIO_BESTEFFORT;
391 ipTos &= 0x1e;
392 switch (ipTos >> 1)
393 {
394 case 0:
395 case 1:
396 case 2:
397 case 3:
398 prio = NS3_PRIO_BESTEFFORT;
399 break;
400 case 4:
401 case 5:
402 case 6:
403 case 7:
404 prio = NS3_PRIO_BULK;
405 break;
406 case 8:
407 case 9:
408 case 10:
409 case 11:
411 break;
412 case 12:
413 case 13:
414 case 14:
415 case 15:
417 break;
418 }
419 return prio;
420}
421
422void
424{
425 Address address;
426 GetSockName(address);
428 {
429 // preserve the least two significant bits of the current TOS
430 // value, which are used for ECN
431 tos &= 0xfc;
432 tos |= m_ipTos & 0x3;
433 }
434 m_ipTos = tos;
436}
437
438uint8_t
440{
441 return m_ipTos;
442}
443
444void
445Socket::SetIpRecvTos(bool ipv4RecvTos)
446{
447 m_ipRecvTos = ipv4RecvTos;
448}
449
450bool
452{
453 return m_ipRecvTos;
454}
455
456void
458{
459 Address address;
460 GetSockName(address);
461
462 // If -1 or invalid values, use default
463 if (tclass == -1 || tclass < -1 || tclass > 0xff)
464 {
465 // Print a warning
466 if (tclass < -1 || tclass > 0xff)
467 {
468 NS_LOG_WARN("Invalid IPV6_TCLASS value. Using default.");
469 }
470 m_manualIpv6Tclass = false;
471 m_ipv6Tclass = 0;
472 }
473 else
474 {
475 m_manualIpv6Tclass = true;
476 m_ipv6Tclass = tclass;
477 }
478}
479
480uint8_t
482{
483 return m_ipv6Tclass;
484}
485
486void
487Socket::SetIpv6RecvTclass(bool ipv6RecvTclass)
488{
489 m_ipv6RecvTclass = ipv6RecvTclass;
490}
491
492bool
494{
495 return m_ipv6RecvTclass;
496}
497
498void
500{
501 m_manualIpTtl = true;
502 m_ipTtl = ttl;
503}
504
505uint8_t
507{
508 return m_ipTtl;
509}
510
511void
512Socket::SetIpRecvTtl(bool ipv4RecvTtl)
513{
514 m_ipRecvTtl = ipv4RecvTtl;
515}
516
517bool
519{
520 return m_ipRecvTtl;
521}
522
523void
524Socket::SetIpv6HopLimit(uint8_t ipHopLimit)
525{
527 m_ipv6HopLimit = ipHopLimit;
528}
529
530uint8_t
532{
533 return m_ipv6HopLimit;
534}
535
536void
537Socket::SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
538{
539 m_ipv6RecvHopLimit = ipv6RecvHopLimit;
540}
541
542bool
544{
545 return m_ipv6RecvHopLimit;
546}
547
548void
550 Ipv6MulticastFilterMode filterMode,
551 std::vector<Ipv6Address> sourceAddresses)
552{
553 NS_LOG_FUNCTION(this << address << &filterMode << &sourceAddresses);
554 NS_ASSERT_MSG(false, "Ipv6JoinGroup not implemented on this socket");
555}
556
557void
559{
560 NS_LOG_FUNCTION(this << address);
561
562 // Join Group. Note that joining a group with no sources means joining without source
563 // restrictions.
564 std::vector<Ipv6Address> sourceAddresses;
565 Ipv6JoinGroup(address, EXCLUDE, sourceAddresses);
566}
567
568void
570{
571 NS_LOG_FUNCTION(this);
573 {
574 NS_LOG_INFO(" The socket was not bound to any group.");
575 return;
576 }
577 // Leave Group. Note that joining a group with no sources means leaving it.
578 std::vector<Ipv6Address> sourceAddresses;
581}
582
583/***************************************************************
584 * Socket Tags
585 ***************************************************************/
586
591
592void
594{
595 NS_LOG_FUNCTION(this << static_cast<uint32_t>(ttl));
596 m_ttl = ttl;
597}
598
599uint8_t
601{
602 NS_LOG_FUNCTION(this);
603 return m_ttl;
604}
605
607
608TypeId
610{
611 static TypeId tid = TypeId("ns3::SocketIpTtlTag")
612 .SetParent<Tag>()
613 .SetGroupName("Network")
614 .AddConstructor<SocketIpTtlTag>();
615 return tid;
616}
617
618TypeId
620{
621 return GetTypeId();
622}
623
626{
627 NS_LOG_FUNCTION(this);
628 return 1;
629}
630
631void
633{
634 NS_LOG_FUNCTION(this << &i);
635 i.WriteU8(m_ttl);
636}
637
638void
640{
641 NS_LOG_FUNCTION(this << &i);
642 m_ttl = i.ReadU8();
643}
644
645void
646SocketIpTtlTag::Print(std::ostream& os) const
647{
648 NS_LOG_FUNCTION(this << &os);
649 os << "Ttl=" << (uint32_t)m_ttl;
650}
651
655
656void
658{
659 m_hopLimit = hopLimit;
660}
661
662uint8_t
664{
665 return m_hopLimit;
666}
667
669
670TypeId
672{
673 static TypeId tid = TypeId("ns3::SocketIpv6HopLimitTag")
674 .SetParent<Tag>()
675 .SetGroupName("Network")
676 .AddConstructor<SocketIpv6HopLimitTag>();
677 return tid;
678}
679
680TypeId
685
688{
689 return 1;
690}
691
692void
697
698void
703
704void
705SocketIpv6HopLimitTag::Print(std::ostream& os) const
706{
707 os << "HopLimit=" << (uint32_t)m_hopLimit;
708}
709
714
715void
721
722void
728
729bool
735
737
738TypeId
740{
741 static TypeId tid = TypeId("ns3::SocketSetDontFragmentTag")
742 .SetParent<Tag>()
743 .SetGroupName("Network")
744 .AddConstructor<SocketSetDontFragmentTag>();
745 return tid;
746}
747
748TypeId
753
756{
757 NS_LOG_FUNCTION(this);
758 return 1;
759}
760
761void
763{
764 NS_LOG_FUNCTION(this << &i);
765 i.WriteU8(m_dontFragment ? 1 : 0);
766}
767
768void
774
775void
776SocketSetDontFragmentTag::Print(std::ostream& os) const
777{
778 NS_LOG_FUNCTION(this << &os);
779 os << (m_dontFragment ? "true" : "false");
780}
781
785
786void
788{
789 m_ipTos = ipTos;
790}
791
792uint8_t
794{
795 return m_ipTos;
796}
797
798TypeId
800{
801 static TypeId tid = TypeId("ns3::SocketIpTosTag")
802 .SetParent<Tag>()
803 .SetGroupName("Network")
804 .AddConstructor<SocketIpTosTag>();
805 return tid;
806}
807
808TypeId
810{
811 return GetTypeId();
812}
813
816{
817 return sizeof(uint8_t);
818}
819
820void
825
826void
831
832void
833SocketIpTosTag::Print(std::ostream& os) const
834{
835 os << "IP_TOS = " << m_ipTos;
836}
837
841
842void
844{
845 m_priority = priority;
846}
847
848uint8_t
850{
851 return m_priority;
852}
853
854TypeId
856{
857 static TypeId tid = TypeId("ns3::SocketPriorityTag")
858 .SetParent<Tag>()
859 .SetGroupName("Network")
860 .AddConstructor<SocketPriorityTag>();
861 return tid;
862}
863
864TypeId
866{
867 return GetTypeId();
868}
869
872{
873 return sizeof(uint8_t);
874}
875
876void
881
882void
887
888void
889SocketPriorityTag::Print(std::ostream& os) const
890{
891 os << "SO_PRIORITY = " << m_priority;
892}
893
897
898void
900{
901 m_ipv6Tclass = tclass;
902}
903
904uint8_t
906{
907 return m_ipv6Tclass;
908}
909
910TypeId
912{
913 static TypeId tid = TypeId("ns3::SocketIpv6TclassTag")
914 .SetParent<Tag>()
915 .SetGroupName("Network")
916 .AddConstructor<SocketIpv6TclassTag>();
917 return tid;
918}
919
920TypeId
922{
923 return GetTypeId();
924}
925
928{
929 return sizeof(uint8_t);
930}
931
932void
937
938void
943
944void
945SocketIpv6TclassTag::Print(std::ostream& os) const
946{
947 os << "IPV6_TCLASS = " << m_ipv6Tclass;
948}
949
950} // namespace ns3
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsAny() const
If the IPv6 address is the "Any" address.
uint32_t GetNDevices() const
Definition node.cc:147
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition node.cc:138
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
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:336
bool IsIpRecvTtl() const
Ask if the socket is currently passing information about IP_TTL up the stack.
Definition socket.cc:518
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
Definition socket.cc:499
virtual Socket::SocketType GetSocketType() const =0
Ptr< Packet > Recv()
Read a single packet from the socket.
Definition socket.cc:163
Callback< void, Ptr< Socket > > m_normalClose
connection closed callback
Definition socket.h:1078
virtual void Ipv6LeaveGroup()
Leaves IPv6 multicast group this socket is joined to.
Definition socket.cc:569
bool m_ipv6RecvHopLimit
socket forwards IPv6 Hop Limit tag to L4
Definition socket.h:1102
uint8_t m_ipTos
the socket IPv4 TOS
Definition socket.h:1095
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:76
uint8_t m_priority
the socket priority
Definition socket.h:1088
bool IsManualIpTtl() const
Checks if the socket has a specific IPv4 TTL set.
Definition socket.cc:363
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
Definition socket.cc:423
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:1100
Callback< bool, Ptr< Socket >, const Address & > m_connectionRequest
connection request callback
Definition socket.h:1081
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
Definition socket.cc:343
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
Definition socket.cc:281
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Notify through the callback (if set) that a new connection has been created.
Definition socket.cc:261
virtual uint8_t GetIpTtl() const
Query the value of IP Time to Live field of this socket.
Definition socket.cc:506
Callback< void, Ptr< Socket > > m_connectionFailed
connection failed callback
Definition socket.h:1077
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:29
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:94
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
Definition socket.cc:350
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:243
uint8_t m_ipTtl
the socket IPv4 TTL
Definition socket.h:1096
uint8_t m_ipv6HopLimit
the socket IPv6 Hop Limit
Definition socket.h:1105
uint8_t GetIpTos() const
Query the value of IP Type of Service of this socket.
Definition socket.cc:439
~Socket() override
Definition socket.cc:55
void SetIpRecvTos(bool ipv4RecvTos)
Tells a socket to pass information about IP Type of Service up the stack.
Definition socket.cc:445
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
Definition socket.h:1073
bool m_ipRecvTos
socket forwards IPv4 TOS tag to L4
Definition socket.h:1092
@ NS3_SOCK_STREAM
Definition socket.h:97
virtual void SetIpv6HopLimit(uint8_t ipHopLimit)
Manually set IPv6 Hop Limit.
Definition socket.cc:524
uint8_t m_ipv6Tclass
the socket IPv6 Tclass
Definition socket.h:1104
bool m_recvPktInfo
if the socket should add packet info tags to the packet forwarded to L4.
Definition socket.h:1072
Callback< void, Ptr< Socket > > m_connectionSucceeded
connection succeeded callback
Definition socket.h:1076
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:103
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
Definition socket.cc:388
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
Definition socket.cc:110
void NotifyErrorClose()
Notify through the callback (if set) that the connection has been closed due to an error.
Definition socket.cc:233
void NotifyDataRecv()
Notify through the callback (if set) that some data have been received.
Definition socket.cc:291
void SetPriority(uint8_t priority)
Manually set the socket priority.
Definition socket.cc:375
bool m_ipv6RecvTclass
socket forwards IPv6 Tclass tag to L4
Definition socket.h:1101
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Definition socket.h:132
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
Definition socket.h:1070
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
Definition socket.cc:316
@ NS3_PRIO_BULK
Definition socket.h:114
@ NS3_PRIO_BESTEFFORT
Definition socket.h:112
@ NS3_PRIO_INTERACTIVE
Definition socket.h:116
@ NS3_PRIO_INTERACTIVE_BULK
Definition socket.h:115
bool m_ipRecvTtl
socket forwards IPv4 TTL tag to L4
Definition socket.h:1093
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:549
Callback< void, Ptr< Socket > > m_receivedData
data received callback
Definition socket.h:1086
void NotifyNormalClose()
Notify through the callback (if set) that the connection has been closed.
Definition socket.cc:223
bool IsIpv6RecvTclass() const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack.
Definition socket.cc:493
bool IsIpv6RecvHopLimit() const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Definition socket.cc:543
virtual uint8_t GetIpv6HopLimit() const
Query the value of IP Hop Limit field of this socket.
Definition socket.cc:531
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:85
bool m_manualIpv6Tclass
socket has IPv6 Tclass set
Definition socket.h:1099
Callback< void, Ptr< Socket >, const Address & > m_newConnectionCreated
connection created callback
Definition socket.h:1083
bool m_manualIpTtl
socket has IPv4 TTL set
Definition socket.h:1091
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
Definition socket.cc:117
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:61
Callback< void, Ptr< Socket >, uint32_t > m_dataSent
data sent callback
Definition socket.h:1084
bool IsIpRecvTos() const
Ask if the socket is currently passing information about IP Type of Service up the stack.
Definition socket.cc:451
Callback< void, Ptr< Socket >, uint32_t > m_sendCb
packet sent callback
Definition socket.h:1085
void SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)
Tells a socket to pass information about IPv6 Hop Limit up the stack.
Definition socket.cc:537
virtual Ptr< Node > GetNode() const =0
Return the node this socket is associated with.
void SetIpv6Tclass(int ipTclass)
Manually set IPv6 Traffic Class field.
Definition socket.cc:457
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition socket.cc:271
void NotifyConnectionSucceeded()
Notify through the callback (if set) that the connection has been established.
Definition socket.cc:203
void SetIpRecvTtl(bool ipv4RecvTtl)
Tells a socket to pass information about IP_TTL up the stack.
Definition socket.cc:512
uint8_t GetPriority() const
Query the priority value of this socket.
Definition socket.cc:382
void SetIpv6RecvTclass(bool ipv6RecvTclass)
Tells a socket to pass information about IPv6 Traffic Class up the stack.
Definition socket.cc:487
void DoDispose() override
Destructor implementation.
Definition socket.cc:301
uint8_t GetIpv6Tclass() const
Query the value of IPv6 Traffic Class field of this socket.
Definition socket.cc:481
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
bool IsManualIpv6HopLimit() const
Checks if the socket has a specific IPv6 Hop Limit set.
Definition socket.cc:369
Callback< void, Ptr< Socket > > m_errorClose
connection closed due to errors callback
Definition socket.h:1079
bool IsManualIpv6Tclass() const
Checks if the socket has a specific IPv6 Tclass set.
Definition socket.cc:357
void NotifyConnectionFailed()
Notify through the callback (if set) that the connection has not been established due to an error.
Definition socket.cc:213
indicates whether the socket has IP_TOS set.
Definition socket.h:1260
uint8_t m_ipTos
the TOS carried by the tag
Definition socket.h:1300
void Serialize(TagBuffer i) const override
Definition socket.cc:821
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:799
uint32_t GetSerializedSize() const override
Definition socket.cc:815
void SetTos(uint8_t tos)
Set the tag's TOS.
Definition socket.cc:787
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition socket.cc:809
uint8_t GetTos() const
Get the tag's TOS.
Definition socket.cc:793
void Print(std::ostream &os) const override
Definition socket.cc:833
void Deserialize(TagBuffer i) override
Definition socket.cc:827
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
Definition socket.h:1113
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Definition socket.cc:593
void Deserialize(TagBuffer i) override
Definition socket.cc:639
uint32_t GetSerializedSize() const override
Definition socket.cc:625
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition socket.cc:619
void Serialize(TagBuffer i) const override
Definition socket.cc:632
uint8_t GetTtl() const
Get the tag's TTL.
Definition socket.cc:600
uint8_t m_ttl
the ttl carried by the tag
Definition socket.h:1153
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:609
void Print(std::ostream &os) const override
Definition socket.cc:646
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition socket.h:1161
uint32_t GetSerializedSize() const override
Definition socket.cc:687
uint8_t GetHopLimit() const
Get the tag's Hop Limit.
Definition socket.cc:663
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:671
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition socket.cc:681
void Serialize(TagBuffer i) const override
Definition socket.cc:693
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition socket.cc:657
void Print(std::ostream &os) const override
Definition socket.cc:705
uint8_t m_hopLimit
the Hop Limit carried by the tag
Definition socket.h:1201
void Deserialize(TagBuffer i) override
Definition socket.cc:699
indicates whether the socket has IPV6_TCLASS set.
Definition socket.h:1355
void Serialize(TagBuffer i) const override
Definition socket.cc:933
void Print(std::ostream &os) const override
Definition socket.cc:945
uint8_t GetTclass() const
Get the tag's Tclass.
Definition socket.cc:905
uint32_t GetSerializedSize() const override
Definition socket.cc:927
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:911
uint8_t m_ipv6Tclass
the Tclass carried by the tag
Definition socket.h:1395
void Deserialize(TagBuffer i) override
Definition socket.cc:939
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition socket.cc:921
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
Definition socket.cc:899
indicates whether the socket has a priority set.
Definition socket.h:1307
uint8_t m_priority
the priority carried by the tag
Definition socket.h:1347
void Print(std::ostream &os) const override
Definition socket.cc:889
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition socket.cc:865
uint32_t GetSerializedSize() const override
Definition socket.cc:871
void Deserialize(TagBuffer i) override
Definition socket.cc:883
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:855
uint8_t GetPriority() const
Get the tag's priority.
Definition socket.cc:849
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition socket.cc:843
void Serialize(TagBuffer i) const override
Definition socket.cc:877
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
Definition socket.h:1209
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition socket.cc:749
static TypeId GetTypeId()
Get the type ID.
Definition socket.cc:739
void Enable()
Enables the DF (Don't Fragment) flag.
Definition socket.cc:716
void Deserialize(TagBuffer i) override
Definition socket.cc:769
uint32_t GetSerializedSize() const override
Definition socket.cc:755
void Print(std::ostream &os) const override
Definition socket.cc:776
void Serialize(TagBuffer i) const override
Definition socket.cc:762
bool m_dontFragment
DF bit value for outgoing packets.
Definition socket.h:1252
bool IsEnabled() const
Checks if the DF (Don't Fragment) flag is set.
Definition socket.cc:730
void Disable()
Disables the DF (Don't Fragment) flag.
Definition socket.cc:723
read and write tag data
Definition tag-buffer.h:41
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
Definition tag-buffer.h:161
TAG_BUFFER_INLINE uint8_t ReadU8()
Definition tag-buffer.h:185
tag a set of bytes in a packet
Definition tag.h:28
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
std::string GetName() const
Get the name.
Definition type-id.cc:1061
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
Callback< R, Args... > MakeNullCallback()
Definition callback.h:727
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:250
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.