Example #1
0
 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)
Example #2
0
def draw_backup():
    """ Select a device/interface and demonstrate."""
    print(plain(doc(interface_configuration)))
    foundInterface = False

    G = nx.Graph()

    for device_name in sorted(inventory_connected()):
        G.add_node(device_name)
        print("%s:" % device_name)
        mgmt_name = management_interface(device_name)
        for interface_name in sorted(interface_names(device_name)):
            # Choose interface on 'data plane' not 'control plane'.
            if interface_name == mgmt_name:
                continue
            else:
                foundInterface = True
                demonstrate(device_name, interface_name)
                interface = interface_configuration(device_name, interface_name)
                address = interface.address
                netmask = interface.netmask
                to_node = match(device_name, to_ip_network(address, netmask))
                print("to_node:%s" % to_node)
                if to_node:
                    G.add_edge(device_name, to_node)
        if not foundInterface:
            print("There are no suitable network interfaces for this device.")

    print(G.nodes())
    print(G.edges())
    # nx.draw(G)
    nx.draw_networkx(G, with_labels=True)
    plt.show()
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
Example #4
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
def match(device_name, interface_network):
    """ Discover matching interface on a different device."""
    for other_device in inventory_mounted():
        if other_device == device_name:
            continue
        for interface_name in interface_names(other_device):
            interface_config = interface_configuration_tuple(other_device, interface_name)
            if interface_config.address is None:
                # Skip network interface with unassigned IP address.             
                continue
            other_network = to_ip_network(interface_config.address, interface_config.netmask)
            if other_network == interface_network:
                print('Match %s/%s/%s to %s/%s' % (device_name, interface_config.address, interface_config.netmask, \
                                                   other_device, interface_network))
                return interface_config.address
    return None
def match(device_name, interface_network):
    """ Discover matching interface on a different device."""
    for other_device in inventory_mounted():
        if other_device == device_name:
            continue
        for interface_name in interface_names(other_device):
            interface_config = interface_configuration_tuple(other_device, interface_name)
            if interface_config.address is None:
                # Skip network interface with unassigned IP address.             
                continue
            other_network = to_ip_network(interface_config.address, interface_config.netmask)
            if other_network == interface_network:
                print('Match %s/%s/%s to %s/%s' % (device_name, interface_config.address, interface_config.netmask, \
                                                   other_device, interface_network))
                return interface_config.address
    return None
def sample_destination(device_name):
    """ Determine a suitable destination for a static route from the specified network device. """
    # Implementation: use 'next subnet' of any data interface on the specified device.
    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
        interface_network = to_ip_network(config.address, config.netmask)
        destination_network = next_subnet(interface_network)
        return destination_network
    return None
def sample_destination(device_name):
    """ Determine a suitable destination for a static route from the specified network device. """
    # Implementation: use 'next subnet' of any data interface on the specified device.
    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
        interface_network = to_ip_network(config.address, config.netmask)
        destination_network = next_subnet(interface_network)
        return destination_network
    return None
Example #9
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 next_subnet(network):
    """ Determine the next subnet, relative to the specified network. """
    return to_ip_network(network.network_address + 256, 24)
def next_subnet(network):
    """ Determine the next subnet, relative to the specified network. """
    return to_ip_network(network.network_address + 256, 24)
Example #12
0
def main():
    device_list = settings.config['network_device']
    connected_list = topology.connected_nodes()

    if len(connected_list) != len(device_list):
        print('not all devices are connected!')
        return

    device_1 = 'iosxrv-1'
    device_2 = 'iosxrv-2'
    device_3 = 'iosxrv-3'
    device_4 = 'iosxrv-4'
    device_5 = 'iosxrv-5'
    device_6 = 'iosxrv-6'
    device_7 = 'iosxrv-7'
    device_8 = 'iosxrv-8'
    interface_0 = 'GigabitEthernet0/0/0/0'
    interface_1 = 'GigabitEthernet0/0/0/1'
    interface_2 = 'GigabitEthernet0/0/0/2'
    interface_3 = 'GigabitEthernet0/0/0/3'
    interface_4 = 'GigabitEthernet0/0/0/4'
    interface_5 = 'GigabitEthernet0/0/0/5'
    interface_6 = 'GigabitEthernet0/0/0/6'

    #add static route for flow 1
    destination_network = to_ip_network('100.0.0.0', '24')
    #device_1
    next_hop_address = '10.0.12.2'
    discription = 'for flow 1: to device_2'
    add_static_route(device_1, destination_network, next_hop_address,
                     discription, 0)
    #device_2
    next_hop_address = '198.18.1.34'
    discription = 'for flow 1: to device_5'
    add_static_route(device_2, destination_network, next_hop_address,
                     discription, 0)
    #device_8
    next_hop_address = '10.0.28.2'
    discription = 'for flow 1: to device_2'
    add_static_route(device_8, destination_network, next_hop_address,
                     discription, 0)
    #display
    print('add route for flow 1 (to 100.0.0.0/24): ', device_8, ' -> ',
          device_2)

    #add static route for flow 2
    destination_network = to_ip_network('200.0.0.0', '24')
    #device_1
    next_hop_address = '10.0.12.2'
    discription = 'for flow 2: to device_2'
    add_static_route(device_1, destination_network, next_hop_address,
                     discription, 0)
    #device_2
    next_hop_address = '198.18.1.34'
    discription = 'for flow 2: to device_5'
    add_static_route(device_2, destination_network, next_hop_address,
                     discription, 0)
    #device_8
    next_hop_address = '10.0.18.1'
    discription = 'for flow 2: to device_1'
    add_static_route(device_8, destination_network, next_hop_address,
                     discription, 0)
    #display
    print('add route for flow 2 (to 200.0.0.0/24): ', device_8, ' -> ',
          device_1, ' -> ', device_2)

    #add static route for flow 3
    destination_network = to_ip_network('50.0.0.0', '24')
    next_hop_address = '198.18.1.32'
    discription = 'for flow 3: to device_3'
    add_static_route(device_8, destination_network, next_hop_address,
                     discription, 0)
    #display
    print('add route for flow 3 (to 50.0.0.0/24): ', device_8,
          ' -> black_hole')

    #display static route
    print('\n')
    routes = static_route_list(device_8)
    print('static route table', device_8)
    print_table(routes)
