Debian Codegraph @

protolib/src/sim/ns/tcp/TCPSocketApp.h

raw
1
2 /**
3 TCPSocketApp: A class to use the ADU NS-2 functionality to implement
4 a bi directional TCP pipe for transfering data over an NS-2 TCP connection.
5 The connection is abstracted as a virtual pipe because rather than extending
6 a TCP protocol to implement these extensions, we implement the sending of data
7 as a separate entity which simply uses an external buffer at the application-level
8 to buffer the data. TCPSocketApp then waits until NS-2 simulates the
9 transfer before retrieving the data from the pipe at thje receiver side of
10 the connection.
11
12 TCPSocketApp subclasses from Application as the pipe is modelled as a
13 connection between two applications wishing to transfer data using a TCP
14 protocol. We use the exisisting NS-2 mechanism for representing application
15 data (ADU - Application Data Unit) and implement other necessities for
16 TCP real-world applications, ike the ability to send data ion both
17 directions. This class basically extends the existing tcpapp code in NS-2
18 to enhance that functionality.
19
20 TCPSocketApp model the TCP connection as a FIFO byte stream. It shouldn't
21 be used if this assumption is violated.
22 */
23
24 #ifndef ns_TCPSocketApp_h
25 #define ns_TCPSocketApp_h
26
27 #include "protoDebug.h"
28
29 #include "app.h"
30 #include "TCPData.h"
31 #include "SimpleList.h"
32
33 #include "TCPEvent.h"
34
35 #include <tcp-full.h>
36
37 class TCPSocketApp : public Application {
38 public:
39 TCPSocketApp(Agent *tcp);
40 ~TCPSocketApp();
41
42 // These are the key methods here, that interface with TCP socket agent
43 void send(AppData *data);
44 void setBytesSent(int bytes) { bytesSent_+=bytes; }
45 void recv(int nbytes);
46
47 void setTCPAgent(Agent *tcp);
48
49 void setTCPSocketAgentListener(TCPSocketAgentListener *listener) { tcpSocketListenerAgent = listener; }
50
51 FullTcpAgent *getTCPAgent() { return (FullTcpAgent *)agent_; }
52
53 void connect(TCPSocketApp *socketApp) { // connect both ways for two way transfer
54 connectedSocketApp = socketApp; socketApp->connectedSocketApp=this; }
55
56 void upcallToApp(char *data, unsigned int size);
57 AppData* get_data(int&, AppData*);
58
59 // Do nothing when a connection is terminated
60 virtual void resume();
61
62
63 protected:
64 virtual int command(int argc, const char*const* argv);
65 TcpData* receiveDataFromClient(); // calls client to retrieve the actual application data
66
67 // We don't have start/stop
68 virtual void start() { abort(); }
69 virtual void stop() { abort(); }
70
71 private:
72
73 void getDataFromOtherSocket();
74 TCPSocketApp *connectedSocketApp;
75 SimpleList tcpDataList_;
76 TcpData *curdata_;
77 int readOffset;
78 int bytesSent_;
79 int curbytes_;
80 TCPSocketAgentListener *tcpSocketListenerAgent;
81 };
82
83 #endif // ns_TCPSocketApp_h