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

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

Minor changes to support SML.

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