Example #1
0
 def CreateSession(
     self,
     request: CreateSessionRequest,
     context,
 ) -> CreateSessionResponse:
     """
     Handles create session request from MME by installing the necessary
     flows in pipelined's enforcement app.
     """
     logging.info('Creating a session for subscriber ID: %s',
                  request.subscriber.id)
     return CreateSessionResponse(
         credits=[],
         static_rules=self._get_static_rules(),
         dynamic_rules=[],
     )
Example #2
0
 def CreateSession(
     self,
     request: CreateSessionRequest,
     context,
 ) -> CreateSessionResponse:
     """
     Handles create session request from MME by installing the necessary
     flows in pipelined's enforcement app.
     """
     imsi = request.subscriber.id
     logging.info('Creating a session for subscriber ID: %s', imsi)
     return CreateSessionResponse(
         credits=self._get_credits(imsi),
         static_rules=self._get_rules_for_imsi(imsi),
         dynamic_rules=self._get_default_dynamic_rules(imsi),
         session_id=request.session_id,
     )
Example #3
0
    def CreateSession(
        self,
        request: CreateSessionRequest,
        context,
    ) -> CreateSessionResponse:
        """
        Handles create session request from MME by installing the necessary
        flows in pipelined's enforcement app.

        NOTE: leave the 'IMSI' prefix
        """
        imsi = request.common_context.sid.id
        apn = request.common_context.apn
        logging.info('Creating a session for subscriber ID: %s', imsi)
        return CreateSessionResponse(
            credits=self._get_credits(imsi),
            static_rules=self._get_session_static_rules(imsi, apn),
            dynamic_rules=self._get_default_dynamic_rules(imsi, apn),
            session_id=request.session_id,
        )
Example #4
0
    def test_reauth(self):
        """
        Send a Gx reauth request which installs one new static rule, one new
        dynamic rule, and removes one static and one dynamic rule.
        """
        dynamic_rule1 = create_uplink_rule('dynamic1',
                                           1,
                                           '46.10.10.1',
                                           tracking=PolicyRule.NO_TRACKING)
        dynamic_rule2 = create_uplink_rule('dynamic2',
                                           1,
                                           '46.10.10.2',
                                           tracking=PolicyRule.NO_TRACKING)

        # Initialize sub with 1 static and 1 dynamic rule
        sub = SubContextConfig('IMSI001010000088888', '192.168.128.74',
                               default_ambr_config, 4)
        self.test_util.controller.mock_create_session = Mock(
            return_value=CreateSessionResponse(
                credits=[create_update_response(sub.imsi, 1, 1024)],
                static_rules=[
                    session_manager_pb2.StaticRuleInstall(rule_id='policy1')
                ],
                dynamic_rules=[
                    session_manager_pb2.DynamicRuleInstall(
                        policy_rule=dynamic_rule1)
                ],
                usage_monitors=[],
            ), )
        self.test_util.controller.mock_terminate_session = Mock(
            return_value=SessionTerminateResponse(), )
        self.test_util.sessiond.CreateSession(
            LocalCreateSessionRequest(
                sid=SubscriberID(id=sub.imsi),
                ue_ipv4=sub.ip,
            ))
        self.assertEqual(
            self.test_util.controller.mock_create_session.call_count,
            1,
        )

        # first, send some packets so we know that the uplink rules are
        # accepting traffic
        self._assert_rules(
            sub,
            [
                session_manager_pb2.DynamicRuleInstall(
                    policy_rule=self.test_util.static_rules['policy1']),
                session_manager_pb2.DynamicRuleInstall(
                    policy_rule=dynamic_rule1)
            ],
        )

        # Now via reauth, remove the old rules and install new uplink rules
        # Verify the new uplink rules allow traffic
        reauth_result = self.test_util.proxy_responder.PolicyReAuth(
            PolicyReAuthRequest(
                imsi=sub.imsi,
                rules_to_remove=['dynamic1', 'policy1'],
                rules_to_install=[
                    session_manager_pb2.StaticRuleInstall(rule_id='policy2')
                ],
                dynamic_rules_to_install=[
                    session_manager_pb2.DynamicRuleInstall(
                        policy_rule=dynamic_rule2)
                ],
            ))
        self.assertEqual(
            reauth_result.result,
            session_manager_pb2.UPDATE_INITIATED,
        )
        self.assertEqual(len(reauth_result.failed_rules), 0)
        self._assert_rules(
            sub,
            [
                session_manager_pb2.DynamicRuleInstall(
                    policy_rule=self.test_util.static_rules['policy2']),
                session_manager_pb2.DynamicRuleInstall(
                    policy_rule=dynamic_rule2)
            ],
        )

        # Verify the old rules no longer allow traffic (uninstalled)
        self._assert_rules(
            sub,
            [
                session_manager_pb2.DynamicRuleInstall(
                    policy_rule=self.test_util.static_rules['policy1']),
                session_manager_pb2.DynamicRuleInstall(
                    policy_rule=dynamic_rule1)
            ],
            expected=0,
        )