/* * * Copyright (c) 2018 Huawei Technologies Co.,Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "configuration_reader.h" #include "container_ip.h" #include "network.h" #include "nstack_log.h" #include "nstack_securec.h" #include "json.h" #include "spl_tcpip.h" #include #include #include #include "nsfw_maintain_api.h" NSTACK_STATIC struct config_data g_ip_module_buff; NSTACK_STATIC struct config_data *g_config_data; NSTACK_STATIC char ip_module_unix_socket[IP_MODULE_MAX_PATH_LEN + 1]; NSTACK_STATIC char ip_module_unix_socket_dir_path[IP_MODULE_MAX_PATH_LEN + 1]; //static unsigned long int g_thread_id = 0; #define MAX_CONNECTION_NUMBER 5 #define TCP_OOS_LEN_MAX 250 NSTACK_STATIC int read_configuration (); NSTACK_STATIC int unix_socket_listen (const char *servername); NSTACK_STATIC int process_query (); /***************************************************************************** * Prototype : is_digit_str * Description : check if a string contains only digit * Input : char *input * Output : 1 for yes, 0 for no * Return Value : int * Calls : * Called By : get_main_pid * *****************************************************************************/ NSTACK_STATIC int is_digit_str (char *input) { if (NULL == input || '\0' == input[0]) { return 0; } while (*input) { if (*input > '9' || *input < '0') { return 0; } input++; } return 1; } /***************************************************************************** * Prototype : process_query * Description : ./nStackCtrl -a query * Input : none * Output : none * Return Value : int * Calls : * Called By : * *****************************************************************************/ NSTACK_STATIC int process_query () { int retval; if (0 == g_config_data->param.type[0]) { return process_post (NULL, IP_MODULE_ALL, IP_MODULE_OPERATE_QUERY); } /*name & p are freed inside process_post */ if (0 == strcmp (g_config_data->param.type, IP_MODULE_TYPE_PORT)) { struct ip_action_param *p = malloc (sizeof (struct ip_action_param)); if (p == NULL) { NSOPR_LOGERR ("name allocation failed!"); NSOPR_SET_ERRINFO (NSCRTL_ERR, "mem alloc error!"); return -1; } retval = MEMSET_S (p, sizeof (struct ip_action_param), 0, sizeof (struct ip_action_param)); if (EOK != retval) { NSOPR_LOGERR ("MEMSET_S failed]ret=%d", retval); NSOPR_SET_ERRINFO (NSCRTL_ERR, "MEMSET_S error!"); free (p); return -1; } retval = STRCPY_S (p->container_id, sizeof (p->container_id), g_config_data->param.container_id); if (EOK != retval) { NSOPR_LOGERR ("STRCPY_S failed]ret=%d", retval); NSOPR_SET_ERRINFO (NSCRTL_ERR, "STRCPY_S error!"); free (p); return -1; } retval = STRCPY_S (p->port_name, sizeof (p->port_name), g_config_data->param.name); if (EOK != retval) { NSOPR_LOGERR ("STRCPY_S failed]ret=%d", retval); NSOPR_SET_ERRINFO (NSCRTL_ERR, "STRCPY_S error!"); free (p); return -1; } return process_post ((void *) p, IP_MODULE_IP, IP_MODULE_OPERATE_QUERY); } else if (0 == strcmp (g_config_data->param.type, IP_MODULE_TYPE_NETWORK)) { if (0 == g_config_data->param.name[0]) { return process_post (NULL, IP_MODULE_NETWORK_ALL, IP_MODULE_OPERATE_QUERY); } else { char *name = malloc (sizeof (g_config_data->param.name)); if (NULL == name) { NSOPR_LOGERR ("name allocation failed!"); NSOPR_SET_ERRINFO (NSCRTL_ERR, "mem alloc error!"); return -1; } retval = MEMSET_S (name, sizeof (g_config_data->param.name), 0, sizeof (g_config_data->param.name)); if (EOK != retval) { NSOPR_LOGERR ("MEMSET_S failed]ret=%d", retval); NSOPR_SET_ERRINFO (NSCRTL_ERR, "MEMSET_S error!"); free (name); return -1; } retval = STRCPY_S (name, sizeof (g_config_data->param.name), g_config_data->param.name); if (EOK != retval) { NSOPR_LOGERR ("STRCPY_S failed]ret=%d", retval); NSOPR_SET_ERRINFO (NSCRTL_ERR, "STRCPY_S error!"); free (name); return -1; } return process_post ((void *) name, IP_MODULE_NETWORK, IP_MODULE_OPERATE_QUERY); } } else if (0 == strcmp (g_config_data->param.type, IP_MODULE_TYPE_IP)) { if (0 == g_config_data->param.name[0]) { return process_post (NULL, IP_MODULE_IP_ALL, IP_MODULE_OPERATE_QUERY); } else { NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "input error!"); } } else { NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "input error!"); } return -1; } int read_ipmoduleoperatesetnet_configuration () { if (strcmp (g_config_data->param.type, IP_MODULE_TYPE_SETLOG) == 0) { if (NSCRTL_OK == setlog_level_value (g_config_data->param.name, g_config_data->param.value)) { NSOPR_LOGDBG ("set log level ok!"); } else { NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "input error!"); } } else if (strcmp (g_config_data->param.type, TCP_MODULE_TYPE_SET_OOS_LEN) == 0) { if (is_digit_str (g_config_data->param.value) == 0) { NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "Invalid value:value must be digital and smaller than %u]value=\"%s\"", TCP_OOS_LEN_MAX, g_config_data->param.value); return 0; } unsigned int value_len = strlen (g_config_data->param.value); if ((value_len >= 2) && (g_config_data->param.value[0] == '0')) { NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "Invalid value:value cannot start with 0"); return 0; } } else { NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "input error!"); } return 0; } /***************************************************************************** * Prototype : read_version * Description : Query Version by nStackCtrl * Input : None * Output : None * Return Value : int * Calls : * Called By : * *****************************************************************************/ int read_version () { int retVal; json_object *version = json_object_new_object (); if (NULL == version) { NSOPR_SET_ERRINFO (NSCRTL_ERR, "internal error for version=NULL!"); return NSCRTL_ERR; } json_object_object_add (version, "moudle", json_object_new_string (NSTACK_GETVER_MODULE)); json_object_object_add (version, "version", json_object_new_string (NSTACK_GETVER_VERSION)); json_object_object_add (version, "buildtime", json_object_new_string (NSTACK_GETVER_BUILDTIME)); json_object *version_array = json_object_new_array (); if (NULL == version_array) { json_object_put (version); NSOPR_SET_ERRINFO (NSCRTL_ERR, "internal error for version_array=NULL!"); return NSCRTL_ERR; } retVal = json_object_array_add (version_array, version); if (0 != retVal) { json_object_put (version_array); json_object_put (version); NSOPR_SET_ERRINFO (NSCRTL_ERR, "internal error for json_object_array_add failed!"); return NSCRTL_ERR; } const char *str = json_object_to_json_string (version_array); if (NULL == str) { json_object_put (version_array); NSOPR_SET_ERRINFO (NSCRTL_ERR, "internal error for str=NULL!"); return NSCRTL_ERR; } size_t str_len = strlen (str); if (str_len >= sizeof (get_config_data ()->json_buff)) { json_object_put (version_array); NSOPR_SET_ERRINFO (NSCRTL_ERR, "internal error!"); return NSCRTL_ERR; } retVal = STRNCPY_S (get_config_data ()->json_buff, sizeof (get_config_data ()->json_buff), str, str_len); if (EOK != retVal) { json_object_put (version_array); NSOPR_SET_ERRINFO (NSCRTL_ERR, "STRNCPY_S error!"); return NSCRTL_ERR; } json_object_put (version_array); return NSCRTL_OK; } void reset_config_data (void) { int retval = MEMSET_S (g_config_data, sizeof (struct config_data), 0, sizeof (struct config_data)); if (EOK != retval) { printf ("MEMSET_S failed]retval=%d.\n", retval); exit (1); } } int get_network_json_data () { STRCPY_S (g_config_data->param.type, sizeof (g_config_data->param.type), "network"); g_config_data->param.action = IP_MODULE_OPERATE_ADD; char *tmp_config_path; tmp_config_path = realpath ("./network_data_tonStack.json", NULL); if (!tmp_config_path) { exit (1); } int fp = open (tmp_config_path, O_RDONLY); if (-1 == fp) { free (tmp_config_path); NSTCP_LOGINF ("network file open failed.\n"); exit (1); } free (tmp_config_path); int nread = read (fp, g_config_data->json_buff, sizeof (g_config_data->json_buff) - 1); if (nread <= 0) { close (fp); NSTCP_LOGINF ("read failed %d.\n", nread); exit (1); } /* though MEMSET_S is done above, MEMSET_S can be removed */ g_config_data->json_buff[nread] = '\0'; close (fp); struct network_configuration *network = NULL; struct network_configuration *tmp = NULL; /* input shouldnot be same with return */ network = parse_network_json (g_config_data->json_buff, NULL); if (!network) { NSTCP_LOGINF ("Invalid network data!"); NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "Invalid network data!"); return -1; } /* run process_post for each network, not only the head node */ while (network) { tmp = network; network = network->next; int retval = add_network_configuration ((struct network_configuration *) tmp); /* When network exceeds max number, just log warning at operation.log */ if (retval == NSCRTL_NETWORK_COUNT_EXCEED) { NSTCP_LOGINF ("Warning!! Network count exceed max allowed number]max=%d", MAX_NETWORK_COUNT); } else { NSTCP_LOGINF ("add_network_configuration %d", retval); NSOPR_SET_ERRINFO (retval, "add_network_configuration return %d", retval); } if (!retval) { /*init DPDK eth */ if ((retval = init_new_network_configuration ()) != ERR_OK) { NSTCP_LOGINF ("process_configuration failed! %d", retval); free_network_configuration ((struct network_configuration *) tmp, IP_MODULE_TRUE); NSOPR_SET_ERRINFO (retval, "init_new_network_configuration return %d", retval); return -1; } } } NSTCP_LOGINF ("Get_network_json_data done!"); return 0; } int get_ip_json_data () { NSTCP_LOGINF ("get_ip_json_data start!"); STRCPY_S (g_config_data->param.type, sizeof (g_config_data->param.type), "ip"); g_config_data->param.action = IP_MODULE_OPERATE_ADD; char *tmp_config_path; tmp_config_path = realpath ("./ip_data.json", NULL); if (!tmp_config_path) { exit (1); } int fp = open (tmp_config_path, O_RDONLY); if (-1 == fp) { free (tmp_config_path); NSTCP_LOGINF ("network file open failed\n"); exit (1); } free (tmp_config_path); int nread = read (fp, g_config_data->json_buff, sizeof (g_config_data->json_buff) - 1); if (nread <= 0) { close (fp); NSTCP_LOGINF ("read failed %d.\n", nread); exit (1); } /* though MEMSET_S is done above, MEMSET_S can be removed */ g_config_data->json_buff[nread] = '\0'; close (fp); struct container_ip *container = parse_container_ip_json (g_config_data->json_buff); if (container) { int retval = add_container (container); NSTCP_LOGINF ("add_container %d", retval); NSOPR_SET_ERRINFO (retval, "add_container return %d", retval); } else { NSTCP_LOGINF ("Invalid IP config data!"); NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "Invalid IP config data!"); return -1; } NSTCP_LOGINF ("get_ip_json_data done!"); return 0; } int read_ipmoduleoperateadd_configuration () { struct network_configuration *tmp = NULL; if (strcmp (g_config_data->param.type, IP_MODULE_TYPE_IP) == 0) { struct container_ip *container = parse_container_ip_json (g_config_data->json_buff); if (container) { return process_post ((void *) container, IP_MODULE_IP, IP_MODULE_OPERATE_ADD); } else { NSOPR_LOGERR ("Invalid IP config data!"); NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "Invalid IP config data!"); return -1; } } else if (strcmp (g_config_data->param.type, IP_MODULE_TYPE_NETWORK) == 0) { struct network_configuration *network = NULL; //Read network.json /* input shouldnot be same with return */ network = parse_network_json (g_config_data->json_buff, NULL); if (!network) { NSOPR_LOGERR ("Invalid network data!"); NSOPR_SET_ERRINFO (NSCRTL_INPUT_ERR, "Invalid network data!"); return -1; } /* run process_post for each network, not only the head node */ while (network) {
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

*** Settings ***
| Resource | resources/libraries/robot/performance/performance_setup.robot
| ...
| Force Tags | 2_NODE_SINGLE_LINK_TOPO | PERFTEST | HW_ENV | MRR
| ... | NIC_Intel-X710 | ETH | IP4FWD | SCALE | FIB_2M
| ...
| Suite Setup | Set up 2-node performance topology with DUT's NIC model
| ... | L3 | Intel-X710
| Suite Teardown | Tear down 2-node performance topology
| ...
| Test Setup | Set up performance test
| ...
| Test Teardown | Tear down performance mrr test
| ...
| Test Template | Local Template
| ...
| Documentation | *Raw results IPv4 routing test cases*
| ...
| ... | *[Top] Network Topologies:* TG-DUT1-TG 2-node circular topology\
| ... | with single links between nodes.
| ... | *[Enc] Packet Encapsulations:* Eth-IPv4 for IPv4 routing.
| ... | *[Cfg] DUT configuration:* DUT1 is configured with IPv4 routing and\
| ... | 2x1M static IPv4 /32 route entries. DUT1 is tested with 2p10GE NIC\
| ... | X710 by Intel.
| ... | *[Ver] TG verification:* In MaxReceivedRate test TG sends traffic\
| ... | at line rate and reports total received/sent packets over trial period.\
| ... | Test packets are generated by TG on links to DUTs. TG traffic profile\