summaryrefslogtreecommitdiffstats
path: root/src/plugins/lb/util.h
blob: 3f082310b6925e4be2ba699639330422fa39fae8 (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
/*
 * Copyright (c) 2016 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.
 */

/*
 * Non-LB specific stuff comes here
 */

#ifndef LB_PLUGIN_LB_UTIL_H_
#define LB_PLUGIN_LB_UTIL_H_

#include <vnet/vnet.h>
#include <vnet/ip/ip.h>

#define ip46_address_type(ip46) (ip46_address_is_ip4(ip46)?IP46_TYPE_IP4:IP46_TYPE_IP6)
#define ip46_prefix_is_ip4(ip46, len) ((len) >= 96 && ip46_address_is_ip4(ip46))
#define ip46_prefix_type(ip46, len) (ip46_prefix_is_ip4(ip46, len)?IP46_TYPE_IP4:IP46_TYPE_IP6)

void ip46_prefix_normalize(ip46_address_t *prefix, u8 plen);
uword unformat_ip46_prefix (unformat_input_t * input, va_list * args);
u8 *format_ip46_prefix (u8 * s, va_list * args);

/**
 * 32 bits integer comparison for running values.
 * 1 > 0 is true. But 1 > 0xffffffff also is.
 */
#define clib_u32_loop_gt(a, b) (((u32)(a)) - ((u32)(b)) < 0x7fffffff)

#endif /* LB_PLUGIN_LB_UTIL_H_ */
ass="p">).setUpClass() try: cls.create_pg_interfaces(range(2)) cls.interfaces = list(cls.pg_interfaces) for i in cls.interfaces: i.admin_up() i.config_ip4() i.config_ip6() i.disable_ipv6_ra() i.resolve_arp() i.resolve_ndp() except Exception: super(TestPing, cls).tearDownClass() raise def tearDown(self): super(TestPing, self).tearDown() if not self.vpp_dead: self.vapi.cli("show hardware") def test_ping_basic(self): """ basic ping test """ try: self.pg_enable_capture(self.pg_interfaces) self.pg_start() self.logger.info(self.vapi.cli("show ip arp")) self.logger.info(self.vapi.cli("show ip6 neighbors")) remote_ip4 = self.pg1.remote_ip4 ping_cmd = "ping " + remote_ip4 + " interval 0.01 repeat 10" ret = self.vapi.cli(ping_cmd) self.logger.info(ret) out = self.pg1.get_capture(10) icmp_id = None icmp_seq = 1 for p in out: ip = p[IP] self.assertEqual(ip.version, 4) self.assertEqual(ip.flags, 0) self.assertEqual(ip.src, self.pg1.local_ip4) self.assertEqual(ip.dst, self.pg1.remote_ip4) self.assertEqual(ip.proto, 1) self.assertEqual(len(ip.options), 0) self.assertGreaterEqual(ip.ttl, 254) icmp = p[ICMP] self.assertEqual(icmp.type, 8) self.assertEqual(icmp.code, 0) self.assertEqual(icmp.seq, icmp_seq) icmp_seq = icmp_seq + 1 if icmp_id is None: icmp_id = icmp.id else: self.assertEqual(icmp.id, icmp_id) finally: self.vapi.cli("show error") def test_ping_burst(self): """ burst ping test """ try: self.pg_enable_capture(self.pg_interfaces) self.pg_start() self.logger.info(self.vapi.cli("show ip arp")) self.logger.info(self.vapi.cli("show ip6 neighbors")) remote_ip4 = self.pg1.remote_ip4 ping_cmd = "ping " + remote_ip4 + " interval 0.01 burst 3" ret = self.vapi.cli(ping_cmd) self.logger.info(ret) out = self.pg1.get_capture(3*5) icmp_id = None icmp_seq = 1 count = 0 for p in out: ip = p[IP] self.assertEqual(ip.version, 4) self.assertEqual(ip.flags, 0) self.assertEqual(ip.src, self.pg1.local_ip4) self.assertEqual(ip.dst, self.pg1.remote_ip4) self.assertEqual(ip.proto, 1) self.assertEqual(len(ip.options), 0) self.assertGreaterEqual(ip.ttl, 254) icmp = p[ICMP] self.assertEqual(icmp.type, 8) self.assertEqual(icmp.code, 0) self.assertEqual(icmp.seq, icmp_seq) count = count + 1 if count >= 3: icmp_seq = icmp_seq + 1 count = 0 if icmp_id is None: icmp_id = icmp.id else: self.assertEqual(icmp.id, icmp_id) finally: self.vapi.cli("show error")