A Discrete-Event Network Simulator
API
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 
31 namespace ns3
32 {
33 
34 class Node;
35 class Socket;
36 class TcpHeader;
37 class Ipv4EndPointDemux;
38 class Ipv6EndPointDemux;
39 class Ipv4Interface;
40 class TcpSocketBase;
41 class Ipv4EndPoint;
42 class Ipv6EndPoint;
43 class NetDevice;
44 
80 {
81  public:
86  static TypeId GetTypeId();
87  static const uint8_t PROT_NUMBER;
88 
89  TcpL4Protocol();
90  ~TcpL4Protocol() override;
91 
92  // Delete copy constructor and assignment operator to avoid misuse
93  TcpL4Protocol(const TcpL4Protocol&) = delete;
95 
100  void SetNode(Ptr<Node> node);
101 
102  // NOTE: API from here should not be removed, only added. Be backward-compatible!
103 
111 
123  Ptr<Socket> CreateSocket(TypeId congestionTypeId, TypeId recoveryTypeId);
124 
133  Ptr<Socket> CreateSocket(TypeId congestionTypeId);
134 
152  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, uint16_t port);
160  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
170  Ipv4EndPoint* Allocate(Ptr<NetDevice> boundNetDevice,
171  Ipv4Address localAddress,
172  uint16_t localPort,
173  Ipv4Address peerAddress,
174  uint16_t peerPort);
192  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, uint16_t port);
200  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
210  Ipv6EndPoint* Allocate6(Ptr<NetDevice> boundNetDevice,
211  Ipv6Address localAddress,
212  uint16_t localPort,
213  Ipv6Address peerAddress,
214  uint16_t peerPort);
215 
225  void SendPacket(Ptr<Packet> pkt,
226  const TcpHeader& outgoing,
227  const Address& saddr,
228  const Address& daddr,
229  Ptr<NetDevice> oif = nullptr) const;
230 
238  void AddSocket(Ptr<TcpSocketBase> socket);
239 
246  bool RemoveSocket(Ptr<TcpSocketBase> socket);
247 
252  void DeAllocate(Ipv4EndPoint* endPoint);
257  void DeAllocate(Ipv6EndPoint* endPoint);
258 
259  // From IpL4Protocol
261  const Ipv4Header& incomingIpHeader,
262  Ptr<Ipv4Interface> incomingInterface) override;
264  const Ipv6Header& incomingIpHeader,
265  Ptr<Ipv6Interface> incomingInterface) override;
266 
267  void ReceiveIcmp(Ipv4Address icmpSource,
268  uint8_t icmpTtl,
269  uint8_t icmpType,
270  uint8_t icmpCode,
271  uint32_t icmpInfo,
272  Ipv4Address payloadSource,
273  Ipv4Address payloadDestination,
274  const uint8_t payload[8]) override;
275  void ReceiveIcmp(Ipv6Address icmpSource,
276  uint8_t icmpTtl,
277  uint8_t icmpType,
278  uint8_t icmpCode,
279  uint32_t icmpInfo,
280  Ipv6Address payloadSource,
281  Ipv6Address payloadDestination,
282  const uint8_t payload[8]) override;
283 
286  int GetProtocolNumber() const override;
289 
290  protected:
291  void DoDispose() override;
292 
302  void NotifyNewAggregate() override;
303 
315  TcpHeader& incomingTcpHeader,
316  const Address& source,
317  const Address& destination);
318 
332  void NoEndPointsFound(const TcpHeader& incomingHeader,
333  const Address& incomingSAddr,
334  const Address& incomingDAddr);
335 
336  private:
343  std::vector<Ptr<TcpSocketBase>> m_sockets;
346 
356  void SendPacketV4(Ptr<Packet> pkt,
357  const TcpHeader& outgoing,
358  const Ipv4Address& saddr,
359  const Ipv4Address& daddr,
360  Ptr<NetDevice> oif = nullptr) const;
361 
371  void SendPacketV6(Ptr<Packet> pkt,
372  const TcpHeader& outgoing,
373  const Ipv6Address& saddr,
374  const Ipv6Address& daddr,
375  Ptr<NetDevice> oif = nullptr) const;
376 };
377 
378 } // namespace ns3
379 
380 #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:43
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:50
Demultiplexer for end points.
A representation of an IPv6 endpoint/connection.
Packet header for IPv6.
Definition: ipv6-header.h:36
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.
enum 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.
TypeId m_congestionTypeId
The socket TypeId.
enum 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.
TcpL4Protocol & operator=(const TcpL4Protocol &)=delete
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.
std::vector< Ptr< TcpSocketBase > > m_sockets
list of sockets
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)
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)
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.
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:60
uint16_t port
Definition: dsdv-manet.cc:45
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.