diff --git a/agents/diamagent.go b/agents/diamagent.go index 2465d39d2..5dd16e6d8 100644 --- a/agents/diamagent.go +++ b/agents/diamagent.go @@ -209,7 +209,7 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) { writeOnConn(c, diamErr) return } - a, err := diamAnswer(m, diam.Success, false, + a, err := diamAnswer(m, 0, false, rply, da.cgrCfg.GeneralCfg().DefaultTimezone) if err != nil { utils.Logger.Warning( diff --git a/agents/libdiam.go b/agents/libdiam.go index 75043872b..b6aeb8448 100644 --- a/agents/libdiam.go +++ b/agents/libdiam.go @@ -407,7 +407,7 @@ func (dP *diameterDP) FieldAsInterface(fldPath []string) (data interface{}, err // diamAnswer builds up the answer to be sent back to the client func diamAnswer(m *diam.Message, resCode uint32, errFlag bool, rply *config.NavigableMap, tmz string) (a *diam.Message, err error) { - a = m.Answer(resCode) + a = newDiamAnswer(m, resCode) if errFlag { a.Header.CommandFlags = diam.ErrorFlag } @@ -489,3 +489,19 @@ func disectDiamListen(addrs string) (ipAddrs []string) { } return } + +// newDiamAnswer temporary until fiorix will fix the issue +func newDiamAnswer(m *diam.Message, resCode uint32) *diam.Message { + nm := diam.NewMessage( + m.Header.CommandCode, + m.Header.CommandFlags&^diam.RequestFlag, // Reset the Request bit. + m.Header.ApplicationID, + m.Header.HopByHopID, + m.Header.EndToEndID, + m.Dictionary(), + ) + if resCode != 0 { + nm.NewAVP(avp.ResultCode, avp.Mbit, 0, datatype.Unsigned32(resCode)) + } + return nm +} diff --git a/config/config_defaults.go b/config/config_defaults.go index 963bf69c5..7e2669f2d 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -386,6 +386,8 @@ const CGRATES_CFG_JSON = ` "*cca": [ {"tag": "SessionId", "field_id": "Session-Id", "type": "*composed", "value": "~*req.Session-Id", "mandatory": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", + "value": "2001"}, {"tag": "OriginHost", "field_id": "Origin-Host", "type": "*composed", "value": "~*vars.OriginHost", "mandatory": true}, {"tag": "OriginRealm", "field_id": "Origin-Realm", "type": "*composed", diff --git a/config/config_json_test.go b/config/config_json_test.go index fee282a08..0cdf55002 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -610,6 +610,10 @@ func TestDiameterAgentJsonCfg(t *testing.T) { Type: utils.StringPointer(utils.META_COMPOSED), Value: utils.StringPointer("~*req.Session-Id"), Mandatory: utils.BoolPointer(true)}, + {Tag: utils.StringPointer("ResultCode"), + Field_id: utils.StringPointer("Result-Code"), + Type: utils.StringPointer(utils.META_CONSTANT), + Value: utils.StringPointer("2001")}, {Tag: utils.StringPointer("OriginHost"), Field_id: utils.StringPointer("Origin-Host"), Type: utils.StringPointer(utils.META_COMPOSED), diff --git a/data/conf/samples/diamagent/voice.json b/data/conf/samples/diamagent/voice.json index c3838e206..5d9e80823 100644 --- a/data/conf/samples/diamagent/voice.json +++ b/data/conf/samples/diamagent/voice.json @@ -29,6 +29,7 @@ "reply_fields":[ {"tag": "ResultCode", "filters": ["*rsr::~*cgrep.Error(!^$)"], "field_id": "Result-Code", "type": "*constant", "value": "5030", "blocker": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", "value": "2001"}, {"tag": "GrantedUnits", "field_id": "Granted-Service-Unit.CC-Time", "type": "*composed", "value": "~*cgrep.MaxUsage{*duration_seconds}", "mandatory": true}, ], @@ -61,6 +62,7 @@ "reply_fields":[ {"tag": "ResultCode", "filters": ["*rsr::~*cgrep.Error(!^$)"], "field_id": "Result-Code", "type": "*constant", "value": "5030", "blocker": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", "value": "2001"}, {"tag": "GrantedUnits", "field_id": "Granted-Service-Unit.CC-Time", "type": "*composed", "value": "~*cgrep.MaxUsage{*duration_seconds}", "mandatory": true}, ], @@ -89,6 +91,11 @@ {"tag": "SubscriberID", "field_id": "SubscriberId", "type": "*composed", "value": "~*req.Subscription-Id.Subscription-Id-Data", "mandatory": true}, ], + "reply_fields":[ + {"tag": "ResultCode", "filters": ["*rsr::~*cgrep.Error(!^$)"], + "field_id": "Result-Code", "type": "*constant", "value": "5030", "blocker": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", "value": "2001"}, + ], }, ], }, diff --git a/data/conf/samples/diamsctpagent/voice.json b/data/conf/samples/diamsctpagent/voice.json index c3838e206..5d9e80823 100755 --- a/data/conf/samples/diamsctpagent/voice.json +++ b/data/conf/samples/diamsctpagent/voice.json @@ -29,6 +29,7 @@ "reply_fields":[ {"tag": "ResultCode", "filters": ["*rsr::~*cgrep.Error(!^$)"], "field_id": "Result-Code", "type": "*constant", "value": "5030", "blocker": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", "value": "2001"}, {"tag": "GrantedUnits", "field_id": "Granted-Service-Unit.CC-Time", "type": "*composed", "value": "~*cgrep.MaxUsage{*duration_seconds}", "mandatory": true}, ], @@ -61,6 +62,7 @@ "reply_fields":[ {"tag": "ResultCode", "filters": ["*rsr::~*cgrep.Error(!^$)"], "field_id": "Result-Code", "type": "*constant", "value": "5030", "blocker": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", "value": "2001"}, {"tag": "GrantedUnits", "field_id": "Granted-Service-Unit.CC-Time", "type": "*composed", "value": "~*cgrep.MaxUsage{*duration_seconds}", "mandatory": true}, ], @@ -89,6 +91,11 @@ {"tag": "SubscriberID", "field_id": "SubscriberId", "type": "*composed", "value": "~*req.Subscription-Id.Subscription-Id-Data", "mandatory": true}, ], + "reply_fields":[ + {"tag": "ResultCode", "filters": ["*rsr::~*cgrep.Error(!^$)"], + "field_id": "Result-Code", "type": "*constant", "value": "5030", "blocker": true}, + {"tag": "ResultCode", "field_id": "Result-Code", "type": "*constant", "value": "2001"}, + ], }, ], }, diff --git a/glide.lock b/glide.lock index b95b58ae4..5a840595c 100644 --- a/glide.lock +++ b/glide.lock @@ -22,7 +22,7 @@ imports: - name: github.com/cgrates/rpcclient version: 7316bff37a2b8692fbadd57f9c9cda070cc33081 - name: github.com/fiorix/go-diameter - version: 16028e641c19a8dd67509053bc558d389258ff6d + version: abaf0a5b14a05f3a4a75b8fe23066ab1f898aeac subpackages: - diam - diam/avp