VPP-1508 Python3 abstract classes
Update the syntax to support abstract classes in python 2 and python 3. Depends on: new style classes -- https://gerrit.fd.io/r/16166 Change-Id: Iad2c1240149f38b3faca1b37ab95d3d210e1daee Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
This commit is contained in:

committed by
Damjan Marion

parent
dd3737284d
commit
3bce8ebfdf
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from abc import abstractmethod, ABCMeta
|
import abc
|
||||||
|
import six
|
||||||
|
|
||||||
from scapy.layers.l2 import Ether, Raw
|
from scapy.layers.l2 import Ether, Raw
|
||||||
from scapy.layers.inet import IP, UDP
|
from scapy.layers.inet import IP, UDP
|
||||||
@ -8,9 +9,9 @@ from scapy.layers.inet import IP, UDP
|
|||||||
from util import ip4_range
|
from util import ip4_range
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class BridgeDomain(object):
|
class BridgeDomain(object):
|
||||||
""" Bridge domain abstraction """
|
""" Bridge domain abstraction """
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def frame_request(self):
|
def frame_request(self):
|
||||||
@ -28,27 +29,27 @@ class BridgeDomain(object):
|
|||||||
UDP(sport=20000, dport=10000) /
|
UDP(sport=20000, dport=10000) /
|
||||||
Raw('\xa5' * 100))
|
Raw('\xa5' * 100))
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def ip_range(self, start, end):
|
def ip_range(self, start, end):
|
||||||
""" range of remote ip's """
|
""" range of remote ip's """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def encap_mcast(self, pkt, src_ip, src_mac, vni):
|
def encap_mcast(self, pkt, src_ip, src_mac, vni):
|
||||||
""" Encapsulate mcast packet """
|
""" Encapsulate mcast packet """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def encapsulate(self, pkt, vni):
|
def encapsulate(self, pkt, vni):
|
||||||
""" Encapsulate packet """
|
""" Encapsulate packet """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def decapsulate(self, pkt):
|
def decapsulate(self, pkt):
|
||||||
""" Decapsulate packet """
|
""" Decapsulate packet """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def check_encapsulation(self, pkt, vni, local_only=False):
|
def check_encapsulation(self, pkt, vni, local_only=False):
|
||||||
""" Verify the encapsulation """
|
""" Verify the encapsulation """
|
||||||
pass
|
pass
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import abc
|
||||||
|
import six
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from scapy.fields import BitField, ByteField, FlagsField, IntField
|
from scapy.fields import BitField, ByteField, FlagsField, IntField
|
||||||
@ -28,6 +31,7 @@ bind_layers(LISP_GPE_Header, IPv6, next_proto=2)
|
|||||||
bind_layers(LISP_GPE_Header, Ether, next_proto=3)
|
bind_layers(LISP_GPE_Header, Ether, next_proto=3)
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class Driver(object):
|
class Driver(object):
|
||||||
|
|
||||||
config_order = ['locator-sets',
|
config_order = ['locator-sets',
|
||||||
@ -61,7 +65,7 @@ class Driver(object):
|
|||||||
Raw(payload))
|
Raw(payload))
|
||||||
return packet
|
return packet
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def run(self):
|
def run(self):
|
||||||
""" testing procedure """
|
""" testing procedure """
|
||||||
pass
|
pass
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
""" test framework utilities """
|
""" test framework utilities """
|
||||||
|
|
||||||
|
import abc
|
||||||
import socket
|
import socket
|
||||||
|
import six
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
from abc import abstractmethod, ABCMeta
|
|
||||||
from scapy.utils6 import in6_mactoifaceid
|
from scapy.utils6 import in6_mactoifaceid
|
||||||
|
|
||||||
from scapy.layers.l2 import Ether
|
from scapy.layers.l2 import Ether
|
||||||
@ -93,11 +94,9 @@ def check_core_path(logger, core_path):
|
|||||||
|
|
||||||
|
|
||||||
class NumericConstant(object):
|
class NumericConstant(object):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
desc_dict = {}
|
desc_dict = {}
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self._value = value
|
self._value = value
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import binascii
|
import binascii
|
||||||
import socket
|
import socket
|
||||||
from abc import abstractmethod, ABCMeta
|
import abc
|
||||||
|
|
||||||
|
import six
|
||||||
from six import moves
|
from six import moves
|
||||||
|
|
||||||
from util import Host, mk_ll_addr
|
from util import Host, mk_ll_addr
|
||||||
from vpp_papi import mac_ntop
|
from vpp_papi import mac_ntop
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class VppInterface(object):
|
class VppInterface(object):
|
||||||
"""Generic VPP interface."""
|
"""Generic VPP interface."""
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sw_if_index(self):
|
def sw_if_index(self):
|
||||||
@ -181,7 +182,7 @@ class VppInterface(object):
|
|||||||
self._hosts_by_ip4[ip4] = host
|
self._hosts_by_ip4[ip4] = host
|
||||||
self._hosts_by_ip6[ip6] = host
|
self._hosts_by_ip6[ip6] = host
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def __init__(self, test):
|
def __init__(self, test):
|
||||||
self._test = test
|
self._test = test
|
||||||
|
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
""" abstract vpp object and object registry """
|
""" abstract vpp object and object registry """
|
||||||
|
|
||||||
from abc import ABCMeta, abstractmethod
|
import abc
|
||||||
|
import six
|
||||||
|
|
||||||
from six import moves
|
from six import moves
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class VppObject(object):
|
class VppObject(object):
|
||||||
""" Abstract vpp object """
|
""" Abstract vpp object """
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def add_vpp_config(self):
|
def add_vpp_config(self):
|
||||||
""" Add the configuration for this object to vpp. """
|
""" Add the configuration for this object to vpp. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def query_vpp_config(self):
|
def query_vpp_config(self):
|
||||||
"""Query the vpp configuration.
|
"""Query the vpp configuration.
|
||||||
|
|
||||||
:return: True if the object is configured"""
|
:return: True if the object is configured"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def remove_vpp_config(self):
|
def remove_vpp_config(self):
|
||||||
""" Remove the configuration for this object from vpp. """
|
""" Remove the configuration for this object from vpp. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def object_id(self):
|
def object_id(self):
|
||||||
""" Return a unique string representing this object. """
|
""" Return a unique string representing this object. """
|
||||||
pass
|
pass
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
from scapy.layers.l2 import Dot1Q
|
from scapy.layers.l2 import Dot1Q
|
||||||
from abc import abstractmethod, ABCMeta
|
import abc
|
||||||
|
import six
|
||||||
from vpp_pg_interface import VppPGInterface
|
from vpp_pg_interface import VppPGInterface
|
||||||
from vpp_papi_provider import L2_VTR_OP
|
from vpp_papi_provider import L2_VTR_OP
|
||||||
from vpp_interface import VppInterface
|
from vpp_interface import VppInterface
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class VppSubInterface(VppPGInterface):
|
class VppSubInterface(VppPGInterface):
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
@ -42,11 +43,11 @@ class VppSubInterface(VppPGInterface):
|
|||||||
super(VppSubInterface, self).set_sw_if_index(sw_if_index)
|
super(VppSubInterface, self).set_sw_if_index(sw_if_index)
|
||||||
self.set_vtr(L2_VTR_OP.L2_DISABLED)
|
self.set_vtr(L2_VTR_OP.L2_DISABLED)
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def create_arp_req(self):
|
def create_arp_req(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def create_ndp_req(self):
|
def create_ndp_req(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ class VppSubInterface(VppPGInterface):
|
|||||||
def resolve_ndp(self):
|
def resolve_ndp(self):
|
||||||
super(VppSubInterface, self).resolve_ndp(self.parent)
|
super(VppSubInterface, self).resolve_ndp(self.parent)
|
||||||
|
|
||||||
@abstractmethod
|
@abc.abstractmethod
|
||||||
def add_dot1_layer(self, pkt):
|
def add_dot1_layer(self, pkt):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
from abc import abstractmethod, ABCMeta
|
import abc
|
||||||
|
import six
|
||||||
from vpp_pg_interface import is_ipv6_misc
|
from vpp_pg_interface import is_ipv6_misc
|
||||||
from vpp_interface import VppInterface
|
from vpp_interface import VppInterface
|
||||||
|
|
||||||
|
|
||||||
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
class VppTunnelInterface(VppInterface):
|
class VppTunnelInterface(VppInterface):
|
||||||
""" VPP tunnel interface abstration """
|
""" VPP tunnel interface abstraction """
|
||||||
__metaclass__ = ABCMeta
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def __init__(self, test, parent_if):
|
def __init__(self, test, parent_if):
|
||||||
super(VppTunnelInterface, self).__init__(test)
|
super(VppTunnelInterface, self).__init__(test)
|
||||||
self.parent_if = parent_if
|
self.parent_if = parent_if
|
||||||
|
Reference in New Issue
Block a user