Skip to content

Commit

Permalink
Added disconnect_method config for diameter agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Trial97 authored and danbogos committed Mar 24, 2020
1 parent 2a5a541 commit d4fc68c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
32 changes: 22 additions & 10 deletions agents/diamagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,29 @@ func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r
utils.DiameterAgent, utils.ToJSON(args.EventStart)))
return utils.ErrMandatoryIeMissing
}
msg, has := engine.Cache.Get(utils.CacheDiameterMessages, ssID.(string))
originID := ssID.(string)
switch da.cgrCfg.DiameterAgentCfg().DisconnectMethod {
case utils.MetaASR:
return da.sendASR(originID, reply)
case utils.MetaRAR:
return da.V1SendRAR(originID, reply)
default:
return fmt.Errorf("Unsupported request type <%s>", da.cgrCfg.DiameterAgentCfg().DisconnectMethod)
}
}

// V1GetActiveSessionIDs is part of the sessions.BiRPClient
func (da *DiameterAgent) V1GetActiveSessionIDs(ignParam string,
sessionIDs *[]*sessions.SessionID) error {
return utils.ErrNotImplemented
}

func (da *DiameterAgent) sendASR(originID string, reply *string) (err error) {
msg, has := engine.Cache.Get(utils.CacheDiameterMessages, originID)
if !has {
utils.Logger.Warning(
fmt.Sprintf("<%s> cannot retrieve message from cache with OriginID: <%s>",
utils.DiameterAgent, ssID))
utils.DiameterAgent, originID))
return utils.ErrMandatoryIeMissing
}
dmd := msg.(*diamMsgData)
Expand All @@ -460,7 +478,7 @@ func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r
if err = aReq.SetFields(da.cgrCfg.DiameterAgentCfg().Templates[da.cgrCfg.DiameterAgentCfg().ASRTemplate]); err != nil {
utils.Logger.Warning(
fmt.Sprintf("<%s> cannot disconnect session with OriginID: <%s>, err: %s",
utils.DiameterAgent, ssID, err.Error()))
utils.DiameterAgent, originID, err.Error()))
return utils.ErrServerError
}
m := diam.NewRequest(dmd.m.Header.CommandCode,
Expand All @@ -469,7 +487,7 @@ func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r
da.cgrCfg.GeneralCfg().DefaultTimezone); err != nil {
utils.Logger.Warning(
fmt.Sprintf("<%s> cannot disconnect session with OriginID: <%s>, err: %s",
utils.DiameterAgent, ssID, err.Error()))
utils.DiameterAgent, originID, err.Error()))
return utils.ErrServerError
}
if err = writeOnConn(dmd.c, m); err != nil {
Expand All @@ -479,12 +497,6 @@ func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r
return
}

// V1GetActiveSessionIDs is part of the sessions.BiRPClient
func (da *DiameterAgent) V1GetActiveSessionIDs(ignParam string,
sessionIDs *[]*sessions.SessionID) error {
return utils.ErrNotImplemented
}

// V1SendRAR sends a rar meseage to diameter client
func (da *DiameterAgent) V1SendRAR(originID string, reply *string) (err error) {
if originID == "" {
Expand Down
3 changes: 2 additions & 1 deletion config/config_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ const CGRATES_CFG_JSON = `
"concurrent_requests": -1, // limit the number of active requests processed by the server <-1|0-n>
"synced_conn_requests": false, // process one request at the time per connection
"asr_template": "", // enable AbortSession message being sent to client on DisconnectSession
"rar_template": "", // for building the RAR
"rar_template": "", // template used to build the Re-Auth-Request
"disconnect_method": "*asr", // the request to send to diameter on DisconnectSession <*asr|*rar>
"templates":{ // default message templates
"*err": [
{"tag": "SessionId", "path": "*rep.Session-Id", "type": "*variable",
Expand Down
1 change: 1 addition & 0 deletions config/config_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ func TestDiameterAgentJsonCfg(t *testing.T) {
Synced_conn_requests: utils.BoolPointer(false),
Asr_template: utils.StringPointer(""),
Rar_template: utils.StringPointer(""),
Disconnect_method: utils.StringPointer(utils.MetaASR),
Templates: map[string][]*FcTemplateJsonCfg{
utils.MetaErr: {
{
Expand Down
4 changes: 4 additions & 0 deletions config/diametercfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type DiameterAgentCfg struct {
SyncedConnReqs bool
ASRTemplate string
RARTemplate string
DisconnectMethod string
Templates map[string][]*FCTemplate
RequestProcessors []*RequestProcessor
}
Expand Down Expand Up @@ -89,6 +90,9 @@ func (da *DiameterAgentCfg) loadFromJsonCfg(jsnCfg *DiameterAgentJsonCfg, separa
if jsnCfg.Rar_template != nil {
da.RARTemplate = *jsnCfg.Rar_template
}
if jsnCfg.Disconnect_method != nil {
da.DisconnectMethod = *jsnCfg.Disconnect_method
}
if jsnCfg.Templates != nil {
if da.Templates == nil {
da.Templates = make(map[string][]*FCTemplate)
Expand Down
1 change: 1 addition & 0 deletions config/libconfig_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ type DiameterAgentJsonCfg struct {
Synced_conn_requests *bool
Asr_template *string
Rar_template *string
Disconnect_method *string
Templates map[string][]*FcTemplateJsonCfg
Request_processors *[]*ReqProcessorJsnCfg
}
Expand Down
1 change: 1 addition & 0 deletions packages/debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium
DataDB/StorDB
* [Migrator] Auto discover tenant from key instead of taking it from config
* [Templates] Fixed missing "*" for strip and pading strategy
* [DiameterAgent] Added RAR support

-- Alexandru Tripon <[email protected]> Wed, 19 Feb 2020 13:25:52 +0200

Expand Down

0 comments on commit d4fc68c

Please sign in to comment.