Example #13
0
 def delete(self):
     device_name = self.devicename.get()
     destination_network = self.ipset.get()
     netmask = self.netmask.get()
     dest = to_ip_network(destination_network, netmask)
     static_route_delete(device_name, dest)
Example #14
0
def main():
    #device_list=settings.config['network_device']
    device_list = settings.config['network_device']
    connected_list = topology.connected_nodes()

    if len(connected_list) != len(device_list):
        print('not all devices are connected!')
        return

    device_1 = 'iosxrv-1'
    device_2 = 'iosxrv-2'
    device_3 = 'iosxrv-3'
    device_4 = 'iosxrv-4'
    device_5 = 'iosxrv-5'
    device_6 = 'iosxrv-6'
    device_7 = 'iosxrv-7'
    device_8 = 'iosxrv-8'
    interface_0 = 'GigabitEthernet0/0/0/0'
    interface_1 = 'GigabitEthernet0/0/0/1'
    interface_2 = 'GigabitEthernet0/0/0/2'
    interface_3 = 'GigabitEthernet0/0/0/3'
    interface_4 = 'GigabitEthernet0/0/0/4'
    interface_5 = 'GigabitEthernet0/0/0/5'
    interface_6 = 'GigabitEthernet0/0/0/6'

    #change path for flow 1
    destination_network = to_ip_network('100.0.0.0', '24')
    prior_next_hop = '10.0.28.2'
    second_next_hop = '10.0.18.1'
    if (interface_configuration_tuple(device_2, interface_2).shutdown
            == False) & (interface_configuration_tuple(
                device_8, interface_2).shutdown == False):
        link_status = 'up'
    else:
        link_status = 'down'
    #loop
    #for i in range(100):
    while True:
        #check the link
        if (interface_configuration_tuple(device_2, interface_2).shutdown
                == False) & (interface_configuration_tuple(
                    device_8, interface_2).shutdown == False):
            new_status = 'up'
            #print('link: device_2 <-> device_8 is OK')
        else:
            new_status = 'down'
            #print('link: device_2 <-> device_8 is fail')

        #link status unchange
        if link_status == new_status:
            print('device_2 <-> device_8 link status unchange')
            time.sleep(1)
            continue
        #link status up -> down
        elif (link_status == 'up') & (new_status == 'down'):
            delete_static_route(device_8, destination_network, 1)
            add_static_route(device_8, destination_network, second_next_hop, 1)
            print(
                'device_2 <-> device_8 link status from up to down: delete prior_route, add second_route, at last for 10s'
            )
            link_status = new_status
            time.sleep(10)
        #link status down -> up
        elif (link_status == 'down') & (new_status == 'up'):
            delete_static_route(device_8, destination_network, 1)
            add_static_route(device_8, destination_network, prior_next_hop, 1)
            print(
                'device_2 <-> device_8 link status from down to up: delete second_route, add prior_route'
            )
            link_status = new_status
            time.sleep(3)
