Added router/switch name with DPID in show host and show link commands
diff --git a/cli/cli/c_actions.py b/cli/cli/c_actions.py
index 9a4e9d4..633b956 100755
--- a/cli/cli/c_actions.py
+++ b/cli/cli/c_actions.py
@@ -1722,6 +1722,7 @@
print result
else:
result = []
+ import fmtcnv
if (onos == 1) and (url == 'links'):
for entry in entries:
src = entry.get('src')
@@ -1731,10 +1732,10 @@
if cmp(dst, tempEntry.get('src')) == 0:
entries.remove(tempEntry)
result.append({
- 'src-switch' : entry['src']['dpid'],
+ 'src-switch' : fmtcnv.print_switch_and_alias(entry['src']['dpid']),
'src-port' : entry['src']['portNumber'],
'src-port-state' : 0,
- 'dst-switch' : entry['dst']['dpid'],
+ 'dst-switch' : fmtcnv.print_switch_and_alias(entry['dst']['dpid']),
'dst-port' : entry['dst']['portNumber'],
'dst-port-state' : 0,
'type' : entry['type'],
diff --git a/cli/cli/desc/version200/core.py b/cli/cli/desc/version200/core.py
index 4e255e5..c95e884 100755
--- a/cli/cli/desc/version200/core.py
+++ b/cli/cli/desc/version200/core.py
@@ -2548,7 +2548,7 @@
},
'fields': {
'dpid' : { 'verbose-name' : 'Router DPID',
- #'formatter' : fmtcnv.replace_switch_with_alias
+ #'formatter' : fmtcnv.eprint_switch_and_alias,
},
'name' : { 'verbose-name' : 'Router Name',
#'formatter' : fmtcnv.decode_port_counter
diff --git a/cli/cli/fmtcnv.py b/cli/cli/fmtcnv.py
index 1e53fe1..485dbf4 100644
--- a/cli/cli/fmtcnv.py
+++ b/cli/cli/fmtcnv.py
@@ -16,6 +16,9 @@
# sdnsh - The Controller Shell
+import urllib
+import urllib2
+
import base64
import struct
import time
@@ -26,6 +29,8 @@
import doctest
import traceback
import utif
+import command
+import json
# Timezone constants
@@ -52,6 +57,25 @@
alias_dicts = {}
+def get_switches_names(object, data =None):
+ """
+ return the switches name (for ONOS)
+ """
+ switches_dpid_name ={}
+ url = "http://127.0.0.1:8000/rest/v1/switches"
+ result = urllib2.urlopen(url).read()
+ #result = command.sdnsh.store.rest_simple_request(query_url)
+ entries = result
+ entries = json.loads(result)
+ #eprint entries
+ for switch in entries:
+ #print switch
+ switches_dpid_name[switch.get("dpid")] = switch.get("stringAttributes").get('name')
+ #print switch.get("dpid")
+ #print switch.get("stringAttributes").get('name')
+ return switches_dpid_name
+
+
def update_alias_dict(obj_type, dict):
"""
Update alias dictionaries: for switch, host, etc.
@@ -999,7 +1023,9 @@
if len(i) == 1:
if_name = decode_openflow_port(i[0]['ingress-port'],
data['attachment-points'][0])
- return replace_switch_with_alias(i[0]['switch']) + '/' + if_name
+ dpid = str(i[0]['switch'])
+ #print print_switch_and_alias(dpid, data)
+ return print_switch_and_alias(i[0]['switch']) + '/' + if_name
if len(i) == 0:
return ""
first = i[0]
@@ -1125,7 +1151,12 @@
dpid = str(i)
alias = replace_switch_with_alias(i, data)
if dpid == alias:
- return dpid
+ dpid_name = get_switches_names(object, data)
+ if i in dpid_name:
+ alias = dpid_name[i]
+ return dpid + ' (' + alias + ')'
+ else:
+ return dpid
else:
return dpid + ' (' + alias + ')'