Пример #1
0
def get_any_flow(flow, flow_info, groups, ifaces, ifstates, ifindexes,
                 fibentries, vpnids, vpninterfaces, einsts, eifaces):
    table = flow['table_id']
    if table in tbls.get_table_map('ifm'):
        return stale_ifm_flow(flow, flow_info, ifaces, ifstates)
    elif table in tbls.get_table_map('acl'):
        return stale_acl_flow(flow, flow_info, ifaces, ifindexes, einsts,
                              eifaces)
    elif table in tbls.get_table_map('elan'):
        return stale_elan_flow(flow, flow_info, ifaces, ifindexes, einsts,
                               eifaces)
    elif table in tbls.get_table_map('l3vpn'):
        return stale_l3vpn_flow(flow, flow_info, groups, ifaces, ifindexes,
                                vpnids, vpninterfaces, fibentries)
    elif table in tbls.get_table_map('nat'):
        return stale_nat_flow(flow, flow_info, ifaces, ifindexes)
    else:
        flow_info = flow_parser.get_flow_info_from_any(flow_info, flow)
        iface = (get_iface_for_lport(ifaces, ifindexes, flow_info.get('lport'))
                 if flow_info.get('lport') else None)
        if iface and iface.get('name'):
            flow_info['ifname'] = iface['name']
    # Get generic fields in here if not already captured
    # flow_info = flow_parser.get_flow_info_from_any(flow_info, flow)
    return create_flow_dict(flow_info, flow)
Пример #2
0
def get_any_flow(flow, groups, ifaces, ifstates, ifindexes, fibentries, vpnids,
                 vpninterfaces, einsts, eifaces):
    table = flow.rdata['table_id']
    if table in tbls.get_table_map('ifm'):
        return stale_ifm_flow(flow, ifaces, ifstates)
    elif table in tbls.get_table_map('acl'):
        return stale_acl_flow(flow, ifaces, ifindexes, einsts, eifaces)
    elif table in tbls.get_table_map('elan'):
        return stale_elan_flow(flow, ifaces, ifindexes, einsts, eifaces)
    elif table in tbls.get_table_map('l3vpn'):
        return stale_l3vpn_flow(flow, groups, ifaces, ifindexes, vpnids,
                                vpninterfaces, fibentries)
    elif table in tbls.get_table_map('nat'):
        return stale_nat_flow(flow, ifaces, ifindexes)
    else:
        flow_parser.get_flow_info_from_any(flow)
        iface = (get_iface_for_lport(ifaces, ifindexes,
                                     flow.pdata.get('lport'))
                 if flow.pdata.get('lport') else None)
        if iface and iface.get('name'):
            flow.pdata['ifname'] = iface['name']
Пример #3
0
def get_any_flow(flow, flow_info, groups, ifaces, ifstates, ifindexes,
                 fibentries, vpnids, vpninterfaces, einsts, eifaces):
    table = flow['table_id']
    if table in tbls.get_table_map('ifm'):
        return stale_ifm_flow(flow, flow_info, ifaces, ifstates)
    elif table in tbls.get_table_map('acl'):
        return stale_acl_flow(flow, flow_info, ifaces, ifindexes, einsts, eifaces)
    elif table in tbls.get_table_map('elan'):
        return stale_elan_flow(flow, flow_info, ifaces, ifindexes, einsts, eifaces)
    elif table in tbls.get_table_map('l3vpn'):
        return stale_l3vpn_flow(flow, flow_info, groups, ifaces, ifindexes, vpnids, vpninterfaces, fibentries)
    elif table in tbls.get_table_map('nat'):
        return stale_nat_flow(flow, flow_info, ifaces, ifindexes)
    else:
        flow_info = flow_parser.get_flow_info_from_any(flow_info, flow)
        iface = (get_iface_for_lport(ifaces, ifindexes, flow_info.get('lport'))
                 if flow_info.get('lport') else None)
        if iface and iface.get('name'):
            flow_info['ifname'] = iface['name']
    # Get generic fields in here if not already captured
    # flow_info = flow_parser.get_flow_info_from_any(flow_info, flow)
    return create_flow_dict(flow_info, flow)
Пример #4
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
Пример #5
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
Пример #6
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
Пример #7
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