-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmngtopo.py
104 lines (91 loc) · 2.58 KB
/
mngtopo.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
from customclass import ONOS
onos_obj = ONOS()
# Fetches all hosts
def get_hosts():
hosts = onos_obj.getmethod("hosts")
return hosts
# Fetches all switches/devices
def get_switches():
devices = onos_obj.getmethod("devices")
return devices
# Fetches JSON data for a particular host
def get_host(user):
hosts = get_hosts()
return hosts[user]
# Enables flow rules for traffic from a specified host to any other host
def enable_flow_rules(host_IP, device_ID, port):
IP_host = host_IP + "/32"
postdata = {
"priority": 41000,
"timeout": 0,
"isPermanent": "true",
"state": "ADD",
"deviceId": str(device_ID),
"treatment": {
"instructions": [
{
"type": "OUTPUT",
"port": "CONTROLLER"
}
]
},
"selector": {
"criteria": [
{
"type": "ETH_TYPE",
"ethType": "0x800"
},
{
"type": "IPV4_SRC",
"ip": str(IP_host)
},
{
"type": "IN_PORT",
"port": str(port)
}
]
}
}
device_url = device_ID.replace('of:', 'of%3A')
response = onos_obj.postmethod(device_url, postdata)
return response
# Disables flow rules for a specified host to stop traffic
def disable_flow_rules(host_IP, device_ID, port):
IP_host = host_IP + "/32"
postdata = {
"priority": 40010,
"timeout": 0,
"isPermanent": "true",
"state": "ADD",
"deviceId": str(device_ID),
"treatment": {
"instructions": [
{
"type": "NOACTION"
}
]
},
"selector": {
"criteria": [
{
"type": "ETH_TYPE",
"ethType": "0x800"
},
{
"type": "IPV4_SRC",
"ip": str(IP_host)
},
{
"type": "IN_PORT",
"port": str(port)
}
]
}
}
device_url = device_ID.replace('of:', 'of%3A')
response = onos_obj.postmethod(device_url, postdata)
return response
# Removes NOACTION flow for a specific login ID and device ID
def disable_no_action(login_ID, deviceID):
response = onos_obj.autodeletmethod(key="flows", device_ID=deviceID, loginID=login_ID)
return response