NetSim Source Code Help
Loading...
Searching...
No Matches
SimulationCommand.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 <signal.h>
16#include "CLI.h"
17
18bool isCommandAsDeviceName(char* name)
19{
20 NETSIM_ID i;
21 for (i = 0; i < NETWORK->nDeviceCount; i++)
22 {
24 return true;
25 }
26 return false;
27}
28
30{
31 int index = 0;
32 if (!info->promptString)
33 {
34 if (isCommandAsDeviceName(command->commands[0]))
35 index = 1;
36
37 if (!_stricmp(command->commands[index], "route"))
38 return validate_route_command(info, command, index);
39
40 if (!_stricmp(command->commands[index], "acl"))
41 return validate_acl_command(info, command, index);
42
43 if (!_stricmp(command->commands[index], CMD_ACLCONFIG))
44 return true;
45
46 if (!_stricmp(command->commands[index], "ping"))
47 return validate_ping_command(info, command, index);
48 }
49 else
50 {
51 if (strstr(info->promptString, CMD_ACLCONFIG))
52 return validate_aclconfig_command(info, command, index);
53 }
54
55 send_message(info, "%s command is not a valid command.\n",
56 command->commands[index]);
57 return false;
58}
59
61{
62 int index = 0;
63 if (info->promptString)
64 {
65 if (strstr(info->promptString, CMD_ACLCONFIG))
66 execute_prompt_aclconfig_command(info, command, index, d);
67 }
68 else
69 {
70 if (isCommandAsDeviceName(command->commands[0]))
71 {
73 index = 1;
74 }
75
76 if (!_stricmp(command->commands[index], "route"))
77 execute_route_command(info, command, index, d);
78 else if (!_stricmp(command->commands[index], "ACL"))
79 execute_acl_command(info, command, index, d);
80 else if (!_stricmp(command->commands[index], "ACLCONFIG"))
81 execute_aclconfig_command(info, command, index, d);
82 else if (!_stricmp(command->commands[index], "ping"))
83 execute_ping_command(info, command, index, d);
84 }
85
86}
87
89{
91 memset(&pevent, 0, sizeof pevent);
93 pevent.nDeviceId = info->deviceId;
94 pevent.nDeviceType = DEVICE_TYPE(info->deviceId);
95 pevent.nEventType = TIMER_EVENT;
97 pevent.szOtherDetails = FORM_CLI_HANDLE(command, info);
98 fnpAddEvent(&pevent);
99 if (info->clientType == CLIENTTYPE_SOCKET)
100 {
101 info->CLIENT.sockClient.iswait = true;
102 WaitOnAddress(&info->CLIENT.sockClient.iswait,
104 sizeof info->CLIENT.sockClient.iswait,
105 INFINITE);
106 }
107}
void execute_acl_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: ACLCommand.c:35
bool validate_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
Definition: ACLCommand.c:95
void execute_prompt_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: ACLCommand.c:139
void execute_aclconfig_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: ACLCommand.c:59
bool validate_acl_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
Definition: ACLCommand.c:49
unsigned int NETSIM_ID
Definition: Animation.h:45
void execute_ping_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: Ping.c:64
bool validate_ping_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
Definition: Ping.c:21
CLIHANDLE FORM_CLI_HANDLE(ptrCOMMANDARRAY cmd, ptrCLIENTINFO info)
bool validate_route_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
Definition: RouteCommand.c:35
void execute_route_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
Definition: RouteCommand.c:150
@ CLIENTTYPE_SOCKET
Definition: CLI.h:26
void send_message(ptrCLIENTINFO info, char *msg,...)
#define CMD_ACLCONFIG
Definition: CLI.h:18
#define _stricmp
Definition: Linux.h:127
#define INFINITE
Definition: Linux.h:82
void execute_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, NETSIM_ID d)
bool isCommandAsDeviceName(char *name)
bool validate_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command)
void pass_to_SDNModule(ptrCLIENTINFO info, ptrCOMMANDARRAY command)
EXPORTED double ldEventTime
Definition: Stack.h:838
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asName(const char *name)
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
@ APP_PROTOCOL_OPENFLOW
Definition: Stack.h:158
#define MILLISECOND
Definition: Stack.h:59
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
@ TIMER_EVENT
Definition: Stack.h:114
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
NETSIM_Name szDeviceName
Definition: Stack.h:713
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
NETSIM_ID nDeviceId
Definition: Stack.h:750
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
struct stru_NetSim_Device ** ppstruDeviceList
Definition: Stack.h:737
CLIENTTYPE clientType
Definition: CLI.h:71
union stru_clientInfo::client CLIENT
char * promptString
Definition: CLI.h:82
NETSIM_ID deviceId
Definition: CLI.h:79
bool dontUseMe
Definition: CLI.h:60
SOCKCLIENTINFO sockClient
Definition: CLI.h:74