summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packet/bgp/bgp.go83
-rw-r--r--packet/bgp/helper.go24
2 files changed, 88 insertions, 19 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 21788549..e29e840e 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -2307,6 +2307,15 @@ func (er *EVPNEthernetAutoDiscoveryRoute) rd() RouteDistinguisherInterface {
return er.RD
}
+func NewEVPNEthernetAutoDiscoveryRoute(rd RouteDistinguisherInterface, esi EthernetSegmentIdentifier, etag uint32, label uint32) *EVPNNLRI {
+ return NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, &EVPNEthernetAutoDiscoveryRoute{
+ RD: rd,
+ ESI: esi,
+ ETag: etag,
+ Label: label,
+ })
+}
+
type EVPNMacIPAdvertisementRoute struct {
RD RouteDistinguisherInterface
ESI EthernetSegmentIdentifier
@@ -2441,6 +2450,30 @@ func (er *EVPNMacIPAdvertisementRoute) rd() RouteDistinguisherInterface {
return er.RD
}
+func NewEVPNMacIPAdvertisementRoute(rd RouteDistinguisherInterface, esi EthernetSegmentIdentifier, etag uint32, macAddress string, ipAddress string, labels []uint32) *EVPNNLRI {
+ mac, _ := net.ParseMAC(macAddress)
+ var ipLen uint8
+ ip := net.ParseIP(ipAddress)
+ if ip != nil {
+ if ipv4 := ip.To4(); ipv4 != nil {
+ ipLen = 32
+ ip = ipv4
+ } else {
+ ipLen = 128
+ }
+ }
+ return NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, &EVPNMacIPAdvertisementRoute{
+ RD: rd,
+ ESI: esi,
+ ETag: etag,
+ MacAddressLength: 6,
+ MacAddress: mac,
+ IPAddressLength: ipLen,
+ IPAddress: ip,
+ Labels: labels,
+ })
+}
+
type EVPNMulticastEthernetTagRoute struct {
RD RouteDistinguisherInterface
ETag uint32
@@ -2522,6 +2555,22 @@ func (er *EVPNMulticastEthernetTagRoute) rd() RouteDistinguisherInterface {
return er.RD
}
+func NewEVPNMulticastEthernetTagRoute(rd RouteDistinguisherInterface, etag uint32, ipAddress string) *EVPNNLRI {
+ ipLen := uint8(32)
+ ip := net.ParseIP(ipAddress)
+ if ipv4 := ip.To4(); ipv4 != nil {
+ ip = ipv4
+ } else {
+ ipLen = 128
+ }
+ return NewEVPNNLRI(EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, &EVPNMulticastEthernetTagRoute{
+ RD: rd,
+ ETag: etag,
+ IPAddressLength: ipLen,
+ IPAddress: ip,
+ })
+}
+
type EVPNEthernetSegmentRoute struct {
RD RouteDistinguisherInterface
ESI EthernetSegmentIdentifier
@@ -2602,6 +2651,22 @@ func (er *EVPNEthernetSegmentRoute) rd() RouteDistinguisherInterface {
return er.RD
}
+func NewEVPNEthernetSegmentRoute(rd RouteDistinguisherInterface, esi EthernetSegmentIdentifier, ipAddress string) *EVPNNLRI {
+ ipLen := uint8(32)
+ ip := net.ParseIP(ipAddress)
+ if ipv4 := ip.To4(); ipv4 != nil {
+ ip = ipv4
+ } else {
+ ipLen = 128
+ }
+ return NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE, &EVPNEthernetSegmentRoute{
+ RD: rd,
+ ESI: esi,
+ IPAddressLength: ipLen,
+ IPAddress: ip,
+ })
+}
+
type EVPNIPPrefixRoute struct {
RD RouteDistinguisherInterface
ESI EthernetSegmentIdentifier
@@ -2736,6 +2801,24 @@ func (er *EVPNIPPrefixRoute) rd() RouteDistinguisherInterface {
return er.RD
}
+func NewEVPNIPPrefixRoute(rd RouteDistinguisherInterface, esi EthernetSegmentIdentifier, etag uint32, ipPrefixLength uint8, ipPrefix string, gateway string, label uint32) *EVPNNLRI {
+ ip := net.ParseIP(ipPrefix)
+ gw := net.ParseIP(gateway)
+ if ipv4 := ip.To4(); ipv4 != nil {
+ ip = ipv4
+ gw = gw.To4()
+ }
+ return NewEVPNNLRI(EVPN_IP_PREFIX, &EVPNIPPrefixRoute{
+ RD: rd,
+ ESI: esi,
+ ETag: etag,
+ IPPrefixLength: ipPrefixLength,
+ IPPrefix: ip,
+ GWIPAddress: gw,
+ Label: label,
+ })
+}
+
type EVPNRouteTypeInterface interface {
Len() int
DecodeFromBytes([]byte) error
diff --git a/packet/bgp/helper.go b/packet/bgp/helper.go
index c816c9d6..5271a70c 100644
--- a/packet/bgp/helper.go
+++ b/packet/bgp/helper.go
@@ -15,10 +15,6 @@
package bgp
-import (
- "net"
-)
-
func NewTestBGPOpenMessage() *BGPMessage {
p1 := NewOptionParameterCapability(
[]ParameterCapabilityInterface{NewCapRouteRefresh()})
@@ -90,22 +86,12 @@ func NewTestBGPUpdateMessage() *BGPMessage {
prefixes4 := []AddrPrefixInterface{NewLabeledIPAddrPrefix(25, "192.168.0.0",
*NewMPLSLabelStack(5, 6, 7))}
- mac, _ := net.ParseMAC("01:23:45:67:89:ab")
prefixes5 := []AddrPrefixInterface{
- NewEVPNNLRI(EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY,
- &EVPNEthernetAutoDiscoveryRoute{NewRouteDistinguisherFourOctetAS(5, 6),
- EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2}),
- NewEVPNNLRI(EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT,
- &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,
- &EVPNMulticastEthernetTagRoute{NewRouteDistinguisherFourOctetAS(5, 6), 3, 32, net.ParseIP("192.2.1.2")}),
- NewEVPNNLRI(EVPN_ETHERNET_SEGMENT_ROUTE,
- &EVPNEthernetSegmentRoute{NewRouteDistinguisherFourOctetAS(5, 6),
- EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)},
- 32, net.ParseIP("192.2.1.1")}),
+ NewEVPNEthernetAutoDiscoveryRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 2, 2),
+ NewEVPNMacIPAdvertisementRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 3, "01:23:45:67:89:ab", "192.2.1.2", []uint32{3, 4}),
+ NewEVPNMulticastEthernetTagRoute(NewRouteDistinguisherFourOctetAS(5, 6), 3, "192.2.1.2"),
+ NewEVPNEthernetSegmentRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, "192.2.1.1"),
+ NewEVPNIPPrefixRoute(NewRouteDistinguisherFourOctetAS(5, 6), EthernetSegmentIdentifier{ESI_ARBITRARY, make([]byte, 9)}, 5, 24, "192.2.1.0", "192.3.1.1", 5),
}
p := []PathAttributeInterface{