Exemplo n.º 1
0
def stale_ifm_flow(flow, flow_info, ifaces, ifstates):
    flow_parser.get_flow_info_from_ifm_table(flow_info, flow)
    flow_ifname = flow_info['ifname']
    iface = ifaces.get(flow_ifname)
    if flow_ifname is not None and not iface:
        flow_info['reason'] = 'Interface doesnt exist'
        return create_flow_dict(flow_info, flow)
    elif flow_ifname and ifstates.get(flow_ifname):
        ifstate = ifstates.get(flow_ifname)
        ncid_list = ifstate.get('lower-layer-if')
        ncid = ncid_list[0] if ncid_list else None
        dpn = Model.get_dpn_from_ofnodeid(ncid)
        if dpn and dpn != flow_info['dpnid']:
            flow_info['reason'] = 'DpnId mismatch for flow and Interface'
            return create_flow_dict(flow_info, flow)
        if flow_info.get('lport') and ifstate.get(
                'if-index') and flow_info['lport'] != ifstate['if-index']:
            flow_info['reason'] = 'Lport and IfIndex mismatch'
            return create_flow_dict(flow_info, flow)
        if (flow_info.get('ofport') and ifstate.get('lower-layer-if')
                and flow_info['ofport'] != Model.get_ofport_from_ncid(
                    ifstate.get('lower-layer-if')[0])):  # NOQA
            flow_info['reason'] = 'OfPort mismatch'
        if (flow_info.get('vlanid') and iface.get('odl-interface:vlan-id')
                and flow_info['vlanid'] !=
                iface.get('odl-interface:vlan-id')):  # NOQA
            flow_info['reason'] = 'VlanId mismatch'
    return None
Exemplo n.º 2
0
def get_flow_info_from_ifm_table(flow_info, flow):
    flow_info['ifname'] = get_ifname_from_flowid(flow['id'], flow['table_id'])
    w_mdata = get_instruction_writemeta(flow)
    if w_mdata:
        metadata = w_mdata['metadata']
        mask = w_mdata['metadata-mask']
        lport = get_lport_from_metadata(metadata, mask)
        if lport:
            flow_info['lport'] = int(lport, 16)
        service_id = get_service_id_from_metadata(metadata, mask)
        if service_id:
            flow_info['serviceid'] = int(service_id, 16)
    m_reg6 = get_match_reg6(flow)
    if not flow.get('lport'):
        lport = get_lport_from_mreg6(m_reg6)
        if lport:
            flow_info['lport'] = int(lport, 16)
    if flow['table_id'] == 0:
        m_inport = get_match_inport(flow)
        if m_inport:
            flow_info['ofport'] = Model.get_ofport_from_ncid(m_inport)
        m_vlan = get_match_vlanid(flow)
        if m_vlan and m_vlan.get('vlan-id'):
            flow_info['vlanid'] = m_vlan.get('vlan-id')
    elif flow['table_id'] == 220:
        a_output = get_act_output(flow)
        a_vlan = get_act_set_vlanid(flow)
        if a_output and a_output.get('output-node-connector'):
            flow_info['ofport'] = a_output.get('output-node-connector')
        if a_vlan and a_vlan.get('vlan-id'):
            flow_info['vlanid'] = a_vlan.get('vlan-id')
    return flow_info
Exemplo n.º 3
0
def get_flow_info_from_ifm_table(flow_info, flow):
    flow_info['ifname'] = get_ifname_from_flowid(flow['id'], flow['table_id'])
    w_mdata = get_instruction_writemeta(flow)
    if w_mdata:
        metadata = w_mdata['metadata']
        mask = w_mdata['metadata-mask']
        if mask & LPORT_MASK:
            lport = ('%x' % (metadata & LPORT_MASK))[:-LPORT_MASK_ZLEN]
            flow_info['lport'] = int(lport, 16)
    m_reg6 = get_match_reg6(flow)
    if not flow.get('lport') and m_reg6 and m_reg6.get('value'):
        lport = (
            ('%x' %
             (m_reg6.get('value') & LPORT_REG6_MASK))[:-LPORT_REG6_MASK_ZLEN])
        flow_info['lport'] = int(lport, 16)
    if flow['table_id'] == 0:
        m_inport = get_match_inport(flow)
        if m_inport:
            flow_info['ofport'] = Model.get_ofport_from_ncid(m_inport)
        m_vlan = get_match_vlanid(flow)
        if m_vlan and m_vlan.get('vlan-id'):
            flow_info['vlanid'] = m_vlan.get('vlan-id')
    elif flow['table_id'] == 220:
        a_output = get_act_output(flow)
        a_vlan = get_act_set_vlanid(flow)
        if a_output and a_output.get('output-node-connector'):
            flow_info['ofport'] = a_output.get('output-node-connector')
        if a_vlan and a_vlan.get('vlan-id'):
            flow_info['vlanid'] = a_vlan.get('vlan-id')
    return flow_info
