예제 #1
0
 def ingress(self, io_port, frame):
     port = self.iface_name_to_port.get(io_port.iface_name)
     log.debug('ingress', port=port, iface_name=io_port.iface_name,
               frame=hexify(frame))
     decoded_frame = Ether(frame)
     if self.ponsim is not None:
         self.ponsim.ingress(port, decoded_frame)
예제 #2
0
    def send_packet_in(self, logical_device_id, logical_port_no, packet):
        self.log.debug('send-packet-in', logical_device_id=logical_device_id,
                       logical_port_no=logical_port_no, packet=hexify(packet))

        if isinstance(packet, Packet):
            packet = str(packet)

        topic = 'packet-in:' + logical_device_id
        self.event_bus.publish(topic, (logical_port_no, packet))
예제 #3
0
파일: omci_cc.py 프로젝트: zychen123/voltha
    def _receive_onu_message(self, rx_frame):
        """ Autonomously generated ONU frame Rx handler"""
        from twisted.internet.defer import QueueOverflow
        self.log.debug('rx-onu-frame',
                       frame_type=type(rx_frame),
                       frame=hexify(str(rx_frame)))

        # TODO: Signal, via defer if Alarm Overflow or just an event?
        msg_type = rx_frame.fields['message_type']

        self._rx_onu_frames += 1

        msg = {TX_REQUEST_KEY: None, RX_RESPONSE_KEY: rx_frame}

        if msg_type == EntityOperations.AlarmNotification.value:
            topic = OMCI_CC.event_bus_topic(self._device_id,
                                            RxEvent.Alarm_Notification)
            reactor.callLater(0, self.event_bus.publish, topic, msg)
            try:
                self._alarm_queue.put(
                    (rx_frame, arrow.utcnow().float_timestamp))

            except QueueOverflow:
                self._rx_alarm_overflow += 1
                self.log.warn('onu-rx-alarm-overflow',
                              cnt=self._rx_alarm_overflow)

        elif msg_type == EntityOperations.AttributeValueChange.value:
            topic = OMCI_CC.event_bus_topic(self._device_id,
                                            RxEvent.AVC_Notification)
            reactor.callLater(0, self.event_bus.publish, topic, msg)
            try:
                self._alarm_queue.put(
                    (rx_frame, arrow.utcnow().float_timestamp))

            except QueueOverflow:
                self._rx_avc_overflow += 1
                self.log.warn('onu-rx-avc-overflow', cnt=self._rx_avc_overflow)

        elif msg_type == EntityOperations.TestResult.value:
            topic = OMCI_CC.event_bus_topic(self._device_id,
                                            RxEvent.Test_Result)
            reactor.callLater(0, self.event_bus.publish, topic, msg)
            try:
                self._test_results_queue.put(
                    (rx_frame, arrow.utcnow().float_timestamp))

            except QueueOverflow:
                self.log.warn('onu-rx-test-results-overflow')

        else:
            # TODO: Need to add test results message support
            self.log.warn('onu-unsupported-autonomous-message', type=msg_type)
            self._rx_onu_discards += 1
예제 #4
0
    def send_packet_in(self, logical_device_id, logical_port_no, packet):
        self.log.debug('send-packet-in',
                       logical_device_id=logical_device_id,
                       logical_port_no=logical_port_no,
                       packet=hexify(packet))

        if isinstance(packet, Packet):
            packet = str(packet)

        topic = 'packet-in:' + logical_device_id
        self.event_bus.publish(topic, (logical_port_no, packet))
예제 #5
0
 def remote_echo(self, pkt_type, pon, onu, port, crc_ok, msg_size,
                 msg_data):
     log.info('received-omci-msg',
              pkt_type=pkt_type,
              pon_id=pon,
              onu_id=onu,
              port_id=port,
              crc_ok=crc_ok,
              msg_size=msg_size,
              msg_data=hexify(msg_data))
     self.omci_rx_queue.put((onu, msg_data))
