l2: API cleanup

Use consistent API types.

Type: fix

Change-Id: I7ac7cd00606101864fa3422e7b9ea2f1143665dd
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
This commit is contained in:
Jakub Grajciar
2019-10-24 13:52:42 +02:00
committed by Ole Trøan
parent 262971e783
commit 145e330f01
6 changed files with 130 additions and 159 deletions

File diff suppressed because it is too large Load Diff

View File

@ -149,7 +149,7 @@ send_l2fib_table_entry (vpe_api_main_t * am,
mp->bd_id =
ntohl (l2input_main.bd_configs[l2fe_key->fields.bd_index].bd_id);
clib_memcpy (mp->mac, l2fe_key->fields.mac, 6);
mac_address_encode ((mac_address_t *) l2fe_key->fields.mac, mp->mac);
mp->sw_if_index = ntohl (l2fe_res->fields.sw_if_index);
mp->static_mac = (l2fib_entry_result_is_set_STATIC (l2fe_res) ? 1 : 0);
mp->filter_mac = (l2fib_entry_result_is_set_FILTER (l2fe_res) ? 1 : 0);
@ -215,13 +215,13 @@ vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
}
u32 bd_index = p[0];
u8 mac[6];
mac_address_t mac;
clib_memcpy (mac, mp->mac, 6);
mac_address_decode (mp->mac, &mac);
if (mp->is_add)
{
if (mp->filter_mac)
l2fib_add_filter_entry (mac, bd_index);
l2fib_add_filter_entry (mac.bytes, bd_index);
else
{
l2fib_entry_result_flags_t flags = L2FIB_ENTRY_RESULT_FLAG_NONE;
@ -246,13 +246,13 @@ vl_api_l2fib_add_del_t_handler (vl_api_l2fib_add_del_t * mp)
flags |= L2FIB_ENTRY_RESULT_FLAG_STATIC;
if (mp->bvi_mac)
flags |= L2FIB_ENTRY_RESULT_FLAG_BVI;
l2fib_add_entry (mac, bd_index, sw_if_index, flags);
l2fib_add_entry (mac.bytes, bd_index, sw_if_index, flags);
}
}
else
{
u32 sw_if_index = ntohl (mp->sw_if_index);
if (l2fib_del_entry (mac, bd_index, sw_if_index))
if (l2fib_del_entry (mac.bytes, bd_index, sw_if_index))
rv = VNET_API_ERROR_NO_SUCH_ENTRY;
}
@ -281,18 +281,27 @@ vl_api_want_l2_macs_events_t_handler (vl_api_want_l2_macs_events_t * mp)
if (mp->max_macs_in_event)
fm->max_macs_in_event = mp->max_macs_in_event * 10;
else
fm->max_macs_in_event = L2FIB_EVENT_MAX_MACS_DEFAULT;
{
rv = VNET_API_ERROR_INVALID_VALUE;
goto exit;
}
if (mp->scan_delay)
fm->event_scan_delay = (f64) (mp->scan_delay) * 10e-3;
else
fm->event_scan_delay = L2FIB_EVENT_SCAN_DELAY_DEFAULT;
{
rv = VNET_API_ERROR_INVALID_VALUE;
goto exit;
}
/* change learn limit and flush all learned MACs */
if (learn_limit && (learn_limit < L2LEARN_DEFAULT_LIMIT))
lm->global_learn_limit = learn_limit;
else
lm->global_learn_limit = L2FIB_EVENT_LEARN_LIMIT_DEFAULT;
{
rv = VNET_API_ERROR_INVALID_VALUE;
goto exit;
}
l2fib_flush_all_mac (vlib_get_main ());
}
@ -506,12 +515,16 @@ vl_api_bridge_domain_dump_t_handler (vl_api_bridge_domain_dump_t * mp)
bd_main_t *bdm = &bd_main;
l2input_main_t *l2im = &l2input_main;
vl_api_registration_t *reg;
u32 bd_id, bd_index, end;
u32 bd_id, bd_index, end, filter_sw_if_index;
reg = vl_api_client_index_to_registration (mp->client_index);
if (!reg)
return;
filter_sw_if_index = ntohl (mp->sw_if_index);
if (filter_sw_if_index != ~0)
return; /* UNIMPLEMENTED */
bd_id = ntohl (mp->bd_id);
if (bd_id == 0)
return;
@ -648,6 +661,7 @@ static void
vlib_main_t *vm = vlib_get_main ();
u32 vtr_op;
int rv = 0;
mac_address_t b_dmac, b_smac;
VALIDATE_SW_IF_INDEX (mp);
@ -666,8 +680,11 @@ static void
goto bad_sw_if_index;
}
mac_address_decode (mp->b_dmac, &b_dmac);
mac_address_decode (mp->b_smac, &b_smac);
rv = l2pbb_configure (vm, vnm, ntohl (mp->sw_if_index), vtr_op,
mp->b_dmac, mp->b_smac, ntohs (mp->b_vlanid),
b_dmac.bytes, b_smac.bytes, ntohs (mp->b_vlanid),
ntohl (mp->i_sid), ntohs (mp->outer_tag));
BAD_SW_IF_INDEX_LABEL;