Exemplo n.º 4
0
def get_flow_info_from_ifm_table(flow_info, flow):
    flow_info['ifname'] = get_ifname_from_flowid(flow['id'], flow['table_id'])
    w_mdata = get_instruction_writemeta(flow)
    if w_mdata:
        metadata = w_mdata['metadata']
        mask = w_mdata['metadata-mask']
        lport = get_lport_from_metadata(metadata, mask)
        if lport:
            flow_info['lport'] = int(lport, 16)
        service_id = get_service_id_from_metadata(metadata, mask)
        if service_id:
            flow_info['serviceid'] = int(service_id, 16)
    m_reg6 = get_match_reg6(flow)
    if not flow.get('lport'):
        lport = get_lport_from_mreg6(m_reg6)
        if lport:
            flow_info['lport'] = int(lport, 16)
    if flow['table_id'] == 0:
        m_inport = get_match_inport(flow)
        if m_inport:
            flow_info['ofport'] = Model.get_ofport_from_ncid(m_inport)
        m_vlan = get_match_vlanid(flow)
        if m_vlan and m_vlan.get('vlan-id'):
            flow_info['vlanid'] = m_vlan.get('vlan-id')
    elif flow['table_id'] == 220:
        a_output = get_act_output(flow)
        a_vlan = get_act_set_vlanid(flow)
        if a_output and a_output.get('output-node-connector'):
            flow_info['ofport'] = a_output.get('output-node-connector')
        if a_vlan and a_vlan.get('vlan-id'):
            flow_info['vlanid'] = a_vlan.get('vlan-id')
    return flow_info
Exemplo n.º 5
0
def stale_ifm_flow(flow, flow_info, ifaces, ifstates):
    flow_parser.get_flow_info_from_ifm_table(flow_info, flow)
    flow_ifname = flow_info['ifname']
    iface = ifaces.get(flow_ifname)
    flow_info['reason'] = None
    if flow_ifname is not None and not iface:
        flow_info['reason'] = 'Interface doesnt exist'
        return create_flow_dict(flow_info, flow)
    elif flow_ifname and ifstates.get(flow_ifname):
        ifstate = ifstates.get(flow_ifname)
        ncid_list = ifstate.get('lower-layer-if')
        ncid = ncid_list[0] if ncid_list else None
        dpn = Model.get_dpn_from_ofnodeid(ncid)
        if dpn and dpn != flow_info['dpnid']:
            flow_info['reason'] = 'DpnId mismatch for flow and Interface'
            return create_flow_dict(flow_info, flow)
        if flow_info.get('lport') and ifstate.get('if-index') and flow_info['lport'] != ifstate['if-index']:
            flow_info['reason'] = 'Lport and IfIndex mismatch'
            return create_flow_dict(flow_info, flow)
        if (flow_info.get('ofport') and ifstate.get('lower-layer-if')
            and flow_info['ofport'] != Model.get_ofport_from_ncid(ifstate.get('lower-layer-if')[0])):  # NOQA
            flow_info['reason'] = 'OfPort mismatch'
            return create_flow_dict(flow_info, flow)
        if (flow_info.get('vlanid') and iface.get('odl-interface:vlan-id')
            and flow_info['vlanid'] != iface.get('odl-interface:vlan-id')):  # NOQA
            flow_info['reason'] = 'VlanId mismatch'
            return create_flow_dict(flow_info, flow)
    return create_flow_dict(flow_info, flow)
Exemplo n.º 6
0
def analyze_trunks(args):
    config.get_models(
        args,
        {
            "ietf_interfaces_interfaces",
            # "ietf_interfaces_interfaces_state",
            "l3vpn_vpn_interfaces",
            "neutron_neutron"
        })

    vpninterfaces = config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key()
    ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
    # ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key()
    nports = config.gmodels.neutron_neutron.get_objects_by_key(
        obj=Neutron.PORTS)
    ntrunks = config.gmodels.neutron_neutron.get_trunks_by_key()
    subport_dict = {}
    for v in ntrunks.values():
        nport = nports.get(v.get('port-id'))
        s_subports = []
        for subport in v.get('sub-ports'):
            sport_id = subport.get('port-id')
            snport = nports.get(sport_id)
            svpniface = vpninterfaces.get(sport_id)
            siface = ifaces.get(sport_id)
            # sifstate = ifstates.get(sport_id)
            subport['SubNeutronPort'] = 'Correct' if snport else 'Wrong'
            subport['SubVpnInterface'] = 'Correct' if svpniface else 'Wrong'
            subport['ofport'] = Model.get_ofport_from_ncid()
            if siface:
                vlan_mode = siface.get('odl-interface:l2vlan-mode')
                parent_iface_id = siface.get('odl-interface:parent-interface')
                if vlan_mode != 'trunk-member':
                    subport['SubIface'] = 'WrongMode'
                elif parent_iface_id != v.get('port-id'):
                    subport['SubIface'] = 'WrongParent'
                elif siface.get('odl-interface:vlan-id') != subport.get(
                        'segmentation-id'):
                    subport['SubIface'] = 'WrongVlanId'
                else:
                    subport['SubIface'] = 'Correct'
            else:
                subport['SubIface'] = 'Wrong'
                # s_subport = 'SegId:{}, PortId:{}, SubNeutronPort:{}, SubIface:{}, SubVpnIface:{}'.format(
                #     subport.get('segmentation-id'), subport.get('port-id'),
                #     subport.get('SubNeutronPort'),
                #     subport.get('SubIface'),
                #     subport.get('SubVpnInterface'))
            s_subports.append(subport)
            subport_dict[subport['port-id']] = subport
            s_trunk = 'TrunkName:{}, TrunkId:{}, PortId:{}, NeutronPort:{}, SubPorts:{}'.format(
                v.get('name'), v.get('uuid'), v.get('port-id'),
                'Correct' if nport else 'Wrong',
                utils.format_json(args, s_subports))
            print(s_trunk)
            print("\n------------------------------------")
            print("Analyzing Flow status for SubPorts")
            print("------------------------------------")
            for flow in utils.sort(
                    flows.get_all_flows(args, ['ifm'], ['vlanid']), 'ifname'):
                subport = subport_dict.get(flow.get('ifname')) or None
                vlanid = subport.get('segmentation-id') if subport else None
                ofport = subport.get('ofport') if subport else None
                flow_status = 'Okay'
                if flow.get('ofport') and flow.get('ofport') != ofport:
                    flow_status = 'OfPort mismatch for SubPort:{} and Flow:{}'.format(
                        subport, flow.get('flow'))
                if flow.get('vlanid') and flow.get('vlanid') != vlanid:
                    flow_status = 'VlanId mismatch for SubPort:{} and Flow:{}'.format(
                        subport, flow.get('flow'))
                if subport:
                    print("SubPort:{},Table:{},FlowStatus:{}".format(
                        subport.get('port-id'), flow.get('table'),
                        flow_status))
