Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | import pprint |
| 3 | import os |
| 4 | import sys |
| 5 | import subprocess |
| 6 | import json |
| 7 | import argparse |
| 8 | import io |
| 9 | import time |
| 10 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 11 | import re |
| 12 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 13 | from flask import Flask, json, Response, render_template, make_response, request |
| 14 | |
| 15 | ## Global Var ## |
Ubuntu | f6ce96c | 2013-02-07 01:45:07 +0000 | [diff] [blame] | 16 | RestIP="localhost" |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 17 | RestPort=8080 |
| 18 | #DBName="onos-network-map" |
Masayoshi Kobayashi | a9ed33a | 2013-03-27 23:14:18 +0000 | [diff] [blame] | 19 | |
| 20 | ## Uncomment the desired block based on your testbed environment |
| 21 | |
| 22 | # Settings for running on production |
| 23 | controllers=["onosgui1", "onosgui2", "onosgui3", "onosgui4", "onosgui5", "onosgui6", "onosgui7", "onosgui8"] |
| 24 | core_switches=["00:00:00:00:ba:5e:ba:11", "00:00:00:00:00:00:ba:12", "00:00:20:4e:7f:51:8a:35", "00:00:00:00:ba:5e:ba:13", "00:00:00:08:a2:08:f9:01", "00:00:00:16:97:08:9a:46"] |
| 25 | ONOS_GUI3_HOST="http://gui3.onlab.us:8080" |
| 26 | ONOS_GUI3_CONTROL_HOST="http://gui3.onlab.us:8081" |
| 27 | |
| 28 | # Settings for running on dev testbed. Replace dev |
| 29 | #controllers=["onosdevb1", "onosdevb2", "onosdevb3", "onosdevb4"] |
| 30 | #core_switches=["00:00:00:00:00:00:01:01", "00:00:00:00:00:00:01:02", "00:00:00:00:00:00:01:03", "00:00:00:00:00:00:01:04", "00:00:00:00:00:00:01:05", "00:00:00:00:00:00:01:06"] |
| 31 | #ONOS_GUI3_HOST="http://devb-gui.onlab.us:8080" |
| 32 | #ONOS_GUI3_CONTROL_HOST="http://devb-gui.onlab.us:8080" |
| 33 | |
| 34 | ONOS_LOCAL_HOST="http://localhost:8080" ;# for Amazon EC2 |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 35 | |
| 36 | nr_flow=0 |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 37 | |
| 38 | DEBUG=1 |
| 39 | pp = pprint.PrettyPrinter(indent=4) |
| 40 | |
| 41 | app = Flask(__name__) |
| 42 | |
| 43 | ## Worker Functions ## |
| 44 | def log_error(txt): |
| 45 | print '%s' % (txt) |
| 46 | |
| 47 | def debug(txt): |
| 48 | if DEBUG: |
| 49 | print '%s' % (txt) |
| 50 | |
| 51 | ## Rest APIs ## |
| 52 | ### File Fetch ### |
| 53 | @app.route('/ui/img/<filename>', methods=['GET']) |
| 54 | @app.route('/img/<filename>', methods=['GET']) |
| 55 | @app.route('/css/<filename>', methods=['GET']) |
| 56 | @app.route('/js/models/<filename>', methods=['GET']) |
| 57 | @app.route('/js/views/<filename>', methods=['GET']) |
| 58 | @app.route('/js/<filename>', methods=['GET']) |
| 59 | @app.route('/lib/<filename>', methods=['GET']) |
| 60 | @app.route('/', methods=['GET']) |
| 61 | @app.route('/<filename>', methods=['GET']) |
| 62 | @app.route('/tpl/<filename>', methods=['GET']) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 63 | @app.route('/ons-demo/<filename>', methods=['GET']) |
| 64 | @app.route('/ons-demo/js/<filename>', methods=['GET']) |
| 65 | @app.route('/ons-demo/css/<filename>', methods=['GET']) |
| 66 | @app.route('/ons-demo/assets/<filename>', methods=['GET']) |
| 67 | @app.route('/ons-demo/data/<filename>', methods=['GET']) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 68 | def return_file(filename="index.html"): |
| 69 | if request.path == "/": |
| 70 | fullpath = "./index.html" |
| 71 | else: |
| 72 | fullpath = str(request.path)[1:] |
| 73 | |
| 74 | response = make_response(open(fullpath).read()) |
| 75 | suffix = fullpath.split(".")[-1] |
| 76 | |
| 77 | if suffix == "html" or suffix == "htm": |
| 78 | response.headers["Content-type"] = "text/html" |
| 79 | elif suffix == "js": |
| 80 | response.headers["Content-type"] = "application/javascript" |
| 81 | elif suffix == "css": |
| 82 | response.headers["Content-type"] = "text/css" |
| 83 | elif suffix == "png": |
| 84 | response.headers["Content-type"] = "image/png" |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 85 | elif suffix == "svg": |
| 86 | response.headers["Content-type"] = "image/svg+xml" |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 87 | |
| 88 | return response |
| 89 | |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 90 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 91 | @app.route("/proxy/gui/link/<cmd>/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>") |
| 92 | def proxy_link_change(cmd, src_dpid, src_port, dst_dpid, dst_port): |
| 93 | try: |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 94 | command = "curl -s %s/gui/link/%s/%s/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, src_dpid, src_port, dst_dpid, dst_port) |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 95 | print command |
| 96 | result = os.popen(command).read() |
| 97 | except: |
| 98 | print "REST IF has issue" |
| 99 | exit |
| 100 | |
| 101 | resp = Response(result, status=200, mimetype='application/json') |
| 102 | return resp |
| 103 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 104 | @app.route("/proxy/gui/switch/<cmd>/<dpid>") |
| 105 | def proxy_switch_status_change(cmd, dpid): |
| 106 | try: |
| 107 | command = "curl -s %s/gui/switch/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, dpid) |
| 108 | print command |
| 109 | result = os.popen(command).read() |
| 110 | except: |
| 111 | print "REST IF has issue" |
| 112 | exit |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 113 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 114 | resp = Response(result, status=200, mimetype='application/json') |
| 115 | return resp |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 116 | |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 117 | @app.route("/proxy/gui/controller/<cmd>/<controller_name>") |
| 118 | def proxy_controller_status_change(cmd, controller_name): |
| 119 | try: |
| 120 | command = "curl -s %s/gui/controller/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, controller_name) |
| 121 | print command |
| 122 | result = os.popen(command).read() |
| 123 | except: |
| 124 | print "REST IF has issue" |
| 125 | exit |
| 126 | |
| 127 | resp = Response(result, status=200, mimetype='application/json') |
| 128 | return resp |
| 129 | |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 130 | @app.route("/wm/core/topology/switches/all/json") |
| 131 | def switches(): |
| 132 | if request.args.get('proxy') == None: |
| 133 | host = ONOS_LOCAL_HOST |
| 134 | else: |
| 135 | host = ONOS_GUI3_HOST |
| 136 | |
| 137 | try: |
| 138 | command = "curl -s %s/wm/core/topology/switches/all/json" % (host) |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 139 | # print command |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 140 | result = os.popen(command).read() |
| 141 | except: |
| 142 | print "REST IF has issue" |
| 143 | exit |
| 144 | |
| 145 | resp = Response(result, status=200, mimetype='application/json') |
| 146 | return resp |
| 147 | |
| 148 | @app.route("/wm/core/topology/links/json") |
| 149 | def links(): |
| 150 | if request.args.get('proxy') == None: |
| 151 | host = ONOS_LOCAL_HOST |
| 152 | else: |
| 153 | host = ONOS_GUI3_HOST |
| 154 | |
| 155 | try: |
| 156 | command = "curl -s %s/wm/core/topology/links/json" % (host) |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 157 | print command |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 158 | result = os.popen(command).read() |
| 159 | except: |
| 160 | print "REST IF has issue" |
| 161 | exit |
| 162 | |
| 163 | resp = Response(result, status=200, mimetype='application/json') |
| 164 | return resp |
| 165 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 166 | @app.route("/wm/flow/getsummary/0/0/json") |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 167 | def flows(): |
| 168 | if request.args.get('proxy') == None: |
| 169 | host = ONOS_LOCAL_HOST |
| 170 | else: |
| 171 | host = ONOS_GUI3_HOST |
| 172 | |
| 173 | try: |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 174 | command = "curl -s %s/wm/flow/getsummary/0/0/json" % (host) |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 175 | # print command |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 176 | result = os.popen(command).read() |
| 177 | except: |
| 178 | print "REST IF has issue" |
| 179 | exit |
| 180 | |
| 181 | resp = Response(result, status=200, mimetype='application/json') |
| 182 | return resp |
| 183 | |
| 184 | @app.route("/wm/registry/controllers/json") |
| 185 | def registry_controllers(): |
| 186 | if request.args.get('proxy') == None: |
| 187 | host = ONOS_LOCAL_HOST |
| 188 | else: |
| 189 | host = ONOS_GUI3_HOST |
| 190 | |
| 191 | try: |
| 192 | command = "curl -s %s/wm/registry/controllers/json" % (host) |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 193 | # print command |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 194 | result = os.popen(command).read() |
| 195 | except: |
| 196 | print "REST IF has issue" |
| 197 | exit |
| 198 | |
| 199 | resp = Response(result, status=200, mimetype='application/json') |
| 200 | return resp |
| 201 | |
| 202 | @app.route("/wm/registry/switches/json") |
| 203 | def registry_switches(): |
| 204 | if request.args.get('proxy') == None: |
| 205 | host = ONOS_LOCAL_HOST |
| 206 | else: |
| 207 | host = ONOS_GUI3_HOST |
| 208 | |
| 209 | try: |
| 210 | command = "curl -s %s/wm/registry/switches/json" % (host) |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 211 | # print command |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 212 | result = os.popen(command).read() |
| 213 | except: |
| 214 | print "REST IF has issue" |
| 215 | exit |
| 216 | |
| 217 | resp = Response(result, status=200, mimetype='application/json') |
| 218 | return resp |
| 219 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 220 | |
| 221 | def node_id(switch_array, dpid): |
| 222 | id = -1 |
| 223 | for i, val in enumerate(switch_array): |
| 224 | if val['name'] == dpid: |
| 225 | id = i |
| 226 | break |
| 227 | |
| 228 | return id |
| 229 | |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 230 | ## API for ON.Lab local GUI ## |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 231 | @app.route('/topology', methods=['GET']) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 232 | def topology_for_gui(): |
| 233 | try: |
| 234 | command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort) |
| 235 | result = os.popen(command).read() |
| 236 | parsedResult = json.loads(result) |
| 237 | except: |
| 238 | log_error("REST IF has issue: %s" % command) |
| 239 | log_error("%s" % result) |
| 240 | sys.exit(0) |
| 241 | |
| 242 | topo = {} |
| 243 | switches = [] |
| 244 | links = [] |
Ubuntu | 37ebda6 | 2013-03-01 00:35:31 +0000 | [diff] [blame] | 245 | devices = [] |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 246 | |
| 247 | for v in parsedResult: |
| 248 | if v.has_key('dpid'): |
| 249 | # if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes |
| 250 | dpid = str(v['dpid']) |
| 251 | state = str(v['state']) |
| 252 | sw = {} |
| 253 | sw['name']=dpid |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 254 | sw['group']= -1 |
Ubuntu | 37ebda6 | 2013-03-01 00:35:31 +0000 | [diff] [blame] | 255 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 256 | if state == "INACTIVE": |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 257 | sw['group']=0 |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 258 | switches.append(sw) |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 259 | |
Ubuntu | 37ebda6 | 2013-03-01 00:35:31 +0000 | [diff] [blame] | 260 | ## Comment in if we need devies |
| 261 | # sw_index = len(switches) - 1 |
| 262 | # for p in v['ports']: |
| 263 | # for d in p['devices']: |
| 264 | # device = {} |
| 265 | # device['attached_switch']=dpid |
| 266 | # device['name']=d['mac'] |
| 267 | # if d['state'] == "ACTIVE": |
| 268 | # device['group']=1000 |
| 269 | # else: |
| 270 | # device['group']=1001 |
| 271 | # |
| 272 | # switches.append(device) |
| 273 | # device_index = len (switches) -1 |
| 274 | # link = {} |
| 275 | # link['source'] = device_index |
| 276 | # link['target'] = sw_index |
| 277 | # link['type'] = -1 |
| 278 | # links.append(link) |
| 279 | # link = {} |
| 280 | # link['source'] = sw_index |
| 281 | # link['target'] = device_index |
| 282 | # link['type'] = -1 |
| 283 | # links.append(link) |
| 284 | |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 285 | # try: |
| 286 | # command = "curl -s \'http://%s:%s/wm/registry/controllers/json\'" % (RestIP, RestPort) |
| 287 | # result = os.popen(command).read() |
| 288 | # controllers = json.loads(result) |
| 289 | # except: |
| 290 | # log_error("xx REST IF has issue: %s" % command) |
| 291 | # log_error("%s" % result) |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 292 | |
| 293 | try: |
| 294 | command = "curl -s \'http://%s:%s/wm/registry/switches/json\'" % (RestIP, RestPort) |
| 295 | result = os.popen(command).read() |
| 296 | parsedResult = json.loads(result) |
| 297 | except: |
| 298 | log_error("REST IF has issue: %s" % command) |
| 299 | log_error("%s" % result) |
| 300 | |
| 301 | for key in parsedResult: |
| 302 | dpid = key |
| 303 | ctrl = parsedResult[dpid][0]['controllerId'] |
| 304 | sw_id = node_id(switches, dpid) |
| 305 | if sw_id != -1: |
| 306 | if switches[sw_id]['group'] != 0: |
| 307 | switches[sw_id]['group'] = controllers.index(ctrl) + 1 |
| 308 | |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 309 | try: |
| 310 | v1 = "00:00:00:00:00:0a:0d:00" |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 311 | # v1 = "00:00:00:00:00:0d:00:d1" |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 312 | p1=1 |
| 313 | v2 = "00:00:00:00:00:0b:0d:03" |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 314 | # v2 = "00:00:00:00:00:0d:00:d3" |
| 315 | p2=1 |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 316 | command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2) |
| 317 | result = os.popen(command).read() |
| 318 | parsedResult = json.loads(result) |
| 319 | except: |
| 320 | log_error("No route") |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 321 | parsedResult = {} |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 322 | |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 323 | path = [] |
| 324 | if parsedResult.has_key('flowEntries'): |
| 325 | flowEntries= parsedResult['flowEntries'] |
| 326 | for i, v in enumerate(flowEntries): |
| 327 | if i < len(flowEntries) - 1: |
| 328 | sdpid= flowEntries[i]['dpid']['value'] |
| 329 | ddpid = flowEntries[i+1]['dpid']['value'] |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 330 | path.append( (sdpid, ddpid)) |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 331 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 332 | try: |
| 333 | command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort) |
| 334 | result = os.popen(command).read() |
| 335 | parsedResult = json.loads(result) |
| 336 | except: |
| 337 | log_error("REST IF has issue: %s" % command) |
| 338 | log_error("%s" % result) |
| 339 | sys.exit(0) |
| 340 | |
| 341 | for v in parsedResult: |
| 342 | link = {} |
| 343 | if v.has_key('dst-switch'): |
| 344 | dst_dpid = str(v['dst-switch']) |
| 345 | dst_id = node_id(switches, dst_dpid) |
| 346 | if v.has_key('src-switch'): |
| 347 | src_dpid = str(v['src-switch']) |
| 348 | src_id = node_id(switches, src_dpid) |
| 349 | link['source'] = src_id |
| 350 | link['target'] = dst_id |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 351 | |
| 352 | onpath = 0 |
| 353 | for (s,d) in path: |
| 354 | if s == v['src-switch'] and d == v['dst-switch']: |
| 355 | onpath = 1 |
| 356 | break |
| 357 | link['type'] = onpath |
| 358 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 359 | links.append(link) |
| 360 | |
| 361 | topo['nodes'] = switches |
| 362 | topo['links'] = links |
| 363 | |
Ubuntu | 37ebda6 | 2013-03-01 00:35:31 +0000 | [diff] [blame] | 364 | pp.pprint(topo) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 365 | js = json.dumps(topo) |
| 366 | resp = Response(js, status=200, mimetype='application/json') |
| 367 | return resp |
| 368 | |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 369 | #@app.route("/wm/topology/toporoute/00:00:00:00:00:a1/2/00:00:00:00:00:c1/3/json") |
| 370 | #@app.route("/wm/topology/toporoute/<srcdpid>/<srcport>/<destdpid>/<destport>/json") |
| 371 | @app.route("/wm/topology/toporoute/<v1>/<p1>/<v2>/<p2>/json") |
| 372 | def shortest_path(v1, p1, v2, p2): |
| 373 | try: |
| 374 | command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort) |
| 375 | result = os.popen(command).read() |
| 376 | parsedResult = json.loads(result) |
| 377 | except: |
| 378 | log_error("REST IF has issue: %s" % command) |
| 379 | log_error("%s" % result) |
| 380 | sys.exit(0) |
| 381 | |
| 382 | topo = {} |
| 383 | switches = [] |
| 384 | links = [] |
| 385 | |
| 386 | for v in parsedResult: |
| 387 | if v.has_key('dpid'): |
| 388 | dpid = str(v['dpid']) |
| 389 | state = str(v['state']) |
| 390 | sw = {} |
| 391 | sw['name']=dpid |
| 392 | if str(v['state']) == "ACTIVE": |
| 393 | if dpid[-2:-1] == "a": |
| 394 | sw['group']=1 |
| 395 | if dpid[-2:-1] == "b": |
| 396 | sw['group']=2 |
| 397 | if dpid[-2:-1] == "c": |
| 398 | sw['group']=3 |
| 399 | if str(v['state']) == "INACTIVE": |
| 400 | sw['group']=0 |
| 401 | |
| 402 | switches.append(sw) |
| 403 | |
| 404 | try: |
| 405 | command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2) |
| 406 | result = os.popen(command).read() |
| 407 | parsedResult = json.loads(result) |
| 408 | except: |
| 409 | log_error("No route") |
| 410 | parsedResult = [] |
| 411 | # exit(1) |
| 412 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 413 | path = []; |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 414 | for i, v in enumerate(parsedResult): |
| 415 | if i < len(parsedResult) - 1: |
| 416 | sdpid= parsedResult[i]['switch'] |
| 417 | ddpid = parsedResult[i+1]['switch'] |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 418 | path.append( (sdpid, ddpid)) |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 419 | |
| 420 | try: |
| 421 | command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort) |
| 422 | result = os.popen(command).read() |
| 423 | parsedResult = json.loads(result) |
| 424 | except: |
| 425 | log_error("REST IF has issue: %s" % command) |
| 426 | log_error("%s" % result) |
| 427 | sys.exit(0) |
| 428 | |
| 429 | for v in parsedResult: |
| 430 | link = {} |
| 431 | if v.has_key('dst-switch'): |
| 432 | dst_dpid = str(v['dst-switch']) |
| 433 | dst_id = node_id(switches, dst_dpid) |
| 434 | if v.has_key('src-switch'): |
| 435 | src_dpid = str(v['src-switch']) |
| 436 | src_id = node_id(switches, src_dpid) |
| 437 | link['source'] = src_id |
| 438 | link['target'] = dst_id |
| 439 | onpath = 0 |
| 440 | for (s,d) in path: |
| 441 | if s == v['src-switch'] and d == v['dst-switch']: |
| 442 | onpath = 1 |
| 443 | break |
| 444 | |
| 445 | link['type'] = onpath |
| 446 | links.append(link) |
| 447 | |
| 448 | topo['nodes'] = switches |
| 449 | topo['links'] = links |
| 450 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 451 | # pp.pprint(topo) |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 452 | js = json.dumps(topo) |
| 453 | resp = Response(js, status=200, mimetype='application/json') |
| 454 | return resp |
| 455 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 456 | @app.route("/wm/core/controller/switches/json") |
| 457 | def query_switch(): |
| 458 | try: |
| 459 | command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort) |
| 460 | # http://localhost:8080/wm/core/topology/switches/active/json |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 461 | print command |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 462 | result = os.popen(command).read() |
| 463 | parsedResult = json.loads(result) |
| 464 | except: |
| 465 | log_error("REST IF has issue: %s" % command) |
| 466 | log_error("%s" % result) |
| 467 | sys.exit(0) |
| 468 | |
| 469 | # print command |
| 470 | # print result |
| 471 | switches_ = [] |
| 472 | for v in parsedResult: |
| 473 | if v.has_key('dpid'): |
| 474 | if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes |
| 475 | dpid = str(v['dpid']) |
| 476 | state = str(v['state']) |
| 477 | sw = {} |
| 478 | sw['dpid']=dpid |
| 479 | sw['active']=state |
| 480 | switches_.append(sw) |
| 481 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 482 | # pp.pprint(switches_) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 483 | js = json.dumps(switches_) |
| 484 | resp = Response(js, status=200, mimetype='application/json') |
| 485 | return resp |
| 486 | |
| 487 | @app.route("/wm/device/") |
| 488 | def devices(): |
| 489 | try: |
| 490 | command = "curl -s http://%s:%s/graphs/%s/vertices\?key=type\&value=device" % (RestIP, RestPort, DBName) |
| 491 | result = os.popen(command).read() |
| 492 | parsedResult = json.loads(result)['results'] |
| 493 | except: |
| 494 | log_error("REST IF has issue: %s" % command) |
| 495 | log_error("%s" % result) |
| 496 | sys.exit(0) |
| 497 | |
| 498 | devices = [] |
| 499 | for v in parsedResult: |
| 500 | dl_addr = v['dl_addr'] |
| 501 | nw_addr = v['nw_addr'] |
| 502 | vertex = v['_id'] |
| 503 | mac = [] |
| 504 | mac.append(dl_addr) |
| 505 | ip = [] |
| 506 | ip.append(nw_addr) |
| 507 | device = {} |
| 508 | device['entryClass']="DefaultEntryClass" |
| 509 | device['mac']=mac |
| 510 | device['ipv4']=ip |
| 511 | device['vlan']=[] |
| 512 | device['lastSeen']=0 |
| 513 | attachpoints =[] |
| 514 | |
| 515 | port, dpid = deviceV_to_attachpoint(vertex) |
| 516 | attachpoint = {} |
| 517 | attachpoint['port']=port |
| 518 | attachpoint['switchDPID']=dpid |
| 519 | attachpoints.append(attachpoint) |
| 520 | device['attachmentPoint']=attachpoints |
| 521 | devices.append(device) |
| 522 | |
| 523 | print devices |
| 524 | js = json.dumps(devices) |
| 525 | resp = Response(js, status=200, mimetype='application/json') |
| 526 | return resp |
| 527 | |
| 528 | #{"entityClass":"DefaultEntityClass","mac":["7c:d1:c3:e0:8c:a3"],"ipv4":["192.168.2.102","10.1.10.35"],"vlan":[],"attachmentPoint":[{"port":13,"switchDPID":"00:01:00:12:e2:78:32:44","errorStatus":null}],"lastSeen":1357333593496} |
| 529 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 530 | ## return fake stat for now |
| 531 | @app.route("/wm/core/switch/<switchId>/<statType>/json") |
| 532 | def switch_stat(switchId, statType): |
| 533 | if statType == "desc": |
| 534 | desc=[{"length":1056,"serialNumber":"None","manufacturerDescription":"Nicira Networks, Inc.","hardwareDescription":"Open vSwitch","softwareDescription":"1.4.0+build0","datapathDescription":"None"}] |
| 535 | ret = {} |
| 536 | ret[switchId]=desc |
| 537 | elif statType == "aggregate": |
| 538 | aggr = {"packetCount":0,"byteCount":0,"flowCount":0} |
| 539 | ret = {} |
| 540 | ret[switchId]=aggr |
| 541 | else: |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 542 | ret = {} |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 543 | |
| 544 | js = json.dumps(ret) |
| 545 | resp = Response(js, status=200, mimetype='application/json') |
| 546 | return resp |
| 547 | |
| 548 | |
| 549 | @app.route("/wm/topology/links/json") |
| 550 | def query_links(): |
| 551 | try: |
| 552 | command = 'curl -s http://%s:%s/graphs/%s/vertices?key=type\&value=port' % (RestIP, RestPort, DBName) |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 553 | print command |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 554 | result = os.popen(command).read() |
| 555 | parsedResult = json.loads(result)['results'] |
| 556 | except: |
| 557 | log_error("REST IF has issue: %s" % command) |
| 558 | log_error("%s" % result) |
| 559 | sys.exit(0) |
| 560 | |
| 561 | debug("query_links %s" % command) |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 562 | # pp.pprint(parsedResult) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 563 | sport = [] |
| 564 | links = [] |
| 565 | for v in parsedResult: |
| 566 | srcport = v['_id'] |
| 567 | try: |
| 568 | command = "curl -s http://%s:%s/graphs/%s/vertices/%d/out?_label=link" % (RestIP, RestPort, DBName, srcport) |
| 569 | print command |
| 570 | result = os.popen(command).read() |
| 571 | linkResults = json.loads(result)['results'] |
| 572 | except: |
| 573 | log_error("REST IF has issue: %s" % command) |
| 574 | log_error("%s" % result) |
| 575 | sys.exit(0) |
| 576 | |
| 577 | for p in linkResults: |
| 578 | if p.has_key('type') and p['type'] == "port": |
| 579 | dstport = p['_id'] |
| 580 | (sport, sdpid) = portV_to_port_dpid(srcport) |
| 581 | (dport, ddpid) = portV_to_port_dpid(dstport) |
| 582 | link = {} |
| 583 | link["src-switch"]=sdpid |
| 584 | link["src-port"]=sport |
| 585 | link["src-port-state"]=0 |
| 586 | link["dst-switch"]=ddpid |
| 587 | link["dst-port"]=dport |
| 588 | link["dst-port-state"]=0 |
| 589 | link["type"]="internal" |
| 590 | links.append(link) |
| 591 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 592 | # pp.pprint(links) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 593 | js = json.dumps(links) |
| 594 | resp = Response(js, status=200, mimetype='application/json') |
| 595 | return resp |
| 596 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 597 | topo_less = { |
| 598 | "nodes" : [ |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 599 | {"name" : "00:a0", "group" : 1}, |
| 600 | {"name" : "00:a1", "group" : 1}, |
| 601 | {"name" : "00:a2", "group" : 1}, |
| 602 | ], |
| 603 | "links" : [ |
| 604 | {"source" :0, "target": 1}, |
| 605 | {"source" :1, "target": 0}, |
| 606 | {"source" :0, "target": 2}, |
| 607 | {"source" :2, "target": 0}, |
| 608 | {"source" :1, "target": 2}, |
| 609 | {"source" :2, "target": 1}, |
| 610 | ] |
| 611 | } |
| 612 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 613 | topo_more = { |
| 614 | "nodes" : [ |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 615 | {"name" : "00:a3", "group" : 2}, |
| 616 | {"name" : "00:a0", "group" : 1}, |
| 617 | {"name" : "00:a1", "group" : 1}, |
| 618 | {"name" : "00:a2", "group" : 1}, |
| 619 | ], |
| 620 | "links" : [ |
| 621 | {"source" :1, "target": 2}, |
| 622 | {"source" :2, "target": 1}, |
| 623 | {"source" :1, "target": 3}, |
| 624 | {"source" :3, "target": 1}, |
| 625 | {"source" :2, "target": 3}, |
| 626 | {"source" :3, "target": 2}, |
| 627 | {"source" :0, "target": 2}, |
| 628 | ] |
| 629 | } |
| 630 | |
| 631 | @app.route("/topology_more") |
| 632 | def topology_more(): |
| 633 | topo = topo_more |
| 634 | js = json.dumps(topo) |
| 635 | resp = Response(js, status=200, mimetype='application/json') |
| 636 | return resp |
| 637 | |
| 638 | @app.route("/topology_less") |
| 639 | def topology_less(): |
| 640 | topo = topo_less |
| 641 | js = json.dumps(topo) |
| 642 | resp = Response(js, status=200, mimetype='application/json') |
| 643 | return resp |
| 644 | |
| 645 | cont_status1 = [ |
| 646 | {"name":"onos9vpc", "onos": 1, "cassandra": 1}, |
| 647 | {"name":"onos10vpc", "onos": 0, "cassandra": 1}, |
| 648 | {"name":"onos11vpc", "onos": 1, "cassandra": 0}, |
| 649 | {"name":"onos12vpc", "onos": 1, "cassandra": 0}] |
| 650 | |
| 651 | cont_status2 = [ |
| 652 | {"name":"onos9vpc", "onos": 0, "cassandra": 1}, |
| 653 | {"name":"onos10vpc", "onos": 0, "cassandra": 1}, |
| 654 | {"name":"onos11vpc", "onos": 0, "cassandra": 1}, |
| 655 | {"name":"onos12vpc", "onos": 0, "cassandra": 1}] |
| 656 | |
| 657 | @app.route("/controller_status1") |
| 658 | def controller_status1(): |
| 659 | status = cont_status1 |
| 660 | js = json.dumps(status) |
| 661 | resp = Response(js, status=200, mimetype='application/json') |
| 662 | pp.pprint(resp) |
| 663 | return resp |
| 664 | |
| 665 | @app.route("/controller_status2") |
| 666 | def controller_status2(): |
| 667 | status = cont_status2 |
| 668 | js = json.dumps(status) |
| 669 | resp = Response(js, status=200, mimetype='application/json') |
| 670 | pp.pprint(resp) |
| 671 | return resp |
| 672 | |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 673 | @app.route("/controller_status") |
| 674 | def controller_status(): |
| 675 | onos_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh status | awk '{print $1}'" |
| 676 | #cassandra_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-cassandra.sh status" |
| 677 | |
| 678 | cont_status=[] |
| 679 | for i in controllers: |
| 680 | status={} |
| 681 | onos=os.popen(onos_check % i).read()[:-1] |
| 682 | status["name"]=i |
| 683 | status["onos"]=onos |
Masayoshi Kobayashi | 5e91bdf | 2013-03-15 01:22:51 +0000 | [diff] [blame] | 684 | status["cassandra"]=0 |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 685 | cont_status.append(status) |
| 686 | |
| 687 | js = json.dumps(cont_status) |
| 688 | resp = Response(js, status=200, mimetype='application/json') |
| 689 | pp.pprint(js) |
| 690 | return resp |
| 691 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 692 | @app.route("/gui/controller/<cmd>/<controller_name>") |
| 693 | def controller_status_change(cmd, controller_name): |
| 694 | start_onos="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh start" % (controller_name) |
| 695 | stop_onos="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh stop" % (controller_name) |
| 696 | |
| 697 | if cmd == "up": |
Masayoshi Kobayashi | c0bc319 | 2013-03-27 23:12:03 +0000 | [diff] [blame] | 698 | print start_onos |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 699 | result=os.popen(start_onos).read() |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 700 | ret = "controller %s is up" % (controller_name) |
| 701 | elif cmd == "down": |
Masayoshi Kobayashi | c0bc319 | 2013-03-27 23:12:03 +0000 | [diff] [blame] | 702 | print stop_onos |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 703 | result=os.popen(stop_onos).read() |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 704 | ret = "controller %s is down" % (controller_name) |
| 705 | |
| 706 | return ret |
| 707 | |
| 708 | @app.route("/gui/switch/<cmd>/<dpid>") |
| 709 | def switch_status_change(cmd, dpid): |
| 710 | r = re.compile(':') |
| 711 | dpid = re.sub(r, '', dpid) |
Masayoshi Kobayashi | c0bc319 | 2013-03-27 23:12:03 +0000 | [diff] [blame] | 712 | host=controllers[0] |
| 713 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./switch.sh %s %s'" % (host, dpid, cmd) |
| 714 | get_status="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./switch.sh %s'" % (host, dpid) |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 715 | print "cmd_string" |
| 716 | |
| 717 | if cmd =="up" or cmd=="down": |
| 718 | print "make dpid %s %s" % (dpid, cmd) |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 719 | os.popen(cmd_string) |
| 720 | result=os.popen(get_status).read() |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 721 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 722 | return result |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 723 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 724 | #* Link Up |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 725 | #http://localhost:9000/gui/link/up/<src_dpid>/<src_port>/<dst_dpid>/<dst_port> |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 726 | @app.route("/gui/link/up/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>") |
| 727 | def link_up(src_dpid, src_port, dst_dpid, dst_port): |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 728 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 729 | cmd = 'up' |
| 730 | result="" |
| 731 | |
| 732 | for dpid in (src_dpid, dst_dpid): |
| 733 | if dpid in core_switches: |
| 734 | host = controllers[0] |
| 735 | src_ports = [1, 2, 3, 4, 5] |
| 736 | else: |
| 737 | hostid=int(src_dpid.split(':')[-2]) |
| 738 | host = controllers[hostid-1] |
| 739 | if hostid == 2 : |
| 740 | src_ports = [51] |
| 741 | else : |
| 742 | src_ports = [26] |
| 743 | |
| 744 | for port in src_ports : |
| 745 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./link.sh %s %s %s'" % (host, dpid, port, cmd) |
| 746 | print cmd_string |
| 747 | res=os.popen(cmd_string).read() |
| 748 | result = result + ' ' + res |
| 749 | |
| 750 | return result |
| 751 | |
| 752 | |
| 753 | #* Link Down |
| 754 | #http://localhost:9000/gui/link/down/<src_dpid>/<src_port>/<dst_dpid>/<dst_port> |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 755 | @app.route("/gui/link/<cmd>/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>") |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 756 | def link_down(cmd, src_dpid, src_port, dst_dpid, dst_port): |
| 757 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 758 | if src_dpid in core_switches: |
| 759 | host = controllers[0] |
| 760 | else: |
| 761 | hostid=int(src_dpid.split(':')[-2]) |
| 762 | host = controllers[hostid-1] |
| 763 | |
| 764 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./link.sh %s %s %s'" % (host, src_dpid, src_port, cmd) |
| 765 | print cmd_string |
| 766 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 767 | result=os.popen(cmd_string).read() |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 768 | |
| 769 | return result |
| 770 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 771 | #* Create Flow |
| 772 | #http://localhost:9000/gui/addflow/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>/<srcMAC>/<dstMAC> |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 773 | #1 FOOBAR 00:00:00:00:00:00:01:01 1 00:00:00:00:00:00:01:0b 1 matchSrcMac 00:00:00:00:00:00 matchDstMac 00:01:00:00:00:00 |
| 774 | @app.route("/gui/addfow/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>/<srcMAC>/<dstMAC>") |
| 775 | def add_flow(src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC): |
| 776 | command = "/home/ubuntu/ONOS/web/get_flow.py all |grep FlowPath |gawk '{print strtonum($4)}'| sort -n | tail -n 1" |
| 777 | print command |
| 778 | ret = os.popen(command).read() |
| 779 | if ret == "": |
| 780 | flow_nr=0 |
| 781 | else: |
| 782 | flow_nr=int(ret) |
| 783 | |
| 784 | flow_nr += 1 |
| 785 | command = "/home/ubuntu/ONOS/web/add_flow.py %d %s %s %s %s %s matchSrcMac %s matchDstMac %s" % (flow_nr, "dummy", src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC) |
| 786 | print command |
| 787 | errcode = os.popen(command).read() |
| 788 | return errcode |
| 789 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 790 | #* Delete Flow |
| 791 | #http://localhost:9000/gui/delflow/<flow_id> |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 792 | @app.route("/gui/delflow/<flow_id>") |
| 793 | def del_flow(flow_id): |
| 794 | command = "/home/ubuntu/ONOS/web/delete_flow.py %s" % (flow_id) |
| 795 | print command |
| 796 | errcode = os.popen(command).read() |
| 797 | return errcode |
| 798 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 799 | #* Start Iperf Througput |
Umesh Krishnaswamy | 6689be3 | 2013-03-27 18:12:26 -0700 | [diff] [blame] | 800 | #http://localhost:9000/gui/iperf/start/<flow_id>/<duration> |
| 801 | @app.route("/gui/iperf/start/<flow_id>/<duration>") |
| 802 | def iperf_start(flow_id,duration): |
| 803 | command = "iperf -xCMSV -t%d -i 0.5 -y c -u -c 127.0.0.1 > iperf_%s.out 2>/dev/null &" % (duration, flow_id) |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 804 | print command |
| 805 | errcode = os.popen(command).read() |
| 806 | return errcode |
| 807 | |
| 808 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 809 | #* Get Iperf Throughput |
| 810 | #http://localhost:9000/gui/iperf/rate/<flow_id> |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 811 | @app.route("/gui/iperf/rate/<flow_id>") |
| 812 | def iperf_rate(flow_id): |
| 813 | try: |
| 814 | command = "curl -s http://%s:%s/iperf_%s.out" % (RestIP, 9000, flow_id) |
| 815 | print command |
| 816 | result = os.popen(command).read() |
| 817 | except: |
| 818 | print "REST IF has issue" |
| 819 | exit |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 820 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 821 | resp = Response(result, status=200, mimetype='text/html') |
| 822 | return resp |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 823 | |
| 824 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 825 | if __name__ == "__main__": |
| 826 | if len(sys.argv) > 1 and sys.argv[1] == "-d": |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 827 | # add_flow("00:00:00:00:00:00:02:02", 1, "00:00:00:00:00:00:03:02", 1, "00:00:00:00:02:02", "00:00:00:00:03:0c") |
| 828 | # link_change("up", "00:00:00:00:ba:5e:ba:11", 1, "00:00:00:00:00:00:00:00", 1) |
| 829 | # link_change("down", "00:00:20:4e:7f:51:8a:35", 1, "00:00:00:00:00:00:00:00", 1) |
| 830 | # link_change("up", "00:00:00:00:00:00:02:03", 1, "00:00:00:00:00:00:00:00", 1) |
| 831 | # link_change("down", "00:00:00:00:00:00:07:12", 1, "00:00:00:00:00:00:00:00", 1) |
| 832 | |
| 833 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 834 | print "-- query all switches --" |
| 835 | query_switch() |
| 836 | print "-- query topo --" |
| 837 | topology_for_gui() |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 838 | # link_change(1,2,3,4) |
| 839 | print "-- query all links --" |
| 840 | query_links() |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 841 | # print "-- query all devices --" |
| 842 | # devices() |
| 843 | else: |
| 844 | app.debug = True |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 845 | app.run(threaded=True, host="0.0.0.0", port=9000) |