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