예제 #6
0
 def packet_out(self, egress_port, msg):
     self.log.info('sending-packet-out', egress_port=egress_port,
                   msg=hexify(msg))
     pkt = Ether(msg)
     out_pkt = (
         Ether(src=pkt.src, dst=pkt.dst) /
         Dot1Q(vlan=4000) /
         Dot1Q(vlan=egress_port, type=pkt.type) /
         pkt.payload
     )
     self.io_port.send(str(out_pkt))
    def packet_out(self, egress_port, msg):
        self.log.info('sending-packet-out',
                      egress_port=egress_port,
                      msg=hexify(msg))
        pkt = Ether(msg)
        out_pkt = (Ether(src=pkt.src, dst=pkt.dst) /
                   Dot1Q(vlan=PACKET_IN_VLAN) /
                   Dot1Q(vlan=egress_port, type=pkt.type) / pkt.payload)

        # TODO: Need to retrieve the correct destination onu_id
        self.bal.packet_out(1, egress_port, str(out_pkt))
예제 #8
0
 def receive_proxied_message(self, proxy_address, msg):
     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.adapter_agent. \
         get_child_device_with_proxy_address(proxy_address)
     if device:
         handler = self.devices_handlers[device.id]
         handler.receive_message(msg)
예제 #9
0
    def send(self, frame, timeout=DEFAULT_OMCI_TIMEOUT):
        """
        Send the OMCI Frame to the ONU via the proxy_channel

        :param frame: (OMCIFrame) Message to send
        :param timeout: (int) Rx Timeout. 0=Forever
        :return: (deferred) A deferred that fires when the response frame is received
                            or if an error/timeout occurs
        """
        self.flush(max_age=MAX_OMCI_REQUEST_AGE)

        assert timeout <= MAX_OMCI_REQUEST_AGE, \
            'Maximum timeout is {} seconds'.format(MAX_OMCI_REQUEST_AGE)
        assert isinstance(frame, OmciFrame), \
            "Invalid frame class '{}'".format(type(frame))

        if not self.enabled or self._proxy_address is None:
            # TODO custom exceptions throughout this code would be helpful
            return fail(
                result=failure.Failure(Exception('OMCI is not enabled')))

        try:
            tx_tid = frame.fields['transaction_id']
            if tx_tid is None:
                tx_tid = self._get_tx_tid()
                frame.fields['transaction_id'] = tx_tid

            assert tx_tid not in self._requests, 'TX TID {} is already exists'.format(
                tx_tid)
            assert tx_tid >= 0, 'Invalid Tx TID: {}'.format(tx_tid)

            ts = arrow.utcnow().float_timestamp
            d = defer.Deferred()

            self._adapter_agent.send_proxied_message(self._proxy_address,
                                                     hexify(str(frame)))
            self._tx_frames += 1
            self._requests[tx_tid] = (ts, d, frame, timeout)

            d.addCallbacks(self._request_success,
                           self._request_failure,
                           errbackArgs=(tx_tid, ))

            if timeout > 0:
                d.addTimeout(timeout, reactor)

        except Exception as e:
            self._tx_errors += 1
            self._consecutive_errors += 1
            self.log.exception('send-omci', e=e)
            return fail(result=failure.Failure(e))

        return d
예제 #10
0
    def receive_packet_out(self, logical_device_id, ofp_packet_out):
        def get_port_out(opo):
            for action in opo.actions:
                if action.type == OUTPUT:
                    return action.output.port

        out_port = get_port_out(ofp_packet_out)
        frame = ofp_packet_out.data
        self.log.debug('rcv-packet-out',
                       logical_device_id=logical_device_id,
                       egress_port_no=out_port,
                       adapter_name=self.adapter_name,
                       data=hexify(ofp_packet_out.data))
        self.adapter.receive_packet_out(logical_device_id, out_port, frame)
예제 #11
0
    def packet_out(self, egress_port, msg):
        self.log.info('sending-packet-out',
                      egress_port=egress_port,
                      msg=hexify(msg))
        pkt = Ether(msg)
        out_pkt = (Ether(src=pkt.src, dst=pkt.dst) / Dot1Q(vlan=4000) /
                   Dot1Q(vlan=egress_port, type=pkt.type) / pkt.payload)

        if self.ponsim_comm == 'grpc':
            # send over grpc stream
            stub = ponsim_pb2.PonSimStub(self.get_channel())
            frame = PonSimFrame(id=self.device_id, payload=str(out_pkt))
            stub.SendFrame(frame)
        else:
            # send over frameio
            self.io_port.send(str(out_pkt))
