X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FIPv4Util.py;h=3b500ab1d95974b3129d40b9e56cdfde0abc5e80;hp=30e185c9ffe955e66d4ab69315a944f5d844832c;hb=1254d80a0b64985de2816eff5ef79e3e22cde972;hpb=da15035461569ea175aabbac1df735cd5598b0b3 diff --git a/resources/libraries/python/IPv4Util.py b/resources/libraries/python/IPv4Util.py index 30e185c9ff..3b500ab1d9 100644 --- a/resources/libraries/python/IPv4Util.py +++ b/resources/libraries/python/IPv4Util.py @@ -35,6 +35,26 @@ class IPv4Util(object): interface, ip_address)) get_node(node).arp_ping(ip_address, interface) + @staticmethod + @keyword('Node "${node}" interface "${port}" has IPv4 address "${address}"' + ' with prefix length "${prefix_length}"') + def set_interface_address(node, interface, address, length): + """See IPv4Node.set_ip for more information. + + :param node: Node where IP address should be set to. + :param interface: Interface name + :param address: IP address + :param length: prefix length + :type node: dict + :type interface: str + :type address: str + :type length: int + """ + log.debug('Node {} interface {} has IPv4 address {} with prefix ' + 'length {}'.format(Topology.get_node_hostname(node), + interface, address, length)) + get_node(node).set_ip(interface, address, int(length)) + @staticmethod @keyword('Node "${node}" routes to IPv4 network "${network}" with prefix ' 'length "${prefix_length}" using interface "${interface}" via ' @@ -56,46 +76,6 @@ class IPv4Util(object): get_node(node).set_route(network, int(prefix_length), gateway, interface) - @staticmethod - @keyword('After ping is sent in topology "${nodes_info}" from node ' - '"${src_node}" interface "${src_port}" "${src_ip}" with ' - 'destination IPv4 address "${dst_ip}" of node "${dst_node}" ' - 'interface "${dst_port}" a ping response arrives and TTL is ' - 'decreased by "${hops}"') - def send_ping(nodes_info, src_node, src_port, src_ip, dst_ip, dst_node, - dst_port, hops): - """Send IPv4 ping and wait for response. - - :param nodes_info: Dictionary containing information on all nodes - in topology. - :param src_node: Source node. - :param src_port: Source interface. - :param src_ip: Source ipv4 address. - :param dst_ip: Destination ipv4 address. - :param dst_node: Destination node. - :param dst_port: Destination interface. - :param hops: Number of hops between src_node and dst_node. - """ - log.debug('After ping is sent from node "{}" interface "{}" ' - 'with destination IPv4 address of node "{}" interface "{}" ' - 'a ping response arrives and TTL is decreased by "${}"'. - format(Topology.get_node_hostname(src_node), src_port, - Topology.get_node_hostname(dst_node), dst_port, hops)) - dst_mac = None - src_mac = Topology.get_interface_mac(src_node, src_port) - if dst_node['type'] == NodeType.TG: - dst_mac = Topology.get_interface_mac(src_node, src_port) - _, adj_int = Topology.\ - get_adjacent_node_and_interface(nodes_info, src_node, src_port) - first_hop_mac = adj_int['mac_address'] - args = '--src_if "{}" --src_mac "{}" --first_hop_mac "{}" ' \ - '--src_ip "{}" --dst_ip "{}" --hops "{}"'\ - .format(src_port, src_mac, first_hop_mac, src_ip, dst_ip, hops) - if dst_node['type'] == NodeType.TG: - args += ' --dst_if "{}" --dst_mac "{}"'.format(dst_port, dst_mac) - TrafficScriptExecutor.run_traffic_script_on_node( - "ipv4_ping_ttl_check.py", src_node, args) - @staticmethod @keyword('Get IPv4 address prefix of node "${node}" interface "${port}" ' 'from "${nodes_addr}"') @@ -142,3 +122,35 @@ class IPv4Util(object): :return: """ get_node(node).flush_ip_addresses(port) + + @staticmethod + def get_link_address(link, nodes_addr): + """Get link IPv4 address. + + :param link: Link name. + :param nodes_addr: Available nodes IPv4 adresses. + :type link: str + :type nodes_addr: dict + :return: Link IPv4 address. + :rtype: str + """ + net = nodes_addr.get(link) + if net is None: + raise ValueError('Link "{0}" not found'.format(link)) + return net.get('net_addr') + + @staticmethod + def get_link_prefix(link, nodes_addr): + """Get link IPv4 address prefix. + + :param link: Link name. + :param nodes_addr: Available nodes IPv4 adresses. + :type link: str + :type nodes_addr: dict + :return: Link IPv4 address prefix. + :rtype: int + """ + net = nodes_addr.get(link) + if net is None: + raise ValueError('Link "{0}" not found'.format(link)) + return net.get('prefix')