forked from hakiri/p4-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouting-controller.py
46 lines (32 loc) · 1.29 KB
/
routing-controller.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
from p4utils.utils.helper import load_topo
from p4utils.utils.sswitch_thrift_API import SimpleSwitchThriftAPI
class RoutingController(object):
def __init__(self):
self.topo = load_topo('topology.json')
self.controllers = {}
self.init()
def init(self):
self.connect_to_switches()
self.reset_states()
self.set_table_defaults()
def reset_states(self):
[controller.reset_state() for controller in self.controllers.values()]
def connect_to_switches(self):
for p4switch in self.topo.get_p4switches():
thrift_port = self.topo.get_thrift_port(p4switch)
self.controllers[p4switch] = SimpleSwitchThriftAPI(thrift_port)
def set_table_defaults(self):
for controller in self.controllers.values():
controller.table_set_default("ipv4_lpm", "drop", [])
controller.table_set_default("ecmp_group_to_nhop", "drop", [])
def set_icmp_ingress_port_table(self):
#TODO 2: Fill the icmp_ingress_port table for all the switches in the topology
pass
def route(self):
#copy from the previous exercise
pass
def main(self):
self.set_icmp_ingress_port_table()
self.route()
if __name__ == "__main__":
controller = RoutingController().main()