Пример #1
0
    def test_ul_answer_s6a_error(self):
        """
        Test that gRPC UpdateLocation response with S6a error triggers Diameter ULA error response
        """
        state_id = 1
        user_name = '1'
        visited_plmn_id = b'(Y'
        ulr_flags = 1 << 2 | 1 << 5
        req = self._update_location_req(user_name, visited_plmn_id, ulr_flags)

        # Encode request message into buffer
        req_buf = bytearray(req.length)
        req.encode(req_buf, 0)

        result_info = avp.AVP('Experimental-Result', [
            avp.AVP('Vendor-Id', 10415),
            avp.AVP('Experimental-Result-Code',
                    avp.ResultCode.DIAMETER_ERROR_USER_UNKNOWN)
        ])
        resp = self._server._s6a_manager._gen_response(
            state_id, req, avp.ResultCode.DIAMETER_ERROR_USER_UNKNOWN,
            [result_info])
        resp_buf = bytearray(resp.length)
        resp.encode(resp_buf, 0)

        result = UpdateLocationAnswer(
            error_code=ErrorCode.Value('USER_UNKNOWN'), )
        result_future = unittest.mock.Mock()
        result_future.exception.side_effect = [None]
        result_future.result.side_effect = [result]

        self._server._s6a_manager._relay_update_location_answer(
            state_id, req, result_future, 0)
        self._writes.assert_called_once_with(resp_buf)
        self._writes.reset_mock()
Пример #2
0
    def test_location_update_resp(self):
        """
        Test that gRPC UpdateLocation success response triggers Diameter ULA success
        """
        state_id = 1
        user_name = '1'
        visited_plmn_id = b'(Y'
        ulr_flags = 1 << 2 | 1 << 5
        default_context_id = 0
        total_ambr = {'ul': 10000, 'dl': 50000}
        all_apns_included = True
        req = self._update_location_req(user_name, visited_plmn_id, ulr_flags)

        # Encode request message into buffer
        req_buf = bytearray(req.length)
        req.encode(req_buf, 0)

        apns = [{
            'context_id': i,
            'service_selection': 'apn.%d' % i,
            'qos_profile': {
                'class_id': i,
                'priority_level': i,
                'preemption_capability': True if i % 2 else False,
                'preemption_vulnerability': False if i % 2 else True,
            },
            'ambr': {
                'ul': 1000 * i,
                'dl': 2000 * i,
            },
        } for i in range(2)]

        resp_avps = [
            avp.AVP('ULA-Flags', 1),
            avp.AVP(
                'Subscription-Data',
                [
                    avp.AVP('MSISDN', b'333608050011'),
                    avp.AVP('Access-Restriction-Data', 47),
                    avp.AVP('Subscriber-Status', 0),
                    avp.AVP('Network-Access-Mode', 2),
                    avp.AVP(
                        'AMBR',
                        [
                            avp.AVP(
                                'Max-Requested-Bandwidth-UL',
                                total_ambr['ul'],
                            ),
                            avp.AVP(
                                'Max-Requested-Bandwidth-DL',
                                total_ambr['dl'],
                            ),
                        ],
                    ),
                    avp.AVP(
                        'APN-Configuration-Profile',
                        [
                            avp.AVP('Context-Identifier', default_context_id),
                            avp.AVP(
                                'All-APN-Configurations-Included-Indicator',
                                1 if all_apns_included else 0,
                            ),
                            *[
                                avp.AVP(
                                    'APN-Configuration',
                                    [
                                        avp.AVP(
                                            'Context-Identifier',
                                            apn['context_id'],
                                        ),
                                        avp.AVP('PDN-Type', 0),
                                        avp.AVP(
                                            'Service-Selection',
                                            apn['service_selection'],
                                        ),
                                        avp.AVP(
                                            'EPS-Subscribed-QoS-Profile',
                                            [
                                                avp.AVP(
                                                    'QoS-Class-Identifier',
                                                    apn['qos_profile']
                                                    ['class_id'],
                                                ),
                                                avp.AVP(
                                                    'Allocation-Retention-Priority',
                                                    [
                                                        avp.AVP(
                                                            'Priority-Level',
                                                            apn['qos_profile']
                                                            ['priority_level'],
                                                        ),
                                                        avp.AVP(
                                                            'Pre-emption-Capability',
                                                            apn['qos_profile']
                                                            ['preemption_capability'],
                                                        ),
                                                        avp.AVP(
                                                            'Pre-emption-Vulnerability',
                                                            apn['qos_profile']
                                                            ['preemption_vulnerability'],
                                                        ),
                                                    ],
                                                ),
                                            ],
                                        ),
                                        avp.AVP(
                                            'AMBR',
                                            [
                                                avp.AVP(
                                                    'Max-Requested-Bandwidth-UL',
                                                    apn['ambr']['ul'],
                                                ),
                                                avp.AVP(
                                                    'Max-Requested-Bandwidth-DL',
                                                    apn['ambr']['dl'],
                                                ),
                                            ],
                                        ),
                                    ],
                                ) for apn in apns
                            ],
                        ],
                    ),
                ],
            ),
        ]
        resp = self._server._s6a_manager._gen_response(
            state_id,
            req,
            avp.ResultCode.DIAMETER_SUCCESS,
            resp_avps,
        )
        resp_buf = bytearray(resp.length)
        resp.encode(resp_buf, 0)

        result = UpdateLocationAnswer(
            error_code=0,
            default_context_id=default_context_id,
            total_ambr=UpdateLocationAnswer.AggregatedMaximumBitrate(
                max_bandwidth_ul=total_ambr['ul'],
                max_bandwidth_dl=total_ambr['dl'],
            ),
            msisdn=b'333608050011',
            all_apns_included=all_apns_included,
            apn=[
                UpdateLocationAnswer.APNConfiguration(
                    context_id=apn['context_id'],
                    service_selection=apn['service_selection'],
                    qos_profile=UpdateLocationAnswer.APNConfiguration.
                    QoSProfile(
                        class_id=apn['qos_profile']['class_id'],
                        priority_level=apn['qos_profile']['priority_level'],
                        preemption_capability=apn['qos_profile']
                        ['preemption_capability'],
                        preemption_vulnerability=apn['qos_profile']
                        ['preemption_vulnerability'],
                    ),
                    ambr=UpdateLocationAnswer.AggregatedMaximumBitrate(
                        max_bandwidth_ul=apn['ambr']['ul'],
                        max_bandwidth_dl=apn['ambr']['dl'],
                    ),
                    pdn=UpdateLocationAnswer.APNConfiguration.IPV4,
                ) for apn in apns
            ],
        )
        result_future = unittest.mock.Mock()
        result_future.exception.side_effect = [None]
        result_future.result.side_effect = [result]

        self._server._s6a_manager._relay_update_location_answer(
            state_id,
            req,
            result_future,
            0,
        )
        self._writes.assert_called_once_with(resp_buf)
        self._writes.reset_mock()