示例#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)
    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)
示例#2
0
文件: flows.py 项目: ww09/netvirt
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
示例#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']
        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
示例#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']
        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
示例#5
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
示例#6
0
def get_stale_flows(modules=['ifm']):
    if not modules:
        return 'No modules specified'
    ifaces = {}
    ifstates = {}
    ifindexes = {}
    # bindings = {}
    einsts = {}
    eifaces = {}
    fibentries = {}
    vpnids = {}
    vpninterfaces = {}
    groups = {}
    table_list = list(set([table for module in modules for table in tbls.get_table_map(module)]))
    # table_list = [214, 244]

    of_nodes = config.gmodels.odl_inventory_nodes.get_clist_by_key()
    if 'ifm' in modules:
        ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key()
    if 'l3vpn' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key()
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key()
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key()
        groups = groups or config.gmodels.odl_inventory_nodes.get_groups(of_nodes)
    if 'acl' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
    if 'elan' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
    stale_flows = []
    for node in of_nodes.values():
        tables = [x for x in node[Nodes.NODE_TABLE] if x['id'] in table_list]
        for table in tables:
            for flow in table.get('flow', []):
                flow_dict = None
                flow_info = {'dpnid': Model.get_dpn_from_ofnodeid(node['id'])}
                if 'ifm' in modules and table['id'] in tbls.get_table_map('ifm'):
                    flow_dict = stale_ifm_flow(flow, flow_info, ifaces, ifstates)
                if 'l3vpn' in modules and table['id'] in tbls.get_table_map('l3vpn'):
                    flow_dict = stale_l3vpn_flow(flow, flow_info, groups, ifaces, ifindexes, vpnids,
                                                 vpninterfaces, fibentries)
                if 'elan' in modules and table['id'] in tbls.get_table_map('elan'):
                    flow_dict = stale_elan_flow(flow, flow_info, ifaces, ifindexes, einsts, eifaces)
                if 'acl' in modules and table['id'] in tbls.get_table_map('acl'):
                    flow_dict = stale_acl_flow(flow, flow_info, ifaces, ifindexes, einsts, eifaces)
                if 'nat' in modules and table['id'] in tbls.get_table_map('nat'):
                    flow_dict = stale_nat_flow(flow, flow_info, ifaces, ifstates)
                if flow_dict.get('reason'):
                    stale_flows.append(flow_dict)
    return stale_flows
示例#7
0
文件: flows.py 项目: vthapar/odltools
def get_stale_flows(modules=['ifm']):
    if not modules:
        return 'No modules specified'
    ifaces = {}
    ifstates = {}
    ifindexes = {}
    # bindings = {}
    einsts = {}
    eifaces = {}
    fibentries = {}
    vpnids = {}
    vpninterfaces = {}
    groups = {}
    table_list = list(set([table for module in modules for table in tbls.get_table_map(module)]))
    # table_list = [214, 244]

    of_nodes = config.gmodels.odl_inventory_nodes.get_clist_by_key()
    if 'ifm' in modules:
        ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key()
    if 'l3vpn' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key()
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key()
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key()
        groups = groups or config.gmodels.odl_inventory_nodes.get_groups(of_nodes)
    if 'acl' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
    if 'elan' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
    stale_flows = []
    for node in of_nodes.values():
        tables = [x for x in node[Nodes.NODE_TABLE] if x['id'] in table_list]
        for table in tables:
            for flow in table.get('flow', []):
                flow_dict = None
                flow_info = {'dpnid': Model.get_dpn_from_ofnodeid(node['id'])}
                if 'ifm' in modules and table['id'] in tbls.get_table_map('ifm'):
                    flow_dict = stale_ifm_flow(flow, flow_info, ifaces, ifstates)
                if 'l3vpn' in modules and table['id'] in tbls.get_table_map('l3vpn'):
                    flow_dict = stale_l3vpn_flow(flow, flow_info, groups, ifaces, ifindexes, vpnids,
                                                 vpninterfaces, fibentries)
                if 'elan' in modules and table['id'] in tbls.get_table_map('elan'):
                    flow_dict = stale_elan_flow(flow, flow_info, ifaces, ifindexes, einsts, eifaces)
                if 'acl' in modules and table['id'] in tbls.get_table_map('acl'):
                    flow_dict = stale_acl_flow(flow, flow_info, ifaces, ifindexes, einsts, eifaces)
                if 'nat' in modules and table['id'] in tbls.get_table_map('nat'):
                    flow_dict = stale_nat_flow(flow, flow_info, ifaces, ifstates)
                if flow_dict.get('reason'):
                    stale_flows.append(flow_dict)
    return stale_flows
