diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-07-02 23:39:20 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-05 23:44:22 +0900 |
commit | 2fc9b887fc63da94e173f75dd15330254e35647c (patch) | |
tree | c25548066c75ad9dc17babbf1e12286a10e60aed /packet | |
parent | cd89516a28f4de85f844a232cb1b40b198218856 (diff) |
server/cli: support add/delete vpnv4/vpnv6 routes
$ gobgp global rib add 1:10.0.0.1:1000:10.0.0.0/24 -a vpnv4
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp.go | 71 | ||||
-rw-r--r-- | packet/bgp_test.go | 8 |
2 files changed, 42 insertions, 37 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index bdd07911..6cc9145d 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -938,14 +938,14 @@ func NewMPLSLabelStack(labels ...uint32) *MPLSLabelStack { // followed by an IPv4 prefix. // -type LabelledVPNIPAddrPrefix struct { +type LabeledVPNIPAddrPrefix struct { IPAddrPrefixDefault Labels MPLSLabelStack RD RouteDistinguisherInterface addrlen uint8 } -func (l *LabelledVPNIPAddrPrefix) DecodeFromBytes(data []byte) error { +func (l *LabeledVPNIPAddrPrefix) DecodeFromBytes(data []byte) error { l.Length = uint8(data[0]) data = data[1:] l.Labels.DecodeFromBytes(data) @@ -960,7 +960,7 @@ func (l *LabelledVPNIPAddrPrefix) DecodeFromBytes(data []byte) error { return nil } -func (l *LabelledVPNIPAddrPrefix) Serialize() ([]byte, error) { +func (l *LabeledVPNIPAddrPrefix) Serialize() ([]byte, error) { buf := make([]byte, 1) buf[0] = l.Length lbuf, err := l.Labels.Serialize() @@ -982,27 +982,32 @@ func (l *LabelledVPNIPAddrPrefix) Serialize() ([]byte, error) { return buf, nil } -func (l *LabelledVPNIPAddrPrefix) AFI() uint16 { +func (l *LabeledVPNIPAddrPrefix) AFI() uint16 { return AFI_IP } -func (l *LabelledVPNIPAddrPrefix) SAFI() uint8 { +func (l *LabeledVPNIPAddrPrefix) SAFI() uint8 { return SAFI_MPLS_VPN } -func (l *LabelledVPNIPAddrPrefix) ToApiStruct() *api.Nlri { +func (l *LabeledVPNIPAddrPrefix) ToApiStruct() *api.Nlri { return &api.Nlri{ Af: &api.AddressFamily{api.AFI(l.AFI()), api.SAFI(l.SAFI())}, Prefix: l.String(), } } -func NewLabelledVPNIPAddrPrefix(length uint8, prefix string, label MPLSLabelStack, rd RouteDistinguisherInterface) *LabelledVPNIPAddrPrefix { +func (l *LabeledVPNIPAddrPrefix) String() string { + masklen := l.IPAddrPrefixDefault.Length - uint8(8*(l.Labels.Len()+l.RD.Len())) + return fmt.Sprintf("%s:%s/%d", l.RD, l.IPAddrPrefixDefault.Prefix, masklen) +} + +func NewLabeledVPNIPAddrPrefix(length uint8, prefix string, label MPLSLabelStack, rd RouteDistinguisherInterface) *LabeledVPNIPAddrPrefix { rdlen := 0 if rd != nil { rdlen = rd.Len() } - return &LabelledVPNIPAddrPrefix{ + return &LabeledVPNIPAddrPrefix{ IPAddrPrefixDefault{length + uint8(8*(label.Len()+rdlen)), net.ParseIP(prefix)}, label, rd, @@ -1010,21 +1015,21 @@ func NewLabelledVPNIPAddrPrefix(length uint8, prefix string, label MPLSLabelStac } } -type LabelledVPNIPv6AddrPrefix struct { - LabelledVPNIPAddrPrefix +type LabeledVPNIPv6AddrPrefix struct { + LabeledVPNIPAddrPrefix } -func (l *LabelledVPNIPv6AddrPrefix) AFI() uint16 { +func (l *LabeledVPNIPv6AddrPrefix) AFI() uint16 { return AFI_IP6 } -func NewLabelledVPNIPv6AddrPrefix(length uint8, prefix string, label MPLSLabelStack, rd RouteDistinguisherInterface) *LabelledVPNIPv6AddrPrefix { +func NewLabeledVPNIPv6AddrPrefix(length uint8, prefix string, label MPLSLabelStack, rd RouteDistinguisherInterface) *LabeledVPNIPv6AddrPrefix { rdlen := 0 if rd != nil { rdlen = rd.Len() } - return &LabelledVPNIPv6AddrPrefix{ - LabelledVPNIPAddrPrefix{ + return &LabeledVPNIPv6AddrPrefix{ + LabeledVPNIPAddrPrefix{ IPAddrPrefixDefault{length + uint8(8*(label.Len()+rdlen)), net.ParseIP(prefix)}, label, rd, @@ -1033,21 +1038,21 @@ func NewLabelledVPNIPv6AddrPrefix(length uint8, prefix string, label MPLSLabelSt } } -type LabelledIPAddrPrefix struct { +type LabeledIPAddrPrefix struct { IPAddrPrefixDefault Labels MPLSLabelStack addrlen uint8 } -func (r *LabelledIPAddrPrefix) AFI() uint16 { +func (r *LabeledIPAddrPrefix) AFI() uint16 { return AFI_IP } -func (r *LabelledIPAddrPrefix) SAFI() uint8 { +func (r *LabeledIPAddrPrefix) SAFI() uint8 { return SAFI_MPLS_LABEL } -func (r *LabelledIPAddrPrefix) ToApiStruct() *api.Nlri { +func (r *LabeledIPAddrPrefix) ToApiStruct() *api.Nlri { return &api.Nlri{ Af: &api.AddressFamily{api.AFI(r.AFI()), api.SAFI(r.SAFI())}, Prefix: r.String(), @@ -1062,18 +1067,18 @@ func (r *IPAddrPrefix) decodeNextHop(data []byte) net.IP { return next } -func (r *LabelledVPNIPAddrPrefix) decodeNextHop(data []byte) net.IP { +func (r *LabeledVPNIPAddrPrefix) decodeNextHop(data []byte) net.IP { // skip rd var next net.IP = data[8 : 8+r.addrlen] return next } -func (r *LabelledIPAddrPrefix) decodeNextHop(data []byte) net.IP { +func (r *LabeledIPAddrPrefix) decodeNextHop(data []byte) net.IP { var next net.IP = data[0:r.addrlen] return next } -func (l *LabelledIPAddrPrefix) DecodeFromBytes(data []byte) error { +func (l *LabeledIPAddrPrefix) DecodeFromBytes(data []byte) error { l.Length = uint8(data[0]) data = data[1:] l.Labels.DecodeFromBytes(data) @@ -1086,7 +1091,7 @@ func (l *LabelledIPAddrPrefix) DecodeFromBytes(data []byte) error { return nil } -func (l *LabelledIPAddrPrefix) Serialize() ([]byte, error) { +func (l *LabeledIPAddrPrefix) Serialize() ([]byte, error) { buf := make([]byte, 1) buf[0] = l.Length restbits := int(l.Length) - 8*(l.Labels.Len()) @@ -1103,21 +1108,21 @@ func (l *LabelledIPAddrPrefix) Serialize() ([]byte, error) { return buf, nil } -func NewLabelledIPAddrPrefix(length uint8, prefix string, label MPLSLabelStack) *LabelledIPAddrPrefix { - return &LabelledIPAddrPrefix{ +func NewLabeledIPAddrPrefix(length uint8, prefix string, label MPLSLabelStack) *LabeledIPAddrPrefix { + return &LabeledIPAddrPrefix{ IPAddrPrefixDefault{length + uint8(label.Len()*8), net.ParseIP(prefix)}, label, 4, } } -type LabelledIPv6AddrPrefix struct { - LabelledIPAddrPrefix +type LabeledIPv6AddrPrefix struct { + LabeledIPAddrPrefix } -func NewLabelledIPv6AddrPrefix(length uint8, prefix string, label MPLSLabelStack) *LabelledIPv6AddrPrefix { - return &LabelledIPv6AddrPrefix{ - LabelledIPAddrPrefix{ +func NewLabeledIPv6AddrPrefix(length uint8, prefix string, label MPLSLabelStack) *LabeledIPv6AddrPrefix { + return &LabeledIPv6AddrPrefix{ + LabeledIPAddrPrefix{ IPAddrPrefixDefault{length + uint8(label.Len()*8), net.ParseIP(prefix)}, label, 16, @@ -1800,13 +1805,13 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8) (prefix AddrPrefixInterfac case RF_IPv6_UC, RF_IPv6_MC: prefix = NewIPv6AddrPrefix(0, "") case RF_IPv4_VPN: - prefix = NewLabelledVPNIPAddrPrefix(0, "", *NewMPLSLabelStack(), nil) + prefix = NewLabeledVPNIPAddrPrefix(0, "", *NewMPLSLabelStack(), nil) case RF_IPv6_VPN: - prefix = NewLabelledVPNIPv6AddrPrefix(0, "", *NewMPLSLabelStack(), nil) + prefix = NewLabeledVPNIPv6AddrPrefix(0, "", *NewMPLSLabelStack(), nil) case RF_IPv4_MPLS: - prefix = NewLabelledIPAddrPrefix(0, "", *NewMPLSLabelStack()) + prefix = NewLabeledIPAddrPrefix(0, "", *NewMPLSLabelStack()) case RF_IPv6_MPLS: - prefix = NewLabelledIPv6AddrPrefix(0, "", *NewMPLSLabelStack()) + prefix = NewLabeledIPv6AddrPrefix(0, "", *NewMPLSLabelStack()) case RF_EVPN: prefix = NewEVPNNLRI(0, 0, nil) case RF_RTC_UC: diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 16055819..84aaed75 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -69,20 +69,20 @@ func update() *BGPMessage { } mp_nlri := []AddrPrefixInterface{ - NewLabelledVPNIPAddrPrefix(20, "192.0.9.0", *NewMPLSLabelStack(1, 2, 3), + NewLabeledVPNIPAddrPrefix(20, "192.0.9.0", *NewMPLSLabelStack(1, 2, 3), NewRouteDistinguisherTwoOctetAS(256, 10000)), - NewLabelledVPNIPAddrPrefix(26, "192.10.8.192", *NewMPLSLabelStack(5, 6, 7, 8), + NewLabeledVPNIPAddrPrefix(26, "192.10.8.192", *NewMPLSLabelStack(5, 6, 7, 8), NewRouteDistinguisherIPAddressAS("10.0.1.1", 10001)), } mp_nlri2 := []AddrPrefixInterface{NewIPv6AddrPrefix(100, "fe80:1234:1234:5667:8967:af12:8912:1023")} - mp_nlri3 := []AddrPrefixInterface{NewLabelledVPNIPv6AddrPrefix(100, + mp_nlri3 := []AddrPrefixInterface{NewLabeledVPNIPv6AddrPrefix(100, "fe80:1234:1234:5667:8967:af12:1203:33a1", *NewMPLSLabelStack(5, 6), NewRouteDistinguisherFourOctetAS(5, 6))} - mp_nlri4 := []AddrPrefixInterface{NewLabelledIPAddrPrefix(25, "192.168.0.0", + mp_nlri4 := []AddrPrefixInterface{NewLabeledIPAddrPrefix(25, "192.168.0.0", *NewMPLSLabelStack(5, 6, 7))} mac, _ := net.ParseMAC("01:23:45:67:89:ab") |