16#include "CLIInterface.h"
18void openFlow_saveHandle(NETSIM_ID d,
22 ptrOPENFLOW of = GET_OPENFLOW_VAR(d);
23 ptrHANDLEINFO h = calloc(1,
sizeof* h);
28 ptrHANDLEINFO t = of->handleInfo;
39ptrHANDLEINFO openFlow_getHandle(NETSIM_ID d,
42 ptrOPENFLOW of = GET_OPENFLOW_VAR(d);
43 ptrHANDLEINFO t = of->handleInfo;
44 ptrHANDLEINFO p = NULL;
52 of->handleInfo = t->next;
64static bool validate_input(CLIHANDLE handle, ptrCOMMANDARRAY cmd)
66 if (!isSDNController(pstruEventDetails->nDeviceId))
68 CLI_SEND_MESSAGE(handle,
"%d (%s) device is not a SDN controller\n",
69 DEVICE_CONFIGID(pstruEventDetails->nDeviceId),
70 DEVICE_NAME(pstruEventDetails->nDeviceId));
73 NETSIM_ID c = fn_NetSim_Stack_GetDeviceId_asName(cmd->commands[0]);
75 !isOPENFLOWConfigured(c))
77 CLI_SEND_MESSAGE(handle,
"%d (%s) device is not an OPEN_FLOW compatible device.\n",
91bool openflow_multiple_response_handler(ptrMULTARG arg,
98 CLI_PRINT_MESSAGE(arg->handle, msg, len);
100 CLI_STOP_WAITING(arg->handle);
104 openFlow_send_response(arg->d,
115void handle_cli_input()
117 CLIHANDLE handle = pstruEventDetails->szOtherDetails;
118 ptrCOMMANDARRAY cmd = CLI_GET_CMDARRAY_FROM_HANDLE(handle);
120 if (validate_input(handle, cmd))
122 CLI_SEND_MESSAGE(handle,
"Input is validated\n");
123 NETSIM_ID d = fn_NetSim_Stack_GetDeviceId_asName(cmd->commands[0]);
124 cmd = remove_first_word_from_commandArray(cmd);
125 if (d == pstruEventDetails->nDeviceId)
127 CLI_SEND_MESSAGE(handle,
"Command is for SDN Controller\n");
129 ptrMULTARG arg = calloc(1,
sizeof* arg);
131 arg->handle = handle;
133 char* ret = CLI_EXECUTE_COMMAND(cmd,
136 openflow_multiple_response_handler,
139 CLI_PRINT_MESSAGE(handle, ret, len);
143 CLI_STOP_WAITING(handle);
148 CLI_SEND_MESSAGE(handle,
"Sending command to client device %d\n", d);
149 if (!fn_NetSim_OPEN_FLOW_SendCommand(d, handle, cmd, cmd->length))
150 CLI_STOP_WAITING(handle);
155 CLI_STOP_WAITING(handle);
159char* openFlow_execute_command(
void* handle, NETSIM_ID d, UINT
id,
int* len,
bool* isMore)
161 ptrMULTARG arg = calloc(1,
sizeof* arg);
164 return CLI_EXECUTE_COMMAND(handle, d, len, openflow_multiple_response_handler, arg, isMore);
167void openFlow_print_response(NETSIM_ID d,
173 void* handle = openFlow_getHandle(d,
id);
176 CLI_PRINT_MESSAGE(handle, msg, len);
178 CLI_STOP_WAITING(handle);
180 openFlow_saveHandle(d,
id, handle);