root/vtcross/branches/wrodgers/src/include/vtcross/components.h @ 275

Revision 275, 13.2 KB (checked in by wrodgers, 15 years ago)

Updated data management, added function descriptions, fixed a few errors

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);
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
191
192/* Policy Engine class declaration.  All public functions are inherited from
193 * parent classes.
194 */
195class PolicyEngine : public Engine
196{
197    public:
198        PolicyEngine();
199        ~PolicyEngine();
200
201        /* Overloaded constructor that creates a policy engine object and
202         * connects it to either the shell or an SML, depening on the SML bool.
203         */
204        PolicyEngine(const char* serverName, const char* serverPort, \
205                const bool SML);
206
207        void SendComponentType();
208        void ConnectToRemoteComponent(const char* serverName, \
209                const char* serverPort, const bool SML);
210        void WaitForSignal();
211        void Shutdown();
212        void Reset();
213        void RegisterComponent();
214        void DeregisterComponent();
215
216        void RegisterServices();
217        void DeregisterServices();
218
219    private:
220        /* Parse and load/reload policies into the policy engine.
221         */
222        void LoadPolicies();
223        void ReloadPolicies();
224
225        /* Return a decision made by the policy engine regarding a certain set
226         * of transmission parameters.
227         */
228        void SendPEDecision(struct Parameter pList[], struct Radio_Info *radio_info, \
229                int32_t decision_array[]);
230
231        /* Validate a set of transmission parameters received from the radio.
232         */
233        void ValidateParameters();
234
235        /* The SML_present bool reflects whether or not the remote component
236         * this object is connected to is an SML.  If it isn't, then it must be
237         * a shell.  The socketFD stores the socket file descriptor for this
238         * connection.
239         */
240        bool SML_present;
241        int32_t commandSocketFD;
242};
243
244
245/* Cognitive Engine class declaration.  All public functions are inherited from
246 * parent classes.
247 */
248class CognitiveEngine : public Engine
249{
250    public:
251        CognitiveEngine();
252        ~CognitiveEngine();
253
254        /* Overloaded constructor that creates a cognitive engine object and
255         * connects it to either the shell or an SML, depening on the SML bool.
256         */
257        CognitiveEngine(const char* serverName, const char* serverPort, \
258                const bool SML);
259       
260        void SendComponentType();
261        void ConnectToRemoteComponent(const char* serverName, \
262                const char* serverPort, const bool SML);
263        void WaitForSignal();
264        void Shutdown();
265        void Reset();
266        void RegisterComponent();
267        void DeregisterComponent();
268
269        void RegisterServices();
270        //void DeregisterServices();
271
272    private:
273        /* Receive the transmitted radio configuration from the radio itself
274         * (the CE will not always be local to the radio).
275         */
276        void ReceiveRadioConfiguration();
277
278        /* Receive an 'experience' report from the radio.
279         */
280        void ReceiveExperience();
281
282        /* Find the most optimal set of transmission parameters given certain
283         * observables and possibly a service if the SML component is present
284         * and active.
285         */
286        Parameter *GetSolution(Observable *observables, Parameter *currentParameters);
287        Parameter *GetSolution(Observable *observables, Parameter *currentParameters, std::string service);
288
289        /* Receive a feedback from the radio regarding the performance of a
290         * certain set of parameters, possibly associated with a service.
291         *
292         * Feedback is a single set of performance statistics that is achieved
293         * corresponding to a specific set of transmission parameters.  Feedback
294         * helps a Cognitive Engine make better future decisions based upon
295         * more accurate performance statistics.
296         */
297        void ReceiveFeedback(Observable *observables,\
298                Parameter *parameters);
299        void ReceiveFeedback(Observable *observables, \
300                Parameter *parameters, std::string service);
301
302
303                /* BuildCognitiveEngine performs the CE implementation specific work
304                 * that defines the internals of a CE.  For example, a CBR CE engine
305                 * would build the case-base reasoner or create the database, a neural
306                 * network based CE may perform the initial training, a GA based CE
307                 * may build the chromosome structure.
308                 */
309                void BuildCognitiveEngine();
310
311        /* The SML_present bool reflects whether or not the remote component
312         * this object is connected to is an SML.  If it isn't, then it must be
313         * a shell.  The socketFD stores the socket file descriptor for this
314         * connection.
315         */
316        bool SML_present;
317        int32_t commandSocketFD;
318       
319        // TODO Need a description for these fields.  Are these radio utilites,
320        // parameters, and observables global to the whole system?
321        Utility *uList;
322        Parameter *pList;
323        Observable *oList;
324        struct Radio_Info *radioInfo;
325};
326
327/* Cognitive Radio Shell class declaration.
328 */
329class CognitiveRadioShell
330{
331    public:
332        CognitiveRadioShell();
333        ~CognitiveRadioShell();
334
335        /* Overloaded constructor that creates a CR Shell object and loads the
336         * passed radio configuration XML file.
337         */
338        CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \
339            int16_t policyPort, int16_t commandPort);
340
341        /* Ask for the component type of a remote component via sockets, or
342         * respond to such a query sent to the shell itself.
343         */
344        std::string GetRemoteComponentType(int32_t socketFD);
345        void SendComponentType(int32_t socketFD);
346
347        void Shutdown();
348        void Reset();
349       
350        /* Start all the socket servers */
351        void StartShellServer();
352
353        int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \
354            Utility* &uList, Observable* &oList, Radio_Info* radioInfo);
355    private:
356        /* Parse and load/reload policies into the policy engine.
357         */
358        void LoadPolicies();
359        void ReloadPolicies();
360
361        /* Register and Deregister the different components.
362         */
363        void RegisterCognitiveEngine(int32_t socketFD);
364        void DeregisterCognitiveEngine(int32_t socketFD);
365        void RegisterPolicyEngine(int32_t socketFD);
366        void DeregisterPolicyEngine(int32_t socketFD);
367        void RegisterSML(int32_t socketFD);
368        void DeregisterSML(int32_t socketFD);
369
370        /* Handle a message that is received from a component.
371         */
372        void HandleMessage(int32_t socketFD);
373       
374        /* Send optimization request to primary port FD.
375         */
376        void GetOptimalParameters(int32_t socketFD);
377
378        bool SendRadioConfiguration(int32_t socketFD);
379        bool SendRadioExperience(int32_t socketFD);
380
381                bool UpdateParameterPerformance(int32_t socketFD);
382
383        bool SML_present;
384        bool PE_present;
385        bool CE_present;
386       
387        int32_t numberOfCognitiveEngines;
388        int16_t primaryPort;
389        int16_t policyPort;
390        int16_t commandPort;
391
392        int32_t ceSocketFD;
393        int32_t commandSocketFD;
394        int32_t policySocketFD;
395
396        Utility *utils;
397        Parameter *params;
398        Observable *observables;
399        struct Radio_Info *radio_info;
400};
401
402#endif
Note: See TracBrowser for help on using the browser.