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

Revision 150, 2.3 KB (checked in by bhilburn, 15 years ago)

Ported the default policy engine demo to our new C++ codebase.

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 <netdb.h>
18#include <netinet/in.h>
19#include <stdint.h>
20#include <sys/types.h>
21#include <sys/socket.h>
22
23#include "vtcross/common.h"
24#include "vtcross/containers.h"
25#include "vtcross/socket_comm.h"
26
27
28#define CR_PORT 30002
29
30
31int32_t
32ValidateTransmissionParameters(struct Parameter pList[], \
33        struct CE_Info *ce_info, int decision_array[])
34{
35    LOG("Policy Engine:: Policies Validated.\n");
36    for (size_t i = 0; i < ce_info->numParameters; i++)
37        decision_array[i] = 1;
38
39    return 1;
40}
41
42
43int32_t
44RegisterPE(int32_t socketFD)
45{
46    SendMessage(socketFD, "p_register");
47    LOG("Policy Engine:: Registration message sent.\n");
48    return 1;
49}
50
51
52int32_t
53SendCEDecision(int32_t socketFD, struct Parameter pList[], \
54        struct CE_Info *ce_info, int32_t decision_array[])
55{
56    char var[50];
57 
58    for (size_t i = 0; i < ce_info->numParameters; i++) {
59        sprintf(var, "%i", decision_array[i]);
60        SendMessage(socketFD, var);
61    }
62   
63    return 1;
64}
65
66
67int32_t
68ParsePolicies()
69{
70
71    LOG("Policy Engine:: Policies parsed.\n");
72    return 1;
73}
74
75
76int32_t
77main(int32_t argc, char *argv[])
78{
79    if(argc < 3)
80       ERROR(1, "Usage: %s hostname port\n", argv[0]);
81
82    int32_t decision_array[10];
83    struct Parameter pList[10];
84    struct CE_Info ce_info;
85    int32_t ret = 0;
86   
87    int32_t socketFD = ClientSocket(argv[1], argv[2]);
88
89    LOG("Policy Engine:: Parsing local policies.\n");
90    ParsePolicies();
91
92    RegisterPE(socketFD);
93
94    while(1) {
95        LOG("Policy Engine:: Waiting for Policy Check Request.\n");
96        ret = GetRequest(socketFD, pList, &ce_info);
97       
98        if(ret == 1) {
99            LOG("Policy Engine:: Validating Transmission Parameters.\n");
100            ValidateTransmissionParameters(pList, &ce_info, decision_array);   
101   
102            LOG("Policy Engine:: Sending Policy decision to Server.\n");
103            SendCEDecision(socketFD, pList, &ce_info, decision_array);
104        }
105    }
106   
107    return 0;
108}
Note: See TracBrowser for help on using the browser.