A Discrete-Event Network Simulator
API
tcp-error-model.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 #ifndef TCPERRORCHANNEL_H
19 #define TCPERRORCHANNEL_H
20 
21 #include "ns3/error-model.h"
22 #include "ns3/ipv4-header.h"
23 #include "ns3/tcp-header.h"
24 
25 namespace ns3
26 {
27 
38 {
39  public:
44  static TypeId GetTypeId();
46 
52  {
53  m_dropCallback = cb;
54  }
55 
56  protected:
64  virtual bool ShouldDrop(const Ipv4Header& ipHeader,
65  const TcpHeader& tcpHeader,
66  uint32_t packetSize) = 0;
67 
68  private:
69  bool DoCorrupt(Ptr<Packet> p) override;
72 };
73 
82 {
83  public:
88  static TypeId GetTypeId();
89 
92  {
93  }
94 
104  {
105  m_seqToKill.insert(m_seqToKill.end(), seq);
106  }
107 
108  protected:
109  bool ShouldDrop(const Ipv4Header& ipHeader,
110  const TcpHeader& tcpHeader,
111  uint32_t packetSize) override;
112 
113  protected:
114  std::list<SequenceNumber32> m_seqToKill;
115 
116  private:
117  void DoReset() override;
118 };
119 
133 {
134  public:
139  static TypeId GetTypeId();
141 
148  {
149  m_flagsToKill = flags;
150  }
151 
163  void SetKillRepeat(int16_t killNumber)
164  {
165  m_killNumber = killNumber;
166  }
167 
168  protected:
169  bool ShouldDrop(const Ipv4Header& ipHeader,
170  const TcpHeader& tcpHeader,
171  uint32_t packetSize) override;
172 
173  protected:
175  int16_t m_killNumber;
176 
177  private:
178  void DoReset() override;
179 };
180 
181 } // namespace ns3
182 
183 #endif // TCPERRORCHANNEL_H
Callback template class.
Definition: callback.h:438
General error model that can be used to corrupt packets.
Definition: error-model.h:117
Packet header for IPv4.
Definition: ipv4-header.h:34
Error model which drop packets with specified TCP flags.
TcpHeader::Flags_t m_flagsToKill
Flags a packet should have to be dropped.
void SetFlagToKill(TcpHeader::Flags_t flags)
Set the flags of the segment that should be killed.
bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize) override
Check if the packet should be dropped.
void DoReset() override
Re-initialize any state.
void SetKillRepeat(int16_t killNumber)
Set how many packets should be killed.
int16_t m_killNumber
The number of times the packet should be killed.
static TypeId GetTypeId()
Get the type ID.
A general (TCP-aware) error model.
bool DoCorrupt(Ptr< Packet > p) override
Corrupt a packet according to the specified model.
Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > m_dropCallback
Drop callback.
void SetDropCallback(Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet >> cb)
Set the drop callback.
virtual bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize)=0
Check if the packet should be dropped.
static TypeId GetTypeId()
Get the type ID.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
Flags_t
TCP flag field values.
Definition: tcp-header.h:277
An error model TCP aware: it drops the sequence number declared.
static TypeId GetTypeId()
Get the type ID.
bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize) override
Check if the packet should be dropped.
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
void DoReset() override
Re-initialize any state.
std::list< SequenceNumber32 > m_seqToKill
List of the sequence numbers to be dropped.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Packet size generated at the AP.