View File

@ -1084,7 +1084,10 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
key.fields.mac, 6);
mp->mac[evt_idx].action =
l2fib_entry_result_is_set_LRN_MOV (&result) ?
MAC_EVENT_ACTION_MOVE : MAC_EVENT_ACTION_ADD;
(vl_api_mac_event_action_t) MAC_EVENT_ACTION_MOVE
: (vl_api_mac_event_action_t) MAC_EVENT_ACTION_ADD;
mp->mac[evt_idx].action =
htonl (mp->mac[evt_idx].action);
mp->mac[evt_idx].sw_if_index =
htonl (result.fields.sw_if_index);
/* clear event bits and update mac entry */
@ -1127,7 +1130,9 @@ l2fib_scan (vlib_main_t * vm, f64 start_time, u8 event_only)
/* copy mac entry to event msg */
clib_memcpy_fast (mp->mac[evt_idx].mac_addr, key.fields.mac,
6);
mp->mac[evt_idx].action = MAC_EVENT_ACTION_DELETE;
mp->mac[evt_idx].action =
(vl_api_mac_event_action_t) MAC_EVENT_ACTION_DELETE;
mp->mac[evt_idx].action = htonl (mp->mac[evt_idx].action);
mp->mac[evt_idx].sw_if_index =
htonl (result.fields.sw_if_index);
evt_idx++;

View File

@ -131,11 +131,6 @@ START_TEST (test_hton_4)
d->header._vl_msg_id = cnt++;
d->header.context = cnt++;
d->payload.bd_id = cnt++;
d->payload.flood = cnt++;
d->payload.uu_flood = cnt++;
d->payload.forward = cnt++;
d->payload.learn = cnt++;
d->payload.arp_term = cnt++;
d->payload.mac_age = cnt++;
d->payload.bvi_sw_if_index = cnt++;
d->payload.n_sw_ifs = vla_count;
@ -156,16 +151,6 @@ START_TEST (test_hton_4)
++tmp;
verify_hton_swap (d->payload.bd_id, tmp);
++tmp;
verify_hton_swap (d->payload.flood, tmp);
++tmp;
verify_hton_swap (d->payload.uu_flood, tmp);
++tmp;
verify_hton_swap (d->payload.forward, tmp);
++tmp;
verify_hton_swap (d->payload.learn, tmp);
++tmp;
verify_hton_swap (d->payload.arp_term, tmp);
++tmp;
verify_hton_swap (d->payload.mac_age, tmp);
++tmp;
verify_hton_swap (d->payload.bvi_sw_if_index, tmp);
@ -189,16 +174,6 @@ START_TEST (test_hton_4)
++tmp;
ck_assert_int_eq (d->payload.bd_id, tmp);
++tmp;
ck_assert_int_eq (d->payload.flood, tmp);
++tmp;
ck_assert_int_eq (d->payload.uu_flood, tmp);
++tmp;
ck_assert_int_eq (d->payload.forward, tmp);
++tmp;
ck_assert_int_eq (d->payload.learn, tmp);
++tmp;
ck_assert_int_eq (d->payload.arp_term, tmp);
++tmp;
ck_assert_int_eq (d->payload.mac_age, tmp);
++tmp;
ck_assert_int_eq (d->payload.bvi_sw_if_index, tmp);
@ -268,11 +243,6 @@ START_TEST (test_ntoh_4)
d->header._vl_msg_id = cnt++;
d->header.context = cnt++;
d->payload.bd_id = cnt++;
d->payload.flood = cnt++;
d->payload.uu_flood = cnt++;
d->payload.forward = cnt++;
d->payload.learn = cnt++;
d->payload.arp_term = cnt++;
d->payload.mac_age = cnt++;
d->payload.bvi_sw_if_index = cnt++;
d->payload.n_sw_ifs = htobe32 (vla_count);
@ -293,16 +263,6 @@ START_TEST (test_ntoh_4)
++tmp;
verify_ntoh_swap (d->payload.bd_id, tmp);
++tmp;
verify_ntoh_swap (d->payload.flood, tmp);
++tmp;
verify_ntoh_swap (d->payload.uu_flood, tmp);
++tmp;
verify_ntoh_swap (d->payload.forward, tmp);
++tmp;
verify_ntoh_swap (d->payload.learn, tmp);
++tmp;
verify_ntoh_swap (d->payload.arp_term, tmp);
++tmp;
verify_ntoh_swap (d->payload.mac_age, tmp);
++tmp;
verify_ntoh_swap (d->payload.bvi_sw_if_index, tmp);
@ -326,16 +286,6 @@ START_TEST (test_ntoh_4)
++tmp;
ck_assert_int_eq (d->payload.bd_id, tmp);
++tmp;
ck_assert_int_eq (d->payload.flood, tmp);
++tmp;
ck_assert_int_eq (d->payload.uu_flood, tmp);
++tmp;
ck_assert_int_eq (d->payload.forward, tmp);
++tmp;
ck_assert_int_eq (d->payload.learn, tmp);
++tmp;
ck_assert_int_eq (d->payload.arp_term, tmp);
++tmp;
ck_assert_int_eq (d->payload.mac_age, tmp);
++tmp;
ck_assert_int_eq (d->payload.bvi_sw_if_index, tmp);

