Skip to content

Instantly share code, notes, and snippets.

@pichuang
Created March 13, 2014 18:08
Show Gist options
  • Save pichuang/9533626 to your computer and use it in GitHub Desktop.
Save pichuang/9533626 to your computer and use it in GitHub Desktop.
Pingall_flood
#!/usr/bin/env python
import httplib
import json
class StaticFlowPusher(object):
def __init__(self, server):
self.server = server
def get(self, data):
ret = self.rest_call({}, 'GET')
return json.loads(ret[2])
def set(self, data):
ret = self.rest_call(data, 'POST')
return ret[0] == 200
def remove(self, objtype, data):
ret = self.rest_call(data, 'DELETE')
return ret[0] == 200
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('127.0.0.1')
flow1 = {
'switch':"00:00:00:00:00:00:00:02",
"name":"flow-mod-1",
"cookie":"0",
"priority":"32768",
"ingress-port":"1",
"active":"true",
"actions":"output=normal"
}
flow2 = {
'switch':"00:00:00:00:00:00:00:02",
"name":"flow-mod-2",
"cookie":"0",
"priority":"32768",
"ingress-port":"2",
"active":"true",
"actions":"output=normal"
}
flow3 = {
'switch':"00:00:00:00:00:00:00:02",
"name":"flow-mod-3",
"cookie":"0",
"priority":"32768",
"ingress-port":"3",
"active":"true",
"actions":"output=normal"
}
flow4 = {
'switch':"00:00:00:00:00:00:00:03",
"name":"flow-mod-4",
"cookie":"0",
"priority":"32768",
"ingress-port":"1",
"active":"true",
"actions":"output=normal"
}
flow5 = {
'switch':"00:00:00:00:00:00:00:03",
"name":"flow-mod-5",
"cookie":"0",
"priority":"32768",
"ingress-port":"2",
"active":"true",
"actions":"output=normal"
}
flow6 = {
'switch':"00:00:00:00:00:00:00:03",
"name":"flow-mod-6",
"cookie":"0",
"priority":"32768",
"ingress-port":"3",
"active":"true",
"actions":"output=normal"
}
flow7 = {
'switch':"00:00:00:00:00:00:00:01",
"name":"flow-mod-7",
"cookie":"0",
"priority":"32768",
"ingress-port":"1",
"active":"true",
"actions":"output=2"
}
flow8 = {
'switch':"00:00:00:00:00:00:00:01",
"name":"flow-mod-8",
"cookie":"0",
"priority":"32768",
"ingress-port":"2",
"active":"true",
"actions":"output=1"
}
pusher.set(flow1)
pusher.set(flow2)
pusher.set(flow3)
pusher.set(flow4)
pusher.set(flow5)
pusher.set(flow6)
pusher.set(flow7)
pusher.set(flow8)
@pichuang
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment