CLI

Overview

Declarations of API for TAPI CLI. More…

// enums

enum tapi_cli_csap_type;
enum tapi_cli_prompt_t;

// global variables

const char*const tapi_cli_csap_type_name[];
const char*const tapi_cli_redhat_cprompt_dflt;
const char*const tapi_cli_debian_cprompt_dflt;
const char*const tapi_cli_serial_lprompt_dflt;
const char*const tapi_cli_serial_pprompt_dflt;
const char*const tapi_cli_telnet_lprompt_dflt;
const char*const tapi_cli_telnet_pprompt_dflt;
const char*const tapi_cli_ssh_lprompt_dflt;
const char*const tapi_cli_ssh_pprompt_dflt;
const char*const tapi_cli_shell_lprompt_dflt;
const char*const tapi_cli_shell_pprompt_dflt;

// global functions

int tapi_cli_csap_local_create(const char* ta_name, int sid, const char* device, tapi_cli_prompt_t command_prompt_type, const char* command_prompt, tapi_cli_prompt_t login_prompt_type, const char* login_prompt, const char* login_name, tapi_cli_prompt_t password_prompt_type, const char* password_prompt, const char* password, csap_handle_t* cli_csap);
int tapi_cli_csap_remote_create(const char* ta_name, int sid, int type, const char* host, int port, tapi_cli_prompt_t command_prompt_type, const char* command_prompt, tapi_cli_prompt_t login_prompt_type, const char* login_prompt, const char* login_name, tapi_cli_prompt_t password_prompt_type, const char* password_prompt, const char* password, csap_handle_t* cli_csap);
int tapi_cli_csap_shell_create(const char* ta_name, int sid, const char* shell_args, tapi_cli_prompt_t command_prompt_type, const char* command_prompt, tapi_cli_prompt_t login_prompt_type, const char* login_prompt, const char* login_name, tapi_cli_prompt_t password_prompt_type, const char* password_prompt, const char* password, csap_handle_t* cli_csap);
int tapi_cli_csap_create(const char* ta_name, int sid, const char* buf, csap_handle_t* cli_csap);
int tapi_cli_send(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command);
int tapi_cli_send_recv_with_prompts(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command, char** msg, unsigned int timeout, tapi_cli_prompt_t cmd_prompt_type, const char* cmd_prompt, tapi_cli_prompt_t passwd_prompt_type, const char* passwd_prompt);
static int tapi_cli_send_recv(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command, char** msg, unsigned int timeout);
static int tapi_cli_send_recv_with_prompt(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command, char** msg, unsigned int timeout, tapi_cli_prompt_t cmd_prompt_type, const char* cmd_prompt);

// macros

#define TAPI_CLI_CSAP_CREATE_SERIAL(ta_name, sid, device, user, pwd, cprompt, cli_csap)
#define TAPI_CLI_CSAP_CREATE_SHELL(ta_name, sid, shell_args, cprompt, lprompt, user, pprompt, pwd, cli_csap)
#define TAPI_CLI_CSAP_CREATE_SSH(ta_name, sid, host, user, pwd, cprompt, cli_csap)
#define TAPI_CLI_CSAP_CREATE_TELNET(ta_name, sid, host, user, pwd, cprompt, cli_csap)
#define TAPI_CLI_SSH_PORT_DFLT
#define TAPI_CLI_TELNET_PORT_DFLT

Detailed Documentation

Declarations of API for TAPI CLI.

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Global Variables

const char*const tapi_cli_csap_type_name[]

CLI CSAP type names

const char*const tapi_cli_redhat_cprompt_dflt

Default command prompt on redhat is ‘[…]$ ‘

const char*const tapi_cli_debian_cprompt_dflt

Default command prompt on debian is ‘…$ ‘

const char*const tapi_cli_serial_lprompt_dflt

Default login prompt for serial console is ‘[L|l]ogin: ‘

const char*const tapi_cli_serial_pprompt_dflt

Default password prompt for serial console is ‘[P|p]assword: ‘

const char*const tapi_cli_telnet_lprompt_dflt

Default login prompt for telnet console is ‘Login: ‘

const char*const tapi_cli_telnet_pprompt_dflt

Default password prompt for telnet console is ‘[P|p]assword: ‘

const char*const tapi_cli_ssh_lprompt_dflt

There is no default login prompt for ssh console

const char*const tapi_cli_ssh_pprompt_dflt

Default password prompt for ssh console is ‘[P|p]assword: ‘

