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