Exemple #1
0
    def packet_in_handler(self, event):
        """Handle when a packet is received."""
        LOGGER.info('New packet_in received.')
        msg = event.msg
        datapath = msg.datapath
        dpid = dpid_to_str(datapath.id)
        in_port = str(msg.match['in_port'])
        packet = InceptionPacket(msg.data)
        packet.serialize()
        packet_data = packet.data.decode('Latin-1').encode('Latin-1')
        pkt_digest = md5.new(packet_data).digest()

        if self.zk_manager.is_master():
            # master role
            # First finish all unfinished packet_ins
            self.zk_manager.process_pktin_cache()
            try:
                # Logging in zookeeper
                pktin_log = i_util.tuple_to_str((dpid, in_port))
                self.zk_manager.add_packetin_log(pktin_log, packet_data)
                self.process_packet_in(dpid, in_port, packet)
                # Enqueue packet so that other controllers
                # can dump the corresponding packet
                self.zk_manager.enqueue(pkt_digest)
                # Delete log after task is finished
                self.zk_manager.del_packetin_log(pktin_log)
            except Exception:
                LOGGER.warning("Unexpected exception in packet handler %s",
                               traceback.format_exc())
        else:
            # slave role
            LOGGER.info('Cache packet_in message from (dpid=%s, in_port=%s)',
                        dpid, in_port)
            self.zk_manager.add_pktin(pkt_digest, dpid, in_port, packet)
Exemple #2
0
    def packet_in_handler(self, event):
        """Handle when a packet is received."""
        LOGGER.info('New packet_in received.')
        msg = event.msg
        datapath = msg.datapath
        dpid = dpid_to_str(datapath.id)
        in_port = str(msg.match['in_port'])
        packet = InceptionPacket(msg.data)
        packet.serialize()
        packet_data = packet.data.decode('Latin-1').encode('Latin-1')
        pkt_digest = md5.new(packet_data).digest()

        if self.zk_manager.is_master():
            # master role
            # First finish all unfinished packet_ins
            self.zk_manager.process_pktin_cache()
            try:
                # Logging in zookeeper
                pktin_log = i_util.tuple_to_str((dpid, in_port))
                self.zk_manager.add_packetin_log(pktin_log, packet_data)
                self.process_packet_in(dpid, in_port, packet)
                # Enqueue packet so that other controllers
                # can dump the corresponding packet
                self.zk_manager.enqueue(pkt_digest)
                # Delete log after task is finished
                self.zk_manager.del_packetin_log(pktin_log)
            except Exception:
                LOGGER.warning("Unexpected exception in packet handler %s",
                               traceback.format_exc())
        else:
            # slave role
            LOGGER.info('Cache packet_in message from (dpid=%s, in_port=%s)',
                        dpid, in_port)
            self.zk_manager.add_pktin(pkt_digest, dpid, in_port, packet)
Exemple #3
0
 def do_rpc(self, func_name, rpc_id, arguments):
     LOGGER.info("RPC: %s", func_name)
     znode = i_util.tuple_to_str((func_name, rpc_id))
     self.zk_manager.add_rpc_log(znode, arguments)
     txn = self.zk_manager.create_transaction()
     func = getattr(self, func_name)
     func(txn, *arguments)
     self.zk_manager.del_rpc_log(znode, txn)