blob: db70d40af49eb5fb45b11fb89a0846daf3cb041b [file] [log] [blame]
Pavlin Radoslavov916832f2013-03-14 17:48:41 -07001#! /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# TODO: remove this! We don't use JSON argument here!
17# curl http://127.0.0.1:8080/wm/flow/clear/{"value":"0xf"}/json'
18#
19
20## Global Var ##
21ControllerIP="127.0.0.1"
22ControllerPort=8080
23
24DEBUG=0
25pp = pprint.PrettyPrinter(indent=4)
26
27app = Flask(__name__)
28
29## Worker Functions ##
30def log_error(txt):
31 print '%s' % (txt)
32
33def debug(txt):
34 if DEBUG:
35 print '%s' % (txt)
36
37# @app.route("/wm/flow/clear/<flow-id>/json")
38def clear_flow_path(flow_id):
39 command = "curl -s \"http://%s:%s/wm/flow/clear/%s/json\"" % (ControllerIP, ControllerPort, flow_id)
40 debug("clear_flow_path %s" % command)
41 result = os.popen(command).read()
42 debug("result %s" % result)
43 # parsedResult = json.loads(result)
44 # debug("parsed %s" % parsedResult)
45
46if __name__ == "__main__":
47 usage_msg = "Clear flow state from the ONOS Network Map\n"
Pavlin Radoslavov7be3bac2013-03-27 09:59:34 -070048 usage_msg = usage_msg + "Usage: %s <begin-flow-id> <end-flow-id>\n" % (sys.argv[0])
49 usage_msg = usage_msg + " %s <flow-id>\n" % (sys.argv[0])
50 usage_msg = usage_msg + "\n"
51 usage_msg = usage_msg + " Arguments:\n"
52 usage_msg = usage_msg + " <begin-flow-id> <end-flow-id> Clear all flows in the flow ID range\n"
53 usage_msg = usage_msg + " <flow-id> Clear a single flow with the flow ID\n"
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +000054 usage_msg = usage_msg + " all Clear all flows\n"
Pavlin Radoslavov916832f2013-03-14 17:48:41 -070055
56 # app.debug = False;
57
58 # Usage info
59 if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
60 print(usage_msg)
61 exit(0)
62
63 # Check arguments
64 if len(sys.argv) < 2:
65 log_error(usage_msg)
66 exit(1)
67
Pavlin Radoslavovbaea9242013-05-08 00:20:09 +000068 if (sys.argv[1] == "all"):
69 clear_flow_path(sys.argv[1])
70 else:
71 begin_flow_id = int(sys.argv[1], 0)
72 if len(sys.argv) >= 3:
73 end_flow_id = int(sys.argv[2], 0)
74 else:
75 end_flow_id = begin_flow_id
76
77 # Do the work
78 flow_id = begin_flow_id
79 while flow_id <= end_flow_id:
80 clear_flow_path(flow_id)
81 flow_id = flow_id + 1