From 57289481ddec5fca526e18093d2a06b6f6cdbfbe Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 2 Dec 2015 13:58:14 +0100 Subject: [PATCH 1/3] Diameter modifications to support vendorId --- agents/libdmt.go | 102 +-- data/diameter/dict/huawei/3gpp_vendor.xml | 748 +++++++++++----------- data/diameter/dict/huawei/huawei.xml | 64 +- data/diameter/dict/huawei/nasreq.xml | 2 +- data/diameter/dict/huawei/nokia.xml | 4 +- data/diameter/dict/huawei/vodafone.xml | 50 ++ 6 files changed, 479 insertions(+), 491 deletions(-) create mode 100644 data/diameter/dict/huawei/vodafone.xml diff --git a/agents/libdmt.go b/agents/libdmt.go index f9492dba6..5e459eea6 100644 --- a/agents/libdmt.go +++ b/agents/libdmt.go @@ -229,19 +229,11 @@ func (self *CCR) AsDiameterMessage() (*diam.Message, error) { if _, err := m.NewAVP("Event-Timestamp", avp.Mbit, 0, datatype.Time(self.EventTimestamp)); err != nil { return nil, err } - subscriptionIdType, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Subscription-Id-Type") - if err != nil { - return nil, err - } - subscriptionIdData, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Subscription-Id-Data") - if err != nil { - return nil, err - } for _, subscriptionId := range self.SubscriptionId { if _, err := m.NewAVP("Subscription-Id", avp.Mbit, 0, &diam.GroupedAVP{ AVP: []*diam.AVP{ - diam.NewAVP(subscriptionIdType.Code, avp.Mbit, 0, datatype.Enumerated(subscriptionId.SubscriptionIdType)), - diam.NewAVP(subscriptionIdData.Code, avp.Mbit, 0, datatype.UTF8String(subscriptionId.SubscriptionIdData)), + diam.NewAVP(450, avp.Mbit, 0, datatype.Enumerated(subscriptionId.SubscriptionIdType)), // Subscription-Id-Type + diam.NewAVP(444, avp.Mbit, 0, datatype.UTF8String(subscriptionId.SubscriptionIdData)), // Subscription-Id-Data }}); err != nil { return nil, err } @@ -249,87 +241,33 @@ func (self *CCR) AsDiameterMessage() (*diam.Message, error) { if _, err := m.NewAVP("Service-Identifier", avp.Mbit, 0, datatype.Unsigned32(self.ServiceIdentifier)); err != nil { return nil, err } - ccTimeAvp, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "CC-Time") - if err != nil { - return nil, err - } if _, err := m.NewAVP("Requested-Service-Unit", avp.Mbit, 0, &diam.GroupedAVP{ AVP: []*diam.AVP{ - diam.NewAVP(ccTimeAvp.Code, avp.Mbit, 0, datatype.Unsigned32(self.RequestedServiceUnit.CCTime))}}); err != nil { + diam.NewAVP(420, avp.Mbit, 0, datatype.Unsigned32(self.RequestedServiceUnit.CCTime))}}); err != nil { // CC-Time return nil, err } - inInformation, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "IN-Information") - if err != nil { - return nil, err - } - callingPartyAddress, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Calling-Party-Address") - if err != nil { - return nil, err - } - calledPartyAddress, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Called-Party-Address") - if err != nil { - return nil, err - } - realCalledNumber, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Real-Called-Number") - if err != nil { - return nil, err - } - chargeFlowType, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Charge-Flow-Type") - if err != nil { - return nil, err - } - callingVlrNumber, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Calling-Vlr-Number") - if err != nil { - return nil, err - } - callingCellIdOrSai, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Calling-CellID-Or-SAI") - if err != nil { - return nil, err - } - bearerCapability, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Bearer-Capability") - if err != nil { - return nil, err - } - callReferenceNumber, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Call-Reference-Number") - if err != nil { - return nil, err - } - mscAddress, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "MSC-Address") - if err != nil { - return nil, err - } - timeZone, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Time-Zone") - if err != nil { - return nil, err - } - calledPartyNP, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "Called-Party-NP") - if err != nil { - return nil, err - } - sspTime, err := m.Dictionary().FindAVP(m.Header.ApplicationID, "SSP-Time") - if err != nil { - return nil, err - } - if _, err := m.NewAVP("Service-Information", avp.Mbit, 0, &diam.GroupedAVP{ + if si, err := m.NewAVP("Service-Information", avp.Mbit, 10415, &diam.GroupedAVP{ AVP: []*diam.AVP{ - diam.NewAVP(inInformation.Code, avp.Mbit, 0, &diam.GroupedAVP{ + diam.NewAVP(20300, avp.Mbit, 20300, &diam.GroupedAVP{ AVP: []*diam.AVP{ - diam.NewAVP(callingPartyAddress.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.CallingPartyAddress)), - diam.NewAVP(calledPartyAddress.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.CalledPartyAddress)), - diam.NewAVP(realCalledNumber.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.RealCalledNumber)), - diam.NewAVP(chargeFlowType.Code, avp.Mbit, 0, datatype.Unsigned32(self.ServiceInformation.INInformation.ChargeFlowType)), - diam.NewAVP(callingVlrNumber.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.CallingVlrNumber)), - diam.NewAVP(callingCellIdOrSai.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.CallingCellIDOrSAI)), - diam.NewAVP(bearerCapability.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.BearerCapability)), - diam.NewAVP(callReferenceNumber.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.CallReferenceNumber)), - diam.NewAVP(mscAddress.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.MSCAddress)), - diam.NewAVP(timeZone.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.TimeZone)), - diam.NewAVP(calledPartyNP.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.CalledPartyNP)), - diam.NewAVP(sspTime.Code, avp.Mbit, 0, datatype.UTF8String(self.ServiceInformation.INInformation.SSPTime)), + diam.NewAVP(831, avp.Mbit, 10415, datatype.UTF8String(self.ServiceInformation.INInformation.CallingPartyAddress)), // Calling-Party-Address + diam.NewAVP(832, avp.Mbit, 10415, datatype.UTF8String(self.ServiceInformation.INInformation.CalledPartyAddress)), // Called-Party-Address + diam.NewAVP(20327, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.RealCalledNumber)), // Real-Called-Number + diam.NewAVP(20339, avp.Mbit, 20300, datatype.Unsigned32(self.ServiceInformation.INInformation.ChargeFlowType)), // Charge-Flow-Type + diam.NewAVP(20302, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.CallingVlrNumber)), // Calling-Vlr-Number + diam.NewAVP(20303, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.CallingCellIDOrSAI)), // Calling-CellID-Or-SAI + diam.NewAVP(20313, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.BearerCapability)), // Bearer-Capability + diam.NewAVP(20321, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.CallReferenceNumber)), // Call-Reference-Number + diam.NewAVP(20322, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.MSCAddress)), // MSC-Address + diam.NewAVP(20324, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.TimeZone)), // Time-Zone + diam.NewAVP(20385, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.CalledPartyNP)), // Called-Party-NP + diam.NewAVP(20386, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.SSPTime)), // SSP-Time }, }), }}); err != nil { return nil, err + } else { + fmt.Printf("### Service-Information AVP: %+v\n", si) } return m, nil } @@ -375,7 +313,7 @@ func (self *CCR) eventFieldValue(fldTpl utils.RSRFields) string { for i, val := range hierarchyPath { hpIf[i] = val } - matchingAvps, err := self.diamMessage.FindAVPsWithPath(hpIf) + matchingAvps, err := self.diamMessage.FindAVPsWithPath(hpIf, dict.UndefinedVendorID) if err != nil || len(matchingAvps) == 0 { utils.Logger.Warning(fmt.Sprintf(" Cannot find AVP for field template with id: %s, ignoring.", rsrTpl.Id)) continue // Filter not matching diff --git a/data/diameter/dict/huawei/3gpp_vendor.xml b/data/diameter/dict/huawei/3gpp_vendor.xml index fa8746cf6..5e08f29c4 100644 --- a/data/diameter/dict/huawei/3gpp_vendor.xml +++ b/data/diameter/dict/huawei/3gpp_vendor.xml @@ -2,28 +2,28 @@ - + - + - + - + - + - + - + - + @@ -31,84 +31,84 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -120,47 +120,47 @@ - + - + - + - + - + - + - + - + @@ -168,19 +168,19 @@ - + - + - + @@ -188,96 +188,96 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -286,10 +286,10 @@ - + - + @@ -299,10 +299,10 @@ - + - + @@ -310,22 +310,22 @@ - + - + - + - + @@ -342,65 +342,65 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -408,41 +408,41 @@ - + - + - + - + - + - + - + - + @@ -452,10 +452,10 @@ - + - + @@ -464,32 +464,32 @@ - + - + - + - + - + - + - + @@ -497,43 +497,43 @@ - + - + - + - + - + - + - + - + - + - + @@ -586,40 +586,40 @@ - + - + - + - + - + - + - + - + - + - + @@ -628,47 +628,47 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -678,14 +678,14 @@ - + - + @@ -693,10 +693,10 @@ - + - + @@ -705,7 +705,7 @@ - + @@ -715,31 +715,31 @@ - + - + - + - + - + - + - + @@ -748,50 +748,50 @@ - + - + - + - + - + - + - + - + - + - + @@ -808,35 +808,35 @@ - + - + - + - + - + - + - + @@ -844,19 +844,19 @@ - + - + - + - + @@ -875,13 +875,13 @@ - + - + @@ -889,16 +889,16 @@ - + - + - + - + @@ -922,44 +922,44 @@ - + - + - + - + - + - + - + - + - + - + @@ -967,14 +967,14 @@ - + - + @@ -996,34 +996,34 @@ - + - + - + - + - + - + - + - + - + - + @@ -1032,42 +1032,42 @@ - + - + - + - + - + - + - + - + @@ -1075,13 +1075,13 @@ - + - + - + @@ -1089,7 +1089,7 @@ - + @@ -1097,32 +1097,32 @@ - + - + - + - + - + - + - + @@ -1132,13 +1132,13 @@ - + - + - + @@ -1147,10 +1147,10 @@ - + - + @@ -1167,22 +1167,22 @@ - + - + - + - + @@ -1190,16 +1190,16 @@ - + - + - + @@ -1207,16 +1207,16 @@ - + - + - + - + @@ -1224,42 +1224,42 @@ - + - + - + - + - + - + - + - + @@ -1319,7 +1319,7 @@ - + @@ -1334,7 +1334,7 @@ - + @@ -1351,16 +1351,16 @@ - + - + - + - + @@ -1369,7 +1369,7 @@ - + @@ -1384,28 +1384,28 @@ - + - + - + - + - + - + @@ -1413,7 +1413,7 @@ - + @@ -1422,50 +1422,50 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -1478,35 +1478,35 @@ - + - + - + - + - + - + - + - + @@ -1520,31 +1520,31 @@ - + - + - + - + - + - + - + @@ -1558,16 +1558,16 @@ - + - + - + @@ -1575,10 +1575,10 @@ - + - + @@ -1604,10 +1604,10 @@ - + - + @@ -1627,22 +1627,22 @@ - + - + - + - + - + @@ -1653,7 +1653,7 @@ - + @@ -1662,40 +1662,40 @@ - + - + - + - + - + - + - + - + - + - + @@ -1705,26 +1705,26 @@ - + - + - + - + - + - + @@ -1750,7 +1750,7 @@ - + @@ -1758,10 +1758,10 @@ - + - + @@ -1776,44 +1776,44 @@ - + - + - + - + - + - + - + - + - + - + - + @@ -1827,13 +1827,13 @@ - + - + @@ -1846,29 +1846,29 @@ - + - + - + - + - + - + - + @@ -1876,31 +1876,31 @@ - + - + - + - + - + - + - + @@ -1908,22 +1908,22 @@ - + - + - + - + - + - + @@ -1936,21 +1936,21 @@ - + - + - + - + @@ -1991,60 +1991,60 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2060,35 +2060,35 @@ - + - + - + - + - + - + - + - + - + - + - \ No newline at end of file + diff --git a/data/diameter/dict/huawei/huawei.xml b/data/diameter/dict/huawei/huawei.xml index 8a6d3658f..9ae1fc15b 100644 --- a/data/diameter/dict/huawei/huawei.xml +++ b/data/diameter/dict/huawei/huawei.xml @@ -2,7 +2,7 @@ - + @@ -28,7 +28,7 @@ - + @@ -36,89 +36,89 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -127,19 +127,19 @@ - + - + - + - + - + diff --git a/data/diameter/dict/huawei/nasreq.xml b/data/diameter/dict/huawei/nasreq.xml index 3ef42fe58..347bf7199 100644 --- a/data/diameter/dict/huawei/nasreq.xml +++ b/data/diameter/dict/huawei/nasreq.xml @@ -872,4 +872,4 @@ - + \ No newline at end of file diff --git a/data/diameter/dict/huawei/nokia.xml b/data/diameter/dict/huawei/nokia.xml index cd1393d0b..2d6d27f11 100644 --- a/data/diameter/dict/huawei/nokia.xml +++ b/data/diameter/dict/huawei/nokia.xml @@ -2,8 +2,8 @@ - + - + \ No newline at end of file diff --git a/data/diameter/dict/huawei/vodafone.xml b/data/diameter/dict/huawei/vodafone.xml new file mode 100644 index 000000000..ff56332c0 --- /dev/null +++ b/data/diameter/dict/huawei/vodafone.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 071f88a7f24e1201892a49ebeef86b77fb29444b Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 3 Dec 2015 13:00:24 +0100 Subject: [PATCH 2/3] Diameter fix timezone in message, fix values returned from session generic in case of debits --- agents/dmtagent_it_test.go | 8 ++++---- agents/libdmt.go | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/agents/dmtagent_it_test.go b/agents/dmtagent_it_test.go index 6e797ddef..7ace75444 100644 --- a/agents/dmtagent_it_test.go +++ b/agents/dmtagent_it_test.go @@ -201,7 +201,7 @@ func TestDmtAgentSendCCRInit(t *testing.T) { time.Sleep(time.Duration(100) * time.Millisecond) var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - eAcntVal := 9.5 + eAcntVal := 9.484 if err := apierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { @@ -232,7 +232,7 @@ func TestDmtAgentSendCCRUpdate(t *testing.T) { time.Sleep(time.Duration(100) * time.Millisecond) var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - eAcntVal := 9.25 + eAcntVal := 9.214 if err := apierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { @@ -263,7 +263,7 @@ func TestDmtAgentSendCCRUpdate2(t *testing.T) { time.Sleep(time.Duration(100) * time.Millisecond) var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - eAcntVal := 9.0 + eAcntVal := 8.944 if err := apierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { @@ -293,7 +293,7 @@ func TestDmtAgentSendCCRTerminate(t *testing.T) { time.Sleep(time.Duration(100) * time.Millisecond) var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - eAcntVal := 9.2416 + eAcntVal := 9.205 if err := apierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { // Should also consider derived charges which double the cost of 6m10s - 2x0.7584 diff --git a/agents/libdmt.go b/agents/libdmt.go index 5e459eea6..d9cee6265 100644 --- a/agents/libdmt.go +++ b/agents/libdmt.go @@ -246,7 +246,7 @@ func (self *CCR) AsDiameterMessage() (*diam.Message, error) { diam.NewAVP(420, avp.Mbit, 0, datatype.Unsigned32(self.RequestedServiceUnit.CCTime))}}); err != nil { // CC-Time return nil, err } - if si, err := m.NewAVP("Service-Information", avp.Mbit, 10415, &diam.GroupedAVP{ + if _, err := m.NewAVP("Service-Information", avp.Mbit, 10415, &diam.GroupedAVP{ AVP: []*diam.AVP{ diam.NewAVP(20300, avp.Mbit, 20300, &diam.GroupedAVP{ AVP: []*diam.AVP{ @@ -259,15 +259,13 @@ func (self *CCR) AsDiameterMessage() (*diam.Message, error) { diam.NewAVP(20313, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.BearerCapability)), // Bearer-Capability diam.NewAVP(20321, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.CallReferenceNumber)), // Call-Reference-Number diam.NewAVP(20322, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.MSCAddress)), // MSC-Address - diam.NewAVP(20324, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.TimeZone)), // Time-Zone + diam.NewAVP(20324, avp.Mbit, 20300, datatype.Unsigned32(self.ServiceInformation.INInformation.TimeZone)), // Time-Zone diam.NewAVP(20385, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.CalledPartyNP)), // Called-Party-NP diam.NewAVP(20386, avp.Mbit, 20300, datatype.UTF8String(self.ServiceInformation.INInformation.SSPTime)), // SSP-Time }, }), }}); err != nil { return nil, err - } else { - fmt.Printf("### Service-Information AVP: %+v\n", si) } return m, nil } From f78c487c5de694977b231cdd08a7fa640b56dddd Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 3 Dec 2015 14:58:46 +0200 Subject: [PATCH 3/3] fix cache loading from mongo --- cmd/cgr-engine/cgr-engine.go | 6 +++--- engine/storage_mongo.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 048c09119..3e819fa82 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -485,9 +485,9 @@ func startCDRS(internalCdrSChan chan *engine.CdrServer, logDb engine.LogStorage, } func startScheduler(internalSchedulerChan chan *scheduler.Scheduler, cacheDoneChan chan struct{}, ratingDb engine.RatingStorage, exitChan chan bool) { - // Wait for cache to load data before starting - cacheDone := <- cacheDoneChan - cacheDoneChan <- cacheDone + // Wait for cache to load data before starting + cacheDone := <-cacheDoneChan + cacheDoneChan <- cacheDone utils.Logger.Info("Starting CGRateS Scheduler.") sched := scheduler.NewScheduler() go reloadSchedulerSingnalHandler(sched, ratingDb) diff --git a/engine/storage_mongo.go b/engine/storage_mongo.go index aa171baa3..5ea101224 100644 --- a/engine/storage_mongo.go +++ b/engine/storage_mongo.go @@ -955,7 +955,7 @@ func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool) (loadInsts []* cache2go.RemKey(utils.LOADINST_KEY) cache2go.Cache(utils.LOADINST_KEY, loadInsts) } - return loadInsts, err + return loadInsts, nil } // Adds a single load instance to load history