NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
SimulationCommand.c
1/************************************************************************************
2* Copyright (C) 2023 *
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 {
23 if (!_stricmp(name, NETWORK->ppstruDeviceList[i]->szDeviceName))
24 return true;
25 }
26 return false;
27}
28
29bool validate_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command)
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
60void execute_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, NETSIM_ID d)
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 {
72 d = fn_NetSim_Stack_GetDeviceId_asName(command->commands[0]);
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
88void pass_to_SDNModule(ptrCLIENTINFO info, ptrCOMMANDARRAY command)
89{
90 NetSim_EVENTDETAILS pevent;
91 memset(&pevent, 0, sizeof pevent);
92 pevent.dEventTime = ldEventTime+MILLISECOND;
93 pevent.nDeviceId = info->deviceId;
94 pevent.nDeviceType = DEVICE_TYPE(info->deviceId);
95 pevent.nEventType = TIMER_EVENT;
96 pevent.nProtocolId = APP_PROTOCOL_OPENFLOW;
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,
103 &info->CLIENT.sockClient.dontUseMe,
104 sizeof info->CLIENT.sockClient.iswait,
105 INFINITE);
106 }
107}