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 |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 10 | import random |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 11 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 12 | import re |
| 13 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 14 | from flask import Flask, json, Response, render_template, make_response, request |
| 15 | |
Pavlin Radoslavov | 092d0e2 | 2013-04-07 05:42:51 +0000 | [diff] [blame] | 16 | |
| 17 | CONFIG_FILE=os.getenv("HOME") + "/ONOS/web/config.json" |
| 18 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 19 | ## Global Var for ON.Lab local REST ## |
Ubuntu | f6ce96c | 2013-02-07 01:45:07 +0000 | [diff] [blame] | 20 | RestIP="localhost" |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 21 | RestPort=8080 |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 22 | ONOS_DEFAULT_HOST="localhost" ;# Has to set if LB=False |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 23 | DEBUG=1 |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 24 | |
Pavlin Radoslavov | 092d0e2 | 2013-04-07 05:42:51 +0000 | [diff] [blame] | 25 | def read_config(): |
Jonathan Hart | b255448 | 2013-04-08 13:40:31 -0700 | [diff] [blame] | 26 | global LB, TESTBED, controllers, core_switches, ONOS_GUI3_HOST, ONOS_GUI3_CONTROL_HOST |
Pavlin Radoslavov | 092d0e2 | 2013-04-07 05:42:51 +0000 | [diff] [blame] | 27 | f = open(CONFIG_FILE) |
| 28 | conf = json.load(f) |
| 29 | LB = conf['LB'] |
Jonathan Hart | b255448 | 2013-04-08 13:40:31 -0700 | [diff] [blame] | 30 | TESTBED = conf['TESTBED'] |
Pavlin Radoslavov | 092d0e2 | 2013-04-07 05:42:51 +0000 | [diff] [blame] | 31 | controllers = conf['controllers'] |
Jonathan Hart | b255448 | 2013-04-08 13:40:31 -0700 | [diff] [blame] | 32 | core_switches=conf['core_switches'] |
Pavlin Radoslavov | 092d0e2 | 2013-04-07 05:42:51 +0000 | [diff] [blame] | 33 | ONOS_GUI3_HOST=conf['ONOS_GUI3_HOST'] |
| 34 | ONOS_GUI3_CONTROL_HOST=conf['ONOS_GUI3_CONTROL_HOST'] |
| 35 | f.close() |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 36 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 37 | pp = pprint.PrettyPrinter(indent=4) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 38 | app = Flask(__name__) |
| 39 | |
| 40 | ## Worker Functions ## |
| 41 | def log_error(txt): |
| 42 | print '%s' % (txt) |
| 43 | |
| 44 | def debug(txt): |
| 45 | if DEBUG: |
| 46 | print '%s' % (txt) |
| 47 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 48 | ### File Fetch ### |
| 49 | @app.route('/ui/img/<filename>', methods=['GET']) |
| 50 | @app.route('/img/<filename>', methods=['GET']) |
| 51 | @app.route('/css/<filename>', methods=['GET']) |
| 52 | @app.route('/js/models/<filename>', methods=['GET']) |
| 53 | @app.route('/js/views/<filename>', methods=['GET']) |
| 54 | @app.route('/js/<filename>', methods=['GET']) |
| 55 | @app.route('/lib/<filename>', methods=['GET']) |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 56 | @app.route('/log/<filename>', methods=['GET']) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 57 | @app.route('/', methods=['GET']) |
| 58 | @app.route('/<filename>', methods=['GET']) |
| 59 | @app.route('/tpl/<filename>', methods=['GET']) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 60 | @app.route('/ons-demo/<filename>', methods=['GET']) |
| 61 | @app.route('/ons-demo/js/<filename>', methods=['GET']) |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 62 | @app.route('/ons-demo/d3/<filename>', methods=['GET']) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 63 | @app.route('/ons-demo/css/<filename>', methods=['GET']) |
| 64 | @app.route('/ons-demo/assets/<filename>', methods=['GET']) |
| 65 | @app.route('/ons-demo/data/<filename>', methods=['GET']) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 66 | def return_file(filename="index.html"): |
| 67 | if request.path == "/": |
| 68 | fullpath = "./index.html" |
| 69 | else: |
| 70 | fullpath = str(request.path)[1:] |
| 71 | |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 72 | try: |
Masayoshi Kobayashi | 03e64b4 | 2013-04-05 05:56:27 +0000 | [diff] [blame] | 73 | open(fullpath) |
| 74 | except: |
| 75 | response = make_response("Cannot find a file: %s" % (fullpath), 500) |
| 76 | response.headers["Content-type"] = "text/html" |
| 77 | return response |
| 78 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 79 | response = make_response(open(fullpath).read()) |
| 80 | suffix = fullpath.split(".")[-1] |
| 81 | |
| 82 | if suffix == "html" or suffix == "htm": |
| 83 | response.headers["Content-type"] = "text/html" |
| 84 | elif suffix == "js": |
| 85 | response.headers["Content-type"] = "application/javascript" |
| 86 | elif suffix == "css": |
| 87 | response.headers["Content-type"] = "text/css" |
| 88 | elif suffix == "png": |
| 89 | response.headers["Content-type"] = "image/png" |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 90 | elif suffix == "svg": |
| 91 | response.headers["Content-type"] = "image/svg+xml" |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 92 | |
| 93 | return response |
| 94 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 95 | ## Proxy ## |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 96 | @app.route("/proxy/gui/link/<cmd>/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>") |
| 97 | def proxy_link_change(cmd, src_dpid, src_port, dst_dpid, dst_port): |
| 98 | try: |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 99 | 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] | 100 | print command |
| 101 | result = os.popen(command).read() |
| 102 | except: |
| 103 | print "REST IF has issue" |
| 104 | exit |
| 105 | |
| 106 | resp = Response(result, status=200, mimetype='application/json') |
| 107 | return resp |
| 108 | |
Masayoshi Kobayashi | 03e64b4 | 2013-04-05 05:56:27 +0000 | [diff] [blame] | 109 | @app.route("/proxy/gui/switchctrl/<cmd>") |
| 110 | def proxy_switch_controller_setting(cmd): |
| 111 | try: |
| 112 | command = "curl -s %s/gui/switchctrl/%s" % (ONOS_GUI3_CONTROL_HOST, cmd) |
| 113 | print command |
| 114 | result = os.popen(command).read() |
| 115 | except: |
| 116 | print "REST IF has issue" |
| 117 | exit |
| 118 | |
| 119 | resp = Response(result, status=200, mimetype='application/json') |
| 120 | return resp |
| 121 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 122 | @app.route("/proxy/gui/switch/<cmd>/<dpid>") |
| 123 | def proxy_switch_status_change(cmd, dpid): |
| 124 | try: |
| 125 | command = "curl -s %s/gui/switch/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, dpid) |
| 126 | print command |
| 127 | result = os.popen(command).read() |
| 128 | except: |
| 129 | print "REST IF has issue" |
| 130 | exit |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 131 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 132 | resp = Response(result, status=200, mimetype='application/json') |
| 133 | return resp |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 134 | |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 135 | @app.route("/proxy/gui/controller/<cmd>/<controller_name>") |
| 136 | def proxy_controller_status_change(cmd, controller_name): |
| 137 | try: |
| 138 | command = "curl -s %s/gui/controller/%s/%s" % (ONOS_GUI3_CONTROL_HOST, cmd, controller_name) |
| 139 | print command |
| 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 | |
Paul Greyson | 472da4c | 2013-03-28 11:43:17 -0700 | [diff] [blame] | 148 | @app.route("/proxy/gui/addflow/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>/<srcMAC>/<dstMAC>") |
| 149 | def proxy_add_flow(src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC): |
| 150 | try: |
| 151 | command = "curl -s %s/gui/addflow/%s/%s/%s/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC) |
| 152 | print command |
| 153 | result = os.popen(command).read() |
| 154 | except: |
| 155 | print "REST IF has issue" |
| 156 | exit |
| 157 | |
| 158 | resp = Response(result, status=200, mimetype='application/json') |
| 159 | return resp |
| 160 | |
Paul Greyson | 6f91840 | 2013-03-28 12:18:30 -0700 | [diff] [blame] | 161 | @app.route("/proxy/gui/delflow/<flow_id>") |
| 162 | def proxy_del_flow(flow_id): |
| 163 | try: |
| 164 | command = "curl -s %s/gui/delflow/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id) |
| 165 | print command |
| 166 | result = os.popen(command).read() |
| 167 | except: |
| 168 | print "REST IF has issue" |
| 169 | exit |
| 170 | |
| 171 | resp = Response(result, status=200, mimetype='application/json') |
| 172 | return resp |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 173 | |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 174 | @app.route("/proxy/gui/iperf/start/<flow_id>/<duration>/<samples>") |
| 175 | def proxy_iperf_start(flow_id,duration,samples): |
| 176 | try: |
| 177 | command = "curl -s %s/gui/iperf/start/%s/%s/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id, duration, samples) |
| 178 | print command |
| 179 | result = os.popen(command).read() |
| 180 | except: |
| 181 | print "REST IF has issue" |
| 182 | exit |
| 183 | |
| 184 | resp = Response(result, status=200, mimetype='application/json') |
| 185 | return resp |
| 186 | |
| 187 | @app.route("/proxy/gui/iperf/rate/<flow_id>") |
| 188 | def proxy_iperf_rate(flow_id): |
| 189 | try: |
| 190 | command = "curl -s %s/gui/iperf/rate/%s" % (ONOS_GUI3_CONTROL_HOST, flow_id) |
| 191 | print command |
| 192 | result = os.popen(command).read() |
| 193 | except: |
| 194 | print "REST IF has issue" |
| 195 | exit |
| 196 | |
| 197 | resp = Response(result, status=200, mimetype='application/json') |
| 198 | return resp |
| 199 | |
Paul Greyson | e6266b9 | 2013-04-09 23:15:27 -0700 | [diff] [blame] | 200 | @app.route("/proxy/gui/switchctrl/<cmd>") |
| 201 | def proxy_switch_controller_setting(cmd): |
| 202 | try: |
| 203 | command = "curl -s %s/gui/switchctrl/%s" % (ONOS_GUI3_CONTROL_HOST, cmd) |
| 204 | print command |
| 205 | result = os.popen(command).read() |
| 206 | except: |
| 207 | print "REST IF has issue" |
| 208 | exit |
| 209 | |
| 210 | resp = Response(result, status=200, mimetype='application/json') |
| 211 | return resp |
| 212 | |
Paul Greyson | 4b4c8af | 2013-04-04 09:02:09 -0700 | [diff] [blame] | 213 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 214 | ###### ONOS RESET API ############################## |
| 215 | ## Worker Func ### |
| 216 | def get_json(url): |
| 217 | code = 200 |
| 218 | try: |
| 219 | command = "curl -s %s" % (url) |
| 220 | result = os.popen(command).read() |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 221 | parsedResult = json.loads(result) |
Masayoshi Kobayashi | 8ac3336 | 2013-04-05 03:17:26 +0000 | [diff] [blame] | 222 | if type(parsedResult) == 'dict' and parsedResult.has_key('code'): |
| 223 | print "REST %s returned code %s" % (command, parsedResult['code']) |
| 224 | code=500 |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 225 | except: |
| 226 | print "REST IF %s has issue" % command |
| 227 | result = "" |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 228 | code = 500 |
| 229 | |
| 230 | return (code, result) |
| 231 | |
| 232 | def pick_host(): |
| 233 | if LB == True: |
| 234 | nr_host=len(controllers) |
| 235 | r=random.randint(0, nr_host - 1) |
| 236 | host=controllers[r] |
| 237 | else: |
| 238 | host=ONOS_DEFAULT_HOST |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 239 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 240 | return "http://" + host + ":8080" |
| 241 | |
| 242 | ## Switch ## |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 243 | @app.route("/wm/core/topology/switches/all/json") |
| 244 | def switches(): |
| 245 | if request.args.get('proxy') == None: |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 246 | host = pick_host() |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 247 | else: |
| 248 | host = ONOS_GUI3_HOST |
| 249 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 250 | url ="%s/wm/core/topology/switches/all/json" % (host) |
| 251 | (code, result) = get_json(url) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 252 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 253 | resp = Response(result, status=code, mimetype='application/json') |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 254 | return resp |
| 255 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 256 | ## Link ## |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 257 | @app.route("/wm/core/topology/links/json") |
| 258 | def links(): |
| 259 | if request.args.get('proxy') == None: |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 260 | host = pick_host() |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 261 | else: |
| 262 | host = ONOS_GUI3_HOST |
| 263 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 264 | url ="%s/wm/core/topology/links/json" % (host) |
| 265 | (code, result) = get_json(url) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 266 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 267 | resp = Response(result, status=code, mimetype='application/json') |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 268 | return resp |
| 269 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 270 | ## FlowSummary ## |
Masayoshi Kobayashi | cdb652f | 2013-04-04 18:24:29 +0000 | [diff] [blame] | 271 | @app.route("/wm/flow/getsummary/<start>/<range>/json") |
| 272 | def flows(start, range): |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 273 | if request.args.get('proxy') == None: |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 274 | host = pick_host() |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 275 | else: |
| 276 | host = ONOS_GUI3_HOST |
| 277 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 278 | url ="%s/wm/flow/getsummary/%s/%s/json" % (host, start, range) |
| 279 | (code, result) = get_json(url) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 280 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 281 | resp = Response(result, status=code, mimetype='application/json') |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 282 | return resp |
| 283 | |
| 284 | @app.route("/wm/registry/controllers/json") |
| 285 | def registry_controllers(): |
| 286 | if request.args.get('proxy') == None: |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 287 | host = pick_host() |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 288 | else: |
| 289 | host = ONOS_GUI3_HOST |
| 290 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 291 | url= "%s/wm/registry/controllers/json" % (host) |
| 292 | (code, result) = get_json(url) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 293 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 294 | resp = Response(result, status=code, mimetype='application/json') |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 295 | return resp |
| 296 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 297 | |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 298 | @app.route("/wm/registry/switches/json") |
| 299 | def registry_switches(): |
| 300 | if request.args.get('proxy') == None: |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 301 | host = pick_host() |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 302 | else: |
| 303 | host = ONOS_GUI3_HOST |
| 304 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 305 | url="%s/wm/registry/switches/json" % (host) |
| 306 | (code, result) = get_json(url) |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 307 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 308 | resp = Response(result, status=code, mimetype='application/json') |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 309 | return resp |
| 310 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 311 | def node_id(switch_array, dpid): |
| 312 | id = -1 |
| 313 | for i, val in enumerate(switch_array): |
| 314 | if val['name'] == dpid: |
| 315 | id = i |
| 316 | break |
| 317 | |
| 318 | return id |
| 319 | |
Masayoshi Kobayashi | 13e2ebe | 2013-03-26 18:38:41 +0000 | [diff] [blame] | 320 | ## API for ON.Lab local GUI ## |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 321 | @app.route('/topology', methods=['GET']) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 322 | def topology_for_gui(): |
| 323 | try: |
| 324 | command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort) |
| 325 | result = os.popen(command).read() |
| 326 | parsedResult = json.loads(result) |
| 327 | except: |
| 328 | log_error("REST IF has issue: %s" % command) |
| 329 | log_error("%s" % result) |
| 330 | sys.exit(0) |
| 331 | |
| 332 | topo = {} |
| 333 | switches = [] |
| 334 | links = [] |
Ubuntu | 37ebda6 | 2013-03-01 00:35:31 +0000 | [diff] [blame] | 335 | devices = [] |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 336 | |
| 337 | for v in parsedResult: |
| 338 | if v.has_key('dpid'): |
| 339 | # if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes |
| 340 | dpid = str(v['dpid']) |
| 341 | state = str(v['state']) |
| 342 | sw = {} |
| 343 | sw['name']=dpid |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 344 | sw['group']= -1 |
Ubuntu | 37ebda6 | 2013-03-01 00:35:31 +0000 | [diff] [blame] | 345 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 346 | if state == "INACTIVE": |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 347 | sw['group']=0 |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 348 | switches.append(sw) |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 349 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 350 | try: |
| 351 | command = "curl -s \'http://%s:%s/wm/registry/switches/json\'" % (RestIP, RestPort) |
| 352 | result = os.popen(command).read() |
| 353 | parsedResult = json.loads(result) |
| 354 | except: |
| 355 | log_error("REST IF has issue: %s" % command) |
| 356 | log_error("%s" % result) |
| 357 | |
| 358 | for key in parsedResult: |
| 359 | dpid = key |
| 360 | ctrl = parsedResult[dpid][0]['controllerId'] |
| 361 | sw_id = node_id(switches, dpid) |
| 362 | if sw_id != -1: |
| 363 | if switches[sw_id]['group'] != 0: |
| 364 | switches[sw_id]['group'] = controllers.index(ctrl) + 1 |
| 365 | |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 366 | try: |
| 367 | v1 = "00:00:00:00:00:0a:0d:00" |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 368 | # v1 = "00:00:00:00:00:0d:00:d1" |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 369 | p1=1 |
| 370 | v2 = "00:00:00:00:00:0b:0d:03" |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 371 | # v2 = "00:00:00:00:00:0d:00:d3" |
| 372 | p2=1 |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 373 | command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2) |
| 374 | result = os.popen(command).read() |
| 375 | parsedResult = json.loads(result) |
| 376 | except: |
| 377 | log_error("No route") |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 378 | parsedResult = {} |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 379 | |
Ubuntu | 765deff | 2013-02-28 18:39:13 +0000 | [diff] [blame] | 380 | path = [] |
| 381 | if parsedResult.has_key('flowEntries'): |
| 382 | flowEntries= parsedResult['flowEntries'] |
| 383 | for i, v in enumerate(flowEntries): |
| 384 | if i < len(flowEntries) - 1: |
| 385 | sdpid= flowEntries[i]['dpid']['value'] |
| 386 | ddpid = flowEntries[i+1]['dpid']['value'] |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 387 | path.append( (sdpid, ddpid)) |
Ubuntu | 5b2b24a | 2013-02-27 09:51:13 +0000 | [diff] [blame] | 388 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 389 | try: |
| 390 | command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort) |
| 391 | result = os.popen(command).read() |
| 392 | parsedResult = json.loads(result) |
| 393 | except: |
| 394 | log_error("REST IF has issue: %s" % command) |
| 395 | log_error("%s" % result) |
| 396 | sys.exit(0) |
| 397 | |
| 398 | for v in parsedResult: |
| 399 | link = {} |
| 400 | if v.has_key('dst-switch'): |
| 401 | dst_dpid = str(v['dst-switch']) |
| 402 | dst_id = node_id(switches, dst_dpid) |
| 403 | if v.has_key('src-switch'): |
| 404 | src_dpid = str(v['src-switch']) |
| 405 | src_id = node_id(switches, src_dpid) |
| 406 | link['source'] = src_id |
| 407 | link['target'] = dst_id |
Masayoshi Kobayashi | 3bc5fde | 2013-02-28 01:02:54 +0000 | [diff] [blame] | 408 | |
| 409 | onpath = 0 |
| 410 | for (s,d) in path: |
| 411 | if s == v['src-switch'] and d == v['dst-switch']: |
| 412 | onpath = 1 |
| 413 | break |
| 414 | link['type'] = onpath |
| 415 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 416 | links.append(link) |
| 417 | |
| 418 | topo['nodes'] = switches |
| 419 | topo['links'] = links |
| 420 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 421 | js = json.dumps(topo) |
| 422 | resp = Response(js, status=200, mimetype='application/json') |
| 423 | return resp |
| 424 | |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 425 | #@app.route("/wm/topology/toporoute/00:00:00:00:00:a1/2/00:00:00:00:00:c1/3/json") |
| 426 | #@app.route("/wm/topology/toporoute/<srcdpid>/<srcport>/<destdpid>/<destport>/json") |
| 427 | @app.route("/wm/topology/toporoute/<v1>/<p1>/<v2>/<p2>/json") |
| 428 | def shortest_path(v1, p1, v2, p2): |
| 429 | try: |
| 430 | command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort) |
| 431 | result = os.popen(command).read() |
| 432 | parsedResult = json.loads(result) |
| 433 | except: |
| 434 | log_error("REST IF has issue: %s" % command) |
| 435 | log_error("%s" % result) |
| 436 | sys.exit(0) |
| 437 | |
| 438 | topo = {} |
| 439 | switches = [] |
| 440 | links = [] |
| 441 | |
| 442 | for v in parsedResult: |
| 443 | if v.has_key('dpid'): |
| 444 | dpid = str(v['dpid']) |
| 445 | state = str(v['state']) |
| 446 | sw = {} |
| 447 | sw['name']=dpid |
| 448 | if str(v['state']) == "ACTIVE": |
| 449 | if dpid[-2:-1] == "a": |
| 450 | sw['group']=1 |
| 451 | if dpid[-2:-1] == "b": |
| 452 | sw['group']=2 |
| 453 | if dpid[-2:-1] == "c": |
| 454 | sw['group']=3 |
| 455 | if str(v['state']) == "INACTIVE": |
| 456 | sw['group']=0 |
| 457 | |
| 458 | switches.append(sw) |
| 459 | |
| 460 | try: |
| 461 | command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (RestIP, RestPort, v1, p1, v2, p2) |
| 462 | result = os.popen(command).read() |
| 463 | parsedResult = json.loads(result) |
| 464 | except: |
| 465 | log_error("No route") |
| 466 | parsedResult = [] |
| 467 | # exit(1) |
| 468 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 469 | path = []; |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 470 | for i, v in enumerate(parsedResult): |
| 471 | if i < len(parsedResult) - 1: |
| 472 | sdpid= parsedResult[i]['switch'] |
| 473 | ddpid = parsedResult[i+1]['switch'] |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 474 | path.append( (sdpid, ddpid)) |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 475 | |
| 476 | try: |
| 477 | command = "curl -s \'http://%s:%s/wm/core/topology/links/json\'" % (RestIP, RestPort) |
| 478 | result = os.popen(command).read() |
| 479 | parsedResult = json.loads(result) |
| 480 | except: |
| 481 | log_error("REST IF has issue: %s" % command) |
| 482 | log_error("%s" % result) |
| 483 | sys.exit(0) |
| 484 | |
| 485 | for v in parsedResult: |
| 486 | link = {} |
| 487 | if v.has_key('dst-switch'): |
| 488 | dst_dpid = str(v['dst-switch']) |
| 489 | dst_id = node_id(switches, dst_dpid) |
| 490 | if v.has_key('src-switch'): |
| 491 | src_dpid = str(v['src-switch']) |
| 492 | src_id = node_id(switches, src_dpid) |
| 493 | link['source'] = src_id |
| 494 | link['target'] = dst_id |
| 495 | onpath = 0 |
| 496 | for (s,d) in path: |
| 497 | if s == v['src-switch'] and d == v['dst-switch']: |
| 498 | onpath = 1 |
| 499 | break |
| 500 | |
| 501 | link['type'] = onpath |
| 502 | links.append(link) |
| 503 | |
| 504 | topo['nodes'] = switches |
| 505 | topo['links'] = links |
| 506 | |
Ubuntu | aea2a68 | 2013-02-08 08:30:10 +0000 | [diff] [blame] | 507 | js = json.dumps(topo) |
| 508 | resp = Response(js, status=200, mimetype='application/json') |
| 509 | return resp |
| 510 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 511 | @app.route("/wm/core/controller/switches/json") |
| 512 | def query_switch(): |
| 513 | try: |
| 514 | command = "curl -s \'http://%s:%s/wm/core/topology/switches/all/json\'" % (RestIP, RestPort) |
| 515 | # http://localhost:8080/wm/core/topology/switches/active/json |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 516 | print command |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 517 | result = os.popen(command).read() |
| 518 | parsedResult = json.loads(result) |
| 519 | except: |
| 520 | log_error("REST IF has issue: %s" % command) |
| 521 | log_error("%s" % result) |
| 522 | sys.exit(0) |
| 523 | |
| 524 | # print command |
| 525 | # print result |
| 526 | switches_ = [] |
| 527 | for v in parsedResult: |
| 528 | if v.has_key('dpid'): |
| 529 | if v.has_key('dpid') and str(v['state']) == "ACTIVE":#;if you want only ACTIVE nodes |
| 530 | dpid = str(v['dpid']) |
| 531 | state = str(v['state']) |
| 532 | sw = {} |
| 533 | sw['dpid']=dpid |
| 534 | sw['active']=state |
| 535 | switches_.append(sw) |
| 536 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 537 | # pp.pprint(switches_) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 538 | js = json.dumps(switches_) |
| 539 | resp = Response(js, status=200, mimetype='application/json') |
| 540 | return resp |
| 541 | |
| 542 | @app.route("/wm/device/") |
| 543 | def devices(): |
| 544 | try: |
| 545 | command = "curl -s http://%s:%s/graphs/%s/vertices\?key=type\&value=device" % (RestIP, RestPort, DBName) |
| 546 | result = os.popen(command).read() |
| 547 | parsedResult = json.loads(result)['results'] |
| 548 | except: |
| 549 | log_error("REST IF has issue: %s" % command) |
| 550 | log_error("%s" % result) |
| 551 | sys.exit(0) |
| 552 | |
| 553 | devices = [] |
| 554 | for v in parsedResult: |
| 555 | dl_addr = v['dl_addr'] |
| 556 | nw_addr = v['nw_addr'] |
| 557 | vertex = v['_id'] |
| 558 | mac = [] |
| 559 | mac.append(dl_addr) |
| 560 | ip = [] |
| 561 | ip.append(nw_addr) |
| 562 | device = {} |
| 563 | device['entryClass']="DefaultEntryClass" |
| 564 | device['mac']=mac |
| 565 | device['ipv4']=ip |
| 566 | device['vlan']=[] |
| 567 | device['lastSeen']=0 |
| 568 | attachpoints =[] |
| 569 | |
| 570 | port, dpid = deviceV_to_attachpoint(vertex) |
| 571 | attachpoint = {} |
| 572 | attachpoint['port']=port |
| 573 | attachpoint['switchDPID']=dpid |
| 574 | attachpoints.append(attachpoint) |
| 575 | device['attachmentPoint']=attachpoints |
| 576 | devices.append(device) |
| 577 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 578 | js = json.dumps(devices) |
| 579 | resp = Response(js, status=200, mimetype='application/json') |
| 580 | return resp |
| 581 | |
| 582 | #{"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} |
| 583 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 584 | ## return fake stat for now |
| 585 | @app.route("/wm/core/switch/<switchId>/<statType>/json") |
| 586 | def switch_stat(switchId, statType): |
| 587 | if statType == "desc": |
| 588 | desc=[{"length":1056,"serialNumber":"None","manufacturerDescription":"Nicira Networks, Inc.","hardwareDescription":"Open vSwitch","softwareDescription":"1.4.0+build0","datapathDescription":"None"}] |
| 589 | ret = {} |
| 590 | ret[switchId]=desc |
| 591 | elif statType == "aggregate": |
| 592 | aggr = {"packetCount":0,"byteCount":0,"flowCount":0} |
| 593 | ret = {} |
| 594 | ret[switchId]=aggr |
| 595 | else: |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 596 | ret = {} |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 597 | |
| 598 | js = json.dumps(ret) |
| 599 | resp = Response(js, status=200, mimetype='application/json') |
| 600 | return resp |
| 601 | |
| 602 | |
| 603 | @app.route("/wm/topology/links/json") |
| 604 | def query_links(): |
| 605 | try: |
| 606 | 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] | 607 | print command |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 608 | result = os.popen(command).read() |
| 609 | parsedResult = json.loads(result)['results'] |
| 610 | except: |
| 611 | log_error("REST IF has issue: %s" % command) |
| 612 | log_error("%s" % result) |
| 613 | sys.exit(0) |
| 614 | |
| 615 | debug("query_links %s" % command) |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 616 | # pp.pprint(parsedResult) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 617 | sport = [] |
| 618 | links = [] |
| 619 | for v in parsedResult: |
| 620 | srcport = v['_id'] |
| 621 | try: |
| 622 | command = "curl -s http://%s:%s/graphs/%s/vertices/%d/out?_label=link" % (RestIP, RestPort, DBName, srcport) |
| 623 | print command |
| 624 | result = os.popen(command).read() |
| 625 | linkResults = json.loads(result)['results'] |
| 626 | except: |
| 627 | log_error("REST IF has issue: %s" % command) |
| 628 | log_error("%s" % result) |
| 629 | sys.exit(0) |
| 630 | |
| 631 | for p in linkResults: |
| 632 | if p.has_key('type') and p['type'] == "port": |
| 633 | dstport = p['_id'] |
| 634 | (sport, sdpid) = portV_to_port_dpid(srcport) |
| 635 | (dport, ddpid) = portV_to_port_dpid(dstport) |
| 636 | link = {} |
| 637 | link["src-switch"]=sdpid |
| 638 | link["src-port"]=sport |
| 639 | link["src-port-state"]=0 |
| 640 | link["dst-switch"]=ddpid |
| 641 | link["dst-port"]=dport |
| 642 | link["dst-port-state"]=0 |
| 643 | link["type"]="internal" |
| 644 | links.append(link) |
| 645 | |
Masayoshi Kobayashi | 1407a50 | 2013-02-27 06:23:08 +0000 | [diff] [blame] | 646 | # pp.pprint(links) |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 647 | js = json.dumps(links) |
| 648 | resp = Response(js, status=200, mimetype='application/json') |
| 649 | return resp |
| 650 | |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 651 | @app.route("/controller_status") |
| 652 | def controller_status(): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 653 | # onos_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh status | awk '{print $1}'" |
| 654 | onos_check="cd; onos status %s | grep %s | awk '{print $2}'" |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 655 | #cassandra_check="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-cassandra.sh status" |
| 656 | |
| 657 | cont_status=[] |
| 658 | for i in controllers: |
| 659 | status={} |
| 660 | onos=os.popen(onos_check % i).read()[:-1] |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 661 | onos=os.popen(onos_check % (i, i.lower())).read()[:-1] |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 662 | status["name"]=i |
| 663 | status["onos"]=onos |
Masayoshi Kobayashi | 5e91bdf | 2013-03-15 01:22:51 +0000 | [diff] [blame] | 664 | status["cassandra"]=0 |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 665 | cont_status.append(status) |
| 666 | |
| 667 | js = json.dumps(cont_status) |
| 668 | resp = Response(js, status=200, mimetype='application/json') |
Ubuntu | c016ba1 | 2013-02-27 21:53:41 +0000 | [diff] [blame] | 669 | return resp |
| 670 | |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 671 | ### Command ### |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 672 | @app.route("/gui/controller/<cmd>/<controller_name>") |
| 673 | def controller_status_change(cmd, controller_name): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 674 | # start_onos="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh start" % (controller_name) |
| 675 | # stop_onos="ssh -i ~/.ssh/onlabkey.pem %s ONOS/start-onos.sh stop" % (controller_name) |
| 676 | start_onos="cd; onos start %s" % (controller_name[-1:]) |
| 677 | stop_onos="cd; onos stop %s" % (controller_name[-1:]) |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 678 | |
| 679 | if cmd == "up": |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 680 | result=os.popen(start_onos).read() |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 681 | ret = "controller %s is up" % (controller_name) |
| 682 | elif cmd == "down": |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 683 | result=os.popen(stop_onos).read() |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 684 | ret = "controller %s is down" % (controller_name) |
| 685 | |
| 686 | return ret |
| 687 | |
Masayoshi Kobayashi | 03e64b4 | 2013-04-05 05:56:27 +0000 | [diff] [blame] | 688 | @app.route("/gui/switchctrl/<cmd>") |
| 689 | def switch_controller_setting(cmd): |
| 690 | if cmd =="local": |
| 691 | print "All aggr switches connects to local controller only" |
| 692 | result="" |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 693 | if (TESTBED == "sw"): |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 694 | for i in range(0, len(controllers)): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 695 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./ctrl-local.sh'" % (controllers[i]) |
| 696 | result += os.popen(cmd_string).read() |
| 697 | else: |
| 698 | cmd_string="cd; switch local" |
Masayoshi Kobayashi | 03e64b4 | 2013-04-05 05:56:27 +0000 | [diff] [blame] | 699 | result += os.popen(cmd_string).read() |
| 700 | elif cmd =="all": |
| 701 | print "All aggr switches connects to all controllers except for core controller" |
| 702 | result="" |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 703 | if (TESTBED == "sw"): |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 704 | for i in range(0, len(controllers)): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 705 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./ctrl-add-ext.sh'" % (controllers[i]) |
| 706 | result += os.popen(cmd_string).read() |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 707 | else: |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 708 | cmd_string="cd; switch all" |
Masayoshi Kobayashi | 03e64b4 | 2013-04-05 05:56:27 +0000 | [diff] [blame] | 709 | result += os.popen(cmd_string).read() |
| 710 | |
| 711 | return result |
| 712 | |
| 713 | |
| 714 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 715 | @app.route("/gui/switch/<cmd>/<dpid>") |
| 716 | def switch_status_change(cmd, dpid): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 717 | result = "" |
| 718 | if (TESTBED == "hw"): |
| 719 | return result |
| 720 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 721 | r = re.compile(':') |
| 722 | dpid = re.sub(r, '', dpid) |
Masayoshi Kobayashi | c0bc319 | 2013-03-27 23:12:03 +0000 | [diff] [blame] | 723 | host=controllers[0] |
| 724 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./switch.sh %s %s'" % (host, dpid, cmd) |
| 725 | 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] | 726 | print "cmd_string" |
| 727 | |
| 728 | if cmd =="up" or cmd=="down": |
| 729 | print "make dpid %s %s" % (dpid, cmd) |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 730 | os.popen(cmd_string) |
| 731 | result=os.popen(get_status).read() |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 732 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 733 | return result |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 734 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 735 | #* Link Up |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 736 | #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] | 737 | @app.route("/gui/link/up/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>") |
| 738 | def link_up(src_dpid, src_port, dst_dpid, dst_port): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 739 | result = "" |
| 740 | |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 741 | if (TESTBED == "sw"): |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 742 | result = link_up_sw(src_dpid, src_port, dst_dpid, dst_port) |
| 743 | else: |
| 744 | result = link_up_hw(src_dpid, src_port, dst_dpid, dst_port) |
| 745 | return result |
| 746 | |
| 747 | # Link up on software testbed |
| 748 | def link_up_sw(src_dpid, src_port, dst_dpid, dst_port): |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 749 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 750 | cmd = 'up' |
| 751 | result="" |
| 752 | |
Paul Greyson | 472da4c | 2013-03-28 11:43:17 -0700 | [diff] [blame] | 753 | for dpid in (src_dpid, dst_dpid): |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 754 | if dpid in core_switches: |
| 755 | host = controllers[0] |
| 756 | src_ports = [1, 2, 3, 4, 5] |
| 757 | else: |
Masayoshi Kobayashi | 05f12b3 | 2013-04-01 09:08:09 +0000 | [diff] [blame] | 758 | hostid=int(dpid.split(':')[-2]) |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 759 | host = controllers[hostid-1] |
| 760 | if hostid == 2 : |
| 761 | src_ports = [51] |
| 762 | else : |
| 763 | src_ports = [26] |
| 764 | |
| 765 | for port in src_ports : |
| 766 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./link.sh %s %s %s'" % (host, dpid, port, cmd) |
| 767 | print cmd_string |
| 768 | res=os.popen(cmd_string).read() |
| 769 | result = result + ' ' + res |
| 770 | |
| 771 | return result |
| 772 | |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 773 | # Link up on hardware testbed |
| 774 | def link_up_hw(src_dpid, src_port, dst_dpid, dst_port): |
| 775 | |
| 776 | port1 = src_port |
| 777 | port2 = dst_port |
| 778 | if src_dpid == "00:00:00:00:ba:5e:ba:11": |
| 779 | if dst_dpid == "00:00:00:08:a2:08:f9:01": |
| 780 | port1 = 24 |
| 781 | port2 = 24 |
| 782 | elif dst_dpid == "00:01:00:16:97:08:9a:46": |
| 783 | port1 = 23 |
| 784 | port2 = 23 |
| 785 | elif src_dpid == "00:00:00:00:ba:5e:ba:13": |
| 786 | if dst_dpid == "00:00:20:4e:7f:51:8a:35": |
| 787 | port1 = 22 |
| 788 | port2 = 22 |
| 789 | elif dst_dpid == "00:00:00:00:00:00:ba:12": |
| 790 | port1 = 23 |
| 791 | port2 = 23 |
| 792 | elif src_dpid == "00:00:00:00:00:00:ba:12": |
| 793 | if dst_dpid == "00:00:00:00:ba:5e:ba:13": |
| 794 | port1 = 23 |
| 795 | port2 = 23 |
| 796 | elif dst_dpid == "00:00:00:08:a2:08:f9:01": |
| 797 | port1 = 22 |
| 798 | port2 = 22 |
| 799 | elif dst_dpid == "00:00:20:4e:7f:51:8a:35": |
| 800 | port1 = 24 |
| 801 | port2 = 21 |
| 802 | elif src_dpid == "00:01:00:16:97:08:9a:46": |
| 803 | if dst_dpid == "00:00:00:00:ba:5e:ba:11": |
| 804 | port1 = 23 |
| 805 | port2 = 23 |
| 806 | elif dst_dpid == "00:00:20:4e:7f:51:8a:35": |
| 807 | port1 = 24 |
| 808 | port2 = 24 |
| 809 | elif src_dpid == "00:00:00:08:a2:08:f9:01": |
| 810 | if dst_dpid == "00:00:00:00:ba:5e:ba:11": |
| 811 | port1 = 24 |
| 812 | port2 = 24 |
| 813 | elif dst_dpid == "00:00:00:00:00:00:ba:12": |
| 814 | port1 = 22 |
| 815 | port2 = 22 |
| 816 | elif dst_dpid == "00:00:20:4e:7f:51:8a:35": |
| 817 | port1 = 23 |
| 818 | port2 = 23 |
| 819 | elif src_dpid == "00:00:20:4e:7f:51:8a:35": |
| 820 | if dst_dpid == "00:00:00:00:00:00:ba:12": |
| 821 | port1 = 21 |
| 822 | port2 = 24 |
| 823 | elif dst_dpid == "00:00:00:00:ba:5e:ba:13": |
| 824 | port1 = 22 |
| 825 | port2 = 22 |
| 826 | elif dst_dpid == "00:01:00:16:97:08:9a:46": |
| 827 | port1 = 24 |
| 828 | port2 = 24 |
| 829 | elif dst_dpid == "00:00:00:08:a2:08:f9:01": |
| 830 | port1 = 23 |
| 831 | port2 = 23 |
| 832 | |
| 833 | cmd = 'up' |
| 834 | result="" |
| 835 | host = controllers[0] |
| 836 | cmd_string="~/ONOS/scripts/link.sh %s %s %s " % (src_dpid, port1, cmd) |
| 837 | print cmd_string |
| 838 | res=os.popen(cmd_string).read() |
| 839 | result = result + ' ' + res |
| 840 | cmd_string="~/ONOS/scripts/link.sh %s %s %s " % (dst_dpid, port2, cmd) |
| 841 | print cmd_string |
| 842 | res=os.popen(cmd_string).read() |
| 843 | result = result + ' ' + res |
| 844 | |
| 845 | |
| 846 | return result |
| 847 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 848 | |
| 849 | #* Link Down |
| 850 | #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] | 851 | @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] | 852 | def link_down(cmd, src_dpid, src_port, dst_dpid, dst_port): |
| 853 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 854 | if src_dpid in core_switches: |
| 855 | host = controllers[0] |
| 856 | else: |
| 857 | hostid=int(src_dpid.split(':')[-2]) |
| 858 | host = controllers[hostid-1] |
| 859 | |
Tim Lindberg | 201ade2 | 2013-04-05 11:52:08 -0700 | [diff] [blame] | 860 | if (TESTBED == "sw"): |
| 861 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./link.sh %s %s %s'" % (host, src_dpid, src_port, cmd) |
| 862 | else: |
Tim Lindberg | a6c0417 | 2013-04-05 17:34:05 -0700 | [diff] [blame] | 863 | if ( src_dpid == "00:00:00:08:a2:08:f9:01" ): |
| 864 | cmd_string="~/ONOS/scripts/link.sh %s %s %s " % ( dst_dpid, dst_port, cmd) |
| 865 | else: |
| 866 | cmd_string="~/ONOS/scripts/link.sh %s %s %s " % ( src_dpid, src_port, cmd) |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 867 | print cmd_string |
| 868 | |
Masayoshi Kobayashi | decab44 | 2013-03-28 11:19:13 +0000 | [diff] [blame] | 869 | result=os.popen(cmd_string).read() |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 870 | |
| 871 | return result |
| 872 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 873 | #* Create Flow |
| 874 | #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] | 875 | #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 |
Masayoshi Kobayashi | 81f6565 | 2013-03-28 21:06:39 +0000 | [diff] [blame] | 876 | @app.route("/gui/addflow/<src_dpid>/<src_port>/<dst_dpid>/<dst_port>/<srcMAC>/<dstMAC>") |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 877 | def add_flow(src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC): |
| 878 | command = "/home/ubuntu/ONOS/web/get_flow.py all |grep FlowPath |gawk '{print strtonum($4)}'| sort -n | tail -n 1" |
| 879 | print command |
| 880 | ret = os.popen(command).read() |
| 881 | if ret == "": |
| 882 | flow_nr=0 |
| 883 | else: |
| 884 | flow_nr=int(ret) |
| 885 | |
| 886 | flow_nr += 1 |
Umesh Krishnaswamy | f22d3ed | 2013-04-03 11:57:54 -0700 | [diff] [blame] | 887 | command = "/home/ubuntu/ONOS/web/add_flow.py -m onos %d %s %s %s %s %s matchSrcMac %s matchDstMac %s" % (flow_nr, "dummy", src_dpid, src_port, dst_dpid, dst_port, srcMAC, dstMAC) |
Masayoshi Kobayashi | cdb652f | 2013-04-04 18:24:29 +0000 | [diff] [blame] | 888 | command1 = "/home/ubuntu/ONOS/web/add_flow.py -m onos %d %s %s %s %s %s matchSrcMac %s matchDstMac %s" % (flow_nr, "dummy", dst_dpid, dst_port, src_dpid, src_port, dstMAC, srcMAC) |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 889 | print command |
| 890 | errcode = os.popen(command).read() |
Masayoshi Kobayashi | cdb652f | 2013-04-04 18:24:29 +0000 | [diff] [blame] | 891 | errcode1 = os.popen(command1).read() |
| 892 | return errcode+" "+errcode1 |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 893 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 894 | #* Delete Flow |
| 895 | #http://localhost:9000/gui/delflow/<flow_id> |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 896 | @app.route("/gui/delflow/<flow_id>") |
| 897 | def del_flow(flow_id): |
| 898 | command = "/home/ubuntu/ONOS/web/delete_flow.py %s" % (flow_id) |
| 899 | print command |
| 900 | errcode = os.popen(command).read() |
| 901 | return errcode |
| 902 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 903 | #* Start Iperf Througput |
Umesh Krishnaswamy | 6689be3 | 2013-03-27 18:12:26 -0700 | [diff] [blame] | 904 | #http://localhost:9000/gui/iperf/start/<flow_id>/<duration> |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 905 | @app.route("/gui/iperf/start/<flow_id>/<duration>/<samples>") |
| 906 | def iperf_start(flow_id,duration,samples): |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 907 | try: |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 908 | command = "curl -s \'http://%s:%s/wm/flow/get/%s/json\'" % (RestIP, RestPort, flow_id) |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 909 | print command |
| 910 | result = os.popen(command).read() |
| 911 | if len(result) == 0: |
| 912 | print "No Flow found" |
| 913 | return; |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 914 | except: |
| 915 | print "REST IF has issue" |
| 916 | exit |
| 917 | |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 918 | parsedResult = json.loads(result) |
| 919 | |
| 920 | flowId = int(parsedResult['flowId']['value'], 16) |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 921 | src_dpid = parsedResult['dataPath']['srcPort']['dpid']['value'] |
| 922 | src_port = parsedResult['dataPath']['srcPort']['port']['value'] |
| 923 | dst_dpid = parsedResult['dataPath']['dstPort']['dpid']['value'] |
| 924 | dst_port = parsedResult['dataPath']['dstPort']['port']['value'] |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 925 | # print "FlowPath: (flowId = %s src = %s/%s dst = %s/%s" % (flowId, src_dpid, src_port, dst_dpid, dst_port) |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 926 | |
| 927 | if src_dpid in core_switches: |
Umesh Krishnaswamy | 5c3eddf | 2013-04-06 00:24:01 -0700 | [diff] [blame] | 928 | src_host = controllers[0] |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 929 | else: |
| 930 | hostid=int(src_dpid.split(':')[-2]) |
Umesh Krishnaswamy | 5c3eddf | 2013-04-06 00:24:01 -0700 | [diff] [blame] | 931 | src_host = controllers[hostid-1] |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 932 | |
Umesh Krishnaswamy | 5c3eddf | 2013-04-06 00:24:01 -0700 | [diff] [blame] | 933 | if dst_dpid in core_switches: |
| 934 | dst_host = controllers[0] |
| 935 | else: |
| 936 | hostid=int(dst_dpid.split(':')[-2]) |
| 937 | dst_host = controllers[hostid-1] |
| 938 | |
| 939 | # /runiperf.sh <flowid> <src_dpid> <dst_dpid> svr|client <proto>/<duration>/<interval>/<samples> |
| 940 | protocol="udp" |
| 941 | interval=0.1 |
| 942 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./runiperf.sh %d %s %s %s %s/%s/%s/%s'" % (dst_host, flowId, src_dpid, dst_dpid, "svr", protocol, duration, interval, samples) |
| 943 | print cmd_string |
| 944 | os.popen(cmd_string) |
| 945 | |
| 946 | cmd_string="ssh -i ~/.ssh/onlabkey.pem %s 'cd ONOS/scripts; ./runiperf.sh %d %s %s %s %s/%s/%s/%s'" % (src_host, flowId, src_dpid, dst_dpid, "client", protocol, duration, interval, samples) |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 947 | print cmd_string |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 948 | os.popen(cmd_string) |
Masayoshi Kobayashi | fd56631 | 2013-04-01 10:34:01 +0000 | [diff] [blame] | 949 | |
Masayoshi Kobayashi | cdb652f | 2013-04-04 18:24:29 +0000 | [diff] [blame] | 950 | return cmd_string |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 951 | |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 952 | #* Get Iperf Throughput |
| 953 | #http://localhost:9000/gui/iperf/rate/<flow_id> |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 954 | @app.route("/gui/iperf/rate/<flow_id>") |
| 955 | def iperf_rate(flow_id): |
Tim Lindberg | a6c0417 | 2013-04-05 17:34:05 -0700 | [diff] [blame] | 956 | if (TESTBED == "hw"): |
| 957 | return "{}" |
| 958 | |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 959 | try: |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 960 | command = "curl -s \'http://%s:%s/wm/flow/get/%s/json\'" % (RestIP, RestPort, flow_id) |
| 961 | print command |
| 962 | result = os.popen(command).read() |
| 963 | if len(result) == 0: |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 964 | resp = Response(result, status=400, mimetype='text/html') |
| 965 | return "no such iperf flow (flowid %s)" % flow_id; |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 966 | except: |
| 967 | print "REST IF has issue" |
| 968 | exit |
| 969 | |
| 970 | parsedResult = json.loads(result) |
| 971 | |
| 972 | flowId = int(parsedResult['flowId']['value'], 16) |
| 973 | src_dpid = parsedResult['dataPath']['srcPort']['dpid']['value'] |
| 974 | src_port = parsedResult['dataPath']['srcPort']['port']['value'] |
| 975 | dst_dpid = parsedResult['dataPath']['dstPort']['dpid']['value'] |
| 976 | dst_port = parsedResult['dataPath']['dstPort']['port']['value'] |
| 977 | |
Umesh Krishnaswamy | 5c3eddf | 2013-04-06 00:24:01 -0700 | [diff] [blame] | 978 | if dst_dpid in core_switches: |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 979 | host = controllers[0] |
| 980 | else: |
Umesh Krishnaswamy | 5c3eddf | 2013-04-06 00:24:01 -0700 | [diff] [blame] | 981 | hostid=int(dst_dpid.split(':')[-2]) |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 982 | host = controllers[hostid-1] |
| 983 | |
| 984 | try: |
Umesh Krishnaswamy | 5c3eddf | 2013-04-06 00:24:01 -0700 | [diff] [blame] | 985 | command = "curl -s http://%s:%s/log/iperfsvr_%s.out" % (host, 9000, flow_id) |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 986 | print command |
| 987 | result = os.popen(command).read() |
| 988 | except: |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 989 | exit |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 990 | |
Masayoshi Kobayashi | b56f297 | 2013-04-05 02:57:29 +0000 | [diff] [blame] | 991 | if len(result) == 0: |
| 992 | resp = Response(result, status=400, mimetype='text/html') |
| 993 | return "no iperf file found (flowid %s)" % flow_id; |
| 994 | else: |
| 995 | resp = Response(result, status=200, mimetype='application/json') |
| 996 | return resp |
Masayoshi Kobayashi | 5101152 | 2013-03-27 00:18:12 +0000 | [diff] [blame] | 997 | |
| 998 | |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 999 | if __name__ == "__main__": |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 1000 | random.seed() |
Pavlin Radoslavov | 092d0e2 | 2013-04-07 05:42:51 +0000 | [diff] [blame] | 1001 | read_config() |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 1002 | if len(sys.argv) > 1 and sys.argv[1] == "-d": |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 1003 | # 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") |
| 1004 | # link_change("up", "00:00:00:00:ba:5e:ba:11", 1, "00:00:00:00:00:00:00:00", 1) |
| 1005 | # link_change("down", "00:00:20:4e:7f:51:8a:35", 1, "00:00:00:00:00:00:00:00", 1) |
| 1006 | # link_change("up", "00:00:00:00:00:00:02:03", 1, "00:00:00:00:00:00:00:00", 1) |
| 1007 | # link_change("down", "00:00:00:00:00:00:07:12", 1, "00:00:00:00:00:00:00:00", 1) |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 1008 | # print "-- query all switches --" |
| 1009 | # query_switch() |
| 1010 | # print "-- query topo --" |
| 1011 | # topology_for_gui() |
Masayoshi Kobayashi | 1e07238 | 2013-03-27 05:17:09 +0000 | [diff] [blame] | 1012 | # link_change(1,2,3,4) |
| 1013 | print "-- query all links --" |
Masayoshi Kobayashi | 3d04931 | 2013-04-02 22:15:16 +0000 | [diff] [blame] | 1014 | # query_links() |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 1015 | # print "-- query all devices --" |
| 1016 | # devices() |
Masayoshi Kobayashi | 2ae891a | 2013-04-05 02:16:19 +0000 | [diff] [blame] | 1017 | # iperf_start(1,10,15) |
| 1018 | # iperf_rate(1) |
| 1019 | switches() |
Ubuntu | 82b8a83 | 2013-02-06 22:00:11 +0000 | [diff] [blame] | 1020 | else: |
| 1021 | app.debug = True |
Masayoshi Kobayashi | f63ef2f | 2013-02-20 21:47:21 +0000 | [diff] [blame] | 1022 | app.run(threaded=True, host="0.0.0.0", port=9000) |