root/vtcross/trunk/src/include/vtcross/components.h @ 228

Revision 228, 12.4 KB (checked in by trnewman, 15 years ago)

Added sending current parameters in the libvt request optimization function.

Added guts to the CBR so it actually creates an sql db and searches it.

Line 
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 */
33class 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 */
82class 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 */
107class 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
124        void SendComponentType();
125        void WaitForSignal();
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();
136
137        /* Receive information regarding a completed 'experience' and pass it on
138         * to the appropriate cognitive engine.
139         */
140        void TransferExperience();
141       
142        /* Listen for other components registering their available services with
143         * the SML.
144         */
145        void ReceiveServices();
146
147        /* Change the active mission of the radio to a new one and adjust radio
148         * behavoir appropriately.
149         */
150        void SetActiveMission();
151
152        /* List all services provided to the radio by registered components.
153         */
154        void ListServices();
155
156        /* Load/Relead the XML configuration file.
157         */
158        void ReloadConfiguration();
159        void LoadConfiguration();
160
161        /* The socket file descriptor information for the shell which this SML
162         * is connected to.
163         */
164        int32_t shellSocketFD;
165};
166
167
168/* Policy Engine class declaration.  All public functions are inherited from
169 * parent classes.
170 */
171class PolicyEngine : public Engine
172{
173    public:
174        PolicyEngine();
175        ~PolicyEngine();
176
177        /* Overloaded constructor that creates a policy engine object and
178         * connects it to either the shell or an SML, depening on the SML bool.
179         */
180        PolicyEngine(const char* serverName, const char* serverPort, \
181                const bool SML);
182
183        void SendComponentType();
184        void ConnectToRemoteComponent(const char* serverName, \
185                const char* serverPort, const bool SML);
186        void WaitForSignal();
187        void Shutdown();
188        void Reset();
189        void RegisterComponent();
190        void DeregisterComponent();
191
192        void RegisterServices();
193        void DeregisterServices();
194
195    private:
196        /* Parse and load/reload policies into the policy engine.
197         */
198        void LoadPolicies();
199        void ReloadPolicies();
200
201        /* Return a decision made by the policy engine regarding a certain set
202         * of transmission parameters.
203         */
204        void SendPEDecision(struct Parameter pList[], struct Radio_Info *radio_info, \
205                int32_t decision_array[]);
206
207        /* Validate a set of transmission parameters received from the radio.
208         */
209        void ValidateParameters();
210
211        /* The SML_present bool reflects whether or not the remote component
212         * this object is connected to is an SML.  If it isn't, then it must be
213         * a shell.  The socketFD stores the socket file descriptor for this
214         * connection.
215         */
216        bool SML_present;
217        int32_t commandSocketFD;
218};
219
220
221/* Cognitive Engine class declaration.  All public functions are inherited from
222 * parent classes.
223 */
224class CognitiveEngine : public Engine
225{
226    public:
227        CognitiveEngine();
228        ~CognitiveEngine();
229
230        /* Overloaded constructor that creates a cognitive engine object and
231         * connects it to either the shell or an SML, depening on the SML bool.
232         */
233        CognitiveEngine(const char* serverName, const char* serverPort, \
234                const bool SML);
235       
236        void SendComponentType();
237        void ConnectToRemoteComponent(const char* serverName, \
238                const char* serverPort, const bool SML);
239        void WaitForSignal();
240        void Shutdown();
241        void Reset();
242        void RegisterComponent();
243        void DeregisterComponent();
244
245        void RegisterServices();
246        void DeregisterServices();
247
248    private:
249        /* Receive the transmitted radio configuration from the radio itself
250         * (the CE will not always be local to the radio).
251         */
252        void ReceiveRadioConfiguration();
253
254        /* Receive an 'experience' report from the radio.
255         */
256        void ReceiveExperience();
257
258        /* Find the most optimal set of transmission parameters given certain
259         * observables and possibly a service if the SML component is present
260         * and active.
261         */
262        Parameter *GetSolution(Observable *observables, Parameter *currentParameters);
263        Parameter *GetSolution(Observable *observables, Parameter *currentParameters, std::string service);
264
265        /* Receive a feedback from the radio regarding the performance of a
266         * certain set of parameters, possibly associated with a service.
267         *
268         * Feedback is a single set of performance statistics that is achieved
269         * corresponding to a specific set of transmission parameters.  Feedback
270         * helps a Cognitive Engine make better future decisions based upon
271         * more accurate performance statistics.
272         */
273        void ReceiveFeedback(Observable *observables,\
274                Parameter *parameters, Utility *utilities);
275        void ReceiveFeedback(Observable *observables, \
276                Parameter *parameters, Utility *utilities, std::string service);
277
278
279                /* BuildCognitiveEngine performs the CE implementation specific work
280                 * that defines the internals of a CE.  For example, a CBR CE engine
281                 * would build the case-base reasoner or create the database, a neural
282                 * network based CE may perform the initial training, a GA based CE
283                 * may build the chromosome structure.
284                 */
285                void BuildCognitiveEngine();
286
287        /* The SML_present bool reflects whether or not the remote component
288         * this object is connected to is an SML.  If it isn't, then it must be
289         * a shell.  The socketFD stores the socket file descriptor for this
290         * connection.
291         */
292        bool SML_present;
293        int32_t commandSocketFD;
294       
295        Utility * uList;
296        Parameter * pList;
297        Observable * oList;
298        struct Radio_Info * radioInfo;
299};
300
301/* Cognitive Radio Shell class declaration.
302 */
303class CognitiveRadioShell
304{
305    public:
306        CognitiveRadioShell();
307        ~CognitiveRadioShell();
308
309        /* Overloaded constructor that creates a CR Shell object and loads the
310         * passed radio configuration XML file.
311         */
312        CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \
313            int16_t policyPort, int16_t commandPort);
314
315        /* Ask for the component type of a remote component via sockets, or
316         * respond to such a query sent to the shell itself.
317         */
318        std::string GetRemoteComponentType(int32_t socketFD);
319        void SendComponentType(int32_t socketFD);
320
321        void Shutdown();
322        void Reset();
323       
324        /* Start all the socket servers */
325        void StartShellServer();
326
327        int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \
328            Utility* &uList, Observable* &oList, Radio_Info* radioInfo);
329    private:
330        /* Parse and load/reload policies into the policy engine.
331         */
332        void LoadPolicies();
333        void ReloadPolicies();
334
335        /* Register and Deregister the different components.
336         */
337        void RegisterCognitiveEngine(int32_t socketFD);
338        void DeregisterCognitiveEngine(int32_t socketFD);
339        void RegisterPolicyEngine(int32_t socketFD);
340        void DeregisterPolicyEngine(int32_t socketFD);
341        void RegisterSML(int32_t socketFD);
342        void DeregisterSML(int32_t socketFD);
343
344        /* Handle a message that is received from a component.
345         */
346        void HandleMessage(int32_t socketFD);
347       
348        /* Send optimization request to primary port FD.
349         */
350        void GetOptimalParameters(int32_t socketFD);
351
352        bool SendRadioConfiguration(int32_t socketFD);
353        bool SendRadioExperience(int32_t socketFD);
354 
355        bool SML_present;
356        bool PE_present;
357        bool CE_present;
358       
359        int32_t numberOfCognitiveEngines;
360        int16_t primaryPort;
361        int16_t policyPort;
362        int16_t commandPort;
363
364        int32_t ceSocketFD;
365        int32_t commandSocketFD;
366        int32_t policySocketFD;
367
368        Utility *utils;
369        Parameter *params;
370        Observable *observables;
371        struct Radio_Info *radio_info;
372};
373
374#endif
Note: See TracBrowser for help on using the browser.