コード例 #1
0
ファイル: datapath.py プロジェクト: ProyectoRRAP/LiveCode
def get_of_match_field(ofparser, s):
    '''
    Creates OF macth field from service openflow section
    '''

    match = ofparser.OFPMatch()

    if s.in_port is not None:
        match.set_in_port(s.in_port)

    if s.in_phy_port is not None:
        match.set_in_phy_port(s.in_phy_port)

    if s.metadata is not None:
        match.set_metadata(s.metadata)

    if s.eth_dst is not None:
        match.set_dl_dst(s.eth_dst)

    if s.eth_src is not None:
        match.set_dl_src(s.eth_src)

    if s.eth_type is not None:
        match.set_dl_type(util.string_to_hexa(s.eth_type))

    if s.vlan_vID is not None:
        match.set_vlan_vid(int(s.vlan_vID, 16))

    if s.vlan_PCP is not None:
        match.set_vlan_pcp(int(s.vlan_PCP, 16))

    if s.IP_dscp is not None:
        match.set_ip_dscp(s.IP_dscp)

    if s.IP_ecn is not None:
        match.set_ip_ecn(s.IP_ecn)

    if s.IP_proto is not None:
        match.set_ip_proto(int(s.IP_proto, 16))

    if s.IPv4_src is not None:
        ip_src, ip_mask_src = stringToIPAddress(s.IPv4_src)
        match.set_ipv4_src_masked(ip_src, ip_mask_src)

    if s.IPv4_dst is not None:
        ip_dst, ip_mask_dst = stringToIPAddress(s.IPv4_dst)
        match.set_ipv4_dst_masked(ip_dst, ip_mask_dst)

    if s.TCP_src is not None:
        match.set_tcp_src(int(s.TCP_src))

    if s.TCP_dst is not None:
        match.set_tcp_dst(int(s.TCP_dst))

    if s.UDP_src is not None:
        match.set_udp_src(int(s.UDP_src))

    if s.UDP_dst is not None:
        match.set_udp_dst(int(s.UDP_dst))

    if s.SCTP_src is not None:
        match.set_sctp_src(s.SCTP_src)

    if s.SCTP_dst is not None:
        match.set_sctp_dst(s.SCTP_dst)

    if s.ICMPv4_type is not None:
        match.set_icmpv4_type(s.ICMPv4_type)

    if s.ICMPv4_code is not None:
        match.set_icmpv4_code(s.ICMPv4_code)

    if s.ARP_op is not None:
        match.set_arp_opcode(s.ARP_op)

    if s.ARP_spa is not None:
        arp_spa, arp_mask_src = stringToIPAddress(s.ARP_spa)
        match.set_arp_spa_masked(arp_spa, arp_mask_src)

    if s.ARP_tpa is not None:
        arp_tpa, arp_mask_dst = stringToIPAddress(s.ARP_tpa)
        match.set_arp_tpa_masked(arp_tpa, arp_mask_dst)

    if s.ARP_sha is not None:
        match.set_arp_sha(s.ARP_sha)

    if s.ARP_tha is not None:
        match.set_arp_tha(s.ARP_tha)

    if s.IPv6_src is not None:
        match.set_ipv6_src(s.IPv6_src)

    if s.IPv6_dst is not None:
        match.set_ipv6_dst(s.IPv6_dst)

    if s.IPv6_flabel is not None:
        match.set_ipv6_flabel(s.IPv6_flabel)

    if s.ICMPv6_type is not None:
        match.set_icmpv6_type(s.ICMPv6_type)

    if s.ICMPv6_code is not None:
        match.set_icmpv6_code(s.ICMPv6_code)

    if s.IPv6_nd_target is not None:
        match.set_ipv6_nd_target(s.IPv6_nd_target)

    if s.IPv6_nd_ssl is not None:
        match.set_ipv6_nd_sll(s.IPv6_nd_ssl)

    if s.IPv6_nd_tll is not None:
        match.set_ipv6_nd_tll(s.IPv6_nd_tll)

    if s.MPLS_label is not None:
        match.set_mpls_label(s.MPLS_label)

    if s.MPLS_tc is not None:
        match.set_mpls_tc(s.MPLS_tc)

    if s.MPLS_bos is not None:
        match.set_mpls_bos(s.MPLS_bos)

    if s.PBB_is_id is not None:
        match.set_pbb_isid(s.PBB_is_id)

    if s.tunnel_id is not None:
        match.set_tunnel_id(s.tunnel_id)

    if s.IPv6_txhdr is not None:
        match.set_ipv6_exthdr(s.IPv6_txhdr)

    return match
