Applicable Versions
NetSim Standard
NetSim Pro


Applicable Releases
v11.1v12


Users can add new commands in addition to those that are currently supported by SDN/Interactive Simulation command set. This can be achieved by modifying the NetSim’s CLI interpreter source codes that are open for user modification.


In this example we have added commands to retrieve device's x, y and z coordinates. This is achieved by adding new set of commands to the command library and defining functions to validate and execute the commands.We have added the following commands 

device_x <DEVICE_NAME>

device_y <DEVICE_NAME>

device_z <DEVICE_NAME> 

which takes the device_name as a parameter along with it and returns the appropriate coordinate value back to the client program.


A new file Device_Properties.c is added to the CLIInterpretor Project, which contains the following source code:

#include "main.h"
#include <signal.h>
#include "CLI.h"
#include "../IP/IP.h"

bool validate_device_x_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
{
  if (command->length - index < 2)
  {
    send_message(info, "USAGE: device_x deviceName\n");
    return false;
  }

  if (_stricmp(command->commands[index], "device_x"))
    return false;

  if (!isCommandAsDeviceName(command->commands[index + 1]))
  {
    
      send_message(info, "%s is not a valid device name.\n",
        command->commands[index + 1]);
      return false;
    
  }
  return true;
}
bool validate_device_y_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
{
  if (command->length - index < 2)
  {
    send_message(info, "USAGE: device_y deviceName\n");
    return false;
  }

  if (_stricmp(command->commands[index], "device_y"))
    return false;

  if (!isCommandAsDeviceName(command->commands[index + 1]))
  {

    send_message(info, "%s is not a valid device name.\n",
      command->commands[index + 1]);
    return false;

  }
  return true;
}
bool validate_device_z_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index)
{
  if (command->length - index < 2)
  {
    send_message(info, "USAGE: device_z deviceName\n");
    return false;
  }

  if (_stricmp(command->commands[index], "device_z"))
    return false;

  if (!isCommandAsDeviceName(command->commands[index + 1]))
  {

    send_message(info, "%s is not a valid device name.\n",
      command->commands[index + 1]);
    return false;

  }
  return true;
}

void execute_device_x_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
{
  NETSIM_ID dest;
  if (isCommandAsDeviceName(command->commands[index + 1]))
  {
    dest = fn_NetSim_Stack_GetDeviceId_asName(command->commands[index + 1]);
    send_message(info, "%f\n", DEVICE_POSITION(dest)->X);
    return;
  }  

}
void execute_device_y_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
{
  NETSIM_ID dest;
  if (isCommandAsDeviceName(command->commands[index + 1]))
  {
    dest = fn_NetSim_Stack_GetDeviceId_asName(command->commands[index + 1]);
    send_message(info, "%f\n", DEVICE_POSITION(dest)->Y);
    return;
  }

}
void execute_device_z_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, int index, NETSIM_ID d)
{
  NETSIM_ID dest;
  if (isCommandAsDeviceName(command->commands[index + 1]))
  {
    dest = fn_NetSim_Stack_GetDeviceId_asName(command->commands[index + 1]);
    send_message(info, "%f\n", DEVICE_POSITION(dest)->Z);
    return;
  }

}


Further modifications are done to the existing validate_comand() function that is part of the SimulationCommand.c file to make calls to the functions newly added in the Device_properties.c file as shown below:

bool validate_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command)
{
  int index = 0;
  if (!info->promptString)
  {
    if (isCommandAsDeviceName(command->commands[0]))
      index = 1;

    if (!_stricmp(command->commands[index], "route"))
      return validate_route_command(info, command, index);

    if (!_stricmp(command->commands[index], "acl"))
      return validate_acl_command(info, command, index);

    if (!_stricmp(command->commands[index], CMD_ACLCONFIG))
      return true;

    if (!_stricmp(command->commands[index], "ping"))
      return validate_ping_command(info, command, index);

    if (!_stricmp(command->commands[index], "device_x"))
      return validate_device_x_command(info, command, index);

    if (!_stricmp(command->commands[index], "device_y"))
      return validate_device_y_command(info, command, index);

    if (!_stricmp(command->commands[index], "device_z"))
      return validate_device_z_command(info, command, index);

  }
  else
  {
    if (strstr(info->promptString, CMD_ACLCONFIG))
      return validate_aclconfig_command(info, command, index);
  }

  send_message(info, "%s command is not a valid command.\n",
         command->commands[index]);
  return false;
}

And also modifications are done to the existing execute_command() function that is part of the SimulationCommand.c file to make calls to the functions newly added in the Device_properties.c file as shown below:

void execute_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command, NETSIM_ID d)
{
  int index = 0;
  if (info->promptString)
  { 
    if (strstr(info->promptString, CMD_ACLCONFIG))
      execute_prompt_aclconfig_command(info, command, index, d);
  }
  else
  {
    if (isCommandAsDeviceName(command->commands[0]))
    {
      d = fn_NetSim_Stack_GetDeviceId_asName(command->commands[0]);
      index = 1;
    }

    if (!_stricmp(command->commands[index], "route"))
      execute_route_command(info, command, index, d);
    else if (!_stricmp(command->commands[index], "ACL"))
      execute_acl_command(info, command, index, d);
    else if (!_stricmp(command->commands[index], "ACLCONFIG"))
      execute_aclconfig_command(info, command, index, d);
    else if (!_stricmp(command->commands[index], "ping"))
      execute_ping_command(info, command, index, d);
    else if (!_stricmp(command->commands[index], "device_x"))
      execute_device_x_command(info, command, index, d);
    else if (!_stricmp(command->commands[index], "device_y"))
      execute_device_y_command(info, command, index, d);
    else if (!_stricmp(command->commands[index], "device_z"))
      execute_device_z_command(info, command, index, d);
  }

}



A MANET network scenario with four wireless nodes as shown below is considered.



In this case we have passed commands to retrieve the X and Y coordinates of node N1 and N2