A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-l4-protocol.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 Georgia Tech Research Corporation
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 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
18 */
19
20#ifndef TCP_L4_PROTOCOL_H
21#define TCP_L4_PROTOCOL_H
22
23#include "ip-l4-protocol.h"
24
25#include "ns3/ipv4-address.h"
26#include "ns3/ipv6-address.h"
27#include "ns3/sequence-number.h"
28
29#include <stdint.h>
30#include <unordered_map>
31
32namespace ns3
33{
34
35class Node;
36class Socket;
37class TcpHeader;
38class Ipv4EndPointDemux;
39class Ipv6EndPointDemux;
40class Ipv4Interface;
41class TcpSocketBase;
42class Ipv4EndPoint;
43class Ipv6EndPoint;
44class NetDevice;
45
81{
82 public:
87 static TypeId GetTypeId();
88 static const uint8_t PROT_NUMBER;
89
91 ~TcpL4Protocol() override;
92
93 // Delete copy constructor and assignment operator to avoid misuse
94 TcpL4Protocol(const TcpL4Protocol&) = delete;
96
101 void SetNode(Ptr<Node> node);
102
103 // NOTE: API from here should not be removed, only added. Be backward-compatible!
104
112
124 Ptr<Socket> CreateSocket(TypeId congestionTypeId, TypeId recoveryTypeId);
125
134 Ptr<Socket> CreateSocket(TypeId congestionTypeId);
135
153 Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, uint16_t port);
161 Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
171 Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice,
172 Ipv4Address localAddress,
173 uint16_t localPort,
174 Ipv4Address peerAddress,
175 uint16_t peerPort);
193 Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, uint16_t port);
201 Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
211 Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice,
212 Ipv6Address localAddress,
213 uint16_t localPort,
214 Ipv6Address peerAddress,
215 uint16_t peerPort);
216
226 void SendPacket(Ptr<Packet> pkt,
227 const TcpHeader& outgoing,
228 const Address& saddr,
229 const Address& daddr,
230 Ptr<NetDevice> oif = nullptr) const;
231
239 void AddSocket(Ptr<TcpSocketBase> socket);
240
247 bool RemoveSocket(Ptr<TcpSocketBase> socket);
248
253 void DeAllocate(Ipv4EndPoint* endPoint);
258 void DeAllocate(Ipv6EndPoint* endPoint);
259
260 // From IpL4Protocol
262 const Ipv4Header& incomingIpHeader,
263 Ptr<Ipv4Interface> incomingInterface) override;
265 const Ipv6Header& incomingIpHeader,
266 Ptr<Ipv6Interface> incomingInterface) override;
267
268 void ReceiveIcmp(Ipv4Address icmpSource,
269 uint8_t icmpTtl,
270 uint8_t icmpType,
271 uint8_t icmpCode,
272 uint32_t icmpInfo,
273 Ipv4Address payloadSource,
274 Ipv4Address payloadDestination,
275 const uint8_t payload[8]) override;
276 void ReceiveIcmp(Ipv6Address icmpSource,
277 uint8_t icmpTtl,
278 uint8_t icmpType,
279 uint8_t icmpCode,
280 uint32_t icmpInfo,
281 Ipv6Address payloadSource,
282 Ipv6Address payloadDestination,
283 const uint8_t payload[8]) override;
284
287 int GetProtocolNumber() const override;
290
291 protected:
292 void DoDispose() override;
293
303 void NotifyNewAggregate() override;
304
316 TcpHeader& incomingTcpHeader,
317 const Address& source,
318 const Address& destination);
319
333 void NoEndPointsFound(const TcpHeader& incomingHeader,
334 const Address& incomingSAddr,
335 const Address& incomingDAddr);
336
337 private:
344 std::unordered_map<uint64_t, Ptr<TcpSocketBase>>
346 uint64_t m_socketIndex{0};
349
359 void SendPacketV4(Ptr<Packet> pkt,
360 const TcpHeader& outgoing,
361 const Ipv4Address& saddr,
362 const Ipv4Address& daddr,
363 Ptr<NetDevice> oif = nullptr) const;
364
374 void SendPacketV6(Ptr<Packet> pkt,
375 const TcpHeader& outgoing,
376 const Ipv6Address& saddr,
377 const Ipv6Address& daddr,
378 Ptr<NetDevice> oif = nullptr) const;
379};
380
381} // namespace ns3
382
383#endif /* TCP_L4_PROTOCOL_H */
a polymophic address class
Definition: address.h:100
L4 Protocol abstract base class.
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Demultiplexes packets to various transport layer endpoints.
A representation of an internet endpoint/connection.
Packet header for IPv4.
Definition: ipv4-header.h:34
Describes an IPv6 address.
Definition: ipv6-address.h:49
Demultiplexer for end points.
A representation of an IPv6 endpoint/connection.
Packet header for IPv6.
Definition: ipv6-header.h:35
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Header for the Transmission Control Protocol.
Definition: tcp-header.h:46
TCP socket creation and multiplexing/demultiplexing.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
TcpL4Protocol(const TcpL4Protocol &)=delete
void SendPacketV4(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv4Address &saddr, const Ipv4Address &daddr, Ptr< NetDevice > oif=nullptr) const
Send a packet via TCP (IPv4)
void NoEndPointsFound(const TcpHeader &incomingHeader, const Address &incomingSAddr, const Address &incomingDAddr)
Check if RST packet should be sent, and in case, send it.
bool RemoveSocket(Ptr< TcpSocketBase > socket)
Remove a socket from the internal list.
TypeId m_congestionTypeId
The socket TypeId.
IpL4Protocol::RxStatus PacketReceived(Ptr< Packet > packet, TcpHeader &incomingTcpHeader, const Address &source, const Address &destination)
Get the tcp header of the incoming packet and checks its checksum if needed.
TypeId m_recoveryTypeId
The recovery TypeId.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
void DoDispose() override
Destructor implementation.
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
Ptr< Node > m_node
the node this stack is associated with
static TypeId GetTypeId()
Get the type ID.
void NotifyNewAggregate() override
Setup socket factory and callbacks when aggregated to a node.
Ipv6EndPoint * Allocate6()
Allocate an IPv6 Endpoint.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
void ReceiveIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo, Ipv4Address payloadSource, Ipv4Address payloadDestination, const uint8_t payload[8]) override
Called from lower-level layers to send the ICMP packet up in the stack.
IpL4Protocol::DownTargetCallback GetDownTarget() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
static const uint8_t PROT_NUMBER
protocol number (0x6)
std::unordered_map< uint64_t, Ptr< TcpSocketBase > > m_sockets
Unordered map of socket IDs and corresponding sockets.
void SetDownTarget(IpL4Protocol::DownTargetCallback cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
Ptr< Socket > CreateSocket()
Create a TCP socket using the TypeId set by SocketType attribute.
void SendPacketV6(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv6Address &saddr, const Ipv6Address &daddr, Ptr< NetDevice > oif=nullptr) const
Send a packet via TCP (IPv6)
TcpL4Protocol & operator=(const TcpL4Protocol &)=delete
uint64_t m_socketIndex
index of the next socket to be created
IpL4Protocol::DownTargetCallback6 GetDownTarget6() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
void SendPacket(Ptr< Packet > pkt, const TcpHeader &outgoing, const Address &saddr, const Address &daddr, Ptr< NetDevice > oif=nullptr) const
Send a packet via TCP (IP-agnostic)
void AddSocket(Ptr< TcpSocketBase > socket)
Make a socket fully operational.
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
IpL4Protocol::RxStatus Receive(Ptr< Packet > p, const Ipv4Header &incomingIpHeader, Ptr< Ipv4Interface > incomingInterface) override
Called from lower-level layers to send the packet up in the stack.
Ipv4EndPoint * Allocate()
Allocate an IPv4 Endpoint.
int GetProtocolNumber() const override
Returns the protocol number of this protocol.
TypeId m_rttTypeId
The RTT Estimator TypeId.
a unique identifier for an interface.
Definition: type-id.h:59
uint16_t port
Definition: dsdv-manet.cc:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.