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 
98  // NOTE: API from here should not be removed, only added. Be backward-compatible!
99 
106  Ptr<Socket> CreateSocket (void);
107 
119  Ptr<Socket> CreateSocket (TypeId congestionTypeId, TypeId recoveryTypeId);
120 
129  Ptr<Socket> CreateSocket (TypeId congestionTypeId);
130 
135  Ipv4EndPoint *Allocate (void);
148  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, uint16_t port);
156  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice, Ipv4Address address, uint16_t port);
166  Ipv4EndPoint *Allocate (Ptr<NetDevice> boundNetDevice,
167  Ipv4Address localAddress, uint16_t localPort,
168  Ipv4Address peerAddress, uint16_t peerPort);
173  Ipv6EndPoint *Allocate6 (void);
186  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, uint16_t port);
194  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice, Ipv6Address address, uint16_t port);
204  Ipv6EndPoint *Allocate6 (Ptr<NetDevice> boundNetDevice,
205  Ipv6Address localAddress, uint16_t localPort,
206  Ipv6Address peerAddress, uint16_t peerPort);
207 
217  void SendPacket (Ptr<Packet> pkt, const TcpHeader &outgoing,
218  const Address &saddr, const Address &daddr,
219  Ptr<NetDevice> oif = 0) const;
220 
228  void AddSocket (Ptr<TcpSocketBase> socket);
229 
236  bool RemoveSocket (Ptr<TcpSocketBase> socket);
237 
242  void DeAllocate (Ipv4EndPoint *endPoint);
247  void DeAllocate (Ipv6EndPoint *endPoint);
248 
249  // From IpL4Protocol
251  Ipv4Header const &incomingIpHeader,
252  Ptr<Ipv4Interface> incomingInterface);
254  Ipv6Header const &incomingIpHeader,
255  Ptr<Ipv6Interface> incomingInterface);
256 
257  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
258  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
259  Ipv4Address payloadSource,Ipv4Address payloadDestination,
260  const uint8_t payload[8]);
261  virtual void ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
262  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
263  Ipv6Address payloadSource,Ipv6Address payloadDestination,
264  const uint8_t payload[8]);
265 
268  virtual int GetProtocolNumber (void) const;
269  virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const;
271 
272 protected:
273  virtual void DoDispose (void);
274 
284  virtual void NotifyNewAggregate ();
285 
297  PacketReceived (Ptr<Packet> packet, TcpHeader &incomingTcpHeader,
298  const Address &source, const Address &destination);
299 
313  void NoEndPointsFound (const TcpHeader &incomingHeader, const Address &incomingSAddr,
314  const Address &incomingDAddr);
315 
316 private:
323  std::vector<Ptr<TcpSocketBase> > m_sockets;
326 
340 
350  void SendPacketV4 (Ptr<Packet> pkt, const TcpHeader &outgoing,
351  const Ipv4Address &saddr, const Ipv4Address &daddr,
352  Ptr<NetDevice> oif = 0) const;
353 
363  void SendPacketV6 (Ptr<Packet> pkt, const TcpHeader &outgoing,
364  const Ipv6Address &saddr, const Ipv6Address &daddr,
365  Ptr<NetDevice> oif = 0) const;
366 };
367 
368 } // namespace ns3
369 
370 #endif /* TCP_L4_PROTOCOL_H */
ns3::TcpL4Protocol::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-l4-protocol.cc:70
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::Ipv4Header
Packet header for IPv4.
Definition: ipv4-header.h:34
ns3::TcpL4Protocol::SendPacketV4
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)
Definition: tcp-l4-protocol.cc:556
ns3::Ipv6EndPointDemux
Demultiplexer for end points.
Definition: ipv6-end-point-demux.h:39
ns3::TcpL4Protocol::PROT_NUMBER
static const uint8_t PROT_NUMBER
protocol number (0x6)
Definition: tcp-l4-protocol.h:87
ns3::Callback< void, Ptr< Packet >, Ipv4Address, Ipv4Address, uint8_t, Ptr< Ipv4Route > >
ns3::TcpL4Protocol::m_downTarget6
IpL4Protocol::DownTargetCallback6 m_downTarget6
Callback to send packets over IPv6.
Definition: tcp-l4-protocol.h:325
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ipv6EndPoint
A representation of an IPv6 endpoint/connection.
Definition: ipv6-end-point.h:51
ns3::TcpL4Protocol::TcpL4Protocol
TcpL4Protocol()
Definition: tcp-l4-protocol.cc:99
ns3::TcpL4Protocol::NotifyNewAggregate
virtual void NotifyNewAggregate()
Setup socket factory and callbacks when aggregated to a node.
Definition: tcp-l4-protocol.cc:118
ns3::TcpL4Protocol::m_congestionTypeId
TypeId m_congestionTypeId
The socket TypeId.
Definition: tcp-l4-protocol.h:321
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::Ipv6Address
Describes an IPv6 address.
Definition: ipv6-address.h:50
ns3::TcpL4Protocol::GetDownTarget6
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...
Definition: tcp-l4-protocol.cc:764
ns3::Ipv6Header
Packet header for IPv6.
Definition: ipv6-header.h:36
ns3::TcpL4Protocol::Allocate6
Ipv6EndPoint * Allocate6(void)
Allocate an IPv6 Endpoint.
Definition: tcp-l4-protocol.cc:269
ns3::TcpL4Protocol::RemoveSocket
bool RemoveSocket(Ptr< TcpSocketBase > socket)
Remove a socket from the internal list.
Definition: tcp-l4-protocol.cc:726
ns3::TcpL4Protocol::SetNode
void SetNode(Ptr< Node > node)
Set node associated with this stack.
Definition: tcp-l4-protocol.cc:111
ns3::TcpL4Protocol::Receive
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.
Definition: tcp-l4-protocol.cc:435
ns3::Ptr< Node >
ns3::TcpL4Protocol::m_node
Ptr< Node > m_node
the node this stack is associated with
Definition: tcp-l4-protocol.h:317
ns3::TcpL4Protocol::m_endPoints6
Ipv6EndPointDemux * m_endPoints6
A list of IPv6 end points.
Definition: tcp-l4-protocol.h:319
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::IpL4Protocol::RxStatus
RxStatus
Rx status codes.
Definition: ip-l4-protocol.h:56
ns3::TcpL4Protocol::PacketReceived
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.
Definition: tcp-l4-protocol.cc:369
ns3::TcpL4Protocol::SendPacket
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)
Definition: tcp-l4-protocol.cc:661
ns3::Ipv4EndPointDemux
Demultiplexes packets to various transport layer endpoints.
Definition: ipv4-end-point-demux.h:45
ns3::TcpL4Protocol::m_endPoints
Ipv4EndPointDemux * m_endPoints
A list of IPv4 end points.
Definition: tcp-l4-protocol.h:318
first.address
address
Definition: first.py:44
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition: tcp-header.h:45
ns3::TcpL4Protocol::TcpL4Protocol
TcpL4Protocol(const TcpL4Protocol &)
Copy constructor.
ns3::TcpL4Protocol::ReceiveIcmp
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.
Definition: tcp-l4-protocol.cc:315
ns3::IpL4Protocol
L4 Protocol abstract base class.
Definition: ip-l4-protocol.h:51
ns3::TcpL4Protocol::SetDownTarget6
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...
Definition: tcp-l4-protocol.cc:758
ns3::TcpL4Protocol::SetDownTarget
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...
Definition: tcp-l4-protocol.cc:746
ns3::TcpL4Protocol::GetProtocolNumber
virtual int GetProtocolNumber(void) const
Returns the protocol number of this protocol.
Definition: tcp-l4-protocol.cc:155
ns3::TcpL4Protocol::DeAllocate
void DeAllocate(Ipv4EndPoint *endPoint)
Remove an IPv4 Endpoint.
Definition: tcp-l4-protocol.cc:262
ns3::TcpL4Protocol::m_downTarget
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
Definition: tcp-l4-protocol.h:324
ns3::TcpL4Protocol::m_recoveryTypeId
TypeId m_recoveryTypeId
The recovery TypeId.
Definition: tcp-l4-protocol.h:322
ns3::TcpL4Protocol::m_rttTypeId
TypeId m_rttTypeId
The RTT Estimator TypeId.
Definition: tcp-l4-protocol.h:320
ns3::TcpL4Protocol::AddSocket
void AddSocket(Ptr< TcpSocketBase > socket)
Make a socket fully operational.
Definition: tcp-l4-protocol.cc:707
ns3::TcpL4Protocol::GetDownTarget
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...
Definition: tcp-l4-protocol.cc:752
ns3::TcpL4Protocol::operator=
TcpL4Protocol & operator=(const TcpL4Protocol &)
Copy constructor.
ns3::TcpL4Protocol::SendPacketV6
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)
Definition: tcp-l4-protocol.cc:607
ns3::TcpL4Protocol::Allocate
Ipv4EndPoint * Allocate(void)
Allocate an IPv4 Endpoint.
Definition: tcp-l4-protocol.cc:223
ns3::TcpL4Protocol
TCP socket creation and multiplexing/demultiplexing.
Definition: tcp-l4-protocol.h:80
ns3::TcpL4Protocol::m_sockets
std::vector< Ptr< TcpSocketBase > > m_sockets
list of sockets
Definition: tcp-l4-protocol.h:323
ns3::TcpL4Protocol::CreateSocket
Ptr< Socket > CreateSocket(void)
Create a TCP socket using the TypeId set by SocketType attribute.
Definition: tcp-l4-protocol.cc:217
ip-l4-protocol.h
ns3::Ipv4EndPoint
A representation of an internet endpoint/connection.
Definition: ipv4-end-point.h:49
ns3::TcpL4Protocol::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: tcp-l4-protocol.cc:161
ns3::TcpL4Protocol::NoEndPointsFound
void NoEndPointsFound(const TcpHeader &incomingHeader, const Address &incomingSAddr, const Address &incomingDAddr)
Check if RST packet should be sent, and in case, send it.
Definition: tcp-l4-protocol.cc:398
ns3::TcpL4Protocol::~TcpL4Protocol
virtual ~TcpL4Protocol()
Definition: tcp-l4-protocol.cc:105
port
uint16_t port
Definition: dsdv-manet.cc:45