Exemplo n.º 1
0
def setContextData(requestType, gtpMsg):
    global IMSI

    if requestType == mt.create_session_response.name:
        teid_gre_key, teid_gre_key_present = icu.getKeyValueFromDict(
            gtpMsg, "teid_gre_key")
        ipv4_address, ipv4_address_present = icu.getKeyValueFromDict(
            gtpMsg, "ipv4address")
        eps_bearer_id, eps_bearer_id_present = icu.getKeyValueFromDict(
            gtpMsg, "eps_bearer_id")
        S11CTXDATA[IMSI][requestType] = {
            "teid_gre_key": icu.formatHex(teid_gre_key),
            "ipv4_address": ipv4_address,
            "eps_bearer_id": eps_bearer_id
        }

    else:
        seq_number, seq_number_present = icu.getKeyValueFromDict(
            gtpMsg, "sequence_number")
        mme_teid, mme_teid_present = icu.getKeyValueFromDict(
            gtpMsg, "teid_gre_key")

        if requestType == mt.create_session_request.name:
            if S11CTXDATA.get(IMSI, None) == None:
                S11CTXDATA[IMSI] = {}

        if mme_teid_present == 'true':
            S11CTXDATA[IMSI][requestType] = {
                "sequence_number": seq_number,
                "teid_key": mme_teid
            }
        else:
            S11CTXDATA[IMSI][requestType] = {"sequence_number": seq_number}
    igniteLogger.logger.info(f"GTP context data  : {S11CTXDATA}")
Exemplo n.º 2
0
def validateS1apIE(requestType,s1apMsg):
    global SERFLAG
    global IMSI

    procedure_code=s1apMessageDict[icu.getKeyValueFromDict(s1apMsg,'procedureCode')[0]]
    if procedure_code == mt.downlink_nas_transport.name:
        validation_dict=nas_validation_file.get(requestType,None)
    else:
        validation_dict=s1ap_validation_file.get(requestType,None)

    if validation_dict !=None:
        response = requests.get(url["diameter_ctx_data_url"])
        if response.json() !={} and response.json().get(str(IMSI),None)!=None:
            diameter_data = response.json()[str(IMSI)]

        response = requests.get(url["gtp_ctx_data_url"])
        if response.json() !={} and response.json().get(str(IMSI),None)!=None:
            gtp_data = response.json()[str(IMSI)]

        for num in range(len(validation_dict["dataToBeVerified"])):
            val_flag=False
            ie_to_validate=validation_dict["dataToBeVerified"][num]
            data_to_compare_path=validation_dict["fromContextData"][num].split(':')

            ie_to_validate_value,ie_to_validate_value_present=icu.getKeyValueFromDict(s1apMsg,ie_to_validate)

            if data_to_compare_path[0] == "s1apContextData":
                if requestType == mt.identity_request.name:
                    data_to_compare=S1APCTXDATA[icu.getKeyValueFromDict(s1apMsg,"ENB-UE-S1AP-ID")[0]]
                else:
                    data_to_compare=S1APCTXDATA[IMSI]          
            elif data_to_compare_path[0] == "diameterContextData":
                data_to_compare = diameter_data

            elif data_to_compare_path[0] == "gtpContextData":
                data_to_compare = gtp_data
                
            data_to_compare_value,data_to_compare_value_present=icu.getKeyValueFromDict(data_to_compare[data_to_compare_path[1]],data_to_compare_path[2])

            if ie_to_validate == "transportLayerAddress":
                data_to_compare_value=convertIpaddressToHex(data_to_compare_value)
            elif ie_to_validate == "m-TMSI":
                data_to_compare_value=icu.formatHex(data_to_compare_value)

            if ie_to_validate_value == data_to_compare_value:
                val_flag = True
            elif type(ie_to_validate_value)==str and data_to_compare_value in ie_to_validate_value:
                val_flag = True

            if val_flag:
                igniteLogger.logger.info(f"request/response name:{requestType} ,IEname:{ie_to_validate} ,expected value:{data_to_compare_value} ,received value:{ie_to_validate_value}")
            else:
                igniteLogger.logger.error(f"request/response name:{requestType} ,IEname:{ie_to_validate} ,expected value:{data_to_compare_value} ,received value:{ie_to_validate_value}")
                raise icu.ValidationException(f"***** ***** *****\nERROR :: Validation fail \nrequest/response name:{requestType} ,IEname:{ie_to_validate} ,expected value:{data_to_compare_value} ,received value:{ie_to_validate_value}***** ***** *****")
