1 | /* Virginia Tech Cognitive Radio Open Source Systems |
---|
2 | * Virginia Tech, 2009 |
---|
3 | * |
---|
4 | * LICENSE INFORMATION GOES HERE |
---|
5 | */ |
---|
6 | |
---|
7 | /* This header exports the declarations for all VT-CROSS radio components. It |
---|
8 | * contains two pure abstract base classes, Component and Engine; Engine derives |
---|
9 | * from Component. All functions contained within the abstract base classes are |
---|
10 | * dynamically linked and pure, and all child non-abstract classes derive using |
---|
11 | * private inheritence. Class functions of the abstract base classes are public |
---|
12 | * for two reasons: (1) To allow for public/protected inheritence in other |
---|
13 | * implementations, (2) So that symbolic debuggers can navigate the call tree |
---|
14 | * for typecasted objects of derivative classes. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef COMPONENTS_H |
---|
18 | #define COMPONENTS_H |
---|
19 | |
---|
20 | |
---|
21 | #include <stdint.h> |
---|
22 | #include <string> |
---|
23 | |
---|
24 | #include "containers.h" |
---|
25 | #include "socketcomm.h" |
---|
26 | |
---|
27 | |
---|
28 | /* Component abstract base class that all component classes should inherit from, |
---|
29 | * including cognitive and policy engines, and the service management layer. |
---|
30 | * Defines only functions required by all component types. |
---|
31 | */ |
---|
32 | class Component |
---|
33 | { |
---|
34 | public: |
---|
35 | /* Asks the component at the passed socket FD for its component type |
---|
36 | * string. Note that this implementation is global for all component |
---|
37 | * types, so is implemented here. Should a component need to override |
---|
38 | * it, that is possible via dynamic binding or overloading. |
---|
39 | */ |
---|
40 | virtual std::string GetRemoteComponentType(int32_t componentSocketFD) |
---|
41 | { |
---|
42 | SendMessage(componentSocketFD, "request_component_type"); |
---|
43 | |
---|
44 | char buffer[256]; |
---|
45 | memset(buffer, 0, 256); |
---|
46 | ReadMessage(componentSocketFD, buffer); |
---|
47 | |
---|
48 | return std::string(buffer); |
---|
49 | } |
---|
50 | |
---|
51 | /* Send an indentfying string for this object's component type in |
---|
52 | * response to a GetRemoteComponentType query. |
---|
53 | */ |
---|
54 | virtual void SendComponentType() = 0; |
---|
55 | |
---|
56 | /* Wait for a command signal containing task instructions. |
---|
57 | */ |
---|
58 | virtual void WaitForSignal() = 0; |
---|
59 | |
---|
60 | /* Completely shutdown the radio and all operations. |
---|
61 | */ |
---|
62 | virtual void Shutdown() = 0; |
---|
63 | |
---|
64 | /* Reset the radio and reload all configuration files. |
---|
65 | * |
---|
66 | * TODO are we remembering experiences in CEs? |
---|
67 | */ |
---|
68 | virtual void Reset() = 0; |
---|
69 | |
---|
70 | /* Register or deregister a component with the primary radio shell. |
---|
71 | */ |
---|
72 | virtual void RegisterComponent() = 0; |
---|
73 | virtual void DeregisterComponent() = 0; |
---|
74 | }; |
---|
75 | |
---|
76 | |
---|
77 | /* Engine abstract base class from which all engine component types should |
---|
78 | * inherit (e.g. cognitive and policy engines). Inherits all functions from the |
---|
79 | * ABC Component publically. |
---|
80 | */ |
---|
81 | class Engine : public Component |
---|
82 | { |
---|
83 | public: |
---|
84 | /* Connect to the remote control component, which will always be either |
---|
85 | * the VTCROSS shell or SML. Based on the status of the SML_present |
---|
86 | * bool, this function will also register the component or services. |
---|
87 | * |
---|
88 | * TODO I feel like the name of this function could be changed to be a |
---|
89 | * little more descriptive? |
---|
90 | */ |
---|
91 | virtual void ConnectToRemoteComponent(const char* serverName, \ |
---|
92 | const char* serverPort, const bool SML) = 0; |
---|
93 | |
---|
94 | /* Register or deregister services that this engine provides with the |
---|
95 | * service management layer. |
---|
96 | */ |
---|
97 | virtual void RegisterServices() = 0; |
---|
98 | virtual void DeregisterServices() = 0; |
---|
99 | }; |
---|
100 | |
---|
101 | |
---|
102 | /* Service Management Layer (SML) class declaration. The functions listed here |
---|
103 | * are required by the VTCROSS API for service-oriented VTCROSS radio |
---|
104 | * architectures. |
---|
105 | */ |
---|
106 | class ServiceManagementLayer : public Component |
---|
107 | { |
---|
108 | public: |
---|
109 | ServiceManagementLayer(); |
---|
110 | ~ServiceManagementLayer(); |
---|
111 | |
---|
112 | /* Overloaded constructor that creates an SML and connects it to the |
---|
113 | * shell with the passed hostname and port. |
---|
114 | */ |
---|
115 | ServiceManagementLayer(const char* serverName, const char* serverPort); |
---|
116 | |
---|
117 | /* Connect and register with the shell component at the passed hostname |
---|
118 | * and port. |
---|
119 | */ |
---|
120 | void ConnectToShell(const char* serverName, \ |
---|
121 | const char* serverPort); |
---|
122 | |
---|
123 | void SendComponentType(); |
---|
124 | void WaitForSignal(); |
---|
125 | void Shutdown(); |
---|
126 | void Reset(); |
---|
127 | void RegisterComponent(); |
---|
128 | void DeregisterComponent(); |
---|
129 | |
---|
130 | private: |
---|
131 | /* Receive the radio configuration settings from the shell and pass them |
---|
132 | * on to another component. |
---|
133 | */ |
---|
134 | void TransferRadioConfiguration(); |
---|
135 | |
---|
136 | /* Receive information regarding a completed 'experience' and pass it on |
---|
137 | * to the appropriate cognitive engine. |
---|
138 | */ |
---|
139 | void TransferExperience(); |
---|
140 | |
---|
141 | /* Listen for other components registering their available services with |
---|
142 | * the SML. |
---|
143 | */ |
---|
144 | void ReceiveServices(); |
---|
145 | |
---|
146 | /* Change the active mission of the radio to a new one and adjust radio |
---|
147 | * behavoir appropriately. |
---|
148 | */ |
---|
149 | void SetActiveMission(); |
---|
150 | |
---|
151 | /* List all services provided to the radio by registered components. |
---|
152 | */ |
---|
153 | void ListServices(); |
---|
154 | |
---|
155 | /* Load/Relead the XML configuration file. |
---|
156 | */ |
---|
157 | void ReloadConfiguration(); |
---|
158 | void LoadConfiguration(); |
---|
159 | |
---|
160 | /* The socket file descriptor information for the shell which this SML |
---|
161 | * is connected to. |
---|
162 | */ |
---|
163 | int32_t shellSocketFD; |
---|
164 | }; |
---|
165 | |
---|
166 | |
---|
167 | /* Policy Engine class declaration. All public functions are inherited from |
---|
168 | * parent classes. |
---|
169 | */ |
---|
170 | class PolicyEngine : public Engine |
---|
171 | { |
---|
172 | public: |
---|
173 | PolicyEngine(); |
---|
174 | ~PolicyEngine(); |
---|
175 | |
---|
176 | /* Overloaded constructor that creates a policy engine object and |
---|
177 | * connects it to either the shell or an SML, depening on the SML bool. |
---|
178 | */ |
---|
179 | PolicyEngine(const char* serverName, const char* serverPort, \ |
---|
180 | const bool SML); |
---|
181 | |
---|
182 | void SendComponentType(); |
---|
183 | void ConnectToRemoteComponent(const char* serverName, \ |
---|
184 | const char* serverPort, const bool SML); |
---|
185 | void WaitForSignal(); |
---|
186 | void Shutdown(); |
---|
187 | void Reset(); |
---|
188 | void RegisterComponent(); |
---|
189 | void DeregisterComponent(); |
---|
190 | |
---|
191 | void RegisterServices(); |
---|
192 | void DeregisterServices(); |
---|
193 | |
---|
194 | private: |
---|
195 | /* Parse and load/reload policies into the policy engine. |
---|
196 | */ |
---|
197 | void LoadPolicies(); |
---|
198 | void ReloadPolicies(); |
---|
199 | |
---|
200 | /* Return a decision made by the policy engine regarding a certain set |
---|
201 | * of transmission parameters. |
---|
202 | */ |
---|
203 | void SendPEDecision(struct Parameter pList[], struct Radio_Info *radio_info, \ |
---|
204 | int32_t decision_array[]); |
---|
205 | |
---|
206 | /* Validate a set of transmission parameters received from the radio. |
---|
207 | */ |
---|
208 | void ValidateParameters(); |
---|
209 | |
---|
210 | /* The SML_present bool reflects whether or not the remote component |
---|
211 | * this object is connected to is an SML. If it isn't, then it must be |
---|
212 | * a shell. The socketFD stores the socket file descriptor for this |
---|
213 | * connection. |
---|
214 | */ |
---|
215 | bool SML_present; |
---|
216 | int32_t commandSocketFD; |
---|
217 | }; |
---|
218 | |
---|
219 | |
---|
220 | /* Cognitive Engine class declaration. All public functions are inherited from |
---|
221 | * parent classes. |
---|
222 | */ |
---|
223 | class CognitiveEngine : public Engine |
---|
224 | { |
---|
225 | public: |
---|
226 | CognitiveEngine(); |
---|
227 | ~CognitiveEngine(); |
---|
228 | |
---|
229 | void SendComponentType(); |
---|
230 | void ConnectToRemoteComponent(const char* serverName, \ |
---|
231 | const char* serverPort, const bool SML); |
---|
232 | void WaitForSignal(); |
---|
233 | void Shutdown(); |
---|
234 | void Reset(); |
---|
235 | void RegisterComponent(); |
---|
236 | void DeregisterComponent(); |
---|
237 | |
---|
238 | void RegisterServices(); |
---|
239 | void DeregisterServices(); |
---|
240 | |
---|
241 | private: |
---|
242 | /* Receive the transmitted radio configuration from the radio itself |
---|
243 | * (the CE will not always be local to the radio). |
---|
244 | */ |
---|
245 | void ReceiveRadioConfiguration(); |
---|
246 | |
---|
247 | /* Receive an 'experience' report from the radio. |
---|
248 | */ |
---|
249 | void ReceiveExperience(); |
---|
250 | |
---|
251 | /* Find the most optimal set of transmission parameters given certain |
---|
252 | * observables and possibly a service if the SML component is present |
---|
253 | * and active. |
---|
254 | */ |
---|
255 | void GetSolution(Observable *observables); |
---|
256 | void GetSolution(Observable *observables, std::string service); |
---|
257 | |
---|
258 | /* Receive a feedback from the radio regarding the performance of a |
---|
259 | * certain set of parameters, possibly associated with a service. |
---|
260 | * |
---|
261 | * TODO what is the difference between experiences and feedback, |
---|
262 | * exactly? we should explain that explicitly here. |
---|
263 | */ |
---|
264 | void ReceiveFeedback(Observable *observables,\ |
---|
265 | Parameter *parameters, Utility *utilities); |
---|
266 | void ReceiveFeedback(Observable *observables, \ |
---|
267 | Parameter *parameters, std::string service); |
---|
268 | |
---|
269 | /* The SML_present bool reflects whether or not the remote component |
---|
270 | * this object is connected to is an SML. If it isn't, then it must be |
---|
271 | * a shell. The socketFD stores the socket file descriptor for this |
---|
272 | * connection. |
---|
273 | */ |
---|
274 | bool SML_present; |
---|
275 | int32_t commandSocketFD; |
---|
276 | }; |
---|
277 | |
---|
278 | /* Cognitive Radio Shell class declaration. |
---|
279 | */ |
---|
280 | class CognitiveRadioShell |
---|
281 | { |
---|
282 | public: |
---|
283 | CognitiveRadioShell(); |
---|
284 | ~CognitiveRadioShell(); |
---|
285 | |
---|
286 | /* Overloaded constructor that creates a CR Shell object and loads the |
---|
287 | * passed radio configuration XML file. |
---|
288 | */ |
---|
289 | CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \ |
---|
290 | int16_t policyPort, int16_t commandPort); |
---|
291 | |
---|
292 | void SendComponentType(int32_t socketFD); |
---|
293 | void Shutdown(); |
---|
294 | void Reset(); |
---|
295 | |
---|
296 | /* Start all the socket servers */ |
---|
297 | void StartShellServer(); |
---|
298 | |
---|
299 | int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \ |
---|
300 | Utility* &uList, Observable* &oList, Radio_Info* radioInfo); |
---|
301 | private: |
---|
302 | /* Parse and load/reload policies into the policy engine. |
---|
303 | */ |
---|
304 | void LoadPolicies(); |
---|
305 | void ReloadPolicies(); |
---|
306 | |
---|
307 | /* Register and Deregister the different components. |
---|
308 | */ |
---|
309 | void RegisterCognitiveEngine(int32_t socketFD); |
---|
310 | void DeregisterCognitiveEngine(int32_t socketFD); |
---|
311 | void RegisterPolicyEngine(int32_t socketFD); |
---|
312 | void DeregisterPolicyEngine(int32_t socketFD); |
---|
313 | void RegisterSML(int32_t socketFD); |
---|
314 | void DeregisterSML(int32_t socketFD); |
---|
315 | |
---|
316 | /* Handle a message that is received from a component. |
---|
317 | */ |
---|
318 | void HandleMessage(int32_t socketFD); |
---|
319 | |
---|
320 | /* Send optimization request to primary port FD. |
---|
321 | */ |
---|
322 | void GetOptimalParameters(int32_t socketFD); |
---|
323 | |
---|
324 | void SendRadioConfiguration(int32_t socketFD); |
---|
325 | void SendRadioExperience(int32_t socketFD); |
---|
326 | |
---|
327 | bool SML_present; |
---|
328 | bool PE_present; |
---|
329 | bool CE_present; |
---|
330 | |
---|
331 | int32_t numberOfCognitiveEngines; |
---|
332 | int16_t primaryPort; |
---|
333 | int16_t policyPort; |
---|
334 | int16_t commandPort; |
---|
335 | |
---|
336 | Utility * u; |
---|
337 | Parameter * p; |
---|
338 | Observable * o; |
---|
339 | struct Radio_Info * radio_info; |
---|
340 | }; |
---|
341 | |
---|
342 | #endif |
---|