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

Revision 285, 13.3 KB (checked in by wrodgers, 15 years ago)

updating SML demo

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