-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaticFlowPusherCustom.py
130 lines (110 loc) · 3.96 KB
/
StaticFlowPusherCustom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#Pushes static flows
#Deletes currents static flows
#Gets current flows
#Zach Meath
import httplib, json
class StaticFlowPusher(object):
def __init__(self, server):
self.server = server
def get(self, data):
path = '/wm/staticflowentrypusher/list/' + data + '/json'
conn = httplib.HTTPConnection(self.server, 8080)
conn.request("GET", path)
response = conn.getresponse()
ret = (response.status, response.reason, response.read())
ret1 = str(ret)
print ret1
x=1
ret1 = ret1[ret1.find("\":{\"",0)+4:]
name = ret1[:ret1.find("\"",0)]
ret1 = ret1[ret1.find("\"port\"",0)-1:]
outport = ret1[ret1.find(":",0)+1:ret1.find(",",0)]
ret1 = ret1[ret1.find("\"inputPort\"",0)+11:]
inport = ret1[1:ret1.find(",")]
if name == "0, 'OK', '{":
print "\nNo flows\n"
else:
print "\n\n"
print"Flow "+"1"+": " + name
print "Inport: "+inport
print "Outport: "+outport
print "\n"
while ret1.find("\"port\"",0) != -1:
ret2 = ret1[:ret1.find("\":{\"actions",0)]
name = ret2[ret2.rfind("\"",0)+1:]
ret1 = ret1[ret1.find("\"port\"",0)-1:]
outport = ret1[ret1.find(":",0)+1:ret1.find(",",0)]
ret1 = ret1[ret1.find("\"inputPort\"",0)+11:]
inport = ret1[1:ret1.find(",")]
x+=1
print "Flow "+str(x)+": " + name
print "Inport: "+inport
print "Outport: "+outport
print "\n"
#print ret1
conn.close()
return ret
def set(self, data):
ret = self.rest_call(data, 'POST')
return ret[0] == 200
def remove(self, data):
ret = self.rest_call(data, 'DELETE')
return ret[0] == 200
def remove_all(self):
path = '/wm/staticflowentrypusher/clear/all/json'
action = 'GET'
conn = httplib.HTTPConnection(self.server, 8080)
conn.request(action, path)
print "DELETED...\n"
conn.close()
def rest_call(self, data, action):
path = '/wm/staticflowentrypusher/json'
headers = {
'Content-type': 'application/json',
'Accept': 'application/json',
}
body = json.dumps(data)
conn = httplib.HTTPConnection(self.server, 8080)
conn.request(action, path, body, headers)
response = conn.getresponse()
ret = (response.status, response.reason, response.read())
print ret
conn.close()
return ret
pusher = StaticFlowPusher('10.11.17.20')
##pusher = StaticFlowPusher('192.168.56.1')
text = raw_input("Enter PUSH, DELETE, GET, or QUIT: \n")
while text.lower() != "quit":
if text.lower() == "push":
name = raw_input("Enter a name for the flow: \n")
inp = raw_input("Enter an ingress port: \n")
a= raw_input("Enter an output port: \n")
outp = "output=" + a
flow1 = {
'switch':"00:00:00:00:00:00:00:0a",
"name":name,
"cookie":"0",
"priority":"32768",
"ingress-port":inp,
"active":"true",
"actions":outp
}
pusher.set(flow1)
if text.lower() == "delete":
name1 = raw_input("Enter a name for the flow you wish to delete (\"all\" to delete all flows): \n")
if name1.lower() == "all":
pusher.remove_all()
else:
flow1 = {
'switch':"00:00:00:00:00:00:00:0a",
"name":name1,
"cookie":"0",
"priority":"32768",
"ingress-port":"1",
"active":"true",
"actions":"output=9"
}
pusher.remove(flow1)
if text.lower() == "get":
pusher.get("all")
text = raw_input("Enter PUSH, DELETE, GET or QUIT: \n")