mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Adding Pdd to derived charging
This commit is contained in:
@@ -287,6 +287,7 @@ CREATE TABLE tp_derived_chargers (
|
||||
`subject_field` varchar(24) NOT NULL,
|
||||
`destination_field` varchar(24) NOT NULL,
|
||||
`setup_time_field` varchar(24) NOT NULL,
|
||||
`pdd_field` varchar(24) NOT NULL,
|
||||
`answer_time_field` varchar(24) NOT NULL,
|
||||
`usage_field` varchar(24) NOT NULL,
|
||||
`supplier_field` varchar(24) NOT NULL,
|
||||
|
||||
@@ -282,6 +282,7 @@ CREATE TABLE tp_derived_chargers (
|
||||
subject_field VARCHAR(24) NOT NULL,
|
||||
destination_field VARCHAR(24) NOT NULL,
|
||||
setup_time_field VARCHAR(24) NOT NULL,
|
||||
pdd_field VARCHAR(24) NOT NULL,
|
||||
answer_time_field VARCHAR(24) NOT NULL,
|
||||
usage_field VARCHAR(24) NOT NULL,
|
||||
supplier_field VARCHAR(24) NOT NULL,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Direction,Tenant,Tor,Account,Subject,RunId,RunFilter,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,UsageField,SupplierField,DisconnectCause
|
||||
*out,cgrates.org,call,dan,dan,extra1,,^prepaid,,,,^rif,^rif,,,,^1s,*default,*default
|
||||
*out,cgrates.org,call,dan,dan,extra2,,,,,,^ivo,^ivo,,,,,*default,*default
|
||||
*out,cgrates.org,call,dan,dan,extra3,~filterhdr1:s/(.+)/special_run3/,,,,,^runusr3,^runusr3,,,,,*default,*default
|
||||
*out,cgrates.org,call,dan,*any,extra1,,,,,,^rif2,^rif2,,,,,*default,*default
|
||||
#Direction[0],Tenant[1],Category[2],Account[3],Subject[4],RunId[5],RunFilter[6],ReqTypeField[7],DirectionField[8],TenantField[9],CategoryField[10],AccountField[11],SubjectField[12],DestinationField[13],SetupTimeField[14],PddField[15],AnswerTimeField[16],UsageField[17],SupplierField[18],DisconnectCause[19]
|
||||
*out,cgrates.org,call,dan,dan,extra1,,^prepaid,,,,^rif,^rif,,,,,^1s,*default,*default
|
||||
*out,cgrates.org,call,dan,dan,extra2,,,,,,^ivo,^ivo,,,,,,*default,*default
|
||||
*out,cgrates.org,call,dan,dan,extra3,~filterhdr1:s/(.+)/special_run3/,,,,,^runusr3,^runusr3,,,,,,*default,*default
|
||||
*out,cgrates.org,call,dan,*any,extra1,,,,,,^rif2,^rif2,,,,,,*default,*default
|
||||
|
||||
|
@@ -1,2 +1,2 @@
|
||||
#Direction[0],Tenant[1],Category[2],Account[3],Subject[4],RunId[5],RunFilter[6],ReqTypeField[7],DirectionField[8],TenantField[9],CategoryField[10],AccountField[11],SubjectField[12],DestinationField[13],SetupTimeField[14],AnswerTimeField[15],UsageField[16],SupplierField[17],DisconnectCause[18]
|
||||
*out,cgrates.org,call,1001,1001,derived_run1,,^*rated,*default,*default,*default,*default,^1002,*default,*default,*default,*default,*default,*default
|
||||
#Direction[0],Tenant[1],Category[2],Account[3],Subject[4],RunId[5],RunFilter[6],ReqTypeField[7],DirectionField[8],TenantField[9],CategoryField[10],AccountField[11],SubjectField[12],DestinationField[13],SetupTimeField[14],PddField[15],AnswerTimeField[16],UsageField[17],SupplierField[18],DisconnectCause[19]
|
||||
*out,cgrates.org,call,1001,1001,derived_run1,,^*rated,*default,*default,*default,*default,^1002,*default,*default,*default,*default,*default,*default,*default
|
||||
|
||||
|
@@ -192,10 +192,10 @@ vdf,emptyY,*out,TOPUP_EMPTY_AT,
|
||||
`
|
||||
|
||||
derivedCharges = `
|
||||
#Direction,Tenant,Category,Account,Subject,RunId,RunFilter,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,UsageField
|
||||
*out,cgrates.org,call,dan,dan,extra1,^filteredHeader1/filterValue1/,^prepaid,,,,rif,rif,,,,,,
|
||||
*out,cgrates.org,call,dan,dan,extra2,,,,,,ivo,ivo,,,,,,
|
||||
*out,cgrates.org,call,dan,*any,extra1,,,,,,rif2,rif2,,,,,,
|
||||
#Direction,Tenant,Category,Account,Subject,RunId,RunFilter,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,PddField,AnswerTimeField,UsageField
|
||||
*out,cgrates.org,call,dan,dan,extra1,^filteredHeader1/filterValue1/,^prepaid,,,,rif,rif,,,,,,,
|
||||
*out,cgrates.org,call,dan,dan,extra2,,,,,,ivo,ivo,,,,,,,
|
||||
*out,cgrates.org,call,dan,*any,extra1,,,,,,rif2,rif2,,,,,,,
|
||||
`
|
||||
cdrStats = `
|
||||
#Id[0],QueueLength[1],TimeWindow[2],Metric[3],SetupInterval[4],TOR[5],CdrHost[6],CdrSource[7],ReqType[8],Direction[9],Tenant[10],Category[11],Account[12],Subject[13],DestinationPrefix[14],PddInterval[15],UsageInterval[16],Supplier[17],DisconnectCause[18],MediationRunIds[19],RatedAccount[20],RatedSubject[21],CostInterval[22],Triggers[23]CDRST1,5,60m,ASR,2014-07-29T15:00:00Z;2014-07-29T16:00:00Z,*voice,87.139.12.167,FS_JSON,*rated,*out,cgrates.org,call,dan,dan,49,5m;10m,suppl1,NORMAL_CLEARING,default,rif,rif,0;2,STANDARD_TRIGGERS
|
||||
@@ -1027,17 +1027,17 @@ func TestLoadDerivedChargers(t *testing.T) {
|
||||
expCharger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", RunFilters: "^filteredHeader1/filterValue1/", ReqTypeField: "^prepaid", DirectionField: utils.META_DEFAULT,
|
||||
TenantField: utils.META_DEFAULT, CategoryField: utils.META_DEFAULT, AccountField: "rif", SubjectField: "rif", DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
|
||||
DisconnectCauseField: utils.META_DEFAULT},
|
||||
SetupTimeField: utils.META_DEFAULT, PddField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT,
|
||||
SupplierField: utils.META_DEFAULT, DisconnectCauseField: utils.META_DEFAULT},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: utils.META_DEFAULT, DirectionField: utils.META_DEFAULT, TenantField: utils.META_DEFAULT,
|
||||
CategoryField: utils.META_DEFAULT, AccountField: "ivo", SubjectField: "ivo", DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
|
||||
DisconnectCauseField: utils.META_DEFAULT},
|
||||
SetupTimeField: utils.META_DEFAULT, PddField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT,
|
||||
SupplierField: utils.META_DEFAULT, DisconnectCauseField: utils.META_DEFAULT},
|
||||
}
|
||||
keyCharger1 := utils.DerivedChargersKey("*out", "cgrates.org", "call", "dan", "dan")
|
||||
|
||||
if !csvr.derivedChargers[keyCharger1].Equal(expCharger1) {
|
||||
t.Errorf("Unexpected charger %+v", csvr.derivedChargers[keyCharger1][0])
|
||||
t.Errorf("Expecting: %+v, received: %+v", expCharger1[0], csvr.derivedChargers[keyCharger1][0])
|
||||
}
|
||||
}
|
||||
func TestLoadCdrStats(t *testing.T) {
|
||||
|
||||
@@ -294,6 +294,7 @@ func APItoModelDerivedCharger(dcs *utils.TPDerivedChargers) (result []TpDerivedC
|
||||
CategoryField: dc.CategoryField,
|
||||
AccountField: dc.AccountField,
|
||||
SubjectField: dc.SubjectField,
|
||||
PddField: dc.PddField,
|
||||
DestinationField: dc.DestinationField,
|
||||
SetupTimeField: dc.SetupTimeField,
|
||||
AnswerTimeField: dc.AnswerTimeField,
|
||||
|
||||
@@ -486,6 +486,7 @@ func (tps TpDerivedChargers) GetDerivedChargers() (map[string]*utils.TPDerivedCh
|
||||
SubjectField: ValueOrDefault(tpDcMdl.SubjectField, utils.META_DEFAULT),
|
||||
DestinationField: ValueOrDefault(tpDcMdl.DestinationField, utils.META_DEFAULT),
|
||||
SetupTimeField: ValueOrDefault(tpDcMdl.SetupTimeField, utils.META_DEFAULT),
|
||||
PddField: ValueOrDefault(tpDcMdl.PddField, utils.META_DEFAULT),
|
||||
AnswerTimeField: ValueOrDefault(tpDcMdl.AnswerTimeField, utils.META_DEFAULT),
|
||||
UsageField: ValueOrDefault(tpDcMdl.UsageField, utils.META_DEFAULT),
|
||||
SupplierField: ValueOrDefault(tpDcMdl.SupplierField, utils.META_DEFAULT),
|
||||
|
||||
@@ -467,6 +467,7 @@ func TestTPDerivedChargersAsExportSlice(t *testing.T) {
|
||||
SubjectField: "^1002",
|
||||
DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT,
|
||||
PddField: utils.META_DEFAULT,
|
||||
AnswerTimeField: utils.META_DEFAULT,
|
||||
UsageField: utils.META_DEFAULT,
|
||||
SupplierField: utils.META_DEFAULT,
|
||||
@@ -483,6 +484,7 @@ func TestTPDerivedChargersAsExportSlice(t *testing.T) {
|
||||
SubjectField: utils.META_DEFAULT,
|
||||
DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT,
|
||||
PddField: utils.META_DEFAULT,
|
||||
AnswerTimeField: utils.META_DEFAULT,
|
||||
UsageField: utils.META_DEFAULT,
|
||||
SupplierField: utils.META_DEFAULT,
|
||||
@@ -492,9 +494,9 @@ func TestTPDerivedChargersAsExportSlice(t *testing.T) {
|
||||
}
|
||||
expectedSlc := [][]string{
|
||||
[]string{"*out", "cgrates.org", "call", "1001", "1001",
|
||||
"derived_run1", "", "^rated", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, "^1002", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT},
|
||||
"derived_run1", "", "^rated", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, "^1002", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT},
|
||||
[]string{"*out", "cgrates.org", "call", "1001", "1001",
|
||||
"derived_run2", "", "^rated", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, "^1002", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT},
|
||||
"derived_run2", "", "^rated", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, "^1002", utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT, utils.META_DEFAULT},
|
||||
}
|
||||
ms := APItoModelDerivedCharger(dcs)
|
||||
var slc [][]string
|
||||
|
||||
@@ -263,10 +263,11 @@ type TpDerivedCharger struct {
|
||||
SubjectField string `index:"12" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
DestinationField string `index:"13" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
SetupTimeField string `index:"14" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
AnswerTimeField string `index:"15" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
UsageField string `index:"16" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
SupplierField string `index:"17" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
DisconnectCauseField string `index:"18" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
PddField string `index:"15" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
AnswerTimeField string `index:"16" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
UsageField string `index:"17" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
SupplierField string `index:"18" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
DisconnectCauseField string `index:"19" re:"\*default\s*|[~^]*[0-9A-Za-z_/:().+]+\s*"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
|
||||
@@ -127,23 +127,23 @@ func TestGetSessionRuns(t *testing.T) {
|
||||
testTenant := "vdf"
|
||||
cdr := StoredCdr{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderId: 123, TOR: utils.VOICE, AccId: "dsafdsaf",
|
||||
CdrHost: "192.168.1.1", CdrSource: "test", ReqType: utils.META_PREPAID, Direction: "*out", Tenant: testTenant, Category: "call", Account: "dan2", Subject: "dan2",
|
||||
Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), Supplier: "suppl1",
|
||||
Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), Pdd: 3 * time.Second, AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), Supplier: "suppl1",
|
||||
MediationRunId: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
|
||||
Cost: 1.01, RatedAccount: "dan", RatedSubject: "dan"}
|
||||
keyCharger1 := utils.ConcatenatedKey("*out", testTenant, "call", "dan2", "dan2")
|
||||
dfDC := &utils.DerivedCharger{RunId: utils.DEFAULT_RUNID, ReqTypeField: utils.META_DEFAULT, DirectionField: utils.META_DEFAULT, TenantField: utils.META_DEFAULT,
|
||||
CategoryField: utils.META_DEFAULT, AccountField: utils.META_DEFAULT, SubjectField: utils.META_DEFAULT, DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT, PddField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
|
||||
DisconnectCauseField: utils.META_DEFAULT}
|
||||
extra1DC := &utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^" + utils.META_PREPAID, DirectionField: utils.META_DEFAULT, TenantField: utils.META_DEFAULT,
|
||||
CategoryField: "^0", AccountField: "^minitsboy", SubjectField: "^rif", DestinationField: "^0256",
|
||||
SetupTimeField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT}
|
||||
SetupTimeField: utils.META_DEFAULT, PddField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT}
|
||||
extra2DC := &utils.DerivedCharger{RunId: "extra2", ReqTypeField: utils.META_DEFAULT, DirectionField: utils.META_DEFAULT, TenantField: utils.META_DEFAULT,
|
||||
CategoryField: utils.META_DEFAULT, AccountField: "^ivo", SubjectField: "^ivo", DestinationField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT}
|
||||
extra3DC := &utils.DerivedCharger{RunId: "extra3", ReqTypeField: "^" + utils.META_PSEUDOPREPAID, DirectionField: utils.META_DEFAULT, TenantField: utils.META_DEFAULT,
|
||||
CategoryField: "^0", AccountField: "^minu", SubjectField: "^rif", DestinationField: "^0256",
|
||||
SetupTimeField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
|
||||
SetupTimeField: utils.META_DEFAULT, PddField: utils.META_DEFAULT, AnswerTimeField: utils.META_DEFAULT, UsageField: utils.META_DEFAULT, SupplierField: utils.META_DEFAULT,
|
||||
DisconnectCauseField: utils.META_DEFAULT}
|
||||
charger1 := utils.DerivedChargers{extra1DC, extra2DC, extra3DC}
|
||||
if err := accountingStorage.SetDerivedChargers(keyCharger1, charger1); err != nil {
|
||||
@@ -161,7 +161,7 @@ func TestGetSessionRuns(t *testing.T) {
|
||||
if err := rsponder.GetSessionRuns(cdr, &sesRuns); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eSRuns, sesRuns) {
|
||||
t.Errorf("Received: %+v", sesRuns)
|
||||
t.Errorf("Expecting: %+v, received: %+v", eSRuns, sesRuns)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -816,7 +816,7 @@ func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save
|
||||
}
|
||||
for _, tpDc := range tpDcs.DerivedChargers {
|
||||
dc, err := utils.NewDerivedCharger(tpDc.RunId, tpDc.RunFilters, tpDc.ReqTypeField, tpDc.DirectionField, tpDc.TenantField, tpDc.CategoryField,
|
||||
tpDc.AccountField, tpDc.SubjectField, tpDc.DestinationField, tpDc.SetupTimeField, tpDc.AnswerTimeField, tpDc.UsageField, tpDc.SupplierField,
|
||||
tpDc.AccountField, tpDc.SubjectField, tpDc.DestinationField, tpDc.SetupTimeField, tpDc.PddField, tpDc.AnswerTimeField, tpDc.UsageField, tpDc.SupplierField,
|
||||
tpDc.DisconnectCauseField)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -184,7 +184,6 @@ func (self *KamailioSessionManager) Connect() error {
|
||||
}
|
||||
|
||||
func (self *KamailioSessionManager) DisconnectSession(ev engine.Event, connId, notify string) error {
|
||||
engine.Logger.Debug(fmt.Sprintf("DisconnectSession, ev: %+v, connId: %s, notify: %s", ev, connId, notify))
|
||||
sessionIds := ev.GetSessionIds()
|
||||
disconnectEv := &KamSessionDisconnect{Event: CGR_SESSION_DISCONNECT, HashEntry: sessionIds[0], HashId: sessionIds[1], Reason: notify}
|
||||
if err := self.conns[connId].Send(disconnectEv.String()); err != nil {
|
||||
|
||||
@@ -403,6 +403,7 @@ type TPDerivedCharger struct {
|
||||
SubjectField string
|
||||
DestinationField string
|
||||
SetupTimeField string
|
||||
PddField string
|
||||
AnswerTimeField string
|
||||
UsageField string
|
||||
SupplierField string
|
||||
|
||||
@@ -20,12 +20,11 @@ package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Wraps regexp compiling in case of rsr fields
|
||||
func NewDerivedCharger(runId, runFilters, reqTypeFld, dirFld, tenantFld, catFld, acntFld, subjFld, dstFld, sTimeFld, aTimeFld, durFld, supplFld, dCauseFld string) (dc *DerivedCharger, err error) {
|
||||
func NewDerivedCharger(runId, runFilters, reqTypeFld, dirFld, tenantFld, catFld, acntFld, subjFld, dstFld, sTimeFld, pddFld, aTimeFld, durFld, supplFld, dCauseFld string) (dc *DerivedCharger, err error) {
|
||||
if len(runId) == 0 {
|
||||
return nil, errors.New("Empty run id field")
|
||||
}
|
||||
@@ -84,6 +83,12 @@ func NewDerivedCharger(runId, runFilters, reqTypeFld, dirFld, tenantFld, catFld,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
dc.PddField = pddFld
|
||||
if strings.HasPrefix(dc.PddField, REGEXP_PREFIX) || strings.HasPrefix(dc.PddField, STATIC_VALUE_PREFIX) {
|
||||
if dc.rsrPddField, err = NewRSRField(dc.PddField); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
dc.AnswerTimeField = aTimeFld
|
||||
if strings.HasPrefix(dc.AnswerTimeField, REGEXP_PREFIX) || strings.HasPrefix(dc.AnswerTimeField, STATIC_VALUE_PREFIX) {
|
||||
if dc.rsrAnswerTimeField, err = NewRSRField(dc.AnswerTimeField); err != nil {
|
||||
@@ -122,6 +127,7 @@ type DerivedCharger struct {
|
||||
SubjectField string // Field containing subject information
|
||||
DestinationField string // Field containing destination information
|
||||
SetupTimeField string // Field containing setup time information
|
||||
PddField string // Field containing setup time information
|
||||
AnswerTimeField string // Field containing answer time information
|
||||
UsageField string // Field containing usage information
|
||||
SupplierField string // Field containing supplier information
|
||||
@@ -135,6 +141,7 @@ type DerivedCharger struct {
|
||||
rsrSubjectField *RSRField
|
||||
rsrDestinationField *RSRField
|
||||
rsrSetupTimeField *RSRField
|
||||
rsrPddField *RSRField
|
||||
rsrAnswerTimeField *RSRField
|
||||
rsrUsageField *RSRField
|
||||
rsrSupplierField *RSRField
|
||||
@@ -162,15 +169,13 @@ func (dcs DerivedChargers) Append(dc *DerivedCharger) (DerivedChargers, error) {
|
||||
|
||||
func (dcs DerivedChargers) AppendDefaultRun() (DerivedChargers, error) {
|
||||
dcDf, _ := NewDerivedCharger(DEFAULT_RUNID, "", META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT,
|
||||
META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT)
|
||||
META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT, META_DEFAULT)
|
||||
return append(dcs, dcDf), nil
|
||||
}
|
||||
|
||||
func (dcs DerivedChargers) Equal(other DerivedChargers) bool {
|
||||
for i, dc := range dcs {
|
||||
if !dc.Equal(other[i]) {
|
||||
log.Printf("DC: %+v", dc)
|
||||
log.Printf("OTHER: %+v", other[i])
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -188,6 +193,7 @@ func (dc *DerivedCharger) Equal(other *DerivedCharger) bool {
|
||||
dc.SubjectField == other.SubjectField &&
|
||||
dc.DestinationField == other.DestinationField &&
|
||||
dc.SetupTimeField == other.SetupTimeField &&
|
||||
dc.PddField == other.PddField &&
|
||||
dc.AnswerTimeField == other.AnswerTimeField &&
|
||||
dc.UsageField == other.UsageField &&
|
||||
dc.SupplierField == other.SupplierField &&
|
||||
|
||||
@@ -56,13 +56,14 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
SubjectField: "subject1",
|
||||
DestinationField: "destination1",
|
||||
SetupTimeField: "setuptime1",
|
||||
PddField: "pdd1",
|
||||
AnswerTimeField: "answertime1",
|
||||
UsageField: "duration1",
|
||||
SupplierField: "supplier1",
|
||||
DisconnectCauseField: "NORMAL_CLEARING",
|
||||
}
|
||||
if dc1, err := NewDerivedCharger("test1", "", "reqtype1", "direction1", "tenant1", "tor1", "account1", "subject1", "destination1",
|
||||
"setuptime1", "answertime1", "duration1", "supplier1", "NORMAL_CLEARING"); err != nil {
|
||||
"setuptime1", "pdd1", "answertime1", "duration1", "supplier1", "NORMAL_CLEARING"); err != nil {
|
||||
t.Error("Unexpected error", err.Error)
|
||||
} else if !reflect.DeepEqual(edc1, dc1) {
|
||||
t.Errorf("Expecting: %v, received: %v", edc1, dc1)
|
||||
@@ -78,6 +79,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
SubjectField: "~subject2:s/sip:(.+)/$1/",
|
||||
DestinationField: "~destination2:s/sip:(.+)/$1/",
|
||||
SetupTimeField: "~setuptime2:s/sip:(.+)/$1/",
|
||||
PddField: "~pdd:s/sip:(.+)/$1/",
|
||||
AnswerTimeField: "~answertime2:s/sip:(.+)/$1/",
|
||||
UsageField: "~duration2:s/sip:(.+)/$1/",
|
||||
SupplierField: "~supplier2:s/(.+)/$1/",
|
||||
@@ -92,6 +94,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
edc2.rsrSubjectField, _ = NewRSRField("~subject2:s/sip:(.+)/$1/")
|
||||
edc2.rsrDestinationField, _ = NewRSRField("~destination2:s/sip:(.+)/$1/")
|
||||
edc2.rsrSetupTimeField, _ = NewRSRField("~setuptime2:s/sip:(.+)/$1/")
|
||||
edc2.rsrPddField, _ = NewRSRField("~pdd:s/sip:(.+)/$1/")
|
||||
edc2.rsrAnswerTimeField, _ = NewRSRField("~answertime2:s/sip:(.+)/$1/")
|
||||
edc2.rsrUsageField, _ = NewRSRField("~duration2:s/sip:(.+)/$1/")
|
||||
edc2.rsrSupplierField, _ = NewRSRField("~supplier2:s/(.+)/$1/")
|
||||
@@ -106,6 +109,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
"~subject2:s/sip:(.+)/$1/",
|
||||
"~destination2:s/sip:(.+)/$1/",
|
||||
"~setuptime2:s/sip:(.+)/$1/",
|
||||
"~pdd:s/sip:(.+)/$1/",
|
||||
"~answertime2:s/sip:(.+)/$1/",
|
||||
"~duration2:s/sip:(.+)/$1/",
|
||||
"~supplier2:s/(.+)/$1/",
|
||||
@@ -126,22 +130,22 @@ func TestAppendDefaultRun(t *testing.T) {
|
||||
var dc1 DerivedChargers
|
||||
dcDf := &DerivedCharger{RunId: DEFAULT_RUNID, RunFilters: "", ReqTypeField: META_DEFAULT, DirectionField: META_DEFAULT,
|
||||
TenantField: META_DEFAULT, CategoryField: META_DEFAULT, AccountField: META_DEFAULT, SubjectField: META_DEFAULT,
|
||||
DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, AnswerTimeField: META_DEFAULT, UsageField: META_DEFAULT, SupplierField: META_DEFAULT,
|
||||
DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, PddField: META_DEFAULT, AnswerTimeField: META_DEFAULT, UsageField: META_DEFAULT, SupplierField: META_DEFAULT,
|
||||
DisconnectCauseField: META_DEFAULT}
|
||||
eDc1 := DerivedChargers{dcDf}
|
||||
if dc1, _ = dc1.AppendDefaultRun(); !reflect.DeepEqual(dc1, eDc1) {
|
||||
t.Error("Unexpected result.")
|
||||
t.Errorf("Expecting: %+v, received: %+v", eDc1[0], dc1[0])
|
||||
}
|
||||
dc2 := DerivedChargers{
|
||||
&DerivedCharger{RunId: "extra1", RunFilters: "", ReqTypeField: "reqtype2", DirectionField: META_DEFAULT, TenantField: META_DEFAULT, CategoryField: META_DEFAULT,
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, AnswerTimeField: META_DEFAULT, UsageField: META_DEFAULT,
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, PddField: META_DEFAULT, AnswerTimeField: META_DEFAULT, UsageField: META_DEFAULT,
|
||||
DisconnectCauseField: META_DEFAULT},
|
||||
&DerivedCharger{RunId: "extra2", ReqTypeField: META_DEFAULT, DirectionField: META_DEFAULT, TenantField: META_DEFAULT, CategoryField: META_DEFAULT,
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, AnswerTimeField: META_DEFAULT,
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: META_DEFAULT, SetupTimeField: META_DEFAULT, PddField: META_DEFAULT, AnswerTimeField: META_DEFAULT,
|
||||
UsageField: META_DEFAULT, SupplierField: META_DEFAULT, DisconnectCauseField: META_DEFAULT},
|
||||
}
|
||||
eDc2 := append(dc2, dcDf)
|
||||
if dc2, _ = dc2.AppendDefaultRun(); !reflect.DeepEqual(dc2, eDc2) {
|
||||
t.Error("Unexpected result.")
|
||||
t.Errorf("Expecting: %+v, received: %+v", eDc2, dc2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user