Ejemplo n.º 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)')
Ejemplo n.º 2
0
def update():

    # if_local_ip:
    # TODO: yamldiff.py must not generate update on list parameters.
    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)')
Ejemplo n.º 3
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)')
Ejemplo n.º 4
0
def _flow_entries(ope):

    params = {}

    if ope == 'add':
        params['svni'] = str(_vni_)
        params['svid'] = str(_vid_)
    else:  # 'delete'
        params['svni'] = str(vni_)
        params['svid'] = str(vid_)

    int_br = "int_br" + params['svni']

    cmd = cmdutil.check_cmd

    if _vid:
        if ope:
            cmd('ovs-ofctl add-flow br-tun table=2,priority=1,tun_id={svni},actions=mod_vlan_vid:{svid},resubmit(,10)'
                .format(**params))
        else:
            cmd('ovs-ofctl del-flows br-tun table=2,tun_id={svni}'.format(
                **params))

    if _peers:
        # Broadcast tree for each vni
        output_ports = ''
        vxlan_ports = get_vxlan_ports(_peers)
        for vxlan_port in vxlan_ports:
            output_ports = output_ports + ',output:' + vxlan_port
        if ope:
            cmd('ovs-ofctl add-flow br-tun table=21,priority=1,dl_vlan={svid},actions=strip_vlan,set_tunnel:{svni}'
                .format(**params) + output_ports)
        else:
            cmd('ovs-ofctl del-flow br-tun table=21,dl_vlan={svid}'.format(
                **params))
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
def _flow_entries(ope, br_tun):
    
        params = {}

        if ope == 'add':
            params['svni'] = str(_vni_)
            params['svid'] = str(_vid_)
        else: # 'delete'
            params['svni'] = str(vni_)
            params['svid'] = str(vid_)

        int_br = "int_br" + params['svni']

        cmd = cmdutil.check_cmd

        if _vid:
            if ope:
                cmd('ovs-ofctl add-flow', br_tun, 'table=2,priority=1,tun_id={svni},actions=mod_vlan_vid:{svid},resubmit(,10)'.format(**params))
            else:
                cmd('ovs-ofctl del-flows', br_tun, 'table=2,tun_id={svni}'.format(**params))

        if _peers:
            # Broadcast tree for each vni
            output_ports = ''
            vxlan_ports = get_vxlan_ports(_peers)
            for vxlan_port in vxlan_ports:
                output_ports = output_ports+',output:'+vxlan_port
            if ope:
                cmd('ovs-ofctl add-flow', br_tun, 'table=21,priority=1,dl_vlan={svid},actions=strip_vlan,set_tunnel:{svni}'.format(**params)+output_ports)
            else:
                cmd('ovs-ofctl del-flow', br_tun, 'table=21,dl_vlan={svid}'.format(**params))
Ejemplo n.º 7
0
def add():
    
    if not _local_ip_:
        raise ModelError('"_local_ip_" is mandatory')
    if _remote_ips:
        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)
            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(_remote_ips) 
        # TODO: yamldiff.py does not work on list parameters very well.
        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)')
Ejemplo n.º 8
0
def delete():
    
    if _remote_ips:
        # vxlan_ports = get_vxlan_ports(_remote_ips) 
        # TODO: yamldiff.py does not work on list parameters very well.
        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('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') 