View File

@ -69,12 +69,7 @@ from scapy.layers.inet import IP, UDP
from framework import VppTestCase, VppTestRunner
from util import Host, ppp
from vpp_papi import mac_pton
# from src/vnet/l2/l2_fib.h
MAC_EVENT_ACTION_ADD = 0
MAC_EVENT_ACTION_DELETE = 1
MAC_EVENT_ACTION_MOVE = 2
from vpp_papi import mac_pton, VppEnum
class TestL2fib(VppTestCase):
@ -325,7 +320,7 @@ class TestL2fib(VppTestCase):
self.assertEqual(ip.dst, saved_packet[IP].dst)
self.assertEqual(udp.sport, saved_packet[UDP].sport)
self.assertEqual(udp.dport, saved_packet[UDP].dport)
except:
except BaseException:
self.logger.error(ppp("Unexpected or invalid packet:", packet))
raise
for i in self.pg_interfaces:
@ -494,9 +489,10 @@ class TestL2fib(VppTestCase):
self.sleep(1)
self.logger.info(self.vapi.ppcli("show l2fib"))
evs = self.vapi.collect_events()
action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD
learned_macs = {
e.mac[i].mac_addr for e in evs for i in range(e.n_macs)
if e.mac[i].action == MAC_EVENT_ACTION_ADD}
e.mac[i].mac_addr.packed for e in evs for i in range(e.n_macs)
if e.mac[i].action == action}
macs = {h.bin_mac for swif in self.bd_ifs(bd1)
for h in hosts[self.pg_interfaces[swif].sw_if_index]}
self.vapi.want_l2_macs_events(enable_disable=0)
@ -518,9 +514,10 @@ class TestL2fib(VppTestCase):
self.vapi.want_l2_macs_events(enable_disable=0)
self.assertGreater(len(evs), 0)
action = VppEnum.vl_api_mac_event_action_t.MAC_EVENT_ACTION_API_ADD
learned_macs = {
e.mac[i].mac_addr for e in evs for i in range(e.n_macs)
if e.mac[i].action == MAC_EVENT_ACTION_ADD}
e.mac[i].mac_addr.packed for e in evs for i in range(e.n_macs)
if e.mac[i].action == action}
macs = {h.bin_mac for swif in self.bd_ifs(bd1)
for h in hosts[self.pg_interfaces[swif].sw_if_index]}

View File

@ -126,7 +126,7 @@ defaultmapping = {
'want_bfd_events': {'enable_disable': 1, },
'want_igmp_events': {'enable': 1, },
'want_interface_events': {'enable_disable': 1, },
'want_l2_macs_events': {'enable_disable': 1, },
'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
}
@ -374,15 +374,6 @@ class VppPapiProvider(object):
{'enable_disable': enable_disable,
'pid': os.getpid(), })
def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
max_macs_in_event=0, learn_limit=0):
return self.api(self.papi.want_l2_macs_events,
{'enable_disable': enable_disable,
'scan_delay': scan_delay,
'max_macs_in_event': max_macs_in_event,
'learn_limit': learn_limit,
'pid': os.getpid(), })
def sw_interface_set_mac_address(self, sw_if_index, mac):
return self.api(self.papi.sw_interface_set_mac_address,
{'sw_if_index': sw_if_index,