6 from vpp_object import VppObject
7 from vpp_lo_interface import VppLoInterface
8 from vpp_papi import MACAddress
9 from vpp_sub_interface import L2_VTR_OP
32 def find_bridge_domain(test, bd_id):
33 bds = test.vapi.bridge_domain_dump(bd_id)
37 def find_bridge_domain_port(test, bd_id, sw_if_index):
38 bds = test.vapi.bridge_domain_dump(bd_id)
40 for p in bd.sw_if_details:
41 if p.sw_if_index == sw_if_index:
46 def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
47 arps = test.vapi.bd_ip_mac_dump(bd_id)
49 # do IP addr comparison too once .api is fixed...
50 if mac == str(arp.entry.mac) and \
51 ip == str(arp.entry.ip):
56 def find_l2_fib_entry(test, bd_id, mac, sw_if_index):
57 vmac = MACAddress(mac)
58 lfs = test.vapi.l2_fib_table_dump(bd_id)
60 if vmac.packed == lf.mac and sw_if_index == lf.sw_if_index:
65 class VppBridgeDomain(VppObject):
67 def __init__(self, test, bd_id,
68 flood=1, uu_flood=1, forward=1,
69 learn=1, arp_term=1, arp_ufwd=0):
73 self.uu_flood = uu_flood
74 self.forward = forward
76 self.arp_term = arp_term
77 self.arp_ufwd = arp_ufwd
79 def add_vpp_config(self):
80 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id,
82 uu_flood=self.uu_flood,
85 arp_term=self.arp_term,
86 arp_ufwd=self.arp_ufwd,
88 self._test.registry.register(self, self._test.logger)
91 def remove_vpp_config(self):
92 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id, is_add=0)
94 def query_vpp_config(self):
95 return find_bridge_domain(self._test, self.bd_id)
98 return "bridge-domain-%d" % (self.bd_id)
101 class VppBridgeDomainPort(VppObject):
103 def __init__(self, test, bd, itf,
104 port_type=L2_PORT_TYPE.NORMAL):
108 self.port_type = port_type
110 def add_vpp_config(self):
111 self._test.vapi.sw_interface_set_l2_bridge(
112 rx_sw_if_index=self.itf.sw_if_index, bd_id=self.bd.bd_id,
113 port_type=self.port_type, enable=1)
114 self._test.registry.register(self, self._test.logger)
117 def remove_vpp_config(self):
118 self._test.vapi.sw_interface_set_l2_bridge(
119 rx_sw_if_index=self.itf.sw_if_index, bd_id=self.bd.bd_id,
120 port_type=self.port_type, enable=0)
122 def query_vpp_config(self):
123 return find_bridge_domain_port(self._test,
125 self.itf.sw_if_index)
128 return "BD-Port-%s-%s" % (self.bd, self.itf)
131 class VppBridgeDomainArpEntry(VppObject):
133 def __init__(self, test, bd, mac, ip):
139 def add_vpp_config(self):
140 self._test.vapi.bd_ip_mac_add_del(is_add=1,
142 'bd_id': self.bd.bd_id,
145 self._test.registry.register(self, self._test.logger)
148 def remove_vpp_config(self):
149 self._test.vapi.bd_ip_mac_add_del(is_add=0,
151 'bd_id': self.bd.bd_id,
155 def query_vpp_config(self):
156 return find_bridge_domain_arp_entry(self._test,
162 return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip)
165 class VppL2FibEntry(VppObject):
167 def __init__(self, test, bd, mac, itf,
168 static_mac=0, filter_mac=0, bvi_mac=-1):
171 self.mac = MACAddress(mac)
173 self.static_mac = static_mac
174 self.filter_mac = filter_mac
176 self.bvi_mac = isinstance(self.itf, VppLoInterface)
178 self.bvi_mac = bvi_mac
180 def add_vpp_config(self):
181 self._test.vapi.l2fib_add_del(
184 self.itf.sw_if_index,
186 static_mac=self.static_mac,
187 filter_mac=self.filter_mac,
188 bvi_mac=self.bvi_mac)
189 self._test.registry.register(self, self._test.logger)
192 def remove_vpp_config(self):
193 self._test.vapi.l2fib_add_del(
196 self.itf.sw_if_index,
199 def query_vpp_config(self):
200 return find_l2_fib_entry(self._test,
203 self.itf.sw_if_index)
206 return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)
209 class VppL2Vtr(VppObject):
211 def __init__(self, test, itf, op):
216 def add_vpp_config(self):
217 self.itf.set_vtr(self.op)
218 self._test.registry.register(self, self._test.logger)
221 def remove_vpp_config(self):
222 self.itf.set_vtr(L2_VTR_OP.L2_DISABLED)
224 def query_vpp_config(self):
225 ds = self._test.vapi.sw_interface_dump()
226 d = self.itf.get_interface_config_from_dump(ds)
229 return (d.vtr_op == self.op)
233 return "L2-vtr-%s-%d" % (str(self.itf), self.op)