6 from vpp_object import *
7 from util import mactobinary
8 from vpp_ip import VppIpAddress
9 from vpp_mac import VppMacAddress
10 from vpp_lo_interface import VppLoInterface
28 def find_bridge_domain(test, bd_id):
29 bds = test.vapi.bridge_domain_dump(bd_id)
33 def find_bridge_domain_port(test, bd_id, sw_if_index):
34 bds = test.vapi.bridge_domain_dump(bd_id)
36 for p in bd.sw_if_details:
37 if p.sw_if_index == sw_if_index:
42 def find_bridge_domain_arp_entry(test, bd_id, mac, ip):
43 vmac = VppMacAddress(mac)
44 vip = VppIpAddress(ip)
51 arps = test.vapi.bd_ip_mac_dump(bd_id)
53 # do IP addr comparison too once .api is fixed...
54 if vmac.bytes == arp.mac_address and \
55 vip.bytes == arp.ip_address[:n]:
60 def find_l2_fib_entry(test, bd_id, mac, sw_if_index):
61 vmac = VppMacAddress(mac)
62 lfs = test.vapi.l2_fib_table_dump(bd_id)
64 if vmac.bytes == lf.mac and sw_if_index == lf.sw_if_index:
69 class VppBridgeDomain(VppObject):
71 def __init__(self, test, bd_id,
72 flood=1, uu_flood=1, forward=1,
77 self.uu_flood = uu_flood
78 self.forward = forward
80 self.arp_term = arp_term
82 def add_vpp_config(self):
83 self._test.vapi.bridge_domain_add_del(
87 uu_flood=self.uu_flood,
90 arp_term=self.arp_term)
91 self._test.registry.register(self, self._test.logger)
93 def remove_vpp_config(self):
94 self._test.vapi.bridge_domain_add_del(self.bd_id, is_add=0)
96 def query_vpp_config(self):
97 return find_bridge_domain(self._test, self.bd_id)
100 return self.object_id()
103 return "bridge-domain-%d" % (self.bd_id)
106 class VppBridgeDomainPort(VppObject):
108 def __init__(self, test, bd, itf,
109 port_type=L2_PORT_TYPE.NORMAL):
113 self.port_type = port_type
115 def add_vpp_config(self):
116 self._test.vapi.sw_interface_set_l2_bridge(
117 self.itf.sw_if_index,
119 port_type=self.port_type,
121 self._test.registry.register(self, self._test.logger)
123 def remove_vpp_config(self):
124 self._test.vapi.sw_interface_set_l2_bridge(
125 self.itf.sw_if_index,
127 port_type=self.port_type,
130 def query_vpp_config(self):
131 return find_bridge_domain_port(self._test,
133 self.itf.sw_if_index)
136 return self.object_id()
139 return "BD-Port-%s-%s" % (self.bd, self.itf)
142 class VppBridgeDomainArpEntry(VppObject):
144 def __init__(self, test, bd, mac, ip):
147 self.mac = VppMacAddress(mac)
148 self.ip = VppIpAddress(ip)
150 def add_vpp_config(self):
151 self._test.vapi.bd_ip_mac_add_del(
156 self._test.registry.register(self, self._test.logger)
158 def remove_vpp_config(self):
159 self._test.vapi.bd_ip_mac_add_del(
165 def query_vpp_config(self):
166 return find_bridge_domain_arp_entry(self._test,
172 return self.object_id()
175 return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip.address)
178 class VppL2FibEntry(VppObject):
180 def __init__(self, test, bd, mac, itf,
181 static_mac=0, filter_mac=0, bvi_mac=-1):
184 self.mac = VppMacAddress(mac)
186 self.static_mac = static_mac
187 self.filter_mac = filter_mac
189 self.bvi_mac = isinstance(self.itf, VppLoInterface)
191 self.bvi_mac = bvi_mac
193 def add_vpp_config(self):
194 self._test.vapi.l2fib_add_del(
197 self.itf.sw_if_index,
199 static_mac=self.static_mac,
200 filter_mac=self.filter_mac,
201 bvi_mac=self.bvi_mac)
202 self._test.registry.register(self, self._test.logger)
204 def remove_vpp_config(self):
205 self._test.vapi.l2fib_add_del(
208 self.itf.sw_if_index,
211 def query_vpp_config(self):
212 return find_l2_fib_entry(self._test,
215 self.itf.sw_if_index)
218 return self.object_id()
221 return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)