const char*const tapi_cli_shell_lprompt_dflt

Default login prompt for shell console is ‘[L|l]ogin: ‘

const char*const tapi_cli_shell_pprompt_dflt

Default password prompt for shell console is ‘[P|p]assword: ‘

Global Functions

int tapi_cli_csap_local_create(const char* ta_name, int sid, const char* device, tapi_cli_prompt_t command_prompt_type, const char* command_prompt, tapi_cli_prompt_t login_prompt_type, const char* login_prompt, const char* login_name, tapi_cli_prompt_t password_prompt_type, const char* password_prompt, const char* password, csap_handle_t* cli_csap)

Create common CLI CSAP on local device (using millicom).

Parameters:

ta_name

Test Agent name

sid

RCF session

device

Local device name

command_prompt_type

Expected command prompt type (plain or regular expression)

command_prompt

Expected command prompt (when commands may be sent)

login_prompt_type

Expected login prompt type (plain or regular expression)

login_prompt

Expected login prompt (when login name may be sent)

login_name

Login name to be sent if login prompt is detected

password_prompt_type

Expected password prompt type (plain or regular expression)

password_prompt

Expected password prompt (when password may be sent)

password

Password to be sent if password prompt is detected

cli_csap

Identifier of created CSAP (OUT)

Returns:

0 on success, otherwise standard or common TE error code.

int tapi_cli_csap_remote_create(const char* ta_name, int sid, int type, const char* host, int port, tapi_cli_prompt_t command_prompt_type, const char* command_prompt, tapi_cli_prompt_t login_prompt_type, const char* login_prompt, const char* login_name, tapi_cli_prompt_t password_prompt_type, const char* password_prompt, const char* password, csap_handle_t* cli_csap)

Create common CLI CSAP on remote connection (telnet or ssh).

Parameters:

ta_name

Test Agent name

sid

RCF session

type

Remote connection type (telnet or ssh)

host

Remote host name

port

Remote port number

command_prompt_type

Expected command prompt type (plain or regular expression)

command_prompt

Expected command prompt (when commands may be sent)

login_prompt_type

Expected login prompt type (plain or regular expression)

login_prompt

Expected login prompt (when login name may be sent)

login_name

Login name to be sent if login prompt is detected

password_prompt_type

Expected password prompt type (plain or regular expression)

password_prompt

Expected password prompt (when password may be sent)

password

Password to be sent if password prompt is detected

cli_csap

Identifier of created CSAP (OUT)

Returns:

0 on success, otherwise standard or common TE error code.

int tapi_cli_csap_shell_create(const char* ta_name, int sid, const char* shell_args, tapi_cli_prompt_t command_prompt_type, const char* command_prompt, tapi_cli_prompt_t login_prompt_type, const char* login_prompt, const char* login_name, tapi_cli_prompt_t password_prompt_type, const char* password_prompt, const char* password, csap_handle_t* cli_csap)

Create common CLI CSAP using shell.

Parameters:

ta_name

Test Agent name

sid

RCF session

shell_args

Arguments to shell interpreter

command_prompt_type

Expected command prompt type (plain or regular expression)

command_prompt

Expected command prompt (when commands may be sent)

login_prompt_type

Expected login prompt type (plain or regular expression)

login_prompt

Expected login prompt (when login name may be sent)

login_name

Login name to be sent if login prompt is detected

password_prompt_type

Expected password prompt type (plain or regular expression)

password_prompt

Expected password prompt (when password may be sent)

password

Password to be sent if password prompt is detected

cli_csap

Identifier of created CSAP (OUT)

Returns:

0 on success, otherwise standard or common TE error code.

int tapi_cli_csap_create(const char* ta_name, int sid, const char* buf, csap_handle_t* cli_csap)

Create common CLI CSAP.

Parameters:

ta_name

Test Agent name;

sid

RCF session;

buf

CLI CSAP initialisation string.

cli_csap

Identifier of created CSAP (OUT).

Returns:

zero on success, otherwise standard or common TE error code.

int tapi_cli_send(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command)

Sends CLI command according specified template from the CSAP. This function is blocking, returns after all commands are sent and CSAP operation finished.

Parameters:

ta_name

Test Agent name

sid

RCF session identifier

cli_csap

CSAP handle

command

Command string to be sent to CLI session

Returns:

zero on success, otherwise standard or common TE error code.

int tapi_cli_send_recv_with_prompts(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command, char** msg, unsigned int timeout, tapi_cli_prompt_t cmd_prompt_type, const char* cmd_prompt, tapi_cli_prompt_t passwd_prompt_type, const char* passwd_prompt)

