diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-08 10:57:43 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-08 13:13:34 +0900 |
commit | 9298e5eeca78e8bb02ff34b500add622b73b4f5f (patch) | |
tree | 857f7646d93ba770527e61edd76dd1838b440249 /packet | |
parent | 89b904b7417932e78c8c6fea2ad5d8a35891b0a4 (diff) |
*: kill bgp.NLRInfo and bgp.WithdrawnRoute
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp.go | 28 | ||||
-rw-r--r-- | packet/bgp_test.go | 8 | ||||
-rw-r--r-- | packet/validate_test.go | 4 |
3 files changed, 13 insertions, 27 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index 0e46ae5e..1b07ec33 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -743,10 +743,6 @@ func NewIPv6AddrPrefix(length uint8, prefix string) *IPv6AddrPrefix { } } -type WithdrawnRoute struct { - IPAddrPrefix -} - const ( BGP_RD_TWO_OCTET_AS = iota BGP_RD_IPV4_ADDRESS @@ -5279,22 +5275,12 @@ func GetPathAttribute(data []byte) (PathAttributeInterface, error) { return &PathAttributeUnknown{}, nil } -type NLRInfo struct { - IPAddrPrefix -} - -func NewNLRInfo(length uint8, prefix string) *NLRInfo { - return &NLRInfo{ - IPAddrPrefix: *NewIPAddrPrefix(length, prefix), - } -} - type BGPUpdate struct { WithdrawnRoutesLen uint16 - WithdrawnRoutes []WithdrawnRoute + WithdrawnRoutes []*IPAddrPrefix TotalPathAttributeLen uint16 PathAttributes []PathAttributeInterface - NLRI []NLRInfo + NLRI []*IPAddrPrefix } func (msg *BGPUpdate) DecodeFromBytes(data []byte) error { @@ -5316,9 +5302,9 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error { return NewMessageError(eCode, eSubCode, nil, "withdrawn route length exceeds message length") } - msg.WithdrawnRoutes = []WithdrawnRoute{} + msg.WithdrawnRoutes = make([]*IPAddrPrefix, 0, msg.WithdrawnRoutesLen) for routelen := msg.WithdrawnRoutesLen; routelen > 0; { - w := WithdrawnRoute{} + w := &IPAddrPrefix{} err := w.DecodeFromBytes(data) if err != nil { return err @@ -5362,9 +5348,9 @@ func (msg *BGPUpdate) DecodeFromBytes(data []byte) error { msg.PathAttributes = append(msg.PathAttributes, p) } - msg.NLRI = []NLRInfo{} + msg.NLRI = make([]*IPAddrPrefix, 0) for restlen := len(data); restlen > 0; { - n := NLRInfo{} + n := &IPAddrPrefix{} err := n.DecodeFromBytes(data) if err != nil { return err @@ -5414,7 +5400,7 @@ func (msg *BGPUpdate) Serialize() ([]byte, error) { return buf, nil } -func NewBGPUpdateMessage(withdrawnRoutes []WithdrawnRoute, pathattrs []PathAttributeInterface, nlri []NLRInfo) *BGPMessage { +func NewBGPUpdateMessage(withdrawnRoutes []*IPAddrPrefix, pathattrs []PathAttributeInterface, nlri []*IPAddrPrefix) *BGPMessage { return &BGPMessage{ Header: BGPHeader{Type: BGP_MSG_UPDATE}, Body: &BGPUpdate{0, withdrawnRoutes, 0, pathattrs, nlri}, diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 74fcb510..20664ba0 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -37,9 +37,9 @@ func open() *BGPMessage { } func update() *BGPMessage { - w1 := WithdrawnRoute{*NewIPAddrPrefix(23, "121.1.3.2")} - w2 := WithdrawnRoute{*NewIPAddrPrefix(17, "100.33.3.0")} - w := []WithdrawnRoute{w1, w2} + w1 := NewIPAddrPrefix(23, "121.1.3.2") + w2 := NewIPAddrPrefix(17, "100.33.3.0") + w := []*IPAddrPrefix{w1, w2} aspath1 := []AsPathParamInterface{ NewAsPathParam(2, []uint16{1000}), @@ -142,7 +142,7 @@ func update() *BGPMessage { }, }, } - n := []NLRInfo{*NewNLRInfo(24, "13.2.3.1")} + n := []*IPAddrPrefix{NewIPAddrPrefix(24, "13.2.3.1")} return NewBGPUpdateMessage(w, p, n) } diff --git a/packet/validate_test.go b/packet/validate_test.go index 2f007c44..6309c74d 100644 --- a/packet/validate_test.go +++ b/packet/validate_test.go @@ -18,7 +18,7 @@ func bgpupdate() *BGPMessage { NewPathAttributeNextHop("192.168.1.1"), } - n := []NLRInfo{*NewNLRInfo(24, "10.10.10.0")} + n := []*IPAddrPrefix{NewIPAddrPrefix(24, "10.10.10.0")} return NewBGPUpdateMessage(nil, p, n) } @@ -35,7 +35,7 @@ func bgpupdateV6() *BGPMessage { NewPathAttributeAsPath(aspath), NewPathAttributeMpReachNLRI("1023::", mp_nlri), } - return NewBGPUpdateMessage(nil, p, []NLRInfo{}) + return NewBGPUpdateMessage(nil, p, nil) } func Test_Validate_CapV4(t *testing.T) { |