blob: 5bea18259b83bdcc197a15c5730be2ac29521d22 [file] [log] [blame]
Pavlin Radoslavov382b22a2013-01-28 09:24:04 -08001#! /usr/bin/env python
2# -*- Mode: python; py-indent-offset: 4; tab-width: 8; indent-tabs-mode: t; -*-
3
4import pprint
5import os
6import sys
7import subprocess
8import json
9import argparse
10import io
11import time
12
13from flask import Flask, json, Response, render_template, make_response, request
14
15#
16# curl http://127.0.0.1:8080/wm/topology/route/00:00:00:00:00:00:0a:01/1/00:00:00:00:00:00:0a:04/1/json
17#
18
19## Global Var ##
20ControllerIP="127.0.0.1"
21ControllerPort=8080
22
23DEBUG=0
24pp = pprint.PrettyPrinter(indent=4)
25
26app = Flask(__name__)
27
28## Worker Functions ##
29def log_error(txt):
30 print '%s' % (txt)
31
32def debug(txt):
33 if DEBUG:
34 print '%s' % (txt)
35
36# @app.route("/wm/topology/route/<srcdpid>/<srcport>/<destdpid>/<destport>/json")
37def shortest_path(v1, p1, v2, p2):
38 try:
39 command = "curl -s http://%s:%s/wm/topology/route/%s/%s/%s/%s/json" % (ControllerIP, ControllerPort, v1, p1, v2, p2)
40 result = os.popen(command).read()
41 parsedResult = json.loads(result)
42 except:
43 log_error("Controller IF has issue")
44 exit(1)
45
46 debug("shortest_path %s" % command)
47 debug("parsed %s" % parsedResult)
48
49 for v in parsedResult:
50 dpid = v['switch'];
51 port = v['port'];
52 print "PathEntry: (%s, %s)" % (dpid, port)
53
54
55if __name__ == "__main__":
56 usage_msg = "Usage: %s <src-dpid> <src-port> <dest-dpid> <dest-port>" % (sys.argv[0])
57
58 # app.debug = False;
59
60 # Usage info
61 if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
62 print(usage_msg)
63 exit(0)
64
65 # Check arguments
66 if len(sys.argv) < 5:
67 log_error(usage_msg)
68 exit(1)
69
70 # Do the work
71 shortest_path(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]);