示例#8
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))
示例#9
0
文件: flows.py 项目: ww09/netvirt
def get_all_flows(args, modules=None, filter_by=None):
    modules = modules if modules else ['ifm']
    filter_by = filter_by if filter_by else []
    if not modules:
        return 'No modules specified'
    ifaces = {}
    ifstates = {}
    ifindexes = {}
    # bindings = {}
    einsts = {}
    eifaces = {}
    fibentries = {}
    vpnids = {}
    vpninterfaces = {}
    groups = {}
    if 'all' in modules:
        table_list = list(range(0, 255))
    else:
        table_list = list(
            set([table for mod in modules for table in TABLE_MAP[mod]]))
    # models = Models(args)
    # odl_inventory_nodes_config = opendaylight_inventory.nodes(Model.CONFIG, args)
    of_nodes = config.gmodels.odl_inventory_nodes_config.get_clist_by_key()
    # ietf_interfaces_interfaces = ietf_interfaces.interfaces(Model.CONFIG, args)
    # ietf_interfaces_interfaces_state = ietf_interfaces.interfaces_state(Model.OPERATIONAL, args)
    # odl_interface_meta_if_index_interface_map = odl_interface_meta.if_indexes_interface_map(Model.OPERATIONAL, args)
    # odl_fib_fib_entries = odl_fib.fib_entries(Model.CONFIG, args)
    # odl_l3vpn_vpn_instance_to_vpn_id = odl_l3vpn.vpn_instance_to_vpn_id(Model.CONFIG, args)
    if 'ifm' in modules:
        ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key(
        )
    if 'l3vpn' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key(
        )
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key(
        )
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key(
        )
        groups = groups or config.gmodels.odl_inventory_nodes_config.get_groups(
            of_nodes)
    if 'acl' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key(
        )
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_elan_interfaces_by_key(
        )
    if 'elan' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key(
        )
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_elan_interfaces_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
    if 'all' in modules:
        groups = groups or config.gmodels.odl_inventory_nodes_config.get_groups(
            of_nodes)
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        ifstates = ifstates or config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key(
        )
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key(
        )
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key(
        )
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key(
        )
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_elan_interfaces_by_key(
        )
    flows = []
    for node in of_nodes.itervalues():
        tables = [x for x in node[Nodes.NODE_TABLE] if x['id'] in table_list]
        for table in tables:
            for flow in table.get('flow', []):
                flow_info = {'dpnid': Model.get_dpn_from_ofnodeid(node['id'])}
                flow_dict = get_any_flow(flow, flow_info, groups, ifaces,
                                         ifstates, ifindexes, fibentries,
                                         vpnids, vpninterfaces, einsts,
                                         eifaces)
                if flow_dict is not None and filter_flow(flow_dict, filter_by):
                    flows.append(flow_dict)
    return flows
示例#10
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))
示例#11
0
def get_all_flows(args, modules=None, filter_by=None):
    config.get_models(args, {
        "elan_elan_instances",
        "elan_elan_interfaces",
        "ietf_interfaces_interfaces",
        "ietf_interfaces_interfaces_state",
        "l3vpn_vpn_interfaces",
        "odl_fib_fib_entries",
        "odl_interface_meta_if_index_interface_map",
        "odl_l3vpn_vpn_instance_to_vpn_id",
        "odl_inventory_nodes"})

    modules = modules if modules else "all"
    filter_by = filter_by if filter_by else []
    if not modules:
        return 'No modules specified'
    ifaces = {}
    ifstates = {}
    ifindexes = {}
    # bindings = {}
    einsts = {}
    eifaces = {}
    fibentries = {}
    vpnids = {}
    vpninterfaces = {}
    groups = {}
    if 'all' in modules:
        table_list = list(range(0, 255))
    else:
        table_list = list(set([table for mod in modules for table in tbls.get_table_map(mod)]))
    of_nodes = config.gmodels.odl_inventory_nodes.get_clist_by_key()
    if 'ifm' in modules:
        ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key()
    if 'l3vpn' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key()
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key()
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key()
        groups = groups or config.gmodels.odl_inventory_nodes.get_groups(of_nodes)
    if 'acl' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
    if 'elan' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
    if 'all' in modules:
        groups = groups or config.gmodels.odl_inventory_nodes.get_groups(of_nodes)
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifstates = ifstates or config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key()
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key()
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key()
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key()
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key()
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key()
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key()
    flows = []
    for node in of_nodes.values():
        tables = [x for x in node[Nodes.NODE_TABLE] if x['id'] in table_list]
        for table in tables:
            for flow in table.get('flow', []):
                flow_info = {'dpnid': Model.get_dpn_from_ofnodeid(node['id'])}
                flow_dict = get_any_flow(flow, flow_info, groups,
                                         ifaces, ifstates, ifindexes,
                                         fibentries, vpnids, vpninterfaces,
                                         einsts, eifaces)
                if flow_dict is not None and filter_flow(flow_dict, filter_by):
                    flows.append(flow_dict)
    return flows
