root/vtcross/branches/bhilburn/src/policy_engines/default_policy_engine.cpp @ 151

Revision 151, 2.2 KB (checked in by bhilburn, 15 years ago)

Removed unnecesary includes.

Line 
1/* Virginia Tech Cognitive Radio Open Source Systems
2 * Virginia Tech, 2009
3 *
4 * TODO LICENSE INFORMATION GOES HERE
5 */
6
7/* TODO DESCRIPTION OF FILE.
8 *
9 * This file is a temporary demo of a policy engine using some of our socket
10 * communication functions. This is *not* an actual implementation of our
11 * defined PolicyEngine class.
12 */
13
14
15#include <cstdlib>
16#include <cstring>
17#include <stdint.h>
18
19#include "vtcross/common.h"
20#include "vtcross/containers.h"
21#include "vtcross/socket_comm.h"
22
23
24#define CR_PORT 30002
25
26
27int32_t
28ValidateTransmissionParameters(struct Parameter pList[], \
29        struct CE_Info *ce_info, int decision_array[])
30{
31    LOG("Policy Engine:: Policies Validated.\n");
32    for (size_t i = 0; i < ce_info->numParameters; i++)
33        decision_array[i] = 1;
34
35    return 1;
36}
37
38
39int32_t
40RegisterPE(int32_t socketFD)
41{
42    SendMessage(socketFD, "p_register");
43    LOG("Policy Engine:: Registration message sent.\n");
44    return 1;
45}
46
47
48int32_t
49SendCEDecision(int32_t socketFD, struct Parameter pList[], \
50        struct CE_Info *ce_info, int32_t decision_array[])
51{
52    char var[50];
53 
54    for (size_t i = 0; i < ce_info->numParameters; i++) {
55        sprintf(var, "%i", decision_array[i]);
56        SendMessage(socketFD, var);
57    }
58   
59    return 1;
60}
61
62
63int32_t
64ParsePolicies()
65{
66
67    LOG("Policy Engine:: Policies parsed.\n");
68    return 1;
69}
70
71
72int32_t
73main(int32_t argc, char *argv[])
74{
75    if(argc < 3)
76       ERROR(1, "Usage: %s hostname port\n", argv[0]);
77
78    int32_t decision_array[10];
79    struct Parameter pList[10];
80    struct CE_Info ce_info;
81    int32_t ret = 0;
82   
83    int32_t socketFD = ClientSocket(argv[1], argv[2]);
84
85    LOG("Policy Engine:: Parsing local policies.\n");
86    ParsePolicies();
87
88    RegisterPE(socketFD);
89
90    while(1) {
91        LOG("Policy Engine:: Waiting for Policy Check Request.\n");
92        ret = GetRequest(socketFD, pList, &ce_info);
93       
94        if(ret == 1) {
95            LOG("Policy Engine:: Validating Transmission Parameters.\n");
96            ValidateTransmissionParameters(pList, &ce_info, decision_array);   
97   
98            LOG("Policy Engine:: Sending Policy decision to Server.\n");
99            SendCEDecision(socketFD, pList, &ce_info, decision_array);
100        }
101    }
102   
103    return 0;
104}
Note: See TracBrowser for help on using the browser.