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
27 def find_bridge_domain(test, bd_id):
28 bds = test.vapi.bridge_domain_dump(bd_id)
32 def find_bridge_domain_port(test, bd_id, sw_if_index):
33 bds = test.vapi.bridge_domain_dump(bd_id)
35 for p in bd.sw_if_details:
36 if p.sw_if_index == sw_if_index:
41 def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
42 vmac = MACAddress(mac)
43 vip = VppIpAddress(ip)
50 arps = test.vapi.bd_ip_mac_dump(bd_id)
52 # do IP addr comparison too once .api is fixed...
53 if vmac.packed == arp.mac_address and \
54 vip.bytes == arp.ip_address[:n]:
59 def find_l2_fib_entry(test, bd_id, mac, sw_if_index):
60 vmac = MACAddress(mac)
61 lfs = test.vapi.l2_fib_table_dump(bd_id)
63 if vmac.packed == lf.mac and sw_if_index == lf.sw_if_index:
68 class VppBridgeDomain(VppObject):
70 def __init__(self, test, bd_id,
71 flood=1, uu_flood=1, forward=1,
76 self.uu_flood = uu_flood
77 self.forward = forward
79 self.arp_term = arp_term
81 def add_vpp_config(self):
82 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id,
84 uu_flood=self.uu_flood,
87 arp_term=self.arp_term, is_add=1)
88 self._test.registry.register(self, self._test.logger)
90 def remove_vpp_config(self):
91 self._test.vapi.bridge_domain_add_del(bd_id=self.bd_id, is_add=0)
93 def query_vpp_config(self):
94 return find_bridge_domain(self._test, self.bd_id)
97 return "bridge-domain-%d" % (self.bd_id)
100 class VppBridgeDomainPort(VppObject):
102 def __init__(self, test, bd, itf,
103 port_type=L2_PORT_TYPE.NORMAL):
107 self.port_type = port_type
109 def add_vpp_config(self):
110 self._test.vapi.sw_interface_set_l2_bridge(
111 rx_sw_if_index=self.itf.sw_if_index, bd_id=self.bd.bd_id,
112 port_type=self.port_type, enable=1)
113 self._test.registry.register(self, self._test.logger)
115 def remove_vpp_config(self):
116 self._test.vapi.sw_interface_set_l2_bridge(
117 rx_sw_if_index=self.itf.sw_if_index, bd_id=self.bd.bd_id,
118 port_type=self.port_type, enable=0)
120 def query_vpp_config(self):
121 return find_bridge_domain_port(self._test,
123 self.itf.sw_if_index)
126 return "BD-Port-%s-%s" % (self.bd, self.itf)
129 class VppBridgeDomainArpEntry(VppObject):
131 def __init__(self, test, bd, mac, ip):
134 self.mac = MACAddress(mac)
135 self.ip = VppIpAddress(ip)
137 def add_vpp_config(self):
138 self._test.vapi.bd_ip_mac_add_del(bd_id=self.bd.bd_id, is_add=1,
141 self._test.registry.register(self, self._test.logger)
143 def remove_vpp_config(self):
144 self._test.vapi.bd_ip_mac_add_del(bd_id=self.bd.bd_id, is_add=0,
148 def query_vpp_config(self):
149 return find_bridge_domain_arp_entry(self._test,
155 return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip.address)
158 class VppL2FibEntry(VppObject):
160 def __init__(self, test, bd, mac, itf,
161 static_mac=0, filter_mac=0, bvi_mac=-1):
164 self.mac = MACAddress(mac)
166 self.static_mac = static_mac
167 self.filter_mac = filter_mac
169 self.bvi_mac = isinstance(self.itf, VppLoInterface)
171 self.bvi_mac = bvi_mac
173 def add_vpp_config(self):
174 self._test.vapi.l2fib_add_del(
177 self.itf.sw_if_index,
179 static_mac=self.static_mac,
180 filter_mac=self.filter_mac,
181 bvi_mac=self.bvi_mac)
182 self._test.registry.register(self, self._test.logger)
184 def remove_vpp_config(self):
185 self._test.vapi.l2fib_add_del(
188 self.itf.sw_if_index,
191 def query_vpp_config(self):
192 return find_l2_fib_entry(self._test,
195 self.itf.sw_if_index)
198 return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)
201 class VppL2Vtr(VppObject):
203 def __init__(self, test, itf, op):
208 def add_vpp_config(self):
209 self.itf.set_vtr(self.op)
210 self._test.registry.register(self, self._test.logger)
212 def remove_vpp_config(self):
213 self.itf.set_vtr(L2_VTR_OP.L2_DISABLED)
215 def query_vpp_config(self):
216 ds = self._test.vapi.sw_interface_dump()
217 d = self.itf.get_interface_config_from_dump(ds)
220 return (d.vtr_op == self.op)
224 return "L2-vtr-%s-%d" % (str(self.itf), self.op)