A Discrete-Event Network Simulator
API
tcp-option-sack-permitted.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Adrian Sai-wah Tam
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  * Original Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
19  * Documentation, test cases: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
20  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
21  * The University of Kansas
22  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
23  */
24 
26 #include "ns3/log.h"
27 #include "ns3/tcp-header.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("TcpOptionSackPermitted");
32 
33 NS_OBJECT_ENSURE_REGISTERED (TcpOptionSackPermitted);
34 
36  : TcpOption ()
37 {
38 }
39 
41 {
42 }
43 
44 TypeId
46 {
47  static TypeId tid = TypeId ("ns3::TcpOptionSackPermitted")
48  .SetParent<TcpOption> ()
49  .SetGroupName ("Internet")
50  .AddConstructor<TcpOptionSackPermitted> ()
51  ;
52  return tid;
53 }
54 
55 TypeId
57 {
58  return GetTypeId ();
59 }
60 
61 void
62 TcpOptionSackPermitted::Print (std::ostream &os) const
63 {
64  os << "[sack_perm]";
65 }
66 
67 uint32_t
69 {
70  return 2;
71 }
72 
73 void
75 {
77  i.WriteU8 (GetKind ()); // Kind
78  i.WriteU8 (2); // Length
79 }
80 
81 uint32_t
83 {
85 
86  uint8_t readKind = i.ReadU8 ();
87  if (readKind != GetKind ())
88  {
89  NS_LOG_WARN ("Malformed Sack-Permitted option");
90  return 0;
91  }
92 
93  uint8_t size = i.ReadU8 ();
94  if (size != 2)
95  {
96  NS_LOG_WARN ("Malformed Sack-Permitted option");
97  return 0;
98  }
99  return GetSerializedSize ();
100 }
101 
102 uint8_t
104 {
106 }
107 
108 } // namespace ns3
virtual void Print(std::ostream &os) const
Print the Option contents.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
def start()
Definition: core.py:1855
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
iterator in a Buffer instance
Definition: buffer.h:98
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
Defines the TCP option of kind 4 (selective acknowledgment permitted option) as in RFC 2018 ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
void WriteU8(uint8_t data)
Definition: buffer.h:869
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:264
virtual uint8_t GetKind(void) const
Get the ‘kind’ (as in RFC 793) of this option.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
uint8_t ReadU8(void)
Definition: buffer.h:1021
Base class for all kinds of TCP options.
Definition: tcp-option.h:36
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.