Tolerate failures when setting MTU
[csit.git] / resources / test_data / softwire / map_e_domains.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.l
13
14 """Variables for MAP-e feature tests."""
15
16 from resources.libraries.python.Map import Map
17 from random import sample, randint
18 from itertools import product
19
20
21 def get_variables(count):
22     """Generate variables with random generated MAP-E configuration sets and
23     IP test sets.
24
25     domain_set = [IPv4_prefix, IPv6_prefix, IPv6_source, 16, 0, 0]
26     ip_set = [IPv4_dst_address, IPv6_dst_address, dst_port, IPv6_src_address]
27
28     :param count: Generate "count" map domain configuration parameters.
29     :type count: int
30     :return: Variable dictionary with domain_sets and ip_sets.
31     :rtype: dict
32     """
33     domain_sets = []
34     ip_sets = []
35
36     ip_product = [x for x in list(product(xrange(2, 224), xrange(0, 256)))
37                   if x[0] != 127]
38
39     for n1, n2 in sample(ip_product, count):
40         v4_pfx = '{}.{}.0.0/16'.format(n1, n2)
41         v6_pfx = '2001:{:x}{:x}::/48'.format(n1, n2)
42         ipv6_br = '2001:ffff::1'
43         domain_set = [v4_pfx,
44                       v6_pfx,
45                       ipv6_br, 16, 0, 0]
46         port = randint(1025, 65500)
47         ipv4_addr = '{}.{}.20.30'.format(n1, n2)
48         ipv6_addr = Map.compute_ipv6_map_destination_address(
49             v4_pfx, v6_pfx, 16, 0, 0, ipv4_addr, port)
50         domain_sets.append(domain_set)
51         ip_sets.append([ipv4_addr, ipv6_addr, port, ipv6_br])
52
53     variables = {
54         "domain_sets": domain_sets,
55         "ip_sets": ip_sets
56     }
57     return variables