8581b1e87971c4c96a0d781378acad549a4d0d8b
[csit.git] / resources / libraries / python / L2Util.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """L2 bridge domain utilities Library."""
15
16 from robot.api.deco import keyword
17 from resources.libraries.python.topology import Topology
18 from resources.libraries.python.VatExecutor import VatExecutor
19
20
21 class L2Util(object):
22     """Utilities for l2 bridge domain configuration"""
23
24     def __init__(self):
25         pass
26
27     @staticmethod
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
32
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
37         :type node: dict
38         :type dst_mac: str
39         :type link: str
40         :type bd_id: str
41         """
42         topology = Topology()
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)
48
49     @staticmethod
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,
54                                    arp_term):
55         """Create a l2 bridge domain on the chosen vpp node
56
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
59         the node.
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
67         :type node: str
68         :type bd_id: str
69         :type flood: bool
70         :type forward: bool
71         :type learn: bool
72         :type arp_term:bool
73         :return:
74         """
75         pass
76
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.
81
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.
86         :param interface:
87         :param bd_id:
88         :param shg:
89         :type node: dict
90         :type interface: str
91         :type bd_id: str
92         :type shg: str
93         :return:
94         """
95         pass
96
97     @staticmethod
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.
102
103         :param node: node data dictionary
104         :param link_names: list of names of links the bridge domain should be
105         connecting
106         :param bd_id: bridge domain index number
107         :type node: dict
108         :type link_names: list
109         :return: dictionary used to generate l2 bridge domain VAT configuration
110         from template file
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
115         """
116         bd_dict = Topology().get_interfaces_by_link_names(node, link_names)
117         bd_dict['bd_id'] = bd_id
118         return bd_dict
119