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 <cstring> |
---|
22 | #include <stdint.h> |
---|
23 | #include <string> |
---|
24 | |
---|
25 | #include "containers.h" |
---|
26 | #include "socketcomm.h" |
---|
27 | |
---|
28 | |
---|
29 | /* Component abstract base class that all component classes should inherit from, |
---|
30 | * including cognitive and policy engines, and the service management layer. |
---|
31 | * Defines only functions required by all component types. |
---|
32 | */ |
---|
33 | class Component |
---|
34 | { |
---|
35 | public: |
---|
36 | /* Asks the component at the passed socket FD for its component type |
---|
37 | * string. Note that this implementation is global for all component |
---|
38 | * types, so is implemented here. Should a component need to override |
---|
39 | * it, that is possible via dynamic binding or overloading. |
---|
40 | */ |
---|
41 | virtual std::string GetRemoteComponentType(int32_t componentSocketFD) |
---|
42 | { |
---|
43 | SendMessage(componentSocketFD, "request_component_type"); |
---|
44 | |
---|
45 | char buffer[256]; |
---|
46 | memset(buffer, 0, 256); |
---|
47 | ReadMessage(componentSocketFD, buffer); |
---|
48 | |
---|
49 | return std::string(buffer); |
---|
50 | } |
---|
51 | |
---|
52 | /* Send an indentfying string for this object's component type in |
---|
53 | * response to a GetRemoteComponentType query. |
---|
54 | */ |
---|
55 | virtual void SendComponentType() = 0; |
---|
56 | |
---|
57 | /* Wait for a command signal containing task instructions. |
---|
58 | */ |
---|
59 | virtual void WaitForSignal() = 0; |
---|
60 | |
---|
61 | /* Completely shutdown the radio and all operations. |
---|
62 | */ |
---|
63 | virtual void Shutdown() = 0; |
---|
64 | |
---|
65 | /* Reset the radio and reload all configuration files. |
---|
66 | * |
---|
67 | * TODO are we remembering experiences in CEs? |
---|
68 | */ |
---|
69 | virtual void Reset() = 0; |
---|
70 | |
---|
71 | /* Register or deregister a component with the primary radio shell. |
---|
72 | */ |
---|
73 | virtual void RegisterComponent() = 0; |
---|
74 | virtual void DeregisterComponent() = 0; |
---|
75 | }; |
---|
76 | |
---|
77 | |
---|
78 | /* Engine abstract base class from which all engine component types should |
---|
79 | * inherit (e.g. cognitive and policy engines). Inherits all functions from the |
---|
80 | * ABC Component publically. |
---|
81 | */ |
---|
82 | class Engine : public Component |
---|
83 | { |
---|
84 | public: |
---|
85 | /* Connect to the remote control component, which will always be either |
---|
86 | * the VTCROSS shell or SML. Based on the status of the SML_present |
---|
87 | * bool, this function will also register the component or services. |
---|
88 | * |
---|
89 | * TODO I feel like the name of this function could be changed to be a |
---|
90 | * little more descriptive? |
---|
91 | */ |
---|
92 | virtual void ConnectToRemoteComponent(const char* serverName, \ |
---|
93 | const char* serverPort, const bool SML) = 0; |
---|
94 | |
---|
95 | /* Register or deregister services that this engine provides with the |
---|
96 | * service management layer. |
---|
97 | */ |
---|
98 | virtual void RegisterServices() = 0; |
---|
99 | virtual void DeregisterServices() = 0; |
---|
100 | }; |
---|
101 | |
---|
102 | |
---|
103 | /* Service Management Layer (SML) class declaration. The functions listed here |
---|
104 | * are required by the VTCROSS API for service-oriented VTCROSS radio |
---|
105 | * architectures. |
---|
106 | */ |
---|
107 | class ServiceManagementLayer : public Component |
---|
108 | { |
---|
109 | public: |
---|
110 | ServiceManagementLayer(); |
---|
111 | ~ServiceManagementLayer(); |
---|
112 | |
---|
113 | /* Overloaded constructor that creates an SML and connects it to the |
---|
114 | * shell with the passed hostname and port. |
---|
115 | */ |
---|
116 | ServiceManagementLayer(const char* serverName, const char* serverPort); |
---|
117 | |
---|
118 | /* Connect and register with the shell component at the passed hostname |
---|
119 | * and port. |
---|
120 | */ |
---|
121 | void ConnectToShell(const char* serverName, \ |
---|
122 | const char* serverPort); |
---|
123 | void SendComponentType(); |
---|
124 | void ShellSignalHandler(); |
---|
125 | void CESignalHandler(int32_t ID); |
---|
126 | void Shutdown(); |
---|
127 | void Reset(); |
---|
128 | void RegisterComponent(); |
---|
129 | void DeregisterComponent(); |
---|
130 | |
---|
131 | private: |
---|
132 | /* Receive the radio configuration settings from the shell and pass them |
---|
133 | * on to another component. |
---|
134 | */ |
---|
135 | void TransferRadioConfiguration(int32_t ID); |
---|
136 | |
---|
137 | /* Receive information regarding a completed 'experience' and pass it on |
---|
138 | * to the appropriate cognitive engine. |
---|
139 | */ |
---|
140 | void TransferExperience(int32_t ID); |
---|
141 | |
---|
142 | /* Listen for other components registering their available services with |
---|
143 | * the SML. |
---|
144 | */ |
---|
145 | void ReceiveServices(int32_t ID); |
---|
146 | void DeregisterServices(int32_t ID); |
---|
147 | |
---|
148 | /* Change the active mission of the radio to a new one and adjust radio |
---|
149 | * behavoir appropriately. |
---|
150 | */ |
---|
151 | void SetActiveMission(); |
---|
152 | |
---|
153 | void RegisterCognitiveEngine(int32_t ID); |
---|
154 | void DeregisterCognitiveEngine(int32_t ID); |
---|
155 | |
---|
156 | /* List all services provided to the radio by registered components. |
---|
157 | */ |
---|
158 | void ListServices(); |
---|
159 | |
---|
160 | /* Load/Relead the XML configuration file. |
---|
161 | */ |
---|
162 | void ReloadConfiguration(); |
---|
163 | void LoadConfiguration(); |
---|
164 | |
---|
165 | /* Create and initialize the DB to hold the services |
---|
166 | */ |
---|
167 | void CreateServicesDB(); |
---|
168 | |
---|
169 | /* Starts the SML Server and watches it for incoming messages |
---|
170 | */ |
---|
171 | void StartSMLServer(); |
---|
172 | |
---|
173 | /* The socket file descriptor information for the shell which this SML |
---|
174 | * is connected to. |
---|
175 | */ |
---|
176 | int32_t shellSocketFD; |
---|
177 | CE_Reg *CE_List; |
---|
178 | int32_t cogEngSrv; |
---|
179 | int16_t CEPort; |
---|
180 | uint16_t numberOfCognitiveEngines; |
---|
181 | uint32_t Current_ID; |
---|
182 | bool CE_Present; |
---|
183 | }; |
---|
184 | |
---|
185 | |
---|
186 | /* Policy Engine class declaration. All public functions are inherited from |
---|
187 | * parent classes. |
---|
188 | */ |
---|
189 | class PolicyEngine : public Engine |
---|
190 | { |
---|
191 | public: |
---|
192 | PolicyEngine(); |
---|
193 | ~PolicyEngine(); |
---|
194 | |
---|
195 | /* Overloaded constructor that creates a policy engine object and |
---|
196 | * connects it to either the shell or an SML, depening on the SML bool. |
---|
197 | */ |
---|
198 | PolicyEngine(const char* serverName, const char* serverPort, \ |
---|
199 | const bool SML); |
---|
200 | |
---|
201 | void SendComponentType(); |
---|
202 | void ConnectToRemoteComponent(const char* serverName, \ |
---|
203 | const char* serverPort, const bool SML); |
---|
204 | void WaitForSignal(); |
---|
205 | void Shutdown(); |
---|
206 | void Reset(); |
---|
207 | void RegisterComponent(); |
---|
208 | void DeregisterComponent(); |
---|
209 | |
---|
210 | void RegisterServices(); |
---|
211 | void DeregisterServices(); |
---|
212 | |
---|
213 | private: |
---|
214 | /* Parse and load/reload policies into the policy engine. |
---|
215 | */ |
---|
216 | void LoadPolicies(); |
---|
217 | void ReloadPolicies(); |
---|
218 | |
---|
219 | /* Return a decision made by the policy engine regarding a certain set |
---|
220 | * of transmission parameters. |
---|
221 | */ |
---|
222 | void SendPEDecision(struct Parameter pList[], struct Radio_Info *radio_info, \ |
---|
223 | int32_t decision_array[]); |
---|
224 | |
---|
225 | /* Validate a set of transmission parameters received from the radio. |
---|
226 | */ |
---|
227 | void ValidateParameters(); |
---|
228 | |
---|
229 | /* The SML_present bool reflects whether or not the remote component |
---|
230 | * this object is connected to is an SML. If it isn't, then it must be |
---|
231 | * a shell. The socketFD stores the socket file descriptor for this |
---|
232 | * connection. |
---|
233 | */ |
---|
234 | bool SML_present; |
---|
235 | int32_t commandSocketFD; |
---|
236 | }; |
---|
237 | |
---|
238 | |
---|
239 | /* Cognitive Engine class declaration. All public functions are inherited from |
---|
240 | * parent classes. |
---|
241 | */ |
---|
242 | class CognitiveEngine : public Engine |
---|
243 | { |
---|
244 | public: |
---|
245 | CognitiveEngine(); |
---|
246 | ~CognitiveEngine(); |
---|
247 | |
---|
248 | /* Overloaded constructor that creates a cognitive engine object and |
---|
249 | * connects it to either the shell or an SML, depening on the SML bool. |
---|
250 | */ |
---|
251 | CognitiveEngine(const char* serverName, const char* serverPort, \ |
---|
252 | const bool SML); |
---|
253 | |
---|
254 | void SendComponentType(); |
---|
255 | void ConnectToRemoteComponent(const char* serverName, \ |
---|
256 | const char* serverPort, const bool SML); |
---|
257 | void WaitForSignal(); |
---|
258 | void Shutdown(); |
---|
259 | void Reset(); |
---|
260 | void RegisterComponent(); |
---|
261 | void DeregisterComponent(); |
---|
262 | |
---|
263 | void RegisterServices(); |
---|
264 | void DeregisterServices(); |
---|
265 | |
---|
266 | private: |
---|
267 | /* Receive the transmitted radio configuration from the radio itself |
---|
268 | * (the CE will not always be local to the radio). |
---|
269 | */ |
---|
270 | void ReceiveRadioConfiguration(); |
---|
271 | |
---|
272 | /* Receive an 'experience' report from the radio. |
---|
273 | */ |
---|
274 | void ReceiveExperience(); |
---|
275 | |
---|
276 | /* Find the most optimal set of transmission parameters given certain |
---|
277 | * observables and possibly a service if the SML component is present |
---|
278 | * and active. |
---|
279 | */ |
---|
280 | Parameter *GetSolution(Observable *observables, Parameter *currentParameters); |
---|
281 | Parameter *GetSolution(Observable *observables, Parameter *currentParameters, std::string service); |
---|
282 | |
---|
283 | /* Receive a feedback from the radio regarding the performance of a |
---|
284 | * certain set of parameters, possibly associated with a service. |
---|
285 | * |
---|
286 | * Feedback is a single set of performance statistics that is achieved |
---|
287 | * corresponding to a specific set of transmission parameters. Feedback |
---|
288 | * helps a Cognitive Engine make better future decisions based upon |
---|
289 | * more accurate performance statistics. |
---|
290 | */ |
---|
291 | void ReceiveFeedback(Observable *observables,\ |
---|
292 | Parameter *parameters); |
---|
293 | void ReceiveFeedback(Observable *observables, \ |
---|
294 | Parameter *parameters, std::string service); |
---|
295 | |
---|
296 | |
---|
297 | /* BuildCognitiveEngine performs the CE implementation specific work |
---|
298 | * that defines the internals of a CE. For example, a CBR CE engine |
---|
299 | * would build the case-base reasoner or create the database, a neural |
---|
300 | * network based CE may perform the initial training, a GA based CE |
---|
301 | * may build the chromosome structure. |
---|
302 | */ |
---|
303 | void BuildCognitiveEngine(); |
---|
304 | |
---|
305 | /* The SML_present bool reflects whether or not the remote component |
---|
306 | * this object is connected to is an SML. If it isn't, then it must be |
---|
307 | * a shell. The socketFD stores the socket file descriptor for this |
---|
308 | * connection. |
---|
309 | */ |
---|
310 | bool SML_present; |
---|
311 | int32_t commandSocketFD; |
---|
312 | |
---|
313 | // TODO Need a description for these fields. Are these radio utilites, |
---|
314 | // parameters, and observables global to the whole system? |
---|
315 | Utility *uList; |
---|
316 | Parameter *pList; |
---|
317 | Observable *oList; |
---|
318 | struct Radio_Info *radioInfo; |
---|
319 | }; |
---|
320 | |
---|
321 | /* Cognitive Radio Shell class declaration. |
---|
322 | */ |
---|
323 | class CognitiveRadioShell |
---|
324 | { |
---|
325 | public: |
---|
326 | CognitiveRadioShell(); |
---|
327 | ~CognitiveRadioShell(); |
---|
328 | |
---|
329 | /* Overloaded constructor that creates a CR Shell object and loads the |
---|
330 | * passed radio configuration XML file. |
---|
331 | */ |
---|
332 | CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \ |
---|
333 | int16_t policyPort, int16_t commandPort); |
---|
334 | |
---|
335 | /* Ask for the component type of a remote component via sockets, or |
---|
336 | * respond to such a query sent to the shell itself. |
---|
337 | */ |
---|
338 | std::string GetRemoteComponentType(int32_t socketFD); |
---|
339 | void SendComponentType(int32_t socketFD); |
---|
340 | |
---|
341 | void Shutdown(); |
---|
342 | void Reset(); |
---|
343 | |
---|
344 | /* Start all the socket servers */ |
---|
345 | void StartShellServer(); |
---|
346 | |
---|
347 | int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \ |
---|
348 | Utility* &uList, Observable* &oList, Radio_Info* radioInfo); |
---|
349 | private: |
---|
350 | /* Parse and load/reload policies into the policy engine. |
---|
351 | */ |
---|
352 | void LoadPolicies(); |
---|
353 | void ReloadPolicies(); |
---|
354 | |
---|
355 | /* Register and Deregister the different components. |
---|
356 | */ |
---|
357 | void RegisterCognitiveEngine(int32_t socketFD); |
---|
358 | void DeregisterCognitiveEngine(int32_t socketFD); |
---|
359 | void RegisterPolicyEngine(int32_t socketFD); |
---|
360 | void DeregisterPolicyEngine(int32_t socketFD); |
---|
361 | void RegisterSML(int32_t socketFD); |
---|
362 | void DeregisterSML(int32_t socketFD); |
---|
363 | |
---|
364 | /* Handle a message that is received from a component. |
---|
365 | */ |
---|
366 | void HandleMessage(int32_t socketFD); |
---|
367 | |
---|
368 | /* Send optimization request to primary port FD. |
---|
369 | */ |
---|
370 | void GetOptimalParameters(int32_t socketFD); |
---|
371 | |
---|
372 | bool SendRadioConfiguration(int32_t socketFD); |
---|
373 | bool SendRadioExperience(int32_t socketFD); |
---|
374 | |
---|
375 | bool UpdateParameterPerformance(int32_t socketFD); |
---|
376 | |
---|
377 | bool SML_present; |
---|
378 | bool PE_present; |
---|
379 | bool CE_present; |
---|
380 | |
---|
381 | int32_t numberOfCognitiveEngines; |
---|
382 | int16_t primaryPort; |
---|
383 | int16_t policyPort; |
---|
384 | int16_t commandPort; |
---|
385 | |
---|
386 | int32_t ceSocketFD; |
---|
387 | int32_t commandSocketFD; |
---|
388 | int32_t policySocketFD; |
---|
389 | |
---|
390 | Utility *utils; |
---|
391 | Parameter *params; |
---|
392 | Observable *observables; |
---|
393 | struct Radio_Info *radio_info; |
---|
394 | }; |
---|
395 | |
---|
396 | #endif |
---|