예제 #12
0
    def packet_out(self, egress_port, msg):
        self.log.debug('sending-packet-out', egress_port=egress_port,
                       msg_hex=hexify(msg))
        pkt = Ether(msg)
        out_pkt = pkt
        self.log.debug("packet_out: incoming: %s" % pkt.summary())
        if egress_port != self.nni_port.port_no:
            # don't do the vlan manipulation for the NNI port, vlans are already correct
            if pkt.haslayer(Dot1Q):
                if pkt.haslayer(Dot1AD):
                    outer_shim = pkt.getlayer(Dot1AD)
                else:
                    outer_shim = pkt.getlayer(Dot1Q)
                if isinstance(outer_shim.payload, Dot1Q):
                    # If double tag, remove the outer tag
                    out_pkt = (
                            Ether(src=pkt.src, dst=pkt.dst,
                                  type=outer_shim.type) /
                            outer_shim.payload
                    )
                else:
                    out_pkt = pkt
            else:
                # Add egress port as VLAN tag
                out_pkt = (
                    Ether(src=pkt.src, dst=pkt.dst) /
                    Dot1Q(vlan=egress_port, type=pkt.type) /
                    pkt.payload
                )
        self.log.debug("packet_out: outgoing: %s" % out_pkt.summary())

        # 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

        if self.ponsim_comm == 'grpc':
            # send over grpc stream
            stub = ponsim_pb2_grpc.PonSimStub(self.get_channel())
            frame = PonSimFrame(id=self.device_id, payload=str(out_pkt), out_port=out_port)
            stub.SendFrame(frame)
        else:
            # send over frameio
            self.io_port.send(str(out_pkt))
예제 #13
0
    def _receive_onu_message(self, rx_frame):
        """ Autonomously generated ONU frame Rx handler"""
        from twisted.internet.defer import QueueOverflow

        self.log.debug('rx-onu-frame',
                       frame_type=type(rx_frame),
                       frame=hexify(str(rx_frame)))

        # TODO: Signal, via defer if Alarm Overflow or just an event?
        msg_type = rx_frame.fields['message_type']

        self._rx_onu_frames += 1

        if msg_type == EntityOperations.AlarmNotification:
            try:
                self._alarm_queue.put(
                    (rx_frame, arrow.utcnow().float_timestamp))

            except QueueOverflow:
                self._rx_alarm_overflow += 1
                self.log.warn('onu-rx-alarm-overflow',
                              cnt=self._rx_alarm_overflow)

        elif msg_type == EntityOperations.AttributeValueChange:
            try:
                self._alarm_queue.put(
                    (rx_frame, arrow.utcnow().float_timestamp))

            except QueueOverflow:
                self._rx_avc_overflow += 1
                self.log.warn('onu-rx-avc-overflow', cnt=self._rx_avc_overflow)
        else:
            # TODO: Need to add test results message support

            self.log.warn('onu-unsupported-autonomous-message', type=msg_type)
            self._rx_onu_discards += 1
예제 #14
0
    def packet_out(self, egress_port, msg):
        self.log.debug('sending-packet-out',
                       egress_port=egress_port,
                       msg_hex=hexify(msg))
        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

        if self.ponsim_comm == 'grpc':
            # send over grpc stream
            stub = ponsim_pb2.PonSimStub(self.get_channel())
            frame = PonSimFrame(id=self.device_id,
                                payload=str(out_pkt),
                                out_port=out_port)
            stub.SendFrame(frame)
        else:
            # send over frameio
            self.io_port.send(str(out_pkt))
예제 #15
0
파일: omci_cc.py 프로젝트: vipul2690/voltha
    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
                    self._adapter_agent.send_proxied_message(self._proxy_address,
                                                             hexify(str(frame)))
                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)
