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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
#!/usr/bin/env python3
"""IRB Test Case HLD:
**config**
- L2 MAC learning enabled in l2bd
- 2 routed interfaces untagged, bvi (Bridge Virtual Interface)
- 2 bridged interfaces in l2bd with bvi
**test**
- sending ip4 eth pkts between routed interfaces
- 2 routed interfaces
- 2 bridged interfaces
- 64B, 512B, 1518B, 9200B (ether_size)
- burst of pkts per interface
- 257pkts per burst
- routed pkts hitting different FIB entries
- bridged pkts hitting different MAC entries
**verify**
- all packets received correctly
"""
import unittest
from random import choice
from scapy.packet import Raw
from scapy.layers.l2 import Ether
from scapy.layers.inet import IP, UDP
from framework import VppTestCase, VppTestRunner
from vpp_papi import MACAddress
from vpp_l2 import L2_PORT_TYPE
class TestIpIrb(VppTestCase):
"""IRB Test Case"""
@classmethod
def setUpClass(cls):
"""
#. Create BD with MAC learning enabled and put interfaces to this BD.
#. Configure IPv4 addresses on BVI interface and routed interface.
#. Configure MAC address binding to IPv4 neighbors on bvi0.
#. Configure MAC address on pg2.
#. BVI interface has remote hosts, one half of hosts are
behind pg0 second behind pg1.
"""
super(TestIpIrb, cls).setUpClass()
cls.pg_if_packet_sizes = [64, 512, 1518, 9018] # packet sizes
cls.bd_id = 10
cls.remote_hosts_count = 250
# create 3 pg interfaces, 1 BVI interface
cls.create_pg_interfaces(range(3))
cls.create_bvi_interfaces(1)
cls.interfaces = list(cls.pg_interfaces)
cls.interfaces.extend(cls.bvi_interfaces)
for i in cls.interfaces:
i.admin_up()
# Create BD with MAC learning enabled and put interfaces to this BD
cls.vapi.sw_interface_set_l2_bridge(
rx_sw_if_index=cls.bvi0.sw_if_index, bd_id=cls.bd_id,
port_type=L2_PORT_TYPE.BVI)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=cls.pg0.sw_if_index,
bd_id=cls.bd_id)
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=cls.pg1.sw_if_index,
bd_id=cls.bd_id)
# Configure IPv4 addresses on BVI interface and routed interface
cls.bvi0.config_ip4()
cls.pg2.config_ip4()
# Configure MAC address binding to IPv4 neighbors on bvi0
cls.bvi0.generate_remote_hosts(cls.remote_hosts_count)
cls.bvi0.configure_ipv4_neighbors()
# configure MAC address on pg2
cls.pg2.resolve_arp()
# BVI interface has remote hosts, one half of hosts are behind
# pg0 second behind pg1
half = cls.remote_hosts_count // 2
cls.pg0.remote_hosts = cls.bvi0.remote_hosts[:half]
cls.pg1.remote_hosts = cls.bvi0.remote_hosts[half:]
@classmethod
def tearDownClass(cls):
super(TestIpIrb, cls).tearDownClass()
def tearDown(self):
"""Run standard test teardown and log ``show l2patch``,
``show l2fib verbose``,``show bridge-domain <bd_id> detail``,
``show ip neighbors``.
"""
super(TestIpIrb, self).tearDown()
def show_commands_at_teardown(self):
self.logger.info(self.vapi.cli("show l2patch"))
self.logger.info(self.vapi.cli("show l2fib verbose"))
self.logger.info(self.vapi.cli("show bridge-domain %s detail" %
self.bd_id))
self.logger.info(self.vapi.cli("show ip neighbors"))
def create_stream(self, src_ip_if, dst_ip_if, packet_sizes):
pkts = []
for i in range(0, 257):
remote_dst_host = choice(dst_ip_if.remote_hosts)
info = self.create_packet_info(src_ip_if, dst_ip_if)
payload = self.info_to_payload(info)
p = (Ether(dst=src_ip_if.local_mac, src=src_ip_if.remote_mac) /
IP(src=src_ip_if.remote_ip4,
dst=remote_dst_host.ip4) /
UDP(sport=1234, dport=1234) /
Raw(payload))
info.data = p/*
* Copyright (c) 2017-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.
*/
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <vcl/vcl_test.h>
#include <sys/epoll.h>
#include <vppinfra/mem.h>
#include <pthread.h>
typedef struct
{
uint8_t is_alloc;
int fd;
uint8_t *buf;
uint32_t buf_size;
vcl_test_cfg_t cfg;
vcl_test_stats_t stats;
vppcom_endpt_t endpt;
uint8_t ip[16];
vppcom_data_segments_t ds;
} vcl_test_server_conn_t;
typedef struct
{
uint16_t port;
uint32_t address_ip6;
u8 proto;
u8 workers;
vppcom_endpt_t endpt;
} vcl_test_server_cfg_t;
typedef struct
{
uint32_t wrk_index;
int listen_fd;
int epfd;
struct epoll_event wait_events[VCL_TEST_CFG_MAX_EPOLL_EVENTS];
size_t conn_pool_size;
vcl_test_server_conn_t *conn_pool;
int nfds;
pthread_t thread_handle;
} vcl_test_server_worker_t;
typedef struct
{
vcl_test_server_cfg_t cfg;
vcl_test_server_worker_t *workers;
struct sockaddr_storage servaddr;
volatile int worker_fails;
volatile int active_workers;
u8 use_ds;
} vcl_test_server_main_t;
static __thread int __wrk_index = 0;
static vcl_test_server_main_t vcl_server_main;
static inline void
conn_pool_expand (vcl_test_server_worker_t * wrk, size_t expand_size)
{
vcl_test_server_conn_t *conn_pool;
size_t new_size = wrk->conn_pool_size + expand_size;
int i;
conn_pool = realloc (wrk->conn_pool, new_size * sizeof (*wrk->conn_pool));
if (conn_pool)
{
for (i = wrk->conn_pool_size; i < new_size; i++)
{
vcl_test_server_conn_t *conn = &conn_pool[i];
memset (conn, 0, sizeof (*conn));
vcl_test_cfg_init (&conn->cfg);
vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
&conn->buf, &conn->buf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
}
wrk->conn_pool = conn_pool;
wrk->conn_pool_size = new_size;
}
else
{
vterr ("conn_pool_expand()", -errno);
}
}
static inline vcl_test_server_conn_t *
conn_pool_alloc (vcl_test_server_worker_t * wrk)
{
int i, expand = 0;
again:
for (i = 0; i < wrk->conn_pool_size; i++)
{
if (!wrk->conn_pool[i].is_alloc)
{
wrk->conn_pool[i].endpt.ip = wrk->conn_pool[i].ip;
wrk->conn_pool[i].is_alloc = 1;
return (&wrk->conn_pool[i]);
}
}
if (expand == 0)
{
conn_pool_expand (wrk, 2 * wrk->conn_pool_size);
expand = 1;
goto again;
}
vtwrn ("Failed to allocate connection even after expand");
return 0;
}
static inline void
conn_pool_free (vcl_test_server_conn_t * conn)
{
conn->fd = 0;
conn->is_alloc = 0;
}
static inline void
sync_config_and_reply (vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
{
conn->cfg = *rx_cfg;
vcl_test_buf_alloc (&conn->cfg, 1 /* is_rxbuf */ ,
&conn->buf, &conn->buf_size);
conn->cfg.txbuf_size = conn->cfg.rxbuf_size;
if (conn->cfg.verbose)
{
vtinf ("(fd %d): Replying to cfg message!\n", conn->fd);
vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
}
(void) vcl_test_write (conn->fd, (uint8_t *) & conn->cfg,
sizeof (conn->cfg), NULL, conn->cfg.verbose);
}
static void
vts_server_start_stop (vcl_test_server_worker_t * wrk,
vcl_test_server_conn_t * conn, vcl_test_cfg_t * rx_cfg)
{
u8 is_bi = rx_cfg->test == VCL_TEST_TYPE_BI;
vcl_test_server_conn_t *tc;
char buf[64];
int i;
if (rx_cfg->ctrl_handle == conn->fd)
{
for (i = 0; i < wrk->conn_pool_size; i++)
{
tc = &wrk->conn_pool[i];
if (tc->cfg.ctrl_handle != conn->fd)
continue;
vcl_test_stats_accumulate (&conn->stats, &tc->stats);
if (vcl_comp_tspec (&conn->stats.stop, &tc->stats.stop) < 0)
conn->stats.stop = tc->stats.stop;
/* Client delays sending of disconnect */
conn->stats.stop.tv_sec -= VCL_TEST_DELAY_DISCONNECT;
if (conn->cfg.verbose)
{
sprintf (buf, "SERVER (fd %d) RESULTS", tc->fd);
vcl_test_stats_dump (buf, &tc->stats, 1 /* show_rx */ ,
is_bi /* show tx */ , conn->cfg.verbose);
}
}
vcl_test_stats_dump ("SERVER RESULTS", &conn->stats, 1 /* show_rx */ ,
is_bi /* show_tx */ , conn->cfg.verbose);
vcl_test_cfg_dump (&conn->cfg, 0 /* is_client */ );
if (conn->cfg.verbose)
{
vtinf (" vcl server main\n"
VCL_TEST_SEPARATOR_STRING
" buf: %p\n"
" buf size: %u (0x%08x)\n"
VCL_TEST_SEPARATOR_STRING,
conn->buf, conn->buf_size, conn->buf_size);
}
sync_config_and_reply (conn, rx_cfg);
memset (&conn->stats, 0, sizeof (conn->stats));
}
else
{
if (rx_cfg->ctrl_handle == ~0)
{
rx_cfg->ctrl_handle = conn->fd;
vtinf ("Set control fd %d for test!", conn->fd);
}
else
{
vtinf (
|