diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-03 16:14:35 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-05 17:24:36 +0900 |
commit | a0f734a6d7e49b6148703f519b601bac3ad30e7b (patch) | |
tree | 5e478d31a84956fa1f1a196e99fd22fcdd9788a6 | |
parent | 062357469b3f82679faebd870d05f2c13ddd8241 (diff) |
packet: add helper function to create RT struct
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | packet/bgp.go | 26 | ||||
-rw-r--r-- | packet/bgp_test.go | 8 |
2 files changed, 29 insertions, 5 deletions
diff --git a/packet/bgp.go b/packet/bgp.go index d058d1ec..35e70e72 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -3116,11 +3116,11 @@ func (e *TwoOctetAsSpecificExtended) ToApiStruct() *api.ExtendedCommunity { } } -func NewTwoOctetAsSpecificExtended(as uint16, rt uint32, isTransitive bool) *TwoOctetAsSpecificExtended { +func NewTwoOctetAsSpecificExtended(as uint16, localAdmin uint32, isTransitive bool) *TwoOctetAsSpecificExtended { return &TwoOctetAsSpecificExtended{ SubType: ExtendedCommunityAttrSubType(EC_SUBTYPE_ROUTE_TARGET), AS: as, - LocalAdmin: rt, + LocalAdmin: localAdmin, IsTransitive: isTransitive, } } @@ -3167,6 +3167,19 @@ func (e *IPv4AddressSpecificExtended) ToApiStruct() *api.ExtendedCommunity { } } +func NewIPv4AddressSpecificExtended(ip string, localAdmin uint16, isTransitive bool) *IPv4AddressSpecificExtended { + ipv4 := net.ParseIP(ip) + if ipv4.To4() == nil { + return nil + } + return &IPv4AddressSpecificExtended{ + SubType: ExtendedCommunityAttrSubType(EC_SUBTYPE_ROUTE_TARGET), + IPv4: ipv4.To4(), + LocalAdmin: localAdmin, + IsTransitive: isTransitive, + } +} + type FourOctetAsSpecificExtended struct { SubType ExtendedCommunityAttrSubType AS uint32 @@ -3213,6 +3226,15 @@ func (e *FourOctetAsSpecificExtended) ToApiStruct() *api.ExtendedCommunity { } } +func NewFourOctetAsSpecificExtended(as uint32, localAdmin uint16, isTransitive bool) *FourOctetAsSpecificExtended { + return &FourOctetAsSpecificExtended{ + SubType: ExtendedCommunityAttrSubType(EC_SUBTYPE_ROUTE_TARGET), + AS: as, + LocalAdmin: localAdmin, + IsTransitive: isTransitive, + } +} + type OpaqueExtendedValueInterface interface { Serialize() ([]byte, error) String() string diff --git a/packet/bgp_test.go b/packet/bgp_test.go index 528b3c4c..731b9870 100644 --- a/packet/bgp_test.go +++ b/packet/bgp_test.go @@ -59,10 +59,12 @@ func update() *BGPMessage { NewAs4PathParam(2, []uint32{1003, 100004}), } + isTransitive := true + ecommunities := []ExtendedCommunityInterface{ - &TwoOctetAsSpecificExtended{SubType: 1, AS: 10003, LocalAdmin: 3 << 20}, - &FourOctetAsSpecificExtended{SubType: 2, AS: 1 << 20, LocalAdmin: 300}, - &IPv4AddressSpecificExtended{SubType: 3, IPv4: net.ParseIP("192.2.1.2").To4(), LocalAdmin: 3000}, + NewTwoOctetAsSpecificExtended(10003, 3<<20, isTransitive), + NewFourOctetAsSpecificExtended(1<<20, 300, isTransitive), + NewIPv4AddressSpecificExtended("192.2.1.2", 3000, isTransitive), &OpaqueExtended{ Value: &DefaultOpaqueExtendedValue{[]byte{0, 1, 2, 3, 4, 5, 6, 7}}, }, |