Пример #1
0
def update():

    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']

    if _local_ip or _remote_ips:
        # Delete all interfaces and flows
        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd('ovs-ofctl del-flows', br_tun,
                'table=0,in_port={vxlan_port}'.format(vxlan_port=vxlan_port))

        for remote_ip in remote_ips_:
            #inf = 'vxlan_' + remote_ip
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Adding a VXLAN tunnel: ' + inf)
            cmd('ovs-vsctl del-port', br_tun, inf)

        # Add those interfaces and flows again to change the local IP address
        for remote_ip in _remote_ips_:
            #inf = 'vxlan_' + remote_ip
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Deleting a VXLAN tunnel: ' + inf)
            cmdp('ovs-vsctl add-port', br_tun, inf, '-- set interface', inf,
                 'type=vxlan options:in_key=flow',
                 'options:local_ip=' + _local_ip_, 'options:out_key=flow',
                 'options:remote_ip=' + remote_ip)

        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd(
                'ovs-ofctl add-flow', br_tun, 'table=0,priority=1,in_port=' +
                vxlan_port + ',actions=resubmit(,2)')
Пример #2
0
def update():

    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']

    if _local_ip or _remote_ips:
        # Delete all interfaces and flows 
        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd('ovs-ofctl del-flows', br_tun, 'table=0,in_port={vxlan_port}'.format(vxlan_port=vxlan_port))
        
        for remote_ip in remote_ips_:
            #inf = 'vxlan_' + remote_ip
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Adding a VXLAN tunnel: ' + inf)
            cmd('ovs-vsctl del-port', br_tun, inf)
       
        # Add those interfaces and flows again to change the local IP address
        for remote_ip in _remote_ips_:
            #inf = 'vxlan_' + remote_ip
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Deleting a VXLAN tunnel: ' + inf)
            cmdp('ovs-vsctl add-port', br_tun, inf, '-- set interface', inf, 'type=vxlan options:in_key=flow', 'options:local_ip='+_local_ip_, 'options:out_key=flow', 'options:remote_ip='+remote_ip)

        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd('ovs-ofctl add-flow', br_tun, 'table=0,priority=1,in_port='+vxlan_port+',actions=resubmit(,2)')
Пример #3
0
def add():

    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']

    if not _local_ip_:
        raise ModelError('"_local_ip_" is mandatory')
    if _remote_ips:
        for remote_ip in _remote_ips:
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Adding a VXLAN tunnel: ' + inf)
            cmdp('ovs-vsctl add-port', br_tun, inf, '-- set interface', inf,
                 'type=vxlan options:in_key=flow',
                 'options:local_ip=' + _local_ip, 'options:out_key=flow',
                 'options:remote_ip=' + remote_ip)

        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd(
                'ovs-ofctl add-flow', br_tun, 'table=0,priority=1,in_port=' +
                vxlan_port + ',actions=resubmit(,2)')

    cmd('ip link set dev', br_tun, 'up')
    cmd('ip link set dev', br_int, 'up')
Пример #4
0
def delete():
    if _vni and _vid_:
        raise ModelError("vid still exists")
    __n__['logger'].info('Deleting vlan: ' + str(_vid))
    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']
    _flow_entries('delete', br_tun)
    _delete_vpls(br_int)
Пример #5
0
def delete():
    if _vni and _vid_:
        raise ModelError("vid still exists")
    __n__['logger'].info('Deleting vlan: ' + str(_vid))
    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']
    _flow_entries('delete', br_tun)
    _delete_vpls(br_int)
Пример #6
0
def add():
    if _vni_ and _vid_:
        __n__['logger'].info('Adding vlan: ' + str(_vid))
        nodes = ptn_nodes.get_nodes(_id)
        br_tun = nodes['ptn']
        br_int = nodes['l2sw']
        _add_vpls(br_int)
        _flow_entries('add', br_tun)
    else:
        raise ModelError("requires at least _vni and _vid")
Пример #7
0
def add():
    if _vni_ and _vid_:
        __n__['logger'].info('Adding vlan: ' + str(_vid))
        nodes = ptn_nodes.get_nodes(_id)
        br_tun = nodes['ptn']
        br_int = nodes['l2sw']
        _add_vpls(br_int)
        _flow_entries('add', br_tun)
    else:
        raise ModelError("requires at least _vni and _vid")
Пример #8
0
def _delete_vpls():

    cmd = cmdutil.check_cmd
    output_cmd = cmdutil.output_cmd

    svni = str(vni_)
    int_br = "int_br" + svni

    br_int = ptn_nodes.get_nodes(_id)[0]['l2sw']

    #>>> Deleting VLAN and a linux bridge
    if ip_:
        cmd('ip addr del dev', int_br, ip_)
    if _vid:
        cmd('ip link set dev', int_br, 'down')
        cmd('ovs-vsctl del-port', br_int, int_br)
Пример #9
0
def _delete_vpls():
	
    cmd = cmdutil.check_cmd
    output_cmd = cmdutil.output_cmd

    svni = str(vni_)
    int_br = "int_br"+svni

    br_int = ptn_nodes.get_nodes(_id)[0]['l2sw']
    
    #>>> Deleting VLAN and a linux bridge
    if ip_:
        cmd('ip addr del dev', int_br, ip_)
    if _vid:
        cmd('ip link set dev', int_br, 'down')
        cmd('ovs-vsctl del-port', br_int, int_br)
Пример #10
0
def add():

    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']

    if not _local_ip_:
        raise ModelError('"_local_ip_" is mandatory')
    if _remote_ips:
        for remote_ip in _remote_ips:
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Adding a VXLAN tunnel: ' + inf)
            cmdp('ovs-vsctl add-port', br_tun, inf, '-- set interface', inf, 'type=vxlan options:in_key=flow', 'options:local_ip='+_local_ip, 'options:out_key=flow', 'options:remote_ip='+remote_ip)

        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd('ovs-ofctl add-flow', br_tun, 'table=0,priority=1,in_port='+vxlan_port+',actions=resubmit(,2)')

    cmd('ip link set dev', br_tun, 'up')
    cmd('ip link set dev', br_int, 'up')
Пример #11
0
def delete():
    
    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']

    if _remote_ips:
        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd('ovs-ofctl del-flows', br_tun, 'table=0,in_port={vxlan_port}'.format(vxlan_port=vxlan_port))
        
        for remote_ip in _remote_ips:
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Deleting a VXLAN tunnel: ' + inf)
            cmd('ovs-vsctl del-port', br_tun, inf)
    
    if _local_ip:
        # All remote IPs must be deleted before deleting local IP
        if remote_ips_:
            if not (set(_remote_ips) == set(remote_ips_)):
                raise ModelError('"local_ip" cannot be deleted') 
Пример #12
0
def delete():

    nodes = ptn_nodes.get_nodes(_id)
    br_tun = nodes['ptn']
    br_int = nodes['l2sw']

    if _remote_ips:
        vxlan_ports = get_vxlan_ports()
        for vxlan_port in vxlan_ports:
            cmd('ovs-ofctl del-flows', br_tun,
                'table=0,in_port={vxlan_port}'.format(vxlan_port=vxlan_port))

        for remote_ip in _remote_ips:
            inf = ''.join([num.zfill(3) for num in remote_ip.split('.')])
            __n__['logger'].info('Deleting a VXLAN tunnel: ' + inf)
            cmd('ovs-vsctl del-port', br_tun, inf)

    if _local_ip:
        # All remote IPs must be deleted before deleting local IP
        if remote_ips_:
            if not (set(_remote_ips) == set(remote_ips_)):
                raise ModelError('"local_ip" cannot be deleted')