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 namespace ns3 {
31
32 NS_LOG_COMPONENT_DEFINE ("Socket");
33
34 NS_OBJECT_ENSURE_REGISTERED (Socket);
35
36 TypeId
GetTypeId(void)37 Socket::GetTypeId (void)
38 {
39 static TypeId tid = TypeId ("ns3::Socket")
40 .SetParent<Object> ()
41 .SetGroupName("Network");
42 return tid;
43 }
44
Socket(void)45 Socket::Socket (void)
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 {
54 NS_LOG_FUNCTION_NOARGS ();
55 m_boundnetdevice = 0;
56 m_recvPktInfo = false;
57
58 m_priority = 0;
59 m_ipTos = 0;
60 m_ipTtl = 0;
61 m_ipv6Tclass = 0;
62 m_ipv6HopLimit = 0;
63 }
64
~Socket()65 Socket::~Socket ()
66 {
67 NS_LOG_FUNCTION (this);
68 }
69
70 Ptr<Socket>
CreateSocket(Ptr<Node> node,TypeId tid)71 Socket::CreateSocket (Ptr<Node> node, TypeId tid)
72 {
73 NS_LOG_FUNCTION (node << tid);
74 Ptr<Socket> s;
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
83 void
SetConnectCallback(Callback<void,Ptr<Socket>> connectionSucceeded,Callback<void,Ptr<Socket>> connectionFailed)84 Socket::SetConnectCallback (
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
93 void
SetCloseCallbacks(Callback<void,Ptr<Socket>> normalClose,Callback<void,Ptr<Socket>> errorClose)94 Socket::SetCloseCallbacks (
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
103 void
SetAcceptCallback(Callback<bool,Ptr<Socket>,const Address &> connectionRequest,Callback<void,Ptr<Socket>,const Address &> newConnectionCreated)104 Socket::SetAcceptCallback (
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
113 void
SetDataSentCallback(Callback<void,Ptr<Socket>,uint32_t> dataSent)114 Socket::SetDataSentCallback (Callback<void, Ptr<Socket>, uint32_t> dataSent)
115 {
116 NS_LOG_FUNCTION (this << &dataSent);
117 m_dataSent = dataSent;
118 }
119
120 void
SetSendCallback(Callback<void,Ptr<Socket>,uint32_t> sendCb)121 Socket::SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> sendCb)
122 {
123 NS_LOG_FUNCTION (this << &sendCb);
124 m_sendCb = sendCb;
125 }
126
127 void
SetRecvCallback(Callback<void,Ptr<Socket>> receivedData)128 Socket::SetRecvCallback (Callback<void, Ptr<Socket> > receivedData)
129 {
130 NS_LOG_FUNCTION (this << &receivedData);
131 m_receivedData = receivedData;
132 }
133
134 int
Send(Ptr<Packet> p)135 Socket::Send (Ptr<Packet> p)
136 {
137 NS_LOG_FUNCTION (this << p);
138 return Send (p, 0);
139 }
140
141 int
Send(const uint8_t * buf,uint32_t size,uint32_t flags)142 Socket::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
157 int
SendTo(const uint8_t * buf,uint32_t size,uint32_t flags,const Address & toAddress)158 Socket::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
174 Ptr<Packet>
Recv(void)175 Socket::Recv (void)
176 {
177 NS_LOG_FUNCTION (this);
178 return Recv (std::numeric_limits<uint32_t>::max (), 0);
179 }
180
181 int
Recv(uint8_t * buf,uint32_t size,uint32_t flags)182 Socket::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
194 Ptr<Packet>
RecvFrom(Address & fromAddress)195 Socket::RecvFrom (Address &fromAddress)
196 {
197 NS_LOG_FUNCTION (this << &fromAddress);
198 return RecvFrom (std::numeric_limits<uint32_t>::max (), 0, fromAddress);
199 }
200
201 int
RecvFrom(uint8_t * buf,uint32_t size,uint32_t flags,Address & fromAddress)202 Socket::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
216 void
NotifyConnectionSucceeded(void)217 Socket::NotifyConnectionSucceeded (void)
218 {
219 NS_LOG_FUNCTION (this);
220 if (!m_connectionSucceeded.IsNull ())
221 {
222 m_connectionSucceeded (this);
223 }
224 }
225
226 void
NotifyConnectionFailed(void)227 Socket::NotifyConnectionFailed (void)
228 {
229 NS_LOG_FUNCTION (this);
230 if (!m_connectionFailed.IsNull ())
231 {
232 m_connectionFailed (this);
233 }
234 }
235
236 void
NotifyNormalClose(void)237 Socket::NotifyNormalClose (void)
238 {
239 NS_LOG_FUNCTION (this);
240 if (!m_normalClose.IsNull ())
241 {
242 m_normalClose (this);
243 }
244 }
245
246 void
NotifyErrorClose(void)247 Socket::NotifyErrorClose (void)
248 {
249 NS_LOG_FUNCTION (this);
250 if (!m_errorClose.IsNull ())
251 {
252 m_errorClose (this);
253 }
254 }
255
256 bool
NotifyConnectionRequest(const Address & from)257 Socket::NotifyConnectionRequest (const Address &from)
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
274 void
NotifyNewConnectionCreated(Ptr<Socket> socket,const Address & from)275 Socket::NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from)
276 {
277 NS_LOG_FUNCTION (this << socket << from);
278 if (!m_newConnectionCreated.IsNull ())
279 {
280 m_newConnectionCreated (socket, from);
281 }
282 }
283
284 void
NotifyDataSent(uint32_t size)285 Socket::NotifyDataSent (uint32_t size)
286 {
287 NS_LOG_FUNCTION (this << size);
288 if (!m_dataSent.IsNull ())
289 {
290 m_dataSent (this, size);
291 }
292 }
293
294 void
NotifySend(uint32_t spaceAvailable)295 Socket::NotifySend (uint32_t spaceAvailable)
296 {
297 NS_LOG_FUNCTION (this << spaceAvailable);
298 if (!m_sendCb.IsNull ())
299 {
300 m_sendCb (this, spaceAvailable);
301 }
302 }
303
304 void
NotifyDataRecv(void)305 Socket::NotifyDataRecv (void)
306 {
307 NS_LOG_FUNCTION (this);
308 if (!m_receivedData.IsNull ())
309 {
310 m_receivedData (this);
311 }
312 }
313
314 void
DoDispose(void)315 Socket::DoDispose (void)
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
329 void
BindToNetDevice(Ptr<NetDevice> netdevice)330 Socket::BindToNetDevice (Ptr<NetDevice> netdevice)
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
350 Ptr<NetDevice>
GetBoundNetDevice()351 Socket::GetBoundNetDevice ()
352 {
353 NS_LOG_FUNCTION (this);
354 return m_boundnetdevice;
355 }
356
357 void
SetRecvPktInfo(bool flag)358 Socket::SetRecvPktInfo (bool flag)
359 {
360 NS_LOG_FUNCTION (this << flag);
361 m_recvPktInfo = flag;
362 }
363
IsRecvPktInfo() const364 bool Socket::IsRecvPktInfo () const
365 {
366 NS_LOG_FUNCTION (this);
367 return m_recvPktInfo;
368 }
369
370 bool
IsManualIpv6Tclass(void) const371 Socket::IsManualIpv6Tclass (void) const
372 {
373 return m_manualIpv6Tclass;
374 }
375
376 bool
IsManualIpTtl(void) const377 Socket::IsManualIpTtl (void) const
378 {
379 return m_manualIpTtl;
380 }
381
382 bool
IsManualIpv6HopLimit(void) const383 Socket::IsManualIpv6HopLimit (void) const
384 {
385 return m_manualIpv6HopLimit;
386 }
387
388 void
SetPriority(uint8_t priority)389 Socket::SetPriority (uint8_t priority)
390 {
391 NS_LOG_FUNCTION (this << priority);
392 m_priority = priority;
393 }
394
395 uint8_t
GetPriority(void) const396 Socket::GetPriority (void) const
397 {
398 return m_priority;
399 }
400
401 uint8_t
IpTos2Priority(uint8_t ipTos)402 Socket::IpTos2Priority (uint8_t ipTos)
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:
424 prio = NS3_PRIO_INTERACTIVE;
425 break;
426 case 12:
427 case 13:
428 case 14:
429 case 15:
430 prio = NS3_PRIO_INTERACTIVE_BULK;
431 break;
432 }
433 return prio;
434 }
435
436 void
SetIpTos(uint8_t tos)437 Socket::SetIpTos (uint8_t tos)
438 {
439 Address address;
440 GetSockName (address);
441 if (GetSocketType () == NS3_SOCK_STREAM)
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;
449 m_priority = IpTos2Priority (tos);
450 }
451
452 uint8_t
GetIpTos(void) const453 Socket::GetIpTos (void) const
454 {
455 return m_ipTos;
456 }
457
458 void
SetIpRecvTos(bool ipv4RecvTos)459 Socket::SetIpRecvTos (bool ipv4RecvTos)
460 {
461 m_ipRecvTos = ipv4RecvTos;
462 }
463
464 bool
IsIpRecvTos(void) const465 Socket::IsIpRecvTos (void) const
466 {
467 return m_ipRecvTos;
468 }
469
470 void
SetIpv6Tclass(int tclass)471 Socket::SetIpv6Tclass (int tclass)
472 {
473 Address address;
474 GetSockName (address);
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
494 uint8_t
GetIpv6Tclass(void) const495 Socket::GetIpv6Tclass (void) const
496 {
497 return m_ipv6Tclass;
498 }
499
500 void
SetIpv6RecvTclass(bool ipv6RecvTclass)501 Socket::SetIpv6RecvTclass (bool ipv6RecvTclass)
502 {
503 m_ipv6RecvTclass = ipv6RecvTclass;
504 }
505
506 bool
IsIpv6RecvTclass(void) const507 Socket::IsIpv6RecvTclass (void) const
508 {
509 return m_ipv6RecvTclass;
510 }
511
512 void
SetIpTtl(uint8_t ttl)513 Socket::SetIpTtl (uint8_t ttl)
514 {
515 m_manualIpTtl = true;
516 m_ipTtl = ttl;
517 }
518
519 uint8_t
GetIpTtl(void) const520 Socket::GetIpTtl (void) const
521 {
522 return m_ipTtl;
523 }
524
525 void
SetIpRecvTtl(bool ipv4RecvTtl)526 Socket::SetIpRecvTtl (bool ipv4RecvTtl)
527 {
528 m_ipRecvTtl = ipv4RecvTtl;
529 }
530
531 bool
IsIpRecvTtl(void) const532 Socket::IsIpRecvTtl (void) const
533 {
534 return m_ipRecvTtl;
535 }
536
537 void
SetIpv6HopLimit(uint8_t ipHopLimit)538 Socket::SetIpv6HopLimit (uint8_t ipHopLimit)
539 {
540 m_manualIpv6HopLimit = true;
541 m_ipv6HopLimit = ipHopLimit;
542 }
543
544 uint8_t
GetIpv6HopLimit(void) const545 Socket::GetIpv6HopLimit (void) const
546 {
547 return m_ipv6HopLimit;
548 }
549
550 void
SetIpv6RecvHopLimit(bool ipv6RecvHopLimit)551 Socket::SetIpv6RecvHopLimit (bool ipv6RecvHopLimit)
552 {
553 m_ipv6RecvHopLimit = ipv6RecvHopLimit;
554 }
555
556 bool
IsIpv6RecvHopLimit(void) const557 Socket::IsIpv6RecvHopLimit (void) const
558 {
559 return m_ipv6RecvHopLimit;
560 }
561
562 void
Ipv6JoinGroup(Ipv6Address address,Ipv6MulticastFilterMode filterMode,std::vector<Ipv6Address> sourceAddresses)563 Socket::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
569 void
Ipv6JoinGroup(Ipv6Address address)570 Socket::Ipv6JoinGroup (Ipv6Address address)
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
579 void
Ipv6LeaveGroup(void)580 Socket::Ipv6LeaveGroup (void)
581 {
582 NS_LOG_FUNCTION (this);
583 if(m_ipv6MulticastGroupAddress.IsAny () )
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;
590 Ipv6JoinGroup (m_ipv6MulticastGroupAddress, INCLUDE, sourceAddresses);
591 m_ipv6MulticastGroupAddress = Ipv6Address::GetAny ();
592 }
593
594 /***************************************************************
595 * Socket Tags
596 ***************************************************************/
597
SocketIpTtlTag()598 SocketIpTtlTag::SocketIpTtlTag ()
599 {
600 NS_LOG_FUNCTION (this);
601 }
602
603 void
SetTtl(uint8_t ttl)604 SocketIpTtlTag::SetTtl (uint8_t ttl)
605 {
606 NS_LOG_FUNCTION (this << static_cast<uint32_t> (ttl));
607 m_ttl = ttl;
608 }
609
610 uint8_t
GetTtl(void) const611 SocketIpTtlTag::GetTtl (void) const
612 {
613 NS_LOG_FUNCTION (this);
614 return m_ttl;
615 }
616
617 NS_OBJECT_ENSURE_REGISTERED (SocketIpTtlTag);
618
619 TypeId
GetTypeId(void)620 SocketIpTtlTag::GetTypeId (void)
621 {
622 static TypeId tid = TypeId ("ns3::SocketIpTtlTag")
623 .SetParent<Tag> ()
624 .SetGroupName("Network")
625 .AddConstructor<SocketIpTtlTag> ()
626 ;
627 return tid;
628 }
629 TypeId
GetInstanceTypeId(void) const630 SocketIpTtlTag::GetInstanceTypeId (void) const
631 {
632 return GetTypeId ();
633 }
634
635 uint32_t
GetSerializedSize(void) const636 SocketIpTtlTag::GetSerializedSize (void) const
637 {
638 NS_LOG_FUNCTION (this);
639 return 1;
640 }
641 void
Serialize(TagBuffer i) const642 SocketIpTtlTag::Serialize (TagBuffer i) const
643 {
644 NS_LOG_FUNCTION (this << &i);
645 i.WriteU8 (m_ttl);
646 }
647 void
Deserialize(TagBuffer i)648 SocketIpTtlTag::Deserialize (TagBuffer i)
649 {
650 NS_LOG_FUNCTION (this << &i);
651 m_ttl = i.ReadU8 ();
652 }
653 void
Print(std::ostream & os) const654 SocketIpTtlTag::Print (std::ostream &os) const
655 {
656 NS_LOG_FUNCTION (this << &os);
657 os << "Ttl=" << (uint32_t) m_ttl;
658 }
659
SocketIpv6HopLimitTag()660 SocketIpv6HopLimitTag::SocketIpv6HopLimitTag ()
661 {
662 }
663
664 void
SetHopLimit(uint8_t hopLimit)665 SocketIpv6HopLimitTag::SetHopLimit (uint8_t hopLimit)
666 {
667 m_hopLimit = hopLimit;
668 }
669
670 uint8_t
GetHopLimit(void) const671 SocketIpv6HopLimitTag::GetHopLimit (void) const
672 {
673 return m_hopLimit;
674 }
675
676 NS_OBJECT_ENSURE_REGISTERED (SocketIpv6HopLimitTag);
677
678 TypeId
GetTypeId(void)679 SocketIpv6HopLimitTag::GetTypeId (void)
680 {
681 static TypeId tid = TypeId ("ns3::SocketIpv6HopLimitTag")
682 .SetParent<Tag> ()
683 .SetGroupName("Network")
684 .AddConstructor<SocketIpv6HopLimitTag> ()
685 ;
686 return tid;
687 }
688 TypeId
GetInstanceTypeId(void) const689 SocketIpv6HopLimitTag::GetInstanceTypeId (void) const
690 {
691 return GetTypeId ();
692 }
693
694 uint32_t
GetSerializedSize(void) const695 SocketIpv6HopLimitTag::GetSerializedSize (void) const
696 {
697 return 1;
698 }
699 void
Serialize(TagBuffer i) const700 SocketIpv6HopLimitTag::Serialize (TagBuffer i) const
701 {
702 i.WriteU8 (m_hopLimit);
703 }
704 void
Deserialize(TagBuffer i)705 SocketIpv6HopLimitTag::Deserialize (TagBuffer i)
706 {
707 m_hopLimit = i.ReadU8 ();
708 }
709 void
Print(std::ostream & os) const710 SocketIpv6HopLimitTag::Print (std::ostream &os) const
711 {
712 os << "HopLimit=" << (uint32_t) m_hopLimit;
713 }
714
SocketSetDontFragmentTag()715 SocketSetDontFragmentTag::SocketSetDontFragmentTag ()
716 {
717 NS_LOG_FUNCTION (this);
718 }
719 void
Enable(void)720 SocketSetDontFragmentTag::Enable (void)
721 {
722 NS_LOG_FUNCTION (this);
723 m_dontFragment = true;
724 }
725 void
Disable(void)726 SocketSetDontFragmentTag::Disable (void)
727 {
728 NS_LOG_FUNCTION (this);
729 m_dontFragment = false;
730 }
731 bool
IsEnabled(void) const732 SocketSetDontFragmentTag::IsEnabled (void) const
733 {
734 NS_LOG_FUNCTION (this);
735 return m_dontFragment;
736 }
737
738 NS_OBJECT_ENSURE_REGISTERED (SocketSetDontFragmentTag);
739
740 TypeId
GetTypeId(void)741 SocketSetDontFragmentTag::GetTypeId (void)
742 {
743 static TypeId tid = TypeId ("ns3::SocketSetDontFragmentTag")
744 .SetParent<Tag> ()
745 .SetGroupName("Network")
746 .AddConstructor<SocketSetDontFragmentTag> ();
747 return tid;
748 }
749 TypeId
GetInstanceTypeId(void) const750 SocketSetDontFragmentTag::GetInstanceTypeId (void) const
751 {
752 return GetTypeId ();
753 }
754 uint32_t
GetSerializedSize(void) const755 SocketSetDontFragmentTag::GetSerializedSize (void) const
756 {
757 NS_LOG_FUNCTION (this);
758 return 1;
759 }
760 void
Serialize(TagBuffer i) const761 SocketSetDontFragmentTag::Serialize (TagBuffer i) const
762 {
763 NS_LOG_FUNCTION (this << &i);
764 i.WriteU8 (m_dontFragment ? 1 : 0);
765 }
766 void
Deserialize(TagBuffer i)767 SocketSetDontFragmentTag::Deserialize (TagBuffer i)
768 {
769 NS_LOG_FUNCTION (this << &i);
770 m_dontFragment = (i.ReadU8 () == 1) ? true : false;
771 }
772 void
Print(std::ostream & os) const773 SocketSetDontFragmentTag::Print (std::ostream &os) const
774 {
775 NS_LOG_FUNCTION (this << &os);
776 os << (m_dontFragment ? "true" : "false");
777 }
778
779
SocketIpTosTag()780 SocketIpTosTag::SocketIpTosTag ()
781 {
782 }
783
784 void
SetTos(uint8_t ipTos)785 SocketIpTosTag::SetTos (uint8_t ipTos)
786 {
787 m_ipTos = ipTos;
788 }
789
790 uint8_t
GetTos(void) const791 SocketIpTosTag::GetTos (void) const
792 {
793 return m_ipTos;
794 }
795
796 TypeId
GetTypeId(void)797 SocketIpTosTag::GetTypeId (void)
798 {
799 static TypeId tid = TypeId ("ns3::SocketIpTosTag")
800 .SetParent<Tag> ()
801 .SetGroupName("Network")
802 .AddConstructor<SocketIpTosTag> ()
803 ;
804 return tid;
805 }
806
807 TypeId
GetInstanceTypeId(void) const808 SocketIpTosTag::GetInstanceTypeId (void) const
809 {
810 return GetTypeId ();
811 }
812
813 uint32_t
GetSerializedSize(void) const814 SocketIpTosTag::GetSerializedSize (void) const
815 {
816 return sizeof (uint8_t);
817 }
818
819 void
Serialize(TagBuffer i) const820 SocketIpTosTag::Serialize (TagBuffer i) const
821 {
822 i.WriteU8 (m_ipTos);
823 }
824
825 void
Deserialize(TagBuffer i)826 SocketIpTosTag::Deserialize (TagBuffer i)
827 {
828 m_ipTos = i.ReadU8();
829 }
830 void
Print(std::ostream & os) const831 SocketIpTosTag::Print (std::ostream &os) const
832 {
833 os << "IP_TOS = " << m_ipTos;
834 }
835
836
SocketPriorityTag()837 SocketPriorityTag::SocketPriorityTag ()
838 {
839 }
840
841 void
SetPriority(uint8_t priority)842 SocketPriorityTag::SetPriority (uint8_t priority)
843 {
844 m_priority = priority;
845 }
846
847 uint8_t
GetPriority(void) const848 SocketPriorityTag::GetPriority (void) const
849 {
850 return m_priority;
851 }
852
853 TypeId
GetTypeId(void)854 SocketPriorityTag::GetTypeId (void)
855 {
856 static TypeId tid = TypeId ("ns3::SocketPriorityTag")
857 .SetParent<Tag> ()
858 .SetGroupName("Network")
859 .AddConstructor<SocketPriorityTag> ()
860 ;
861 return tid;
862 }
863
864 TypeId
GetInstanceTypeId(void) const865 SocketPriorityTag::GetInstanceTypeId (void) const
866 {
867 return GetTypeId ();
868 }
869
870 uint32_t
GetSerializedSize(void) const871 SocketPriorityTag::GetSerializedSize (void) const
872 {
873 return sizeof (uint8_t);
874 }
875
876 void
Serialize(TagBuffer i) const877 SocketPriorityTag::Serialize (TagBuffer i) const
878 {
879 i.WriteU8 (m_priority);
880 }
881
882 void
Deserialize(TagBuffer i)883 SocketPriorityTag::Deserialize (TagBuffer i)
884 {
885 m_priority = i.ReadU8();
886 }
887
888 void
Print(std::ostream & os) const889 SocketPriorityTag::Print (std::ostream &os) const
890 {
891 os << "SO_PRIORITY = " << m_priority;
892 }
893
894
SocketIpv6TclassTag()895 SocketIpv6TclassTag::SocketIpv6TclassTag ()
896 {
897 }
898
899 void
SetTclass(uint8_t tclass)900 SocketIpv6TclassTag::SetTclass (uint8_t tclass)
901 {
902 m_ipv6Tclass = tclass;
903 }
904
905 uint8_t
GetTclass(void) const906 SocketIpv6TclassTag::GetTclass (void) const
907 {
908 return m_ipv6Tclass;
909 }
910
911 TypeId
GetTypeId(void)912 SocketIpv6TclassTag::GetTypeId (void)
913 {
914 static TypeId tid = TypeId ("ns3::SocketIpv6TclassTag")
915 .SetParent<Tag> ()
916 .SetGroupName("Network")
917 .AddConstructor<SocketIpv6TclassTag> ()
918 ;
919 return tid;
920 }
921
922 TypeId
GetInstanceTypeId(void) const923 SocketIpv6TclassTag::GetInstanceTypeId (void) const
924 {
925 return GetTypeId ();
926 }
927
928 uint32_t
GetSerializedSize(void) const929 SocketIpv6TclassTag::GetSerializedSize (void) const
930 {
931 return sizeof (uint8_t);
932 }
933
934 void
Serialize(TagBuffer i) const935 SocketIpv6TclassTag::Serialize (TagBuffer i) const
936 {
937 i.WriteU8 (m_ipv6Tclass);
938 }
939
940 void
Deserialize(TagBuffer i)941 SocketIpv6TclassTag::Deserialize (TagBuffer i)
942 {
943 m_ipv6Tclass = i.ReadU8();
944 }
945 void
Print(std::ostream & os) const946 SocketIpv6TclassTag::Print (std::ostream &os) const
947 {
948 os << "IPV6_TCLASS = " << m_ipv6Tclass;
949 }
950
951 } // namespace ns3
952