CSIT-523 HC Test: routing
[csit.git] / resources / test_data / honeycomb / routing.py
1 # Copyright (c) 2017 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 """Test data for Honeycomb routing test."""
15
16 from resources.libraries.python.topology import Topology
17
18
19 def get_variables(node, ip_version, out_interface):
20
21     out_interface = Topology.convert_interface_reference(
22         node, out_interface, "name")
23
24     ip_version = ip_version.lower()
25     variables = {}
26
27     # base network settings
28     ipv4_base = {
29         "dut_to_tg_if1_ip": "16.0.0.1",
30         "dut_to_tg_if2_ip": "16.0.1.1",
31         "src_ip": "16.0.0.2",
32         "dst_ip": "16.0.2.1",
33         "dst_net": "16.0.2.0",
34         "prefix_len": 24,
35         "next_hop": "16.0.1.2",
36         "next_hop1": "16.0.1.3",
37         "next_hop2": "16.0.1.4",
38         "next_hop_mac1": "00:11:22:33:44:55",
39         "next_hop_mac2": "11:22:33:44:55:66"
40     }
41
42     ipv6_base = {
43         "dut_to_tg_if1_ip": "10::1",
44         "dut_to_tg_if2_ip": "11::1",
45         "src_ip": "10::2",
46         "dst_ip": "12::1",
47         "dst_net": "12::0",
48         "dst_net_full": "12:0:0:0:0:0:0:0",
49         "prefix_len": 64,
50         "next_hop": "11::2",
51         "next_hop1": "11::3",
52         "next_hop2": "11::4",
53         "next_hop_mac1": "00:11:22:33:44:55",
54         "next_hop_mac2": "11:22:33:44:55:66"
55     }
56
57     if ip_version == "ipv4":
58         variables.update(ipv4_base)
59     elif ip_version == "ipv6":
60         variables.update(ipv6_base)
61     else:
62         raise ValueError("IP version must be either IPv4 or IPv6.")
63
64     # route configuration used in tests
65     tables_cfg = {
66         "table1": {
67             "id": 1,
68             "description": "single hop ipv4",
69             "destination-prefix":
70                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
71             "next-hop": ipv4_base["next_hop"],
72             "outgoing-interface": out_interface,
73             "vpp-ipv4-route": {}
74         },
75         "table2": {
76             "id": 1,
77             "description": "multi hop ipv4",
78             "destination-prefix":
79                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
80             "next-hop-list": {
81                 "next-hop": [
82                     {
83                         "id": 1,
84                         "address": ipv4_base["next_hop1"],
85                         "outgoing-interface": out_interface,
86                         "weight": "1"
87                     },
88                     {
89                         "id": 2,
90                         "address": ipv4_base["next_hop2"],
91                         "outgoing-interface": out_interface,
92                         "weight": "1"
93                     }
94                 ]
95             }
96         },
97         "table3": {
98             "id": 1,
99             "description": "blackhole ipv4",
100             "destination-prefix":
101                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
102             "special-next-hop": "receive"
103         },
104         "table4": {
105             "id": 1,
106             "description": "single hop ipv6",
107             "destination-prefix":
108                 "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
109             "next-hop": ipv6_base["next_hop"],
110             "outgoing-interface": out_interface,
111             "vpp-ipv6-route": {}
112         },
113         "table5": {
114             "id": 1,
115             "description": "multi hop ipv6",
116             "destination-prefix":
117                 "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
118             "next-hop-list": {
119                 "next-hop": [
120                     {
121                         "id": 1,
122                         "address": ipv6_base["next_hop1"],
123                         "outgoing-interface": out_interface,
124                         "weight": "1"
125                     },
126                     {
127                         "id": 2,
128                         "address": ipv6_base["next_hop2"],
129                         "outgoing-interface": out_interface,
130                         "weight": "1"
131                     }
132                 ]
133             }
134         },
135         "table6": {
136             "id": 1,
137             "description": "blackhole ipv6",
138             "destination-prefix":
139                 "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
140             "special-next-hop": "blackhole"
141         }
142     }
143
144     # expected route operational data
145     tables_oper = {
146         "table1_oper": {
147             "destination-prefix":
148                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
149             "next-hop": ipv4_base["next_hop"],
150             "outgoing-interface": out_interface,
151             "vpp-ipv4-route-state": {}
152         },
153         "table2_oper": {
154             "destination-prefix":
155                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
156             "next-hop-list": {
157                 "next-hop": [
158                     {
159                         "address": ipv4_base["next_hop1"],
160                         "outgoing-interface": out_interface,
161                         "weight": 1
162                     },
163                     {
164                         "address": ipv4_base["next_hop2"],
165                         "outgoing-interface": out_interface,
166                         "weight": 1
167                     }
168                 ]
169             },
170             'vpp-ipv4-route-state': {}
171         },
172         "table3_oper": {
173             "destination-prefix":
174                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
175             "special-next-hop": "receive",
176             "vpp-ipv4-route-state": {}
177         },
178         "table4_oper": {
179             "destination-prefix":
180                 "{0}/{1}".format(ipv6_base["dst_net_full"],
181                                  ipv6_base["prefix_len"]),
182             "next-hop": ipv6_base["next_hop"],
183             "outgoing-interface": out_interface,
184             "vpp-ipv6-route-state": {}
185         },
186         "table5_oper": {
187             "destination-prefix":
188                 "{0}/{1}".format(ipv6_base["dst_net_full"],
189                                  ipv6_base["prefix_len"]),
190             "next-hop-list": {
191                 "next-hop": [
192                     {
193                         "address": ipv6_base["next_hop1"],
194                         "outgoing-interface": out_interface,
195                         "weight": 1
196                     },
197                     {
198                         "address": ipv6_base["next_hop2"],
199                         "outgoing-interface": out_interface,
200                         "weight": 1
201                     }
202                 ]
203             },
204             "vpp-ipv6-route-state": {}
205         },
206         "table6_oper": {
207             "destination-prefix":
208                 "{0}/{1}".format(ipv6_base["dst_net_full"],
209                                  ipv6_base["prefix_len"]),
210             "special-next-hop": "blackhole",
211             'vpp-ipv6-route-state': {}
212         }
213     }
214
215     for item in tables_oper.values():
216         if "next-hop-list" in item.keys():
217             item["next-hop-list"]["next-hop"].sort()
218
219     variables.update(tables_cfg)
220     variables.update(tables_oper)
221     return variables