summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp/bgp_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'packet/bgp/bgp_test.go')
-rw-r--r--packet/bgp/bgp_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go
index 362c8fb8..8fedf5fe 100644
--- a/packet/bgp/bgp_test.go
+++ b/packet/bgp/bgp_test.go
@@ -812,3 +812,34 @@ func Test_MpReachNLRIWithIPv4PrefixWithIPv6Nexthop(t *testing.T) {
// Test serialised value
assert.Equal(bufin, bufout)
}
+
+func Test_ParseRouteDistingusher(t *testing.T) {
+ assert := assert.New(t)
+
+ rd, _ := ParseRouteDistinguisher("100:1000")
+ rdType0, ok := rd.(*RouteDistinguisherTwoOctetAS)
+ if !ok {
+ t.Fatal("Type of RD interface is not RouteDistinguisherTwoOctetAS")
+ }
+
+ assert.Equal(uint16(100), rdType0.Admin)
+ assert.Equal(uint32(1000), rdType0.Assigned)
+
+ rd, _ = ParseRouteDistinguisher("10.0.0.0:100")
+ rdType1, ok := rd.(*RouteDistinguisherIPAddressAS)
+ if !ok {
+ t.Fatal("Type of RD interface is not RouteDistinguisherIPAddressAS")
+ }
+
+ assert.Equal("10.0.0.0", rdType1.Admin.String())
+ assert.Equal(uint16(100), rdType1.Assigned)
+
+ rd, _ = ParseRouteDistinguisher("100.1000:10000")
+ rdType2, ok := rd.(*RouteDistinguisherFourOctetAS)
+ if !ok {
+ t.Fatal("Type of RD interface is not RouteDistinguisherFourOctetAS")
+ }
+
+ assert.Equal(uint32((100<<16)|1000), rdType2.Admin)
+ assert.Equal(uint16(10000), rdType2.Assigned)
+}