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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
14 """Robot framework variable file.
16 Create dictionary variable nodes_ipv6_addr with IPv6 addresses from available
20 from resources.libraries.python.IPv6Setup import IPv6Networks
21 from resources.libraries.python.topology import Topology
23 # Default list of available IPv6 networks
24 IPV6_NETWORKS = ['3ffe:{0:04x}::/64'.format(i) for i in range(1, 100)]
27 def get_variables(nodes, networks=IPV6_NETWORKS):
28 """Special robot framework method that returns dictionary nodes_ipv6_addr,
29 mapping of node and interface name to IPv6 address.
31 :param nodes: Nodes of the test topology.
32 :param networks: List of available IPv6 networks.
37 Robot framework calls it automatically.
40 links = topo.get_links(nodes)
42 if len(links) > len(networks):
43 raise Exception('Not enough available IPv6 networks for topology.')
45 ip6_n = IPv6Networks(networks)
50 ip6_net = ip6_n.next_network()
51 net_hosts = ip6_net.hosts()
54 for node in nodes.values():
55 if_key = topo.get_interface_by_link_name(node, link)
56 if_name = topo.get_interface_name(node, if_key)
57 if if_name is not None:
58 port = {'addr': str(next(net_hosts)),
62 port_id = 'port{0}'.format(port_idx)
63 ports.update({port_id: port})
64 nets.update({link: {'net_addr': str(ip6_net.network_address),
65 'prefix': ip6_net.prefixlen,
68 return {'DICT__nodes_ipv6_addr': nets}