Exemplo n.º 3
0
def sendS1ap(requestType,s1apData,enbUeS1apId,nasData={},imsi=None,ieUpdateValDict=None):

    global SERFLAG
    global TIMEOUTFLAG
    global IMSI

    igniteLogger.logger.info(f"s1ap message type : {requestType}")
    s1apData["NAS-MESSAGE"] = nasData
    count=0
    if enbUeS1apId !=None:
        if requestType == mt.attach_request.name:
            icu.updateKeyValueInDict(s1apData, "ENB-UE-S1AP-ID", enbUeS1apId)
            nu.setImsi(imsi,nasData)
            if imsi ==None:
                S1APCTXDATA[enbUeS1apId]={}
            else:
                if S1APCTXDATA.get(IMSI,None)==None:
                    IMSI=imsi
                    S1APCTXDATA[IMSI]={}
                    S1APCTXDATA[IMSI][requestType]={'imsi':str(imsi)}

        elif requestType == mt.identity_response.name:
            IMSI=imsi
            nu.setImsi(imsi,nasData)
            if S1APCTXDATA.get(enbUeS1apId,None)!=None:
                S1APCTXDATA[IMSI]=S1APCTXDATA[enbUeS1apId].copy()
                del S1APCTXDATA[enbUeS1apId]
                S1APCTXDATA[IMSI][requestType]={'imsi':str(imsi)}
            updateMessageFromContextData(s1apData,requestType)
        elif requestType == mt.attach_request_guti.name:
            icu.updateKeyValueInDict(s1apData, "ENB-UE-S1AP-ID", enbUeS1apId)
            S1APCTXDATA[enbUeS1apId]={}
            if imsi!=None:
                nu.setGuti(imsi,s1apData)
            else:
                nu.setGuti(S1APCTXDATA[IMSI][mt.attach_accept.name]["guti_list"],s1apData)
                
        elif requestType==mt.service_request.name:
            SERFLAG=True
            icu.updateKeyValueInDict(s1apData, "ENB-UE-S1AP-ID", enbUeS1apId)
            icu.updateKeyValueInDict(s1apData,"m-TMSI", icu.formatHex(S1APCTXDATA[IMSI][mt.attach_accept.name]["m_tmsi"]))
            icu.updateKeyValueInDict(s1apData,"mMEC", '0'+str(S1APCTXDATA[IMSI][mt.attach_accept.name]["mme_code"]))
 
        else:
            if requestType == mt.initial_context_setup_response.name:
                if count == 0:
                    gtp_teid=icu.generateUniqueId('gTP-TEID')
                    S1APCTXDATA[IMSI]["gTP_TEID"]=gtp_teid
                    icu.updateKeyValueInDict(s1apData, "gTP-TEID", gtp_teid)
                    count+=1
                else:
                    gtp_teid=S1APCTXDATA[IMSI]["gTP_TEID"]
                    gtp_teid=icu.icrementGtpTeid(gtp_teid)
                    S1APCTXDATA[IMSI]["gTP_TEID"]=gtp_teid
                    icu.updateKeyValueInDict(s1apData, "gTP-TEID", gtp_teid)
                    count+=1
                icu.updateKeyValueInDict(s1apData, "transportLayerAddress",transportLayerAddressUpdate())

            elif requestType==mt.authentication_response.name:
                TIMEOUTFLAG=False

            elif requestType==mt.ue_context_release_complete.name:
                SERFLAG=False

            updateMessageFromContextData(s1apData,requestType)
            
    if ieUpdateValDict != None:
        icu.setValueFromTC(s1apData,ieUpdateValDict)
    setContextData(s1apData,requestType)
    
    igniteLogger.logger.info(f"s1ap data send : {s1apData}")
    send_response = requests.post(url["send_url"], json=[s1apData,S1APCTXDATA,"s1ap"])
    igniteLogger.logger.info(f"URL response for send s1ap data : {str(send_response)}")
