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