예제 #16
0
    def send(self, frame, timeout=DEFAULT_OMCI_TIMEOUT):
        """
        Send the OMCI Frame to the ONU via the proxy_channel

        :param frame: (OMCIFrame) Message to send
        :param timeout: (int) Rx Timeout. 0=Forever
        :return: (deferred) A deferred that fires when the response frame is received
                            or if an error/timeout occurs
        """
        self.flush(max_age=MAX_OMCI_REQUEST_AGE)

        assert timeout <= MAX_OMCI_REQUEST_AGE, \
            'Maximum timeout is {} seconds'.format(MAX_OMCI_REQUEST_AGE)
        assert isinstance(frame, OmciFrame), \
            "Invalid frame class '{}'".format(type(frame))

        if not self.enabled or self._proxy_address is None:
            # TODO custom exceptions throughout this code would be helpful
            return fail(result=failure.Failure(Exception('OMCI is not enabled')))

        try:
            tx_tid = frame.fields['transaction_id']
            if tx_tid is None:
                tx_tid = self._get_tx_tid()
                frame.fields['transaction_id'] = tx_tid

            assert tx_tid not in self._requests, 'TX TID {} is already exists'.format(tx_tid)
            assert tx_tid >= 0, 'Invalid Tx TID: {}'.format(tx_tid)

            ts = arrow.utcnow().float_timestamp
            d = defer.Deferred()

            # 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
            try:
                self._adapter_agent.send_proxied_message(self._proxy_address,
                                                         hexify(str(frame)))
            finally:
                omci_entities.entity_id_to_class_map = saved_me_map

            self._tx_frames += 1
            self._requests[tx_tid] = (ts, d, frame, timeout)

            d.addCallbacks(self._request_success, self._request_failure,
                           errbackArgs=(tx_tid,))

            if timeout > 0:
                d.addTimeout(timeout, reactor)

        except Exception as e:
            self._tx_errors += 1
            self._consecutive_errors += 1

            if self._consecutive_errors == 1:
                reactor.callLater(0, self._publish_connectivity_event, False)

            self.log.exception('send-omci', e=e)
            return fail(result=failure.Failure(e))

        return d
