routing-controller.py 1.42 KB
Newer Older
cedgar's avatar
cedgar committed
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
from p4utils.utils.topology import Topology
from p4utils.utils.sswitch_API import SimpleSwitchAPI

class RoutingController(object):

    def __init__(self):
        """Initializes controller
        """
        self.topo = Topology(db="topology.db")
        self.controllers = {}
        self.init()

    def init(self):
        """Calls init functions
        """
        self.connect_to_switches()
        self.reset_states()
        self.set_table_defaults()

    def reset_states(self):
        """Reset tables and stateful objects
        """
        [controller.reset_state() for controller in self.controllers.values()]

    def connect_to_switches(self):
        """Connects to all p4 switchs and saves controllers in self.controllers
        """
        for p4switch in self.topo.get_p4switches():
            thrift_port = self.topo.get_thrift_port(p4switch)
            self.controllers[p4switch] = SimpleSwitchAPI(thrift_port)

    def set_table_defaults(self):
        """Set table defaults to drop
        """
        for controller in self.controllers.values():
            controller.table_set_default("ipv4_lpm", "drop", [])
            controller.table_set_default("ecmp_group_to_nhop", "drop", [])

    def route(self):
        """Populates ECMP routing tables
        """

        # Task 2, TODO: Implement route function

    def main(self):
        self.route()


if __name__ == "__main__":
    controller = RoutingController().main()