Base net-virt CLI files on top of which ONOS specific changes will be done
diff --git a/cli/sdncon/ui/scripts/__init__.py b/cli/sdncon/ui/scripts/__init__.py
new file mode 100755
index 0000000..9ab2783
--- /dev/null
+++ b/cli/sdncon/ui/scripts/__init__.py
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+
diff --git a/cli/sdncon/ui/scripts/buildtopology.py b/cli/sdncon/ui/scripts/buildtopology.py
new file mode 100755
index 0000000..2d7e940
--- /dev/null
+++ b/cli/sdncon/ui/scripts/buildtopology.py
@@ -0,0 +1,124 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+#
+# Build a simple JSON of the topology for use in the ForceDirected
+# Visualization in the InfoVis Toolkit
+#
+
+#Importing modules
+import re
+import sys
+import time
+import json
+import urllib2
+import switchalias
+from sdncon.rest.views import do_switches, do_model_list, do_instance, do_device, do_links
+
+def build_topology_data(request):
+
+ # Query JSON from API and load into dictionary
+ switches = json.loads(do_switches(request).content)
+ devices = json.loads(do_device(request).content)
+ links = json.loads(do_links(request).content)
+ aliasDict = switchalias.aliasDict(request)
+
+ # Dictionaries
+ parsedswitch = []
+ parseddevices = []
+ parsedlinks = []
+
+ # Step through master 'switches' list, extract entry for each dictionary.
+ for index_switches,value1_switches in enumerate(switches):
+ tempdict = {}
+
+ # get needed entries in 'switches'
+ tempdict['dpid'] = value1_switches.get('dpid','')
+ tempdict['inetAddress'] = value1_switches.get('inetAddress','')
+
+ # append to final sorted output.
+ parsedswitch.append(tempdict)
+
+ # Step through master 'device' list, extract entry for each dictionary.
+ for index_devices,value1_devices in enumerate(devices):
+ tempdict = {}
+
+ # get needed entries in 'devices'
+ for index_mac,value_mac in enumerate(value1_devices['mac']):
+ tempdict['mac'] = value_mac
+ tempdict['ipv4'] = value1_devices.get('ipv4','Unknown')
+ for index_switch2,value_switch2 in enumerate(value1_devices['attachmentPoint']):
+ switchconnlist = []
+ switchtempdict = {}
+ if value_switch2.get('switchDPID', 'UNKNOWN') != '':
+ if value_switch2.get('port', 'UNKNOWN') != '':
+ switchtempdict['port'] = value_switch2['port']
+ switchtempdict['DPID'] = value_switch2['switchDPID']
+ switchconnlist.append(switchtempdict)
+ tempdict['attachments'] = switchconnlist
+ # append to final sorted output.
+ parseddevices.append(tempdict)
+
+
+ # Step through master 'links' list, extract entry for each dictionary.
+ for index_links,value1_links in enumerate(links):
+ tempdict = {}
+
+ # get needed entries in 'links'
+ tempdict['src-switch'] = value1_links.get('src-switch','')
+ tempdict['src-port'] = value1_links.get('src-port','')
+ tempdict['src-port-state'] = value1_links.get('src-port-state','')
+ tempdict['dst-switch'] = value1_links.get('dst-switch','')
+ tempdict['dst-port'] = value1_links.get('dst-port','')
+ tempdict['dst-port-state'] = value1_links.get('dst-port-state','')
+
+ # append to final sorted output.
+ parsedlinks.append(tempdict)
+
+ #Begin puting the data in the JSON list
+ jsonoutput = []
+ result = ''
+
+
+ # Print switches by themselves to handle orphaned switches.
+ for index_switch,value_switch in enumerate(parsedswitch):
+ adjacenciestmp = []
+ datatmp = {}
+
+ datatmp = { '$color': '#f15922', '$type': 'square', '$dim': '10'}
+ jsonoutput.append({'adjacencies': [], 'data': datatmp, 'id': value_switch['dpid'], 'name': aliasDict.get(value_switch['dpid'], value_switch['dpid'])})
+
+
+ # Determine host -> Switch links
+ for index_devices,value_devices in enumerate(parseddevices):
+ adjacenciestmp = []
+ datatmp = {}
+
+ for index_adj,value_adj in enumerate(value_devices.get('attachments', '')):
+ adjacenciestmp.append({'nodeTo': str(value_adj['DPID']), 'nodeFrom': value_devices['mac'], 'data': { '$color': '#fdb813', '$lineWidth': '3' }})
+ datatmp = { '$color': '#fdb813', '$type': 'circle', '$dim': '10'}
+ jsonoutput.append({'adjacencies': adjacenciestmp, 'data': datatmp, 'id': value_devices['mac'], 'name': value_devices['mac']})
+
+ # Determine Switch -> Switch links
+ for index_link,value_link in enumerate(parsedlinks):
+ adjacenciestmp = []
+ datatmp = {}
+ adjacenciestmp.append({'nodeTo': str(value_link['src-switch']), 'nodeFrom': value_link['dst-switch'], 'data': { '$color': '#f15922', '$lineWidth': '3' }})
+ datatmp = { '$color': '#f15922', '$type': 'square', '$dim': '10'}
+ jsonoutput.append({'adjacencies': adjacenciestmp, 'data': datatmp, 'id': value_link['dst-switch'], 'name': aliasDict.get(value_link['dst-switch'], value_link['dst-switch'])})
+
+ result += 'var json =' + json.dumps(jsonoutput, sort_keys=True, indent=4, separators=(',', ': ')) + ';'
+ return result
\ No newline at end of file
diff --git a/cli/sdncon/ui/scripts/showhost.py b/cli/sdncon/ui/scripts/showhost.py
new file mode 100755
index 0000000..9c72fb5
--- /dev/null
+++ b/cli/sdncon/ui/scripts/showhost.py
@@ -0,0 +1,106 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+#
+# Python script for querying API and displaying connected hosts in a table
+#
+#
+
+#Importing modules
+import re
+import sys
+import time
+import datetime
+import json
+import urllib2
+import switchalias
+from sdncon.rest.views import do_switches, do_model_list, do_instance, do_device
+
+def show_host_data(request):
+
+ # Query JSON from API and load into dictionary
+ switches = json.loads(do_switches(request).content)
+ switchdevices = json.loads(do_device(request).content)
+
+ # Dictionaries
+ sorteddict = []
+ aliasDict = switchalias.aliasDict(request)
+ unsortdict = []
+
+ # Step through master 'device' list, extract entry for each dictionary.
+ for index_devices,value1_devices in enumerate(switchdevices):
+ tempdict = {}
+ tempswitchdict = {}
+
+ # get needed entries in 'devices'
+ tempdict['mac'] = value1_devices.get('mac','')
+ tempdict['entityClass'] = value1_devices.get('entityClass','')
+ tempdict['vlan'] = value1_devices.get('vlan','')
+ tempdict['ipv4'] = value1_devices.get('ipv4','Unknown')
+ tempdict['switch'] = value1_devices.get('attachmentPoint','')
+ tempdict['lastSeen'] = value1_devices.get('lastSeen','')
+
+ # append to final sorted output.
+ unsortdict.append(tempdict)
+
+
+ sorteddict = sorted(unsortdict, key=lambda elem: "%s" % (elem['mac']))
+
+ #print sorteddict
+ #print time.strftime('%Y-%m-%d %H:%M:%S %Z', time.gmtime(sorteddict[0]['connectedSince'] / float(1000)))
+
+ result = ''
+ # Print table output
+ result += '<table id="showdeviceoutput" >'
+ result += '<tbody style="border-top: 0px;">'
+ result += '<tr><td>ID</td><td>MAC Address</td><td>Address Space</td><td>VLAN</td><td>IP</td><td>Switch</td><td>Last Seen</td></tr>'
+ for index_output,value_output in enumerate(sorteddict):
+ result += '<tr>'
+ result += ' <td>' + str(index_output + 1) + '</td>'
+ result += ' <td>'
+ for tmp_index,tmp_value in enumerate(value_output['mac']):
+ if tmp_index > 0:
+ result += ', ',
+ result += str(tmp_value)
+ result += '</td>'
+ result += ' <td>' + value_output.get('entityClass','') + '</td>'
+ result += ' <td>'
+ for tmp_index,tmp_value in enumerate(value_output['vlan']):
+ if tmp_index > 0:
+ result += ', ',
+ result += str(tmp_value)
+ result += '</td>'
+ result += ' <td>'
+ for tmp_index,tmp_value in enumerate(value_output['ipv4']):
+ if tmp_index > 0:
+ result += ', ',
+ result += str(tmp_value)
+ result += '</td>'
+ result += ' <td>'
+ for tmp_index,tmp_value in enumerate(value_output['switch']):
+ if tmp_index > 0:
+ result += ', ',
+ result += aliasDict.get(tmp_value.get('switchDPID', 'UNKNOWN'), tmp_value.get('switchDPID', 'UNKNOWN')) + ' Port ' + str(tmp_value.get('port', 'UNKNOWN'))
+ result += '</td>'
+ delta = round(time.time(),0) - (round(value_output.get('lastSeen',time.time()) / int(1000)))
+ if delta <= 0:
+ result += ' <td> Now </td>'
+ else:
+ result += ' <td>' + str(datetime.timedelta(seconds=delta)) + '</td>'
+ result += '</tr>'
+ result += '</tbody>'
+ result += '</table>'
+ return result
diff --git a/cli/sdncon/ui/scripts/showlink.py b/cli/sdncon/ui/scripts/showlink.py
new file mode 100755
index 0000000..4a91d50
--- /dev/null
+++ b/cli/sdncon/ui/scripts/showlink.py
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+#
+# Python script to query link states from REST API
+#
+#
+
+#Importing modules
+import re
+import sys
+import time
+import json
+import urllib2
+import switchalias
+from sdncon.rest.views import do_switches, do_model_list, do_instance, do_device, do_links
+
+
+def show_link_data(request):
+
+ # Query JSON from API and load into dictionary
+ switches = json.loads(do_switches(request).content)
+ switchlinks = json.loads(do_links(request).content)
+
+ # Dictionaries
+ sorteddict = []
+ aliasDict = switchalias.aliasDict(request)
+ unsortdict = []
+ statedict = {0: 'FORWARDING', 1: 'DOWN', 2: 'FORWARD', 3: 'BLOCK', 4: 'MASK'}
+
+ # Step through master 'links' list, extract entry for each dictionary.
+ for index_links,value1_links in enumerate(switchlinks):
+ tempdict = {}
+ tempswitchdict = {}
+
+ # get needed entries in 'links'
+ tempdict['src-switch'] = value1_links.get('src-switch','')
+ tempdict['src-port'] = value1_links.get('src-port','')
+ tempdict['src-port-state'] = value1_links.get('src-port-state','')
+ tempdict['dst-switch'] = value1_links.get('dst-switch','')
+ tempdict['dst-port'] = value1_links.get('dst-port','')
+ tempdict['dst-port-state'] = value1_links.get('dst-port-state','')
+ tempdict['type'] = value1_links.get('type','')
+
+ # append to final sorted output.
+ unsortdict.append(tempdict)
+
+
+ sorteddict = sorted(unsortdict, key=lambda elem: "%s %02d" % (elem['src-switch'], elem['src-port']))
+
+ result = ''
+ # Print table output
+ result += '<table id="showlinkoutput" >'
+ result += '<tbody>'
+ result += '<tr><td>ID</td><td>Source Switch</td><td>Source Port</td><td>Source Port State</td><td>Destination Switch</td><td>Destination Port</td><td>Destination Port State</td><td>Connection Type</td></tr>'
+ for index_output,value_output in enumerate(sorteddict):
+ result += '<tr>'
+ result += ' <td>' + str(index_output + 1) + '</td>'
+ result += ' <td>'
+ result += aliasDict.get(value_output.get('src-switch', 'UNKNOWN'), value_output.get('src-switch', 'UNKNOWN'))
+ result += '</td>'
+ result += ' <td>' + str(value_output.get('src-port','')) + '</td>'
+ result += ' <td>' + statedict.get(value_output.get('src-port-state',0),'DOWN') + '</td>'
+ result += ' <td>'
+ result += aliasDict.get(value_output.get('dst-switch', 'UNKNOWN'), value_output.get('dst-switch', 'UNKNOWN'))
+ result += '</td>'
+ result += ' <td>' + str(value_output.get('dst-port','')) + '</td>'
+ result += ' <td>' + statedict.get(value_output.get('dst-port-state',0),'DOWN') + '</td>'
+ result += ' <td>' + value_output.get('type','') + '</td>'
+ result += '</tr>'
+ result += '</tbody>'
+ result += '</table>'
+ return result
+
diff --git a/cli/sdncon/ui/scripts/showswitch.py b/cli/sdncon/ui/scripts/showswitch.py
new file mode 100755
index 0000000..8b8317e
--- /dev/null
+++ b/cli/sdncon/ui/scripts/showswitch.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+#
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# Python script for querying REST API and displaying connected switches in
+# a table
+#
+
+#Importing modules
+import re
+import sys
+import time
+import json
+import urllib2
+from sdncon.rest.views import do_switches, do_model_list, do_instance
+
+def show_switch_data(request):
+
+ switches = json.loads(do_switches(request).content)
+ switchaliases = json.loads(do_instance(request, 'switch-alias').content)
+ switchconfig = json.loads(do_instance(request, "switch-config").content)
+
+ # Dictionaries
+ sorteddict = []
+
+ # Step through master 'switches' list, extract entry for each dictionary.
+ for index_switches,value1_switches in enumerate(switches):
+ tempdict = {}
+ tempaliasdict = {}
+ tempconfigdict = {}
+
+ # get needed entries in 'switches'
+ tempdict['dpid'] = value1_switches.get('dpid','')
+ tempdict['inetAddress'] = value1_switches.get('inetAddress','')
+ tempdict['connectedSince'] = value1_switches.get('connectedSince','')
+
+ # get related entries in other JSON queries
+ for index_switchaliases,value1_switchaliases in enumerate(switchaliases):
+ if value1_switchaliases['switch'] == value1_switches['dpid']:
+ tempaliasdict['alias'] = value1_switchaliases.get('id','')
+ tempdict['alias'] = tempaliasdict.get('alias','')
+
+ for index_switchconfig,value1_switchconfig in enumerate(switchconfig):
+ if value1_switchconfig['dpid'] == value1_switches['dpid']:
+ tempconfigdict['core-switch'] = value1_switchconfig.get('core-switch','')
+ tempconfigdict['tunnel-termination'] = value1_switchconfig.get('tunnel-termination','')
+ tempdict['core-switch'] = tempconfigdict.get('core-switch','')
+ tempdict['tunnel-termination'] = tempconfigdict.get('tunnel-termination','')
+
+ # append to final sorted output.
+ sorteddict.append(tempdict)
+ sorteddict.reverse()
+
+ result = ''
+ # Print table output
+ result += '<table id="showswitchoutput">'
+ result += '<tbody>'
+ result += '<tr><td>ID</td><td>Alias</td><td>Switch DPID</td><td>IP Address</td><td>Connected Since</td></tr>'
+ for index_output,value_output in enumerate(sorteddict):
+ formatIPresult = re.search('/(.*):',value_output['inetAddress'])
+ result += '<tr>'
+ result += ' <td>' + str(index_output + 1) + '</td>'
+ result += ' <td>' + value_output.get('alias','') + '</td>'
+ result += ' <td>' + value_output.get('dpid','') + '</td>'
+ result += ' <td>' + formatIPresult.group(1) + '</td>'
+ if value_output['connectedSince'] != '':
+ result += ' <td>' + time.strftime('%Y-%m-%d %H:%M:%S %Z', time.gmtime(value_output['connectedSince'] / float(1000))) + '</td>'
+ else:
+ result += ' <td>Disconnected</td>'
+ result += '</tr>'
+ result += '</tbody>'
+ result += '</table>'
+
+ return result
+
diff --git a/cli/sdncon/ui/scripts/showtunnel.py b/cli/sdncon/ui/scripts/showtunnel.py
new file mode 100755
index 0000000..a8c0545
--- /dev/null
+++ b/cli/sdncon/ui/scripts/showtunnel.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+#
+# Python script to query tunnel states from REST API
+#
+#
+
+#Importing modules
+import re
+import sys
+import time
+import json
+import urllib2
+import switchalias
+from sdncon.rest.views import do_sdnplatform_tunnel_manager
+
+def show_tunnel_data(request):
+
+ # Query JSON from API and load into dictionary
+ tunnels = json.loads(do_sdnplatform_tunnel_manager(request,'all').content)
+
+ # Dictionaries
+ sorteddict = []
+ aliasDict = switchalias.aliasDict(request)
+ unsortdict = []
+ statedict = {0: 'FORWARDING', 1: 'DOWN', 2: 'FORWARD', 3: 'BLOCK', 4: 'MASK'}
+
+ # Step through master 'tunnels' list, extract entry for each dictionary.
+ for index_tunnels,value1_tunnels in tunnels.iteritems():
+ tempdict = {}
+ temptunneldict = {}
+
+ # get needed entries in 'links'
+ tempdict['dpid'] = value1_tunnels.get('hexDpid','')
+ tempdict['tunnelEnabled'] = value1_tunnels.get('tunnelEnabled','')
+ tempdict['tunnelIPAddr'] = value1_tunnels.get('tunnelIPAddr','')
+ tempdict['tunnelActive'] = value1_tunnels.get('tunnelActive','')
+ tempdict['tunnelState'] = value1_tunnels.get('tunnelState','')
+ tempdict['tunnelIf'] = value1_tunnels.get('tunnelEndPointIntfName','')
+ tempdict['tunnelCapable'] = value1_tunnels.get('tunnelCapable','')
+ # append to final sorted output.
+ if value1_tunnels.get('tunnelCapable',''):
+ unsortdict.append(tempdict)
+
+ sorteddict = sorted(unsortdict, key=lambda elem: "%s %s" % (elem['dpid'], elem['tunnelIPAddr']))
+
+ result = ''
+ # Print table output
+ result += '<table id="showtunneloutput" >'
+ result += '<tbody>'
+ result += '<tr><td>ID</td><td>Switch</td><td>Tunnel Source IP</td><td>Tunnel Interface</td><td>Tunnel Enabled</td><td>Tunnel State</td></tr>'
+
+ for index_output,value_output in enumerate(sorteddict):
+ result += '<tr>'
+ result += ' <td>' + str(index_output + 1) + '</td>'
+ result += ' <td>'
+ result += aliasDict.get(value_output.get('dpid', 'UNKNOWN'), value_output.get('dpid', 'UNKNOWN'))
+ result += '</td>'
+ result += ' <td>' + str(value_output.get('tunnelIPAddr','')) + '</td>'
+ result += ' <td>' + value_output.get('tunnelIf','UNKNOWN') + '</td>'
+ result += ' <td>' + str(value_output.get('tunnelActive','')) + '</td>'
+ result += ' <td>' + value_output.get('tunnelState','') + '</td>'
+ result += '</tr>'
+ result += '</tbody>'
+ result += '</table>'
+ return result
+
+
\ No newline at end of file
diff --git a/cli/sdncon/ui/scripts/switchalias.py b/cli/sdncon/ui/scripts/switchalias.py
new file mode 100755
index 0000000..768cf60
--- /dev/null
+++ b/cli/sdncon/ui/scripts/switchalias.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+#
+#
+# Copyright (c) 2013 Big Switch Networks, Inc.
+#
+# Licensed under the Eclipse Public License, Version 1.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# Query REST API, return dictionary with alias to DPID mappings.
+#
+
+#Importing modules
+import re
+import sys
+import json
+import urllib2
+from sdncon.rest.views import do_instance
+
+def aliasDict(request):
+
+ # Query JSON from API and load into dictionary
+ rawdict = json.loads(do_instance(request, 'switch-alias').content)
+
+ # Dictionaries
+ aliasdict = {}
+
+ # Step through master 'alias' list, extract entry for each dictionary.
+ for index_query,value1_query in enumerate(rawdict):
+
+ # get needed entries in 'alias'
+ aliasdict[value1_query.get('switch','ERR')] = value1_query.get('id',' ')
+
+ return aliasdict