A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
nsc-tcp-l4-protocol.h
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 #ifndef NSC_TCP_L4_PROTOCOL_H
18 #define NSC_TCP_L4_PROTOCOL_H
19 
20 #include <stdint.h>
21 
22 #include "ns3/packet.h"
23 #include "ns3/ipv4-address.h"
24 #include "ns3/ptr.h"
25 #include "ns3/object-factory.h"
26 #include "ns3/timer.h"
27 #include "ip-l4-protocol.h"
28 
29 struct INetStack;
30 
31 namespace ns3 {
32 
33 class Node;
34 class Socket;
35 class Ipv4EndPointDemux;
36 class Ipv4Interface;
37 class NscTcpSocketImpl;
38 class Ipv4EndPoint;
39 class NscInterfaceImpl;
40 
47 public:
48  static const uint8_t PROT_NUMBER;
49  static TypeId GetTypeId (void);
54  virtual ~NscTcpL4Protocol ();
55 
56  void SetNode (Ptr<Node> node);
57  void SetNscLibrary (const std::string &lib);
58  std::string GetNscLibrary (void) const;
59  virtual int GetProtocolNumber (void) const;
60  virtual int GetVersion (void) const;
61 
67 
68  Ipv4EndPoint *Allocate (void);
69  Ipv4EndPoint *Allocate (Ipv4Address address);
70  Ipv4EndPoint *Allocate (uint16_t port);
71  Ipv4EndPoint *Allocate (Ipv4Address address, uint16_t port);
72  Ipv4EndPoint *Allocate (Ipv4Address localAddress, uint16_t localPort,
73  Ipv4Address peerAddress, uint16_t peerPort);
74 
75  void DeAllocate (Ipv4EndPoint *endPoint);
76 
83  virtual IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
84  Ipv4Header const &header,
85  Ptr<Ipv4Interface> incomingInterface);
86  virtual IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
87  Ipv6Header const &header,
88  Ptr<Ipv6Interface> interface);
89 
90  // From IpL4Protocol
92  virtual void SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb);
93  // From IpL4Protocol
95  virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6 (void) const;
96 protected:
97  virtual void DoDispose (void);
98  virtual void NotifyNewAggregate ();
99 private:
101  NscTcpL4Protocol& operator= (NscTcpL4Protocol const &);
102 
103  // NSC callbacks.
104  // NSC invokes these hooks to interact with the simulator.
105  // In any case, these methods are only to be called by NSC.
106  //
107  // send_callback is invoked by NSCs 'ethernet driver' to re-inject
108  // a packet (i.e. an octet soup consisting of an IP Header, TCP Header
109  // and user payload, if any), into ns-3.
110  void send_callback (const void *data, int datalen);
111  // This is called by the NSC stack whenever something of interest
112  // has happened, e.g. when data arrives on a socket, a listen socket
113  // has a new connection pending, etc.
114  void wakeup ();
115  // This is called by the Linux stack RNG initialization.
116  // Its also used by the cradle code to add a timestamp to
117  // printk/printf/debug output.
118  void gettime (unsigned int *sec, unsigned int *usec);
119  void AddInterface (void);
120  void SoftInterrupt (void);
121  friend class NscInterfaceImpl;
122  friend class NscTcpSocketImpl;
123  Ptr<Node> m_node;
124  Ipv4EndPointDemux *m_endPoints;
125  INetStack* m_nscStack;
126  NscInterfaceImpl *m_nscInterface;
127  void *m_dlopenHandle;
128  std::string m_nscLibrary;
129  Timer m_softTimer;
130  std::vector<Ptr<NscTcpSocketImpl> > m_sockets;
132 };
133 
134 } // namespace ns3
135 
136 #endif /* NSC_TCP_L4_PROTOCOL_H */
Nsc wrapper glue, to interface with the Ipv4 protocol underneath.
Packet header for IPv6.
Definition: ipv6-header.h:33
a simple Timer class
Definition: timer.h:45
Ptr< Socket > CreateSocket(void)
Demultiplexes packets to various transport layer endpoints.
Packet header for IPv4.
Definition: ipv4-header.h:31
Socket logic for the NSC TCP sockets.
virtual void NotifyNewAggregate()
virtual void DoDispose(void)
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
virtual IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)
Receive a packet up the protocol stack.
L4 Protocol abstract base class.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
virtual int GetProtocolNumber(void) const
a unique identifier for an interface.
Definition: type-id.h:44
A representation of an internet endpoint/connection.
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const