Added test for *mms charging

This commit is contained in:
adragusin
2020-03-27 16:18:31 +02:00
committed by Dan Christian Bogos
parent a924ddf8f4
commit 4a5c0f9819
12 changed files with 728 additions and 2 deletions

View File

@@ -65,6 +65,7 @@ var (
testDiamItCCRTerminate,
testDiamItCCRSMS,
testDiamItCCRMMS,
testDiamItKillEngine,
}
)
@@ -900,6 +901,85 @@ func testDiamItCCRSMS(t *testing.T) {
}
}
func testDiamItCCRMMS(t *testing.T) {
ccr := diam.NewRequest(diam.CreditControl, 4, nil)
ccr.NewAVP(avp.SessionID, avp.Mbit, 0, datatype.UTF8String("TestDmtAgentSendCCRMMS"))
ccr.NewAVP(avp.OriginHost, avp.Mbit, 0, datatype.DiameterIdentity("CGR-DA"))
ccr.NewAVP(avp.OriginRealm, avp.Mbit, 0, datatype.DiameterIdentity("cgrates.org"))
ccr.NewAVP(avp.AuthApplicationID, avp.Mbit, 0, datatype.Unsigned32(4))
ccr.NewAVP(avp.ServiceContextID, avp.Mbit, 0, datatype.UTF8String("mms@DiamItCCRMMS"))
ccr.NewAVP(avp.CCRequestType, avp.Mbit, 0, datatype.Enumerated(4))
ccr.NewAVP(avp.CCRequestNumber, avp.Mbit, 0, datatype.Unsigned32(0))
ccr.NewAVP(avp.EventTimestamp, avp.Mbit, 0, datatype.Time(time.Date(2018, 10, 5, 11, 43, 10, 0, time.UTC)))
ccr.NewAVP(avp.SubscriptionID, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(avp.SubscriptionIDType, avp.Mbit, 0, datatype.Enumerated(0)),
diam.NewAVP(avp.SubscriptionIDData, avp.Mbit, 0, datatype.UTF8String("1001")), // Subscription-Id-Data
}})
ccr.NewAVP(avp.SubscriptionID, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(avp.SubscriptionIDType, avp.Mbit, 0, datatype.Enumerated(1)),
diam.NewAVP(avp.SubscriptionIDData, avp.Mbit, 0, datatype.UTF8String("104502200011")), // Subscription-Id-Data
}})
ccr.NewAVP(avp.ServiceIdentifier, avp.Mbit, 0, datatype.Unsigned32(0))
ccr.NewAVP(avp.RequestedAction, avp.Mbit, 0, datatype.Enumerated(0))
ccr.NewAVP(avp.RequestedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{
AVP: []*diam.AVP{
diam.NewAVP(avp.CCTime, avp.Mbit, 0, datatype.Unsigned32(1))}})
ccr.NewAVP(873, avp.Mbit, 10415, &diam.GroupedAVP{ //
AVP: []*diam.AVP{
diam.NewAVP(20300, avp.Mbit, 2011, &diam.GroupedAVP{ // IN-Information
AVP: []*diam.AVP{
diam.NewAVP(20302, avp.Mbit, 2011, datatype.UTF8String("22509")), // Calling-Vlr-Number
diam.NewAVP(20385, avp.Mbit, 2011, datatype.UTF8String("4002")), // Called-Party-NP
},
}),
diam.NewAVP(2000, avp.Mbit, 10415, &diam.GroupedAVP{ // SMS-Information
AVP: []*diam.AVP{
diam.NewAVP(886, avp.Mbit, 10415, &diam.GroupedAVP{ // Originator-Address
AVP: []*diam.AVP{
diam.NewAVP(899, avp.Mbit, 10415, datatype.Enumerated(1)), // Address-Type
diam.NewAVP(897, avp.Mbit, 10415, datatype.UTF8String("1001")), // Address-Data
}}),
diam.NewAVP(1201, avp.Mbit, 10415, &diam.GroupedAVP{ // Recipient-Address
AVP: []*diam.AVP{
diam.NewAVP(899, avp.Mbit, 10415, datatype.Enumerated(1)), // Address-Type
diam.NewAVP(897, avp.Mbit, 10415, datatype.UTF8String("1003")), // Address-Data
}}),
},
}),
}})
// ============================================
// prevent nil pointer dereference
// ============================================
if diamClnt == nil {
t.Fatal("Diameter client should not be nil")
}
if diamClnt.conn == nil {
t.Fatal("Diameter connection should not be nil")
}
if ccr == nil {
t.Fatal("The mesage to diameter should not be nil")
}
// ============================================
if err := diamClnt.SendMessage(ccr); err != nil {
t.Error(err)
}
time.Sleep(time.Duration(100) * time.Millisecond)
diamClnt.ReceivedMessage(rplyTimeout)
var cdrs []*engine.CDR
args := &utils.RPCCDRsFilterWithArgDispatcher{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaRaw}, ToRs: []string{utils.MMS}}}
if err := apierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if len(cdrs) != 1 {
t.Error("Unexpected number of CDRs returned: ", len(cdrs))
} else if cdrs[0].Usage != 1 {
t.Errorf("Unexpected Usage CDR: %+v", cdrs[0])
}
}
func testDiamInitWithSessionDisconnect(t *testing.T) {
attrSetBalance := utils.AttrSetBalance{Tenant: "cgrates.org",
Account: "testDiamInitWithSessionDisconnect",

View File

@@ -0,0 +1,91 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -0,0 +1,91 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -0,0 +1,91 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -0,0 +1,91 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -0,0 +1,91 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -0,0 +1,91 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -0,0 +1,96 @@
{
"diameter_agent": {
"request_processors": [
{
"id": "mms",
"filters": [
"*string:~*vars.*cmd:CCR",
"*prefix:~*req.Service-Context-Id:mms",
"*string:~*req.CC-Request-Type:4"
],
"flags": ["*message", "*accounts", "*cdrs","*attributes"],
"request_fields":[
{
"tag": "ToR",
"path": "*cgreq.ToR",
"type": "*constant",
"value": "*mms"
},
{ "tag": "*api_key",
"path": "*cgreq.*api_key",
"type": "*constant",
"value": "ses12345"
},
{
"tag": "OriginID",
"path": "*cgreq.OriginID",
"type": "*variable",
"value": "~*req.Session-Id",
"mandatory": true
},
{
"tag": "Category",
"path": "*cgreq.Category",
"type": "*constant",
"value": "mms"
},
{
"tag": "RequestType",
"path": "*cgreq.RequestType",
"type": "*constant",
"value": "*prepaid"
},
{
"tag": "Account",
"path": "*cgreq.Account",
"type": "*variable",
"mandatory": true,
"value": "~*req.Subscription-Id.Subscription-Id-Data[~Subscription-Id-Type(0)]"
},
{
"tag": "Destination",
"path": "*cgreq.Destination",
"type": "*variable",
"mandatory": true,
"value": "~*req.Service-Information.SMS-Information.Recipient-Address.Address-Data"
},
{
"tag": "SetupTime",
"path": "*cgreq.SetupTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "AnswerTime",
"path": "*cgreq.AnswerTime",
"type": "*variable",
"value": "~*req.Event-Timestamp",
"mandatory": true
},
{
"tag": "Usage",
"path": "*cgreq.Usage",
"type": "*variable",
"value": "~*req.Requested-Service-Unit.CC-Time",
"mandatory": true
},
],
"reply_fields":[
{
"tag": "ResultCode",
"filters": ["*notempty:~*cgrep.Error:"],
"path": "*rep.Result-Code",
"type": "*constant",
"value": "5030",
"blocker": true
},
],
},
],
},
}

View File

@@ -4,4 +4,4 @@ DR_1002_20CNT,DST_1002,RT_20CNT,*up,4,0,
DR_1003_MAXCOST_DISC,DST_1003,RT_1CNT_PER_SEC,*up,4,0.12,*disconnect
DR_1001_10CNT,DST_1001,RT_10CNT,*up,4,0,
DR_SMS,*any,RT_SMS,*up,4,0,
DR_MMS,*any,RT_MMS,*up,4,0,
1 #Id DestinationId RatesTag RoundingMethod RoundingDecimals MaxCost MaxCostStrategy
4 DR_1003_MAXCOST_DISC DST_1003 RT_1CNT_PER_SEC *up 4 0.12 *disconnect
5 DR_1001_10CNT DST_1001 RT_10CNT *up 4 0
6 DR_SMS *any RT_SMS *up 4 0
7 DR_MMS *any RT_MMS *up 4 0

View File

@@ -8,3 +8,4 @@ RT_40CNT,0,0.2,60s,10s,60s
RT_1CNT,0,0.01,60s,60s,0s
RT_1CNT_PER_SEC,0,0.01,1s,1s,0s
RT_SMS,0,0.01,1,1,0
RT_MMS,0,0.01,1,1,0
1 #Id ConnectFee Rate RateUnit RateIncrement GroupIntervalStart
8 RT_1CNT 0 0.01 60s 60s 0s
9 RT_1CNT_PER_SEC 0 0.01 1s 1s 0s
10 RT_SMS 0 0.01 1 1 0
11 RT_MMS 0 0.01 1 1 0

View File

@@ -4,4 +4,5 @@ RP_1001,DR_1003_MAXCOST_DISC,*any,10
RP_1002,DR_1001_20CNT,*any,10
RP_1002_LOW,DR_1001_10CNT,*any,10
RP_1003,DR_1001_10CNT,*any,10
RP_SMS,DR_SMS,*any,0
RP_SMS,DR_SMS,*any,0
RP_MMS,DR_MMS,*any,0
1 #Id DestinationRatesId TimingTag Weight
4 RP_1002 DR_1001_20CNT *any 10
5 RP_1002_LOW DR_1001_10CNT *any 10
6 RP_1003 DR_1001_10CNT *any 10
7 RP_SMS DR_SMS *any 0
8 RP_MMS DR_MMS *any 0

View File

@@ -3,3 +3,5 @@ cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,
cgrates.org,call,1002,2014-01-14T00:00:00Z,RP_1002,
cgrates.org,call,1003,2014-01-14T00:00:00Z,RP_1003,
cgrates.org,sms,*any,2014-01-14T00:00:00Z,RP_SMS,
cgrates.org,mms,*any,2014-01-14T00:00:00Z,RP_MMS,
1 #Tenant Category Subject ActivationTime RatingPlanId RatesFallbackSubject
3 cgrates.org call 1002 2014-01-14T00:00:00Z RP_1002
4 cgrates.org call 1003 2014-01-14T00:00:00Z RP_1003
5 cgrates.org sms *any 2014-01-14T00:00:00Z RP_SMS
6 cgrates.org mms *any 2014-01-14T00:00:00Z RP_MMS
7