6 from vpp_object import *
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(
86 uu_flood=self.uu_flood,
89 arp_term=self.arp_term)
90 self._test.registry.register(self, self._test.logger)
92 def remove_vpp_config(self):
93 self._test.vapi.bridge_domain_add_del(self.bd_id, is_add=0)
95 def query_vpp_config(self):
96 return find_bridge_domain(self._test, self.bd_id)
99 return self.object_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 self.itf.sw_if_index,
118 port_type=self.port_type,
120 self._test.registry.register(self, self._test.logger)
122 def remove_vpp_config(self):
123 self._test.vapi.sw_interface_set_l2_bridge(
124 self.itf.sw_if_index,
126 port_type=self.port_type,
129 def query_vpp_config(self):
130 return find_bridge_domain_port(self._test,
132 self.itf.sw_if_index)
135 return self.object_id()
138 return "BD-Port-%s-%s" % (self.bd, self.itf)
141 class VppBridgeDomainArpEntry(VppObject):
143 def __init__(self, test, bd, mac, ip):
146 self.mac = MACAddress(mac)
147 self.ip = VppIpAddress(ip)
149 def add_vpp_config(self):
150 self._test.vapi.bd_ip_mac_add_del(
155 self._test.registry.register(self, self._test.logger)
157 def remove_vpp_config(self):
158 self._test.vapi.bd_ip_mac_add_del(
164 def query_vpp_config(self):
165 return find_bridge_domain_arp_entry(self._test,
171 return self.object_id()
174 return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip.address)
177 class VppL2FibEntry(VppObject):
179 def __init__(self, test, bd, mac, itf,
180 static_mac=0, filter_mac=0, bvi_mac=-1):
183 self.mac = MACAddress(mac)
185 self.static_mac = static_mac
186 self.filter_mac = filter_mac
188 self.bvi_mac = isinstance(self.itf, VppLoInterface)
190 self.bvi_mac = bvi_mac
192 def add_vpp_config(self):
193 self._test.vapi.l2fib_add_del(
196 self.itf.sw_if_index,
198 static_mac=self.static_mac,
199 filter_mac=self.filter_mac,
200 bvi_mac=self.bvi_mac)
201 self._test.registry.register(self, self._test.logger)
203 def remove_vpp_config(self):
204 self._test.vapi.l2fib_add_del(
207 self.itf.sw_if_index,
210 def query_vpp_config(self):
211 return find_l2_fib_entry(self._test,
214 self.itf.sw_if_index)
217 return self.object_id()
220 return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)