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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7#ifndef TCPERRORCHANNEL_H
8#define TCPERRORCHANNEL_H
9
10#include "ns3/error-model.h"
11#include "ns3/ipv4-header.h"
12#include "ns3/tcp-header.h"
13
14namespace ns3
15{
16
17/**
18 * @ingroup internet-test
19 *
20 * @brief A general (TCP-aware) error model.
21 *
22 * The class is responsible to take away the IP and TCP header from the packet,
23 * and then to interrogate the method ShouldDrop, dropping the packet accordingly
24 * to the returned value.
25 */
27{
28 public:
29 /**
30 * @brief Get the type ID.
31 * @return the object TypeId
32 */
33 static TypeId GetTypeId();
35
36 /**
37 * @brief Set the drop callback.
38 * @param cb The callback to be set.
39 */
41 {
42 m_dropCallback = cb;
43 }
44
45 protected:
46 /**
47 * @brief Check if the packet should be dropped.
48 * @param ipHeader The packet IPv4 header.
49 * @param tcpHeader The packet TCP header.
50 * @param packetSize The packet size.
51 * @returns True if the packet should be dropped.
52 */
53 virtual bool ShouldDrop(const Ipv4Header& ipHeader,
54 const TcpHeader& tcpHeader,
56
57 private:
58 bool DoCorrupt(Ptr<Packet> p) override;
60 m_dropCallback; //!< Drop callback.
61};
62
63/**
64 * @ingroup internet-test
65 *
66 * @brief An error model TCP aware: it drops the sequence number declared.
67 *
68 * @see AddSeqToKill
69 */
71{
72 public:
73 /**
74 * @brief Get the type ID.
75 * @return the object TypeId
76 */
77 static TypeId GetTypeId();
78
83
84 /**
85 * @brief Add the sequence number to the list of segments to be killed
86 *
87 * Calling x times this function indicates that you want to kill
88 * the segment x times.
89 *
90 * @param seq sequence number to be killed
91 */
93 {
94 m_seqToKill.insert(m_seqToKill.end(), seq);
95 }
96
97 protected:
98 bool ShouldDrop(const Ipv4Header& ipHeader,
99 const TcpHeader& tcpHeader,
100 uint32_t packetSize) override;
101
102 protected:
103 std::list<SequenceNumber32> m_seqToKill; //!< List of the sequence numbers to be dropped.
104
105 private:
106 void DoReset() override;
107};
108
109/**
110 * @ingroup internet-test
111 *
112 * @brief Error model which drop packets with specified TCP flags.
113 *
114 * Set the flags with SetFlagToKill and the number of the packets with such flags
115 * which should be killed.
116 *
117 * @see SetFlagToKill
118 * @see SetKillRepeat
119 *
120 */
122{
123 public:
124 /**
125 * @brief Get the type ID.
126 * @return the object TypeId
127 */
128 static TypeId GetTypeId();
130
131 /**
132 * @brief Set the flags of the segment that should be killed
133 *
134 * @param flags Flags
135 */
137 {
138 m_flagsToKill = flags;
139 }
140
141 /**
142 * @brief Set how many packets should be killed
143 *
144 * If the flags are the same, this specified the numbers of drops:
145 *
146 * # -1 for infinite drops
147 * # 0 for no drops
148 * # >1 the number of drops
149 *
150 * @param killNumber Specifies the number of times the packet should be killed
151 */
152 void SetKillRepeat(int16_t killNumber)
153 {
154 m_killNumber = killNumber;
155 }
156
157 protected:
158 bool ShouldDrop(const Ipv4Header& ipHeader,
159 const TcpHeader& tcpHeader,
160 uint32_t packetSize) override;
161
162 protected:
163 TcpHeader::Flags_t m_flagsToKill; //!< Flags a packet should have to be dropped.
164 int16_t m_killNumber; //!< The number of times the packet should be killed.
165
166 private:
167 void DoReset() override;
168};
169
170} // namespace ns3
171
172#endif // TCPERRORCHANNEL_H
Callback template class.
Definition callback.h:422
General error model that can be used to corrupt packets.
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
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:36
Flags_t
TCP flag field values.
Definition tcp-header.h:266
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:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t packetSize
Packet size generated at the AP.