Ejemplo n.º 1
0
def deactivate_gy_flows(client, args):
    policies = [VersionedPolicyID(rule_id=rule_id, version=1) for rule_id
                in args.rule_ids.split(',') if args.rule_ids]
    request = DeactivateFlowsRequest(
        sid=SIDUtils.to_pb(args.imsi),
        ip_addr=args.ipv4,
        policies=policies,
        request_origin=RequestOriginType(type=RequestOriginType.GY))
    client.DeactivateFlows(request)
Ejemplo n.º 2
0
    def CreateDelQERinPDR(
        qos_enforce_rule: QoSEnforceRuleEntry,
        ue_ip_addr: str,
    ) -> DeactivateFlowsRequest:

        qos_enforce_rule = DeactivateFlowsRequest(
            sid=SIDUtils.to_pb(qos_enforce_rule.imsi),
            ip_addr=ue_ip_addr,
            policies=[VersionedPolicyID(rule_id=qos_enforce_rule.rule_id)],
            request_origin=RequestOriginType(type=RequestOriginType.N4),
        )

        return qos_enforce_rule
Ejemplo n.º 3
0
def get_deactivate_req(request: ActivateFlowsRequest):
    versioned_policy_ids = [
        VersionedPolicyID(rule_id=p.rule.id, version=p.version) for
        p in request.policies
    ]
    return DeactivateFlowsRequest(
        sid=request.sid,
        ip_addr=request.ip_addr,
        ipv6_addr=request.ipv6_addr,
        request_origin=request.request_origin,
        remove_default_drop_flows=True,
        uplink_tunnel=request.uplink_tunnel,
        downlink_tunnel=request.downlink_tunnel,
        policies=versioned_policy_ids,
    )
Ejemplo n.º 4
0
def _build_deactivate_flows_data(ue_dict):
    deactivate_flow_reqs = []

    for ue in ue_dict:
        request = DeactivateFlowsRequest(
            sid=SIDUtils.to_pb(ue.imsi_str),
            ip_addr=ue.ipv4_src,
            policies=[
                VersionedPolicyID(
                    rule_id=ue.rule_id,
                    version=1)
            ],
            request_origin=RequestOriginType(type=RequestOriginType.GX),
            remove_default_drop_flows=True)
        request_dict = json_format.MessageToDict(request)
        # Dumping ActivateFlows request into json
        deactivate_flow_reqs.append(request_dict)
    with open('deactivate_flows.json', 'w') as file:
        json.dump(deactivate_flow_reqs, file, separators=(',', ':'))
Ejemplo n.º 5
0
    def test_deactivate_flows_req(self):
        policies = [VersionedPolicyID(rule_id="rule1", version=1)]
        req = DeactivateFlowsRequest(
            sid=SubscriberID(id="imsi12345"),
            ip_addr="1.2.3.4",
            uplink_tunnel=0x1,
            downlink_tunnel=0x2,
            policies=policies,
        )
        ip_addr = IPAddress(
            version=IPAddress.IPV4,
            address=req.ip_addr.encode('utf-8'),
        )

        self.pipelined_srv.DeactivateFlows(req, MagicMock())
        assert self._enforcer_app.deactivate_rules.call_args.args[
            0] == req.sid.id
        assert self._enforcer_app.deactivate_rules.call_args.args[
            1].version == ip_addr.version
        assert self._enforcer_app.deactivate_rules.call_args.args[
            1].address == ip_addr.address
        assert self._enforcer_app.deactivate_rules.call_args.args[2] == [
            "rule1"
        ]
Ejemplo n.º 6
0
def stress_test_grpc(client, args):
    print("WARNING: DO NOT USE ON PRODUCTION SETUPS")
    delta_time = 1 / args.attaches_per_sec
    print("Attach every ~{0} seconds".format(delta_time))

    if args.disable_qos:
        print("QOS Disabled")
        apn_ambr = None
    else:
        print("QOS Enabled")
        apn_ambr = AggregatedMaximumBitrate(
            max_bandwidth_ul=1000000000,
            max_bandwidth_dl=1000000000,
        )

    for i in range(0, args.test_iterations):
        print("Starting iteration {0} of attach/detach requests".format(i))
        ue_dict = _gen_ue_set(args.num_of_ues)
        print("Starting attaches")

        timestamp = datetime.now()
        completed_reqs = 0
        for ue in ue_dict:
            grpc_start_timestamp = datetime.now()
            request = ActivateFlowsRequest(
                sid=SIDUtils.to_pb(ue.imsi_str),
                ip_addr=ue.ipv4_src,
                policies=[
                    VersionedPolicy(
                        rule=PolicyRule(
                            id=ue.rule_id,
                            priority=10,
                            flow_list=[
                                FlowDescription(
                                    match=FlowMatch(
                                        ip_dst=convert_ipv4_str_to_ip_proto(ue.ipv4_src),
                                        direction=FlowMatch.UPLINK,
                                    ),
                                ),
                                FlowDescription(
                                    match=FlowMatch(
                                        ip_src=convert_ipv4_str_to_ip_proto(ue.ipv4_dst),
                                        direction=FlowMatch.DOWNLINK,
                                    ),
                                ),
                            ],
                        ),
                        version=1,
                    ),
                ],
                request_origin=RequestOriginType(type=RequestOriginType.GX),
                apn_ambr=apn_ambr,
            )
            response = client.ActivateFlows(request)
            if any(
                r.result != RuleModResult.SUCCESS for
                r in response.policy_results
            ):
                _print_rule_mod_results(response.policy_results)

            grpc_end_timestamp = datetime.now()
            call_duration = (grpc_end_timestamp - grpc_start_timestamp).total_seconds()
            if call_duration < delta_time:
                time.sleep(delta_time - call_duration)
            if completed_reqs % LOG_INCREMENT == 0:
                print("Finished {0}".format(completed_reqs))
            completed_reqs += 1

        duration = (datetime.now() - timestamp).total_seconds()
        print(
            "Finished {0} attaches in {1} seconds".format(
                len(ue_dict),
                duration,
            ),
        )
        print("Actual attach rate = {0} UEs per sec".format(round(len(ue_dict) / duration)))

        time.sleep(args.time_between_detach)

        print("Starting detaches")
        timestamp = datetime.now()
        completed_reqs = 0
        for ue in ue_dict:
            grpc_start_timestamp = datetime.now()
            request = DeactivateFlowsRequest(
                sid=SIDUtils.to_pb(ue.imsi_str),
                ip_addr=ue.ipv4_src,
                policies=[
                    VersionedPolicyID(
                        rule_id=ue.rule_id,
                        version=1,
                    ),
                ],
                request_origin=RequestOriginType(type=RequestOriginType.GX),
                remove_default_drop_flows=True,
            )
            response = client.DeactivateFlows(request)
            if response.result != DeactivateFlowsResult.SUCCESS:
                _print_rule_mod_results(response.policy_results)

            grpc_end_timestamp = datetime.now()
            call_duration = (grpc_end_timestamp - grpc_start_timestamp).total_seconds()
            if call_duration < delta_time:
                time.sleep(delta_time - call_duration)
            if completed_reqs % LOG_INCREMENT == 0:
                print("Finished {0}".format(completed_reqs))
            completed_reqs += 1

        duration = (datetime.now() - timestamp).total_seconds()
        print(
            "Finished {0} detaches in {1} seconds".format(
                len(ue_dict),
                duration,
            ),
        )
        print(
            "Actual detach rate = {0} UEs per sec".format(
                round(len(ue_dict) / duration),
            ),
        )