Esempio n. 1
0
    def activate_rules(self, imsi, msisdn: bytes, uplink_tunnel: int, ip_addr, apn_ambr, policies):
        """
        Activate the flows for a subscriber based on the rules stored in Redis.
        During activation, a default flow may be installed for the subscriber.

        Args:
            imsi (string): subscriber id
            msisdn (bytes): subscriber MSISDN
            uplink_tunnel(int): Tunnel ID of the subscriber session.
            ip_addr (string): subscriber session ipv4 address
            policies (VersionedPolicies []): list of versioned policies to activate
        """
        if self._datapath is None:
            self.logger.error('Datapath not initialized for adding flows')
            return ActivateFlowsResult(
                policy_results=[RuleModResult(
                    rule_id=policy.rule.id,
                    version=policy.version,
                    result=RuleModResult.FAILURE,
                ) for policy in policies],
            )
        policy_results = []
        for policy in policies:
            res = self._install_flow_for_rule(imsi, msisdn, uplink_tunnel, ip_addr, apn_ambr, policy.rule, policy.version)
            policy_results.append(RuleModResult(rule_id=policy.rule.id, version=policy.version, result=res))

        # Install a base flow for when no rule is matched.
        self._install_default_flow_for_subscriber(imsi, ip_addr)
        return ActivateFlowsResult(
            policy_results=policy_results,
        )
Esempio n. 2
0
    def activate_flows(self, imsi, ip_addr, static_rule_ids, dynamic_rules,
                       fut):
        """
        Activate the flows for a subscriber based on the rules stored in Redis.
        During activation, another low priority flow is installed for the
        subscriber in the event that all rules are out of credit.

        Args:
            imsi (string): subscriber id
            ip_addr (string): subscriber session ipv4 address
            static_rule_ids (string []): list of static rules to activate
            dynamic_rules (PolicyRule []): list of dynamic rules to activate
            fut (Future): future to wait on the results of flow activations
        """
        if self._datapath is None:
            self.logger.error('Datapath not initialized for adding flows')
            fut.set_result(
                ActivateFlowsResult(
                    static_rule_results=[
                        RuleModResult(
                            rule_id=rule_id,
                            result=RuleModResult.FAILURE,
                        ) for rule_id in static_rule_ids
                    ],
                    dynamic_rule_results=[
                        RuleModResult(
                            rule_id=rule.id,
                            result=RuleModResult.FAILURE,
                        ) for rule in dynamic_rules
                    ],
                ))
            return
        static_results = []
        for rule_id in static_rule_ids:
            res = self._install_flow_for_static_rule(imsi, ip_addr, rule_id)
            static_results.append(RuleModResult(rule_id=rule_id, result=res))
        dyn_results = []
        for rule in dynamic_rules:
            res = self._install_flow_for_rule(imsi, ip_addr, rule)
            dyn_results.append(RuleModResult(rule_id=rule.id, result=res))

        # No matter what, install base flow to drop packets when all other
        # flows have been deactivated
        self._install_drop_flow(imsi)
        fut.set_result(
            ActivateFlowsResult(
                static_rule_results=static_results,
                dynamic_rule_results=dyn_results,
            ))
Esempio n. 3
0
    def activate_rules(self, imsi, msisdn: bytes, uplink_tunnel: int, ip_addr,
                       apn_ambr, static_rule_ids, dynamic_rules):
        """
        Activate the flows for a subscriber based on the rules stored in Redis.
        During activation, a default flow may be installed for the subscriber.

        Args:
            imsi (string): subscriber id
            msisdn (bytes): subscriber MSISDN
            uplink_tunnel(int): Tunnel ID of the subscriber session.
            ip_addr (string): subscriber session ipv4 address
            static_rule_ids (string []): list of static rules to activate
            dynamic_rules (PolicyRule []): list of dynamic rules to activate
        """
        if self._datapath is None:
            self.logger.error('Datapath not initialized for adding flows')
            return ActivateFlowsResult(
                static_rule_results=[
                    RuleModResult(
                        rule_id=rule_id,
                        result=RuleModResult.FAILURE,
                    ) for rule_id in static_rule_ids
                ],
                dynamic_rule_results=[
                    RuleModResult(
                        rule_id=rule.id,
                        result=RuleModResult.FAILURE,
                    ) for rule in dynamic_rules
                ],
            )
        static_results = []
        for rule_id in static_rule_ids:
            res = self._install_flow_for_static_rule(imsi, msisdn,
                                                     uplink_tunnel, ip_addr,
                                                     apn_ambr, rule_id)
            static_results.append(RuleModResult(rule_id=rule_id, result=res))
        dyn_results = []
        for rule in dynamic_rules:
            res = self._install_flow_for_rule(imsi, msisdn, uplink_tunnel,
                                              ip_addr, apn_ambr, rule)
            dyn_results.append(RuleModResult(rule_id=rule.id, result=res))

        # Install a base flow for when no rule is matched.
        self._install_default_flow_for_subscriber(imsi, ip_addr)
        return ActivateFlowsResult(
            static_rule_results=static_results,
            dynamic_rule_results=dyn_results,
        )
Esempio n. 4
0
    def activate_rules(self, imsi, ip_addr, static_rule_ids, dynamic_rules,
                       fut):
        """
        Activate the flows for a subscriber based on the rules stored in Redis.
        During activation, a default flow may be installed for the subscriber.

        Args:
            imsi (string): subscriber id
            ip_addr (string): subscriber session ipv4 address
            static_rule_ids (string []): list of static rules to activate
            dynamic_rules (PolicyRule []): list of dynamic rules to activate
            fut (Future): future to wait on the results of flow activations
        """
        if self._datapath is None:
            self.logger.error('Datapath not initialized for adding flows')
            fut.set_result(ActivateFlowsResult(
                static_rule_results=[RuleModResult(
                    rule_id=rule_id,
                    result=RuleModResult.FAILURE,
                ) for rule_id in static_rule_ids],
                dynamic_rule_results=[RuleModResult(
                    rule_id=rule.id,
                    result=RuleModResult.FAILURE,
                ) for rule in dynamic_rules],
            ))
            return
        static_results = []
        for rule_id in static_rule_ids:
            res = self._install_flow_for_static_rule(imsi, ip_addr, rule_id)
            static_results.append(RuleModResult(rule_id=rule_id, result=res))
        dyn_results = []
        for rule in dynamic_rules:
            res = self._install_flow_for_rule(imsi, ip_addr, rule)
            dyn_results.append(RuleModResult(rule_id=rule.id, result=res))

        # Install a base flow for when no rule is matched.
        self._install_default_flow_for_subscriber(imsi)
        fut.set_result(ActivateFlowsResult(
            static_rule_results=static_results,
            dynamic_rule_results=dyn_results,
        ))