root/vtcross/branches/fixingSML/src/include/vtcross/components.h @ 460

Revision 460, 14.3 KB (checked in by bhilburn, 15 years ago)

Mostly whitespace fixes. Only commiting so I can merge changes and
delete this branch.

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