A Discrete-Event Network Simulator
API
tcp-error-model.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
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  */
19 #ifndef TCPERRORCHANNEL_H
20 #define TCPERRORCHANNEL_H
21 
22 #include "ns3/error-model.h"
23 #include "ns3/tcp-header.h"
24 #include "ns3/ipv4-header.h"
25 
26 namespace ns3 {
27 
39 {
40 public:
45  static TypeId GetTypeId (void);
47 
53  {
54  m_dropCallback = cb;
55  }
56 
57 protected:
65  virtual bool ShouldDrop (const Ipv4Header &ipHeader, const TcpHeader &tcpHeader,
66  uint32_t packetSize) = 0;
67 
68 
69 private:
70  virtual bool DoCorrupt (Ptr<Packet> p);
72 };
73 
83 {
84 public:
89  static TypeId GetTypeId (void);
91 
100  void AddSeqToKill (const SequenceNumber32 &seq)
101  {
102  m_seqToKill.insert(m_seqToKill.end(), seq);
103  }
104 
105 protected:
106  virtual bool ShouldDrop (const Ipv4Header &ipHeader, const TcpHeader &tcpHeader,
107  uint32_t packetSize);
108 
109 protected:
110  std::list<SequenceNumber32> m_seqToKill;
111 
112 private:
113  virtual void DoReset (void);
114 };
115 
130 {
131 public:
136  static TypeId GetTypeId (void);
138 
145  {
146  m_flagsToKill = flags;
147  }
148 
160  void SetKillRepeat (int16_t killNumber)
161  {
162  m_killNumber = killNumber;
163  }
164 
165 protected:
166  virtual bool ShouldDrop (const Ipv4Header &ipHeader, const TcpHeader &tcpHeader,
167  uint32_t packetSize);
168 
169 protected:
171  int16_t m_killNumber;
172 
173 private:
174  virtual void DoReset (void);
175 };
176 
177 } // namespace ns3
178 
179 #endif // TCPERRORCHANNEL_H
virtual void DoReset(void)
Re-initialize any state.
static TypeId GetTypeId(void)
Get the type ID.
Callback template class.
Definition: callback.h:1176
void SetDropCallback(Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > cb)
Set the drop callback.
A general (TCP-aware) error model.
General error model that can be used to corrupt packets.
Definition: error-model.h:115
An error model TCP aware: it drops the sequence number declared.
Packet header for IPv4.
Definition: ipv4-header.h:33
TcpHeader::Flags_t m_flagsToKill
Flags a packet should have to be dropped.
void SetKillRepeat(int16_t killNumber)
Set how many packets should be killed.
static TypeId GetTypeId(void)
Get the type ID.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
virtual bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize)
Check if the packet should be dropped.
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
Flags_t
TCP flag field values.
Definition: tcp-header.h:279
std::list< SequenceNumber32 > m_seqToKill
List of the sequence numbers to be dropped.
int16_t m_killNumber
The number of times the packet should be killed.
static TypeId GetTypeId(void)
Get the type ID.
Error model which drop packets with specified TCP flags.
virtual bool DoCorrupt(Ptr< Packet > p)
Corrupt a packet according to the specified model.
static const uint32_t packetSize
virtual bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize)
Check if the packet should be dropped.
virtual void DoReset(void)
Re-initialize any state.
a unique identifier for an interface.
Definition: type-id.h:58
Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > m_dropCallback
Drop callback.
void SetFlagToKill(TcpHeader::Flags_t flags)
Set the flags of the segment that should be killed.
virtual bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize)=0
Check if the packet should be dropped.