def demonstrate(device_name):
    """
    Apply function 'static_route_create' to the specified device.
    
    Choose a destination that does not already exist. 
    Choose a next-hop on the same sub-network as an existing interface.
    If the next-hop is unknown then use any valid ip-address.
    """
    
    print('Select a destination network for which a static route does not exist.')
    destination_network_iterator = destination_network_generator()
    while True: 
        destination_network = next(destination_network_iterator)
        print('static_route_exists(%s, %s)' % (device_name, destination_network))
        exists = static_route_exists(device_name, destination_network)
        print(exists)
        print()
        if not exists:
            break
    
    print('Determine which interface is on the management plane (to avoid it).')     
    print('device_control(%s)' % device_name)
    device_mgmt = device_control(device_name)
    print_table(device_mgmt)
    print()

    print('Determine ip-address and network-mask of every interface.')     
    print('interface_configuration_tuple(%s)' % device_name)
    interface_config_list = interface_configuration_tuple(device_name)
    print_table(interface_config_list)
    print()
    
    for interface_config in interface_config_list:
        if interface_config.address is None:
            # Skip network interface with unassigned IP address.             
            continue
        if interface_config.address == device_mgmt.address:
            # Do not configure static routes on the 'management plane'.             
            continue
        if 'Loopback' in interface_config.name:
            # Do not configure static routes on the 'control plane'.             
            continue
        
        print('Determine next-hop for a network interface.')
        interface_network = interface_config.ip_network
        next_hop_address = match(device_name, interface_network)
        if next_hop_address is None:
            print('Next-hop for %s/%s %s/%s is outside the known topology.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask))
            next_hop_address = interface_network.network_address
            if next_hop_address == interface_config.ip_interface:
                next_hop_address += 1
            print('Assume that next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        else:
            print('Next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        print()

        print('static_route_create(%s, %s, %s)' % (device_name, destination_network, next_hop_address))
        static_route_create(device_name, destination_network, next_hop_address)
        return True
    return False
def demonstrate(device_name):
    ''' Apply function 'static_route_exists' to one or more static route destinations for the specified device.'''
    destination_network = static_route_fixture.sample_destination(device_name)
    print()
    print('static_route_exists(' + device_name, destination_network, sep=', ', end=')\n')
    print('\t', static_route_exists(device_name, destination_network))
    return True
def demonstrate(device_name):
    """
    Apply function 'static_route_create' to the specified device.
    
    Choose a destination that does not already exist. 
    Choose a next-hop on the same sub-network as an existing interface.
    If the next-hop is unknown then use any valid ip-address.
    """
    
    print('Select a destination network for which a static route does not exist.')
    destination_network_iterator = destination_network_generator()
    while True: 
        destination_network = next(destination_network_iterator)
        print('static_route_exists(%s, %s)' % (device_name, destination_network))
        exists = static_route_exists(device_name, destination_network)
        print(exists)
        print()
        if not exists:
            break
    
    print('Determine which interface is on the management plane (to avoid it).')     
    print('device_control(%s)' % device_name)
    device_mgmt = device_control(device_name)
    print_table(device_mgmt)
    print()

    print('Determine ip-address and network-mask of every interface.')     
    print('interface_configuration_tuple(%s)' % device_name)
    interface_config_list = interface_configuration_tuple(device_name)
    print_table(interface_config_list)
    print()
    
    for interface_config in interface_config_list:
        if interface_config.address is None:
            # Skip network interface with unassigned IP address.             
            continue
        if interface_config.address == device_mgmt.address:
            # Do not configure static routes on the 'management plane'.             
            continue
        if 'Loopback' in interface_config.name:
            # Do not configure static routes on the 'control plane'.             
            continue
        
        print('Determine next-hop for a network interface.')
        interface_network = interface_config.ip_network
        next_hop_address = match(device_name, interface_network)
        if next_hop_address is None:
            print('Next-hop for %s/%s %s/%s is outside the known topology.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask))
            next_hop_address = interface_network.network_address
            if next_hop_address == interface_config.ip_interface:
                next_hop_address += 1
            print('Assume that next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        else:
            print('Next-hop for %s/%s %s/%s is %s.' % (device_name, interface_config.name, interface_config.address, interface_config.netmask, next_hop_address))
        print()

        print('static_route_create(%s, %s, %s)' % (device_name, destination_network, next_hop_address))
        static_route_create(device_name, destination_network, next_hop_address)
        return True
    return False
Пример #4
0
def delete_static_route(device_name, destination_network, print_tag):
    #if static route exist, delete it first
    if static_route_exists(device_name, destination_network):
        static_route_delete(device_name, destination_network)
        if print_tag == 1:
            print('remove route to %s' % destination_network,
                  'in %s' % device_name)
def demonstrate(device_name):
    ''' Apply function 'static_route_exists' to one or more static route destinations for the specified device.'''
    destination_network = static_route_fixture.sample_destination(device_name)
    print()
    print('static_route_exists(' + device_name,
          destination_network,
          sep=', ',
          end=')\n')
    print('\t', static_route_exists(device_name, destination_network))
    return True
def add_static_route(device_name, destination_network, next_hop_address, print_tag):
    #if static route exist, delete it first
    if static_route_exists(device_name, destination_network):
        static_route_delete(device_name, destination_network)
        if print_tag == 1:
            print('remove route to %s' % destination_network, 'in %s' % device_name)
    #add the static route
    static_route_create(device_name, destination_network, next_hop_address)
    if print_tag == 1:
        print('add route to %s' % destination_network, ' next_hop: %s' % next_hop_address, 'in %s' % device_name)
def add_static_route(device_name, destination_network, next_hop_address,
                     print_tag):
    #if static route exist, delete it first
    if static_route_exists(device_name, destination_network):
        static_route_delete(device_name, destination_network)
        if print_tag == 1:
            print('remove route to %s' % destination_network,
                  'in %s' % device_name)
    #add the static route
    static_route_create(device_name, destination_network, next_hop_address)
    if print_tag == 1:
        print('add route to %s' % destination_network,
              ' next_hop: %s' % next_hop_address, 'in %s' % device_name)
def demonstrate(device_name):
    """ 
    Apply function 'static_route_exists' to the specified device for each destination in the list.
    """
    destination_network_iterator = destination_network_generator()
    while True: 
        destination_network = next(destination_network_iterator)
        print('static_route_exists(%s, %s)' % (device_name, destination_network))
        exists = static_route_exists(device_name, destination_network)
        print(exists)
        if not exists:
            return True
        else:
            print()
Пример #9
0
def demonstrate(device_name):
    """ 
    Apply function 'static_route_exists' to the specified device for each destination in the list.
    """
    destination_network_iterator = destination_network_generator()
    while True:
        destination_network = next(destination_network_iterator)
        print('static_route_exists(%s, %s)' %
              (device_name, destination_network))
        exists = static_route_exists(device_name, destination_network)
        print(exists)
        if not exists:
            return True
        else:
            print()
def new_destination(device_name, interface_network):
    """ Determine a static route destination that does not exist on the specified device. """
    destination_network = next_subnet(interface_network)
    while static_route_exists(device_name, destination_network):
        destination_network = next_subnet(destination_network)
    return destination_network
def new_destination(device_name, interface_network):
    """ Determine a static route destination that does not exist on the specified device. """
    destination_network=next_subnet(interface_network)
    while static_route_exists(device_name, destination_network):
        destination_network=next_subnet(destination_network)
    return destination_network
def delete_static_route(device_name, destination_network, print_tag):
    #if static route exist, delete it first
    if static_route_exists(device_name, destination_network):
        static_route_delete(device_name, destination_network)
        if print_tag == 1:
            print('remove route to %s' % destination_network, 'in %s' % device_name)