Exemplo n.º 7
0
def analyze_trunks(args):
    config.get_models(args, {
        "ietf_interfaces_interfaces",
        # "ietf_interfaces_interfaces_state",
        "l3vpn_vpn_interfaces",
        "neutron_neutron"})

    vpninterfaces = config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key()
    ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
    # ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key()
    nports = config.gmodels.neutron_neutron.get_objects_by_key(obj=Neutron.PORTS)
    ntrunks = config.gmodels.neutron_neutron.get_trunks_by_key()
    subport_dict = {}
    for v in ntrunks.values():
        nport = nports.get(v.get('port-id'))
        s_subports = []
        for subport in v.get('sub-ports'):
            sport_id = subport.get('port-id')
            snport = nports.get(sport_id)
            svpniface = vpninterfaces.get(sport_id)
            siface = ifaces.get(sport_id)
            # sifstate = ifstates.get(sport_id)
            subport['SubNeutronPort'] = 'Correct' if snport else 'Wrong'
            subport['SubVpnInterface'] = 'Correct' if svpniface else 'Wrong'
            subport['ofport'] = Model.get_ofport_from_ncid()
            if siface:
                vlan_mode = siface.get('odl-interface:l2vlan-mode')
                parent_iface_id = siface.get('odl-interface:parent-interface')
                if vlan_mode != 'trunk-member':
                    subport['SubIface'] = 'WrongMode'
                elif parent_iface_id != v.get('port-id'):
                    subport['SubIface'] = 'WrongParent'
                elif siface.get('odl-interface:vlan-id') != subport.get('segmentation-id'):
                    subport['SubIface'] = 'WrongVlanId'
                else:
                    subport['SubIface'] = 'Correct'
            else:
                subport['SubIface'] = 'Wrong'
                # s_subport = 'SegId:{}, PortId:{}, SubNeutronPort:{}, SubIface:{}, SubVpnIface:{}'.format(
                #     subport.get('segmentation-id'), subport.get('port-id'),
                #     subport.get('SubNeutronPort'),
                #     subport.get('SubIface'),
                #     subport.get('SubVpnInterface'))
            s_subports.append(subport)
            subport_dict[subport['port-id']] = subport
            s_trunk = 'TrunkName:{}, TrunkId:{}, PortId:{}, NeutronPort:{}, SubPorts:{}'.format(
                v.get('name'), v.get('uuid'), v.get('port-id'),
                'Correct' if nport else 'Wrong', utils.format_json(args, s_subports))
            print(s_trunk)
            print("\n------------------------------------")
            print("Analyzing Flow status for SubPorts")
            print("------------------------------------")
            for flow in utils.sort(flows.get_all_flows(args, ['ifm'], ['vlanid']), 'ifname'):
                subport = subport_dict.get(flow.get('ifname')) or None
                vlanid = subport.get('segmentation-id') if subport else None
                ofport = subport.get('ofport') if subport else None
                flow_status = 'Okay'
                if flow.get('ofport') and flow.get('ofport') != ofport:
                    flow_status = 'OfPort mismatch for SubPort:{} and Flow:{}'.format(subport, flow.get('flow'))
                if flow.get('vlanid') and flow.get('vlanid') != vlanid:
                    flow_status = 'VlanId mismatch for SubPort:{} and Flow:{}'.format(subport, flow.get('flow'))
                if subport:
                    print("SubPort:{},Table:{},FlowStatus:{}".format(
                        subport.get('port-id'), flow.get('table'), flow_status))