Capture VPP stats for Long and Short tests
[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 resources.libraries.python.VatExecutor import VatTerminal
17 from resources.libraries.python.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: dict
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         with VatTerminal(node) as vat:
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
46     @staticmethod
47     def add_fib_table(node, network, prefix_len, fib_id, place):
48         """Create new FIB table according to ID.
49
50         :param node: Node to add FIB on.
51         :param network: IP address to add to the FIB table.
52         :param prefix_len: IP address prefix length.
53         :param fib_id: FIB table ID.
54         :param place: Possible variants are local, drop.
55         :type node: dict
56         :type network: str
57         :type prefix_len: int
58         :type fib_id: int
59         :type place: str
60         """
61         with VatTerminal(node) as vat:
62             vat.vat_terminal_exec_cmd_from_template('add_fib_table.vat',
63                                                     network=network,
64                                                     prefix_length=prefix_len,
65                                                     fib_number=fib_id,
66                                                     where=place)