Example MDC Python Script
The following code shows an example script that creates an MDC and writes the compact version of it to a file.
#!/usr/bin/python
#===============================================================================
#
# Copyright 2010-2019, MATRIXX Software, Inc. All rights reserved.
#
#-------------------------------------------------------------------------------
#
# @file
# @author original:
# @author last modified by: $Author: $
# @date $Date: 2019-04-11 22:34:16 -0700 (Thu, 11 Apr 2019) $
#
# $Id: create_mdc.py 61262 2019-04-12 05:34:16Z $
#
#===============================================================================
#
import data_container as MDC
# Check if the data_container_defs.py needs to be re-created
MDC.createDefsFileIfNeeded()
import data_container_defs as MDCDEFS
import optparse
debug = 0
#
#===============================================================================
#
def main():
global debug
#
parser = optparse.OptionParser()
parser.add_option('--debug', '-d', action='store_true')
# pylint: disable=W0612
options, arguments = parser.parse_args()
debug = options.debug
#===========================================================================
#
# file: inMtxDiamRoMsg01.txt
#
# Test using decode_diameter_address on an MtxDiamRoMsg MDC.
# '9000',
#===========================================================================
#
# file: inMtxDiamRoMsg01.txt
myFileName = 'inMtxDiamRoMsg01.txt'
aMtxDiamRoMsg = MDCDEFS.kMtxDiamRoMsgMdcDesc.create()
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgExternalServiceTypeFldKey, '101')
aLevel0StructList = []
aMtxMultiServiceData = MDCDEFS.kMtxMultiServiceDataMdcDesc.create()
aMtxQuantityData = MDCDEFS.kMtxQuantityDataMdcDesc.create()
aMtxQuantityData.setUsingKey(MDCDEFS.kMtxQuantityDataQuantityFldKey, '1.0')
aMtxMultiServiceData.setUsingKey(MDCDEFS.kMtxMultiServiceDataRequestedQuantityFldKey, aMtxQuantityData)
#
aMtxUsedQuantityList = []
aMtxUsedQuantityData = MDCDEFS.kMtxUsedQuantityDataMdcDesc.create()
aMtxUsedQuantityData.setUsingKey(MDCDEFS.kMtxUsedQuantityDataEventChargingTimestampListFldKey,
['2015-02-27T05:24:22.000000Z', '2015-02-27T05:25:23.000000Z'])
aMtxUsedQuantityList.append(aMtxUsedQuantityData)
#
aMtxUsedQuantityData = MDCDEFS.kMtxUsedQuantityDataMdcDesc.create()
aMtxUsedQuantityData.setUsingKey(MDCDEFS.kMtxUsedQuantityDataEventChargingTimestampListFldKey,
['2015-02-27T05:24:22.111000Z', '2015-02-27T05:25:23.111000Z'])
aMtxUsedQuantityList.append(aMtxUsedQuantityData)
#
aMtxMultiServiceData.setUsingKey(MDCDEFS.kMtxMultiServiceDataUsedQuantityListFldKey, aMtxUsedQuantityList)
#
aLevel0StructList.append(aMtxMultiServiceData)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgMultiServiceListFldKey, aLevel0StructList)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgEventTimeFldKey, '2015-02-27T05:24:22.000000Z')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgServiceContextIdFldKey, 'SMS')
aMtxDiamServiceInfoData = MDCDEFS.kMtxDiamServiceInfoDataMdcDesc.create()
aMtxDiamPsInfoData = MDCDEFS.kMtxDiamPsInfoDataMdcDesc.create()
aMtxDiamServiceInfoData.setUsingKey(MDCDEFS.kMtxDiamServiceInfoDataDiamPsInfoFldKey, aMtxDiamPsInfoData)
aMtxDiamSmsInfoData = MDCDEFS.kMtxDiamSmsInfoDataMdcDesc.create()
aMtxDiamSmsInfoData.setUsingKey(MDCDEFS.kMtxDiamSmsInfoDataSourceSccpAddressInfoFldKey,
'\\00\\01\\01\\02\\03\\04')
aMtxDiamSmsInfoData.setUsingKey(MDCDEFS.kMtxDiamSmsInfoDataSmscAddressInfoFldKey, '\\00\\08\\aa\\bb\\cc\\dd ')
aMtxDiamSmsInfoData.setUsingKey(MDCDEFS.kMtxDiamSmsInfoDataSentMsgCountFldKey, '1')
aLevel2StructList = []
aMtxDiamRecipientInfoData = MDCDEFS.kMtxDiamRecipientInfoDataMdcDesc.create()
aLevel3StructList = []
aMtxDiamRecipientAddressData = MDCDEFS.kMtxDiamRecipientAddressDataMdcDesc.create()
aMtxDiamRecipientAddressData.setUsingKey(MDCDEFS.kMtxDiamRecipientAddressDataAddressDataFldKey, '12345678903')
aLevel3StructList.append(aMtxDiamRecipientAddressData)
aMtxDiamRecipientInfoData.setUsingKey(MDCDEFS.kMtxDiamRecipientInfoDataRecipientAddressListFldKey,
aLevel3StructList)
aMtxDiamRecipientInfoData.setUsingKey(MDCDEFS.kMtxDiamRecipientInfoDataRecipientSccpAddressInfoFldKey,
'\\00\\01\\01\\02\\03\\04')
aLevel2StructList.append(aMtxDiamRecipientInfoData)
aMtxDiamSmsInfoData.setUsingKey(MDCDEFS.kMtxDiamSmsInfoDataRecipientInfoListFldKey, aLevel2StructList)
aMtxDiamServiceInfoData.setUsingKey(MDCDEFS.kMtxDiamServiceInfoDataSmsInfoFldKey, aMtxDiamSmsInfoData)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgServiceInfoFldKey, aMtxDiamServiceInfoData)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgRequestedActionFldKey, '0')
aLevel0StructList = []
aMtxDiamServiceParameterInfoData = MDCDEFS.kMtxDiamServiceParameterInfoDataMdcDesc.create()
aMtxDiamServiceParameterInfoData.setUsingKey(
MDCDEFS.kMtxDiamServiceParameterInfoDataServiceParameterTypeFldKey, '2')
aMtxDiamServiceParameterInfoData.setUsingKey(
MDCDEFS.kMtxDiamServiceParameterInfoDataServiceParameterValueFldKey, '123:456')
aLevel0StructList.append(aMtxDiamServiceParameterInfoData)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamRoMsgServiceParameterInfoListFldKey, aLevel0StructList)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamSubscriberMsgSubscriberNameFldKey, 'MAINS')
aLevel0StructList = []
aMtxSubscriberIdData = MDCDEFS.kMtxSubscriberIdDataMdcDesc.create()
aMtxSubscriberIdData.setUsingKey(MDCDEFS.kMtxSubscriberIdDataTypeFldKey, '0')
aMtxSubscriberIdData.setUsingKey(MDCDEFS.kMtxSubscriberIdDataIdFldKey, '12345678901')
aLevel0StructList.append(aMtxSubscriberIdData)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamSubscriberMsgSubscriberIdListFldKey, aLevel0StructList)
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamSubscriberMsgAccessNumberFldKey, '12345678901')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgProxyFlagFldKey, '0')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgApplicationIdFldKey, '4')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgDiamOpFldKey, '272')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgSessionIdFldKey, '13710;12;13')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgNormalizedSessionIdFldKey, '222333444555666')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgSessionMsgIdFldKey, '1')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgSourceHostFldKey, 'aaa.bbb.com')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgSourceRealmFldKey, 'bbb.com')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgDestinationRealmFldKey, 'matrixx.aaa.bbb.com')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgDestinationHostFldKey, 'host03')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgSourceStateIdFldKey, '369')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxDiamMsgAuthApplicationIdFldKey, '4')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxChrgMsgMaybeDuplicateFlagFldKey, '0')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxMsgReceiveTimeFldKey, '2016-05-19T05:36:15.969000Z')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxMsgGatewaySocketIdFldKey, '268500992')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxMsgOpFldKey, '1') # Accounting:single event
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxMsgHopByHopIdFldKey, '3398880219')
aMtxDiamRoMsg.setUsingKey(MDCDEFS.kMtxMsgEndToEndIdFldKey, '1240110521')
#
mdcStr = aMtxDiamRoMsg.printCompact()
outputFile = open(myFileName, 'w')
print(mdcStr, file=outputFile)
outputFile.close()
#
#===============================================================================
#
if __name__ == "__main__":
main()