Skip to content

Commit

Permalink
[feg] session_proxy add Offline and Online AVPs (#7419)
Browse files Browse the repository at this point in the history
  • Loading branch information
uri200 committed Jun 29, 2021
1 parent 8a27411 commit 9c0a20c
Show file tree
Hide file tree
Showing 22 changed files with 848 additions and 696 deletions.
4 changes: 2 additions & 2 deletions feg/gateway/go.mod
Expand Up @@ -26,7 +26,7 @@ require (
github.com/emakeev/snowflake v0.0.0-20200206205012-767080b052fe
github.com/envoyproxy/go-control-plane v0.9.4
github.com/fiorix/go-diameter/v4 v4.0.4
github.com/go-openapi/swag v0.19.5
github.com/go-openapi/swag v0.19.15
github.com/go-redis/redis v6.14.1+incompatible
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.5.2
Expand All @@ -45,7 +45,7 @@ require (
golang.org/x/sys v0.0.0-20210426080607-c94f62235c83 // indirect
google.golang.org/grpc v1.33.2
google.golang.org/protobuf v1.26.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
gotest.tools/gotestsum v1.6.4 // indirect
layeh.com/radius v0.0.0-20200615152116-663b41c3bf86
magma/feg/cloud/go v0.0.0
magma/feg/cloud/go/protos v0.0.0
Expand Down
8 changes: 8 additions & 0 deletions feg/gateway/go.sum
Expand Up @@ -100,6 +100,7 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down Expand Up @@ -251,6 +252,8 @@ github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-openapi/validate v0.17.2/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
github.com/go-openapi/validate v0.18.0 h1:PVXYcP1GkTl+XIAJnyJxOmK6CSG5Q1UcvoCvNO++5Kg=
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
Expand Down Expand Up @@ -397,6 +400,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -427,6 +432,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/labstack/echo v0.0.0-20181123063414-c54d9e8eed6c h1:RJpEpNeljivHmL1Q5DB2QBoGbnBXY18rZshzbHxMCFo=
github.com/labstack/echo v0.0.0-20181123063414-c54d9e8eed6c/go.mod h1:rS0D1UPvC8/3sXjhSwEq+K1olh7ipbDhjDWATN2KSgA=
Expand Down Expand Up @@ -458,6 +464,8 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
Expand Down
Expand Up @@ -93,6 +93,8 @@ type CreditControlAnswer struct {
EventTriggers []EventTrigger
RevalidationTime *time.Time
Qos *QosInformation
Online int32
Offline int32
}

type UsageReport struct {
Expand Down Expand Up @@ -133,6 +135,8 @@ type RuleDefinition struct {
RedirectInformation *RedirectInformation `avp:"Redirect-Information"`
Qos *QosInformation `avp:"QoS-Information"`
ServiceIdentifier *uint32 `avp:"Service-Identifier"`
Online int32 `avp:"Online"`
Offline int32 `avp:"Offline"`
}

// QoS per service date flow message
Expand Down Expand Up @@ -187,6 +191,8 @@ type CCADiameterMessage struct {
EventTriggers []EventTrigger `avp:"Event-Trigger"`
RevalidationTime *time.Time `avp:"Revalidation-Time"`
Qos *QosInformation `avp:"QoS-Information"`
Online int32 `avp:"Online"`
Offline int32 `avp:"Offline"`
}

//<RA-Request> ::= < Diameter Header: 258, REQ, PXY >
Expand Down
Expand Up @@ -53,6 +53,8 @@ func ccaHandler(message *diam.Message) diameter.KeyAndAnswer {
EventTriggers: cca.EventTriggers,
RevalidationTime: cca.RevalidationTime,
Qos: cca.Qos,
Online: cca.Online,
Offline: cca.Offline,
},
}
}
Expand Down
Expand Up @@ -73,6 +73,8 @@ func (rd *RuleDefinition) ToProto() *protos.PolicyRule {
FlowList: rd.GetFlowList(),
Qos: rd.Qos.ToProto(),
TrackingType: rd.GetTrackingType(),
Offline: Int32ToBoolean(rd.Offline),
Online: Int32ToBoolean(rd.Online),
}
}

Expand Down Expand Up @@ -350,3 +352,8 @@ func GetIPCANType(pRATType protos.RATType) credit_control.IPCANType {
return credit_control.IPCAN_Non3GPP
}
}

//Int32ToBoolean converts int32 to true if diffent than 0
func Int32ToBoolean(val int32) bool {
return val != 0
}
Expand Up @@ -397,7 +397,6 @@ func getMSCCAVP(requestType credit_control.CreditRequestType, credits *UsedCredi
}
avpGroup = append(
avpGroup, diam.NewAVP(avp.RequestedServiceUnit, avp.Mbit, 0, &diam.GroupedAVP{AVP: usuGrp}))

}

