Beispiel #1
0
 def receive_proxied_message(self, proxy_address, msg):
     self.log.debug('receive-proxied-message', proxy_address=proxy_address,
              device_id=proxy_address.device_id, msg=hexify(msg))
     # Device_id from the proxy_address is the olt device id. We need to
     # get the onu device id using the port number in the proxy_address
     device = self.core_proxy. \
         get_child_device_with_proxy_address(proxy_address)
     if device:
         handler = self.devices_handlers[device.id]
         handler.receive_message(msg)
Beispiel #2
0
    def packet_out(self, egress_port, msg):
        self.log.info('sending-packet-out',
                      egress_port=egress_port,
                      msg=hexify(msg))
        try:
            pkt = Ether(msg)
            out_pkt = pkt
            if egress_port != self.nni_port.port_no:
                # don't do the vlan manipulation for the NNI port, vlans are already correct
                out_pkt = (Ether(src=pkt.src, dst=pkt.dst) /
                           Dot1Q(vlan=egress_port, type=pkt.type) /
                           pkt.payload)

            # TODO need better way of mapping logical ports to PON ports
            out_port = self.nni_port.port_no if egress_port == self.nni_port.port_no else 1

            # send over grpc stream
            stub = PonSimStub(self.channel)
            frame = PonSimFrame(id=self.device_id,
                                payload=str(out_pkt),
                                out_port=out_port)
            stub.SendFrame(frame)
        except Exception as e:
            self.log.exception("error-processing-packet-out", e=e)
Beispiel #3
0
    def _send_next_request(self, high_priority):
        """
        Pull next tx request and send it

        :param high_priority: (bool) True if this was a high priority request
        :return: results, so callback chain continues if needed
        """
        index = self._get_priority_index(high_priority)

        if self._tx_request[
                index] is None:  # TODO or self._tx_request[index][OMCI_CC.REQUEST_DEFERRED].called:
            d = None
            try:
                if len(self._pending[index]) and \
                        not self._ok_to_send(self._pending[index][0][OMCI_CC.PENDING_FRAME],
                                             high_priority):
                    reactor.callLater(0.05, self._send_next_request,
                                      high_priority)
                    return

                next_frame = self._pending[index].pop(0)

                d = next_frame[OMCI_CC.PENDING_DEFERRED]
                frame = next_frame[OMCI_CC.PENDING_FRAME]
                timeout = next_frame[OMCI_CC.PENDING_TIMEOUT]
                retry = next_frame[OMCI_CC.PENDING_RETRY]

                tx_tid = frame.fields['transaction_id']

                # NOTE: Since we may need to do an independent ME map on a per-ONU basis
                #       save the current value of the entity_id_to_class_map, then
                #       replace it with our custom one before decode, and then finally
                #       restore it later. Tried other ways but really made the code messy.
                saved_me_map = omci_entities.entity_id_to_class_map
                omci_entities.entity_id_to_class_map = self._me_map

                ts = arrow.utcnow().float_timestamp
                try:
                    self._rx_response[index] = None

                    omci_msg = InterAdapterOmciMessage(
                        message=hexify(str(frame)))

                    self.log.debug('inter-adapter-send-omci',
                                   omci_msg=omci_msg)

                    yield self._adapter_proxy.send_inter_adapter_message(
                        msg=omci_msg,
                        type=InterAdapterMessageType.OMCI_REQUEST,
                        from_adapter=self._device.type,
                        to_adapter=self._proxy_address.device_type,
                        to_device_id=self._device_id,
                        proxy_device_id=self._proxy_address.device_id)

                finally:
                    omci_entities.entity_id_to_class_map = saved_me_map

                self._tx_frames += 1

                # Note: the 'd' deferred in the queued request we just got will
                # already have its success callback queued (callLater -> 0) with a
                # result of "queued".  Here we need time it out internally so
                # we can call cleanup appropriately. G.988 mentions that most ONUs
                # will process an request in < 1 second.
                dc_timeout = timeout if timeout > 0 else 1.0

                # Timeout on internal deferred to support internal retries if requested
                dc = self.reactor.callLater(dc_timeout, self._request_timeout,
                                            tx_tid, high_priority)

                # (timestamp, defer, frame, timeout, retry, delayedCall)
                self._tx_request[index] = (ts, d, frame, timeout, retry, dc)

                if timeout > 0:
                    d.addCallbacks(self._request_success,
                                   self._request_failure,
                                   callbackArgs=(high_priority, ),
                                   errbackArgs=(tx_tid, high_priority))

            except IndexError:
                pass  # Nothing pending in this queue

            except Exception as e:
                self.log.exception('send-proxy-exception', e=e)
                self._tx_request[index] = None
                self.reactor.callLater(0, self._send_next_request,
                                       high_priority)

                if d is not None:
                    d.errback(failure.Failure(e))
        else:
            self.log.debug("tx-request-occupied", index=index)