コード例 #1
0
ファイル: controller.py プロジェクト: uni-tue-kn/p4-bier
def connect_to_switches(controller=None):
    """
    Connect to switches and set forwarding pipeline
    :param controller: base controller who handles connections
    :param topology_controller: topology controller, who will send topology packets
    :return:
    """
    controller.connect()
    Configuration.set('system_done', True)
コード例 #2
0
ファイル: controller.py プロジェクト: uni-tue-kn/p4-bier
def init_switches(controller=None,
                  topology_controller=None,
                  group_controller=None):
    """
    Connect to switches and set forwarding pipeline
    :param controller: base controller who handles connections
    :param topology_controller: topology controller, who will send topology packets
    :return:
    """
    controller.connect_and_arbitrate(grpc_port=Configuration.get('grpc_port'),
                                     device_id=Configuration.get('device_id'))
    controller.set_forwarding_pipeline_config()

    Configuration.set('system_done', True)

    group_controller.add_flood_node()
    group_controller.init_flood_group()

    topology_controller.send_topology_packets()
コード例 #3
0
ファイル: controller.py プロジェクト: uni-tue-kn/p4-lfa
def init_switches(controller=None, topology_controller=None, pd=None):
    """
    Connect to switches and set forwarding pipeline
    :param controller: base controller who handles connections
    :param topology_controller: topology controller, who will send topology packets
    :return:
    """
    controller.connect_and_arbitrate(grpc_port=Configuration.get('grpc_port'), device_id=Configuration.get('device_id'))
    controller.set_forwarding_pipeline_config()

    try:
        pd.setPorts(Configuration.get("ports"))
        pd.setFlood(Configuration.get("ports"))
        pd.setPortMonitor(Configuration.get("ports"))
        pd.configureTopologyPackets()
    except Exception as e:
        Log.error(e)

    Configuration.set('system_done', True)
コード例 #4
0
    def connect(self):
        """
        All switches grpc addresses are in ascending order.
        Connect until a connection can't be established
        :return:
        """

        for switch in Configuration.get("switches"):
            try:
                self.__connections[switch["name"]] = SwitchConnection(
                    grpc_address='127.0.0.1:{0}'.format(
                        switch["local_controller_port"]))
                Log.async_debug("Connected to controller on port",
                                switch["local_controller_port"])
                Event.trigger('switch_connected', name=switch["name"])
            except grpc.RpcError as e:
                raise SwitchConnectionFailed(switch["name"],
                                             switch["local_controller_port"])

        Log.async_info("Connected to", len(self.__connections), "controller")
        Configuration.set('connected', True)
コード例 #5
0
ファイル: controller.py プロジェクト: uni-tue-kn/p4-bier
def main():
    Configuration.set('system_done', False)

    # without this line, no events would be fired, no topology discovered and no entries computed
    Event.activate()

    # register event for new switch connections, this will add switches to device list
    Event.on('new_switch_connection', TopologyManager.add_device)

    # base controller
    controller = BaseController()

    # register events for static classes
    Event.on("igmp_packet_in", GroupManager.handle_packet_in)  # handles (un-)sub requests
    Event.on("port_message", TopologyManager.react_to_port_change)
    Event.on("topology_change", TopologyManager.build_domain)

    topology = TopologyController(controller)

    # Create instances of sub controller for CLI
    ipv4 = IPv4Controller(controller)
    bier = BierController(controller)
    #tunnel = TunnelController(controller)

    # add some cli commands for static classes without init
    CLI.add_command("plot_topology", TopologyManager.plot, "Plot topology")
    CLI.add_command("describe_topology", TopologyManager.describe, "Describe topology")
    CLI.add_command("describe_groups", GroupManager.describe, "Describe groups")
    CLI.add_command("show_configuration", Configuration.show_all, "Show all configurations")
    CLI.add_command("table_manager", TableEntryManager.handle_cli_command, "show_tables <controller name>")

    CLI.add_command("load_static_rules", load_static_rules, "Load static rules", ipv4)

    # start global grpc control server
    GRPCServer(listen_port=Configuration.get('listen_port')).start()

    # start connection procedure in thread, so that cli will get initialized and logs can be printed
    threading.Timer(2, connect_to_switches, kwargs={'controller': controller}).start()

    CLI.start_cli()
コード例 #6
0
    def connect_and_arbitrate(self, grpc_port=0, device_id=0):
        """
        Connect and arbitrate to the switch
        :param grpc_port: grpc port of the p4 switch
        :param device_id: device id of the p4 switch
        :return:
        """

        i = Configuration.get('bfr_id')
        
        try:
            # add connection to switch
            self.__connection = self.__add_switch_connection(name='s{0}'.format(i),
                                                             address='127.0.0.1:{0}'.format(grpc_port),
                                                             device_id=device_id)

            # start packet in thread
            self.__connection.start_thread()

            if self.__connection.MasterArbitrationUpdate():
                base_mac = int('20:00:00:00:00:00'.translate(None, ":,-"), 16)
                real_mac = format(base_mac + i, 'x')
                mac = ":".join(real_mac[i:i + 2] for i in range(0, len(real_mac), 2))

                Configuration.set('name', 's{0}'.format(i).encode('utf-8'))

                Event.trigger("new_switch_connection", name='s{0}'.format(i),
                              device=Switch(name='s{0}'.format(i).encode('utf-8'), ip='20.0.{0}.0'.format(i).encode('utf-8'),
                                            mac=mac.encode('utf-8'), bfr_id=i))

                Log.info("Arbitration done. Connected to swtich")
                Event.trigger("arbitration_done")
            else:
                Log.error("Master arbitration failed")


        except Exception as e:
            Log.error(e)