예제 #17
0
    def test_rx_table_get_extvlantagging(self):
        self.setup_one_of_each()

        onu = self.onu_handler.onu_mock
        entity_id = 1
        vlan_tag_op1 = VlanTaggingOperation(
            filter_outer_priority=15,
            filter_outer_vid=4096,
            filter_outer_tpid_de=2,
            filter_inner_priority=15,
            filter_inner_vid=4096,
            filter_inner_tpid_de=0,
            filter_ether_type=0,
            treatment_tags_to_remove=0,
            treatment_outer_priority=15,
            treatment_outer_vid=1234,
            treatment_outer_tpid_de=0,
            treatment_inner_priority=0,
            treatment_inner_vid=4091,
            treatment_inner_tpid_de=4,
        )
        vlan_tag_op2 = VlanTaggingOperation(
            filter_outer_priority=14,
            filter_outer_vid=1234,
            filter_outer_tpid_de=5,
            filter_inner_priority=1,
            filter_inner_vid=2345,
            filter_inner_tpid_de=1,
            filter_ether_type=0,
            treatment_tags_to_remove=1,
            treatment_outer_priority=15,
            treatment_outer_vid=2222,
            treatment_outer_tpid_de=1,
            treatment_inner_priority=1,
            treatment_inner_vid=3333,
            treatment_inner_tpid_de=5,
        )
        vlan_tag_op3 = VlanTaggingOperation(
            filter_outer_priority=13,
            filter_outer_vid=55,
            filter_outer_tpid_de=1,
            filter_inner_priority=7,
            filter_inner_vid=4567,
            filter_inner_tpid_de=1,
            filter_ether_type=0,
            treatment_tags_to_remove=1,
            treatment_outer_priority=2,
            treatment_outer_vid=1111,
            treatment_outer_tpid_de=1,
            treatment_inner_priority=1,
            treatment_inner_vid=3131,
            treatment_inner_tpid_de=5,
        )
        tbl = [vlan_tag_op1, vlan_tag_op2, vlan_tag_op3]
        tblstr = str(vlan_tag_op1) + str(vlan_tag_op2) + str(vlan_tag_op3)

        onu._omci_response[OP.Get.value][
            ExtendedVlanTaggingOperationConfigurationData.class_id] = {
                entity_id:
                OmciFrame(
                    transaction_id=0,
                    message_type=OmciGetResponse.message_id,
                    omci_message=OmciGetResponse(
                        entity_class=
                        ExtendedVlanTaggingOperationConfigurationData.class_id,
                        entity_id=1,
                        success_code=RC.Success.value,
                        attributes_mask=
                        ExtendedVlanTaggingOperationConfigurationData.mask_for(
                            'received_frame_vlan_tagging_operation_table'),
                        data={
                            'received_frame_vlan_tagging_operation_table':
                            16 * len(tbl)
                        }))
            }

        rsp1 = binascii.a2b_hex(hexify(tblstr[0:OmciTableField.PDU_SIZE]))
        rsp2 = binascii.a2b_hex(hexify(tblstr[OmciTableField.PDU_SIZE:]))
        onu._omci_response[OP.GetNext.value][
            ExtendedVlanTaggingOperationConfigurationData.class_id] = {
                entity_id: {
                    0: {
                        'failures':
                        2,
                        'frame':
                        OmciFrame(
                            transaction_id=0,
                            message_type=OmciGetNextResponse.message_id,
                            omci_message=OmciGetNextResponse(
                                entity_class=
                                ExtendedVlanTaggingOperationConfigurationData.
                                class_id,
                                entity_id=1,
                                success_code=RC.Success.value,
                                attributes_mask=
                                ExtendedVlanTaggingOperationConfigurationData.
                                mask_for(
                                    'received_frame_vlan_tagging_operation_table'
                                ),
                                data={
                                    'received_frame_vlan_tagging_operation_table':
                                    rsp1
                                }))
                    },
                    1:
                    OmciFrame(
                        transaction_id=0,
                        message_type=OmciGetNextResponse.message_id,
                        omci_message=OmciGetNextResponse(
                            entity_class=
                            ExtendedVlanTaggingOperationConfigurationData.
                            class_id,
                            entity_id=1,
                            success_code=RC.Success.value,
                            attributes_mask=
                            ExtendedVlanTaggingOperationConfigurationData.
                            mask_for(
                                'received_frame_vlan_tagging_operation_table'),
                            data={
                                'received_frame_vlan_tagging_operation_table':
                                rsp2
                            }))
                }
            }

        omci_cc = self.onu_handler.omci_cc
        omci_cc.enabled = True

        msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
            entity_id,
            attributes={'received_frame_vlan_tagging_operation_table': True})

        snapshot = self._snapshot_stats()

        frame = msg.get()
        d = omci_cc.send(frame, timeout=5.0)

        d.addCallbacks(self._is_omci_frame, self._default_errback,
                       [OmciGetResponse])
        d.addCallback(self._check_status, RC.Success)

        d.addCallback(self._check_stats, snapshot, 'tx_frames',
                      snapshot['tx_frames'] + 5)
        d.addCallback(self._check_stats, snapshot, 'rx_frames',
                      snapshot['rx_frames'] + 3)
        d.addCallback(self._check_stats, snapshot, 'rx_unknown_tid',
                      snapshot['rx_unknown_tid'])
        d.addCallback(self._check_stats, snapshot, 'rx_onu_frames',
                      snapshot['rx_onu_frames'])
        d.addCallback(self._check_stats, snapshot, 'rx_onu_discards',
                      snapshot['rx_onu_discards'])
        d.addCallback(self._check_stats, snapshot, 'rx_unknown_me',
                      snapshot['rx_unknown_me'])
        d.addCallback(self._check_stats, snapshot, 'rx_timeouts',
                      snapshot['rx_timeouts'] + 2)
        d.addCallback(self._check_stats, snapshot, 'tx_errors',
                      snapshot['tx_errors'])
        d.addCallback(self._check_stats, snapshot, 'consecutive_errors', 0)
        d.addCallback(self._check_vlan_tag_op,
                      'received_frame_vlan_tagging_operation_table', tbl)

        return d
예제 #18
0
 def packet_in(self, ofp_packet_in):
     self.log.info('packet-in', logical_device_id=self.logical_device_id,
                   pkt=ofp_packet_in, data=hexify(ofp_packet_in.data))
     self.local_handler.send_packet_in(
         self.logical_device_id, ofp_packet_in)
예제 #19
0
파일: realio.py 프로젝트: netsia/voltha_doc
 def egress(self, port, frame):
     if isinstance(frame, Packet):
         frame = str(frame)
     io_port = self.io_ports[port]
     log.debug('sending', port=port, frame=hexify(frame))
     io_port.send(frame)
