Remove postinit from make-test interfaces

Change-Id: I1eb0f735c5d025e6096d5760eb01419a1c58530a
Signed-off-by: Matej Klotton <mklotton@cisco.com>
This commit is contained in:
Matej Klotton
2016-11-23 15:27:17 +01:00
committed by Damjan Marion
parent 1cd8f3c985
commit c5bf07fabe
4 changed files with 33 additions and 44 deletions

View File

@ -1,6 +1,5 @@
from abc import abstractmethod, ABCMeta from abc import abstractmethod, ABCMeta
import socket import socket
from logging import info
from util import Host from util import Host
@ -100,7 +99,7 @@ class VppInterface(object):
def host_by_mac(self, mac): def host_by_mac(self, mac):
""" """
:param ip: MAC address to find host by. :param mac: MAC address to find host by.
:return: Host object assigned to interface. :return: Host object assigned to interface.
""" """
return self._hosts_by_mac[mac] return self._hosts_by_mac[mac]
@ -138,8 +137,14 @@ 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
def post_init_setup(self): @abstractmethod
"""Additional setup run after creating an interface object.""" def __init__(self, test):
self._test = test
self._remote_hosts = []
self._hosts_by_mac = {}
self._hosts_by_ip4 = {}
self._hosts_by_ip6 = {}
self.generate_remote_hosts() self.generate_remote_hosts()
@ -153,8 +158,10 @@ class VppInterface(object):
for intf in r: for intf in r:
if intf.sw_if_index == self.sw_if_index: if intf.sw_if_index == self.sw_if_index:
self._name = intf.interface_name.split(b'\0', 1)[0] self._name = intf.interface_name.split(b'\0', 1)[0]
self._local_mac = ':'.join(intf.l2_address.encode('hex')[i:i + 2] self._local_mac = ':'.join(
for i in range(0, 12, 2)) intf.l2_address.encode('hex')[i:i + 2]
for i in range(0, 12, 2)
)
self._dump = intf self._dump = intf
break break
else: else:
@ -163,13 +170,6 @@ class VppInterface(object):
"in interface dump %s" % "in interface dump %s" %
(self.sw_if_index, repr(r))) (self.sw_if_index, repr(r)))
@abstractmethod
def __init__(self, test, index):
self._test = test
self.post_init_setup()
info("New %s, MAC=%s, remote_ip4=%s, local_ip4=%s" %
(self.__name__, self.remote_mac, self.remote_ip4, self.local_ip4))
def config_ip4(self): def config_ip4(self):
"""Configure IPv4 address on the VPP interface.""" """Configure IPv4 address on the VPP interface."""
addr = self.local_ip4n addr = self.local_ip4n

View File

@ -7,8 +7,7 @@ class VppLoInterface(VppInterface):
def __init__(self, test, lo_index): def __init__(self, test, lo_index):
""" Create VPP loopback interface """ """ Create VPP loopback interface """
self._lo_index = lo_index r = test.vapi.create_loopback()
self._test = test
r = self.test.vapi.create_loopback()
self._sw_if_index = r.sw_if_index self._sw_if_index = r.sw_if_index
self.post_init_setup() super(VppLoInterface, self).__init__(test)
self._lo_index = lo_index

View File

