1 # Copyright (c) 2016 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """L2 bridge domain utilities Library."""
16 from robot.api.deco import keyword
17 from resources.libraries.python.topology import Topology
18 from resources.libraries.python.VatExecutor import VatExecutor
22 """Utilities for l2 bridge domain configuration"""
28 def vpp_add_l2fib_entry(node, mac, interface, bd_id):
29 """ Creates a static L2FIB entry on a vpp node.
31 :param node: Node to add L2FIB entry on.
32 :param mac: Destination mac address.
33 :param interface: Interface name.
34 :param bd_id: Bridge domain id.
40 sw_if_index = Topology.get_interface_sw_index(node, interface)
41 VatExecutor.cmd_from_template(node, "add_l2_fib_entry.vat",
43 interface=sw_if_index)
46 @keyword('Setup l2 bridge domain with id "${bd_id}" flooding "${flood}" '
47 'forwarding "${forward}" learning "${learn}" and arp termination '
48 '"${arp_term}" on vpp node "${node}"')
49 def setup_vpp_l2_bridge_domain(node, bd_id, flood, forward, learn,
51 """Create a l2 bridge domain on the chosen vpp node
53 Executes "bridge_domain_add_del bd_id {bd_id} flood {flood} uu-flood 1
54 forward {forward} learn {learn} arp-term {arp_term}" VAT command on
56 For the moment acts as a placeholder
57 :param node: node where we wish to crate the l2 bridge domain
58 :param bd_id: bridge domain id
59 :param flood: enable flooding
60 :param forward: enable forwarding
61 :param learn: enable mac address learning to fib
62 :param arp_term: enable arp_termination
73 @keyword('Add interface "${interface}" to l2 bridge domain with index '
74 '"${bd_id}" and shg "${shg}" on vpp node "${node}"')
75 def add_interface_to_l2_bd(self, node, interface, bd_id, shg):
76 """Adds interface to l2 bridge domain.
78 Executes the "sw_interface_set_l2_bridge {interface1} bd_id {bd_id}
79 shg {shg} enable" VAT command on the given node.
80 For the moment acts as a placeholder
81 :param node: node where we want to execute the command that does this.
94 @keyword('Create dict used in bridge domain template file for node '
95 '"${node}" with links "${link_names}" and bd_id "${bd_id}"')
96 def create_bridge_domain_vat_dict(node, link_names, bd_id):
97 """Creates dictionary that can be used in l2 bridge domain template.
99 :param node: node data dictionary
100 :param link_names: list of names of links the bridge domain should be
102 :param bd_id: bridge domain index number
104 :type link_names: list
105 :return: dictionary used to generate l2 bridge domain VAT configuration
107 The resulting dictionary looks like this:
108 'interface1': interface name of first interface
109 'interface2': interface name of second interface
110 'bd_id': bridge domian index
112 bd_dict = Topology().get_interfaces_by_link_names(node, link_names)
113 bd_dict['bd_id'] = bd_id
117 def vpp_add_l2_bridge_domain(node, bd_id, port_1, port_2, learn=True):
118 """Add L2 bridge domain with 2 interfaces to the VPP node.
120 :param node: Node to add L2BD on.
121 :param bd_id: Bridge domain ID.
122 :param port_1: First interface name added to L2BD.
123 :param port_2: Second interface name addded to L2BD.
124 :param learn: Enable/disable MAC learn.
127 :type interface1: str
128 :type interface2: str
131 sw_if_index1 = Topology.get_interface_sw_index(node, port_1)
132 sw_if_index2 = Topology.get_interface_sw_index(node, port_2)
133 VatExecutor.cmd_from_template(node,
134 'l2_bridge_domain.vat',
135 sw_if_id1=sw_if_index1,
136 sw_if_id2=sw_if_index2,