summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/tests
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2020-06-02 14:38:53 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-08-11 13:51:59 +0000
commit710fe104620683755de71e2bb5d97c438987df74 (patch)
tree9df125d39f3ec03ab10f7e650d44dee3130f63b0 /src/vpp-api/python/vpp_papi/tests
parentfdc678081ca5f0971b8bcbf312c1e83017365c33 (diff)
papi: allow unknown address family
In unions all representations of the union are decoded. Which means trying to decode something that isn't an address might have invalid address family types. Type: fix Ticket: VPP-1884 Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: Id3381ef8cc885952c1eb488ebc70e276eaceb366
Diffstat (limited to 'src/vpp-api/python/vpp_papi/tests')
-rwxr-xr-xsrc/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
index 5d6993f91a7..317fea7269a 100755
--- a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
+++ b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
@@ -4,6 +4,7 @@ import unittest
from vpp_papi.vpp_serializer import VPPType, VPPEnumType
from vpp_papi.vpp_serializer import VPPUnionType, VPPMessage
from vpp_papi.vpp_serializer import VPPTypeAlias, VPPSerializerValueError
+from vpp_papi import MACAddress
from socket import inet_pton, AF_INET, AF_INET6
import logging
import sys
@@ -557,5 +558,56 @@ class TestAddType(unittest.TestCase):
self.assertEqual(len(b), 20)
+ def test_lisp(self):
+ VPPEnumType('vl_api_eid_type_t',
+ [["EID_TYPE_API_PREFIX", 0],
+ ["EID_TYPE_API_MAC", 1],
+ ["EID_TYPE_API_NSH", 2],
+ {"enumtype": "u32"}])
+
+ VPPTypeAlias('vl_api_mac_address_t', {'type': 'u8',
+ 'length': 6})
+
+ VPPType('vl_api_nsh_t',
+ [["u32", "spi"],
+ ["u8", "si"]])
+
+ VPPEnumType('vl_api_address_family_t', [["ADDRESS_IP4", 0],
+ ["ADDRESS_IP6", 1],
+ {"enumtype": "u32"}])
+ VPPTypeAlias('vl_api_ip4_address_t', {'type': 'u8',
+ 'length': 4})
+ VPPTypeAlias('vl_api_ip6_address_t', {'type': 'u8',
+ 'length': 16})
+ VPPUnionType('vl_api_address_union_t',
+ [["vl_api_ip4_address_t", "ip4"],
+ ["vl_api_ip6_address_t", "ip6"]])
+
+ VPPType('vl_api_address_t',
+ [['vl_api_address_family_t', 'af'],
+ ['vl_api_address_union_t', 'un']])
+
+ VPPType('vl_api_prefix_t',
+ [['vl_api_address_t', 'address'],
+ ['u8', 'len']])
+
+ VPPUnionType('vl_api_eid_address_t',
+ [["vl_api_prefix_t", "prefix"],
+ ["vl_api_mac_address_t", "mac"],
+ ["vl_api_nsh_t", "nsh"]])
+
+ eid = VPPType('vl_api_eid_t',
+ [["vl_api_eid_type_t", "type"],
+ ["vl_api_eid_address_t", "address"]])
+
+ b = eid.pack({'type':1,
+ 'address': {
+ 'mac': MACAddress('aa:bb:cc:dd:ee:ff')}})
+ self.assertEqual(len(b), 25)
+ nt, size = eid.unpack(b)
+ self.assertEqual(str(nt.address.mac), 'aa:bb:cc:dd:ee:ff')
+ self.assertIsNone(nt.address.prefix)
+
+
if __name__ == '__main__':
unittest.main()