示例#12
0
def get_all_flows(args, modules=None, filter_by=None):
    config.get_models(
        args, {
            "elan_elan_instances", "elan_elan_interfaces",
            "ietf_interfaces_interfaces", "ietf_interfaces_interfaces_state",
            "l3vpn_vpn_interfaces", "odl_fib_fib_entries",
            "odl_interface_meta_if_index_interface_map",
            "odl_l3vpn_vpn_instance_to_vpn_id", "odl_inventory_nodes"
        })

    modules = modules if modules else args.modules if args.modules else "all"
    filter_by = filter_by if filter_by else []
    if not modules:
        return 'No modules specified'
    ifaces = {}
    ifstates = {}
    ifindexes = {}
    # bindings = {}
    einsts = {}
    eifaces = {}
    fibentries = {}
    vpnids = {}
    vpninterfaces = {}
    groups = {}
    if 'all' in modules:
        table_list = list(range(0, 255))
    else:
        table_list = list(
            set([
                table for mod in modules for table in tbls.get_table_map(mod)
            ]))
    of_nodes = config.gmodels.odl_inventory_nodes.get_clist_by_key()
    if 'ifm' in modules:
        ifaces = config.gmodels.ietf_interfaces_interfaces.get_clist_by_key()
        ifstates = config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key(
        )
    if 'l3vpn' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key(
        )
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key(
        )
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key(
        )
        groups = groups or config.gmodels.odl_inventory_nodes.get_groups(
            of_nodes)
    if 'acl' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key(
        )
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key(
        )
    if 'elan' in modules:
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key(
        )
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
    if 'all' in modules:
        groups = groups or config.gmodels.odl_inventory_nodes.get_groups(
            of_nodes)
        ifaces = ifaces or config.gmodels.ietf_interfaces_interfaces.get_clist_by_key(
        )
        ifstates = ifstates or config.gmodels.ietf_interfaces_interfaces_state.get_clist_by_key(
        )
        ifindexes = ifindexes or config.gmodels.odl_interface_meta_if_index_interface_map.get_clist_by_key(
        )
        fibentries = fibentries or config.gmodels.odl_fib_fib_entries.get_vrf_entries_by_key(
        )
        vpnids = vpnids or config.gmodels.odl_l3vpn_vpn_instance_to_vpn_id.get_clist_by_key(
        )
        vpninterfaces = vpninterfaces or config.gmodels.l3vpn_vpn_interfaces.get_clist_by_key(
        )
        einsts = einsts or config.gmodels.elan_elan_instances.get_clist_by_key(
        )
        eifaces = eifaces or config.gmodels.elan_elan_interfaces.get_clist_by_key(
        )
    flows = []
    for node in of_nodes.values():
        tables = [x for x in node[Nodes.NODE_TABLE] if x['id'] in table_list]
        for table in tables:
            for odl_flow in table.get('flow', []):
                flow = OdlFlow(odl_flow)
                flow.pdata = {'dpnid': Model.get_dpn_from_ofnodeid(node['id'])}
                get_any_flow(flow, groups, ifaces, ifstates, ifindexes,
                             fibentries, vpnids, vpninterfaces, einsts,
                             eifaces)
                if flow.pdata is not None and filter_flow(
                        flow.pdata, filter_by):
                    flows.append(flow)
    return flows