NetSim Source Code Help
Loading...
Searching...
No Matches
CLIInterface.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi Kant Suman *
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "OpenFlow.h"
16#include "CLIInterface.h"
17
19 UINT id,
20 void* handle)
21{
23 ptrHANDLEINFO h = calloc(1, sizeof* h);
24 h->handle = handle;
25 h->id = id;
26 if (of->handleInfo)
27 {
29 while (t->next)
30 t = t->next;
31 t->next = h;
32 }
33 else
34 {
35 of->handleInfo = h;
36 }
37}
38
40 UINT id)
41{
44 ptrHANDLEINFO p = NULL;
45 while (t)
46 {
47 if (t->id == id)
48 {
49 if (p)
50 p->next = t->next;
51 else
52 of->handleInfo = t->next;
53 void* h = t->handle;
54 free(t);
55 return h;
56 }
57 p = t;
58 t = t->next;
59 }
60 return NULL;
61}
62
63
65{
67 {
68 CLI_SEND_MESSAGE(handle, "%d (%s) device is not a SDN controller\n",
71 return false;
72 }
74 if (!c ||
76 {
77 CLI_SEND_MESSAGE(handle, "%d (%s) device is not an OPEN_FLOW compatible device.\n",
78 c,
79 cmd->commands[0]);
80 return false;
81 }
82 return true;
83}
84
85typedef struct stru_multArgs
86{
89 void* handle;
92 char* msg,
93 int len,
94 bool isMore)
95{
96 if (!arg->id)
97 {
98 CLI_PRINT_MESSAGE(arg->handle, msg, len);
99 if (!isMore)
101 }
102 else
103 {
105 arg->id,
106 msg,
107 len,
108 isMore);
109 }
110 if (!isMore)
111 free(arg);
112 return isMore;
113}
114
116{
119
120 if (validate_input(handle, cmd))
121 {
122 CLI_SEND_MESSAGE(handle, "Input is validated\n");
126 {
127 CLI_SEND_MESSAGE(handle, "Command is for SDN Controller\n");
128 int len = 0;
129 ptrMULTARG arg = calloc(1, sizeof* arg);
130 arg->d = d;
131 arg->handle = handle;
132 bool isMore;
133 char* ret = CLI_EXECUTE_COMMAND(cmd,
134 d,
135 &len,
137 arg,
138 &isMore);
139 CLI_PRINT_MESSAGE(handle, ret, len);
140 if (!isMore)
141 {
142 free(arg);
144 }
145 }
146 else
147 {
148 CLI_SEND_MESSAGE(handle, "Sending command to client device %d\n", d);
151 }
152 }
153 else
154 {
156 }
157}
158
159char* openFlow_execute_command(void* handle, NETSIM_ID d, UINT id, int* len, bool* isMore)
160{
161 ptrMULTARG arg = calloc(1, sizeof* arg);
162 arg->d = d;
163 arg->id = id;
165}
166
168 UINT id,
169 void* msg,
170 int len,
171 bool isMore)
172{
173 void* handle = openFlow_getHandle(d, id);
174 if (handle)
175 {
176 CLI_PRINT_MESSAGE(handle, msg, len);
177 if (!isMore)
179 else
181 }
182}
unsigned int NETSIM_ID
Definition: Animation.h:45
static ANIM_HANDLE handle
Definition: BatteryModel.c:197
static bool validate_input(CLIHANDLE handle, ptrCOMMANDARRAY cmd)
Definition: CLIInterface.c:64
struct stru_multArgs * ptrMULTARG
void openFlow_print_response(NETSIM_ID d, UINT id, void *msg, int len, bool isMore)
Definition: CLIInterface.c:167
ptrHANDLEINFO openFlow_getHandle(NETSIM_ID d, UINT id)
Definition: CLIInterface.c:39
struct stru_multArgs MULTARG
bool openflow_multiple_response_handler(ptrMULTARG arg, char *msg, int len, bool isMore)
Definition: CLIInterface.c:91
void openFlow_saveHandle(NETSIM_ID d, UINT id, void *handle)
Definition: CLIInterface.c:18
char * openFlow_execute_command(void *handle, NETSIM_ID d, UINT id, int *len, bool *isMore)
Definition: CLIInterface.c:159
void handle_cli_input()
Definition: CLIInterface.c:115
void CLI_PRINT_MESSAGE(CLIHANDLE handle, char *msg, int len)
void CLI_SEND_MESSAGE(CLIHANDLE handle, char *msg,...)
ptrCOMMANDARRAY remove_first_word_from_commandArray(ptrCOMMANDARRAY c)
Definition: Command.c:70
void * CLIHANDLE
Definition: CLIInterface.h:64
void CLI_STOP_WAITING(CLIHANDLE handle)
char * CLI_EXECUTE_COMMAND(ptrCOMMANDARRAY cmd, NETSIM_ID d, int *len, bool(*multResp)(void *, char *msg, int len, bool isMore), void *arg, bool *isMore)
ptrCOMMANDARRAY CLI_GET_CMDARRAY_FROM_HANDLE(CLIHANDLE handle)
#define c
#define UINT
Definition: Linux.h:38
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
bool isOPENFLOWConfigured(NETSIM_ID d)
Definition: OpenFlow.c:194
#define GET_OPENFLOW_VAR(d)
Definition: OpenFlow.h:72
void openFlow_send_response(NETSIM_ID dev, UINT id, char *payload, int len, bool isMore)
Definition: OpenFlowMsg.c:145
bool isSDNController(NETSIM_ID d)
Definition: SDNController.c:17
bool fn_NetSim_OPEN_FLOW_SendCommand(NETSIM_ID dest, void *handle, void *command, UINT len)
Definition: OpenFlowMsg.c:110
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asName(const char *name)
#define DEVICE_NAME(DeviceId)
Definition: Stack.h:774
#define DEVICE_CONFIGID(DeviceId)
Definition: Stack.h:779
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
struct stru_HandleInfo * next
Definition: OpenFlow.h:50
void * handle
Definition: OpenFlow.h:49
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETSIM_ID d
Definition: CLIInterface.c:87
ptrHANDLEINFO handleInfo
Definition: OpenFlow.h:70