Exemple #1
0
def activate_he_urls_for_ue(ip: IPAddress, rule_id: str, urls: List[str],
                            imsi: str, msisdn: str) -> bool:
    """
    Make RPC call to 'Envoy Controller' to add target URLs to envoy datapath.
    """
    try:
        chan = ServiceRegistry.get_rpc_channel(SERVICE_NAME,
                                               ServiceRegistry.LOCAL)
    except grpc.RpcError:
        logging.error('Cant get RPC channel to %s', SERVICE_NAME)
        return False

    client = EnvoyControllerStub(chan)
    try:
        headers = [Header(name=IMSI_HDR, value=imsi)]
        if msisdn:
            headers.append(Header(name=MSISDN_HDR, value=msisdn))
        he_info = AddUEHeaderEnrichmentRequest(ue_ip=ip,
                                               rule_id=rule_id,
                                               websites=urls,
                                               headers=headers)
        ret = client.AddUEHeaderEnrichment(he_info, timeout=TIMEOUT_SEC)
        return ret.result == AddUEHeaderEnrichmentResult.SUCCESS
    except grpc.RpcError as err:
        logging.error(
            "Activate HE proxy error[%s] %s",
            err.code(),
            err.details())

    return False
Exemple #2
0
def deactivate_he_urls_for_ue(ip: IPAddress, rule_id: str) -> bool:
    """
    Make RPC call to 'Envoy Controller' to remove the proxy rule for the UE.
    """
    try:
        chan = ServiceRegistry.get_rpc_channel(
            SERVICE_NAME,
            ServiceRegistry.LOCAL,
        )
    except grpc.RpcError:
        logging.error('Cant get RPC channel to %s', SERVICE_NAME)
        return False

    client = EnvoyControllerStub(chan)

    try:
        he_info = DeactivateUEHeaderEnrichmentRequest(ue_ip=ip,
                                                      rule_id=rule_id)
        ret = client.DeactivateUEHeaderEnrichment(he_info, timeout=TIMEOUT_SEC)
        return ret.result == DeactivateUEHeaderEnrichmentResult.SUCCESS
    except grpc.RpcError as err:
        logging.error(
            "Deactivate HE proxy error[%s] %s",
            err.code(),
            err.details(),
        )

    return False
Exemple #3
0
def set_he_urls_for_ue(ip: str, urls: List[str], imsi: str, msisdn: str):
    """
    Make RPC call to 'SetGatewayInfo' method of local mobilityD service
    """

    try:
        chan = ServiceRegistry.get_rpc_channel(SERVICE_NAME,
                                               ServiceRegistry.LOCAL)
    except grpc.RpcError:
        logging.error('Cant get RPC channel to %s', SERVICE_NAME)
        return

    client = EnvoyControllerStub(chan)
    try:
        h1 = {IMSI_HDR: imsi}
        h2 = {MSISDN_HDR: msisdn}

        he_info = AddUEHeaderEnrichmentRequest(ue_ip=ip,
                                               websites=urls,
                                               headers=[h1, h2])
        client.AddUEHeaderEnrichment(he_info)
    except grpc.RpcError as err:
        logging.error("SetGatewayInfo error[%s] %s", err.code(), err.details())