예제 #20
0
파일: tibit_olt.py 프로젝트: weibit/voltha
    def _rcv_io(self, port, frame):

        log.info('frame-received', frame=hexify(frame))

        # make into frame to extract source mac
        response = Ether(frame)

        if response.haslayer(Dot1Q):

            # All OAM responses from the OLT should have a TIBIT_MGMT_VLAN.
            # Responses from the ONUs should have a TIBIT_MGMT_VLAN followed by a ONU CTAG
            # All packet-in frames will have the TIBIT_PACKET_IN_VLAN.
            if response.getlayer(Dot1Q).type == 0x8100:

                if response.getlayer(Dot1Q).vlan == TIBIT_PACKET_IN_VLAN:

                    inner_tag_and_rest = response.payload.payload

                    if isinstance(inner_tag_and_rest, Dot1Q):

                        cvid = inner_tag_and_rest.vlan

                        frame = Ether(src=response.src,
                                      dst=response.dst,
                                      type=inner_tag_and_rest.type) /\
                                      inner_tag_and_rest.payload

                        _, logical_device_id = self.vlan_to_device_ids.get(cvid)
                        if logical_device_id is None:
                            log.error('invalid-cvid', cvid=cvid)
                        else:
                            self.adapter_agent.send_packet_in(
                                logical_device_id=logical_device_id,
                                logical_port_no=cvid,  # C-VID encodes port no
                                packet=str(frame))

                    else:
                        log.error('packet-in-single-tagged',
                                  frame=hexify(response))

                else:
                    ## Mgmt responses received from the ONU
                    ## Since the type of the first layer is 0x8100,
                    ## then the frame must have an inner tag layer
                    olt_mac = response.src
                    device_id = self.device_ids[olt_mac]
                    channel_id = response[Dot1Q:2].vlan
                    log.info('received_channel_id', channel_id=channel_id,
                             device_id=device_id)

                    proxy_address=Device.ProxyAddress(
                        device_id=device_id,
                        channel_id=channel_id
                        )
                    # pop dot1q header(s)
                    msg = response.payload.payload
                    self.adapter_agent.receive_proxied_message(proxy_address, msg)

            else:
                ## Mgmt responses received from the OLT
                ## enqueue incoming parsed frame to right device
                log.info('received-dot1q-not-8100')
                self.incoming_queues[response.src].put(response)
예제 #21
0
 def receive_message(self, msg):
     self.log.debug('function-entry', msg=hexify(msg))
     if self.omci_cc is not None:
         self.omci_cc.receive_message(msg)
예제 #22
0
파일: chat.py 프로젝트: netsia/voltha_doc
def chat():
    proxy = OmciProxy()
    yield proxy.connect()

    tx_id = [0]

    def get_tx_id():
        tx_id[0] += 1
        return tx_id[0]

    if 0:
        # MIB RESET
        frame = OmciFrame(
            transaction_id=get_tx_id(),
            message_type=OmciMibReset.message_id,
            omci_message=OmciMibReset(entity_class=OntData.class_id))
        yield proxy.send_omci(hexify(str(frame)))

        # MIB RESET RESPONSE
        response = yield proxy.receive()
        resp = OmciFrame(response)
        resp.show()

    if 0:
        # GET ALL ALARMS
        frame = OmciFrame(transaction_id=get_tx_id(),
                          message_type=OmciGetAllAlarms.message_id,
                          omci_message=OmciGetAllAlarms(
                              entity_class=OntData.class_id, entity_id=0))
        yield proxy.send_omci(hexify(str(frame)))

        # MIB UPLOAD RESPONSE
        response = yield proxy.receive()
        resp = OmciFrame(response)
        resp.show()

    if 0:
        # MIB UPLOAD
        frame = OmciFrame(
            transaction_id=get_tx_id(),
            message_type=OmciMibUpload.message_id,
            omci_message=OmciMibUpload(entity_class=OntData.class_id))
        yield proxy.send_omci(hexify(str(frame)))

        # MIB UPLOAD RESPONSE
        response = yield proxy.receive()
        resp = OmciFrame(response)
        resp.show()

        n_commands = resp.omci_message.number_of_commands
        for seq_num in range(n_commands):
            print 'seq_num', seq_num
            frame = OmciFrame(transaction_id=get_tx_id(),
                              message_type=OmciMibUploadNext.message_id,
                              omci_message=OmciMibUploadNext(
                                  entity_class=OntData.class_id,
                                  command_sequence_number=seq_num))
            yield proxy.send_omci(hexify(str(frame)))

            response = yield proxy.receive()
            print hexify(response)
            # resp = OmciFrame(response)
            # resp.show()

    if 1:
        # GET CIRCUIT PACK
        frame = OmciFrame(
            transaction_id=get_tx_id(),
            message_type=OmciGet.message_id,
            omci_message=OmciGet(
                entity_class=CircuitPack.class_id,
                entity_id=0x101,
                attributes_mask=CircuitPack.mask_for('vendor_id')))
        yield proxy.send_omci(hexify(str(frame)))

        # MIB UPLOAD RESPONSE
        response = yield proxy.receive()
        resp = OmciFrame(response)
        resp.show()

    yield asleep(1)
    reactor.stop()