Exemplo n.º 4
0
def sendS1ap(requestType,s1apData,enbUeS1apId,nasData={},imsi=None,ieUpdateValDict=None):

    global SERFLAG
    global TIMEOUTFLAG
    global IMSI

    igniteLogger.logger.info(f"s1ap message type : {requestType}")
    s1apData["NAS-MESSAGE"] = nasData
    count=0
    if enbUeS1apId !=None:
        if requestType == mt.attach_request.name:
            icu.updateKeyValueInDict(s1apData, "ENB-UE-S1AP-ID", enbUeS1apId)
            nu.setImsi(imsi,nasData)
            if imsi ==None:
                S1APCTXDATA[enbUeS1apId]={}
            else:
                if S1APCTXDATA.get(IMSI,None)==None:
                    IMSI=imsi
                    S1APCTXDATA[IMSI]={}
                    S1APCTXDATA[IMSI][requestType]={'imsi':str(imsi)}

        elif requestType == mt.identity_response.name:
            IMSI=imsi
            nu.setImsi(imsi,nasData)
            if S1APCTXDATA.get(enbUeS1apId,None)!=None:
                S1APCTXDATA[IMSI]=S1APCTXDATA[enbUeS1apId].copy()
                del S1APCTXDATA[enbUeS1apId]
                S1APCTXDATA[IMSI][requestType]={'imsi':str(imsi)}
            updateMessageFromContextData(s1apData,requestType)
        elif requestType == mt.attach_request_guti.name:
            icu.updateKeyValueInDict(s1apData, "ENB-UE-S1AP-ID", enbUeS1apId)
            S1APCTXDATA[enbUeS1apId]={}
            if imsi!=None:
                nu.setGuti(imsi,s1apData)
            else:
                nu.setGuti(S1APCTXDATA[IMSI][mt.attach_accept.name]["guti_list"],s1apData)

        elif requestType==mt.service_request.name:
            SERFLAG=True
            icu.updateKeyValueInDict(s1apData, "ENB-UE-S1AP-ID", enbUeS1apId)
            icu.updateKeyValueInDict(s1apData,"m-TMSI", icu.formatHex(S1APCTXDATA[IMSI][mt.attach_accept.name]["m_tmsi"]))
            icu.updateKeyValueInDict(s1apData,"mMEC", '0'+str(S1APCTXDATA[IMSI][mt.attach_accept.name]["mme_code"]))

        else:
            if requestType == mt.initial_context_setup_response.name:
                if count == 0:
                    gtp_teid=icu.generateUniqueId('gTP-TEID')
                    S1APCTXDATA[IMSI]["gTP_TEID"]=gtp_teid
                    icu.updateKeyValueInDict(s1apData, "gTP-TEID", gtp_teid)
                    count+=1
                else:
                    gtp_teid=S1APCTXDATA[IMSI]["gTP_TEID"]
                    gtp_teid=icu.icrementGtpTeid(gtp_teid)
                    S1APCTXDATA[IMSI]["gTP_TEID"]=gtp_teid
                    icu.updateKeyValueInDict(s1apData, "gTP-TEID", gtp_teid)
                    count+=1
                icu.updateKeyValueInDict(s1apData, "transportLayerAddress",transportLayerAddressUpdate())

            elif requestType == mt.handover_request_acknowledge.name:
                gtp_teid=icu.generateUniqueId('gTP-TEID')
                gtp_teid_1=icu.generateUniqueId('gTP-TEID')
                S1APCTXDATA[IMSI]["gTP_TEID_2"]=gtp_teid
                icu.updateKeyValueInDict(s1apData, "gTP-TEID", gtp_teid)
                icu.updateKeyValueInDict(s1apData, "transportLayerAddress",transportLayerAddressUpdate())
                icu.updateKeyValueInDict(s1apData, "dL-transportLayerAddress",transportLayerAddressUpdate())
                icu.updateKeyValueInDict(s1apData, "gTP-TEID", gtp_teid_1)

            elif requestType == mt.erab_modification_indication.name:
                tl_address=transportLayerAddressUpdate()
                generateIeValueForErabModInd(s1apData,tl_address,GTP_TEID_LIST)
                S1APCTXDATA[IMSI]["gTP_TEID"]=GTP_TEID_LIST
            
            elif requestType==mt.authentication_response.name:
                TIMEOUTFLAG=False

            elif requestType==mt.ue_context_release_complete.name:
                SERFLAG=False

            updateMessageFromContextData(s1apData,requestType)

    if ieUpdateValDict != None:
        icu.setValueFromTC(s1apData,ieUpdateValDict)
    setContextData(s1apData,requestType)

    igniteLogger.logger.info(f"s1ap data send : {s1apData}")
    if requestType in [mt.s1_setup_request_target.name,mt.handover_request_acknowledge.name,mt.handover_notify.name]:
        send_url = "http://"+str(config_file["s1ap_target"]["ignite_ip"])+":"+str(config_file["s1ap_target"]["tc_port"])+"/sendMessagesToProxy"
        send_response = requests.post(url["send_url"], json=[None,S1APCTXDATA,"s1ap"])
    else:
        send_url = url["send_url"]

    send_response = requests.post(send_url, json=[s1apData,S1APCTXDATA,"s1ap"])
    igniteLogger.logger.info(f"URL response for send s1ap data : {str(send_response)}")