def main():   
    device_list=settings.config['network_device']
    connected_list = topology.connected_nodes()
    
    if len(connected_list) != len(device_list):
        print('not all devices are connected!')
        return
    
    device_1 = 'iosxrv-1'
    device_2 = 'iosxrv-2'
    device_3 = 'iosxrv-3'
    device_4 = 'iosxrv-4'
    device_5 = 'iosxrv-5'
    device_6 = 'iosxrv-6'
    device_7 = 'iosxrv-7'
    device_8 = 'iosxrv-8'
    interface_0 = 'GigabitEthernet0/0/0/0'
    interface_1 = 'GigabitEthernet0/0/0/1'
    interface_2 = 'GigabitEthernet0/0/0/2'
    interface_3 = 'GigabitEthernet0/0/0/3'
    interface_4 = 'GigabitEthernet0/0/0/4'
    interface_5 = 'GigabitEthernet0/0/0/5'
    interface_6 = 'GigabitEthernet0/0/0/6'



    #add static route for flow 1
    destination_network = to_ip_network('100.0.0.0', '24')
    #device_1
    next_hop_address = '10.0.12.2'
    add_static_route(device_1, destination_network, next_hop_address, 0)
    #device_2
    next_hop_address = '198.18.1.34'
    add_static_route(device_2, destination_network, next_hop_address, 0)
    #device_8
    next_hop_address = '10.0.28.2'
    add_static_route(device_8, destination_network, next_hop_address, 0)
    #display
    print('add route for flow 1 (to 100.0.0.0/24): ', device_8, ' -> ', device_2)

    #add static route for flow 2
    destination_network = to_ip_network('200.0.0.0', '24')
    #device_1
    next_hop_address = '10.0.12.2'
    add_static_route(device_1, destination_network, next_hop_address, 0)
    #device_2
    next_hop_address = '198.18.1.34'
    add_static_route(device_2, destination_network, next_hop_address, 0)
    #device_8
    next_hop_address = '10.0.18.1'
    add_static_route(device_8, destination_network, next_hop_address, 0)
    #display
    print('add route for flow 2 (to 200.0.0.0/24): ', device_8, ' -> ', device_1, ' -> ', device_2)
    
    #add static route for flow 3
    destination_network = to_ip_network('50.0.0.0', '24')
    next_hop_address = '198.18.1.32'
    add_static_route(device_8, destination_network, next_hop_address, 0)
    #display
    print('add route for flow 3 (to 50.0.0.0/24): ', device_8, ' -> black_hole')

    
    #display static route
    print('\n')
    routes = static_route_list(device_8)
    print('static route table', device_8)
    print_table(routes)
def main():
    #device_list=settings.config['network_device']
    device_list = settings.config['network_device']
    connected_list = topology.connected_nodes()
    
    if len(connected_list) != len(device_list):
        print('not all devices are connected!')
        return
    
    device_1 = 'iosxrv-1'
    device_2 = 'iosxrv-2'
    device_3 = 'iosxrv-3'
    device_4 = 'iosxrv-4'
    device_5 = 'iosxrv-5'
    device_6 = 'iosxrv-6'
    device_7 = 'iosxrv-7'
    device_8 = 'iosxrv-8'
    interface_0 = 'GigabitEthernet0/0/0/0'
    interface_1 = 'GigabitEthernet0/0/0/1'
    interface_2 = 'GigabitEthernet0/0/0/2'
    interface_3 = 'GigabitEthernet0/0/0/3'
    interface_4 = 'GigabitEthernet0/0/0/4'
    interface_5 = 'GigabitEthernet0/0/0/5'
    interface_6 = 'GigabitEthernet0/0/0/6'
    
    
    #change path for flow 1
    destination_network = to_ip_network('100.0.0.0', '24')
    prior_next_hop = '10.0.28.2'
    second_next_hop = '10.0.18.1'
    if (interface_configuration_tuple(device_2, interface_2).shutdown == False) & (interface_configuration_tuple(device_8, interface_2).shutdown == False):
        link_status = 'up'
    else:
        link_status = 'down'
    #loop
    #for i in range(100):
    while True:
        #check the link
        if (interface_configuration_tuple(device_2, interface_2).shutdown == False) & (interface_configuration_tuple(device_8, interface_2).shutdown == False):
            new_status = 'up'
            #print('link: device_2 <-> device_8 is OK')
        else:
            new_status = 'down'
            #print('link: device_2 <-> device_8 is fail')
            
        #link status unchange
        if link_status == new_status:
            print('device_2 <-> device_8 link status unchange')
            time.sleep(1)
            continue
        #link status up -> down
        elif (link_status == 'up') & (new_status == 'down'): 
            delete_static_route(device_8, destination_network, 1)
            add_static_route(device_8, destination_network, second_next_hop, 1)
            print('device_2 <-> device_8 link status from up to down: delete prior_route, add second_route, at last for 10s')
            link_status = new_status
            time.sleep(10)
        #link status down -> up
        elif (link_status == 'down') & (new_status == 'up'): 
            delete_static_route(device_8, destination_network, 1)
            add_static_route(device_8, destination_network, prior_next_hop, 1)
            print('device_2 <-> device_8 link status from down to up: delete second_route, add prior_route')
            link_status = new_status
            time.sleep(3)