forked from sdn-ixp/iSDX
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowmodmsg.py
85 lines (74 loc) · 2.67 KB
/
flowmodmsg.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
#!/usr/bin/env python
# Author:
# Rudiger Birkner (Networked Systems Group ETH Zurich)
class FlowModMsgBuilder(object):
def __init__(self, participant, key):
self.participant = participant
self.key = key
self.flow_mods = []
def add_flow_mod(self, mod_type, rule_type, priority, match, action, cookie = None):
if cookie is None:
cookie = (len(self.flow_mods)+1, 65535)
fm = {
"cookie": cookie,
"mod_type": mod_type,
"rule_type": rule_type,
"priority": priority,
"match": match,
"action": action
}
self.flow_mods.append(fm)
return cookie
def delete_flow_mod(self, mod_type, rule_type, cookie, cookie_mask):
fm = {
"cookie": (cookie, cookie_mask),
"mod_type": mod_type,
"rule_type": rule_type,
}
self.flow_mods.append(fm)
def get_msg(self):
msg = {
"auth_info": {
"participant" : self.participant,
"key" : self.key
},
"flow_mods": self.flow_mods
}
return msg
# request body format:
# {"auth_info": {
# "participant": 1,
# "key": "xyz"
# }
# "flow_mods": [
# { "cookie": (1, 2**16-1),
# "mod_type": "insert/remove",
# "rule_type": "inbound/outbound/main",
# "priority": 1,
# "match" : {
# "eth_type" : 0x0806,
# "arp_tpa" : ("172.1.0.0", "255.255.255.0"),
# "in_port" : 5,
# "eth_dst" : "ff:ff:ff:ff:ff:ff",
# "eth_src" : "80:23:ff:98:10:01",
# "ipv4_src" : "192.168.1.1",
# "ipv4_dst" : "192.168.1.2",
# "tcp_src" : 80,
# "tcp_dst" : 179,
# "udp_src" : 23,
# "udp_dst" : 22,
# },
# "action" : {
# "fwd": ["inbound"/"outbound"/"main-in"/main-out"],
# "set_eth_src": "80:23:ff:98:10:01",
# "set_eth_dst": ("00:00:00:00:00:01","00:00:00:00:03:ff")
# }
# },
# { "cookie": (2, 2**16-1),
# "mod_type": "insert/remove",
# "rule_type": "inbound/outbound/main",
# "match" : {"tcp_dst" : 80},
# "action" : {"fwd": [3]}
# }
# ...]
# }