A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tcp-l4-protocol.h
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/packet.h"
27 #include "ns3/ipv4-address.h"
28 #include "ns3/ipv6-address.h"
29 #include "ns3/ptr.h"
30 #include "ns3/object-factory.h"
31 #include "ip-l4-protocol.h"
32 #include "ns3/net-device.h"
33 
34 namespace ns3 {
35 
36 class Node;
37 class Socket;
38 class TcpHeader;
39 class Ipv4EndPointDemux;
40 class Ipv6EndPointDemux;
41 class Ipv4Interface;
42 class TcpSocketBase;
43 class Ipv4EndPoint;
44 class Ipv6EndPoint;
45 
56 class TcpL4Protocol : public IpL4Protocol {
57 public:
58  static TypeId GetTypeId (void);
59  static const uint8_t PROT_NUMBER;
63  TcpL4Protocol ();
64  virtual ~TcpL4Protocol ();
65 
66  void SetNode (Ptr<Node> node);
67 
68  virtual int GetProtocolNumber (void) const;
69 
75  Ptr<Socket> CreateSocket (TypeId socketTypeId);
76 
77  Ipv4EndPoint *Allocate (void);
78  Ipv4EndPoint *Allocate (Ipv4Address address);
79  Ipv4EndPoint *Allocate (uint16_t port);
80  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
81  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
82  Ipv4Address peerAddress, uint16_t peerPort);
83  Ipv6EndPoint *Allocate6 (void);
84  Ipv6EndPoint *Allocate6 (Ipv6Address address);
85  Ipv6EndPoint *Allocate6 (uint16_t port);
86  Ipv6EndPoint *Allocate6 (Ipv6Address address, uint16_t port);
87  Ipv6EndPoint *Allocate6 (Ipv6Address localAddress, uint16_t localPort,
88  Ipv6Address peerAddress, uint16_t peerPort);
89 
90  void DeAllocate (Ipv4EndPoint *endPoint);
91  void DeAllocate (Ipv6EndPoint *endPoint);
92 
102  void Send (Ptr<Packet> packet,
103  Ipv4Address saddr, Ipv4Address daddr,
104  uint16_t sport, uint16_t dport, Ptr<NetDevice> oif = 0);
105  void Send (Ptr<Packet> packet,
106  Ipv6Address saddr, Ipv6Address daddr,
107  uint16_t sport, uint16_t dport, Ptr<NetDevice> oif = 0);
114  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
115  Ipv4Header const &header,
116  Ptr<Ipv4Interface> incomingInterface);
117  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
118  Ipv6Header const &header,
119  Ptr<Ipv6Interface> interface);
120 
132  virtual void ReceiveIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
133  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
134  Ipv4Address payloadSource,Ipv4Address payloadDestination,
135  const uint8_t payload[8]);
136  virtual void ReceiveIcmp (Ipv6Address icmpSource, uint8_t icmpTtl,
137  uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo,
138  Ipv6Address payloadSource,Ipv6Address payloadDestination,
139  const uint8_t payload[8]);
140 
141  // From IpL4Protocol
143  virtual void SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb);
144  // From IpL4Protocol
145  virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const;
146  virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6 (void) const;
147 
148 protected:
149  virtual void DoDispose (void);
150  /*
151  * This function will notify other components connected to the node that a new stack member is now connected
152  * This will be used to notify Layer 3 protocol of layer 4 protocol stack to connect them together.
153  */
154  virtual void NotifyNewAggregate ();
155 private:
156  Ptr<Node> m_node;
157  Ipv4EndPointDemux *m_endPoints;
158  Ipv6EndPointDemux *m_endPoints6;
159  TypeId m_rttTypeId;
160  TypeId m_socketTypeId;
161 private:
162  friend class TcpSocketBase;
163  void SendPacket (Ptr<Packet>, const TcpHeader &,
165  void SendPacket (Ptr<Packet>, const TcpHeader &,
167  TcpL4Protocol (const TcpL4Protocol &o);
168  TcpL4Protocol &operator = (const TcpL4Protocol &o);
169 
170  std::vector<Ptr<TcpSocketBase> > m_sockets;
172  IpL4Protocol::DownTargetCallback6 m_downTarget6;
173 };
174 
175 } // namespace ns3
176 
177 #endif /* TCP_L4_PROTOCOL_H */
Ptr< Socket > CreateSocket(void)
Packet header for IPv6.
Definition: ipv6-header.h:33
virtual void DoDispose(void)
void Send(Ptr< Packet > packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t sport, uint16_t dport, Ptr< NetDevice > oif=0)
Send a packet via TCP.
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])
Receive an ICMP packet.
A layer between the sockets interface and IP.
virtual void NotifyNewAggregate()
Demultiplexes packets to various transport layer endpoints.
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)
Receive a packet up the protocol stack.
TcpL4Protocol()
Constructor.
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
A base class for implementation of a stream socket using TCP.
Header for the Transmission Control Protocol.
Definition: tcp-header.h:43
virtual int GetProtocolNumber(void) const
L4 Protocol abstract base class.
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Demultiplexor for end points.
An IPv6 end point, four tuples identification.
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
a unique identifier for an interface.
Definition: type-id.h:44
A representation of an internet endpoint/connection.