Debian Codegraph @

protolib/src/sim/opnet/11.5/opnetProtoSimProcess.h

raw
1 #ifndef _OPNET_PROTO_SIM_PROCESS
2 #define _OPNET_PROTO_SIM_PROCESS
3
4 // The "OpnetProtoSimProcess" plays a role similar to that of the
5 // "ProtoDispatcher" class which provides liason between Protolib
6 // classes and the computer operating system.
7
8 // Opnet agents based on Protolib code can use this as a base
9 // class. ProtoSockets used by the Protolib code _must_ have
10 // their "notifier" set as a pointer to their corresponding
11 // OpnetProtoSimProcess instance. Similarly, ProtoTimerMgrs used by the
12 // Protolib code _must_ have their "installer" set to their
13 // corresponding "OpnetProtoSimProcess" instance.
14
15 #include "protoSimAgent.h"
16 #include "protoSocket.h"
17 #include "protoTimer.h"
18 #include "opnet.h"
19 #include <tcp_api_v3.h>
20 #include "mgen.h"
21
22 #define SELF_INTRT_CODE_TIMEOUT_EVENT 0
23
24 class OpnetProtoSimProcess : public ProtoSimAgent
25 {
26 public:
27 // LP 6-13-04 - replaced
28 // virtual ~OpnetProtoSimProcess();
29 ~OpnetProtoSimProcess();
30
31 // end LP
32
33 // These must be overridden by derived OPNET process class
34 virtual bool OnStartup(int argc, const char*const* argv) = 0;
35 virtual bool ProcessCommands(int argc, const char*const* argv) = 0;
36 virtual void OnShutdown() = 0;
37
38 // Some helper methods
39 void ActivateTimer(ProtoTimer& theTimer)
40 {ProtoSimAgent::ActivateTimer(theTimer);}
41
42 void DeactivateTimer(ProtoTimer& theTimer)
43 {ProtoSimAgent::DeactivateTimer(theTimer);}
44
45 ProtoSocket::Notifier& GetSocketNotifier()
46 {return ProtoSimAgent::GetSocketNotifier();}
47
48 ProtoTimerMgr& GetTimerMgr()
49 {return ProtoSimAgent::GetTimerMgr();}
50
51 virtual bool GetLocalAddress(ProtoAddress& localAddr)
52 {
53 localAddr.SimSetAddress((unsigned int)op_id_self());
54 return true;
55 }
56
57 void OnSystemTimeout() {ProtoSimAgent::OnSystemTimeout();}
58
59 // Some OPNET specific utility methods
60 void SetUdpProcessId(Objid udpProcessId)
61 {udp_process_id = udpProcessId;}
62 void SetTcpHostAddress(ProtoAddress hostAddr)
63 {tcp_host_addr = hostAddr;}
64 void SetTcpRemAddress(ProtoAddress remAddr) // JPH 7/27/2006 - TCP support
65 {tcp_ind_rem_addr = remAddr;}
66 void SetTcpHandle(ApiT_Tcp_App_Handle tcpHandle)
67 {tcp_handle = tcpHandle;}
68 void OnReceive(int strm_indx); // JPH 4/11/06 added strm_indx
69 SocketProxy* FindProxyByConn(int connId)
70 {return socket_proxy_list.FindProxyByConn(connId);} // JPH 8/13/2006 - TCP support
71
72 // These can be overridden for packet stats, etc ...
73 virtual void ReceivePacketMonitor(Ici* ici, Packet* pkt) {}
74 virtual void TransmitPacketMonitor(Ici* ici, Packet* pkt) {}
75 virtual void HandleMgenMessage(char* buffer,
76 unsigned int len,
77 const ProtoAddress& srcAddr) {};
78
79 protected:
80 OpnetProtoSimProcess();
81
82 // override of ProtoSimAgent::UpdateSystemTimer() method
83 bool UpdateSystemTimer(ProtoTimer::Command command,
84 double delay)
85 {
86 // printf("\t\tOpnetProtoSimProcess.h - Class OpnetProtoSimProces::UpdateSystemTimer(command,delay)\n"); // LP
87 switch (command)
88 {
89 case ProtoTimer::MODIFY:
90 op_ev_cancel(timer_handle);
91 case ProtoTimer::INSTALL:
92 timer_handle =
93 op_intrpt_schedule_self(op_sim_time() + delay, SELF_INTRT_CODE_TIMEOUT_EVENT);
94 break;
95 case ProtoTimer::REMOVE:
96 op_ev_cancel(timer_handle);
97 //timer_handle = (Evhandle)NULL; // ???
98 break;
99 } // end switch
100 return true;
101 } // end bool UpdatesSystemTime()
102
103
104 // The "UdpSocketProxy" provides liason between a UDP "ProtoSocket"
105 // instance and the neighboring OPNET UDP process
106 class UdpSocketProxy;
107 friend UdpSocketProxy;
108 class UdpSocketProxy : public ProtoSimAgent::SocketProxy
109 {
110 friend class OpnetProtoSimProcess;
111
112 public:
113 UdpSocketProxy(OpnetProtoSimProcess* sim_process); // JPH sim_process param
114 virtual ~UdpSocketProxy();
115
116 bool Bind(UINT16& thePort);
117 bool Connect(const ProtoAddress& theAddress){return false;}
118 bool Listen(UINT16 thePort){return false;}
119 bool Accept(ProtoSocket* theSocket){return false;}
120 bool RecvFrom(char* buffer, unsigned int& numBytes, ProtoAddress& srcAddr);
121
122 bool JoinGroup(const ProtoAddress& groupAddr);
123 bool LeaveGroup(const ProtoAddress& groupAddr);
124 void SetTTL(unsigned char ttl) {mcast_ttl = ttl;}
125 void SetLoopback(bool loopback) {mcast_loopback = loopback;}
126 void SetStream(int theStream) {strm_index = theStream;} // JPH 3/30/06
127
128 virtual bool SendTo(const char* buffer,
129 unsigned int& numBytes,
130 const ProtoAddress& dstAddr);
131
132 void OnReceive(char* recvData,
133 unsigned int recvLen,
134 const ProtoAddress& srcAddr,
135 const ProtoAddress& dstAddr);
136 int GetConn(){return 0;}
137
138 protected:
139 //Objid udp_process_id;
140 OpnetProtoSimProcess* sim_process; // JPH need sim_process rather than udp_process_id
141 unsigned char mcast_ttl;
142 bool mcast_loopback;
143 char* recv_data;
144 UINT16 recv_data_len;
145 ProtoAddress src_addr;
146 Ici* udp_command_ici; // LP 6-21-04 - added
147 int strm_index; // JPH 3/30/06 - added
148 }; // end class OpnetProtoSimProcess::UdpSocketProxy
149
150 // The "TcpSocketProxy" provides liason between a TCP "ProtoSocket" - JPH 7/3/06
151 // instance and the neighboring OPNET TCP process
152 class TcpSocketProxy;
153 friend TcpSocketProxy;
154 class TcpSocketProxy : public ProtoSimAgent::SocketProxy
155 {
156 friend class OpnetProtoSimProcess;
157
158 public:
159 TcpSocketProxy(OpnetProtoSimProcess* sim_process); // JPH sim_process param
160 virtual ~TcpSocketProxy();
161
162 bool Bind(UINT16& thePort);
163 bool Connect(const ProtoAddress& theAddress);
164 bool Listen(UINT16 thePort);
165 bool Accept(ProtoSocket* theSocket);
166 bool RecvFrom(char* buffer, unsigned int& numBytes, ProtoAddress& srcAddr);
167 bool JoinGroup(const ProtoAddress& groupAddr);
168 bool LeaveGroup(const ProtoAddress& groupAddr);
169 void SetTTL(unsigned char ttl) {}
170 void SetLoopback(bool loopback) {}
171 void SetStream(int theStream) {strm_index = theStream;} // JPH 3/30/06
172
173 virtual bool SendTo(const char* buffer,
174 unsigned int& numBytes,
175 const ProtoAddress& dstAddr);
176
177
178 void OnReceive(char* recvData,
179 unsigned int recvLen,
180 const ProtoAddress& srcAddr,
181 const ProtoAddress& dstAddr);
182
183 UINT16 GetPort(){return local_port;}
184 ProtoAddress GetTcpHostAddress(){return sim_process->tcp_host_addr;}
185 ProtoAddress GetTcpRemAddress(){return sim_process->tcp_ind_rem_addr;}
186 bool Send(const char* buffer,
187 unsigned int& numBytes);
188 bool Recv(char* buffer,
189 unsigned int& numBytes);
190 int GetConn(){return conn_id;}
191
192 protected:
193 class TcpSockList : public ProtoSimAgent::SocketProxy::List
194 {
195 public:
196 TcpSockList(){}
197 ~TcpSockList(){}
198 SocketProxy* FindProxyByConn(int connId);
199 }; // end class TcpSockList
200
201 friend class TcpSockList;
202
203 //ProtoSocket* proto_socket;
204
205 //SocketProxy* prev;
206 //SocketProxy* next;
207 OpnetProtoSimProcess* sim_process;
208 char* recv_data;
209 UINT16 recv_data_len;
210 ProtoAddress src_addr;
211 Ici* tcp_command_ici;
212 int strm_index;
213 int conn_id;
214 UINT16 local_port;
215 }; // end class OpnetProtoSimProcess::TcpSocketProxy
216
217
218 ProtoSimAgent::SocketProxy* OpenSocket(ProtoSocket& theSocket);
219 void CloseSocket(ProtoSocket& theSocket);
220 Objid GetUdpProcId() {return udp_process_id;}
221 ApiT_Tcp_App_Handle* GetTcpHandle(){return &tcp_handle;}
222
223 Objid udp_process_id;
224 ProtoAddress tcp_host_addr;
225 ProtoAddress tcp_ind_rem_addr;
226 //ProtoSimAgent::SocketProxy::List socket_proxy_list;
227 TcpSocketProxy::TcpSockList socket_proxy_list;
228 Evhandle timer_handle;
229 ApiT_Tcp_App_Handle tcp_handle; // JPH - needed to declare this last??
230
231
232 }; // end class OpnetProtoSimProcess
233
234 #endif //_OPNET_PROTO_SIM_PROCESS