コード例 #2
0
ファイル: datapath.py プロジェクト: ProyectoRRAP/LiveCode
def get_of_match_field(ofparser, s):
    '''
    Creates OF macth field from service openflow section
    '''
    
    match = ofparser.OFPMatch()

    if s.in_port is not None:
        match.set_in_port(s.in_port)

    if s.in_phy_port is not None:
        match.set_in_phy_port(s.in_phy_port)

    if s.metadata is not None:
        match.set_metadata(s.metadata)

    if s.eth_dst is not None:
        match.set_dl_dst(s.eth_dst)

    if s.eth_src is not None:
        match.set_dl_src(s.eth_src)

    if s.eth_type is not None:
        match.set_dl_type(util.string_to_hexa(s.eth_type))

    if s.vlan_vID is not None:
        match.set_vlan_vid(int(s.vlan_vID, 16))

    if s.vlan_PCP is not None:
        match.set_vlan_pcp(int(s.vlan_PCP, 16))

    if s.IP_dscp is not None:
        match.set_ip_dscp(s.IP_dscp)

    if s.IP_ecn is not None:
        match.set_ip_ecn(s.IP_ecn)

    if s.IP_proto is not None:
        match.set_ip_proto(int(s.IP_proto, 16))

    if s.IPv4_src is not None:
        ip_src, ip_mask_src = stringToIPAddress(s.IPv4_src)
        match.set_ipv4_src_masked(ip_src, ip_mask_src)

    if s.IPv4_dst is not None:
        ip_dst, ip_mask_dst = stringToIPAddress(s.IPv4_dst)
        match.set_ipv4_dst_masked(ip_dst, ip_mask_dst)

    if s.TCP_src is not None:
        match.set_tcp_src(int(s.TCP_src))

    if s.TCP_dst is not None:
        match.set_tcp_dst(int(s.TCP_dst))

    if s.UDP_src is not None:
        match.set_udp_src(int(s.UDP_src))

    if s.UDP_dst is not None:
        match.set_udp_dst(int(s.UDP_dst))

    if s.SCTP_src is not None:
        match.set_sctp_src(s.SCTP_src)

    if s.SCTP_dst is not None:
        match.set_sctp_dst(s.SCTP_dst)

    if s.ICMPv4_type is not None:
        match.set_icmpv4_type(s.ICMPv4_type)

    if s.ICMPv4_code is not None:
        match.set_icmpv4_code(s.ICMPv4_code)

    if s.ARP_op is not None:
        match.set_arp_opcode(s.ARP_op)

    if s.ARP_spa is not None:
        arp_spa, arp_mask_src = stringToIPAddress(s.ARP_spa)
        match.set_arp_spa_masked(arp_spa, arp_mask_src)

    if s.ARP_tpa is not None:
        arp_tpa, arp_mask_dst = stringToIPAddress(s.ARP_tpa)
        match.set_arp_tpa_masked(arp_tpa, arp_mask_dst)

    if s.ARP_sha is not None:
        match.set_arp_sha(s.ARP_sha)

    if s.ARP_tha is not None:
        match.set_arp_tha(s.ARP_tha)

    if s.IPv6_src is not None:
        match.set_ipv6_src(s.IPv6_src)

    if s.IPv6_dst is not None:
        match.set_ipv6_dst(s.IPv6_dst)

    if s.IPv6_flabel is not None:
        match.set_ipv6_flabel(s.IPv6_flabel)

    if s.ICMPv6_type is not None:
        match.set_icmpv6_type(s.ICMPv6_type)

    if s.ICMPv6_code is not None:
        match.set_icmpv6_code(s.ICMPv6_code)
   
    if s.IPv6_nd_target is not None:
        match.set_ipv6_nd_target(s.IPv6_nd_target)

    if s.IPv6_nd_ssl is not None:
        match.set_ipv6_nd_sll(s.IPv6_nd_ssl)

    if s.IPv6_nd_tll is not None:
        match.set_ipv6_nd_tll(s.IPv6_nd_tll)

    if s.MPLS_label is not None:
        match.set_mpls_label(s.MPLS_label)

    if s.MPLS_tc is not None:
        match.set_mpls_tc(s.MPLS_tc)

    if s.MPLS_bos is not None:
        match.set_mpls_bos(s.MPLS_bos)

    if s.PBB_is_id is not None:
        match.set_pbb_isid(s.PBB_is_id)

    if s.tunnel_id is not None:
        match.set_tunnel_id(s.tunnel_id)

    if s.IPv6_txhdr is not None:
        match.set_ipv6_exthdr(s.IPv6_txhdr)

    return match 
