6 from vpp_object import VppObject
7 from vpp_ip import VppIpAddress
8 from vpp_lo_interface import VppLoInterface
9 from vpp_papi import MACAddress
10 from vpp_sub_interface import L2_VTR_OP
29 def find_bridge_domain(test, bd_id):
30 bds = test.vapi.bridge_domain_dump(bd_id)
34 def find_bridge_domain_port(test, bd_id, sw_if_index):
35 bds = test.vapi.bridge_domain_dump(bd_id)
37 for p in bd.sw_if_details:
38 if p.sw_if_index == sw_if_index:
43 def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
44 vmac = MACAddress(mac)
45 vip = VppIpAddress(ip)
52 arps = test.vapi.bd_ip_mac_dump(bd_id)
54 # do IP addr comparison too once .api is fixed...
55 if vmac.packed == arp.mac_address and \
56 vip.bytes == arp.ip_address[:n]:
61 def find_l2_fib_entry(test, bd_id, mac, sw_if_index):
62 vmac = MACAddress(mac)
63 lfs = test.vapi.l2_fib_table_dump(bd_id)
65 if vmac.packed == lf.mac and sw_if_index == lf.sw_if_index:
70 class VppBridgeDomain(VppObject):
72 def __init__(self, test, bd_id,
73 flood=1, uu_flood=1, forward=1,
74 learn=1, arp_term=1, arp_ufwd=0):
78 self.uu_flood = uu_flood
79 self.forward = forward
81 self.arp_term = arp_term
82 self.arp_ufwd = arp_ufwd
84 def add_vpp_config(self):
85 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id,
87 uu_flood=self.uu_flood,
90 arp_term=self.arp_term,
91 arp_ufwd=self.arp_ufwd,
93 self._test.registry.register(self, self._test.logger)
95 def remove_vpp_config(self):
96 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id, is_add=0)
98 def query_vpp_config(self):
99 return find_bridge_domain(self._test, self.bd_id)
102 return "bridge-domain-%d" % (self.bd_id)
105 class VppBridgeDomainPort(VppObject):
107 def __init__(self, test, bd, itf,
108 port_type=L2_PORT_TYPE.NORMAL):
112 self.port_type = port_type
114 def add_vpp_config(self):
115 self._test.vapi.sw_interface_set_l2_bridge(
116 rx_sw_if_index=self.itf.sw_if_index, bd_id=self.bd.bd_id,
117 port_type=self.port_type, enable=1)
118 self._test.registry.register(self, self._test.logger)
120 def remove_vpp_config(self):
121 self._test.vapi.sw_interface_set_l2_bridge(
122 rx_sw_if_index=self.itf.sw_if_index, bd_id=self.bd.bd_id,
123 port_type=self.port_type, enable=0)
125 def query_vpp_config(self):
126 return find_bridge_domain_port(self._test,
128 self.itf.sw_if_index)
131 return "BD-Port-%s-%s" % (self.bd, self.itf)
134 class VppBridgeDomainArpEntry(VppObject):
136 def __init__(self, test, bd, mac, ip):
139 self.mac = MACAddress(mac)
140 self.ip = VppIpAddress(ip)
142 def add_vpp_config(self):
143 self._test.vapi.bd_ip_mac_add_del(bd_id=self.bd.bd_id, is_add=1,
146 self._test.registry.register(self, self._test.logger)
148 def remove_vpp_config(self):
149 self._test.vapi.bd_ip_mac_add_del(bd_id=self.bd.bd_id, is_add=0,
153 def query_vpp_config(self):
154 return find_bridge_domain_arp_entry(self._test,
160 return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip.address)
163 class VppL2FibEntry(VppObject):
165 def __init__(self, test, bd, mac, itf,
166 static_mac=0, filter_mac=0, bvi_mac=-1):
169 self.mac = MACAddress(mac)
171 self.static_mac = static_mac
172 self.filter_mac = filter_mac
174 self.bvi_mac = isinstance(self.itf, VppLoInterface)
176 self.bvi_mac = bvi_mac
178 def add_vpp_config(self):
179 self._test.vapi.l2fib_add_del(
182 self.itf.sw_if_index,
184 static_mac=self.static_mac,
185 filter_mac=self.filter_mac,
186 bvi_mac=self.bvi_mac)
187 self._test.registry.register(self, self._test.logger)
189 def remove_vpp_config(self):
190 self._test.vapi.l2fib_add_del(
193 self.itf.sw_if_index,
196 def query_vpp_config(self):
197 return find_l2_fib_entry(self._test,
200 self.itf.sw_if_index)
203 return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)
206 class VppL2Vtr(VppObject):
208 def __init__(self, test, itf, op):
213 def add_vpp_config(self):
214 self.itf.set_vtr(self.op)
215 self._test.registry.register(self, self._test.logger)
217 def remove_vpp_config(self):
218 self.itf.set_vtr(L2_VTR_OP.L2_DISABLED)
220 def query_vpp_config(self):
221 ds = self._test.vapi.sw_interface_dump()
222 d = self.itf.get_interface_config_from_dump(ds)
225 return (d.vtr_op == self.op)
229 return "L2-vtr-%s-%d" % (str(self.itf), self.op)