diff --git a/agents/dnsagent_it_test.go b/agents/dnsagent_it_test.go index 838916f7e..6d9e4cf0d 100644 --- a/agents/dnsagent_it_test.go +++ b/agents/dnsagent_it_test.go @@ -46,7 +46,8 @@ var sTestsDNS = []func(t *testing.T){ testDNSitApierRpcConn, testDNSitTPFromFolder, testDNSitClntConn, - testDNSitClntNAPTRDryRun, + //testDNSitClntNAPTRDryRun, + testDNSitClntNAPTRSuppliers, testDNSitStopEngine, } @@ -147,6 +148,28 @@ func testDNSitClntNAPTRDryRun(t *testing.T) { } } +func testDNSitClntNAPTRSuppliers(t *testing.T) { + m := new(dns.Msg) + m.SetQuestion("4.6.9.4.7.1.7.1.5.6.8.9.4.e164.arpa.", dns.TypeNAPTR) + if err := dnsClnt.WriteMsg(m); err != nil { + t.Error(err) + } + if rply, err := dnsClnt.ReadMsg(); err != nil { + t.Error(err) + } else { + if rply.Rcode != dns.RcodeSuccess { + t.Errorf("failed to get an valid answer\n%v", rply) + } + answr := rply.Answer[0].(*dns.NAPTR) + if answr.Order != 100 { + t.Errorf("received: <%q>", answr.Order) + } + if answr.Replacement != "sip:1\\@172.16.1.10." { + t.Errorf("received: <%q>", answr.Replacement) + } + } +} + func testDNSitStopEngine(t *testing.T) { if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) diff --git a/data/conf/samples/dnsagent/cgrates.json b/data/conf/samples/dnsagent/cgrates.json index 3f4be3ba6..07ececad6 100644 --- a/data/conf/samples/dnsagent/cgrates.json +++ b/data/conf/samples/dnsagent/cgrates.json @@ -34,6 +34,9 @@ "chargers_conns": [ {"address": "*internal"} ], + "suppliers_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"} + ], }, @@ -60,9 +63,17 @@ }, +"suppliers": { + "enabled": true, +}, + + "dns_agent": { "enabled": true, - "listen": ":2053" + "listen": ":2053", + "sessions_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"} + ], }, diff --git a/data/conf/samples/dnsagent/dryrun.json b/data/conf/samples/dnsagent/dryrun.json index bcf991215..ebdfb2c32 100644 --- a/data/conf/samples/dnsagent/dryrun.json +++ b/data/conf/samples/dnsagent/dryrun.json @@ -3,7 +3,7 @@ "dns_agent": { "request_processors": [ { - "id": "dryrun1", + "id": "DryRunNAPTR", "filters": ["*string:~*vars.QueryType:NAPTR", "*string:~*vars.E164Address:4986517174963"], "flags": ["*dryrun"], "request_fields":[ diff --git a/engine/libsuppliers.go b/engine/libsuppliers.go index f3576c774..b50c317f1 100644 --- a/engine/libsuppliers.go +++ b/engine/libsuppliers.go @@ -37,6 +37,7 @@ type SortedSupplier struct { type SortedSuppliers struct { ProfileID string // Profile matched Sorting string // Sorting algorithm + Count int // number of suppliers returned SortedSuppliers []*SortedSupplier // list of supplier IDs and SortingData data } diff --git a/engine/suppliers.go b/engine/suppliers.go index f1bd63c05..a5ab6f989 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -441,6 +441,7 @@ func (spS *SupplierService) sortedSuppliersForEvent(args *ArgsGetSuppliers) (sor sortedSuppliers.SortedSuppliers = sortedSuppliers.SortedSuppliers[:*args.Paginator.Limit] } } + sortedSuppliers.Count = len(sortedSuppliers.SortedSuppliers) return sortedSuppliers, nil } diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go index 54a46d3b8..7f4be3da1 100644 --- a/engine/suppliers_test.go +++ b/engine/suppliers_test.go @@ -415,6 +415,7 @@ func TestSuppliersSortedForEvent(t *testing.T) { eFirstSupplierProfile := &SortedSuppliers{ ProfileID: "SupplierProfile1", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*SortedSupplier{ { SupplierID: "supplier1", @@ -436,6 +437,7 @@ func TestSuppliersSortedForEvent(t *testing.T) { eFirstSupplierProfile = &SortedSuppliers{ ProfileID: "SupplierProfile2", Sorting: utils.MetaWeight, + Count: 3, SortedSuppliers: []*SortedSupplier{ { SupplierID: "supplier1", @@ -472,6 +474,7 @@ func TestSuppliersSortedForEvent(t *testing.T) { eFirstSupplierProfile = &SortedSuppliers{ ProfileID: "SupplierProfilePrefix", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*SortedSupplier{ { SupplierID: "supplier1", @@ -496,6 +499,7 @@ func TestSuppliersSortedForEventWithLimit(t *testing.T) { eFirstSupplierProfile := &SortedSuppliers{ ProfileID: "SupplierProfile2", Sorting: utils.MetaWeight, + Count: 2, SortedSuppliers: []*SortedSupplier{ { SupplierID: "supplier1", @@ -529,6 +533,7 @@ func TestSuppliersSortedForEventWithOffset(t *testing.T) { eFirstSupplierProfile := &SortedSuppliers{ ProfileID: "SupplierProfile2", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*SortedSupplier{ { SupplierID: "supplier3", @@ -555,6 +560,7 @@ func TestSuppliersSortedForEventWithLimitAndOffset(t *testing.T) { eFirstSupplierProfile := &SortedSuppliers{ ProfileID: "SupplierProfile2", Sorting: utils.MetaWeight, + Count: 1, SortedSuppliers: []*SortedSupplier{ { SupplierID: "supplier2",