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