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 @keyword('Setup static L2FIB entry on node "${node}" for MAC "${dst_mac}"'
29 ' link "${link}" pair on bd_index "${bd_id}"')
30 def static_l2_fib_entry_via_links(node, dst_mac, link, bd_id):
31 """ Creates a static fib entry on a vpp node
33 :param node: node where we wish to add the static fib entry
34 :param dst_mac: destination mac address in the entry
35 :param link: link name of the node destination interface
36 :param bd_id: l2 bridge domain id
43 interface_name = topology.get_interface_by_link_name(node, link)
44 sw_if_index = topology.get_interface_sw_index(node, interface_name)
45 VatExecutor.cmd_from_template(node, "add_l2_fib_entry.vat",
46 mac=dst_mac, bd=bd_id,
47 interface=sw_if_index)
50 @keyword('Setup l2 bridge domain with id "${bd_id}" flooding "${flood}" '
51 'forwarding "${forward}" learning "${learn}" and arp termination '
52 '"${arp_term}" on vpp node "${node}"')
53 def setup_vpp_l2_bridge_domain(node, bd_id, flood, forward, learn,
55 """Create a l2 bridge domain on the chosen vpp node
57 Executes "bridge_domain_add_del bd_id {bd_id} flood {flood} uu-flood 1
58 forward {forward} learn {learn} arp-term {arp_term}" VAT command on
60 For the moment acts as a placeholder
61 :param node: node where we wish to crate the l2 bridge domain
62 :param bd_id: bridge domain id
63 :param flood: enable flooding
64 :param forward: enable forwarding
65 :param learn: enable mac address learning to fib
66 :param arp_term: enable arp_termination
77 @keyword('Add interface "${interface}" to l2 bridge domain with index '
78 '"${bd_id}" and shg "${shg}" on vpp node "${node}"')
79 def add_interface_to_l2_bd(self, node, interface, bd_id, shg):
80 """Adds interface to l2 bridge domain.
82 Executes the "sw_interface_set_l2_bridge {interface1} bd_id {bd_id}
83 shg {shg} enable" VAT command on the given node.
84 For the moment acts as a placeholder
85 :param node: node where we want to execute the command that does this.
98 @keyword('Create dict used in bridge domain template file for node '
99 '"${node}" with links "${link_names}" and bd_id "${bd_id}"')
100 def create_bridge_domain_vat_dict(node, link_names, bd_id):
101 """Creates dictionary that can be used in l2 bridge domain template.
103 :param node: node data dictionary
104 :param link_names: list of names of links the bridge domain should be
106 :param bd_id: bridge domain index number
108 :type link_names: list
109 :return: dictionary used to generate l2 bridge domain VAT configuration
111 The resulting dictionary looks like this:
112 'interface1': interface name of first interface
113 'interface2': interface name of second interface
114 'bd_id': bridge domian index
116 bd_dict = Topology().get_interfaces_by_link_names(node, link_names)
117 bd_dict['bd_id'] = bd_id