summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-04-12 09:39:09 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-04-12 09:39:09 +0900
commit9c3e5b159c6c9cc2f42302045006af721e33e2e9 (patch)
tree1162f97a33fd4dd67cd06f087bac29c81348d7b4
parent8daa5116576b3e3582e6c8e05ae1b64f56197ec6 (diff)
packet: create bmp package
move bmp stuff from bgp to bmp package. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--config/default.go3
-rw-r--r--gobgp/cmd/bmp.go4
-rw-r--r--gobmpd/main.go8
-rw-r--r--packet/bgp/bgp.go20
-rw-r--r--packet/bgp/bgp_test.go147
-rw-r--r--packet/bgp/helper.go150
-rw-r--r--packet/bmp/bmp.go (renamed from packet/bgp/bmp.go)45
-rw-r--r--packet/bmp/bmp_test.go (renamed from packet/bgp/bmp_test.go)9
-rw-r--r--server/bmp.go33
-rw-r--r--server/server.go13
10 files changed, 236 insertions, 196 deletions
diff --git a/config/default.go b/config/default.go
index b9ce5366..7431d267 100644
--- a/config/default.go
+++ b/config/default.go
@@ -3,6 +3,7 @@ package config
import (
"fmt"
"github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/packet/bmp"
"github.com/osrg/gobgp/packet/rtr"
"github.com/spf13/viper"
"net"
@@ -55,7 +56,7 @@ func SetDefaultConfigValues(v *viper.Viper, b *Bgp) error {
for idx, server := range b.BmpServers {
if server.Config.Port == 0 {
- server.Config.Port = bgp.BMP_DEFAULT_PORT
+ server.Config.Port = bmp.BMP_DEFAULT_PORT
}
b.BmpServers[idx] = server
}
diff --git a/gobgp/cmd/bmp.go b/gobgp/cmd/bmp.go
index 08d24ca0..70ea8f47 100644
--- a/gobgp/cmd/bmp.go
+++ b/gobgp/cmd/bmp.go
@@ -18,7 +18,7 @@ package cmd
import (
"fmt"
api "github.com/osrg/gobgp/api"
- "github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/packet/bmp"
"github.com/spf13/cobra"
"golang.org/x/net/context"
"net"
@@ -38,7 +38,7 @@ func modBmpServer(cmdType string, args []string) error {
return nil
}
arg.Address = args[0]
- arg.Port = bgp.BMP_DEFAULT_PORT
+ arg.Port = bmp.BMP_DEFAULT_PORT
} else {
arg.Address = host
p, _ := strconv.Atoi(port)
diff --git a/gobmpd/main.go b/gobmpd/main.go
index c6cf99a4..a91d3752 100644
--- a/gobmpd/main.go
+++ b/gobmpd/main.go
@@ -20,7 +20,7 @@ import (
"encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
- "github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/packet/bmp"
"net"
"os"
"strconv"
@@ -29,10 +29,10 @@ import (
func connLoop(conn *net.TCPConn) {
addr := conn.RemoteAddr()
scanner := bufio.NewScanner(bufio.NewReader(conn))
- scanner.Split(bgp.SplitBMP)
+ scanner.Split(bmp.SplitBMP)
for scanner.Scan() {
- msg, err := bgp.ParseBMPMessage(scanner.Bytes())
+ msg, err := bmp.ParseBMPMessage(scanner.Bytes())
if err != nil {
log.Info(err)
continue
@@ -44,7 +44,7 @@ func connLoop(conn *net.TCPConn) {
}
func main() {
- service := ":" + strconv.Itoa(bgp.BMP_DEFAULT_PORT)
+ service := ":" + strconv.Itoa(bmp.BMP_DEFAULT_PORT)
addr, _ := net.ResolveTCPAddr("tcp", service)
l, err := net.ListenTCP("tcp", addr)
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 2de2af63..8bfea717 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -6785,3 +6785,23 @@ func (msg *BGPMessage) Serialize() ([]byte, error) {
}
return append(h, b...), nil
}
+
+type MessageError struct {
+ TypeCode uint8
+ SubTypeCode uint8
+ Data []byte
+ Message string
+}
+
+func NewMessageError(typeCode, subTypeCode uint8, data []byte, msg string) error {
+ return &MessageError{
+ TypeCode: typeCode,
+ SubTypeCode: subTypeCode,
+ Data: data,
+ Message: msg,
+ }
+}
+
+func (e *MessageError) Error() string {
+ return e.Message
+}
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go
index 29aa4e69..612e8c7b 100644
--- a/packet/bgp/bgp_test.go
+++ b/packet/bgp/bgp_test.go
@@ -1,3 +1,18 @@
+// Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package bgp
import (
@@ -22,138 +37,8 @@ func refresh() *BGPMessage {
return NewBGPRouteRefreshMessage(1, 2, 10)
}
-func open() *BGPMessage {
- p1 := NewOptionParameterCapability(
- []ParameterCapabilityInterface{NewCapRouteRefresh()})
- p2 := NewOptionParameterCapability(
- []ParameterCapabilityInterface{NewCapMultiProtocol(RF_IPv4_UC)})
- g := &CapGracefulRestartTuple{4, 2, 3}
- p3 := NewOptionParameterCapability(
- []ParameterCapabilityInterface{NewCapGracefulRestart(false, 100,
- []*CapGracefulRestartTuple{g})})
- p4 := NewOptionParameterCapability(
- []ParameterCapabilityInterface{NewCapFourOctetASNumber(100000)})
- p5 := NewOptionParameterCapability(
- []ParameterCapabilityInterface{NewCapAddPath(RF_IPv4_UC, BGP_ADD_PATH_BOTH)})
- return NewBGPOpenMessage(11033, 303, "100.4.10.3",
- []OptionParameterInterface{p1, p2, p3, p4, p5})
-}
-
-func update() *BGPMessage {
- w1 := NewIPAddrPrefix(23, "121.1.3.2")
- w2 := NewIPAddrPrefix(17, "100.33.3.0")
- w := []*IPAddrPrefix{w1, w2}
-
- aspath1 := []AsPathParamInterface{
- NewAsPathParam(2, []uint16{1000}),
- NewAsPathParam(1, []uint16{1001, 1002}),
- NewAsPathParam(2, []uint16{1003, 1004}),
- }
-
- aspath2 := []AsPathParamInterface{
- NewAs4PathParam(2, []uint32{1000000}),
- NewAs4PathParam(1, []uint32{1000001, 1002}),
- NewAs4PathParam(2, []uint32{1003, 100004}),
- }
-
- aspath3 := []*As4PathParam{
- NewAs4PathParam(2, []uint32{1000000}),
- NewAs4PathParam(1, []uint32{1000001, 1002}),
- NewAs4PathParam(2, []uint32{1003, 100004}),
- }
-
- isTransitive := true
-
- ecommunities := []ExtendedCommunityInterface{
- NewTwoOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 10003, 3<<20, isTransitive),
- NewFourOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 1<<20, 300, isTransitive),
- NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, "192.2.1.2", 3000, isTransitive),
- &OpaqueExtended{
- Value: &DefaultOpaqueExtendedValue{[]byte{255, 1, 2, 3, 4, 5, 6, 7}},
- },
- &OpaqueExtended{
- Value: &ValidationExtended{Value: VALIDATION_STATE_INVALID},
- },
- &UnknownExtended{Type: 99, Value: []byte{0, 1, 2, 3, 4, 5, 6, 7}},
- NewESILabelExtended(1000, true),
- NewESImportRouteTarget("11:22:33:44:55:66"),
- NewMacMobilityExtended(123, false),
- }
-
- mp_nlri := []AddrPrefixInterface{
- NewLabeledVPNIPAddrPrefix(20, "192.0.9.0", *NewMPLSLabelStack(1, 2, 3),
- NewRouteDistinguisherTwoOctetAS(256, 10000)),
- 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{NewLabeledVPNIPv6AddrPrefix(100,
- "fe80:1234:1234:5667:8967:af12:1203:33a1", *NewMPLSLabelStack(5, 6),
- NewRouteDistinguisherFourOctetAS(5, 6))}
-
- mp_nlri4 := []AddrPrefixInterface{NewLabeledIPAddrPrefix(25, "192.168.0.0",
- *NewMPLSLabelStack(5, 6, 7))}
-
- mac, _ := net.ParseMAC("01:23:45:67:89:ab")
- mp_nlri5 := []AddrPrefixInterface{
- NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0,
- &EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6),
- EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}),
- NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, 0,
- &EVPNMacIPAdvertisementRoute{NewRouteDistinguisherFourOctetAS(5, 6),
- EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 3, 48,
- mac, 32, net.ParseIP("192.2.1.2"),
- []uint32{3, 4}}),
- NewEVPNNLRI(EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, 0,
- &EVPNMulticastEthernetTagRoute{NewRouteDistinguisherFourOctetAS(5, 6), 3, 32, net.ParseIP("192.2.1.2")}),
- NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE, 0,
- &EVPNEthernetSegmentRoute{NewRouteDistinguisherFourOctetAS(5, 6),
- EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)},
- 32, net.ParseIP("192.2.1.1")}),
- }
-
- p := []PathAttributeInterface{
- NewPathAttributeOrigin(3),
- NewPathAttributeAsPath(aspath1),
- NewPathAttributeAsPath(aspath2),
- NewPathAttributeNextHop("129.1.1.2"),
- NewPathAttributeMultiExitDisc(1 << 20),
- NewPathAttributeLocalPref(1 << 22),
- NewPathAttributeAtomicAggregate(),
- NewPathAttributeAggregator(uint16(30002), "129.0.2.99"),
- NewPathAttributeAggregator(uint32(30002), "129.0.2.99"),
- NewPathAttributeAggregator(uint32(300020), "129.0.2.99"),
- NewPathAttributeCommunities([]uint32{1, 3}),
- NewPathAttributeOriginatorId("10.10.0.1"),
- NewPathAttributeClusterList([]string{"10.10.0.2", "10.10.0.3"}),
- NewPathAttributeExtendedCommunities(ecommunities),
- NewPathAttributeAs4Path(aspath3),
- NewPathAttributeAs4Aggregator(10000, "112.22.2.1"),
- NewPathAttributeMpReachNLRI("112.22.2.0", mp_nlri),
- NewPathAttributeMpReachNLRI("1023::", mp_nlri2),
- NewPathAttributeMpReachNLRI("fe80::", mp_nlri3),
- NewPathAttributeMpReachNLRI("129.1.1.1", mp_nlri4),
- NewPathAttributeMpReachNLRI("129.1.1.1", mp_nlri5),
- NewPathAttributeMpUnreachNLRI(mp_nlri),
- //NewPathAttributeMpReachNLRI("112.22.2.0", []AddrPrefixInterface{}),
- //NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}),
- &PathAttributeUnknown{
- PathAttribute: PathAttribute{
- Flags: BGP_ATTR_FLAG_TRANSITIVE,
- Type: 100,
- Value: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
- },
- },
- }
- n := []*IPAddrPrefix{NewIPAddrPrefix(24, "13.2.3.1")}
- return NewBGPUpdateMessage(w, p, n)
-}
-
func Test_Message(t *testing.T) {
- l := []*BGPMessage{keepalive(), notification(), refresh(), open(), update()}
+ l := []*BGPMessage{keepalive(), notification(), refresh(), NewTestBGPOpenMessage(), NewTestBGPUpdateMessage()}
for _, m1 := range l {
buf1, _ := m1.Serialize()
t.Log("LEN =", len(buf1))
diff --git a/packet/bgp/helper.go b/packet/bgp/helper.go
new file mode 100644
index 00000000..423361b1
--- /dev/null
+++ b/packet/bgp/helper.go
@@ -0,0 +1,150 @@
+// Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package bgp
+
+import (
+ "net"
+)
+
+func NewTestBGPOpenMessage() *BGPMessage {
+ p1 := NewOptionParameterCapability(
+ []ParameterCapabilityInterface{NewCapRouteRefresh()})
+ p2 := NewOptionParameterCapability(
+ []ParameterCapabilityInterface{NewCapMultiProtocol(RF_IPv4_UC)})
+ g := &CapGracefulRestartTuple{4, 2, 3}
+ p3 := NewOptionParameterCapability(
+ []ParameterCapabilityInterface{NewCapGracefulRestart(false, 100,
+ []*CapGracefulRestartTuple{g})})
+ p4 := NewOptionParameterCapability(
+ []ParameterCapabilityInterface{NewCapFourOctetASNumber(100000)})
+ p5 := NewOptionParameterCapability(
+ []ParameterCapabilityInterface{NewCapAddPath(RF_IPv4_UC, BGP_ADD_PATH_BOTH)})
+ return NewBGPOpenMessage(11033, 303, "100.4.10.3",
+ []OptionParameterInterface{p1, p2, p3, p4, p5})
+}
+
+func NewTestBGPUpdateMessage() *BGPMessage {
+ w1 := NewIPAddrPrefix(23, "121.1.3.2")
+ w2 := NewIPAddrPrefix(17, "100.33.3.0")
+ w := []*IPAddrPrefix{w1, w2}
+
+ aspath1 := []AsPathParamInterface{
+ NewAsPathParam(2, []uint16{1000}),
+ NewAsPathParam(1, []uint16{1001, 1002}),
+ NewAsPathParam(2, []uint16{1003, 1004}),
+ }
+
+ aspath2 := []AsPathParamInterface{
+ NewAs4PathParam(2, []uint32{1000000}),
+ NewAs4PathParam(1, []uint32{1000001, 1002}),
+ NewAs4PathParam(2, []uint32{1003, 100004}),
+ }
+
+ aspath3 := []*As4PathParam{
+ NewAs4PathParam(2, []uint32{1000000}),
+ NewAs4PathParam(1, []uint32{1000001, 1002}),
+ NewAs4PathParam(2, []uint32{1003, 100004}),
+ }
+
+ isTransitive := true
+
+ ecommunities := []ExtendedCommunityInterface{
+ NewTwoOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 10003, 3<<20, isTransitive),
+ NewFourOctetAsSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, 1<<20, 300, isTransitive),
+ NewIPv4AddressSpecificExtended(EC_SUBTYPE_ROUTE_TARGET, "192.2.1.2", 3000, isTransitive),
+ &OpaqueExtended{
+ Value: &DefaultOpaqueExtendedValue{[]byte{255, 1, 2, 3, 4, 5, 6, 7}},
+ },
+ &OpaqueExtended{
+ Value: &ValidationExtended{Value: VALIDATION_STATE_INVALID},
+ },
+ &UnknownExtended{Type: 99, Value: []byte{0, 1, 2, 3, 4, 5, 6, 7}},
+ NewESILabelExtended(1000, true),
+ NewESImportRouteTarget("11:22:33:44:55:66"),
+ NewMacMobilityExtended(123, false),
+ }
+
+ mp_nlri := []AddrPrefixInterface{
+ NewLabeledVPNIPAddrPrefix(20, "192.0.9.0", *NewMPLSLabelStack(1, 2, 3),
+ NewRouteDistinguisherTwoOctetAS(256, 10000)),
+ 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{NewLabeledVPNIPv6AddrPrefix(100,
+ "fe80:1234:1234:5667:8967:af12:1203:33a1", *NewMPLSLabelStack(5, 6),
+ NewRouteDistinguisherFourOctetAS(5, 6))}
+
+ mp_nlri4 := []AddrPrefixInterface{NewLabeledIPAddrPrefix(25, "192.168.0.0",
+ *NewMPLSLabelStack(5, 6, 7))}
+
+ mac, _ := net.ParseMAC("01:23:45:67:89:ab")
+ mp_nlri5 := []AddrPrefixInterface{
+ NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0,
+ &EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6),
+ EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}),
+ NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, 0,
+ &EVPNMacIPAdvertisementRoute{NewRouteDistinguisherFourOctetAS(5, 6),
+ EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 3, 48,
+ mac, 32, net.ParseIP("192.2.1.2"),
+ []uint32{3, 4}}),
+ NewEVPNNLRI(EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, 0,
+ &EVPNMulticastEthernetTagRoute{NewRouteDistinguisherFourOctetAS(5, 6), 3, 32, net.ParseIP("192.2.1.2")}),
+ NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE, 0,
+ &EVPNEthernetSegmentRoute{NewRouteDistinguisherFourOctetAS(5, 6),
+ EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)},
+ 32, net.ParseIP("192.2.1.1")}),
+ }
+
+ p := []PathAttributeInterface{
+ NewPathAttributeOrigin(3),
+ NewPathAttributeAsPath(aspath1),
+ NewPathAttributeAsPath(aspath2),
+ NewPathAttributeNextHop("129.1.1.2"),
+ NewPathAttributeMultiExitDisc(1 << 20),
+ NewPathAttributeLocalPref(1 << 22),
+ NewPathAttributeAtomicAggregate(),
+ NewPathAttributeAggregator(uint16(30002), "129.0.2.99"),
+ NewPathAttributeAggregator(uint32(30002), "129.0.2.99"),
+ NewPathAttributeAggregator(uint32(300020), "129.0.2.99"),
+ NewPathAttributeCommunities([]uint32{1, 3}),
+ NewPathAttributeOriginatorId("10.10.0.1"),
+ NewPathAttributeClusterList([]string{"10.10.0.2", "10.10.0.3"}),
+ NewPathAttributeExtendedCommunities(ecommunities),
+ NewPathAttributeAs4Path(aspath3),
+ NewPathAttributeAs4Aggregator(10000, "112.22.2.1"),
+ NewPathAttributeMpReachNLRI("112.22.2.0", mp_nlri),
+ NewPathAttributeMpReachNLRI("1023::", mp_nlri2),
+ NewPathAttributeMpReachNLRI("fe80::", mp_nlri3),
+ NewPathAttributeMpReachNLRI("129.1.1.1", mp_nlri4),
+ NewPathAttributeMpReachNLRI("129.1.1.1", mp_nlri5),
+ NewPathAttributeMpUnreachNLRI(mp_nlri),
+ //NewPathAttributeMpReachNLRI("112.22.2.0", []AddrPrefixInterface{}),
+ //NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}),
+ &PathAttributeUnknown{
+ PathAttribute: PathAttribute{
+ Flags: BGP_ATTR_FLAG_TRANSITIVE,
+ Type: 100,
+ Value: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
+ },
+ },
+ }
+ n := []*IPAddrPrefix{NewIPAddrPrefix(24, "13.2.3.1")}
+ return NewBGPUpdateMessage(w, p, n)
+}
diff --git a/packet/bgp/bmp.go b/packet/bmp/bmp.go
index 4813aff9..084a0d16 100644
--- a/packet/bgp/bmp.go
+++ b/packet/bmp/bmp.go
@@ -13,11 +13,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package bgp
+package bmp
import (
"encoding/binary"
"fmt"
+ "github.com/osrg/gobgp/packet/bgp"
"math"
"net"
)
@@ -136,11 +137,11 @@ func (h *BMPPeerHeader) Serialize() ([]byte, error) {
}
type BMPRouteMonitoring struct {
- BGPUpdate *BGPMessage
+ BGPUpdate *bgp.BGPMessage
BGPUpdatePayload []byte
}
-func NewBMPRouteMonitoring(p BMPPeerHeader, update *BGPMessage) *BMPMessage {
+func NewBMPRouteMonitoring(p BMPPeerHeader, update *bgp.BGPMessage) *BMPMessage {
return &BMPMessage{
Header: BMPHeader{
Version: BMP_VERSION,
@@ -154,7 +155,7 @@ func NewBMPRouteMonitoring(p BMPPeerHeader, update *BGPMessage) *BMPMessage {
}
func (body *BMPRouteMonitoring) ParseBody(msg *BMPMessage, data []byte) error {
- update, err := ParseBGPMessage(data)
+ update, err := bgp.ParseBGPMessage(data)
if err != nil {
return err
}
@@ -202,11 +203,11 @@ const (
type BMPPeerDownNotification struct {
Reason uint8
- BGPNotification *BGPMessage
+ BGPNotification *bgp.BGPMessage
Data []byte
}
-func NewBMPPeerDownNotification(p BMPPeerHeader, reason uint8, notification *BGPMessage, data []byte) *BMPMessage {
+func NewBMPPeerDownNotification(p BMPPeerHeader, reason uint8, notification *bgp.BGPMessage, data []byte) *BMPMessage {
b := &BMPPeerDownNotification{
Reason: reason,
}
@@ -230,7 +231,7 @@ func (body *BMPPeerDownNotification) ParseBody(msg *BMPMessage, data []byte) err
body.Reason = data[0]
data = data[1:]
if body.Reason == BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION || body.Reason == BMP_PEER_DOWN_REASON_REMOTE_BGP_NOTIFICATION {
- notification, err := ParseBGPMessage(data)
+ notification, err := bgp.ParseBGPMessage(data)
if err != nil {
return err
}
@@ -266,11 +267,11 @@ type BMPPeerUpNotification struct {
LocalAddress net.IP
LocalPort uint16
RemotePort uint16
- SentOpenMsg *BGPMessage
- ReceivedOpenMsg *BGPMessage
+ SentOpenMsg *bgp.BGPMessage
+ ReceivedOpenMsg *bgp.BGPMessage
}
-func NewBMPPeerUpNotification(p BMPPeerHeader, lAddr string, lPort, rPort uint16, sent, recv *BGPMessage) *BMPMessage {
+func NewBMPPeerUpNotification(p BMPPeerHeader, lAddr string, lPort, rPort uint16, sent, recv *bgp.BGPMessage) *BMPMessage {
b := &BMPPeerUpNotification{
LocalPort: lPort,
RemotePort: rPort,
@@ -304,13 +305,13 @@ func (body *BMPPeerUpNotification) ParseBody(msg *BMPMessage, data []byte) error
body.RemotePort = binary.BigEndian.Uint16(data[18:20])
data = data[20:]
- sentopen, err := ParseBGPMessage(data)
+ sentopen, err := bgp.ParseBGPMessage(data)
if err != nil {
return err
}
body.SentOpenMsg = sentopen
data = data[body.SentOpenMsg.Header.Len:]
- body.ReceivedOpenMsg, err = ParseBGPMessage(data)
+ body.ReceivedOpenMsg, err = bgp.ParseBGPMessage(data)
if err != nil {
return err
}
@@ -574,26 +575,6 @@ func ParseBMPMessage(data []byte) (*BMPMessage, error) {
return msg, nil
}
-type MessageError struct {
- TypeCode uint8
- SubTypeCode uint8
- Data []byte
- Message string
-}
-
-func NewMessageError(typeCode, subTypeCode uint8, data []byte, msg string) error {
- return &MessageError{
- TypeCode: typeCode,
- SubTypeCode: subTypeCode,
- Data: data,
- Message: msg,
- }
-}
-
-func (e *MessageError) Error() string {
- return e.Message
-}
-
func SplitBMP(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 || len(data) < BMP_HEADER_SIZE {
return 0, nil, nil
diff --git a/packet/bgp/bmp_test.go b/packet/bmp/bmp_test.go
index e07c2455..dd7391aa 100644
--- a/packet/bgp/bmp_test.go
+++ b/packet/bmp/bmp_test.go
@@ -13,9 +13,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package bgp
+package bmp
import (
+ "github.com/osrg/gobgp/packet/bgp"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
@@ -46,7 +47,7 @@ func Test_Initiation(t *testing.T) {
}
func Test_PeerUpNotification(t *testing.T) {
- m := open()
+ m := bgp.NewTestBGPOpenMessage()
p0 := NewBMPPeerHeader(0, false, 1000, "10.0.0.1", 70000, "10.0.0.2", 1)
verify(t, NewBMPPeerUpNotification(*p0, "10.0.0.3", 10, 100, m, m))
p1 := NewBMPPeerHeader(0, false, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1)
@@ -56,12 +57,12 @@ func Test_PeerUpNotification(t *testing.T) {
func Test_PeerDownNotification(t *testing.T) {
p0 := NewBMPPeerHeader(0, false, 1000, "10.0.0.1", 70000, "10.0.0.2", 1)
verify(t, NewBMPPeerDownNotification(*p0, BMP_PEER_DOWN_REASON_UNKNOWN, nil, []byte{0x3, 0xb}))
- m := NewBGPNotificationMessage(1, 2, nil)
+ m := bgp.NewBGPNotificationMessage(1, 2, nil)
verify(t, NewBMPPeerDownNotification(*p0, BMP_PEER_DOWN_REASON_LOCAL_BGP_NOTIFICATION, m, nil))
}
func Test_RouteMonitoring(t *testing.T) {
- m := update()
+ m := bgp.NewTestBGPUpdateMessage()
p0 := NewBMPPeerHeader(0, false, 1000, "fe80::6e40:8ff:feab:2c2a", 70000, "10.0.0.2", 1)
verify(t, NewBMPRouteMonitoring(*p0, m))
}
diff --git a/server/bmp.go b/server/bmp.go
index 7ac79ada..33e0b745 100644
--- a/server/bmp.go
+++ b/server/bmp.go
@@ -20,6 +20,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/packet/bmp"
"github.com/osrg/gobgp/table"
"gopkg.in/tomb.v2"
"net"
@@ -121,7 +122,7 @@ func (w *bmpWatcher) loop() error {
log.Warnf("Can't find bmp server %s", newConn.RemoteAddr().String())
break
}
- i := bgp.NewBMPInitiation([]bgp.BMPTLV{})
+ i := bmp.NewBMPInitiation([]bmp.BMPTLV{})
buf, _ := i.Serialize()
if _, err := newConn.Write(buf); err != nil {
log.Warnf("failed to write to bmp server %s", server.host)
@@ -135,7 +136,7 @@ func (w *bmpWatcher) loop() error {
w.apiCh <- req
write := func(req *GrpcRequest) error {
for res := range req.ResponseCh {
- for _, msg := range res.Data.([]*bgp.BMPMessage) {
+ for _, msg := range res.Data.([]*bmp.BMPMessage) {
buf, _ = msg.Serialize()
if _, err := newConn.Write(buf); err != nil {
log.Warnf("failed to write to bmp server %s %s", server.host, err)
@@ -178,7 +179,7 @@ func (w *bmpWatcher) loop() error {
AS: msg.peerAS,
ID: msg.peerID,
}
- buf, _ := bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, msg.postPolicy, 0, info, msg.timestamp.Unix(), msg.payload).Serialize()
+ buf, _ := bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, msg.postPolicy, 0, info, msg.timestamp.Unix(), msg.payload).Serialize()
for _, server := range w.connMap {
if server.conn != nil {
send := server.typ != config.BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY && !msg.postPolicy
@@ -192,16 +193,16 @@ func (w *bmpWatcher) loop() error {
}
}
case *watcherEventStateChangedMsg:
- var bmpmsg *bgp.BMPMessage
+ var bmpmsg *bmp.BMPMessage
info := &table.PeerInfo{
Address: msg.peerAddress,
AS: msg.peerAS,
ID: msg.peerID,
}
if msg.state == bgp.BGP_FSM_ESTABLISHED {
- bmpmsg = bmpPeerUp(msg.localAddress.String(), msg.localPort, msg.peerPort, msg.sentOpen, msg.recvOpen, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, info, msg.timestamp.Unix())
+ bmpmsg = bmpPeerUp(msg.localAddress.String(), msg.localPort, msg.peerPort, msg.sentOpen, msg.recvOpen, bmp.BMP_PEER_TYPE_GLOBAL, false, 0, info, msg.timestamp.Unix())
} else {
- bmpmsg = bmpPeerDown(bgp.BMP_PEER_DOWN_REASON_UNKNOWN, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, info, msg.timestamp.Unix())
+ bmpmsg = bmpPeerDown(bmp.BMP_PEER_DOWN_REASON_UNKNOWN, bmp.BMP_PEER_TYPE_GLOBAL, false, 0, info, msg.timestamp.Unix())
}
buf, _ := bmpmsg.Serialize()
for _, server := range w.connMap {
@@ -230,20 +231,20 @@ func (w *bmpWatcher) restart(string) error {
return nil
}
-func bmpPeerUp(laddr string, lport, rport uint16, sent, recv *bgp.BGPMessage, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bgp.BMPMessage {
- ph := bgp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
- return bgp.NewBMPPeerUpNotification(*ph, laddr, lport, rport, sent, recv)
+func bmpPeerUp(laddr string, lport, rport uint16, sent, recv *bgp.BGPMessage, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bmp.BMPMessage {
+ ph := bmp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
+ return bmp.NewBMPPeerUpNotification(*ph, laddr, lport, rport, sent, recv)
}
-func bmpPeerDown(reason uint8, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bgp.BMPMessage {
- ph := bgp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
- return bgp.NewBMPPeerDownNotification(*ph, reason, nil, []byte{})
+func bmpPeerDown(reason uint8, t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64) *bmp.BMPMessage {
+ ph := bmp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
+ return bmp.NewBMPPeerDownNotification(*ph, reason, nil, []byte{})
}
-func bmpPeerRoute(t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64, payload []byte) *bgp.BMPMessage {
- ph := bgp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
- m := bgp.NewBMPRouteMonitoring(*ph, nil)
- body := m.Body.(*bgp.BMPRouteMonitoring)
+func bmpPeerRoute(t uint8, policy bool, pd uint64, peeri *table.PeerInfo, timestamp int64, payload []byte) *bmp.BMPMessage {
+ ph := bmp.NewBMPPeerHeader(t, policy, pd, peeri.Address.String(), peeri.AS, peeri.ID.String(), float64(timestamp))
+ m := bmp.NewBMPRouteMonitoring(*ph, nil)
+ body := m.Body.(*bmp.BMPRouteMonitoring)
body.BGPUpdatePayload = payload
return m
}
diff --git a/server/server.go b/server/server.go
index 1bfc5d51..71e569b2 100644
--- a/server/server.go
+++ b/server/server.go
@@ -30,6 +30,7 @@ import (
api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/packet/bmp"
"github.com/osrg/gobgp/packet/mrt"
"github.com/osrg/gobgp/table"
"github.com/osrg/gobgp/zebra"
@@ -1813,11 +1814,11 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
close(grpcReq.ResponseCh)
case REQ_BMP_GLOBAL:
paths := server.globalRib.GetBestPathList(table.GLOBAL_RIB_NAME, server.globalRib.GetRFlist())
- bmpmsgs := make([]*bgp.BMPMessage, 0, len(paths))
+ bmpmsgs := make([]*bmp.BMPMessage, 0, len(paths))
for _, path := range paths {
msgs := table.CreateUpdateMsgFromPaths([]*table.Path{path})
buf, _ := msgs[0].Serialize()
- bmpmsgs = append(bmpmsgs, bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, true, 0, path.GetSource(), path.GetTimestamp().Unix(), buf))
+ bmpmsgs = append(bmpmsgs, bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, true, 0, path.GetSource(), path.GetTimestamp().Unix(), buf))
}
grpcReq.ResponseCh <- &GrpcResponse{
Data: bmpmsgs,
@@ -1848,7 +1849,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
go sendMultipleResponses(grpcReq, results)
case REQ_BMP_NEIGHBORS:
//TODO: merge REQ_NEIGHBORS and REQ_BMP_NEIGHBORS
- msgs := make([]*bgp.BMPMessage, 0, len(server.neighborMap))
+ msgs := make([]*bmp.BMPMessage, 0, len(server.neighborMap))
for _, peer := range server.neighborMap {
if peer.fsm.state != bgp.BGP_FSM_ESTABLISHED {
continue
@@ -1858,7 +1859,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
sentOpen := buildopen(peer.fsm.gConf, peer.fsm.pConf)
info := peer.fsm.peerInfo
timestamp := peer.conf.Timers.State.Uptime
- msg := bmpPeerUp(laddr, lport, rport, sentOpen, peer.fsm.recvOpen, bgp.BMP_PEER_TYPE_GLOBAL, false, 0, info, timestamp)
+ msg := bmpPeerUp(laddr, lport, rport, sentOpen, peer.fsm.recvOpen, bmp.BMP_PEER_TYPE_GLOBAL, false, 0, info, timestamp)
msgs = append(msgs, msg)
}
grpcReq.ResponseCh <- &GrpcResponse{
@@ -1945,7 +1946,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
close(grpcReq.ResponseCh)
case REQ_BMP_ADJ_IN:
- bmpmsgs := make([]*bgp.BMPMessage, 0)
+ bmpmsgs := make([]*bmp.BMPMessage, 0)
for _, peer := range server.neighborMap {
if peer.fsm.state != bgp.BGP_FSM_ESTABLISHED {
continue
@@ -1953,7 +1954,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
for _, path := range peer.adjRibIn.PathList(peer.configuredRFlist(), false) {
msgs := table.CreateUpdateMsgFromPaths([]*table.Path{path})
buf, _ := msgs[0].Serialize()
- bmpmsgs = append(bmpmsgs, bmpPeerRoute(bgp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.fsm.peerInfo, path.GetTimestamp().Unix(), buf))
+ bmpmsgs = append(bmpmsgs, bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, false, 0, peer.fsm.peerInfo, path.GetTimestamp().Unix(), buf))
}
}
grpcReq.ResponseCh <- &GrpcResponse{