def _create_port_for_controller(self, guest_eth_addr, host_device):
    # Wire up a new port for the switch leading to this controller's io_worker, and
    # The ethernet address we assign to the switch's port shouldn't matter afaict.
    port = ofp_phy_port(port_no=len(self.switch.ports)+1)
    self.switch.bring_port_up(port)

    # Hook up a raw_socket and io_worker for this host_device.
    # TODO(cs): suport pcap filtering as an alternative to raw sockets. Would
    # require us to modify pxpcap to allow us to wrap a non-blocking pcap in
    # an io_worker.
    raw_socket = bind_raw_socket(host_device)
    # Set up an io worker for our end of the socket, and tell it to
    # immediately send packets to the switch.
    # TODO(cs): create_io_worker is a broken reference!
    io_worker = self.create_io_worker(raw_socket)
    # TODO(cs): not sure if this line is strictly needed for the closure.
    switch = self.switch
    def _process_raw_socket_read(io_worker):
      # N.B. raw sockets return exactly one ethernet frame for every read().
      data = io_worker.peek_receive_buf()
      packet = ethernet(bytes(data))
      io_worker.consume_receive_buf(len(data))
      if log.isEnabledFor(logging.DEBUG):
        log.debug("Dequeing packet %s, port %s" % (packet, port))
      switch.process_packet(packet, port.port_no)
    io_worker.set_receive_handler(_process_raw_socket_read)
    self._port2io_worker[port] = io_worker
    return port
dataset/ETHPy150Open ucb-sts/sts/sts/controller_manager.py/UserSpaceControllerPatchPanel._create_port_for_controller/original