コード例 #3
0
ファイル: datapath.py プロジェクト: ProyectoRRAP/LiveCode
def install_egress_node_flow_for_service(service,
                                         node,
                                         ovs_port_in,
                                         ovs_port_out,
                                         label_in,
                                         action,
                                         interface=None):
    '''
    Docs    
    '''

    print 'Install ingress node flow: ' + str(node.router_id)
    print '- Input port:  ' + str(ovs_port_in)
    print '- Output port: ' + str(ovs_port_out)

    #Check if node is OF type and the state is OF functional
    if node.net_type == 1 and node.of_ready:

        #Get access to node datapath
        datapath = node.datapath

        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        #Built OF match field
        #match = get_of_match_field(ofparser=parser, s=service

        if service.VPN_service_type == 2:

            # Para cada etherype del servicio instala un flujo para poner la etieueta mpls
            for eth, l in service.labels.iteritems():

                match = parser.OFPMatch()

                #Modify specific match fields
                if ovs_port_in is not None:
                    match.set_in_port(int(ovs_port_in))

                match.set_dl_type(0x8847)
                match.set_mpls_bos(1)

                #Specify actions
                actions = []

                if label_in is not None:
                    match.set_mpls_label(int(l, 16))

                if action is not None:
                    if action.isPOP():
                        match.set_dl_type(0x8847)
                        actions.append(
                            parser.OFPActionPopMpls(util.string_to_hexa(eth)))

                #Specify forwarding
                if ovs_port_out is not None:
                    actions.append(parser.OFPActionOutput(int(ovs_port_out)))

                inst = []
                add_flow(datapath=datapath,
                         priority=0,
                         match=match,
                         actions=actions,
                         tableid=0)
        else:

            match = parser.OFPMatch()

            #Modify specific match fields
            if ovs_port_in is not None:
                match.set_in_port(int(ovs_port_in))

            match.set_dl_type(0x8847)
            match.set_mpls_bos(1)

            #Specify actions
            actions = []

            if label_in is not None:
                match.set_mpls_label(int(label_in, 16))

            #Specify MPLS label manipulation
            if action is not None:
                if action.isPOP():
                    match.set_dl_type(0x8847)
                    actions.append(
                        parser.OFPActionPopMpls(
                            util.string_to_hexa(service.eth_type)))

            #Specify forwarding
            actions.append(
                parser.OFPActionSetField(eth_dst=interface.ce_mac_address))

            if ovs_port_out is not None:
                actions.append(parser.OFPActionOutput(int(ovs_port_out)))

            #actions.append(parser.OFPActionOutput(ofproto.OFPP_NORMAL, 0))

            inst = []
            add_flow(datapath=datapath,
                     priority=0,
                     match=match,
                     actions=actions,
                     tableid=0)
コード例 #4
0
ファイル: datapath.py プロジェクト: ProyectoRRAP/LiveCode
def install_egress_node_flow_for_service(service, node, ovs_port_in, ovs_port_out, label_in, action, interface=None):
    '''
    Docs    
    '''

    print 'Install ingress node flow: ' + str(node.router_id)
    print '- Input port:  ' +  str(ovs_port_in)
    print '- Output port: ' + str(ovs_port_out)

    #Check if node is OF type and the state is OF functional
    if node.net_type == 1 and node.of_ready:

        #Get access to node datapath
        datapath = node.datapath

        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        #Built OF match field
        #match = get_of_match_field(ofparser=parser, s=service
    
        if service.VPN_service_type == 2:

            # Para cada etherype del servicio instala un flujo para poner la etieueta mpls
            for eth, l in service.labels.iteritems():

                match = parser.OFPMatch()

                #Modify specific match fields
                if ovs_port_in is not None:
                    match.set_in_port(int(ovs_port_in))
                
                match.set_dl_type(0x8847)
                match.set_mpls_bos(1)

                #Specify actions
                actions = []

                if label_in is not None:
                    match.set_mpls_label(int(l, 16))

                if action is not None:
                    if action.isPOP():
                        match.set_dl_type(0x8847)
                        actions.append(parser.OFPActionPopMpls(util.string_to_hexa(eth)))
                    
                #Specify forwarding 
                if ovs_port_out is not None:
                    actions.append(parser.OFPActionOutput(int(ovs_port_out)))

                inst = []
                add_flow(datapath=datapath, priority=0, match=match, actions=actions, tableid=0)
        else:

            match = parser.OFPMatch()

            #Modify specific match fields
            if ovs_port_in is not None:
                match.set_in_port(int(ovs_port_in))
            
            match.set_dl_type(0x8847)
            match.set_mpls_bos(1)

            #Specify actions
            actions = []

            if label_in is not None:
                match.set_mpls_label(int(label_in, 16))

            #Specify MPLS label manipulation
            if action is not None:
                if action.isPOP():
                    match.set_dl_type(0x8847)
                    actions.append(parser.OFPActionPopMpls(util.string_to_hexa(service.eth_type)))
                
            #Specify forwarding 
            actions.append(parser.OFPActionSetField(eth_dst=interface.ce_mac_address))
            
            if ovs_port_out is not None:
                actions.append(parser.OFPActionOutput(int(ovs_port_out)))

            #actions.append(parser.OFPActionOutput(ofproto.OFPP_NORMAL, 0))
           
            inst = []
            add_flow(datapath=datapath, priority=0, match=match, actions=actions, tableid=0)