Ejemplo n.º 9
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')
Ejemplo n.º 10
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') 
Ejemplo n.º 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')
Ejemplo n.º 12
0
def _flow_entries(ope):
    
    # serarch Open_vSwitch table
    if not search('Controller', ['target']): # no OpenFlow Controller

        params = {}

        if ope == 'add':
            params['svni'] = str(_vni_)
            params['svid'] = str(_vid_)
            if _ip_dvr:
                params['defaultgw'] = _ip_dvr['addr'].split('/')[0]
        else: # 'delete'
            params['svni'] = str(vni_)
            params['svid'] = str(vid_)
            if _ip_dvr:
                params['defaultgw'] = ip_dvr_['addr'].split('/')[0]

        int_dvr = "int_dvr" + params['svni']
        int_br = "int_br" + params['svni']

        cmd = cmdutil.check_cmd

        if _vid:
            if ope:
                cmd('ovs-ofctl add-flow br-tun table=2,priority=1,tun_id={svni},actions=mod_vlan_vid:{svid},resubmit(,10)'.format(**params))
            else:
                cmd('ovs-ofctl del-flows br-tun table=2,tun_id={svni}'.format(**params))
        
        if _ip_dvr and 'mode' not in _ip_dvr:
            raise ModelError('requires "mode"')

        if _ip_dvr and _ip_dvr['mode'] == 'dvr':
            if ope:
                cmd('ovs-ofctl add-flow br-tun', 'table=19,priority=1,dl_type=0x0806,dl_vlan={svid},nw_dst={defaultgw},actions=drop'.format(**params))
            else:
                cmd('ovs-ofctl del-flows br-tun', 'table=19,dl_type=0x0806,dl_vlan={svid},nw_dst={defaultgw}'.format(**params))

        # Redirects a packet to int_dvr port if nw_dst is a private ip address
        elif _ip_dvr and _ip_dvr['mode'] == 'spoke_dvr':
           
            mask = _ip_dvr['addr'].split('/')[1]
            #address = params['defaultgw'].split('.')
            nw_dst = network_address(params['defaultgw'], mask)+'/'+mask
            
            output = cmdutil.output_cmd('ip link show dev', int_dvr).split('\n')[1]
            dl_dst = output.split()[1]
            
            r = OvsdbRow('Interface', ('name', int_dvr))
            outport = str(r['ofport'])
            r = OvsdbRow('Interface', ('name', int_br))
            inport = str(r['ofport'])

            params['inport'] = inport
            params['outport'] = outport
            params['dl_type'] = '0x0800' 
            params['dl_dst'] = dl_dst 
            params['nw_dst'] = nw_dst
            params['nw_dst10'] = nw_dst10
            params['nw_dst172'] = nw_dst172
            params['nw_dst192'] = nw_dst192
            params['cmdadd'] = 'ovs-ofctl add-flow br-int'
            params['cmddel'] = 'ovs-ofctl del-flows br-int'

            if ope:
                cmd('{cmdadd} table=0,priority=2,in_port={inport},dl_type={dl_type},nw_dst={nw_dst},actions=normal'.format(**params))
                cmd('{cmdadd} table=0,priority=1,in_port={inport},dl_type={dl_type},nw_dst={nw_dst10},actions=resubmit(,1)'.format(**params))
                cmd('{cmdadd} table=0,priority=1,in_port={inport},dl_type={dl_type},nw_dst={nw_dst172},actions=resubmit(,1)'.format(**params))
                cmd('{cmdadd} table=0,priority=1,in_port={inport},dl_type={dl_type},nw_dst={nw_dst192},actions=resubmit(,1)'.format(**params))
                # ARP, opcode = 2, TPA = defaultgw
                cmd('{cmdadd} table=0,priority=1,in_port={outport},dl_type=0x0806,nw_src={defaultgw},nw_proto=2,actions=drop'.format(**params))
                cmd('{cmdadd} table=1,priority=0,in_port={inport},actions=set_field:{dl_dst}->dl_dst,output:{outport}'.format(**params))
            else:
                cmd('{cmddel} table=0,in_port={inport},dl_type={dl_type},nw_dst={nw_dst}'.format(**params))
                cmd('{cmddel} table=0,in_port={inport},dl_type={dl_type},nw_dst={nw_dst10}'.format(**params))
                cmd('{cmddel} table=0,in_port={inport},dl_type={dl_type},nw_dst={nw_dst172}'.format(**params))
                cmd('{cmddel} table=0,in_port={inport},dl_type={dl_type},nw_dst={nw_dst192}'.format(**params))
                # ARP, opcode = 2, TPA = defaultgw
                cmd('{cmddel} table=0,in_port={outport},dl_type=0x0806,nw_src={defaultgw},nw_proto=2'.format(**params))
                cmd('{cmddel} table=1,in_port={inport}'.format(**params))

        elif _ip_dvr and _ip_dvr['mode'] == 'hub' or 'spoke':
            pass
        else:
            pass 

        if _peers:
            # Broadcast tree for each vni
            output_ports = ''
            vxlan_ports = get_vxlan_ports(_peers)
            for vxlan_port in vxlan_ports:
                output_ports = output_ports+',output:'+vxlan_port
            if ope:
                cmd('ovs-ofctl add-flow br-tun table=21,priority=1,dl_vlan={svid},actions=strip_vlan,set_tunnel:{svni}'.format(**params)+output_ports)
            else:
                cmd('ovs-ofctl del-flow br-tun table=21,dl_vlan={svid}'.format(**params))