Refactoring and Duplicate Id detection 58/67458/2
authorVishal Thapar <vishal.thapar@ericsson.com>
Tue, 23 Jan 2018 08:13:06 +0000 (13:43 +0530)
committerSam Hague <shague@redhat.com>
Sat, 10 Feb 2018 02:01:06 +0000 (02:01 +0000)
Change-Id: I4c76953a9dec8bf044374ae1a6dd6afb007bf4b2
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
resources/tools/odl/netvirt/constants.py
resources/tools/odl/netvirt/ds_analyze.py
resources/tools/odl/netvirt/ds_get_data.py
resources/tools/odl/netvirt/netvirt_utils.py

index f5c44d04f36034e6a31b20bc2b4f3beb0c20c608..b4286bce424d3571ddf0001a90bebc2c67a0f65c 100644 (file)
@@ -34,6 +34,8 @@ DSMAP = {
                        'elan-interfaces', 'elan-interface'],
     'fibentries': ['fibentries.log', 'config', 'odl-fib:fibEntries',
                    'fibEntries', 'vrfTables'],
+    'idpools': ['idpools.log', 'config', 'id-manager:id-pools',
+                      'id-pools', 'id-pool'],
     'ifconfig': ['iface-config.log', 'config', 'ietf-interfaces:interfaces',
                  'interfaces', 'interface'],
     'ifindexes': ['ifindexes.log', 'operational',
@@ -44,8 +46,6 @@ DSMAP = {
                 'interfaces-state', 'interface'],
     'inventory': ['inventory-config.log', 'config',
                   'opendaylight-inventory:nodes', 'nodes', 'node'],
-    'l3vpn': ['l3vpn-config.log', 'config', 'l3vpn:vpn-interfaces',
-              'vpn-interfaces', 'vpn-interface'],
     'neutronports': ['neutron-ports.log', 'config', 'neutron:neutron/ports',
                      'ports', 'port'],
     'neutronvpn-portip': ['neutronvpn-portip-port.log', 'config',
index 2f2dcf1eae2af83d1e5ee6d21b17f458a3574f1d..b182ef3d286f0f64531f0a1b765361e9cdafeb96 100644 (file)
@@ -19,7 +19,6 @@ operNodes = {}
 
 
 def by_ifname(ifname):
-    print ifname
     ifstate = ifstates.get(ifname)
     iface = ifaces.get(ifname)
     port = None
@@ -51,7 +50,7 @@ def analyze_interface(ifname=None):
     if not ifname:
         print_keys()
         exit(1)
-    ifname = ifname[1]
+    ifname = ifname[0]
     iface,ifstate,port,tunnel,tunState = by_ifname(ifname)
     print "InterfaceConfig: "
     utils.pretty_print(iface)
@@ -232,7 +231,7 @@ def show_link_flow_binding():
 def show_stale_flows(sort_by='table'):
     compute_map = get_dpn_host_mapping()
     nports = dsg.get_neutron_ports()
-    for flow in utils.sort(get_stale_flows(['acl']), sort_by):
+    for flow in utils.sort(get_stale_flows(['ifm', 'acl', 'elan', 'l3vpn']), sort_by):
         host = compute_map.get(flow.get('dpnid'), flow.get('dpnid'))
         ip_list = get_ips_for_iface(nports, flow.get('ifname'))
         if ip_list:
@@ -324,7 +323,7 @@ def show_all_flows():
             flow['table'], host, flow['id'],
             utils.show_optionals(flow))
         print result
-        print 'Flow:', json.dumps(parse_flow(flow['flow']))
+        #print 'Flow:', json.dumps(parse_flow(flow['flow']))
 
 
 def show_elan_flows():
@@ -338,6 +337,38 @@ def show_elan_instances():
     json.dumps(insts)
 
 
+def get_duplicate_ids():
+    duplicate_ids= {}
+    for pool in dsg.get_idpools().itervalues():
+        id_values = {}
+        for id_entry in pool.get('id-entries', []):
+            id_info = {}
+            id_value = id_entry.get('id-value')[0]
+            id_key = id_entry.get('id-key')
+            if id_values and id_values.get(id_value, None):
+                key_list = id_values.get(id_value)
+                key_list.append(id_key)
+                id_info['id-value'] = id_value
+                id_info['id-keys'] = key_list
+                id_info['pool-name'] = pool.get('pool-name')
+                id_info['parent-pool-name'] = pool.get('parent-pool-name')
+                duplicate_ids[id_value] = id_info
+            else:
+                id_values[id_value] = [id_key]
+    return duplicate_ids
+
+
+
+def show_idpools():
+    for k,v in get_duplicate_ids().iteritems():
+        result = "Id:{},Keys:{}".format(k, json.dumps(v.get('id-keys')))
+        if v.get('pool-name'):
+            result = "{},Pool:{}".format(result, v.get('pool-name'))
+        if v.get('parent-pool-name'):
+            result = "{},ParentPool:{}".format(result, v.get('parent-pool-name'))
+        print result
+
+
 def parse_flow(flow):
     #parse flow fields
     #hex(int(mask, 16) & int(data, 16))
index 10156ff76a533b091da0107f81c75d8eb7214dcc..c929901c0d651cd96ce7d5748ebd2d742657bf9c 100644 (file)
@@ -174,3 +174,11 @@ def get_vpninterfaces(filename=None):
     for vpninterface in vpninterfaces:
         vpninterfaces_dict[vpninterface['name']] = vpninterface
     return vpninterfaces_dict
+
+
+def get_idpools(filename=None):
+    idpools_dict = {}
+    idpools = get_ds_data('idpools')
+    for idpool in idpools:
+        idpools_dict[idpool['pool-name']] = idpool
+    return idpools_dict
index f9befa5833988700a66c029473c62484718ff4a8..9c6b92f25690b690237888f82dc2a494c27ad699 100644 (file)
@@ -99,7 +99,6 @@ def sort(data, field):
     return sorted(data, key=lambda x: x[field])
 
 
-
 def show_optionals(flow):
     result = ''
     lport = flow.get('lport')
@@ -120,3 +119,9 @@ def show_optionals(flow):
     result = '{},Reason:{}'.format(result, flow.get('reason'))
     return result
 
+
+def get_optionals(m_str):
+    if str:
+        return dict(s.split('=',1) for s in m_str.split(','))
+    return None
+