summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-20 13:28:25 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-20 13:51:27 +0900
commit0564b24aef48f5821e97055d1b1e6eef5b73d14e (patch)
tree73ca853476ed9fa2924ac8cc7483f3dec93ec093
parent19858453d73bf6fb38eedac96e82a23f2d3632e5 (diff)
packet/bgp: Rename snake case to camel case
This patch renames some variable names in snake case (e.g., "last_byte_value") to that in the camel case (e.g., "lastByte") because Go prefers the camel case for variable names. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r--packet/bgp/bgp.go58
-rw-r--r--packet/bgp/helper.go22
-rw-r--r--packet/bgp/validate_test.go7
3 files changed, 44 insertions, 43 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 21dc892d..6e58d5e2 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -1055,20 +1055,20 @@ func (r *IPAddrPrefixDefault) decodePrefix(data []byte, bitlen uint8, addrlen ui
return nil
}
-func (r *IPAddrPrefixDefault) serializePrefix(bitlen uint8) ([]byte, error) {
- bytelen := (int(bitlen) + 7) / 8
- buf := make([]byte, bytelen)
+func (r *IPAddrPrefixDefault) serializePrefix(bitLen uint8) ([]byte, error) {
+ byteLen := (int(bitLen) + 7) / 8
+ buf := make([]byte, byteLen)
copy(buf, r.Prefix)
// clear trailing bits in the last byte. rfc doesn't require
// this though.
- if bitlen%8 != 0 {
- mask := 0xff00 >> (bitlen % 8)
- last_byte_value := buf[bytelen-1] & byte(mask)
- buf[bytelen-1] = last_byte_value
- }
- b := make([]byte, len(r.Prefix))
- copy(b, buf)
- copy(r.Prefix, b)
+ rem := bitLen % 8
+ if rem != 0 {
+ mask := 0xff00 >> rem
+ lastByte := buf[byteLen-1] & byte(mask)
+ buf[byteLen-1] = lastByte
+ }
+ r.Prefix = make([]byte, len(r.Prefix))
+ copy(r.Prefix, buf)
return buf, nil
}
@@ -3249,11 +3249,11 @@ type FlowSpecComponentInterface interface {
type flowSpecPrefix struct {
Prefix AddrPrefixInterface
- type_ BGPFlowSpecType
+ typ BGPFlowSpecType
}
func (p *flowSpecPrefix) DecodeFromBytes(data []byte, options ...*MarshallingOption) error {
- p.type_ = BGPFlowSpecType(data[0])
+ p.typ = BGPFlowSpecType(data[0])
return p.Prefix.DecodeFromBytes(data[1:], options...)
}
@@ -3272,7 +3272,7 @@ func (p *flowSpecPrefix) Len(options ...*MarshallingOption) int {
}
func (p *flowSpecPrefix) Type() BGPFlowSpecType {
- return p.type_
+ return p.typ
}
func (p *flowSpecPrefix) String() string {
@@ -3292,13 +3292,13 @@ func (p *flowSpecPrefix) MarshalJSON() ([]byte, error) {
type flowSpecPrefix6 struct {
Prefix AddrPrefixInterface
Offset uint8
- type_ BGPFlowSpecType
+ typ BGPFlowSpecType
}
// draft-ietf-idr-flow-spec-v6-06
// <type (1 octet), prefix length (1 octet), prefix offset(1 octet), prefix>
func (p *flowSpecPrefix6) DecodeFromBytes(data []byte, options ...*MarshallingOption) error {
- p.type_ = BGPFlowSpecType(data[0])
+ p.typ = BGPFlowSpecType(data[0])
p.Offset = data[2]
prefix := append([]byte{data[1]}, data[3:]...)
return p.Prefix.DecodeFromBytes(prefix, options...)
@@ -3321,7 +3321,7 @@ func (p *flowSpecPrefix6) Len(options ...*MarshallingOption) int {
}
func (p *flowSpecPrefix6) Type() BGPFlowSpecType {
- return p.type_
+ return p.typ
}
func (p *flowSpecPrefix6) String() string {
@@ -3373,15 +3373,15 @@ func NewFlowSpecSourcePrefix6(prefix AddrPrefixInterface, offset uint8) *FlowSpe
}
type flowSpecMac struct {
- Mac net.HardwareAddr
- type_ BGPFlowSpecType
+ Mac net.HardwareAddr
+ typ BGPFlowSpecType
}
func (p *flowSpecMac) DecodeFromBytes(data []byte, options ...*MarshallingOption) error {
if len(data) < 2 || len(data) < 2+int(data[1]) {
return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, "not all mac bits available")
}
- p.type_ = BGPFlowSpecType(data[0])
+ p.typ = BGPFlowSpecType(data[0])
p.Mac = net.HardwareAddr(data[2 : 2+int(data[1])])
return nil
}
@@ -3399,7 +3399,7 @@ func (p *flowSpecMac) Len(options ...*MarshallingOption) int {
}
func (p *flowSpecMac) Type() BGPFlowSpecType {
- return p.type_
+ return p.typ
}
func (p *flowSpecMac) String() string {
@@ -3421,7 +3421,7 @@ type FlowSpecSourceMac struct {
}
func NewFlowSpecSourceMac(mac net.HardwareAddr) *FlowSpecSourceMac {
- return &FlowSpecSourceMac{flowSpecMac{Mac: mac, type_: FLOW_SPEC_TYPE_SRC_MAC}}
+ return &FlowSpecSourceMac{flowSpecMac{Mac: mac, typ: FLOW_SPEC_TYPE_SRC_MAC}}
}
type FlowSpecDestinationMac struct {
@@ -3429,7 +3429,7 @@ type FlowSpecDestinationMac struct {
}
func NewFlowSpecDestinationMac(mac net.HardwareAddr) *FlowSpecDestinationMac {
- return &FlowSpecDestinationMac{flowSpecMac{Mac: mac, type_: FLOW_SPEC_TYPE_DST_MAC}}
+ return &FlowSpecDestinationMac{flowSpecMac{Mac: mac, typ: FLOW_SPEC_TYPE_DST_MAC}}
}
type FlowSpecComponentItem struct {
@@ -3492,11 +3492,11 @@ func NewFlowSpecComponentItem(op int, value int) *FlowSpecComponentItem {
type FlowSpecComponent struct {
Items []*FlowSpecComponentItem
- type_ BGPFlowSpecType
+ typ BGPFlowSpecType
}
func (p *FlowSpecComponent) DecodeFromBytes(data []byte, options ...*MarshallingOption) error {
- p.type_ = BGPFlowSpecType(data[0])
+ p.typ = BGPFlowSpecType(data[0])
data = data[1:]
p.Items = make([]*FlowSpecComponentItem, 0)
for {
@@ -3546,7 +3546,7 @@ func (p *FlowSpecComponent) Len(options ...*MarshallingOption) int {
}
func (p *FlowSpecComponent) Type() BGPFlowSpecType {
- return p.type_
+ return p.typ
}
func formatRaw(op int, value int) string {
@@ -3692,7 +3692,7 @@ func (p *FlowSpecComponent) String() string {
for _, i := range p.Items {
buf.WriteString(f(i.Op, i.Value))
}
- return fmt.Sprintf("[%s:%s]", p.type_, buf.String())
+ return fmt.Sprintf("[%s:%s]", p.typ, buf.String())
}
func (p *FlowSpecComponent) MarshalJSON() ([]byte, error) {
@@ -3705,10 +3705,10 @@ func (p *FlowSpecComponent) MarshalJSON() ([]byte, error) {
})
}
-func NewFlowSpecComponent(type_ BGPFlowSpecType, items []*FlowSpecComponentItem) *FlowSpecComponent {
+func NewFlowSpecComponent(typ BGPFlowSpecType, items []*FlowSpecComponentItem) *FlowSpecComponent {
return &FlowSpecComponent{
Items: items,
- type_: type_,
+ typ: typ,
}
}
diff --git a/packet/bgp/helper.go b/packet/bgp/helper.go
index d97095f9..1061d915 100644
--- a/packet/bgp/helper.go
+++ b/packet/bgp/helper.go
@@ -77,25 +77,25 @@ func NewTestBGPUpdateMessage() *BGPMessage {
NewMacMobilityExtended(123, false),
}
- mp_nlri := []AddrPrefixInterface{
+ prefixes1 := []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,
+ prefixes2 := []AddrPrefixInterface{NewIPv6AddrPrefix(100,
"fe80:1234:1234:5667:8967:af12:8912:1023")}
- mp_nlri3 := []AddrPrefixInterface{NewLabeledVPNIPv6AddrPrefix(100,
+ prefixes3 := []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",
+ prefixes4 := []AddrPrefixInterface{NewLabeledIPAddrPrefix(25, "192.168.0.0",
*NewMPLSLabelStack(5, 6, 7))}
mac, _ := net.ParseMAC("01:23:45:67:89:ab")
- mp_nlri5 := []AddrPrefixInterface{
+ prefixes5 := []AddrPrefixInterface{
NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, 0,
&EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6),
EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}),
@@ -129,12 +129,12 @@ func NewTestBGPUpdateMessage() *BGPMessage {
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", prefixes1),
+ NewPathAttributeMpReachNLRI("1023::", prefixes2),
+ NewPathAttributeMpReachNLRI("fe80::", prefixes3),
+ NewPathAttributeMpReachNLRI("129.1.1.1", prefixes4),
+ NewPathAttributeMpReachNLRI("129.1.1.1", prefixes5),
+ NewPathAttributeMpUnreachNLRI(prefixes1),
//NewPathAttributeMpReachNLRI("112.22.2.0", []AddrPrefixInterface{}),
//NewPathAttributeMpUnreachNLRI([]AddrPrefixInterface{}),
&PathAttributeUnknown{
diff --git a/packet/bgp/validate_test.go b/packet/bgp/validate_test.go
index 5e986300..3bb60639 100644
--- a/packet/bgp/validate_test.go
+++ b/packet/bgp/validate_test.go
@@ -2,9 +2,10 @@ package bgp
import (
"encoding/binary"
- "github.com/stretchr/testify/assert"
"net"
"testing"
+
+ "github.com/stretchr/testify/assert"
)
func bgpupdate() *BGPMessage {
@@ -27,13 +28,13 @@ func bgpupdateV6() *BGPMessage {
NewAsPathParam(2, []uint16{65001}),
}
- mp_nlri := []AddrPrefixInterface{NewIPv6AddrPrefix(100,
+ prefixes := []AddrPrefixInterface{NewIPv6AddrPrefix(100,
"fe80:1234:1234:5667:8967:af12:8912:1023")}
p := []PathAttributeInterface{
NewPathAttributeOrigin(1),
NewPathAttributeAsPath(aspath),
- NewPathAttributeMpReachNLRI("1023::", mp_nlri),
+ NewPathAttributeMpReachNLRI("1023::", prefixes),
}
return NewBGPUpdateMessage(nil, p, nil)
}