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_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 add(self):
     device_name = self.devicename.get()
     destination_network = self.ipset.get()
     netmask = self.netmask.get()
     dest = to_ip_network(destination_network, netmask)
     next_hop_address = self.nexthop.get()
     static_route_create(device_name, dest, next_hop_address)
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)
Beispiel #6
0
def demonstrate(device_name):
    ''' Apply function 'static_route_create' to the specified device for a new destination.'''
    mgmt_name = management_interface(device_name)
    interface_list = interface_names(device_name)
    for interface_name in interface_list:
        if interface_name == mgmt_name:
            # Do not configure static routes on the control plane.             
            continue
        config = interface_configuration_tuple(device_name, interface_name)
        if config.address is None:
            # Skip network interface with unassigned IP address.             
            continue
        print()
        interface_network = to_ip_network(config.address, config.netmask)
        next_hop_address = match(device_name, interface_network)
        if next_hop_address is None:
            print('No end-point for %s/%s/%s/%s' % (device_name, interface_name, config.address, config.netmask))
            continue
        destination_network = static_route_fixture.new_destination(device_name, interface_network)
        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 static_route_send_sub(edge,ip):
    '''
        Descripthon :
            This is the subroutine of the static_route_send function
    '''
    remote_ip = edge['remoteaddr']
    nodesrc = edge['localnode']
    destination_network=to_ip_network(ip,'255.255.255.255')
    #detination_network should be destination node's network
    rs = static_route_create(devid2devname(nodesrc), destination_network, remote_ip)
    if rs.status_code == 204 or rs.status_code == 409 :
        return rs
    else:
        print(_BUG_CHECK %'push static route is failed!')
        return None
Beispiel #8
0
def static_route_send_sub(edge, ip):
    '''
        Descripthon :
            This is the subroutine of the static_route_send function
    '''
    remote_ip = edge['remoteaddr']
    nodesrc = edge['localnode']
    destination_network = to_ip_network(ip, '255.255.255.255')
    #detination_network should be destination node's network
    rs = static_route_create(devid2devname(nodesrc), destination_network,
                             remote_ip)
    if rs.status_code == 204 or rs.status_code == 409:
        return rs
    else:
        print(_BUG_CHECK % 'push static route is failed!')
        return None