summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-12-17 12:02:26 +0100
committerNeale Ranns <nranns@cisco.com>2018-12-18 11:54:24 +0000
commit8006c6aa425126529b4017768a9201e4f03964ad (patch)
tree7b7342e6fb4964a5c8ca65c3d13d8dcc980f120d
parent02782d6ebd13ce02f2d3facebb54fec3c2137c88 (diff)
PAPI: Add MACAddress object wrapper for vl_api_mac_address_t
Change the definition of vl_api_mac_address_t to an aliased type. Change-Id: I1434f316d0fad6a099592f39bceeb8faeaf1d134 Signed-off-by: Ole Troan <ot@cisco.com>
-rw-r--r--extras/vom/vom/api_types.cpp12
-rw-r--r--extras/vom/vom/api_types.hpp2
-rw-r--r--extras/vom/vom/bridge_domain_arp_entry_cmds.cpp4
-rw-r--r--extras/vom/vom/gbp_contract_cmds.cpp2
-rw-r--r--extras/vom/vom/gbp_endpoint_cmds.cpp2
-rw-r--r--src/plugins/gbp/gbp_api.c6
-rw-r--r--src/vat/api_format.c10
-rw-r--r--src/vnet/ethernet/ethernet_types.api4
-rw-r--r--src/vnet/ethernet/ethernet_types_api.c8
-rw-r--r--src/vnet/ethernet/ethernet_types_api.h11
-rw-r--r--src/vnet/l2/l2.api2
-rw-r--r--src/vnet/l2/l2_api.c2
-rw-r--r--src/vpp-api/python/vpp_papi/macaddress.py54
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_format.py7
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py2
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_serializer.py7
-rw-r--r--src/vpp/api/types.c4
-rw-r--r--test/test_bond.py4
-rw-r--r--test/test_dhcp.py22
-rw-r--r--test/test_gbp.py91
-rw-r--r--test/test_ip4_irb.py4
-rw-r--r--test/test_l2_fib.py5
-rw-r--r--test/test_l2bd_arp_term.py3
-rw-r--r--test/test_nat.py14
-rw-r--r--test/test_p2p_ethernet.py12
-rw-r--r--test/test_pppoe.py1
-rwxr-xr-xtest/test_util.py6
-rw-r--r--test/util.py4
-rw-r--r--test/vpp_interface.py15
-rw-r--r--test/vpp_l2.py26
-rw-r--r--test/vpp_mac.py50
-rw-r--r--test/vpp_neighbor.py6
-rw-r--r--test/vpp_papi_provider.py7
-rw-r--r--test/vpp_pppoe_interface.py6
34 files changed, 199 insertions, 216 deletions
diff --git a/extras/vom/vom/api_types.cpp b/extras/vom/vom/api_types.cpp
index 418f3e43564..53cd047332a 100644
--- a/extras/vom/vom/api_types.cpp
+++ b/extras/vom/vom/api_types.cpp
@@ -54,20 +54,16 @@ from_api(const vapi_type_address& v)
return addr;
}
-vapi_type_mac_address
-to_api(const mac_address_t& a)
+void
+to_api(const mac_address_t& a, vapi_type_mac_address& v)
{
- vapi_type_mac_address v;
-
- std::copy(std::begin(a.bytes), std::end(a.bytes), v.bytes);
-
- return (v);
+ std::copy(std::begin(a.bytes), std::end(a.bytes), v);
}
mac_address_t
from_api(const vapi_type_mac_address& v)
{
- return mac_address_t(v.bytes);
+ return mac_address_t(v);
}
route::prefix_t
diff --git a/extras/vom/vom/api_types.hpp b/extras/vom/vom/api_types.hpp
index c28ae1e997d..784ace2c293 100644
--- a/extras/vom/vom/api_types.hpp
+++ b/extras/vom/vom/api_types.hpp
@@ -29,7 +29,7 @@ void to_api(const boost::asio::ip::address& a, vapi_type_ip4_address& v);
ip_address_t from_api(const vapi_type_address& v);
ip_address_t from_api(const vapi_type_ip4_address& v);
-vapi_type_mac_address to_api(const mac_address_t& a);
+void to_api(const mac_address_t& a, vapi_type_mac_address& m);
mac_address_t from_api(const vapi_type_mac_address& v);
diff --git a/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp b/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp
index da5c547bb3b..a72ad3ed874 100644
--- a/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp
+++ b/extras/vom/vom/bridge_domain_arp_entry_cmds.cpp
@@ -45,7 +45,7 @@ create_cmd::issue(connection& con)
auto& payload = req.get_request().get_payload();
payload.bd_id = m_bd;
payload.is_add = 1;
- payload.mac = to_api(m_mac);
+ to_api(m_mac, payload.mac);
to_api(m_ip_addr, payload.ip);
VAPI_CALL(req.execute());
@@ -90,7 +90,7 @@ delete_cmd::issue(connection& con)
auto& payload = req.get_request().get_payload();
payload.bd_id = m_bd;
payload.is_add = 0;
- payload.mac = to_api(m_mac);
+ to_api(m_mac, payload.mac);
to_api(m_ip_addr, payload.ip);
VAPI_CALL(req.execute());
diff --git a/extras/vom/vom/gbp_contract_cmds.cpp b/extras/vom/vom/gbp_contract_cmds.cpp
index 1a3975b832a..8b15e8cb519 100644
--- a/extras/vom/vom/gbp_contract_cmds.cpp
+++ b/extras/vom/vom/gbp_contract_cmds.cpp
@@ -78,7 +78,7 @@ create_cmd::issue(connection& con)
payload.contract.rules[ii].nh_set.n_nhs = nh_size;
while (jj < nh_size) {
to_api(nh_it->getIp(), payload.contract.rules[ii].nh_set.nhs[jj].ip);
- payload.contract.rules[ii].nh_set.nhs[jj].mac = to_api(nh_it->getMac());
+ to_api(nh_it->getMac(), payload.contract.rules[ii].nh_set.nhs[jj].mac);
payload.contract.rules[ii].nh_set.nhs[jj].bd_id = nh_it->getBdId();
payload.contract.rules[ii].nh_set.nhs[jj].rd_id = nh_it->getRdId();
++nh_it;
diff --git a/extras/vom/vom/gbp_endpoint_cmds.cpp b/extras/vom/vom/gbp_endpoint_cmds.cpp
index b15b941b125..2732d1cc297 100644
--- a/extras/vom/vom/gbp_endpoint_cmds.cpp
+++ b/extras/vom/vom/gbp_endpoint_cmds.cpp
@@ -56,7 +56,7 @@ create_cmd::issue(connection& con)
for (n = 0; n < payload.endpoint.n_ips; n++) {
to_api(m_ip_addrs[n], payload.endpoint.ips[n]);
}
- payload.endpoint.mac = to_api(m_mac);
+ to_api(m_mac, payload.endpoint.mac);
VAPI_CALL(req.execute());
diff --git a/src/plugins/gbp/gbp_api.c b/src/plugins/gbp/gbp_api.c
index 5f87db8f83c..74355d1c033 100644
--- a/src/plugins/gbp/gbp_api.c
+++ b/src/plugins/gbp/gbp_api.c
@@ -154,7 +154,7 @@ vl_api_gbp_endpoint_add_t_handler (vl_api_gbp_endpoint_add_t * mp)
ip_address_decode (&mp->endpoint.ips[ii], &ips[ii]);
}
}
- mac_address_decode (&mp->endpoint.mac, &mac);
+ mac_address_decode (mp->endpoint.mac, &mac);
if (GBP_ENDPOINT_FLAG_REMOTE & gef)
{
@@ -260,7 +260,7 @@ gbp_endpoint_send_details (index_t gei, void *args)
mp->endpoint.flags = gbp_endpoint_flags_encode (gef->gef_flags);
mp->handle = htonl (gei);
mp->age = vlib_time_now (vlib_get_main ()) - ge->ge_last_time;
- mac_address_encode (&ge->ge_key.gek_mac, &mp->endpoint.mac);
+ mac_address_encode (&ge->ge_key.gek_mac, mp->endpoint.mac);
vec_foreach_index (ii, ge->ge_key.gek_ips)
{
@@ -821,7 +821,7 @@ gbp_next_hop_decode (const vl_api_gbp_next_hop_t * in, index_t * gnhi)
return (VNET_API_ERROR_NO_SUCH_FIB);
ip_address_decode (&in->ip, &ip);
- mac_address_decode (&in->mac, &mac);
+ mac_address_decode (in->mac, &mac);
*gnhi = gbp_next_hop_alloc (&ip, grd, &mac, gbd);
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index fc4c38b52c8..55f5197b5eb 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -82,14 +82,6 @@
#if VPP_API_TEST_BUILTIN == 0
#include <netdb.h>
-/* *INDENT-OFF* */
-const mac_address_t ZERO_MAC_ADDRESS = {
- .bytes = {
- 0, 0, 0, 0, 0, 0,
- },
-};
-/* *INDENT-ON* */
-
u32
vl (void *p)
{
@@ -7323,7 +7315,7 @@ static int
api_bd_ip_mac_add_del (vat_main_t * vam)
{
vl_api_address_t ip = VL_API_ZERO_ADDRESS;
- vl_api_mac_address_t mac = VL_API_ZERO_MAC_ADDRESS;
+ vl_api_mac_address_t mac = { 0 };
unformat_input_t *i = vam->input;
vl_api_bd_ip_mac_add_del_t *mp;
ip46_type_t type;
diff --git a/src/vnet/ethernet/ethernet_types.api b/src/vnet/ethernet/ethernet_types.api
index c33a02c377a..f945f20910f 100644
--- a/src/vnet/ethernet/ethernet_types.api
+++ b/src/vnet/ethernet/ethernet_types.api
@@ -14,6 +14,4 @@
* limitations under the License.
*/
-typedef mac_address {
- u8 bytes[6];
-};
+typedef u8 mac_address[6];
diff --git a/src/vnet/ethernet/ethernet_types_api.c b/src/vnet/ethernet/ethernet_types_api.c
index 4b84d386e4e..90b630d46be 100644
--- a/src/vnet/ethernet/ethernet_types_api.c
+++ b/src/vnet/ethernet/ethernet_types_api.c
@@ -30,15 +30,15 @@
#undef vl_printfun
void
-mac_address_decode (const vl_api_mac_address_t * in, mac_address_t * out)
+mac_address_decode (const u8 * in, mac_address_t * out)
{
- mac_address_from_bytes (out, in->bytes);
+ mac_address_from_bytes (out, in);
}
void
-mac_address_encode (const mac_address_t * in, vl_api_mac_address_t * out)
+mac_address_encode (const mac_address_t * in, u8 * out)
{
- clib_memcpy_fast (out->bytes, in->bytes, 6);
+ clib_memcpy_fast (out, in->bytes, 6);
}
/*
diff --git a/src/vnet/ethernet/ethernet_types_api.h b/src/vnet/ethernet/ethernet_types_api.h
index b65d9d46c86..e2c638d1fec 100644
--- a/src/vnet/ethernet/ethernet_types_api.h
+++ b/src/vnet/ethernet/ethernet_types_api.h
@@ -22,15 +22,8 @@
#include <vnet/ethernet/mac_address.h>
-/**
- * Forward declarations so we need not #include the API definitions here
- */
-struct _vl_api_mac_address;
-
-extern void mac_address_decode (const struct _vl_api_mac_address *in,
- mac_address_t * out);
-extern void mac_address_encode (const mac_address_t * in,
- struct _vl_api_mac_address *out);
+extern void mac_address_decode (const u8 * in, mac_address_t * out);
+extern void mac_address_encode (const mac_address_t * in, u8 * out);
#endif
diff --git a/src/vnet/l2/l2.api b/src/vnet/l2/l2.api
index 7c71ea6e151..ea24a71feb5 100644
--- a/src/vnet/l2/l2.api
+++ b/src/vnet/l2/l2.api
@@ -499,7 +499,7 @@ define bd_ip_mac_details
u32 bd_id;
u8 is_ipv6;
u8 ip_address[16];
- u8 mac_address[6];
+ vl_api_mac_address_t mac_address;
};
/** \brief Dump bridge domain IP to MAC entries
diff --git a/src/vnet/l2/l2_api.c b/src/vnet/l2/l2_api.c
index 2fa238eadb3..9e3a47f772b 100644
--- a/src/vnet/l2/l2_api.c
+++ b/src/vnet/l2/l2_api.c
@@ -883,7 +883,7 @@ vl_api_bd_ip_mac_add_del_t_handler (vl_api_bd_ip_mac_add_del_t * mp)
bd_index = p[0];
type = ip_address_decode (&mp->ip, &ip_addr);
- mac_address_decode (&mp->mac, &mac);
+ mac_address_decode (mp->mac, &mac);
if (bd_add_del_ip_mac (bd_index, type, &ip_addr, &mac, mp->is_add))
rv = VNET_API_ERROR_UNSPECIFIED;
diff --git a/src/vpp-api/python/vpp_papi/macaddress.py b/src/vpp-api/python/vpp_papi/macaddress.py
new file mode 100644
index 00000000000..a1003812003
--- /dev/null
+++ b/src/vpp-api/python/vpp_papi/macaddress.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+import binascii
+
+
+def mac_pton(s):
+ '''Convert MAC address as text to binary'''
+ return binascii.unhexlify(s.replace(':', ''))
+
+
+def mac_ntop(binary):
+ '''Convert MAC address as binary to text'''
+ x = b':'.join(binascii.hexlify(binary)[i:i + 2]
+ for i in range(0, 12, 2))
+ return str(x.decode('ascii'))
+
+
+class MACAddress():
+ def __init__(self, mac):
+ '''MAC Address as a text-string (aa:bb:cc:dd:ee:ff) or 6 bytes'''
+ # Of course Python 2 doesn't distinguish str from bytes
+ if type(mac) is bytes and len(mac) == 6:
+ self.mac_binary = mac
+ self.mac_string = mac_ntop(mac)
+ else:
+ self.mac_binary = mac_pton(mac)
+ self.mac_string = mac
+
+ @property
+ def packed(self):
+ return self.mac_binary
+
+ def __len__(self):
+ return 6
+
+ def __str__(self):
+ return self.mac_string
+
+ def __repr__(self):
+ return '%s(%s)' % (self.__class__.__name__, self.mac_string)
diff --git a/src/vpp-api/python/vpp_papi/vpp_format.py b/src/vpp-api/python/vpp_papi/vpp_format.py
index 1b880ecd248..fec0667862c 100644
--- a/src/vpp-api/python/vpp_papi/vpp_format.py
+++ b/src/vpp-api/python/vpp_papi/vpp_format.py
@@ -16,6 +16,7 @@
from socket import inet_pton, inet_ntop, AF_INET6, AF_INET
import socket
import ipaddress
+from . import macaddress
# Copies from vl_api_address_t definition
ADDRESS_IP4 = 0
@@ -94,6 +95,11 @@ conversion_table = {
'len': o.prefixlen},
'str': lambda s: format_vl_api_prefix_t(s)
},
+ 'vl_api_mac_address_t':
+ {
+ 'MACAddress': lambda o: o.packed,
+ 'str': lambda s: macaddress.mac_pton(s)
+ },
}
@@ -118,4 +124,5 @@ conversion_unpacker_table = {
'vl_api_ip4_prefix_t': lambda o: ipaddress.IPv4Network((o.prefix, o.len)),
'vl_api_address_t': lambda o: unformat_api_address_t(o),
'vl_api_prefix_t': lambda o: unformat_api_prefix_t(o),
+ 'vl_api_mac_address_t': lambda o: macaddress.MACAddress(o),
}
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index 4de257c6924..9c4ede90d48 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -28,6 +28,7 @@ import weakref
import atexit
from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType, BaseTypes
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
+from . macaddress import MACAddress, mac_pton, mac_ntop
logger = logging.getLogger(__name__)
@@ -57,6 +58,7 @@ def vpp_atexit(vpp_weakref):
vpp_instance.logger.debug('Cleaning up VPP on exit')
vpp_instance.disconnect()
+
if sys.version[0] == '2':
def vpp_iterator(d):
return d.iteritems()
diff --git a/src/vpp-api/python/vpp_papi/vpp_serializer.py b/src/vpp-api/python/vpp_papi/vpp_serializer.py
index 418c0243402..d62e3a4a57a 100644
--- a/src/vpp-api/python/vpp_papi/vpp_serializer.py
+++ b/src/vpp-api/python/vpp_papi/vpp_serializer.py
@@ -30,9 +30,10 @@ import socket
logger = logging.getLogger(__name__)
if sys.version[0] == '2':
- check = lambda d: type(d) is dict
+ def check(d): type(d) is dict
else:
- check = lambda d: type(d) is dict or type(d) is bytes
+ def check(d): type(d) is dict or type(d) is bytes
+
def conversion_required(data, field_type):
if check(data):
@@ -101,7 +102,7 @@ class String(object):
return b'', 0
p = BaseTypes('u8', length)
x, size = p.unpack(data, offset + length_field_size)
- x2 = x.split(b'\0',1)[0]
+ x2 = x.split(b'\0', 1)[0]
return (x2.decode('utf8'), size + length_field_size)
diff --git a/src/vpp/api/types.c b/src/vpp/api/types.c
index 1e36bf5fb69..0a48711c611 100644
--- a/src/vpp/api/types.c
+++ b/src/vpp/api/types.c
@@ -63,7 +63,7 @@ unformat_vl_api_mac_address (unformat_input_t * input, va_list * args)
{
vl_api_mac_address_t *mac = va_arg (*args, vl_api_mac_address_t *);
- return (unformat (input, "%U",unformat_ethernet_address, mac->bytes));
+ return (unformat (input, "%U",unformat_ethernet_address, mac));
}
uword
@@ -86,6 +86,6 @@ format_vl_api_mac_address (u8 * s, va_list * args)
{
vl_api_mac_address_t *mac = va_arg (*args, vl_api_mac_address_t *);
- return (format (s, "%U", format_ethernet_address, mac->bytes));
+ return (format (s, "%U", format_ethernet_address, mac));
}
diff --git a/test/test_bond.py b/test/test_bond.py
index b955f899190..9926d230564 100644
--- a/test/test_bond.py
+++ b/test/test_bond.py
@@ -7,8 +7,8 @@ from framework import VppTestCase, VppTestRunner
from scapy.packet import Raw
from scapy.layers.l2 import Ether
from scapy.layers.inet import IP, UDP
-from vpp_mac import mactobinary
from vpp_bond_interface import VppBondInterface
+from vpp_papi import MACAddress
class TestBondInterface(VppTestCase):
@@ -56,7 +56,7 @@ class TestBondInterface(VppTestCase):
# create interface (BondEthernet0)
# self.logger.info("create bond")
bond0_mac = "02:fe:38:30:59:3c"
- mac = mactobinary(bond0_mac)
+ mac = MACAddress(bond0_mac).packed
bond0 = VppBondInterface(self,
mode=3,
lb=1,
diff --git a/test/test_dhcp.py b/test/test_dhcp.py
index db3e3f3bab0..3d00f1b8468 100644
--- a/test/test_dhcp.py
+++ b/test/test_dhcp.py
@@ -8,7 +8,6 @@ from framework import VppTestCase, VppTestRunner, running_extended_tests
from vpp_neighbor import VppNeighbor
from vpp_ip_route import find_route, VppIpTable
from util import mk_ll_addr
-from vpp_mac import mactobinary, binarytomac
from scapy.layers.l2 import Ether, getmacbyip, ARP
from scapy.layers.inet import IP, UDP, ICMP
from scapy.layers.inet6 import IPv6, in6_getnsmac
@@ -20,6 +19,7 @@ from scapy.layers.dhcp6 import DHCP6, DHCP6_Solicit, DHCP6_RelayForward, \
from socket import AF_INET, AF_INET6
from scapy.utils import inet_pton, inet_ntop
from scapy.utils6 import in6_ptop
+from vpp_papi import mac_pton
DHCP4_CLIENT_PORT = 68
DHCP4_SERVER_PORT = 67
@@ -1218,7 +1218,7 @@ class TestDHCP(VppTestCase):
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1,
yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'offer'),
('server_id', self.pg3.remote_ip4),
'end']))
@@ -1238,7 +1238,7 @@ class TestDHCP(VppTestCase):
IP(src=self.pg3.remote_ip4, dst="255.255.255.255") /
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1, yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'ack'),
('subnet_mask', "255.255.255.0"),
('router', self.pg3.remote_ip4),
@@ -1267,7 +1267,7 @@ class TestDHCP(VppTestCase):
# remove the left over ARP entry
self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
- mactobinary(self.pg3.remote_mac),
+ mac_pton(self.pg3.remote_mac),
self.pg3.remote_ip4,
is_add=0)
#
@@ -1315,7 +1315,7 @@ class TestDHCP(VppTestCase):
IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1, yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'ack'),
('subnet_mask', "255.255.255.0"),
('router', self.pg3.remote_ip4),
@@ -1373,7 +1373,7 @@ class TestDHCP(VppTestCase):
IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1, yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'offer'),
('server_id', self.pg3.remote_ip4),
'end']))
@@ -1394,7 +1394,7 @@ class TestDHCP(VppTestCase):
IP(src=self.pg3.remote_ip4, dst=self.pg3.local_ip4) /
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1, yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'ack'),
('subnet_mask', "255.255.255.0"),
('router', self.pg3.remote_ip4),
@@ -1423,7 +1423,7 @@ class TestDHCP(VppTestCase):
# remove the left over ARP entry
self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
- mactobinary(self.pg3.remote_mac),
+ mac_pton(self.pg3.remote_mac),
self.pg3.remote_ip4,
is_add=0)
@@ -1481,7 +1481,7 @@ class TestDHCP(VppTestCase):
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1,
yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'offer'),
('server_id', self.pg3.remote_ip4),
('lease_time', lease_time),
@@ -1502,7 +1502,7 @@ class TestDHCP(VppTestCase):
IP(src=self.pg3.remote_ip4, dst='255.255.255.255') /
UDP(sport=DHCP4_SERVER_PORT, dport=DHCP4_CLIENT_PORT) /
BOOTP(op=1, yiaddr=self.pg3.local_ip4,
- chaddr=mactobinary(self.pg3.local_mac)) /
+ chaddr=mac_pton(self.pg3.local_mac)) /
DHCP(options=[('message-type', 'ack'),
('subnet_mask', '255.255.255.0'),
('router', self.pg3.remote_ip4),
@@ -1530,7 +1530,7 @@ class TestDHCP(VppTestCase):
# remove the left over ARP entry
self.vapi.ip_neighbor_add_del(self.pg3.sw_if_index,
- mactobinary(self.pg3.remote_mac),
+ mac_pton(self.pg3.remote_mac),
self.pg3.remote_ip4,
is_add=0)
diff --git a/test/test_gbp.py b/test/test_gbp.py
index efac2de6756..d587759fffa 100644
--- a/test/test_gbp.py
+++ b/test/test_gbp.py
@@ -14,9 +14,8 @@ from vpp_vxlan_gbp_tunnel import *
from vpp_sub_interface import VppDot1QSubint
from vpp_ip import *
-from vpp_mac import *
from vpp_papi_provider import L2_PORT_TYPE
-from vpp_papi import VppEnum
+from vpp_papi import VppEnum, MACAddress
from scapy.packet import Raw
from scapy.layers.l2 import Ether, ARP, Dot1Q
@@ -35,7 +34,7 @@ def find_gbp_endpoint(test, sw_if_index=None, ip=None, mac=None):
if ip:
vip = VppIpAddress(ip)
if mac:
- vmac = VppMacAddress(mac)
+ vmac = MACAddress(mac)
eps = test.vapi.gbp_endpoint_dump()
@@ -48,7 +47,7 @@ def find_gbp_endpoint(test, sw_if_index=None, ip=None, mac=None):
if vip == eip:
return True
if mac:
- if vmac == ep.endpoint.mac:
+ if vmac.packed == ep.endpoint.mac:
return True
return False
@@ -67,12 +66,8 @@ class VppGbpEndpoint(VppObject):
"""
@property
- def bin_mac(self):
- return self.vmac.bytes
-
- @property
def mac(self):
- return self.vmac.address
+ return str(self.vmac)
@property
def mac(self):
@@ -118,9 +113,9 @@ class VppGbpEndpoint(VppObject):
self._fip6 = VppIpAddress(fip6)
if mac:
- self.vmac = VppMacAddress(self.itf.remote_mac)
+ self.vmac = MACAddress(self.itf.remote_mac)
else:
- self.vmac = VppMacAddress("00:00:00:00:00:00")
+ self.vmac = MACAddress("00:00:00:00:00:00")
self.flags = flags
self.tun_src = VppIpAddress(tun_src)
@@ -130,7 +125,7 @@ class VppGbpEndpoint(VppObject):
res = self._test.vapi.gbp_endpoint_add(
self.itf.sw_if_index,
[self.ip4.encode(), self.ip6.encode()],
- self.vmac.encode(),
+ self.vmac.packed,
self.epg.epg,
self.flags,
self.tun_src.encode(),
@@ -414,7 +409,7 @@ class VppGbpContractNextHop():
def encode(self):
return {'ip': self.ip.encode(),
- 'mac': self.mac.encode(),
+ 'mac': self.mac.packed,
'bd_id': self.bd.bd.bd_id,
'rd_id': self.rd.rd_id}
@@ -584,7 +579,7 @@ class TestGBP(VppTestCase):
self.create_pg_interfaces(range(9))
self.create_loopback_interfaces(8)
- self.router_mac = VppMacAddress("00:11:22:33:44:55")
+ self.router_mac = MACAddress("00:11:22:33:44:55")
for i in self.pg_interfaces:
i.admin_up()
@@ -671,7 +666,7 @@ class TestGBP(VppTestCase):
rx = self.send_and_expect(src, tx, dst)
for r in rx:
- self.assertEqual(r[Ether].src, self.router_mac.address)
+ self.assertEqual(r[Ether].src, str(self.router_mac))
self.assertEqual(r[Ether].dst, dst.remote_mac)
self.assertEqual(r[IP].dst, dst_ip)
self.assertEqual(r[IP].src, src_ip)
@@ -681,7 +676,7 @@ class TestGBP(VppTestCase):
rx = self.send_and_expect(src, tx, dst)
for r in rx:
- self.assertEqual(r[Ether].src, self.router_mac.address)
+ self.assertEqual(r[Ether].src, str(self.router_mac))
self.assertEqual(r[Ether].dst, dst.remote_mac)
self.assertEqual(r[IPv6].dst, dst_ip)
self.assertEqual(r[IPv6].src, src_ip)
@@ -797,7 +792,7 @@ class TestGBP(VppTestCase):
VppIpInterfaceBind(self, epg.bvi, epg.rd.t6).add_vpp_config()
self.vapi.sw_interface_set_mac_address(
epg.bvi.sw_if_index,
- self.router_mac.bytes)
+ self.router_mac.packed)
# The BVIs are NAT inside interfaces
self.vapi.nat44_interface_add_del_feature(epg.bvi.sw_if_index,
@@ -818,10 +813,10 @@ class TestGBP(VppTestCase):
# add the BD ARP termination entry for BVI IP
epg.bd_arp_ip4 = VppBridgeDomainArpEntry(self, epg.bd.bd,
- self.router_mac.address,
+ str(self.router_mac),
epg.bvi_ip4)
epg.bd_arp_ip6 = VppBridgeDomainArpEntry(self, epg.bd.bd,
- self.router_mac.address,
+ str(self.router_mac),
epg.bvi_ip6)
epg.bd_arp_ip4.add_vpp_config()
epg.bd_arp_ip6.add_vpp_config()
@@ -977,13 +972,13 @@ class TestGBP(VppTestCase):
# packets to non-local L3 destinations dropped
#
pkt_intra_epg_220_ip4 = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IP(src=eps[0].ip4.address,
dst="10.0.0.99") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
pkt_inter_epg_222_ip4 = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IP(src=eps[0].ip4.address,
dst="10.0.1.99") /
UDP(sport=1234, dport=1234) /
@@ -992,7 +987,7 @@ class TestGBP(VppTestCase):
self.send_and_assert_no_replies(self.pg0, pkt_intra_epg_220_ip4 * 65)
pkt_inter_epg_222_ip6 = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IPv6(src=eps[0].ip6.address,
dst="2001:10::99") /
UDP(sport=1234, dport=1234) /
@@ -1120,7 +1115,7 @@ class TestGBP(VppTestCase):
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
pkt_inter_epg_220_to_222 = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IP(src=eps[0].ip4.address,
dst=eps[3].ip4.address) /
UDP(sport=1234, dport=1234) /
@@ -1201,7 +1196,7 @@ class TestGBP(VppTestCase):
self.send_and_expect_routed(eps[0].itf,
pkt_inter_epg_220_to_222 * 65,
eps[3].itf,
- self.router_mac.address)
+ str(self.router_mac))
#
# remove both contracts, traffic stops in both directions
@@ -1272,7 +1267,7 @@ class TestGBP(VppTestCase):
# From an EP to an outside addess: IN2OUT
#
pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IP(src=eps[0].ip4.address,
dst="1.1.1.1") /
UDP(sport=1234, dport=1234) /
@@ -1307,7 +1302,7 @@ class TestGBP(VppTestCase):
eps[0].fip4.address)
pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IPv6(src=eps[0].ip6.address,
dst="6001::1") /
UDP(sport=1234, dport=1234) /
@@ -1321,7 +1316,7 @@ class TestGBP(VppTestCase):
#
# From a global address to an EP: OUT2IN
#
- pkt_inter_epg_220_from_global = (Ether(src=self.router_mac.address,
+ pkt_inter_epg_220_from_global = (Ether(src=str(self.router_mac),
dst=self.pg0.remote_mac) /
IP(dst=eps[0].fip4.address,
src="1.1.1.1") /
@@ -1347,7 +1342,7 @@ class TestGBP(VppTestCase):
eps[0].itf,
eps[0].ip4.address)
- pkt_inter_epg_220_from_global = (Ether(src=self.router_mac.address,
+ pkt_inter_epg_220_from_global = (Ether(src=str(self.router_mac),
dst=self.pg0.remote_mac) /
IPv6(dst=eps[0].fip6.address,
src="6001::1") /
@@ -1364,7 +1359,7 @@ class TestGBP(VppTestCase):
# IN2OUT2IN
#
pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IP(src=eps[0].ip4.address,
dst=eps[1].fip4.address) /
UDP(sport=1234, dport=1234) /
@@ -1377,7 +1372,7 @@ class TestGBP(VppTestCase):
eps[1].ip4.address)
pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac,
- dst=self.router_mac.address) /
+ dst=str(self.router_mac)) /
IPv6(src=eps[0].ip6.address,
dst=eps[1].fip6.address) /
UDP(sport=1234, dport=1234) /
@@ -2039,7 +2034,7 @@ class TestGBP(VppTestCase):
rd1 = VppGbpRouteDomain(self, 2, t4, t6, tun_ip4_uu, tun_ip6_uu)
rd1.add_vpp_config()
- self.loop0.set_mac(self.router_mac.address)
+ self.loop0.set_mac(self.router_mac)
#
# Bind the BVI to the RD
@@ -2476,7 +2471,7 @@ class TestGBP(VppTestCase):
rd1 = VppGbpRouteDomain(self, 2, t4, t6)
rd1.add_vpp_config()
- self.loop0.set_mac(self.router_mac.address)
+ self.loop0.set_mac(self.router_mac)
#
# Bind the BVI to the RD
@@ -2840,19 +2835,19 @@ class TestGBP(VppTestCase):
# an L3 switch packet between local EPs in different EPGs
# different dest ports on each so the are LB hashed differently
#
- p4 = [(Ether(src=ep1.mac, dst=self.router_mac.address) /
+ p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
IP(src=ep1.ip4.address, dst=ep2.ip4.address) /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100)),
- (Ether(src=ep2.mac, dst=self.router_mac.address) /
+ (Ether(src=ep2.mac, dst=str(self.router_mac)) /
IP(src=ep2.ip4.address, dst=ep1.ip4.address) /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))]
- p6 = [(Ether(src=ep1.mac, dst=self.router_mac.address) /
+ p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
IPv6(src=ep1.ip6.address, dst=ep2.ip6.address) /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100)),
- (Ether(src=ep2.mac, dst=self.router_mac.address) /
+ (Ether(src=ep2.mac, dst=str(self.router_mac)) /
IPv6(src=ep2.ip6.address, dst=ep1.ip6.address) /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))]
@@ -2907,7 +2902,7 @@ class TestGBP(VppTestCase):
dst=self.pg7.local_ip4) /
UDP(sport=1234, dport=48879) /
VXLAN(vni=444, gpid=221, flags=0x88) /
- Ether(src="00:22:22:22:22:33", dst=self.router_mac.address) /
+ Ether(src="00:22:22:22:22:33", dst=str(self.router_mac)) /
IP(src="10.0.0.88", dst=ep1.ip4.address) /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
@@ -2925,7 +2920,7 @@ class TestGBP(VppTestCase):
dst=self.pg7.local_ip4) /
UDP(sport=1234, dport=48879) /
VXLAN(vni=444, gpid=221, flags=0x88) /
- Ether(src="00:22:22:22:22:33", dst=self.router_mac.address) /
+ Ether(src="00:22:22:22:22:33", dst=str(self.router_mac)) /
IPv6(src="2001:10::88", dst=ep1.ip6.address) /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
@@ -2940,11 +2935,11 @@ class TestGBP(VppTestCase):
#
# L3 switch from local to remote EP
#
- p4 = [(Ether(src=ep1.mac, dst=self.router_mac.address) /
+ p4 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
IP(src=ep1.ip4.address, dst="10.0.0.88") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))]
- p6 = [(Ether(src=ep1.mac, dst=self.router_mac.address) /
+ p6 = [(Ether(src=ep1.mac, dst=str(self.router_mac)) /
IPv6(src=ep1.ip6.address, dst="2001:10::88") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))]
@@ -3027,7 +3022,7 @@ class TestGBP(VppTestCase):
rd1 = VppGbpRouteDomain(self, 2, t4, t6)
rd1.add_vpp_config()
- self.loop0.set_mac(self.router_mac.address)
+ self.loop0.set_mac(self.router_mac)
#
# Bind the BVI to the RD
@@ -3104,12 +3099,12 @@ class TestGBP(VppTestCase):
# packets destined to unkown addresses in the BVI's subnet
# are ARP'd for
#
- p4 = (Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ p4 = (Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
Dot1Q(vlan=100) /
IP(src="10.0.0.1", dst="10.0.0.88") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
- p6 = (Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ p6 = (Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
Dot1Q(vlan=100) /
IPv6(src="2001:10::1", dst="2001:10::88") /
UDP(sport=1234, dport=1234) /
@@ -3165,7 +3160,7 @@ class TestGBP(VppTestCase):
dst=self.pg7.local_ip4) /
UDP(sport=1234, dport=48879) /
VXLAN(vni=444, gpid=220, flags=0x88) /
- Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
IP(src="10.0.0.101", dst="10.0.0.1") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
@@ -3193,7 +3188,7 @@ class TestGBP(VppTestCase):
dst=self.pg7.local_ip4) /
UDP(sport=1234, dport=48879) /
VXLAN(vni=444, gpid=220, flags=0x88) /
- Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
IP(src="10.0.0.101", dst="10.220.0.1") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
@@ -3221,7 +3216,7 @@ class TestGBP(VppTestCase):
dst=self.pg7.local_ip4) /
UDP(sport=1234, dport=48879) /
VXLAN(vni=444, gpid=220, flags=0x88) /
- Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
IP(src="10.0.0.101", dst="10.200.0.1") /
UDP(sport=1234, dport=1234) /
Raw('\xa5' * 100))
@@ -3234,7 +3229,7 @@ class TestGBP(VppTestCase):
#
# from the the subnet in EPG 220 beyond the external to remote
#
- p4 = (Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ p4 = (Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
Dot1Q(vlan=100) /
IP(src="10.220.0.1", dst=rep.ip4.address) /
UDP(sport=1234, dport=1234) /
@@ -3257,7 +3252,7 @@ class TestGBP(VppTestCase):
# from the the subnet in EPG 200 beyond the external to remote
# dropped due to no contract
#
- p4 = (Ether(src=self.pg0.remote_mac, dst=self.router_mac.address) /
+ p4 = (Ether(src=self.pg0.remote_mac, dst=str(self.router_mac)) /
Dot1Q(vlan=100) /
IP(src="10.200.0.1", dst=rep.ip4.address) /
UDP(sport=1234, dport=1234) /
diff --git a/test/test_ip4_irb.py b/test/test_ip4_irb.py
index a7fe7875053..8c3830c2d81 100644
--- a/test/test_ip4_irb.py
+++ b/test/test_ip4_irb.py
@@ -31,7 +31,7 @@ from scapy.layers.l2 import Ether
from scapy.layers.inet import IP, UDP
from framework import VppTestCase, VppTestRunner
-from vpp_mac import mactobinary
+from vpp_papi import MACAddress
from vpp_papi_provider import L2_PORT_TYPE
@@ -265,7 +265,7 @@ class TestIpIrb(VppTestCase):
self.send_and_verify_l2_to_ip()
# change the BVI's mac and resed traffic
- self.loop0.set_mac("00:00:00:11:11:33")
+ self.loop0.set_mac(MACAddress("00:00:00:11:11:33"))
self.send_and_verify_l2_to_ip()
# check it wasn't flooded
diff --git a/test/test_l2_fib.py b/test/test_l2_fib.py
index 436aa10c3ec..1cee58982e5 100644
--- a/test/test_l2_fib.py
+++ b/test/test_l2_fib.py
@@ -69,6 +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
@@ -205,7 +206,7 @@ class TestL2fib(VppTestCase):
swif = pg_if.sw_if_index
for host in hosts[swif]:
self.vapi.l2fib_add_del(
- host.mac, bd_id, swif, static_mac=1)
+ mac_pton(host.mac), bd_id, swif, static_mac=1)
def delete_l2_fib_entry(self, bd_id, hosts):
"""
@@ -218,7 +219,7 @@ class TestL2fib(VppTestCase):
swif = pg_if.sw_if_index
for host in hosts[swif]:
self.vapi.l2fib_add_del(
- host.mac, bd_id, swif, is_add=0)
+ mac_pton(host.mac), bd_id, swif, is_add=0)
def flush_int(self, swif, learned_hosts):
"""
diff --git a/test/test_l2bd_arp_term.py b/test/test_l2bd_arp_term.py
index f25be57d8e4..2321aa7c094 100644
--- a/test/test_l2bd_arp_term.py
+++ b/test/test_l2bd_arp_term.py
@@ -20,7 +20,6 @@ from scapy.layers.inet6 import IPv6, UDP, ICMPv6ND_NS, ICMPv6ND_RS, \
from framework import VppTestCase, VppTestRunner
from util import Host, ppp
-from vpp_mac import VppMacAddress, mactobinary
class TestL2bdArpTerm(VppTestCase):
@@ -72,7 +71,7 @@ class TestL2bdArpTerm(VppTestCase):
for e in entries:
ip = e.ip4 if is_ipv6 == 0 else e.ip6
self.vapi.bd_ip_mac_add_del(bd_id=bd_id,
- mac=VppMacAddress(e.mac).encode(),
+ mac=e.mac,
ip=ip,
is_ipv6=is_ipv6,
is_add=is_add)
diff --git a/test/test_nat.py b/test/test_nat.py
index a7ca6d3a6e0..9879b762cc9 100644
--- a/test/test_nat.py
+++ b/test/test_nat.py
@@ -18,7 +18,7 @@ from util import ppp
from ipfix import IPFIX, Set, Template, Data, IPFIXDecoder
from time import sleep
from util import ip4_range
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
from syslog_rfc5424_parser import SyslogMessage, ParseError
from syslog_rfc5424_parser.constants import SyslogFacility, SyslogSeverity
from vpp_papi_provider import SYSLOG_SEVERITY
@@ -2952,11 +2952,11 @@ class TestNAT44(MethodHolder):
""" NAT44 interfaces without configured IP address """
self.vapi.ip_neighbor_add_del(self.pg7.sw_if_index,
- mactobinary(self.pg7.remote_mac),
+ mac_pton(self.pg7.remote_mac),
self.pg7.remote_ip4n,
is_static=1)
self.vapi.ip_neighbor_add_del(self.pg8.sw_if_index,
- mactobinary(self.pg8.remote_mac),
+ mac_pton(self.pg8.remote_mac),
self.pg8.remote_ip4n,
is_static=1)
@@ -2994,11 +2994,11 @@ class TestNAT44(MethodHolder):
""" NAT44 interfaces without configured IP address - 1:1 NAT """
self.vapi.ip_neighbor_add_del(self.pg7.sw_if_index,
- mactobinary(self.pg7.remote_mac),
+ mac_pton(self.pg7.remote_mac),
self.pg7.remote_ip4n,
is_static=1)
self.vapi.ip_neighbor_add_del(self.pg8.sw_if_index,
- mactobinary(self.pg8.remote_mac),
+ mac_pton(self.pg8.remote_mac),
self.pg8.remote_ip4n,
is_static=1)
@@ -3040,11 +3040,11 @@ class TestNAT44(MethodHolder):
self.icmp_id_out = 30608
self.vapi.ip_neighbor_add_del(self.pg7.sw_if_index,
- mactobinary(self.pg7.remote_mac),
+ mac_pton(self.pg7.remote_mac),
self.pg7.remote_ip4n,
is_static=1)
self.vapi.ip_neighbor_add_del(self.pg8.sw_if_index,
- mactobinary(self.pg8.remote_mac),
+ mac_pton(self.pg8.remote_mac),
self.pg8.remote_ip4n,
is_static=1)
diff --git a/test/test_p2p_ethernet.py b/test/test_p2p_ethernet.py
index f08d0cc2b1f..34a4c24f655 100644
--- a/test/test_p2p_ethernet.py
+++ b/test/test_p2p_ethernet.py
@@ -13,7 +13,7 @@ from framework import VppTestCase, VppTestRunner
from vpp_sub_interface import VppP2PSubint
from vpp_ip import DpoProto
from vpp_ip_route import VppIpRoute, VppRoutePath
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
class P2PEthernetAPI(VppTestCase):
@@ -33,12 +33,12 @@ class P2PEthernetAPI(VppTestCase):
i.admin_up()
def create_p2p_ethernet(self, parent_if, sub_id, remote_mac):
- p2p = VppP2PSubint(self, parent_if, sub_id, mactobinary(remote_mac))
+ p2p = VppP2PSubint(self, parent_if, sub_id, mac_pton(remote_mac))
self.p2p_sub_ifs.append(p2p)
def delete_p2p_ethernet(self, parent_if, remote_mac):
self.vapi.delete_p2pethernet_subif(parent_if.sw_if_index,
- mactobinary(remote_mac))
+ mac_pton(remote_mac))
def test_api(self):
"""delete/create p2p subif"""
@@ -79,7 +79,7 @@ class P2PEthernetAPI(VppTestCase):
try:
macs.append(':'.join(re.findall('..', '{:02x}'.format(mac+i))))
self.vapi.create_p2pethernet_subif(self.pg2.sw_if_index,
- mactobinary(macs[i-1]),
+ mac_pton(macs[i-1]),
i)
except Exception:
self.logger.info("Failed to create subif %d %s" % (
@@ -144,7 +144,7 @@ class P2PEthernetIPV6(VppTestCase):
super(P2PEthernetIPV6, self).tearDown()
def create_p2p_ethernet(self, parent_if, sub_id, remote_mac):
- p2p = VppP2PSubint(self, parent_if, sub_id, mactobinary(remote_mac))
+ p2p = VppP2PSubint(self, parent_if, sub_id, mac_pton(remote_mac))
p2p.admin_up()
p2p.config_ip6()
p2p.disable_ipv6_ra()
@@ -389,7 +389,7 @@ class P2PEthernetIPV4(VppTestCase):
return dst_if.get_capture(count)
def create_p2p_ethernet(self, parent_if, sub_id, remote_mac):
- p2p = VppP2PSubint(self, parent_if, sub_id, mactobinary(remote_mac))
+ p2p = VppP2PSubint(self, parent_if, sub_id, mac_pton(remote_mac))
p2p.admin_up()
p2p.config_ip4()
return p2p
diff --git a/test/test_pppoe.py b/test/test_pppoe.py
index 615b7a0c880..b181f6bced7 100644
--- a/test/test_pppoe.py
+++ b/test/test_pppoe.py
@@ -14,7 +14,6 @@ from scapy.layers.ppp import PPPoE, PPPoED, PPP
from scapy.layers.inet import IP, UDP
from scapy.layers.inet6 import IPv6
from scapy.volatile import RandMAC, RandIP
-from vpp_mac import mactobinary
from util import ppp, ppc
import socket
diff --git a/test/test_util.py b/test/test_util.py
index 49095d85931..01ba8623952 100755
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -3,15 +3,15 @@
import unittest
from framework import VppTestCase, VppTestRunner
-from vpp_mac import mactobinary, binarytomac
+from vpp_papi import mac_pton, mac_ntop
class TestUtil (VppTestCase):
""" MAC to binary and back """
def test_mac_to_binary(self):
mac = 'aa:bb:cc:dd:ee:ff'
- b = mactobinary(mac)
- mac2 = binarytomac(b)
+ b = mac_pton(mac)
+ mac2 = mac_ntop(b)
self.assertEqual(type(mac), type(mac2))
self.assertEqual(mac2, mac)
diff --git a/test/util.py b/test/util.py
index a3ec6e3326b..9652b803f1d 100644
--- a/test/util.py
+++ b/test/util.py
@@ -14,7 +14,7 @@ from scapy.layers.inet6 import IPv6, IPv6ExtHdrFragment, IPv6ExtHdrRouting,\
from scapy.utils import hexdump
from socket import AF_INET6
from io import BytesIO
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
def ppp(headline, packet):
@@ -130,7 +130,7 @@ class Host(object):
@property
def bin_mac(self):
""" MAC address """
- return mactobinary(self._mac)
+ return mac_pton(self._mac)
@property
def ip4(self):
diff --git a/test/vpp_interface.py b/test/vpp_interface.py
index 3235d3f68c6..719f77b36c7 100644
--- a/test/vpp_interface.py
+++ b/test/vpp_interface.py
@@ -5,7 +5,7 @@ from abc import abstractmethod, ABCMeta
from six import moves
from util import Host, mk_ll_addr
-from vpp_mac import mactobinary, binarytomac
+from vpp_papi import mac_pton, mac_ntop
class VppInterface(object):
@@ -191,11 +191,10 @@ class VppInterface(object):
self._hosts_by_ip6 = {}
def set_mac(self, mac):
- self._local_mac = mac
- self._local_ip6_ll = mk_ll_addr(mac)
+ self._local_mac = str(mac)
+ self._local_ip6_ll = mk_ll_addr(self._local_mac)
self.test.vapi.sw_interface_set_mac_address(
- self.sw_if_index,
- mactobinary(self._local_mac))
+ self.sw_if_index, mac.packed)
def set_sw_if_index(self, sw_if_index):
self._sw_if_index = sw_if_index
@@ -234,7 +233,7 @@ class VppInterface(object):
if intf.sw_if_index == self.sw_if_index:
self._name = intf.interface_name.split(b'\0',
1)[0].decode('utf8')
- self._local_mac = binarytomac(intf.l2_address)
+ self._local_mac = mac_ntop(intf.l2_address)
self._dump = intf
break
else:
@@ -274,7 +273,7 @@ class VppInterface(object):
:param vrf_id: The FIB table / VRF ID. (Default value = 0)
"""
for host in self._remote_hosts:
- macn = mactobinary(host.mac)
+ macn = mac_pton(host.mac)
ipn = host.ip4n
self.test.vapi.ip_neighbor_add_del(
self.sw_if_index, macn, ipn)
@@ -305,7 +304,7 @@ class VppInterface(object):
:param vrf_id: The FIB table / VRF ID. (Default value = 0)
"""
for host in self._remote_hosts:
- macn = mactobinary(host.mac)
+ macn = mac_pton(host.mac)
ipn = host.ip6n
self.test.vapi.ip_neighbor_add_del(
self.sw_if_index, macn, ipn, is_ipv6=1)
diff --git a/test/vpp_l2.py b/test/vpp_l2.py
index e2f3760f1d1..182f2ce7419 100644
--- a/test/vpp_l2.py
+++ b/test/vpp_l2.py
@@ -5,8 +5,8 @@
from vpp_object import *
from vpp_ip import VppIpAddress
-from vpp_mac import VppMacAddress, mactobinary
from vpp_lo_interface import VppLoInterface
+from vpp_papi import MACAddress
class L2_PORT_TYPE:
@@ -39,7 +39,7 @@ def find_bridge_domain_port(test, bd_id, sw_if_index):
def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
- vmac = VppMacAddress(mac)
+ vmac = MACAddress(mac)
vip = VppIpAddress(ip)
if vip.version == 4:
@@ -50,17 +50,17 @@ def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
arps = test.vapi.bd_ip_mac_dump(bd_id)
for arp in arps:
# do IP addr comparison too once .api is fixed...
- if vmac.bytes == arp.mac_address and \
+ if vmac.packed == arp.mac_address and \
vip.bytes == arp.ip_address[:n]:
return True
return False
def find_l2_fib_entry(test, bd_id, mac, sw_if_index):
- vmac = VppMacAddress(mac)
+ vmac = MACAddress(mac)
lfs = test.vapi.l2_fib_table_dump(bd_id)
for lf in lfs:
- if vmac.bytes == lf.mac and sw_if_index == lf.sw_if_index:
+ if vmac.packed == lf.mac and sw_if_index == lf.sw_if_index:
return True
return False
@@ -143,13 +143,13 @@ class VppBridgeDomainArpEntry(VppObject):
def __init__(self, test, bd, mac, ip):
self._test = test
self.bd = bd
- self.mac = VppMacAddress(mac)
+ self.mac = MACAddress(mac)
self.ip = VppIpAddress(ip)
def add_vpp_config(self):
self._test.vapi.bd_ip_mac_add_del(
self.bd.bd_id,
- self.mac.encode(),
+ self.mac.packed,
self.ip.encode(),
is_add=1)
self._test.registry.register(self, self._test.logger)
@@ -157,14 +157,14 @@ class VppBridgeDomainArpEntry(VppObject):
def remove_vpp_config(self):
self._test.vapi.bd_ip_mac_add_del(
self.bd.bd_id,
- self.mac.encode(),
+ self.mac.packed,
self.ip.encode(),
is_add=0)
def query_vpp_config(self):
return find_bridge_domain_arp_entry(self._test,
self.bd.bd_id,
- self.mac.address,
+ self.mac.packed,
self.ip.address)
def __str__(self):
@@ -180,7 +180,7 @@ class VppL2FibEntry(VppObject):
static_mac=0, filter_mac=0, bvi_mac=-1):
self._test = test
self.bd = bd
- self.mac = VppMacAddress(mac)
+ self.mac = MACAddress(mac)
self.itf = itf
self.static_mac = static_mac
self.filter_mac = filter_mac
@@ -191,7 +191,7 @@ class VppL2FibEntry(VppObject):
def add_vpp_config(self):
self._test.vapi.l2fib_add_del(
- self.mac.address,
+ self.mac.packed,
self.bd.bd_id,
self.itf.sw_if_index,
is_add=1,
@@ -202,7 +202,7 @@ class VppL2FibEntry(VppObject):
def remove_vpp_config(self):
self._test.vapi.l2fib_add_del(
- self.mac.address,
+ self.mac.packed,
self.bd.bd_id,
self.itf.sw_if_index,
is_add=0)
@@ -210,7 +210,7 @@ class VppL2FibEntry(VppObject):
def query_vpp_config(self):
return find_l2_fib_entry(self._test,
self.bd.bd_id,
- self.mac.address,
+ self.mac.packed,
self.itf.sw_if_index)
def __str__(self):
diff --git a/test/vpp_mac.py b/test/vpp_mac.py
deleted file mode 100644
index b20bf54634c..00000000000
--- a/test/vpp_mac.py
+++ /dev/null
@@ -1,50 +0,0 @@
-"""
- MAC Types
-
-"""
-import binascii
-
-
-def mactobinary(mac):
- """ Convert the : separated format into binary packet data for the API """
- return binascii.unhexlify(mac.replace(':', ''))
-
-
-def binarytomac(binary):
- """ Convert binary packed data in a : separated string """
- x = b':'.join(binascii.hexlify(binary)[i:i + 2]
- for i in range(0, 12, 2))
- return str(x.decode('ascii'))
-
-
-class VppMacAddress():
- def __init__(self, addr):
- self._address = addr
-
- def encode(self):
- return {
- 'bytes': self.bytes
- }
-
- @property
- def bytes(self):
- return mactobinary(self.address)
-
- @property
- def address(self):
- return self._address
-
- def __str__(self):
- return self.address
-
- def __eq__(self, other):
- if isinstance(other, self.__class__):
- return self.address == other.address
- elif hasattr(other, "bytes"):
- # vl_api_mac_addres_t
- return self.bytes == other.bytes
- else:
- raise TypeError("Comparing VppMacAddress:%s"
- "with unknown type: %s" %
- (self, other))
- return False
diff --git a/test/vpp_neighbor.py b/test/vpp_neighbor.py
index 46854c9ba8c..7815a286fef 100644
--- a/test/vpp_neighbor.py
+++ b/test/vpp_neighbor.py
@@ -6,7 +6,7 @@
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
from vpp_object import *
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
def find_nbr(test, sw_if_index, ip_addr, is_static=0, inet=AF_INET, mac=None):
@@ -22,7 +22,7 @@ def find_nbr(test, sw_if_index, ip_addr, is_static=0, inet=AF_INET, mac=None):
if nbr_addr == n.ip_address[:s] \
and is_static == n.is_static:
if mac:
- if n.mac_address == mactobinary(mac):
+ if n.mac_address == mac_pton(mac):
return True
else:
return True
@@ -38,7 +38,7 @@ class VppNeighbor(VppObject):
af=AF_INET, is_static=False, is_no_fib_entry=0):
self._test = test
self.sw_if_index = sw_if_index
- self.mac_addr = mactobinary(mac_addr)
+ self.mac_addr = mac_pton(mac_addr)
self.af = af
self.is_static = is_static
self.is_no_fib_entry = is_no_fib_entry
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 4812cb6ef70..0a33c1eb2ac 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -4,7 +4,7 @@ import time
from collections import deque
from six import moves
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
from hook import Hook
from vpp_l2 import L2_PORT_TYPE
@@ -223,9 +223,6 @@ class VppPapiProvider(object):
"""
return cli + "\n" + str(self.cli(cli))
- def _convert_mac(self, mac):
- return mactobinary(mac)
-
def show_version(self):
""" """
return self.api(self.papi.show_version, {})
@@ -643,7 +640,7 @@ class VppPapiProvider(object):
interface. (Default value = 0)
"""
return self.api(self.papi.l2fib_add_del,
- {'mac': self._convert_mac(mac),
+ {'mac': mac,
'bd_id': bd_id,
'sw_if_index': sw_if_index,
'is_add': is_add,
diff --git a/test/vpp_pppoe_interface.py b/test/vpp_pppoe_interface.py
index 28d8a714972..9be92327dcf 100644
--- a/test/vpp_pppoe_interface.py
+++ b/test/vpp_pppoe_interface.py
@@ -1,7 +1,7 @@
from vpp_interface import VppInterface
import socket
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
class VppPppoeInterface(VppInterface):
@@ -20,7 +20,7 @@ class VppPppoeInterface(VppInterface):
def add_vpp_config(self):
cip = socket.inet_pton(socket.AF_INET, self.client_ip)
- cmac = mactobinary(self.client_mac)
+ cmac = mac_pton(self.client_mac)
r = self.test.vapi.pppoe_add_del_session(
cip, cmac,
session_id=self.session_id,
@@ -30,7 +30,7 @@ class VppPppoeInterface(VppInterface):
def remove_vpp_config(self):
cip = socket.inet_pton(socket.AF_INET, self.client_ip)
- cmac = mactobinary(self.client_mac)
+ cmac = mac_pton(self.client_mac)
self.unconfig()
self.test.vapi.pppoe_add_del_session(
cip, cmac,