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
33 def find_bridge_domain(test, bd_id):
34 bds = test.vapi.bridge_domain_dump(bd_id)
38 def find_bridge_domain_port(test, bd_id, sw_if_index):
39 bds = test.vapi.bridge_domain_dump(bd_id)
41 for p in bd.sw_if_details:
42 if p.sw_if_index == sw_if_index:
47 def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
48 arps = test.vapi.bd_ip_mac_dump(bd_id)
50 # do IP addr comparison too once .api is fixed...
51 if mac == str(arp.entry.mac) and 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):
80 self.uu_flood = uu_flood
81 self.forward = forward
83 self.arp_term = arp_term
84 self.arp_ufwd = arp_ufwd
86 def add_vpp_config(self):
87 self._test.vapi.bridge_domain_add_del(
90 uu_flood=self.uu_flood,
93 arp_term=self.arp_term,
94 arp_ufwd=self.arp_ufwd,
97 self._test.registry.register(self, self._test.logger)
100 def remove_vpp_config(self):
101 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id, is_add=0)
103 def query_vpp_config(self):
104 return find_bridge_domain(self._test, self.bd_id)
107 return "bridge-domain-%d" % (self.bd_id)
110 class VppBridgeDomainPort(VppObject):
111 def __init__(self, test, bd, itf, port_type=L2_PORT_TYPE.NORMAL):
115 self.port_type = port_type
117 def add_vpp_config(self):
118 self._test.vapi.sw_interface_set_l2_bridge(
119 rx_sw_if_index=self.itf.sw_if_index,
121 port_type=self.port_type,
124 self._test.registry.register(self, self._test.logger)
127 def remove_vpp_config(self):
128 self._test.vapi.sw_interface_set_l2_bridge(
129 rx_sw_if_index=self.itf.sw_if_index,
131 port_type=self.port_type,
135 def query_vpp_config(self):
136 return find_bridge_domain_port(self._test, self.bd.bd_id, self.itf.sw_if_index)
139 return "BD-Port-%s-%s" % (self.bd, self.itf)
142 class VppBridgeDomainArpEntry(VppObject):
143 def __init__(self, test, bd, mac, ip):
149 def add_vpp_config(self):
150 self._test.vapi.bd_ip_mac_add_del(
151 is_add=1, entry={"bd_id": self.bd.bd_id, "ip": self.ip, "mac": self.mac}
153 self._test.registry.register(self, self._test.logger)
156 def remove_vpp_config(self):
157 self._test.vapi.bd_ip_mac_add_del(
158 is_add=0, entry={"bd_id": self.bd.bd_id, "ip": self.ip, "mac": self.mac}
161 def query_vpp_config(self):
162 return find_bridge_domain_arp_entry(
163 self._test, self.bd.bd_id, self.mac, self.ip
167 return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip)
170 class VppL2FibEntry(VppObject):
171 def __init__(self, test, bd, mac, itf, static_mac=0, filter_mac=0, bvi_mac=-1):
174 self.mac = MACAddress(mac)
176 self.static_mac = static_mac
177 self.filter_mac = filter_mac
179 self.bvi_mac = isinstance(self.itf, VppLoInterface)
181 self.bvi_mac = bvi_mac
183 def add_vpp_config(self):
184 self._test.vapi.l2fib_add_del(
187 self.itf.sw_if_index,
189 static_mac=self.static_mac,
190 filter_mac=self.filter_mac,
191 bvi_mac=self.bvi_mac,
193 self._test.registry.register(self, self._test.logger)
196 def remove_vpp_config(self):
197 self._test.vapi.l2fib_add_del(
198 self.mac.packed, self.bd.bd_id, self.itf.sw_if_index, is_add=0
201 def query_vpp_config(self):
202 return find_l2_fib_entry(
203 self._test, self.bd.bd_id, self.mac.packed, self.itf.sw_if_index
207 return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)
210 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)