A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
25namespace ns3
26{
27
28/**
29 * \ingroup internet-test
30 *
31 * \brief A general (TCP-aware) error model.
32 *
33 * The class is responsible to take away the IP and TCP header from the packet,
34 * and then to interrogate the method ShouldDrop, dropping the packet accordingly
35 * to the returned value.
36 */
38{
39 public:
40 /**
41 * \brief Get the type ID.
42 * \return the object TypeId
43 */
44 static TypeId GetTypeId();
46
47 /**
48 * \brief Set the drop callback.
49 * \param cb The callback to be set.
50 */
52 {
53 m_dropCallback = cb;
54 }
55
56 protected:
57 /**
58 * \brief Check if the packet should be dropped.
59 * \param ipHeader The packet IPv4 header.
60 * \param tcpHeader The packet TCP header.
61 * \param packetSize The packet size.
62 * \returns True if the packet should be dropped.
63 */
64 virtual bool ShouldDrop(const Ipv4Header& ipHeader,
65 const TcpHeader& tcpHeader,
67
68 private:
69 bool DoCorrupt(Ptr<Packet> p) override;
71 m_dropCallback; //!< Drop callback.
72};
73
74/**
75 * \ingroup internet-test
76 *
77 * \brief An error model TCP aware: it drops the sequence number declared.
78 *
79 * \see AddSeqToKill
80 */
82{
83 public:
84 /**
85 * \brief Get the type ID.
86 * \return the object TypeId
87 */
88 static TypeId GetTypeId();
89
92 {
93 }
94
95 /**
96 * \brief Add the sequence number to the list of segments to be killed
97 *
98 * Calling x times this function indicates that you want to kill
99 * the segment x times.
100 *
101 * \param seq sequence number to be killed
102 */
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; //!< List of the sequence numbers to be dropped.
115
116 private:
117 void DoReset() override;
118};
119
120/**
121 * \ingroup internet-test
122 *
123 * \brief Error model which drop packets with specified TCP flags.
124 *
125 * Set the flags with SetFlagToKill and the number of the packets with such flags
126 * which should be killed.
127 *
128 * \see SetFlagToKill
129 * \see SetKillRepeat
130 *
131 */
133{
134 public:
135 /**
136 * \brief Get the type ID.
137 * \return the object TypeId
138 */
139 static TypeId GetTypeId();
141
142 /**
143 * \brief Set the flags of the segment that should be killed
144 *
145 * \param flags Flags
146 */
148 {
149 m_flagsToKill = flags;
150 }
151
152 /**
153 * \brief Set how many packets should be killed
154 *
155 * If the flags are the same, this specified the numbers of drops:
156 *
157 * # -1 for infinite drops
158 * # 0 for no drops
159 * # >1 the number of drops
160 *
161 * \param killNumber Specifies the number of times the packet should be killed
162 */
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:
174 TcpHeader::Flags_t m_flagsToKill; //!< Flags a packet should have to be dropped.
175 int16_t m_killNumber; //!< The number of times the packet should be killed.
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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.
void SetDropCallback(Callback< void, const Ipv4Header &, const TcpHeader &, Ptr< const Packet > > cb)
Set the drop callback.
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.
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.