A Discrete-Event Network Simulator
API
tcp-l4-protocol.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 Georgia Tech Research Corporation
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  * Author: Raj Bhattacharjea <raj.b@gatech.edu>
19  */
20 
21 #ifndef TCP_L4_PROTOCOL_H
22 #define TCP_L4_PROTOCOL_H
23 
24 #include <stdint.h>
25 
26 #include "ns3/ipv4-address.h"
27 #include "ns3/ipv6-address.h"
28 #include "ns3/sequence-number.h"
29 #include "ip-l4-protocol.h"
30 
31 
32 namespace ns3 {
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 
45 
80 class TcpL4Protocol : public IpL4Protocol {
81 public:
86  static TypeId GetTypeId (void);
87  static const uint8_t PROT_NUMBER;
88 
89  TcpL4Protocol ();
90  virtual ~TcpL4Protocol ();
91 
96  void SetNode (Ptr<Node> node);
97 
104  Ptr<Socket> CreateSocket (void);
105 
116  Ptr<Socket> CreateSocket (TypeId congestionTypeId);
117 
122  Ipv4EndPoint *Allocate (void);
135  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
143  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
153  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice,
154  Ipv4Address localAddress, uint16_t localPort,
155  Ipv4Address peerAddress, uint16_t peerPort);
160  Ipv6EndPoint *Allocate6 (void);
173  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port);
181  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
191  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice,
192  Ipv6Address localAddress, uint16_t localPort,
193  Ipv6Address peerAddress, uint16_t peerPort);
194 
204  void SendPacket (Ptr<Packet> pkt, const TcpHeader &outgoing,
205  const Address &saddr, const Address &daddr,
206  Ptr<NetDevice> oif = 0) const;
207 
215  void AddSocket (Ptr<TcpSocketBase> socket);
216 
223  bool RemoveSocket (Ptr<TcpSocketBase> socket);
224 
229  void DeAllocate (Ipv4EndPoint *endPoint);
234  void DeAllocate (Ipv6EndPoint *endPoint);
235 
236  // From IpL4Protocol
238  Ipv4Header const &incomingIpHeader,
239  Ptr<Ipv4Interface> incomingInterface);
241  Ipv6Header const &incomingIpHeader,
242  Ptr<Ipv6Interface> incomingInterface);
243 
244  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
245  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
246  Ipv4Address payloadSource,Ipv4Address payloadDestination,
247  const uint8_t payload[8]);
248  virtual void ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
249  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
250  Ipv6Address payloadSource,Ipv6Address payloadDestination,
251  const uint8_t payload[8]);
252 
255  virtual int GetProtocolNumber (void) const;
256  virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const;
258 
259 protected:
260  virtual void DoDispose (void);
261 
271  virtual void NotifyNewAggregate ();
272 
284  PacketReceived (Ptr<Packet> packet, TcpHeader &incomingTcpHeader,
285  const Address &source, const Address &destination);
286 
300  void NoEndPointsFound (const TcpHeader &incomingHeader, const Address &incomingSAddr,
301  const Address &incomingDAddr);
302 
303 private:
309  std::vector<Ptr<TcpSocketBase> > m_sockets;
312 
318  TcpL4Protocol (const TcpL4Protocol &);
326 
336  void SendPacketV4 (Ptr<Packet> pkt, const TcpHeader &outgoing,
337  const Ipv4Address &saddr, const Ipv4Address &daddr,
338  Ptr<NetDevice> oif = 0) const;
339 
349  void SendPacketV6 (Ptr<Packet> pkt, const TcpHeader &outgoing,
350  const Ipv6Address &saddr, const Ipv6Address &daddr,
351  Ptr<NetDevice> oif = 0) const;
352 };
353 
354 } // namespace ns3
355 
356 #endif /* TCP_L4_PROTOCOL_H */
TypeId m_congestionTypeId
The socket TypeId.
Ptr< Socket > CreateSocket(void)
Create a TCP socket using the TypeId set by SocketType attribute.
Packet header for IPv6.
Definition: ipv6-header.h:34
Ptr< Node > m_node
the node this stack is associated with
virtual void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
void SendPacketV4(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv4Address &saddr, const Ipv4Address &daddr, Ptr< NetDevice > oif=0) const
Send a packet via TCP (IPv4)
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &incomingIpHeader, Ptr< Ipv4Interface > incomingInterface)
Called from lower-level layers to send the packet up in the stack.
virtual void DoDispose(void)
Destructor implementation.
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
virtual 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])
Called from lower-level layers to send the ICMP packet up in the stack.
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.
void AddSocket(Ptr< TcpSocketBase > socket)
Make a socket fully operational.
RxStatus
Rx status codes.
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
TCP socket creation and multiplexing/demultiplexing.
virtual void NotifyNewAggregate()
Setup socket factory and callbacks when aggregated to a node.
Demultiplexes packets to various transport layer endpoints.
Packet header for IPv4.
Definition: ipv4-header.h:33
TcpL4Protocol & operator=(const TcpL4Protocol &)
Copy constructor.
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
std::vector< Ptr< TcpSocketBase > > m_sockets
list of sockets
static const uint8_t PROT_NUMBER
protocol number (0x6)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
void NoEndPointsFound(const TcpHeader &incomingHeader, const Address &incomingSAddr, const Address &incomingDAddr)
Check if RST packet should be sent, and in case, send it.
L4 Protocol abstract base class.
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
void SendPacketV6(Ptr< Packet > pkt, const TcpHeader &outgoing, const Ipv6Address &saddr, const Ipv6Address &daddr, Ptr< NetDevice > oif=0) const
Send a packet via TCP (IPv6)
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
Describes an IPv6 address.
Definition: ipv6-address.h:48
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
static TypeId GetTypeId(void)
Get the type ID.
Demultiplexer for end points.
A representation of an IPv6 endpoint/connection.
bool RemoveSocket(Ptr< TcpSocketBase > socket)
Remove a socket from the internal list.
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
void SendPacket(Ptr< Packet > pkt, const TcpHeader &outgoing, const Address &saddr, const Address &daddr, Ptr< NetDevice > oif=0) const
Send a packet via TCP (IP-agnostic)
TypeId m_rttTypeId
The RTT Estimator TypeId.
tuple address
Definition: first.py:37
a unique identifier for an interface.
Definition: type-id.h:58
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
A representation of an internet endpoint/connection.
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.