@ -58,9 +58,16 @@ class VppPGInterface(VppInterface):
self._out_history_counter += 1 self._out_history_counter += 1
return v return v
def post_init_setup(self): def __init__(self, test, pg_index):
""" Perform post-init setup for super class and add our own setup """ """ Create VPP packet-generator interface """
super(VppPGInterface, self).post_init_setup() r = test.vapi.pg_create_interface(pg_index)
self._sw_if_index = r.sw_if_index
super(VppPGInterface, self).__init__(test)
self._in_history_counter = 0
self._out_history_counter = 0
self._pg_index = pg_index
self._out_file = "pg%u_out.pcap" % self.pg_index self._out_file = "pg%u_out.pcap" % self.pg_index
self._out_path = self.test.tempdir + "/" + self._out_file self._out_path = self.test.tempdir + "/" + self._out_file
self._in_file = "pg%u_in.pcap" % self.pg_index self._in_file = "pg%u_in.pcap" % self.pg_index
@ -71,16 +78,6 @@ class VppPGInterface(VppInterface):
self._input_cli = "packet-generator new pcap %s source pg%u name %s" % ( self._input_cli = "packet-generator new pcap %s source pg%u name %s" % (
self.in_path, self.pg_index, self.cap_name) self.in_path, self.pg_index, self.cap_name)
def __init__(self, test, pg_index):
""" Create VPP packet-generator interface """
self._in_history_counter = 0
self._out_history_counter = 0
self._pg_index = pg_index
self._test = test
r = self.test.vapi.pg_create_interface(self.pg_index)
self._sw_if_index = r.sw_if_index
self.post_init_setup()
def enable_capture(self): def enable_capture(self):
""" Enable capture on this packet-generator interface""" """ Enable capture on this packet-generator interface"""
try: try:

View File

@ -18,7 +18,7 @@ class VppSubInterface(VppPGInterface):
return self._sub_id return self._sub_id
def __init__(self, test, parent, sub_id): def __init__(self, test, parent, sub_id):
self._test = test VppInterface.__init__(self, test)
self._parent = parent self._parent = parent
self._parent.add_sub_if(self) self._parent.add_sub_if(self)
self._sub_id = sub_id self._sub_id = sub_id
@ -55,11 +55,10 @@ class VppDot1QSubint(VppSubInterface):
def __init__(self, test, parent, sub_id, vlan=None): def __init__(self, test, parent, sub_id, vlan=None):
if vlan is None: if vlan is None:
vlan = sub_id vlan = sub_id
super(VppDot1QSubint, self).__init__(test, parent, sub_id)
self._vlan = vlan self._vlan = vlan
r = self.test.vapi.create_vlan_subif(parent.sw_if_index, self.vlan) r = test.vapi.create_vlan_subif(parent.sw_if_index, vlan)
self._sw_if_index = r.sw_if_index self._sw_if_index = r.sw_if_index
VppInterface.post_init_setup(self) super(VppDot1QSubint, self).__init__(test, parent, sub_id)
def create_arp_req(self): def create_arp_req(self):
packet = VppPGInterface.create_arp_req(self) packet = VppPGInterface.create_arp_req(self)
@ -98,21 +97,15 @@ class VppDot1ADSubint(VppSubInterface):
return self._inner_vlan return self._inner_vlan
def __init__(self, test, parent, sub_id, outer_vlan, inner_vlan): def __init__(self, test, parent, sub_id, outer_vlan, inner_vlan):
r = test.vapi.create_subif(parent.sw_if_index, sub_id, outer_vlan,
inner_vlan, dot1ad=1, two_tags=1,
exact_match=1)
self._sw_if_index = r.sw_if_index
super(VppDot1ADSubint, self).__init__(test, parent, sub_id) super(VppDot1ADSubint, self).__init__(test, parent, sub_id)
self.DOT1AD_TYPE = 0x88A8 self.DOT1AD_TYPE = 0x88A8
self.DOT1Q_TYPE = 0x8100 self.DOT1Q_TYPE = 0x8100
self._outer_vlan = outer_vlan self._outer_vlan = outer_vlan
self._inner_vlan = inner_vlan self._inner_vlan = inner_vlan
r = self.test.vapi.create_subif(
parent.sw_if_index,
self.sub_id,
self.outer_vlan,
self.inner_vlan,
dot1ad=1,
two_tags=1,
exact_match=1)
self._sw_if_index = r.sw_if_index
VppInterface.post_init_setup(self)
def create_arp_req(self): def create_arp_req(self):
packet = VppPGInterface.create_arp_req(self) packet = VppPGInterface.create_arp_req(self)