diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-09 13:21:41 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-09 13:21:41 +0900 |
commit | 900cb321fb3dc353b102aa1970e652184abc24eb (patch) | |
tree | 2fa7ba4dd183781051b10c1df52043e433da0ca3 /packet | |
parent | 0ad83ce995ab8c87c2f68aa4d52a22e1a232ab1d (diff) |
table: fix tableKey()
tableKey() must use Prefix (address + mask) as key.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp.go | 4 | ||||
-rw-r--r-- | packet/bgp_test.go | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 505212b4..ae222a34 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -469,6 +469,10 @@ func (r *IPAddrPrefixDefault) Len() int { return int(1 + ((r.Length + 7) / 8)) } +func (r *IPAddrPrefixDefault) String() string { + return fmt.Sprintf("%s/%d", r.Prefix.String(), r.Length) +} + type IPAddrPrefix struct { IPAddrPrefixDefault addrlen uint8 diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 46ff293d..2cc36a85 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -2,6 +2,7 @@ package bgp import ( "bytes" + "github.com/stretchr/testify/assert" "net" "testing" ) @@ -131,3 +132,12 @@ func Test_Message(t *testing.T) { } } } + +func Test_IPAddrPrefixString(t *testing.T) { + ipv4 := NewIPAddrPrefix(24, "129.6.10.0") + assert.Equal(t, "129.6.10.0/24", ipv4.String()) + ipv6 := NewIPv6AddrPrefix(18, "3343:faba:3903::1") + assert.Equal(t, "3343:faba:3903::1/18", ipv6.String()) + ipv6 = NewIPv6AddrPrefix(18, "3343:faba:3903::0") + assert.Equal(t, "3343:faba:3903::/18", ipv6.String()) +} |