Exemple #1
0
    def __make_flow_id(self, dpid, flow, mask, priority):  #dpid, resp):
        dl_src = dl_dst = nw_src = nw_dst = ""

        dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src)
        dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst)
        dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src)
        dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst)

        if mask.dl_type and (flow.dl_type == 0x86dd):
            nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0)
            if nw_src == "-1":
                nw_src = "----:----:----:----:----:----:----:---/80"
                nw_src = str(nw_src).replace(":", "").replace("/", "")
                nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1)
            if nw_dst == "-1":
                nw_dst = "----:----:----:----:----:----:----:----/80"
                nw_dst = str(nw_dst).replace(":", "").replace("/", "")
        else:
            str_sip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0)
            str_dip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1)
            for sip in str(str_sip).replace("/", ".").split("."):
                nw_src += "%02x" % int(sip)
            for dip in str(str_dip).replace("/", ".").split("."):
                nw_dst += "%02x" % int(dip)
            if str_sip == "-1":
                nw_src = "--------20"
            if str_dip == "-1":
                nw_dst = "--------20"
        flow_id = "%016x" % dpid + "%02x" % flow.table_id + "%04x" % priority
        flow_id += dl_src.replace(
            ':', '') if dl_src_mask != '00:00:00:00:00:00' else '------------'
        flow_id += dl_dst.replace(
            ':', '') if dl_dst_mask != '00:00:00:00:00:00' else '------------'
        flow_id += "%04x" % flow.dl_type if mask.dl_type else '----'
        flow_id += "%03x" % flow.dl_vlan if mask.dl_vlan else '---'
        flow_id += "%01d" % flow.dl_vlan_pcp if mask.dl_vlan_pcp else '-'
        flow_id += "%05x" % flow.mpls_label if mask.mpls_label else '-----'
        flow_id += "%01d" % flow.mpls_tc if mask.mpls_tc else '-'
        flow_id += "%01d" % flow.mpls_bos if mask.mpls_bos else '-'
        flow_id += "%04x" % flow.in_port if mask.in_port else '----'
        flow_id += "%02x" % flow.nw_proto if mask.nw_proto else '--'
        flow_id += "%02x" % flow.nw_tos if mask.nw_tos else '--'
        flow_id += "%04x" % flow.tp_dst if mask.tp_dst else '----'
        flow_id += "%04x" % flow.tp_src if mask.tp_src else '----'
        flow_id += nw_src + nw_dst

        return flow_id
Exemple #2
0
    def __make_flow_id(self, dpid, flow, mask, priority):#dpid, resp):
        dl_src = dl_dst = nw_src = nw_dst = ""

        dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src)
        dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst)
        dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src)
        dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst)

        if mask.dl_type and (flow.dl_type == 0x86dd):
            nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0)
            if nw_src == "-1":
                nw_src = "----:----:----:----:----:----:----:---/80"
                nw_src = str(nw_src).replace(":","").replace("/","")
                nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1)
            if nw_dst == "-1":
                nw_dst = "----:----:----:----:----:----:----:----/80"
                nw_dst = str(nw_dst).replace(":","").replace("/","")
        else:
            str_sip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0)
            str_dip = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1)
            for sip in str(str_sip).replace("/",".").split("."):
                nw_src += "%02x" % int(sip)
            for dip in str(str_dip).replace("/",".").split("."):
                nw_dst += "%02x" % int(dip)
            if str_sip == "-1":
                nw_src = "--------20"
            if str_dip == "-1":
                nw_dst = "--------20"

        flow_id = "%016x" %dpid + "%02x" %flow.table_id + "%04x" %priority
        flow_id += dl_src.replace(':','')   if dl_src_mask != '00:00:00:00:00:00' else '------------'
        flow_id += dl_dst.replace(':','')   if dl_dst_mask != '00:00:00:00:00:00' else '------------'
        flow_id += "%04x" %flow.dl_type     if mask.dl_type else '----'
        flow_id += "%03x" %flow.dl_vlan     if mask.dl_vlan else '---'
        flow_id += "%01d" %flow.dl_vlan_pcp if mask.dl_vlan_pcp else '-'
        flow_id += "%05x" %flow.mpls_label  if mask.mpls_label else '-----'
        flow_id += "%01d" %flow.mpls_tc     if mask.mpls_tc else '-'
        flow_id += "%01d" %flow.mpls_bos    if mask.mpls_bos else '-'
        flow_id += "%04x" %flow.in_port     if mask.in_port else '----'
        flow_id += "%02x" %flow.nw_proto    if mask.nw_proto else '--'
        flow_id += "%02x" %flow.nw_tos      if mask.nw_tos else '--'
        flow_id += "%04x" %flow.tp_dst      if mask.tp_dst else '----'
        flow_id += "%04x" %flow.tp_src      if mask.tp_src else '----'
        flow_id += nw_src + nw_dst

        return flow_id
