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)
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
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
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
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
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
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