Last bulk update of CSIT.
[csit.git] / resources / libraries / python / Routing.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 """Routing utilities library."""
15
16 from VatExecutor import VatTerminal
17 from topology import Topology
18
19
20 class Routing(object):
21     """Routing utilities."""
22
23     @staticmethod
24     def vpp_route_add(node, network, prefix_len, gateway, interface):
25         """Add route to the VPP node.
26
27         :param node: Node to add route on.
28         :param network: Route destination network address.
29         :param prefix_len: Route destination network prefix length.
30         :param gateway: Route gateway address.
31         :param interface: Route interface.
32         :type node: str
33         :type network: str
34         :type prefix_len: int
35         :type gateway: str
36         :type interface: str
37         """
38         sw_if_index = Topology.get_interface_sw_index(node, interface)
39         vat = VatTerminal(node)
40         vat.vat_terminal_exec_cmd_from_template('add_route.vat',
41                                                 network=network,
42                                                 prefix_length=prefix_len,
43                                                 gateway=gateway,
44                                                 sw_if_index=sw_if_index)
45         vat.vat_terminal_close()