aboutsummaryrefslogtreecommitdiffstats
path: root/tests/vpp/device/vm_vhost/ip4/eth2p-ethip4-ip4base-eth-2vhost-1vm-dev.robot
blob: 9c9bd39de5374a184512eb29c6098e34d9888997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (c) 2019 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 ***
| Library | resources.libraries.python.InterfaceUtil
| Library | resources.libraries.python.IPUtil
| Library | resources.libraries.python.NodePath
| Library | resources.libraries.python.topology.Topology
| Library | resources.libraries.python.Trace
| Library | resources.libraries.python.VhostUser
| Library | resources.libraries.python.VPPUtil
| ...
| Resource | resources/libraries/robot/ip/ip4.robot
| Resource | resources/libraries/robot/l2/l2_bridge_domain.robot
| Resource | resources/libraries/robot/shared/default.robot
| Resource | resources/libraries/robot/shared/interfaces.robot
| Resource | resources/libraries/robot/shared/testing_path.robot
| Resource | resources/libraries/robot/shared/traffic.robot
| ...
| Force Tags | 2_NODE_SINGLE_LINK_TOPO | DEVICETEST | HW_ENV | DCR_ENV
| ... | FUNCTEST | IP4FWD | BASE | ETH | VHOST | 1VM
| ...
| Test Setup | Set up VPP device test
| ...
| Test Teardown | Tear down test | packet_trace | vhost
| ...
| Documentation | *IPv4 routing test cases with vhost user interface*
| ...
| ... | *[Top] Network Topologies:* TG-DUT1-TG 2-node circular topology with \
| ... | VM and single links between nodes.
| ... | *[Enc] Packet Encapsulations:* Eth-IPv4-ICMPv4 for IPv4 routing on \
| ... | both links.
| ... | *[Cfg] DUT configuration:* DUT1 is configured with IPv4 routing and \
| ... | two static IPv4 /24 route entries. Qemu Guest is connected to VPP via \
| ... | vhost-user interfaces. Guest is configured with linux bridge \
| ... | interconnecting vhost-user interfaces.
| ... | *[Ver] TG verification:* Test ICMPv4 Echo Request packets are sent in \
| ... | one direction by TG on links to DUT1; on receive TG verifies packets \
| ... | for correctness and their IPv4 src-addr, dst-addr and MAC addresses.
| ... | *[Ref] Applicable standard specifications:* RFC791, RFC826, RFC792

*** Variables ***
| ${net1}= | 10.0.1.0
| ${net3}= | 10.0.3.0
| ${net1_ip1}= | 10.0.1.1
| ${net1_ip2}= | 10.0.1.2
| ${net2_ip1}= | 10.0.2.1
| ${net2_ip2}= | 10.0.2.2
| ${net3_ip1}= | 10.0.3.1
| ${net3_ip2}= | 10.0.3.2
| ${prefix_length}= | 24
| ${fib_table_2}= | 20
| ${sock1}= | /tmp/sock1
| ${sock2}= | /tmp/sock2

