summaryrefslogtreecommitdiffhomepage
path: root/server/rpki_test.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-21 06:44:02 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-21 06:44:02 -0800
commitbbed1307daa2cda8434ac5f91ae68f41fb59461e (patch)
tree39696c072fa0f33da23568311e7de762cb1794bb /server/rpki_test.go
parent7899f30f3a8875256b49c579953ca5cee3fe7eaf (diff)
rpki: fix the numbers of records and prefixes about removal
Let's calculate the numbers of records and prefixes when they are necessary. This fixes a bug that the numbers of records and prefixes in deleteAllROA(). Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/rpki_test.go')
-rw-r--r--server/rpki_test.go99
1 files changed, 36 insertions, 63 deletions
diff --git a/server/rpki_test.go b/server/rpki_test.go
index 3d7be7b3..aa0a85be 100644
--- a/server/rpki_test.go
+++ b/server/rpki_test.go
@@ -60,16 +60,13 @@ func validateOne(tree *radix.Tree, cidr, aspathStr string) config.RpkiValidation
func TestValidate0(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 100, net.ParseIP("192.168.0.0").To4(), 24, 32)
- addROA(client, bgp.AFI_IP, tree, 200, net.ParseIP("192.168.0.0").To4(), 24, 24)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("192.168.0.0").To4(), 24, 32, 100, ""))
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("192.168.0.0").To4(), 24, 24, 200, ""))
var r config.RpkiValidationResultType
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "192.168.0.0/24", "100")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
@@ -92,15 +89,12 @@ func TestValidate0(t *testing.T) {
func TestValidate1(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 65000, net.ParseIP("10.0.0.0").To4(), 16, 16)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, ""))
var r config.RpkiValidationResultType
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
@@ -111,10 +105,11 @@ func TestValidate1(t *testing.T) {
func TestValidate2(t *testing.T) {
assert := assert.New(t)
- tree := radix.New()
+ manager, _ := newROAManager(0, []config.RpkiServer{})
var r config.RpkiValidationResultType
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
@@ -125,41 +120,35 @@ func TestValidate2(t *testing.T) {
func TestValidate3(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree1 := radix.New()
- addROA(client, bgp.AFI_IP, tree1, 65000, net.ParseIP("10.0.0.0").To4(), 16, 16)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, ""))
var r config.RpkiValidationResultType
- r = validateOne(tree1, "10.0.0.0/8", "65000")
+ tree := manager.roas[bgp.RF_IPv4_UC]
+ r = validateOne(tree, "10.0.0.0/8", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
- r = validateOne(tree1, "10.0.0.0/17", "65000")
+ r = validateOne(tree, "10.0.0.0/17", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_INVALID)
- tree2 := radix.New()
- addROA(client, bgp.AFI_IP, tree2, 65000, net.ParseIP("10.0.0.0").To4(), 16, 24)
+ manager, _ = newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, ""))
- r = validateOne(tree2, "10.0.0.0/17", "65000")
+ tree = manager.roas[bgp.RF_IPv4_UC]
+ r = validateOne(tree, "10.0.0.0/17", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
}
func TestValidate4(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 65000, net.ParseIP("10.0.0.0").To4(), 16, 16)
- addROA(client, bgp.AFI_IP, tree, 65001, net.ParseIP("10.0.0.0").To4(), 16, 16)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65000, ""))
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 16, 65001, ""))
var r config.RpkiValidationResultType
-
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)
@@ -170,16 +159,12 @@ func TestValidate4(t *testing.T) {
func TestValidate5(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 65000, net.ParseIP("10.0.0.0").To4(), 17, 17)
- addROA(client, bgp.AFI_IP, tree, 65000, net.ParseIP("10.0.128.0").To4(), 17, 17)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 17, 17, 65000, ""))
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.128.0").To4(), 17, 17, 65000, ""))
var r config.RpkiValidationResultType
-
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/16", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
}
@@ -187,15 +172,11 @@ func TestValidate5(t *testing.T) {
func TestValidate6(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 0, net.ParseIP("10.0.0.0").To4(), 8, 32)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 8, 32, 0, ""))
var r config.RpkiValidationResultType
-
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/7", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
@@ -209,15 +190,11 @@ func TestValidate6(t *testing.T) {
func TestValidate7(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 65000, net.ParseIP("10.0.0.0").To4(), 16, 24)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, ""))
var r config.RpkiValidationResultType
-
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/24", "{65000}")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND)
@@ -231,16 +208,12 @@ func TestValidate7(t *testing.T) {
func TestValidate8(t *testing.T) {
assert := assert.New(t)
- client := &roaClient{
- records: make(map[int]uint32),
- prefixes: make(map[int]uint32),
- }
- tree := radix.New()
- addROA(client, bgp.AFI_IP, tree, 0, net.ParseIP("10.0.0.0").To4(), 16, 24)
- addROA(client, bgp.AFI_IP, tree, 65000, net.ParseIP("10.0.0.0").To4(), 16, 24)
+ manager, _ := newROAManager(0, []config.RpkiServer{})
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 0, ""))
+ manager.addROA(NewROA(bgp.AFI_IP, net.ParseIP("10.0.0.0").To4(), 16, 24, 65000, ""))
var r config.RpkiValidationResultType
-
+ tree := manager.roas[bgp.RF_IPv4_UC]
r = validateOne(tree, "10.0.0.0/24", "65000")
assert.Equal(r, config.RPKI_VALIDATION_RESULT_TYPE_VALID)