if serviceIdentifier >= 0 {
Expand Down
2 changes: 2 additions & 0 deletions feg/gateway/services/session_proxy/servicers/policy.go
Expand Up @@ -90,6 +90,8 @@ func generateGxLessCCAInit() (*gx.CreditControlAnswer, error) {
UsageMonitors: []*gx.UsageMonitoringInfo{},
EventTriggers: []gx.EventTrigger{},
RevalidationTime: nil,
Online: 1,
Offline: 0,
}, nil
}

Expand Down
Expand Up @@ -109,13 +109,16 @@ func (srv *CentralSessionController) CreateSession(
gxOriginHost, gyOriginHost := gxCCAInit.OriginHost, ""

credits := []*protos.CreditUpdateResponse{}
// Gy

// Gy: only send Gy if it is Enabled and flag Online is true (1)
if !srv.cfg.DisableGy {
if srv.cfg.UseGyForAuthOnly {
return srv.handleUseGyForAuthOnly(
imsi, request, staticRuleInstalls, dynamicRuleInstalls, gxCCAInit)
}
if len(chargingKeys) > 0 {
if !gx.Int32ToBoolean(gxCCAInit.Online) {
glog.V(2).Info("Online AVP (1009) is 0. Not sending Gy CCI-R")
} else if len(chargingKeys) > 0 {
gyCCRInit := makeCCRInit(imsi, request, chargingKeys)
gyCCAInit, err := srv.sendSingleCreditRequest(gyCCRInit)
metrics.ReportCreateGySession(err)
Expand All @@ -138,6 +141,8 @@ func (srv *CentralSessionController) CreateSession(
SessionId: request.SessionId,
EventTriggers: eventTriggers,
RevalidationTime: revalidationTime,
Online: gx.Int32ToBoolean(gxCCAInit.Online),
Offline: gx.Int32ToBoolean(gxCCAInit.Offline),
}, nil
}

Expand Down
Expand Up @@ -155,6 +155,7 @@ func TestStartSessionGyFail(t *testing.T) {
SessionID: request.SessionID,
RequestNumber: request.RequestNumber,
RuleInstallAVP: ruleInstalls,
Online: 1,
}
}).Once()

Expand Down Expand Up @@ -277,6 +278,7 @@ func standardUsageTest(
SessionID: request.SessionID,
RequestNumber: request.RequestNumber,
RuleInstallAVP: ruleInstalls,
Online: 1,
}
}).Once()

Expand Down Expand Up @@ -454,6 +456,7 @@ func TestSessionCreateWithOmnipresentRules(t *testing.T) {
SessionID: request.SessionID,
RequestNumber: request.RequestNumber,
RuleInstallAVP: ruleInstalls,
Online: 1,
}
}).Once()
mockPolicyDBClient.On("GetRuleIDsForBaseNames", []string{"base_10"}).Return([]string{"base_rule_1", "base_rule_2"})
Expand Down Expand Up @@ -1717,6 +1720,7 @@ func TestSessionControllerUseGyForAuthOnlySubscriberBarred(t *testing.T) {
SessionID: request.SessionID,
RequestNumber: request.RequestNumber,
RuleInstallAVP: ruleInstalls,
Online: 1,
}
}).Once()

Expand Down
7 changes: 7 additions & 0 deletions feg/gateway/services/testcore/pcrf/mock_pcrf/ccr_handler.go
Expand Up @@ -19,6 +19,7 @@ import (
"reflect"

"magma/feg/cloud/go/protos"
"magma/feg/gateway/diameter"
"magma/feg/gateway/services/session_proxy/credit_control"
"magma/feg/gateway/services/session_proxy/credit_control/gx"

Expand All @@ -41,6 +42,8 @@ type ccrMessage struct {
UsageMonitors []*usageMonitorRequestAVP `avp:"Usage-Monitoring-Information"`
CalledStationId string `avp:"Called-Station-Id"`
EventTrigger datatype.Enumerated `avp:"Event-Trigger"`
Online int32 `avp:"Online"`
Offline int32 `avp:"Offline"`
}

type subscriptionIDDiam struct {
Expand Down Expand Up @@ -141,6 +144,10 @@ func sendAnswer(
a.NewAVP(avp.DestinationHost, avp.Mbit, 0, ccr.OriginHost)
a.NewAVP(avp.CCRequestType, avp.Mbit, 0, ccr.RequestType)
a.NewAVP(avp.CCRequestNumber, avp.Mbit, 0, ccr.RequestNumber)
if credit_control.CreditRequestType(ccr.RequestType) == credit_control.CRTInit {
a.NewAVP(avp.Online, avp.Mbit|avp.Vbit, diameter.Vendor3GPP, datatype.Enumerated(1))
a.NewAVP(avp.Offline, avp.Mbit|avp.Vbit, diameter.Vendor3GPP, datatype.Enumerated(0))
}
for _, avp := range additionalAVPs {
a.InsertAVP(avp)
}
Expand Down

0 comments on commit 9c0a20c

Please sign in to comment.