*** Test Cases ***
| tc01-eth2p-ethip4-ip4base-eth-2vhost-1vm-device
| | [Documentation]
| | ... | Test uses two VRFs to route IPv4 traffic through two vhost-user \
| | ... | interfaces. Both interfaces are configured with IP addresses from \
| | ... | the same network. There is created linux bridge on VM to pass packet \
| | ... | from one vhost-user interface to another one.
| | ...
| | Given Configure path in 2-node circular topology
| | ... | ${nodes['TG']} | ${nodes['DUT1']} | ${nodes['TG']}
| | And Configure interfaces in path up
| | ${vhost1}= | And Vpp Create Vhost User Interface | ${dut_node} | ${sock1}
| | ${vhost2}= | And Vpp Create Vhost User Interface | ${dut_node} | ${sock2}
| | And Set Interface State | ${dut_node} | ${vhost1} | up
| | And Set Interface State | ${dut_node} | ${vhost2} | up
| | And Add Fib Table | ${dut_node} | ${fib_table_2}
| | And Assign Interface To Fib Table | ${dut_node}
| | ... | ${vhost2} | ${fib_table_2}
| | And Assign Interface To Fib Table | ${dut_node}
| | ... | ${dut_to_tg_if2} | ${fib_table_2}
| | And Configure IP addresses on interfaces
| | ... | ${dut_node} | ${dut_to_tg_if1} | ${net1_ip1} | ${prefix_length}
| | ... | ${dut_node} | ${vhost1} | ${net2_ip1} | ${prefix_length}
| | ... | ${dut_node} | ${vhost2} | ${net2_ip2} | ${prefix_length}
| | ... | ${dut_node} | ${dut_to_tg_if2} | ${net3_ip1} | ${prefix_length}
| | ${vhost2_mac}= | And Get Vhost User Mac By SW Index
| | ... | ${dut_node} | ${vhost2}
| | And Vpp Route Add | ${dut_node} | ${net3} | ${prefix_length}
| | ... | gateway=${net2_ip2} | interface=${vhost1}
| | And Vpp Route Add | ${dut_node} | ${net1} | ${prefix_length}
| | ... | gateway=${net2_ip1} | interface=${vhost2}
| | ... | vrf=${fib_table_2}
| | VPP Add IP Neighbor | ${dut_node} | ${vhost1} | ${net2_ip2} | ${vhost2_mac}
| | VPP Add IP Neighbor
| | ... | ${dut_node} | ${dut_to_tg_if2} | ${net3_ip2} | ${tg_to_dut_if2_mac}
| | When Configure VM for vhost L2BD forwarding
| | ... | ${dut_node} | ${sock1} | ${sock2}
| | Then Send packet and verify headers
| | ... | ${tg_node} | ${net1_ip2} | ${net3_ip2}
| | ... | ${tg_to_dut_if1} | ${tg_to_dut_if1_mac} | ${dut_to_tg_if1_mac}
| | ... | ${tg_to_dut_if2} | ${dut_to_tg_if2_mac} | ${tg_to_dut_if2_mac}
>* get_stat_vector_r (stat_client_main_t *sm) { ASSERT (sm->shared_header); return stat_segment_adjust (sm, (void *) sm->shared_header->directory_vector); } int stat_segment_connect_r (const char *socket_name, stat_client_main_t * sm) { int mfd = -1; int sock; clib_memset (sm, 0, sizeof (*sm)); if ((sock = socket (AF_UNIX, SOCK_SEQPACKET, 0)) < 0) { perror ("Stat client couldn't open socket"); return -1; } struct sockaddr_un un = { 0 }; un.sun_family = AF_UNIX; strncpy ((char *) un.sun_path, socket_name, sizeof (un.sun_path) - 1); if (connect (sock, (struct sockaddr *) &un, sizeof (struct sockaddr_un)) < 0) { close (sock); return -2; } if ((mfd = recv_fd (sock)) < 0) { close (sock); fprintf (stderr, "Receiving file descriptor failed\n"); return -3; } close (sock); /* mmap shared memory segment. */ void *memaddr; struct stat st = { 0 }; if (fstat (mfd, &st) == -1) { close (mfd); perror ("mmap fstat failed"); return -4; } if ((memaddr = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, mfd, 0)) == MAP_FAILED) { close (mfd); perror ("mmap map failed"); return -5; } close (mfd); sm->memory_size = st.st_size; sm->shared_header = memaddr; sm->directory_vector = stat_segment_adjust (sm, (void *) sm->shared_header->directory_vector); return 0; } int stat_segment_connect (const char *socket_name) { stat_client_main_t *sm = &stat_client_main; return stat_segment_connect_r (socket_name, sm); } void stat_segment_disconnect_r (stat_client_main_t * sm) { munmap (sm->shared_header, sm->memory_size); return; } void stat_segment_disconnect (void) { stat_client_main_t *sm = &stat_client_main; return stat_segment_disconnect_r (sm); } double stat_segment_heartbeat_r (stat_client_main_t * sm) { stat_segment_access_t sa; vlib_stats_entry_t *ep; /* Has directory been updated? */ if (sm->shared_header->epoch != sm->current_epoch) return 0; if (stat_segment_access_start (&sa, sm)) return 0; ep = vec_elt_at_index (sm->directory_vector, STAT_COUNTER_HEARTBEAT); if (!stat_segment_access_end (&sa, sm)) return 0.0; return ep->value; } double stat_segment_heartbeat (void) { stat_client_main_t *sm = &stat_client_main; return stat_segment_heartbeat_r (sm); } #define stat_vec_dup(S,V) \ ({ \ __typeof__ ((V)[0]) * _v(v) = 0; \ if (V && ((void *)V > (void *)S->shared_header) && \ (((void*)V + vec_bytes(V)) < \ ((void *)S->shared_header + S->memory_size))) \ _v(v) = vec_dup(V); \ _v(v); \ }) static counter_t * stat_vec_simple_init (counter_t c) { counter_t *v = 0; vec_add1 (v, c); return v; } static vlib_counter_t * stat_vec_combined_init (vlib_counter_t c) { vlib_counter_t *v = 0; vec_add1 (v, c); return v; } /* * If index2 is specified copy out the column (the indexed value across all * threads), otherwise copy out all values. */ static stat_segment_data_t copy_data (vlib_stats_entry_t *ep, u32 index2, char *name, stat_client_main_t *sm) { stat_segment_data_t result = { 0 }; int i; vlib_counter_t **combined_c; /* Combined counter */ counter_t **simple_c; /* Simple counter */ assert (sm->shared_header); result.type = ep->type; result.name = strdup (name ? name : ep->name); switch (ep->type) { case STAT_DIR_TYPE_SCALAR_INDEX: result.scalar_value = ep->value; break; case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE: simple_c = stat_segment_adjust (sm, ep->data); result.simple_counter_vec = stat_vec_dup (sm, simple_c); for (i = 0; i < vec_len (simple_c); i++) { counter_t *cb = stat_segment_adjust (sm, simple_c[i]); if (index2 != ~0) result.simple_counter_vec[i] = stat_vec_simple_init (cb[index2]); else result.simple_counter_vec[i] = stat_vec_dup (sm, cb); } break; case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED: combined_c = stat_segment_adjust (sm, ep->data); result.combined_counter_vec = stat_vec_dup (sm, combined_c); for (i = 0; i < vec_len (combined_c); i++) { vlib_counter_t *cb = stat_segment_adjust (sm, combined_c[i]); if (index2 != ~0) result.combined_counter_vec[i] = stat_vec_combined_init (cb[index2]); else result.combined_counter_vec[i] = stat_vec_dup (sm, cb); } break; case STAT_DIR_TYPE_NAME_VECTOR: { uint8_t **name_vector = stat_segment_adjust (sm, ep->data); result.name_vector = stat_vec_dup (sm, name_vector); for (i = 0; i < vec_len (name_vector); i++) { u8 *name = stat_segment_adjust (sm, name_vector[i]); result.name_vector[i] = stat_vec_dup (sm, name); } } break; case STAT_DIR_TYPE_SYMLINK: /* Gather info from all threads into a vector */ { vlib_stats_entry_t *ep2; ep2 = vec_elt_at_index (sm->directory_vector, ep->index1); /* We do not intend to return the "result", avoid a leak */ free (result.name); return copy_data (ep2, ep->index2, ep->name, sm); } case STAT_DIR_TYPE_EMPTY: break; default: fprintf (stderr, "Unknown type: %d\n", ep->type); } return result; } void stat_segment_data_free (stat_segment_data_t * res) { int i, j; for (i = 0; i < vec_len (res); i++) { switch (res[i].type) { case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE: for (j = 0; j < vec_len (res[i].simple_counter_vec); j++) vec_free (res[i].simple_counter_vec[j]); vec_free (res[i].simple_counter_vec); break; case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED: for (j = 0; j < vec_len (res[i].combined_counter_vec); j++) vec_free (res[i].combined_counter_vec[j]); vec_free (res[i].combined_counter_vec); break; case STAT_DIR_TYPE_NAME_VECTOR: for (j = 0; j < vec_len (res[i].name_vector); j++) vec_free (res[i].name_vector[j]); vec_free (res[i].name_vector); break; case STAT_DIR_TYPE_SCALAR_INDEX: case STAT_DIR_TYPE_EMPTY: break; default: assert (0); } free (res[i].name); } vec_free (res); } uint32_t * stat_segment_ls_r (uint8_t ** patterns, stat_client_main_t * sm) { stat_segment_access_t sa; uint32_t *dir = 0; regex_t regex[vec_len (patterns)]; int i, j; for (i = 0; i < vec_len (patterns); i++) { int rv = regcomp (&regex[i], (const char *) patterns[i], 0); if (rv) { fprintf (stderr, "Could not compile regex %s\n", patterns[i]); return dir; } } if (stat_segment_access_start (&sa, sm)) return 0; vlib_stats_entry_t *counter_vec = get_stat_vector_r (sm); for (j = 0; j < vec_len (counter_vec); j++) { for (i = 0; i < vec_len (patterns); i++) { int rv = regexec (&regex[i], counter_vec[j].name, 0, NULL, 0); if (rv == 0) { vec_add1 (dir, j); break; } } if (vec_len (patterns) == 0) vec_add1 (dir, j); } for (i = 0; i < vec_len (patterns); i++) regfree (&regex[i]); if (!stat_segment_access_end (&sa, sm)) { /* Failed, clean up */ vec_free (dir); return 0; } /* Update last version */ sm->current_epoch = sa.epoch; return dir; } uint32_t * stat_segment_ls (uint8_t ** patterns) { stat_client_main_t *sm = &stat_client_main; return stat_segment_ls_r ((uint8_t **) patterns, sm); } stat_segment_data_t * stat_segment_dump_r (uint32_t * stats, stat_client_main_t * sm) { int i; vlib_stats_entry_t *ep; stat_segment_data_t *res = 0; stat_segment_access_t sa; /* Has directory been update? */ if (sm->shared_header->epoch != sm->current_epoch) return 0; if (stat_segment_access_start (&sa, sm)) return 0; for (i = 0; i < vec_len (stats); i++) { /* Collect counter */ ep = vec_elt_at_index (sm->directory_vector, stats[i]); vec_add1 (res, copy_data (ep, ~0, 0, sm)); } if (stat_segment_access_end (&sa, sm)) return res; fprintf (stderr, "Epoch changed while reading, invalid results\n"); // TODO increase counter return 0; } stat_segment_data_t * stat_segment_dump (uint32_t * stats) { stat_client_main_t *sm = &stat_client_main; return stat_segment_dump_r (stats, sm); } /* Wrapper for accessing vectors from other languages */ int stat_segment_vec_len (void *vec) { return vec_len (vec); } void stat_segment_vec_free (void *vec) { vec_free (vec); } /* Create a vector from a string (or add to existing) */ uint8_t ** stat_segment_string_vector (uint8_t ** string_vector, const char *string) { uint8_t *name = 0; size_t len = strlen (string); vec_validate_init_c_string (name, string, len); vec_add1 (string_vector, name); return string_vector; } stat_segment_data_t * stat_segment_dump_entry_r (uint32_t index, stat_client_main_t * sm) { vlib_stats_entry_t *ep; stat_segment_data_t *res = 0; stat_segment_access_t sa; /* Has directory been update? */ if (sm->shared_header->epoch != sm->current_epoch) return 0; if (stat_segment_access_start (&sa, sm)) return 0; /* Collect counter */ ep = vec_elt_at_index (sm->directory_vector, index); vec_add1 (res, copy_data (ep, ~0, 0, sm)); if (stat_segment_access_end (&sa, sm)) return res; return 0; } stat_segment_data_t * stat_segment_dump_entry (uint32_t index) { stat_client_main_t *sm = &stat_client_main; return stat_segment_dump_entry_r (index, sm); } char * stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm) { vlib_stats_entry_t *ep; stat_segment_access_t sa; vlib_stats_entry_t *vec; /* Has directory been update? */ if (sm->shared_header->epoch != sm->current_epoch) return 0; if (stat_segment_access_start (&sa, sm)) return 0; vec = get_stat_vector_r (sm); ep = vec_elt_at_index (vec, index); if (!stat_segment_access_end (&sa, sm)) return 0; return strdup (ep->name); } char * stat_segment_index_to_name (uint32_t index) { stat_client_main_t *sm = &stat_client_main; return stat_segment_index_to_name_r (index, sm); } uint64_t stat_segment_version_r (stat_client_main_t * sm) { ASSERT (sm->shared_header); return sm->shared_header->version; } uint64_t stat_segment_version (void) { stat_client_main_t *sm = &stat_client_main; return stat_segment_version_r (sm); } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */