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}***** ***** *****")
def validateDiameterAvp(requestType,diameterMsg): global IMSI validation_dict=validation_file.get(requestType,None) response = requests.get(url["s1ap_ctx_data_url"]) if response.json()!={} and response.json().get(IMSI,None)!=None: s1ap_data = response.json()[IMSI] response = requests.get(url["gtp_ctx_data_url"]) if response.json() !={} and response.json().get(IMSI,None)!=None: gtp_data = response.json()[IMSI] if validation_dict !=None: 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(":") #collecting the path of expected data for AVP ie_to_validate_value,ie_to_validate_value_present=icu.getKeyValueFromDict(diameterMsg,ie_to_validate) if ie_to_validate == "rat-type": if ie_to_validate_value == rat_type_diameter_map["EUTRAN"]: val_flag = True else: if data_to_compare_path[0] == "diameterContextData": data_to_compare=S6ACTXDATA[IMSI] elif data_to_compare_path[0] == "s1apContextData": data_to_compare = s1ap_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 data_to_compare_value_present == "false": if ie_to_validate =="user-name": data_to_compare_value,data_to_compare_value_present=icu.getKeyValueFromDict(data_to_compare[mt.identity_response.name],data_to_compare_path[2]) if ie_to_validate_value == data_to_compare_value: val_flag=True if val_flag == True: 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}***** ***** *****")
def validateGtpIE(requestType, gtpMsg): global SEQNUM global IMSI response = requests.get(url["s1ap_ctx_data_url"]) s1ap_data = response.json() if response.json() != {} and response.json().get(IMSI, None) != None: s1ap_data = s1ap_data[IMSI] response = requests.get(url["diameter_ctx_data_url"]) if response.json() != {} and response.json().get(IMSI, None) != None: diameter_data = response.json()[IMSI] validation_dict = validation_file.get(requestType, None) if validation_dict != None: 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(':') if ie_to_validate == "tai" or ie_to_validate == "ecgi": ie_to_validate_value = taiEcgiTohex( icu.getKeyValueFromDict(gtpMsg, ie_to_validate)[0]) elif ie_to_validate == "ipv4address": ie_to_validate_value = ipadressToHex( icu.getKeyValueFromDict(gtpMsg, ie_to_validate)[0]) else: ie_to_validate_value, ie_to_validate_value_present = icu.getKeyValueFromDict( gtpMsg, ie_to_validate) if ie_to_validate == "rat_type": val_flag, data_to_compare_value = validateRatType( ie_to_validate_value) elif ie_to_validate == "interface_type": val_flag, data_to_compare_value = validateInterfaceType( ie_to_validate_value) else: if data_to_compare_path[0] == "gtpContextData": data_to_compare = S11CTXDATA[IMSI] elif data_to_compare_path[0] == "s1apContextData": data_to_compare = s1ap_data elif data_to_compare_path[0] == "diameterContextData": data_to_compare = diameter_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 data_to_compare_value_present == "false": if ie_to_validate == "imsi": data_to_compare_value, data_to_compare_value_present = icu.getKeyValueFromDict( data_to_compare[mt.identity_response.name], data_to_compare_path[2]) if ie_to_validate_value == data_to_compare_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}***** ***** *****" )