c28b2212a4d2a5ad63945703fef79e337eac1faa
[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::",
48         "prefix_len": 64,
49         "next_hop": "11::2",
50         "next_hop1": "11::3",
51         "next_hop2": "11::4",
52         "next_hop_mac1": "00:11:22:33:44:55",
53         "next_hop_mac2": "11:22:33:44:55:66"
54     }
55
56     if ip_version == "ipv4":
57         variables.update(ipv4_base)
58     elif ip_version == "ipv6":
59         variables.update(ipv6_base)
60     else:
61         raise ValueError("IP version must be either IPv4 or IPv6.")
62
63     # route configuration used in tests
64     tables_cfg = {
65         "table1": {
66             "id": 1,
67             "description": "single hop ipv4",
68             "destination-prefix":
69                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
70             "next-hop": ipv4_base["next_hop"],
71             "outgoing-interface": out_interface,
72             "vpp-ipv4-route": {}
73         },
74         "table2": {
75             "id": 1,
76             "description": "multi hop ipv4",
77             "destination-prefix":
78                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
79             "next-hop-list": {
80                 "next-hop": [
81                     {
82                         "id": 1,
83                         "address": ipv4_base["next_hop1"],
84                         "outgoing-interface": out_interface,
85                         "weight": "1"
86                     },
87                     {
88                         "id": 2,
89                         "address": ipv4_base["next_hop2"],
90                         "outgoing-interface": out_interface,
91                         "weight": "1"
92                     }
93                 ]
94             }
95         },
96         "table3": {
97             "id": 1,
98             "description": "blackhole ipv4",
99             "destination-prefix":
100                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
101             "special-next-hop": "receive"
102         },
103         "table4": {
104             "id": 1,
105             "description": "single hop ipv6",
106             "destination-prefix":
107                 "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
108             "next-hop": ipv6_base["next_hop"],
109             "outgoing-interface": out_interface,
110             "vpp-ipv6-route": {}
111         },
112         "table5": {
113             "id": 1,
114             "description": "multi hop ipv6",
115             "destination-prefix":
116                 "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
117             "next-hop-list": {
118                 "next-hop": [
119                     {
120                         "id": 1,
121                         "address": ipv6_base["next_hop1"],
122                         "outgoing-interface": out_interface,
123                         "weight": "1"
124                     },
125                     {
126                         "id": 2,
127                         "address": ipv6_base["next_hop2"],
128                         "outgoing-interface": out_interface,
129                         "weight": "1"
130                     }
131                 ]
132             }
133         },
134         "table6": {
135             "id": 1,
136             "description": "blackhole ipv6",
137             "destination-prefix":
138                 "{0}/{1}".format(ipv6_base["dst_net"], ipv6_base["prefix_len"]),
139             "special-next-hop": "blackhole"
140         }
141     }
142
143     # expected route operational data
144     tables_oper = {
145         "table1_oper": {
146             "destination-prefix":
147                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
148             "next-hop": ipv4_base["next_hop"],
149             "outgoing-interface": out_interface,
150             "vpp-ipv4-route-state": {}
151         },
152         "table2_oper": {
153             "destination-prefix":
154                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
155             "next-hop-list": {
156                 "next-hop": [
157                     {
158                         "address": ipv4_base["next_hop1"],
159                         "outgoing-interface": out_interface,
160                         "weight": 1
161                     },
162                     {
163                         "address": ipv4_base["next_hop2"],
164                         "outgoing-interface": out_interface,
165                         "weight": 1
166                     }
167                 ]
168             },
169             'vpp-ipv4-route-state': {}
170         },
171         "table3_oper": {
172             "destination-prefix":
173                 "{0}/{1}".format(ipv4_base["dst_net"], ipv4_base["prefix_len"]),
174             "special-next-hop": "receive",
175             "vpp-ipv4-route-state": {}
176         },
177         "table4_oper": {
178             "destination-prefix":
179                 "{0}/{1}".format(ipv6_base["dst_net"],
180                                  ipv6_base["prefix_len"]),
181             "next-hop": ipv6_base["next_hop"],
182             "outgoing-interface": out_interface,
183             "vpp-ipv6-route-state": {}
184         },
185         "table5_oper": {
186             "destination-prefix":
187                 "{0}/{1}".format(ipv6_base["dst_net"],
188                                  ipv6_base["prefix_len"]),
189             "next-hop-list": {
190                 "next-hop": [
191                     {
192                         "address": ipv6_base["next_hop1"],
193                         "outgoing-interface": out_interface,
194                         "weight": 1
195                     },
196                     {
197                         "address": ipv6_base["next_hop2"],
198                         "outgoing-interface": out_interface,
199                         "weight": 1
200                     }
201                 ]
202             },
203             "vpp-ipv6-route-state": {}
204         },
205         "table6_oper": {
206             "destination-prefix":
207                 "{0}/{1}".format(ipv6_base["dst_net"],
208                                  ipv6_base["prefix_len"]),
209             "special-next-hop": "blackhole",
210             'vpp-ipv6-route-state': {}
211         }
212     }
213
214     for item in tables_oper.values():
215         if "next-hop-list" in item.keys():
216             item["next-hop-list"]["next-hop"].sort()
217
218     variables.update(tables_cfg)
219     variables.update(tables_oper)
220     return variables