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

Revision 431, 14.2 KB (checked in by bhilburn, 15 years ago)

Fixing some data typing issues, and some style bugs.

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