Send specified command to the CSAP’s CLI session and receive response. This function is blocking, returns after all commands are sent and response is received or timeout ocured. The function allows to specify prompts to be used for this operation.

If necessary to update login prompt, login name or password for a particular command, please update this function adding new parameters.

Parameters:

ta_name

Test Agent name;

sid

RCF session identifier;

cli_csap

CSAP handle;

command

Command to send;

msg

Returned CLI response to command (memory for the response is allocated inside this routine);

timeout

CLI response timeout in seconds;

cmd_prompt_type

Type of command prompt;

cmd_prompt

Command prompt to use for command run;

passwd_prompt_type

Type of password prompt;

passwd_prompt

Password prompt value (NULL to use default);

Returns:

zero on success, otherwise standard or common TE error code.

static int tapi_cli_send_recv(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command, char** msg, unsigned int timeout)

Send specified command to the CSAP’s CLI session and receive response. This function is blocking, returns after all commands are sent and response is received or timeout ocured.

Parameters:

ta_name

Test Agent name;

sid

RCF session identifier;

cli_csap

CSAP handle;

command

Command to send;

msg

Returned CLI response to command (memory for the response is allocated inside this routine);

timeout

CLI response timeout in seconds;

Returns:

zero on success, otherwise standard or common TE error code.

static int tapi_cli_send_recv_with_prompt(const char* ta_name, int sid, csap_handle_t cli_csap, const char* command, char** msg, unsigned int timeout, tapi_cli_prompt_t cmd_prompt_type, const char* cmd_prompt)

Send specified command to the CSAP’s CLI session and receive response. The function allows to specify command prompt value to use while analyzing the response (suitable when switching between command views).

Parameters:

ta_name

Test Agent name;

sid

RCF session identifier;

cli_csap

CSAP handle;

command

Command to send;

msg

Returned CLI response to command (memory for the response is allocated inside this routine);

timeout

CLI response timeout in seconds;

cmd_prompt_type

Type of command prompt;

cmd_prompt

Command prompt to use for command run.

Returns:

zero on success, otherwise standard or common TE error code.

Macros

#define TAPI_CLI_CSAP_CREATE_SERIAL(ta_name, sid, device, user, pwd, cprompt, cli_csap)

Macro around tapi_cli_csap_local_create()

Parameters:

ta_name

Test agent name

sid

RCF session id

device

local device name

user

Login name to be sent if login prompt is detected

pwd

Password to be sent if password prompt is detected

cprompt

Expected command prompt (when commands may be sent)

cli_csap

Identifier of created CSAP

#define TAPI_CLI_CSAP_CREATE_SHELL(ta_name, sid, shell_args, cprompt, lprompt, user, pprompt, pwd, cli_csap)

Macro around tapi_cli_csap_shell_create() when connection type is TAPI_CLI_CSAP_TYPE_SHELL

Parameters:

ta_name

Test agent name

sid

RCF session id

shell_args

Shell arguments

user

Login name to be sent if login prompt is detected

pwd

Password to be sent if password prompt is detected

cprompt

Expected command prompt (when commands may be sent)

cli_csap

Identifier of created CSAP

#define TAPI_CLI_CSAP_CREATE_SSH(ta_name, sid, host, user, pwd, cprompt, cli_csap)

Macro around tapi_cli_csap_remote_create() when connection type is TAPI_CLI_CSAP_TYPE_SSH

Parameters:

ta_name

Test agent name

sid

RCF session id

host

Remote host name

user

Login name to be sent if login prompt is detected

pwd

Password to be sent if password prompt is detected

cprompt

Expected command prompt (when commands may be sent)

cli_csap

Identifier of created CSAP

#define TAPI_CLI_CSAP_CREATE_TELNET(ta_name, sid, host, user, pwd, cprompt, cli_csap)

Macro around tapi_cli_csap_remote_create() when connection type is TAPI_CLI_CSAP_TYPE_TELNET

Parameters:

ta_name

Test agent name

sid

RCF session id

host

Remote host name

user

Login name to be sent if login prompt is detected

pwd

Password to be sent if password prompt is detected

cprompt

Expected command prompt (when commands may be sent)

cli_csap

Identifier of created CSAP

#define TAPI_CLI_SSH_PORT_DFLT

Default ssh port is 22

#define TAPI_CLI_TELNET_PORT_DFLT

Default telnet port is 23