예제 #23
0
 def _deliver_proxy_message(self, proxy_address, response):
     from common.frameio.frameio import hexify
     self._adapter_agent.receive_proxied_message(proxy_address,
                                                 hexify(str(response)))
예제 #24
0
 def receive_proxied_message(self, proxy_address, msg):
     log.info('receive-proxied-message', proxy_address=proxy_address,
              device_id=proxy_address.device_id, msg=hexify(msg))
     handler = self.devices_handlers[proxy_address.channel_id]
     handler.receive_message(msg)
예제 #25
0
 def egress(self, port, frame):
     if isinstance(frame, Packet):
         frame = str(frame)
     io_port = self.io_ports[port]
     log.debug('sending', port=port, frame=hexify(frame))
     io_port.send(frame)
예제 #26
0
    def packet_out_process(self, topic, msg):

        def get_port_out(opo):
            for action in opo.actions:
                if action.type == OUTPUT:
                    return action.output.port

        pb = Parse(loads(msg), ofp.PacketOut(), ignore_unknown_fields=True)

        logical_device_id = pb.id
        ofp_packet_out = pb.packet_out

        self.log.debug("received packet-out form kafka",
                       logical_device_id=logical_device_id,
                       ofp_packet_out=ofp_packet_out)

        egress_port = get_port_out(ofp_packet_out)
        msg = ofp_packet_out.data

        self.log.debug('rcv-packet-out', logical_device_id=logical_device_id,
                       egress_port=egress_port,
                       # adapter_name=self.adapter_name,
                       data=hexify(msg))

        pkt = Ether(msg)
        self.log.debug('packet out', egress_port=egress_port,
                       packet=str(pkt).encode("HEX"))

        # Find port type
        egress_port_type = self.device.platform \
            .intf_id_to_port_type_name(egress_port)

        if egress_port_type == Port.ETHERNET_UNI:

            if pkt.haslayer(Dot1Q):
                outer_shim = pkt.getlayer(Dot1Q)
                if isinstance(outer_shim.payload, Dot1Q):
                    # If double tag, remove the outer tag
                    payload = (
                            Ether(src=pkt.src, dst=pkt.dst,
                                  type=outer_shim.type) /
                            outer_shim.payload
                    )
                else:
                    payload = pkt
            else:
                payload = pkt

            send_pkt = binascii.unhexlify(str(payload).encode("HEX"))

            self.log.debug(
                'sending-packet-to-ONU', egress_port=egress_port,
                intf_id=self.device.platform.intf_id_from_uni_port_num(
                    egress_port),
                onu_id=self.device.platform.onu_id_from_port_num(egress_port),
                uni_id=self.device.platform.uni_id_from_port_num(egress_port),
                port_no=egress_port,
                packet=str(payload).encode("HEX"))

            onu_pkt = openolt_pb2.OnuPacket(
                intf_id=self.device.platform.intf_id_from_uni_port_num(
                    egress_port),
                onu_id=self.device.platform.onu_id_from_port_num(egress_port),
                port_no=egress_port,
                pkt=send_pkt)

            self.device.stub.OnuPacketOut(onu_pkt)

        elif egress_port_type == Port.ETHERNET_NNI:
            self.log.debug('sending-packet-to-uplink', egress_port=egress_port,
                           packet=str(pkt).encode("HEX"))

            send_pkt = binascii.unhexlify(str(pkt).encode("HEX"))

            uplink_pkt = openolt_pb2.UplinkPacket(
                intf_id=self.device.platform.intf_id_from_nni_port_num(
                    egress_port),
                pkt=send_pkt)

            self.device.stub.UplinkPacketOut(uplink_pkt)

        else:
            self.log.warn('Packet-out-to-this-interface-type-not-implemented',
                          egress_port=egress_port,
                          port_type=egress_port_type)
 def packet_in(self, ofp_packet_in):
     self.log.info('packet-in', logical_device_id=self.logical_device_id,
                   pkt=ofp_packet_in, data=hexify(ofp_packet_in.data))
     self.local_handler.send_packet_in(
         self.logical_device_id, ofp_packet_in)