Exemple #3
0
    def __flow_struct_serialization(self, flow, mask):

        dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src)
        dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst)
        dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src)
        dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst)

        ret = { 'table_id'  : flow.table_id }
        if dl_src_mask != "00:00:00:00:00:00" :
            ret.update({'dl_src' : dl_src})
        if dl_dst_mask != "00:00:00:00:00:00" :
            ret.update({'dl_dst' : dl_dst})
        if mask.dl_type     : ret.update({'dl_type'     : '0x%lx' % flow.dl_type})
        if mask.dl_vlan     : ret.update({'dl_vlan'     : flow.dl_vlan})
        if mask.dl_vlan_pcp : ret.update({'dl_vlan_pcp' : flow.dl_vlan_pcp})
        if mask.mpls_label  : ret.update({'mpls_label'  : flow.mpls_label})
        if mask.mpls_tc     : ret.update({'mpls_tc'     : flow.mpls_tc})
        if mask.mpls_bos    : ret.update({'mpls_bos'    : flow.mpls_bos})
        if mask.in_port     : ret.update({'in_port'    : flow.in_port})

    #if mask.dl_type and (flow.dl_type is mul.ETH_TYPE_IP or mul.ETH_TYPE_ARP or mul.ETH_TYPE_IPV6):
        if mask.dl_type and (flow.dl_type is 0x0800 or 0x0806 or 0x86dd):
            if mask.nw_proto : ret.update({'nw_proto': flow.nw_proto})
            if mask.nw_tos   : ret.update({'nw_tos'  : flow.nw_tos})
            if mask.tp_dst   : ret.update({'tp_dst'  : flow.tp_dst})
            if mask.tp_src   : ret.update({'tp_src'  : flow.tp_src})

        if flow.dl_type == 0x86dd:
            nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0)
            nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1)
            if nw_dst != '-1' : ret.update({'nw_dst6' : nw_dst})
            if nw_src != '-1' : ret.update({'nw_src6' : nw_src})
        else:
            nw_src = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0)
            nw_dst = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1)
            if nw_dst != '-1' : ret.update({'nw_dst': nw_dst})
            if nw_src != '-1' : ret.update({'nw_src': nw_src})
        return ret
Exemple #4
0
    def __flow_struct_serialization(self, flow, mask):

        dl_src = mul.nbapi_parse_mac_to_str(flow.dl_src)
        dl_dst = mul.nbapi_parse_mac_to_str(flow.dl_dst)
        dl_src_mask = mul.nbapi_parse_mac_to_str(mask.dl_src)
        dl_dst_mask = mul.nbapi_parse_mac_to_str(mask.dl_dst)

        ret = {'table_id': flow.table_id}
        if dl_src_mask != "00:00:00:00:00:00":
            ret.update({'dl_src': dl_src})
        if dl_dst_mask != "00:00:00:00:00:00":
            ret.update({'dl_dst': dl_dst})
        if mask.dl_type: ret.update({'dl_type': '0x%lx' % flow.dl_type})
        if mask.dl_vlan: ret.update({'dl_vlan': flow.dl_vlan})
        if mask.dl_vlan_pcp: ret.update({'dl_vlan_pcp': flow.dl_vlan_pcp})
        if mask.mpls_label: ret.update({'mpls_label': flow.mpls_label})
        if mask.mpls_tc: ret.update({'mpls_tc': flow.mpls_tc})
        if mask.mpls_bos: ret.update({'mpls_bos': flow.mpls_bos})
        if mask.in_port: ret.update({'in_port': flow.in_port})

        #if mask.dl_type and (flow.dl_type is mul.ETH_TYPE_IP or mul.ETH_TYPE_ARP or mul.ETH_TYPE_IPV6):
        if mask.dl_type and (flow.dl_type is 0x0800 or 0x0806 or 0x86dd):
            if mask.nw_proto: ret.update({'nw_proto': flow.nw_proto})
            if mask.nw_tos: ret.update({'nw_tos': flow.nw_tos})
            if mask.tp_dst: ret.update({'tp_dst': flow.tp_dst})
            if mask.tp_src: ret.update({'tp_src': flow.tp_src})

        if flow.dl_type == 0x86dd:
            nw_src = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 0)
            nw_dst = mul.nbapi_parse_ipv6_nw_addr_to_str(flow, mask, 1)
            if nw_dst != '-1': ret.update({'nw_dst6': nw_dst})
            if nw_src != '-1': ret.update({'nw_src6': nw_src})
        else:
            nw_src = mul.nbapi_parse_nw_addr_to_str(flow, mask, 0)
            nw_dst = mul.nbapi_parse_nw_addr_to_str(flow, mask, 1)
            if nw_dst != '-1': ret.update({'nw_dst': nw_dst})
            if nw_src != '-1': ret.update({'nw_src': nw_src})
        return ret