Add unit tests
This commit is contained in:
359
vendor/github.com/osrg/gobgp/internal/pkg/apiutil/attribute.go
generated
vendored
359
vendor/github.com/osrg/gobgp/internal/pkg/apiutil/attribute.go
generated
vendored
@@ -45,7 +45,9 @@ func UnmarshalAttribute(an *any.Any) (bgp.PathAttributeInterface, error) {
|
||||
case *api.NextHopAttribute:
|
||||
nexthop := net.ParseIP(a.NextHop).To4()
|
||||
if nexthop == nil {
|
||||
return nil, fmt.Errorf("invalid nexthop address: %s", a.NextHop)
|
||||
if nexthop = net.ParseIP(a.NextHop).To16(); nexthop == nil {
|
||||
return nil, fmt.Errorf("invalid nexthop address: %s", a.NextHop)
|
||||
}
|
||||
}
|
||||
return bgp.NewPathAttributeNextHop(a.NextHop), nil
|
||||
case *api.MultiExitDiscAttribute:
|
||||
@@ -73,6 +75,8 @@ func UnmarshalAttribute(an *any.Any) (bgp.PathAttributeInterface, error) {
|
||||
}
|
||||
}
|
||||
return bgp.NewPathAttributeClusterList(a.Ids), nil
|
||||
case *api.PrefixSID:
|
||||
return bgp.NewPathAttributePrefixSID(a)
|
||||
}
|
||||
return nil, errors.New("unexpected object")
|
||||
}
|
||||
@@ -147,6 +151,114 @@ func NewClusterListAttributeFromNative(a *bgp.PathAttributeClusterList) *api.Clu
|
||||
}
|
||||
}
|
||||
|
||||
func NewPrefixSIDAttributeFromNative(a *bgp.PathAttributePrefixSID) *api.PrefixSID {
|
||||
psid := &api.PrefixSID{}
|
||||
psid.Tlvs = MarshalSRv6TLVs(a.TLVs)
|
||||
|
||||
return psid
|
||||
}
|
||||
|
||||
func MarshalSRv6TLVs(tlvs []bgp.PrefixSIDTLVInterface) []*any.Any {
|
||||
mtlvs := make([]*any.Any, len(tlvs))
|
||||
for i, tlv := range tlvs {
|
||||
var r proto.Message
|
||||
switch t := tlv.(type) {
|
||||
case *bgp.SRv6L3ServiceAttribute:
|
||||
o := &api.SRv6L3ServiceTLV{}
|
||||
o.SubTlvs = MarshalSRv6SubTLVs(t.SubTLVs)
|
||||
r = o
|
||||
default:
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "protobuf",
|
||||
"SRv6": t,
|
||||
}).Warn("invalid prefix sid tlv type to marshal")
|
||||
return nil
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(r)
|
||||
mtlvs[i] = a
|
||||
}
|
||||
|
||||
return mtlvs
|
||||
}
|
||||
|
||||
func MarshalSRv6SubTLVs(tlvs []bgp.PrefixSIDTLVInterface) map[uint32]*api.SRv6TLV {
|
||||
mtlvs := make(map[uint32]*api.SRv6TLV)
|
||||
var key uint32
|
||||
for _, tlv := range tlvs {
|
||||
var r proto.Message
|
||||
switch t := tlv.(type) {
|
||||
case *bgp.SRv6InformationSubTLV:
|
||||
o := &api.SRv6InformationSubTLV{
|
||||
EndpointBehavior: uint32(t.EndpointBehavior),
|
||||
// TODO Once flags are used in RFC, add processing.
|
||||
Flags: &api.SRv6SIDFlags{},
|
||||
}
|
||||
o.Sid = make([]byte, len(t.SID))
|
||||
copy(o.Sid, t.SID)
|
||||
o.SubSubTlvs = MarshalSRv6SubSubTLVs(t.SubSubTLVs)
|
||||
// SRv6 Information Sub TLV is type 1 Sub TLV
|
||||
key = 1
|
||||
r = o
|
||||
default:
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "protobuf",
|
||||
"SRv6": t,
|
||||
}).Warn("invalid prefix sid sub tlv type to marshal")
|
||||
return nil
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(r)
|
||||
tlvs, ok := mtlvs[key]
|
||||
if !ok {
|
||||
tlvs = &api.SRv6TLV{
|
||||
Tlv: make([]*any.Any, 0),
|
||||
}
|
||||
mtlvs[key] = tlvs
|
||||
}
|
||||
tlvs.Tlv = append(tlvs.Tlv, a)
|
||||
}
|
||||
|
||||
return mtlvs
|
||||
}
|
||||
|
||||
func MarshalSRv6SubSubTLVs(tlvs []bgp.PrefixSIDTLVInterface) map[uint32]*api.SRv6TLV {
|
||||
mtlvs := make(map[uint32]*api.SRv6TLV)
|
||||
var key uint32
|
||||
for _, tlv := range tlvs {
|
||||
var r proto.Message
|
||||
switch t := tlv.(type) {
|
||||
case *bgp.SRv6SIDStructureSubSubTLV:
|
||||
o := &api.SRv6StructureSubSubTLV{
|
||||
LocalBlockLength: uint32(t.LocalBlockLength),
|
||||
LocalNodeLength: uint32(t.LocatorNodeLength),
|
||||
FunctionLength: uint32(t.FunctionLength),
|
||||
ArgumentLength: uint32(t.ArgumentLength),
|
||||
TranspositionLength: uint32(t.TranspositionLength),
|
||||
TranspositionOffset: uint32(t.TranspositionOffset),
|
||||
}
|
||||
// SRv6 SID Structure Sub Sub TLV is type 1 Sub Sub TLV
|
||||
key = 1
|
||||
r = o
|
||||
default:
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "protobuf",
|
||||
"SRv6": t,
|
||||
}).Warn("invalid prefix sid sub sub tlv type to marshal")
|
||||
return nil
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(r)
|
||||
tlvs, ok := mtlvs[key]
|
||||
if !ok {
|
||||
tlvs = &api.SRv6TLV{
|
||||
Tlv: make([]*any.Any, 0),
|
||||
}
|
||||
mtlvs[key] = tlvs
|
||||
}
|
||||
tlvs.Tlv = append(tlvs.Tlv, a)
|
||||
}
|
||||
|
||||
return mtlvs
|
||||
}
|
||||
|
||||
func MarshalRD(rd bgp.RouteDistinguisherInterface) *any.Any {
|
||||
var r proto.Message
|
||||
switch v := rd.(type) {
|
||||
@@ -319,6 +431,88 @@ func UnmarshalFlowSpecRules(values []*any.Any) ([]bgp.FlowSpecComponentInterface
|
||||
return rules, nil
|
||||
}
|
||||
|
||||
func MarshalLsNodeDescriptor(d *bgp.LsNodeDescriptor) *api.LsNodeDescriptor {
|
||||
return &api.LsNodeDescriptor{
|
||||
Asn: d.Asn,
|
||||
BgpLsId: d.BGPLsID,
|
||||
OspfAreaId: d.OspfAreaID,
|
||||
Pseudonode: d.PseudoNode,
|
||||
IgpRouterId: d.IGPRouterID,
|
||||
}
|
||||
}
|
||||
|
||||
func MarshalLsLinkDescriptor(n *bgp.LsLinkDescriptor) *api.LsLinkDescriptor {
|
||||
return &api.LsLinkDescriptor{
|
||||
LinkLocalId: uint32OrDefault(n.LinkLocalID),
|
||||
LinkRemoteId: uint32OrDefault(n.LinkRemoteID),
|
||||
InterfaceAddrIpv4: ipOrDefault(n.InterfaceAddrIPv4),
|
||||
NeighborAddrIpv4: ipOrDefault(n.NeighborAddrIPv4),
|
||||
InterfaceAddrIpv6: ipOrDefault(n.InterfaceAddrIPv6),
|
||||
NeighborAddrIpv6: ipOrDefault(n.NeighborAddrIPv6),
|
||||
}
|
||||
}
|
||||
|
||||
func MarshalLsPrefixDescriptor(d *bgp.LsPrefixDescriptor) *api.LsPrefixDescriptor {
|
||||
p := &api.LsPrefixDescriptor{
|
||||
OspfRouteType: d.OSPFRouteType.String(),
|
||||
}
|
||||
|
||||
for _, ip := range d.IPReachability {
|
||||
p.IpReachability = append(p.IpReachability, ip.String())
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func MarshalLsNodeNLRI(n *bgp.LsNodeNLRI) *any.Any {
|
||||
node := &api.LsNodeNLRI{
|
||||
LocalNode: MarshalLsNodeDescriptor(n.LocalNodeDesc.(*bgp.LsTLVNodeDescriptor).Extract()),
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(node)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func MarshalLsLinkNLRI(n *bgp.LsLinkNLRI) *any.Any {
|
||||
desc := &bgp.LsLinkDescriptor{}
|
||||
desc.ParseTLVs(n.LinkDesc)
|
||||
|
||||
link := &api.LsLinkNLRI{
|
||||
LocalNode: MarshalLsNodeDescriptor(n.LocalNodeDesc.(*bgp.LsTLVNodeDescriptor).Extract()),
|
||||
RemoteNode: MarshalLsNodeDescriptor(n.RemoteNodeDesc.(*bgp.LsTLVNodeDescriptor).Extract()),
|
||||
LinkDescriptor: MarshalLsLinkDescriptor(desc),
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(link)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func MarshalLsPrefixV4NLRI(n *bgp.LsPrefixV4NLRI) *any.Any {
|
||||
desc := &bgp.LsPrefixDescriptor{}
|
||||
desc.ParseTLVs(n.PrefixDesc, false)
|
||||
|
||||
prefix := &api.LsPrefixV4NLRI{
|
||||
LocalNode: MarshalLsNodeDescriptor(n.LocalNodeDesc.(*bgp.LsTLVNodeDescriptor).Extract()),
|
||||
PrefixDescriptor: MarshalLsPrefixDescriptor(desc),
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(prefix)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func MarshalLsPrefixV6NLRI(n *bgp.LsPrefixV6NLRI) *any.Any {
|
||||
desc := &bgp.LsPrefixDescriptor{}
|
||||
desc.ParseTLVs(n.PrefixDesc, true)
|
||||
|
||||
prefix := &api.LsPrefixV6NLRI{
|
||||
LocalNode: MarshalLsNodeDescriptor(n.LocalNodeDesc.(*bgp.LsTLVNodeDescriptor).Extract()),
|
||||
PrefixDescriptor: MarshalLsPrefixDescriptor(desc),
|
||||
}
|
||||
a, _ := ptypes.MarshalAny(prefix)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func MarshalNLRI(value bgp.AddrPrefixInterface) *any.Any {
|
||||
var nlri proto.Message
|
||||
|
||||
@@ -436,6 +630,32 @@ func MarshalNLRI(value bgp.AddrPrefixInterface) *any.Any {
|
||||
Rd: MarshalRD(v.RD()),
|
||||
Rules: MarshalFlowSpecRules(v.Value),
|
||||
}
|
||||
case *bgp.LsAddrPrefix:
|
||||
switch n := v.NLRI.(type) {
|
||||
case *bgp.LsNodeNLRI:
|
||||
nlri = &api.LsAddrPrefix{
|
||||
Type: api.LsNLRIType_LS_NLRI_NODE,
|
||||
Nlri: MarshalLsNodeNLRI(n),
|
||||
}
|
||||
|
||||
case *bgp.LsLinkNLRI:
|
||||
nlri = &api.LsAddrPrefix{
|
||||
Type: api.LsNLRIType_LS_NLRI_LINK,
|
||||
Nlri: MarshalLsLinkNLRI(n),
|
||||
}
|
||||
|
||||
case *bgp.LsPrefixV4NLRI:
|
||||
nlri = &api.LsAddrPrefix{
|
||||
Type: api.LsNLRIType_LS_NLRI_PREFIX_V4,
|
||||
Nlri: MarshalLsPrefixV4NLRI(n),
|
||||
}
|
||||
|
||||
case *bgp.LsPrefixV6NLRI:
|
||||
nlri = &api.LsAddrPrefix{
|
||||
Type: api.LsNLRIType_LS_NLRI_PREFIX_V6,
|
||||
Nlri: MarshalLsPrefixV6NLRI(n),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
an, _ := ptypes.MarshalAny(nlri)
|
||||
@@ -1011,6 +1231,133 @@ func NewLargeCommunitiesAttributeFromNative(a *bgp.PathAttributeLargeCommunities
|
||||
}
|
||||
}
|
||||
|
||||
func stringOrDefault(s *string) string {
|
||||
if s == nil {
|
||||
return ""
|
||||
}
|
||||
return *s
|
||||
}
|
||||
|
||||
func bytesOrDefault(b *[]byte) []byte {
|
||||
if b == nil {
|
||||
return []byte{}
|
||||
}
|
||||
return *b
|
||||
}
|
||||
|
||||
func ipOrDefault(ip *net.IP) string {
|
||||
if ip == nil {
|
||||
return ""
|
||||
}
|
||||
return ip.String()
|
||||
}
|
||||
|
||||
func uint32OrDefault(i *uint32) uint32 {
|
||||
if i == nil {
|
||||
return 0
|
||||
}
|
||||
return *i
|
||||
}
|
||||
|
||||
func float32OrDefault(f *float32) float32 {
|
||||
if f == nil {
|
||||
return 0.0
|
||||
}
|
||||
return *f
|
||||
}
|
||||
|
||||
func NewLsAttributeFromNative(a *bgp.PathAttributeLs) *api.LsAttribute {
|
||||
attr := a.Extract()
|
||||
|
||||
apiAttr := &api.LsAttribute{
|
||||
Node: &api.LsAttributeNode{
|
||||
Name: stringOrDefault(attr.Node.Name),
|
||||
Opaque: bytesOrDefault(attr.Node.Opaque),
|
||||
IsisArea: bytesOrDefault(attr.Node.IsisArea),
|
||||
LocalRouterId: ipOrDefault(attr.Node.LocalRouterID),
|
||||
LocalRouterIdV6: ipOrDefault(attr.Node.LocalRouterIDv6),
|
||||
|
||||
SrAlgorithms: bytesOrDefault(attr.Node.SrAlgorithms),
|
||||
},
|
||||
Link: &api.LsAttributeLink{
|
||||
Name: stringOrDefault(attr.Link.Name),
|
||||
Opaque: bytesOrDefault(attr.Link.Opaque),
|
||||
LocalRouterId: ipOrDefault(attr.Link.LocalRouterID),
|
||||
LocalRouterIdV6: ipOrDefault(attr.Link.LocalRouterIDv6),
|
||||
RemoteRouterId: ipOrDefault(attr.Link.RemoteRouterID),
|
||||
RemoteRouterIdV6: ipOrDefault(attr.Link.RemoteRouterIDv6),
|
||||
AdminGroup: uint32OrDefault(attr.Link.AdminGroup),
|
||||
DefaultTeMetric: uint32OrDefault(attr.Link.DefaultTEMetric),
|
||||
IgpMetric: uint32OrDefault(attr.Link.IGPMetric),
|
||||
|
||||
Bandwidth: float32OrDefault(attr.Link.Bandwidth),
|
||||
ReservableBandwidth: float32OrDefault(attr.Link.ReservableBandwidth),
|
||||
SrAdjacencySid: uint32OrDefault(attr.Link.SrAdjacencySID),
|
||||
},
|
||||
Prefix: &api.LsAttributePrefix{
|
||||
Opaque: bytesOrDefault(attr.Prefix.Opaque),
|
||||
|
||||
SrPrefixSid: uint32OrDefault(attr.Prefix.SrPrefixSID),
|
||||
},
|
||||
}
|
||||
|
||||
if attr.Node.Flags != nil {
|
||||
apiAttr.Node.Flags = &api.LsNodeFlags{
|
||||
Overload: attr.Node.Flags.Overload,
|
||||
Attached: attr.Node.Flags.Attached,
|
||||
External: attr.Node.Flags.External,
|
||||
Abr: attr.Node.Flags.ABR,
|
||||
Router: attr.Node.Flags.Router,
|
||||
V6: attr.Node.Flags.V6,
|
||||
}
|
||||
}
|
||||
|
||||
if attr.Node.SrCapabilties != nil {
|
||||
apiAttr.Node.SrCapabilities = &api.LsSrCapabilities{
|
||||
Ipv4Supported: attr.Node.SrCapabilties.IPv4Supported,
|
||||
Ipv6Supported: attr.Node.SrCapabilties.IPv6Supported,
|
||||
}
|
||||
|
||||
for _, r := range attr.Node.SrCapabilties.Ranges {
|
||||
apiAttr.Node.SrCapabilities.Ranges = append(apiAttr.Node.SrCapabilities.Ranges, &api.LsSrRange{
|
||||
Begin: r.Begin,
|
||||
End: r.End,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if attr.Node.SrLocalBlock != nil {
|
||||
apiAttr.Node.SrLocalBlock = &api.LsSrLocalBlock{}
|
||||
for _, r := range attr.Node.SrLocalBlock.Ranges {
|
||||
apiAttr.Node.SrLocalBlock.Ranges = append(apiAttr.Node.SrLocalBlock.Ranges, &api.LsSrRange{
|
||||
Begin: r.Begin,
|
||||
End: r.End,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if attr.Link.UnreservedBandwidth != nil {
|
||||
for _, f := range attr.Link.UnreservedBandwidth {
|
||||
apiAttr.Link.UnreservedBandwidth = append(apiAttr.Link.UnreservedBandwidth, f)
|
||||
}
|
||||
}
|
||||
|
||||
if attr.Link.Srlgs != nil {
|
||||
apiAttr.Link.Srlgs = append(apiAttr.Link.Srlgs, *attr.Link.Srlgs...)
|
||||
}
|
||||
|
||||
if attr.Prefix.IGPFlags != nil {
|
||||
apiAttr.Prefix.IgpFlags = &api.LsIGPFlags{
|
||||
Down: attr.Prefix.IGPFlags.Down,
|
||||
NoUnicast: attr.Prefix.IGPFlags.NoUnicast,
|
||||
LocalAddress: attr.Prefix.IGPFlags.LocalAddress,
|
||||
PropagateNssa: attr.Prefix.IGPFlags.PropagateNSSA,
|
||||
}
|
||||
}
|
||||
|
||||
return apiAttr
|
||||
}
|
||||
|
||||
func NewUnknownAttributeFromNative(a *bgp.PathAttributeUnknown) *api.UnknownAttribute {
|
||||
return &api.UnknownAttribute{
|
||||
Flags: uint32(a.Flags),
|
||||
@@ -1083,6 +1430,9 @@ func MarshalPathAttributes(attrList []bgp.PathAttributeInterface) []*any.Any {
|
||||
case *bgp.PathAttributeLargeCommunities:
|
||||
n, _ := ptypes.MarshalAny(NewLargeCommunitiesAttributeFromNative(a))
|
||||
anyList = append(anyList, n)
|
||||
case *bgp.PathAttributeLs:
|
||||
n, _ := ptypes.MarshalAny(NewLsAttributeFromNative(a))
|
||||
anyList = append(anyList, n)
|
||||
case *bgp.PathAttributeUnknown:
|
||||
n, _ := ptypes.MarshalAny(NewUnknownAttributeFromNative(a))
|
||||
anyList = append(anyList, n)
|
||||
@@ -1125,7 +1475,9 @@ func unmarshalAttribute(an *any.Any) (bgp.PathAttributeInterface, error) {
|
||||
case *api.NextHopAttribute:
|
||||
nexthop := net.ParseIP(a.NextHop).To4()
|
||||
if nexthop == nil {
|
||||
return nil, fmt.Errorf("invalid nexthop address: %s", a.NextHop)
|
||||
if nexthop = net.ParseIP(a.NextHop).To16(); nexthop == nil {
|
||||
return nil, fmt.Errorf("invalid nexthop address: %s", a.NextHop)
|
||||
}
|
||||
}
|
||||
return bgp.NewPathAttributeNextHop(a.NextHop), nil
|
||||
case *api.MultiExitDiscAttribute:
|
||||
@@ -1295,7 +1647,8 @@ func unmarshalAttribute(an *any.Any) (bgp.PathAttributeInterface, error) {
|
||||
communities = append(communities, bgp.NewLargeCommunity(c.GlobalAdmin, c.LocalData1, c.LocalData2))
|
||||
}
|
||||
return bgp.NewPathAttributeLargeCommunities(communities), nil
|
||||
|
||||
case *api.PrefixSID:
|
||||
return bgp.NewPathAttributePrefixSID(a)
|
||||
case *api.UnknownAttribute:
|
||||
return bgp.NewPathAttributeUnknown(bgp.BGPAttrFlag(a.Flags), bgp.BGPAttrType(a.Type), a.Value), nil
|
||||
}
|
||||
|
||||
27
vendor/github.com/osrg/gobgp/internal/pkg/apiutil/util.go
generated
vendored
27
vendor/github.com/osrg/gobgp/internal/pkg/apiutil/util.go
generated
vendored
@@ -17,9 +17,11 @@ package apiutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
api "github.com/osrg/gobgp/api"
|
||||
"github.com/osrg/gobgp/pkg/packet/bgp"
|
||||
)
|
||||
@@ -49,9 +51,10 @@ func NewDestination(dst *api.Destination) *Destination {
|
||||
for _, p := range dst.Paths {
|
||||
nlri, _ := GetNativeNlri(p)
|
||||
attrs, _ := GetNativePathAttributes(p)
|
||||
t, _ := ptypes.Timestamp(p.Age)
|
||||
l = append(l, &Path{
|
||||
Nlri: nlri,
|
||||
Age: p.Age,
|
||||
Age: t.Unix(),
|
||||
Best: p.Best,
|
||||
Attrs: attrs,
|
||||
Stale: p.Stale,
|
||||
@@ -64,10 +67,11 @@ func NewDestination(dst *api.Destination) *Destination {
|
||||
}
|
||||
|
||||
func NewPath(nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, age time.Time) *api.Path {
|
||||
t, _ := ptypes.TimestampProto(age)
|
||||
return &api.Path{
|
||||
AnyNlri: MarshalNLRI(nlri),
|
||||
AnyPattrs: MarshalPathAttributes(attrs),
|
||||
Age: age.Unix(),
|
||||
Nlri: MarshalNLRI(nlri),
|
||||
Pattrs: MarshalPathAttributes(attrs),
|
||||
Age: t,
|
||||
IsWithdraw: isWithdraw,
|
||||
Family: ToApiFamily(nlri.AFI(), nlri.SAFI()),
|
||||
Identifier: nlri.PathIdentifier(),
|
||||
@@ -87,17 +91,20 @@ func getNLRI(family bgp.RouteFamily, buf []byte) (bgp.AddrPrefixInterface, error
|
||||
}
|
||||
|
||||
func GetNativeNlri(p *api.Path) (bgp.AddrPrefixInterface, error) {
|
||||
if len(p.Nlri) > 0 {
|
||||
return getNLRI(ToRouteFamily(p.Family), p.Nlri)
|
||||
if p.Family == nil {
|
||||
return nil, fmt.Errorf("family cannot be nil")
|
||||
}
|
||||
return UnmarshalNLRI(ToRouteFamily(p.Family), p.AnyNlri)
|
||||
if len(p.NlriBinary) > 0 {
|
||||
return getNLRI(ToRouteFamily(p.Family), p.NlriBinary)
|
||||
}
|
||||
return UnmarshalNLRI(ToRouteFamily(p.Family), p.Nlri)
|
||||
}
|
||||
|
||||
func GetNativePathAttributes(p *api.Path) ([]bgp.PathAttributeInterface, error) {
|
||||
pattrsLen := len(p.Pattrs)
|
||||
pattrsLen := len(p.PattrsBinary)
|
||||
if pattrsLen > 0 {
|
||||
pattrs := make([]bgp.PathAttributeInterface, 0, pattrsLen)
|
||||
for _, attr := range p.Pattrs {
|
||||
for _, attr := range p.PattrsBinary {
|
||||
a, err := bgp.GetPathAttribute(attr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -110,7 +117,7 @@ func GetNativePathAttributes(p *api.Path) ([]bgp.PathAttributeInterface, error)
|
||||
}
|
||||
return pattrs, nil
|
||||
}
|
||||
return UnmarshalPathAttributes(p.AnyPattrs)
|
||||
return UnmarshalPathAttributes(p.Pattrs)
|
||||
}
|
||||
|
||||
func ToRouteFamily(f *api.Family) bgp.RouteFamily {
|
||||
|
||||
428
vendor/github.com/osrg/gobgp/internal/pkg/config/bgp_configs.go
generated
vendored
428
vendor/github.com/osrg/gobgp/internal/pkg/config/bgp_configs.go
generated
vendored
@@ -1,7 +1,7 @@
|
||||
// DO NOT EDIT
|
||||
// generated by pyang using OpenConfig https://github.com/openconfig/public
|
||||
//
|
||||
// Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
|
||||
// Copyright (C) 2014-2019 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Code generated by pyang. DO NOT EDIT.
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
@@ -55,14 +57,6 @@ var RemovePrivateAsOptionToIntMap = map[RemovePrivateAsOption]int{
|
||||
REMOVE_PRIVATE_AS_OPTION_REPLACE: 1,
|
||||
}
|
||||
|
||||
func (v RemovePrivateAsOption) ToInt() int {
|
||||
i, ok := RemovePrivateAsOptionToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToRemovePrivateAsOptionMap = map[int]RemovePrivateAsOption{
|
||||
0: REMOVE_PRIVATE_AS_OPTION_ALL,
|
||||
1: REMOVE_PRIVATE_AS_OPTION_REPLACE,
|
||||
@@ -75,6 +69,14 @@ func (v RemovePrivateAsOption) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v RemovePrivateAsOption) ToInt() int {
|
||||
i, ok := RemovePrivateAsOptionToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for typedef bgp-types:bgp-community-regexp-type.
|
||||
type BgpCommunityRegexpType StdRegexp
|
||||
|
||||
@@ -99,14 +101,6 @@ var CommunityTypeToIntMap = map[CommunityType]int{
|
||||
COMMUNITY_TYPE_NONE: 3,
|
||||
}
|
||||
|
||||
func (v CommunityType) ToInt() int {
|
||||
i, ok := CommunityTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToCommunityTypeMap = map[int]CommunityType{
|
||||
0: COMMUNITY_TYPE_STANDARD,
|
||||
1: COMMUNITY_TYPE_EXTENDED,
|
||||
@@ -121,6 +115,14 @@ func (v CommunityType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v CommunityType) ToInt() int {
|
||||
i, ok := CommunityTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for typedef bgp-types:bgp-ext-community-type.
|
||||
type BgpExtCommunityType string
|
||||
|
||||
@@ -142,14 +144,6 @@ var PeerTypeToIntMap = map[PeerType]int{
|
||||
PEER_TYPE_EXTERNAL: 1,
|
||||
}
|
||||
|
||||
func (v PeerType) ToInt() int {
|
||||
i, ok := PeerTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToPeerTypeMap = map[int]PeerType{
|
||||
0: PEER_TYPE_INTERNAL,
|
||||
1: PEER_TYPE_EXTERNAL,
|
||||
@@ -162,6 +156,14 @@ func (v PeerType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v PeerType) ToInt() int {
|
||||
i, ok := PeerTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp-types:bgp-session-direction.
|
||||
// Type to describe the direction of NLRI transmission.
|
||||
type BgpSessionDirection string
|
||||
@@ -176,14 +178,6 @@ var BgpSessionDirectionToIntMap = map[BgpSessionDirection]int{
|
||||
BGP_SESSION_DIRECTION_OUTBOUND: 1,
|
||||
}
|
||||
|
||||
func (v BgpSessionDirection) ToInt() int {
|
||||
i, ok := BgpSessionDirectionToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToBgpSessionDirectionMap = map[int]BgpSessionDirection{
|
||||
0: BGP_SESSION_DIRECTION_INBOUND,
|
||||
1: BGP_SESSION_DIRECTION_OUTBOUND,
|
||||
@@ -196,6 +190,14 @@ func (v BgpSessionDirection) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v BgpSessionDirection) ToInt() int {
|
||||
i, ok := BgpSessionDirectionToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp-types:bgp-origin-attr-type.
|
||||
// Type definition for standard BGP origin attribute.
|
||||
type BgpOriginAttrType string
|
||||
@@ -212,14 +214,6 @@ var BgpOriginAttrTypeToIntMap = map[BgpOriginAttrType]int{
|
||||
BGP_ORIGIN_ATTR_TYPE_INCOMPLETE: 2,
|
||||
}
|
||||
|
||||
func (v BgpOriginAttrType) ToInt() int {
|
||||
i, ok := BgpOriginAttrTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToBgpOriginAttrTypeMap = map[int]BgpOriginAttrType{
|
||||
0: BGP_ORIGIN_ATTR_TYPE_IGP,
|
||||
1: BGP_ORIGIN_ATTR_TYPE_EGP,
|
||||
@@ -233,6 +227,14 @@ func (v BgpOriginAttrType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v BgpOriginAttrType) ToInt() int {
|
||||
i, ok := BgpOriginAttrTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp-types:afi-safi-type.
|
||||
// Base identity type for AFI,SAFI tuples for BGP-4.
|
||||
type AfiSafiType string
|
||||
@@ -259,6 +261,7 @@ const (
|
||||
AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC AfiSafiType = "l3vpn-ipv6-flowspec"
|
||||
AFI_SAFI_TYPE_L2VPN_FLOWSPEC AfiSafiType = "l2vpn-flowspec"
|
||||
AFI_SAFI_TYPE_OPAQUE AfiSafiType = "opaque"
|
||||
AFI_SAFI_TYPE_LS AfiSafiType = "ls"
|
||||
)
|
||||
|
||||
var AfiSafiTypeToIntMap = map[AfiSafiType]int{
|
||||
@@ -283,14 +286,7 @@ var AfiSafiTypeToIntMap = map[AfiSafiType]int{
|
||||
AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC: 18,
|
||||
AFI_SAFI_TYPE_L2VPN_FLOWSPEC: 19,
|
||||
AFI_SAFI_TYPE_OPAQUE: 20,
|
||||
}
|
||||
|
||||
func (v AfiSafiType) ToInt() int {
|
||||
i, ok := AfiSafiTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
AFI_SAFI_TYPE_LS: 21,
|
||||
}
|
||||
|
||||
var IntToAfiSafiTypeMap = map[int]AfiSafiType{
|
||||
@@ -315,6 +311,7 @@ var IntToAfiSafiTypeMap = map[int]AfiSafiType{
|
||||
18: AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC,
|
||||
19: AFI_SAFI_TYPE_L2VPN_FLOWSPEC,
|
||||
20: AFI_SAFI_TYPE_OPAQUE,
|
||||
21: AFI_SAFI_TYPE_LS,
|
||||
}
|
||||
|
||||
func (v AfiSafiType) Validate() error {
|
||||
@@ -324,6 +321,14 @@ func (v AfiSafiType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v AfiSafiType) ToInt() int {
|
||||
i, ok := AfiSafiTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp-types:bgp-capability.
|
||||
// Base identity for a BGP capability.
|
||||
type BgpCapability string
|
||||
@@ -344,14 +349,6 @@ var BgpCapabilityToIntMap = map[BgpCapability]int{
|
||||
BGP_CAPABILITY_ADD_PATHS: 4,
|
||||
}
|
||||
|
||||
func (v BgpCapability) ToInt() int {
|
||||
i, ok := BgpCapabilityToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToBgpCapabilityMap = map[int]BgpCapability{
|
||||
0: BGP_CAPABILITY_MPBGP,
|
||||
1: BGP_CAPABILITY_ROUTE_REFRESH,
|
||||
@@ -367,6 +364,14 @@ func (v BgpCapability) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v BgpCapability) ToInt() int {
|
||||
i, ok := BgpCapabilityToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp-types:bgp-well-known-std-community.
|
||||
// Reserved communities within the standard community space
|
||||
// defined by RFC1997. These communities must fall within the
|
||||
@@ -387,14 +392,6 @@ var BgpWellKnownStdCommunityToIntMap = map[BgpWellKnownStdCommunity]int{
|
||||
BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER: 3,
|
||||
}
|
||||
|
||||
func (v BgpWellKnownStdCommunity) ToInt() int {
|
||||
i, ok := BgpWellKnownStdCommunityToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToBgpWellKnownStdCommunityMap = map[int]BgpWellKnownStdCommunity{
|
||||
0: BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT,
|
||||
1: BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE,
|
||||
@@ -409,6 +406,14 @@ func (v BgpWellKnownStdCommunity) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v BgpWellKnownStdCommunity) ToInt() int {
|
||||
i, ok := BgpWellKnownStdCommunityToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity ptypes:match-set-options-restricted-type.
|
||||
// Options that govern the behavior of a match statement. The
|
||||
// default behavior is ANY, i.e., the given value matches any
|
||||
@@ -426,14 +431,6 @@ var MatchSetOptionsRestrictedTypeToIntMap = map[MatchSetOptionsRestrictedType]in
|
||||
MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT: 1,
|
||||
}
|
||||
|
||||
func (v MatchSetOptionsRestrictedType) ToInt() int {
|
||||
i, ok := MatchSetOptionsRestrictedTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToMatchSetOptionsRestrictedTypeMap = map[int]MatchSetOptionsRestrictedType{
|
||||
0: MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY,
|
||||
1: MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT,
|
||||
@@ -456,6 +453,14 @@ func (v MatchSetOptionsRestrictedType) DefaultAsNeeded() MatchSetOptionsRestrict
|
||||
}
|
||||
return v
|
||||
}
|
||||
func (v MatchSetOptionsRestrictedType) ToInt() int {
|
||||
_v := v.DefaultAsNeeded()
|
||||
i, ok := MatchSetOptionsRestrictedTypeToIntMap[_v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity ptypes:match-set-options-type.
|
||||
// Options that govern the behavior of a match statement. The
|
||||
@@ -475,14 +480,6 @@ var MatchSetOptionsTypeToIntMap = map[MatchSetOptionsType]int{
|
||||
MATCH_SET_OPTIONS_TYPE_INVERT: 2,
|
||||
}
|
||||
|
||||
func (v MatchSetOptionsType) ToInt() int {
|
||||
i, ok := MatchSetOptionsTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToMatchSetOptionsTypeMap = map[int]MatchSetOptionsType{
|
||||
0: MATCH_SET_OPTIONS_TYPE_ANY,
|
||||
1: MATCH_SET_OPTIONS_TYPE_ALL,
|
||||
@@ -506,6 +503,14 @@ func (v MatchSetOptionsType) DefaultAsNeeded() MatchSetOptionsType {
|
||||
}
|
||||
return v
|
||||
}
|
||||
func (v MatchSetOptionsType) ToInt() int {
|
||||
_v := v.DefaultAsNeeded()
|
||||
i, ok := MatchSetOptionsTypeToIntMap[_v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for typedef ptypes:tag-type.
|
||||
type TagType string
|
||||
@@ -535,14 +540,6 @@ var InstallProtocolTypeToIntMap = map[InstallProtocolType]int{
|
||||
INSTALL_PROTOCOL_TYPE_LOCAL_AGGREGATE: 6,
|
||||
}
|
||||
|
||||
func (v InstallProtocolType) ToInt() int {
|
||||
i, ok := InstallProtocolTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToInstallProtocolTypeMap = map[int]InstallProtocolType{
|
||||
0: INSTALL_PROTOCOL_TYPE_BGP,
|
||||
1: INSTALL_PROTOCOL_TYPE_ISIS,
|
||||
@@ -560,6 +557,14 @@ func (v InstallProtocolType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v InstallProtocolType) ToInt() int {
|
||||
i, ok := InstallProtocolTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity ptypes:attribute-comparison.
|
||||
// base type for supported comparison operators on route
|
||||
// attributes.
|
||||
@@ -583,14 +588,6 @@ var AttributeComparisonToIntMap = map[AttributeComparison]int{
|
||||
ATTRIBUTE_COMPARISON_LE: 5,
|
||||
}
|
||||
|
||||
func (v AttributeComparison) ToInt() int {
|
||||
i, ok := AttributeComparisonToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToAttributeComparisonMap = map[int]AttributeComparison{
|
||||
0: ATTRIBUTE_COMPARISON_ATTRIBUTE_EQ,
|
||||
1: ATTRIBUTE_COMPARISON_ATTRIBUTE_GE,
|
||||
@@ -607,6 +604,14 @@ func (v AttributeComparison) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v AttributeComparison) ToInt() int {
|
||||
i, ok := AttributeComparisonToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity rpol:route-disposition.
|
||||
// Select the final disposition for the route, either
|
||||
// accept or reject.
|
||||
@@ -624,14 +629,6 @@ var RouteDispositionToIntMap = map[RouteDisposition]int{
|
||||
ROUTE_DISPOSITION_REJECT_ROUTE: 2,
|
||||
}
|
||||
|
||||
func (v RouteDisposition) ToInt() int {
|
||||
i, ok := RouteDispositionToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToRouteDispositionMap = map[int]RouteDisposition{
|
||||
0: ROUTE_DISPOSITION_NONE,
|
||||
1: ROUTE_DISPOSITION_ACCEPT_ROUTE,
|
||||
@@ -645,6 +642,14 @@ func (v RouteDisposition) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v RouteDisposition) ToInt() int {
|
||||
i, ok := RouteDispositionToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity rpol:route-type.
|
||||
// Condition to check the route type in the route update.
|
||||
type RouteType string
|
||||
@@ -663,14 +668,6 @@ var RouteTypeToIntMap = map[RouteType]int{
|
||||
ROUTE_TYPE_LOCAL: 3,
|
||||
}
|
||||
|
||||
func (v RouteType) ToInt() int {
|
||||
i, ok := RouteTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToRouteTypeMap = map[int]RouteType{
|
||||
0: ROUTE_TYPE_NONE,
|
||||
1: ROUTE_TYPE_INTERNAL,
|
||||
@@ -685,6 +682,14 @@ func (v RouteType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v RouteType) ToInt() int {
|
||||
i, ok := RouteTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity rpol:default-policy-type.
|
||||
// type used to specify default route disposition in
|
||||
// a policy chain.
|
||||
@@ -700,14 +705,6 @@ var DefaultPolicyTypeToIntMap = map[DefaultPolicyType]int{
|
||||
DEFAULT_POLICY_TYPE_REJECT_ROUTE: 1,
|
||||
}
|
||||
|
||||
func (v DefaultPolicyType) ToInt() int {
|
||||
i, ok := DefaultPolicyTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToDefaultPolicyTypeMap = map[int]DefaultPolicyType{
|
||||
0: DEFAULT_POLICY_TYPE_ACCEPT_ROUTE,
|
||||
1: DEFAULT_POLICY_TYPE_REJECT_ROUTE,
|
||||
@@ -720,6 +717,14 @@ func (v DefaultPolicyType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v DefaultPolicyType) ToInt() int {
|
||||
i, ok := DefaultPolicyTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp:session-state.
|
||||
// Operational state of the BGP peer.
|
||||
type SessionState string
|
||||
@@ -742,14 +747,6 @@ var SessionStateToIntMap = map[SessionState]int{
|
||||
SESSION_STATE_ESTABLISHED: 5,
|
||||
}
|
||||
|
||||
func (v SessionState) ToInt() int {
|
||||
i, ok := SessionStateToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToSessionStateMap = map[int]SessionState{
|
||||
0: SESSION_STATE_IDLE,
|
||||
1: SESSION_STATE_CONNECT,
|
||||
@@ -766,6 +763,14 @@ func (v SessionState) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v SessionState) ToInt() int {
|
||||
i, ok := SessionStateToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp:admin-state.
|
||||
type AdminState string
|
||||
|
||||
@@ -781,14 +786,6 @@ var AdminStateToIntMap = map[AdminState]int{
|
||||
ADMIN_STATE_PFX_CT: 2,
|
||||
}
|
||||
|
||||
func (v AdminState) ToInt() int {
|
||||
i, ok := AdminStateToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToAdminStateMap = map[int]AdminState{
|
||||
0: ADMIN_STATE_UP,
|
||||
1: ADMIN_STATE_DOWN,
|
||||
@@ -802,6 +799,14 @@ func (v AdminState) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v AdminState) ToInt() int {
|
||||
i, ok := AdminStateToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity bgp:mode.
|
||||
// Ths leaf indicates the mode of operation of BGP graceful
|
||||
// restart with the peer.
|
||||
@@ -819,14 +824,6 @@ var ModeToIntMap = map[Mode]int{
|
||||
MODE_REMOTE_HELPER: 2,
|
||||
}
|
||||
|
||||
func (v Mode) ToInt() int {
|
||||
i, ok := ModeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToModeMap = map[int]Mode{
|
||||
0: MODE_HELPER_ONLY,
|
||||
1: MODE_BILATERAL,
|
||||
@@ -840,6 +837,14 @@ func (v Mode) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v Mode) ToInt() int {
|
||||
i, ok := ModeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for typedef bgp-pol:bgp-next-hop-type.
|
||||
type BgpNextHopType string
|
||||
|
||||
@@ -866,14 +871,6 @@ var BgpSetCommunityOptionTypeToIntMap = map[BgpSetCommunityOptionType]int{
|
||||
BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE: 2,
|
||||
}
|
||||
|
||||
func (v BgpSetCommunityOptionType) ToInt() int {
|
||||
i, ok := BgpSetCommunityOptionTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToBgpSetCommunityOptionTypeMap = map[int]BgpSetCommunityOptionType{
|
||||
0: BGP_SET_COMMUNITY_OPTION_TYPE_ADD,
|
||||
1: BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE,
|
||||
@@ -887,6 +884,14 @@ func (v BgpSetCommunityOptionType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v BgpSetCommunityOptionType) ToInt() int {
|
||||
i, ok := BgpSetCommunityOptionTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity gobgp:bmp-route-monitoring-policy-type.
|
||||
type BmpRouteMonitoringPolicyType string
|
||||
|
||||
@@ -906,14 +911,6 @@ var BmpRouteMonitoringPolicyTypeToIntMap = map[BmpRouteMonitoringPolicyType]int{
|
||||
BMP_ROUTE_MONITORING_POLICY_TYPE_ALL: 4,
|
||||
}
|
||||
|
||||
func (v BmpRouteMonitoringPolicyType) ToInt() int {
|
||||
i, ok := BmpRouteMonitoringPolicyTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToBmpRouteMonitoringPolicyTypeMap = map[int]BmpRouteMonitoringPolicyType{
|
||||
0: BMP_ROUTE_MONITORING_POLICY_TYPE_PRE_POLICY,
|
||||
1: BMP_ROUTE_MONITORING_POLICY_TYPE_POST_POLICY,
|
||||
@@ -929,6 +926,14 @@ func (v BmpRouteMonitoringPolicyType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v BmpRouteMonitoringPolicyType) ToInt() int {
|
||||
i, ok := BmpRouteMonitoringPolicyTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity gobgp:mrt-type.
|
||||
type MrtType string
|
||||
|
||||
@@ -942,14 +947,6 @@ var MrtTypeToIntMap = map[MrtType]int{
|
||||
MRT_TYPE_TABLE: 1,
|
||||
}
|
||||
|
||||
func (v MrtType) ToInt() int {
|
||||
i, ok := MrtTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToMrtTypeMap = map[int]MrtType{
|
||||
0: MRT_TYPE_UPDATES,
|
||||
1: MRT_TYPE_TABLE,
|
||||
@@ -962,6 +959,14 @@ func (v MrtType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v MrtType) ToInt() int {
|
||||
i, ok := MrtTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// typedef for identity gobgp:rpki-validation-result-type.
|
||||
// indicate the validation result of RPKI based on ROA.
|
||||
type RpkiValidationResultType string
|
||||
@@ -980,14 +985,6 @@ var RpkiValidationResultTypeToIntMap = map[RpkiValidationResultType]int{
|
||||
RPKI_VALIDATION_RESULT_TYPE_INVALID: 3,
|
||||
}
|
||||
|
||||
func (v RpkiValidationResultType) ToInt() int {
|
||||
i, ok := RpkiValidationResultTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
var IntToRpkiValidationResultTypeMap = map[int]RpkiValidationResultType{
|
||||
0: RPKI_VALIDATION_RESULT_TYPE_NONE,
|
||||
1: RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND,
|
||||
@@ -1002,6 +999,14 @@ func (v RpkiValidationResultType) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v RpkiValidationResultType) ToInt() int {
|
||||
i, ok := RpkiValidationResultTypeToIntMap[v]
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// struct for container gobgp:state.
|
||||
type DynamicNeighborState struct {
|
||||
// original -> gobgp:prefix
|
||||
@@ -1116,13 +1121,22 @@ type ZebraState struct {
|
||||
// original -> gobgp:redistribute-route-type
|
||||
RedistributeRouteTypeList []string `mapstructure:"redistribute-route-type-list" json:"redistribute-route-type-list,omitempty"`
|
||||
// original -> gobgp:version
|
||||
// Configure version of zebra protocol. Default is 2. Supported up to 3.
|
||||
// Configure version of zebra protocol. Default is 2.
|
||||
// Supported version are 2 or 3 for Quagga and 4, 5 or 6 for FRRouting.
|
||||
Version uint8 `mapstructure:"version" json:"version,omitempty"`
|
||||
// original -> gobgp:nexthop-trigger-enable
|
||||
// gobgp:nexthop-trigger-enable's original type is boolean.
|
||||
NexthopTriggerEnable bool `mapstructure:"nexthop-trigger-enable" json:"nexthop-trigger-enable,omitempty"`
|
||||
// original -> gobgp:nexthop-trigger-delay
|
||||
NexthopTriggerDelay uint8 `mapstructure:"nexthop-trigger-delay" json:"nexthop-trigger-delay,omitempty"`
|
||||
// original -> gobgp:mpls-label-range-size
|
||||
// Configure MPLS label range size which will be requested to
|
||||
// FRR/Zebra.
|
||||
MplsLabelRangeSize uint32 `mapstructure:"mpls-label-range-size" json:"mpls-label-range-size,omitempty"`
|
||||
// original -> gobgp:software-name
|
||||
// Configure zebra software name.
|
||||
// quagga, frr3, frr4, frr5, frr6, frr7 can be used.
|
||||
SoftwareName string `mapstructure:"software-name" json:"software-name,omitempty"`
|
||||
}
|
||||
|
||||
// struct for container gobgp:config.
|
||||
@@ -1137,13 +1151,22 @@ type ZebraConfig struct {
|
||||
// original -> gobgp:redistribute-route-type
|
||||
RedistributeRouteTypeList []string `mapstructure:"redistribute-route-type-list" json:"redistribute-route-type-list,omitempty"`
|
||||
// original -> gobgp:version
|
||||
// Configure version of zebra protocol. Default is 2. Supported up to 3.
|
||||
// Configure version of zebra protocol. Default is 2.
|
||||
// Supported version are 2 or 3 for Quagga and 4, 5 or 6 for FRRouting.
|
||||
Version uint8 `mapstructure:"version" json:"version,omitempty"`
|
||||
// original -> gobgp:nexthop-trigger-enable
|
||||
// gobgp:nexthop-trigger-enable's original type is boolean.
|
||||
NexthopTriggerEnable bool `mapstructure:"nexthop-trigger-enable" json:"nexthop-trigger-enable,omitempty"`
|
||||
// original -> gobgp:nexthop-trigger-delay
|
||||
NexthopTriggerDelay uint8 `mapstructure:"nexthop-trigger-delay" json:"nexthop-trigger-delay,omitempty"`
|
||||
// original -> gobgp:mpls-label-range-size
|
||||
// Configure MPLS label range size which will be requested to
|
||||
// FRR/Zebra.
|
||||
MplsLabelRangeSize uint32 `mapstructure:"mpls-label-range-size" json:"mpls-label-range-size,omitempty"`
|
||||
// original -> gobgp:software-name
|
||||
// Configure zebra software name.
|
||||
// quagga, frr3, frr4, frr5, frr6, frr7 can be used.
|
||||
SoftwareName string `mapstructure:"software-name" json:"software-name,omitempty"`
|
||||
}
|
||||
|
||||
func (lhs *ZebraConfig) Equal(rhs *ZebraConfig) bool {
|
||||
@@ -1173,6 +1196,12 @@ func (lhs *ZebraConfig) Equal(rhs *ZebraConfig) bool {
|
||||
if lhs.NexthopTriggerDelay != rhs.NexthopTriggerDelay {
|
||||
return false
|
||||
}
|
||||
if lhs.MplsLabelRangeSize != rhs.MplsLabelRangeSize {
|
||||
return false
|
||||
}
|
||||
if lhs.SoftwareName != rhs.SoftwareName {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1376,6 +1405,12 @@ type BmpServerState struct {
|
||||
// Enable feature for mirroring of received BGP messages
|
||||
// mainly for debugging purpose.
|
||||
RouteMirroringEnabled bool `mapstructure:"route-mirroring-enabled" json:"route-mirroring-enabled,omitempty"`
|
||||
// original -> gobgp:sys-name
|
||||
// Reference to the SysName of the BMP server.
|
||||
SysName string `mapstructure:"sys-name" json:"sys-name,omitempty"`
|
||||
// original -> gobgp:sys-descr
|
||||
// Reference to the SysDescr of the BMP server.
|
||||
SysDescr string `mapstructure:"sys-descr" json:"sys-descr,omitempty"`
|
||||
}
|
||||
|
||||
// struct for container gobgp:config.
|
||||
@@ -1399,6 +1434,12 @@ type BmpServerConfig struct {
|
||||
// Enable feature for mirroring of received BGP messages
|
||||
// mainly for debugging purpose.
|
||||
RouteMirroringEnabled bool `mapstructure:"route-mirroring-enabled" json:"route-mirroring-enabled,omitempty"`
|
||||
// original -> gobgp:sys-name
|
||||
// Reference to the SysName of the BMP server.
|
||||
SysName string `mapstructure:"sys-name" json:"sys-name,omitempty"`
|
||||
// original -> gobgp:sys-descr
|
||||
// Reference to the SysDescr of the BMP server.
|
||||
SysDescr string `mapstructure:"sys-descr" json:"sys-descr,omitempty"`
|
||||
}
|
||||
|
||||
func (lhs *BmpServerConfig) Equal(rhs *BmpServerConfig) bool {
|
||||
@@ -1420,6 +1461,12 @@ func (lhs *BmpServerConfig) Equal(rhs *BmpServerConfig) bool {
|
||||
if lhs.RouteMirroringEnabled != rhs.RouteMirroringEnabled {
|
||||
return false
|
||||
}
|
||||
if lhs.SysName != rhs.SysName {
|
||||
return false
|
||||
}
|
||||
if lhs.SysDescr != rhs.SysDescr {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1984,6 +2031,12 @@ type RouteServerState struct {
|
||||
// gobgp:route-server-client's original type is boolean.
|
||||
// Configure the neighbor as a route server client.
|
||||
RouteServerClient bool `mapstructure:"route-server-client" json:"route-server-client,omitempty"`
|
||||
// original -> gobgp:secondary-route
|
||||
// gobgp:secondary-route's original type is boolean.
|
||||
// if an export policy rejects a selected route, try the next route in
|
||||
// order until one that is accepted is found or all routes for the peer
|
||||
// are rejected.
|
||||
SecondaryRoute bool `mapstructure:"secondary-route" json:"secondary-route,omitempty"`
|
||||
}
|
||||
|
||||
// struct for container gobgp:config.
|
||||
@@ -1994,6 +2047,12 @@ type RouteServerConfig struct {
|
||||
// gobgp:route-server-client's original type is boolean.
|
||||
// Configure the neighbor as a route server client.
|
||||
RouteServerClient bool `mapstructure:"route-server-client" json:"route-server-client,omitempty"`
|
||||
// original -> gobgp:secondary-route
|
||||
// gobgp:secondary-route's original type is boolean.
|
||||
// if an export policy rejects a selected route, try the next route in
|
||||
// order until one that is accepted is found or all routes for the peer
|
||||
// are rejected.
|
||||
SecondaryRoute bool `mapstructure:"secondary-route" json:"secondary-route,omitempty"`
|
||||
}
|
||||
|
||||
func (lhs *RouteServerConfig) Equal(rhs *RouteServerConfig) bool {
|
||||
@@ -2003,6 +2062,9 @@ func (lhs *RouteServerConfig) Equal(rhs *RouteServerConfig) bool {
|
||||
if lhs.RouteServerClient != rhs.RouteServerClient {
|
||||
return false
|
||||
}
|
||||
if lhs.SecondaryRoute != rhs.SecondaryRoute {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -2518,6 +2580,9 @@ type TransportConfig struct {
|
||||
// original -> gobgp:ttl
|
||||
// TTL value for BGP packets.
|
||||
Ttl uint8 `mapstructure:"ttl" json:"ttl,omitempty"`
|
||||
// original -> gobgp:bind-interface
|
||||
// Interface name for binding.
|
||||
BindInterface string `mapstructure:"bind-interface" json:"bind-interface,omitempty"`
|
||||
}
|
||||
|
||||
func (lhs *TransportConfig) Equal(rhs *TransportConfig) bool {
|
||||
@@ -2542,6 +2607,9 @@ func (lhs *TransportConfig) Equal(rhs *TransportConfig) bool {
|
||||
if lhs.Ttl != rhs.Ttl {
|
||||
return false
|
||||
}
|
||||
if lhs.BindInterface != rhs.BindInterface {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -2620,7 +2688,7 @@ type TimersState struct {
|
||||
// BGP last transitioned out of the Established state.
|
||||
Downtime int64 `mapstructure:"downtime" json:"downtime,omitempty"`
|
||||
// original -> gobgp:update-recv-time
|
||||
// The number of seconds elasped since January 1, 1970 UTC
|
||||
// The number of seconds elapsed since January 1, 1970 UTC
|
||||
// last time the BGP session received an UPDATE message.
|
||||
UpdateRecvTime int64 `mapstructure:"update-recv-time" json:"update-recv-time,omitempty"`
|
||||
}
|
||||
|
||||
31
vendor/github.com/osrg/gobgp/internal/pkg/config/default.go
generated
vendored
31
vendor/github.com/osrg/gobgp/internal/pkg/config/default.go
generated
vendored
@@ -8,6 +8,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"github.com/osrg/gobgp/internal/pkg/zebra"
|
||||
"github.com/osrg/gobgp/pkg/packet/bgp"
|
||||
"github.com/osrg/gobgp/pkg/packet/bmp"
|
||||
"github.com/osrg/gobgp/pkg/packet/rtr"
|
||||
@@ -197,11 +198,15 @@ func setDefaultNeighborConfigValuesWithViper(v *viper.Viper, n *Neighbor, g *Glo
|
||||
}
|
||||
n.AfiSafis[i].MpGracefulRestart.State.Enabled = n.AfiSafis[i].MpGracefulRestart.Config.Enabled
|
||||
if !vv.IsSet("afi-safi.add-paths.config.receive") {
|
||||
n.AfiSafis[i].AddPaths.Config.Receive = n.AddPaths.Config.Receive
|
||||
if n.AddPaths.Config.Receive {
|
||||
n.AfiSafis[i].AddPaths.Config.Receive = n.AddPaths.Config.Receive
|
||||
}
|
||||
}
|
||||
n.AfiSafis[i].AddPaths.State.Receive = n.AfiSafis[i].AddPaths.Config.Receive
|
||||
if !vv.IsSet("afi-safi.add-paths.config.send-max") {
|
||||
n.AfiSafis[i].AddPaths.Config.SendMax = n.AddPaths.Config.SendMax
|
||||
if n.AddPaths.Config.SendMax != 0 {
|
||||
n.AfiSafis[i].AddPaths.Config.SendMax = n.AddPaths.Config.SendMax
|
||||
}
|
||||
}
|
||||
n.AfiSafis[i].AddPaths.State.SendMax = n.AfiSafis[i].AddPaths.Config.SendMax
|
||||
}
|
||||
@@ -344,7 +349,14 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error {
|
||||
return err
|
||||
}
|
||||
|
||||
bmpSysPrefix := "Gobgp-R"
|
||||
for idx, server := range b.BmpServers {
|
||||
if server.Config.SysName == "" {
|
||||
server.Config.SysName = bmpSysPrefix + strconv.Itoa(idx)
|
||||
}
|
||||
if server.Config.SysDescr == "" {
|
||||
server.Config.SysDescr = "Gobgp Version: master"
|
||||
}
|
||||
if server.Config.Port == 0 {
|
||||
server.Config.Port = bmp.BMP_DEFAULT_PORT
|
||||
}
|
||||
@@ -396,11 +408,12 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error {
|
||||
if b.Zebra.Config.Url == "" {
|
||||
b.Zebra.Config.Url = "unix:/var/run/quagga/zserv.api"
|
||||
}
|
||||
if b.Zebra.Config.Version < 2 {
|
||||
b.Zebra.Config.Version = 2
|
||||
} else if b.Zebra.Config.Version > 5 {
|
||||
b.Zebra.Config.Version = 5
|
||||
if b.Zebra.Config.Version < zebra.MinZapiVer {
|
||||
b.Zebra.Config.Version = zebra.MinZapiVer
|
||||
} else if b.Zebra.Config.Version > zebra.MaxZapiVer {
|
||||
b.Zebra.Config.Version = zebra.MaxZapiVer
|
||||
}
|
||||
|
||||
if !v.IsSet("zebra.config.nexthop-trigger-enable") && !b.Zebra.Config.NexthopTriggerEnable && b.Zebra.Config.Version > 2 {
|
||||
b.Zebra.Config.NexthopTriggerEnable = true
|
||||
}
|
||||
@@ -408,6 +421,10 @@ func setDefaultConfigValuesWithViper(v *viper.Viper, b *BgpConfigSet) error {
|
||||
b.Zebra.Config.NexthopTriggerDelay = 5
|
||||
}
|
||||
|
||||
if !zebra.IsAllowableSoftwareName(b.Zebra.Config.Version, b.Zebra.Config.SoftwareName) {
|
||||
b.Zebra.Config.SoftwareName = ""
|
||||
}
|
||||
|
||||
list, err := extractArray(v.Get("neighbors"))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -495,7 +512,7 @@ func OverwriteNeighborConfigWithPeerGroup(c *Neighbor, pg *PeerGroup) error {
|
||||
overwriteConfig(&c.TtlSecurity.Config, &pg.TtlSecurity.Config, "neighbor.ttl-security.config", v)
|
||||
|
||||
if !v.IsSet("neighbor.afi-safis") {
|
||||
c.AfiSafis = append(c.AfiSafis, pg.AfiSafis...)
|
||||
c.AfiSafis = append([]AfiSafi{}, pg.AfiSafis...)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
64
vendor/github.com/osrg/gobgp/internal/pkg/config/serve.go
generated
vendored
64
vendor/github.com/osrg/gobgp/internal/pkg/config/serve.go
generated
vendored
@@ -1,10 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -24,55 +20,25 @@ type BgpConfigSet struct {
|
||||
DynamicNeighbors []DynamicNeighbor `mapstructure:"dynamic-neighbors"`
|
||||
}
|
||||
|
||||
func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) {
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGHUP)
|
||||
|
||||
func ReadConfigfile(path, format string) (*BgpConfigSet, error) {
|
||||
// Update config file type, if detectable
|
||||
format = detectConfigFileType(path, format)
|
||||
|
||||
cnt := 0
|
||||
for {
|
||||
c := &BgpConfigSet{}
|
||||
v := viper.New()
|
||||
v.SetConfigFile(path)
|
||||
v.SetConfigType(format)
|
||||
var err error
|
||||
if err = v.ReadInConfig(); err != nil {
|
||||
goto ERROR
|
||||
}
|
||||
if err = v.UnmarshalExact(c); err != nil {
|
||||
goto ERROR
|
||||
}
|
||||
if err = setDefaultConfigValuesWithViper(v, c); err != nil {
|
||||
goto ERROR
|
||||
}
|
||||
if cnt == 0 {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Config",
|
||||
}).Info("Finished reading the config file")
|
||||
}
|
||||
cnt++
|
||||
configCh <- c
|
||||
goto NEXT
|
||||
ERROR:
|
||||
if cnt == 0 {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Config",
|
||||
"Error": err,
|
||||
}).Fatalf("Can't read config file %s", path)
|
||||
} else {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Config",
|
||||
"Error": err,
|
||||
}).Warningf("Can't read config file %s", path)
|
||||
}
|
||||
NEXT:
|
||||
<-sigCh
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Config",
|
||||
}).Info("Reload the config file")
|
||||
config := &BgpConfigSet{}
|
||||
v := viper.New()
|
||||
v.SetConfigFile(path)
|
||||
v.SetConfigType(format)
|
||||
var err error
|
||||
if err = v.ReadInConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = v.UnmarshalExact(config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = setDefaultConfigValuesWithViper(v, config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func ConfigSetToRoutingPolicy(c *BgpConfigSet) *RoutingPolicy {
|
||||
|
||||
482
vendor/github.com/osrg/gobgp/internal/pkg/config/util.go
generated
vendored
482
vendor/github.com/osrg/gobgp/internal/pkg/config/util.go
generated
vendored
@@ -21,7 +21,13 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
api "github.com/osrg/gobgp/api"
|
||||
"github.com/osrg/gobgp/internal/pkg/apiutil"
|
||||
"github.com/osrg/gobgp/pkg/packet/bgp"
|
||||
)
|
||||
|
||||
@@ -203,12 +209,12 @@ func isAfiSafiChanged(x, y []AfiSafi) bool {
|
||||
if len(x) != len(y) {
|
||||
return true
|
||||
}
|
||||
m := make(map[string]bool)
|
||||
for _, e := range x {
|
||||
m[string(e.Config.AfiSafiName)] = true
|
||||
m := make(map[string]AfiSafi)
|
||||
for i, e := range x {
|
||||
m[string(e.Config.AfiSafiName)] = x[i]
|
||||
}
|
||||
for _, e := range y {
|
||||
if !m[string(e.Config.AfiSafiName)] {
|
||||
if v, ok := m[string(e.Config.AfiSafiName)]; !ok || !v.Config.Equal(&e.Config) || !v.AddPaths.Config.Equal(&e.AddPaths.Config) || !v.MpGracefulRestart.Config.Equal(&e.MpGracefulRestart.Config) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -219,6 +225,7 @@ func (n *Neighbor) NeedsResendOpenMessage(new *Neighbor) bool {
|
||||
return !n.Config.Equal(&new.Config) ||
|
||||
!n.Transport.Config.Equal(&new.Transport.Config) ||
|
||||
!n.AddPaths.Config.Equal(&new.AddPaths.Config) ||
|
||||
!n.AsPathOptions.Config.Equal(&new.AsPathOptions.Config) ||
|
||||
!n.GracefulRestart.Config.Equal(&new.GracefulRestart.Config) ||
|
||||
isAfiSafiChanged(n.AfiSafis, new.AfiSafis)
|
||||
}
|
||||
@@ -262,3 +269,470 @@ func ParseMaskLength(prefix, mask string) (int, int, error) {
|
||||
}
|
||||
return int(min), int(max), nil
|
||||
}
|
||||
|
||||
func extractFamilyFromConfigAfiSafi(c *AfiSafi) uint32 {
|
||||
if c == nil {
|
||||
return 0
|
||||
}
|
||||
// If address family value is already stored in AfiSafiState structure,
|
||||
// we prefer to use this value.
|
||||
if c.State.Family != 0 {
|
||||
return uint32(c.State.Family)
|
||||
}
|
||||
// In case that Neighbor structure came from CLI or gRPC, address family
|
||||
// value in AfiSafiState structure can be omitted.
|
||||
// Here extracts value from AfiSafiName field in AfiSafiConfig structure.
|
||||
if rf, err := bgp.GetRouteFamily(string(c.Config.AfiSafiName)); err == nil {
|
||||
return uint32(rf)
|
||||
}
|
||||
// Ignores invalid address family name
|
||||
return 0
|
||||
}
|
||||
|
||||
func newAfiSafiConfigFromConfigStruct(c *AfiSafi) *api.AfiSafiConfig {
|
||||
rf := extractFamilyFromConfigAfiSafi(c)
|
||||
afi, safi := bgp.RouteFamilyToAfiSafi(bgp.RouteFamily(rf))
|
||||
return &api.AfiSafiConfig{
|
||||
Family: &api.Family{Afi: api.Family_Afi(afi), Safi: api.Family_Safi(safi)},
|
||||
Enabled: c.Config.Enabled,
|
||||
}
|
||||
}
|
||||
|
||||
func newApplyPolicyFromConfigStruct(c *ApplyPolicy) *api.ApplyPolicy {
|
||||
applyPolicy := &api.ApplyPolicy{
|
||||
ImportPolicy: &api.PolicyAssignment{
|
||||
Direction: api.PolicyDirection_IMPORT,
|
||||
DefaultAction: api.RouteAction(c.Config.DefaultImportPolicy.ToInt()),
|
||||
},
|
||||
ExportPolicy: &api.PolicyAssignment{
|
||||
Direction: api.PolicyDirection_EXPORT,
|
||||
DefaultAction: api.RouteAction(c.Config.DefaultExportPolicy.ToInt()),
|
||||
},
|
||||
}
|
||||
|
||||
for _, pname := range c.Config.ImportPolicyList {
|
||||
applyPolicy.ImportPolicy.Policies = append(applyPolicy.ImportPolicy.Policies, &api.Policy{Name: pname})
|
||||
}
|
||||
for _, pname := range c.Config.ExportPolicyList {
|
||||
applyPolicy.ExportPolicy.Policies = append(applyPolicy.ExportPolicy.Policies, &api.Policy{Name: pname})
|
||||
}
|
||||
|
||||
return applyPolicy
|
||||
}
|
||||
|
||||
func newPrefixLimitFromConfigStruct(c *AfiSafi) *api.PrefixLimit {
|
||||
if c.PrefixLimit.Config.MaxPrefixes == 0 {
|
||||
return nil
|
||||
}
|
||||
afi, safi := bgp.RouteFamilyToAfiSafi(bgp.RouteFamily(c.State.Family))
|
||||
return &api.PrefixLimit{
|
||||
Family: &api.Family{Afi: api.Family_Afi(afi), Safi: api.Family_Safi(safi)},
|
||||
MaxPrefixes: c.PrefixLimit.Config.MaxPrefixes,
|
||||
ShutdownThresholdPct: uint32(c.PrefixLimit.Config.ShutdownThresholdPct),
|
||||
}
|
||||
}
|
||||
|
||||
func newRouteTargetMembershipFromConfigStruct(c *RouteTargetMembership) *api.RouteTargetMembership {
|
||||
return &api.RouteTargetMembership{
|
||||
Config: &api.RouteTargetMembershipConfig{
|
||||
DeferralTime: uint32(c.Config.DeferralTime),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newLongLivedGracefulRestartFromConfigStruct(c *LongLivedGracefulRestart) *api.LongLivedGracefulRestart {
|
||||
return &api.LongLivedGracefulRestart{
|
||||
Config: &api.LongLivedGracefulRestartConfig{
|
||||
Enabled: c.Config.Enabled,
|
||||
RestartTime: c.Config.RestartTime,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newAddPathsFromConfigStruct(c *AddPaths) *api.AddPaths {
|
||||
return &api.AddPaths{
|
||||
Config: &api.AddPathsConfig{
|
||||
Receive: c.Config.Receive,
|
||||
SendMax: uint32(c.Config.SendMax),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newRouteSelectionOptionsFromConfigStruct(c *RouteSelectionOptions) *api.RouteSelectionOptions {
|
||||
return &api.RouteSelectionOptions{
|
||||
Config: &api.RouteSelectionOptionsConfig{
|
||||
AlwaysCompareMed: c.Config.AlwaysCompareMed,
|
||||
IgnoreAsPathLength: c.Config.IgnoreAsPathLength,
|
||||
ExternalCompareRouterId: c.Config.ExternalCompareRouterId,
|
||||
AdvertiseInactiveRoutes: c.Config.AdvertiseInactiveRoutes,
|
||||
EnableAigp: c.Config.EnableAigp,
|
||||
IgnoreNextHopIgpMetric: c.Config.IgnoreNextHopIgpMetric,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newMpGracefulRestartFromConfigStruct(c *MpGracefulRestart) *api.MpGracefulRestart {
|
||||
return &api.MpGracefulRestart{
|
||||
Config: &api.MpGracefulRestartConfig{
|
||||
Enabled: c.Config.Enabled,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newUseMultiplePathsFromConfigStruct(c *UseMultiplePaths) *api.UseMultiplePaths {
|
||||
return &api.UseMultiplePaths{
|
||||
Config: &api.UseMultiplePathsConfig{
|
||||
Enabled: c.Config.Enabled,
|
||||
},
|
||||
Ebgp: &api.Ebgp{
|
||||
Config: &api.EbgpConfig{
|
||||
AllowMultipleAs: c.Ebgp.Config.AllowMultipleAs,
|
||||
MaximumPaths: c.Ebgp.Config.MaximumPaths,
|
||||
},
|
||||
},
|
||||
Ibgp: &api.Ibgp{
|
||||
Config: &api.IbgpConfig{
|
||||
MaximumPaths: c.Ibgp.Config.MaximumPaths,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func newAfiSafiFromConfigStruct(c *AfiSafi) *api.AfiSafi {
|
||||
return &api.AfiSafi{
|
||||
MpGracefulRestart: newMpGracefulRestartFromConfigStruct(&c.MpGracefulRestart),
|
||||
Config: newAfiSafiConfigFromConfigStruct(c),
|
||||
ApplyPolicy: newApplyPolicyFromConfigStruct(&c.ApplyPolicy),
|
||||
RouteSelectionOptions: newRouteSelectionOptionsFromConfigStruct(&c.RouteSelectionOptions),
|
||||
UseMultiplePaths: newUseMultiplePathsFromConfigStruct(&c.UseMultiplePaths),
|
||||
PrefixLimits: newPrefixLimitFromConfigStruct(c),
|
||||
RouteTargetMembership: newRouteTargetMembershipFromConfigStruct(&c.RouteTargetMembership),
|
||||
LongLivedGracefulRestart: newLongLivedGracefulRestartFromConfigStruct(&c.LongLivedGracefulRestart),
|
||||
AddPaths: newAddPathsFromConfigStruct(&c.AddPaths),
|
||||
}
|
||||
}
|
||||
|
||||
func ProtoTimestamp(secs int64) *timestamp.Timestamp {
|
||||
if secs == 0 {
|
||||
return nil
|
||||
}
|
||||
t, _ := ptypes.TimestampProto(time.Unix(secs, 0))
|
||||
return t
|
||||
}
|
||||
|
||||
func NewPeerFromConfigStruct(pconf *Neighbor) *api.Peer {
|
||||
afiSafis := make([]*api.AfiSafi, 0, len(pconf.AfiSafis))
|
||||
for _, f := range pconf.AfiSafis {
|
||||
if afiSafi := newAfiSafiFromConfigStruct(&f); afiSafi != nil {
|
||||
afiSafis = append(afiSafis, afiSafi)
|
||||
}
|
||||
}
|
||||
|
||||
timer := pconf.Timers
|
||||
s := pconf.State
|
||||
localAddress := pconf.Transport.Config.LocalAddress
|
||||
if pconf.Transport.State.LocalAddress != "" {
|
||||
localAddress = pconf.Transport.State.LocalAddress
|
||||
}
|
||||
remoteCap, err := apiutil.MarshalCapabilities(pconf.State.RemoteCapabilityList)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
localCap, err := apiutil.MarshalCapabilities(pconf.State.LocalCapabilityList)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var removePrivateAs api.PeerConf_RemovePrivateAs
|
||||
switch pconf.Config.RemovePrivateAs {
|
||||
case REMOVE_PRIVATE_AS_OPTION_ALL:
|
||||
removePrivateAs = api.PeerConf_ALL
|
||||
case REMOVE_PRIVATE_AS_OPTION_REPLACE:
|
||||
removePrivateAs = api.PeerConf_REPLACE
|
||||
}
|
||||
return &api.Peer{
|
||||
ApplyPolicy: newApplyPolicyFromConfigStruct(&pconf.ApplyPolicy),
|
||||
Conf: &api.PeerConf{
|
||||
NeighborAddress: pconf.Config.NeighborAddress,
|
||||
PeerAs: pconf.Config.PeerAs,
|
||||
LocalAs: pconf.Config.LocalAs,
|
||||
PeerType: uint32(pconf.Config.PeerType.ToInt()),
|
||||
AuthPassword: pconf.Config.AuthPassword,
|
||||
RouteFlapDamping: pconf.Config.RouteFlapDamping,
|
||||
Description: pconf.Config.Description,
|
||||
PeerGroup: pconf.Config.PeerGroup,
|
||||
NeighborInterface: pconf.Config.NeighborInterface,
|
||||
Vrf: pconf.Config.Vrf,
|
||||
AllowOwnAs: uint32(pconf.AsPathOptions.Config.AllowOwnAs),
|
||||
RemovePrivateAs: removePrivateAs,
|
||||
ReplacePeerAs: pconf.AsPathOptions.Config.ReplacePeerAs,
|
||||
AdminDown: pconf.Config.AdminDown,
|
||||
},
|
||||
State: &api.PeerState{
|
||||
SessionState: api.PeerState_SessionState(api.PeerState_SessionState_value[strings.ToUpper(string(s.SessionState))]),
|
||||
AdminState: api.PeerState_AdminState(s.AdminState.ToInt()),
|
||||
Messages: &api.Messages{
|
||||
Received: &api.Message{
|
||||
Notification: s.Messages.Received.Notification,
|
||||
Update: s.Messages.Received.Update,
|
||||
Open: s.Messages.Received.Open,
|
||||
Keepalive: s.Messages.Received.Keepalive,
|
||||
Refresh: s.Messages.Received.Refresh,
|
||||
Discarded: s.Messages.Received.Discarded,
|
||||
Total: s.Messages.Received.Total,
|
||||
WithdrawUpdate: uint64(s.Messages.Received.WithdrawUpdate),
|
||||
WithdrawPrefix: uint64(s.Messages.Received.WithdrawPrefix),
|
||||
},
|
||||
Sent: &api.Message{
|
||||
Notification: s.Messages.Sent.Notification,
|
||||
Update: s.Messages.Sent.Update,
|
||||
Open: s.Messages.Sent.Open,
|
||||
Keepalive: s.Messages.Sent.Keepalive,
|
||||
Refresh: s.Messages.Sent.Refresh,
|
||||
Discarded: s.Messages.Sent.Discarded,
|
||||
Total: s.Messages.Sent.Total,
|
||||
},
|
||||
},
|
||||
PeerAs: s.PeerAs,
|
||||
PeerType: uint32(s.PeerType.ToInt()),
|
||||
NeighborAddress: pconf.State.NeighborAddress,
|
||||
Queues: &api.Queues{},
|
||||
RemoteCap: remoteCap,
|
||||
LocalCap: localCap,
|
||||
RouterId: s.RemoteRouterId,
|
||||
},
|
||||
EbgpMultihop: &api.EbgpMultihop{
|
||||
Enabled: pconf.EbgpMultihop.Config.Enabled,
|
||||
MultihopTtl: uint32(pconf.EbgpMultihop.Config.MultihopTtl),
|
||||
},
|
||||
Timers: &api.Timers{
|
||||
Config: &api.TimersConfig{
|
||||
ConnectRetry: uint64(timer.Config.ConnectRetry),
|
||||
HoldTime: uint64(timer.Config.HoldTime),
|
||||
KeepaliveInterval: uint64(timer.Config.KeepaliveInterval),
|
||||
IdleHoldTimeAfterReset: uint64(timer.Config.IdleHoldTimeAfterReset),
|
||||
},
|
||||
State: &api.TimersState{
|
||||
KeepaliveInterval: uint64(timer.State.KeepaliveInterval),
|
||||
NegotiatedHoldTime: uint64(timer.State.NegotiatedHoldTime),
|
||||
Uptime: ProtoTimestamp(timer.State.Uptime),
|
||||
Downtime: ProtoTimestamp(timer.State.Downtime),
|
||||
},
|
||||
},
|
||||
RouteReflector: &api.RouteReflector{
|
||||
RouteReflectorClient: pconf.RouteReflector.Config.RouteReflectorClient,
|
||||
RouteReflectorClusterId: string(pconf.RouteReflector.State.RouteReflectorClusterId),
|
||||
},
|
||||
RouteServer: &api.RouteServer{
|
||||
RouteServerClient: pconf.RouteServer.Config.RouteServerClient,
|
||||
SecondaryRoute: pconf.RouteServer.Config.SecondaryRoute,
|
||||
},
|
||||
GracefulRestart: &api.GracefulRestart{
|
||||
Enabled: pconf.GracefulRestart.Config.Enabled,
|
||||
RestartTime: uint32(pconf.GracefulRestart.Config.RestartTime),
|
||||
HelperOnly: pconf.GracefulRestart.Config.HelperOnly,
|
||||
DeferralTime: uint32(pconf.GracefulRestart.Config.DeferralTime),
|
||||
NotificationEnabled: pconf.GracefulRestart.Config.NotificationEnabled,
|
||||
LonglivedEnabled: pconf.GracefulRestart.Config.LongLivedEnabled,
|
||||
LocalRestarting: pconf.GracefulRestart.State.LocalRestarting,
|
||||
},
|
||||
Transport: &api.Transport{
|
||||
RemotePort: uint32(pconf.Transport.Config.RemotePort),
|
||||
LocalAddress: localAddress,
|
||||
PassiveMode: pconf.Transport.Config.PassiveMode,
|
||||
BindInterface: pconf.Transport.Config.BindInterface,
|
||||
},
|
||||
AfiSafis: afiSafis,
|
||||
}
|
||||
}
|
||||
|
||||
func NewPeerGroupFromConfigStruct(pconf *PeerGroup) *api.PeerGroup {
|
||||
afiSafis := make([]*api.AfiSafi, 0, len(pconf.AfiSafis))
|
||||
for _, f := range pconf.AfiSafis {
|
||||
if afiSafi := newAfiSafiFromConfigStruct(&f); afiSafi != nil {
|
||||
afiSafis = append(afiSafis, afiSafi)
|
||||
}
|
||||
}
|
||||
|
||||
timer := pconf.Timers
|
||||
s := pconf.State
|
||||
return &api.PeerGroup{
|
||||
ApplyPolicy: newApplyPolicyFromConfigStruct(&pconf.ApplyPolicy),
|
||||
Conf: &api.PeerGroupConf{
|
||||
PeerAs: pconf.Config.PeerAs,
|
||||
LocalAs: pconf.Config.LocalAs,
|
||||
PeerType: uint32(pconf.Config.PeerType.ToInt()),
|
||||
AuthPassword: pconf.Config.AuthPassword,
|
||||
RouteFlapDamping: pconf.Config.RouteFlapDamping,
|
||||
Description: pconf.Config.Description,
|
||||
PeerGroupName: pconf.Config.PeerGroupName,
|
||||
},
|
||||
Info: &api.PeerGroupState{
|
||||
PeerAs: s.PeerAs,
|
||||
PeerType: uint32(s.PeerType.ToInt()),
|
||||
TotalPaths: s.TotalPaths,
|
||||
TotalPrefixes: s.TotalPrefixes,
|
||||
},
|
||||
EbgpMultihop: &api.EbgpMultihop{
|
||||
Enabled: pconf.EbgpMultihop.Config.Enabled,
|
||||
MultihopTtl: uint32(pconf.EbgpMultihop.Config.MultihopTtl),
|
||||
},
|
||||
Timers: &api.Timers{
|
||||
Config: &api.TimersConfig{
|
||||
ConnectRetry: uint64(timer.Config.ConnectRetry),
|
||||
HoldTime: uint64(timer.Config.HoldTime),
|
||||
KeepaliveInterval: uint64(timer.Config.KeepaliveInterval),
|
||||
IdleHoldTimeAfterReset: uint64(timer.Config.IdleHoldTimeAfterReset),
|
||||
},
|
||||
State: &api.TimersState{
|
||||
KeepaliveInterval: uint64(timer.State.KeepaliveInterval),
|
||||
NegotiatedHoldTime: uint64(timer.State.NegotiatedHoldTime),
|
||||
Uptime: ProtoTimestamp(timer.State.Uptime),
|
||||
Downtime: ProtoTimestamp(timer.State.Downtime),
|
||||
},
|
||||
},
|
||||
RouteReflector: &api.RouteReflector{
|
||||
RouteReflectorClient: pconf.RouteReflector.Config.RouteReflectorClient,
|
||||
RouteReflectorClusterId: string(pconf.RouteReflector.Config.RouteReflectorClusterId),
|
||||
},
|
||||
RouteServer: &api.RouteServer{
|
||||
RouteServerClient: pconf.RouteServer.Config.RouteServerClient,
|
||||
SecondaryRoute: pconf.RouteServer.Config.SecondaryRoute,
|
||||
},
|
||||
GracefulRestart: &api.GracefulRestart{
|
||||
Enabled: pconf.GracefulRestart.Config.Enabled,
|
||||
RestartTime: uint32(pconf.GracefulRestart.Config.RestartTime),
|
||||
HelperOnly: pconf.GracefulRestart.Config.HelperOnly,
|
||||
DeferralTime: uint32(pconf.GracefulRestart.Config.DeferralTime),
|
||||
NotificationEnabled: pconf.GracefulRestart.Config.NotificationEnabled,
|
||||
LonglivedEnabled: pconf.GracefulRestart.Config.LongLivedEnabled,
|
||||
LocalRestarting: pconf.GracefulRestart.State.LocalRestarting,
|
||||
},
|
||||
Transport: &api.Transport{
|
||||
RemotePort: uint32(pconf.Transport.Config.RemotePort),
|
||||
LocalAddress: pconf.Transport.Config.LocalAddress,
|
||||
PassiveMode: pconf.Transport.Config.PassiveMode,
|
||||
},
|
||||
AfiSafis: afiSafis,
|
||||
}
|
||||
}
|
||||
|
||||
func NewGlobalFromConfigStruct(c *Global) *api.Global {
|
||||
families := make([]uint32, 0, len(c.AfiSafis))
|
||||
for _, f := range c.AfiSafis {
|
||||
families = append(families, uint32(AfiSafiTypeToIntMap[f.Config.AfiSafiName]))
|
||||
}
|
||||
|
||||
applyPolicy := newApplyPolicyFromConfigStruct(&c.ApplyPolicy)
|
||||
|
||||
return &api.Global{
|
||||
As: c.Config.As,
|
||||
RouterId: c.Config.RouterId,
|
||||
ListenPort: c.Config.Port,
|
||||
ListenAddresses: c.Config.LocalAddressList,
|
||||
Families: families,
|
||||
UseMultiplePaths: c.UseMultiplePaths.Config.Enabled,
|
||||
RouteSelectionOptions: &api.RouteSelectionOptionsConfig{
|
||||
AlwaysCompareMed: c.RouteSelectionOptions.Config.AlwaysCompareMed,
|
||||
IgnoreAsPathLength: c.RouteSelectionOptions.Config.IgnoreAsPathLength,
|
||||
ExternalCompareRouterId: c.RouteSelectionOptions.Config.ExternalCompareRouterId,
|
||||
AdvertiseInactiveRoutes: c.RouteSelectionOptions.Config.AdvertiseInactiveRoutes,
|
||||
EnableAigp: c.RouteSelectionOptions.Config.EnableAigp,
|
||||
IgnoreNextHopIgpMetric: c.RouteSelectionOptions.Config.IgnoreNextHopIgpMetric,
|
||||
DisableBestPathSelection: c.RouteSelectionOptions.Config.DisableBestPathSelection,
|
||||
},
|
||||
DefaultRouteDistance: &api.DefaultRouteDistance{
|
||||
ExternalRouteDistance: uint32(c.DefaultRouteDistance.Config.ExternalRouteDistance),
|
||||
InternalRouteDistance: uint32(c.DefaultRouteDistance.Config.InternalRouteDistance),
|
||||
},
|
||||
Confederation: &api.Confederation{
|
||||
Enabled: c.Confederation.Config.Enabled,
|
||||
Identifier: c.Confederation.Config.Identifier,
|
||||
MemberAsList: c.Confederation.Config.MemberAsList,
|
||||
},
|
||||
GracefulRestart: &api.GracefulRestart{
|
||||
Enabled: c.GracefulRestart.Config.Enabled,
|
||||
RestartTime: uint32(c.GracefulRestart.Config.RestartTime),
|
||||
StaleRoutesTime: uint32(c.GracefulRestart.Config.StaleRoutesTime),
|
||||
HelperOnly: c.GracefulRestart.Config.HelperOnly,
|
||||
DeferralTime: uint32(c.GracefulRestart.Config.DeferralTime),
|
||||
NotificationEnabled: c.GracefulRestart.Config.NotificationEnabled,
|
||||
LonglivedEnabled: c.GracefulRestart.Config.LongLivedEnabled,
|
||||
},
|
||||
ApplyPolicy: applyPolicy,
|
||||
}
|
||||
}
|
||||
|
||||
func newAPIPrefixFromConfigStruct(c Prefix) (*api.Prefix, error) {
|
||||
min, max, err := ParseMaskLength(c.IpPrefix, c.MasklengthRange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &api.Prefix{
|
||||
IpPrefix: c.IpPrefix,
|
||||
MaskLengthMin: uint32(min),
|
||||
MaskLengthMax: uint32(max),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewAPIDefinedSetsFromConfigStruct(t *DefinedSets) ([]*api.DefinedSet, error) {
|
||||
definedSets := make([]*api.DefinedSet, 0)
|
||||
|
||||
for _, ps := range t.PrefixSets {
|
||||
prefixes := make([]*api.Prefix, 0)
|
||||
for _, p := range ps.PrefixList {
|
||||
ap, err := newAPIPrefixFromConfigStruct(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prefixes = append(prefixes, ap)
|
||||
}
|
||||
definedSets = append(definedSets, &api.DefinedSet{
|
||||
DefinedType: api.DefinedType_PREFIX,
|
||||
Name: ps.PrefixSetName,
|
||||
Prefixes: prefixes,
|
||||
})
|
||||
}
|
||||
|
||||
for _, ns := range t.NeighborSets {
|
||||
definedSets = append(definedSets, &api.DefinedSet{
|
||||
DefinedType: api.DefinedType_NEIGHBOR,
|
||||
Name: ns.NeighborSetName,
|
||||
List: ns.NeighborInfoList,
|
||||
})
|
||||
}
|
||||
|
||||
bs := t.BgpDefinedSets
|
||||
for _, cs := range bs.CommunitySets {
|
||||
definedSets = append(definedSets, &api.DefinedSet{
|
||||
DefinedType: api.DefinedType_COMMUNITY,
|
||||
Name: cs.CommunitySetName,
|
||||
List: cs.CommunityList,
|
||||
})
|
||||
}
|
||||
|
||||
for _, es := range bs.ExtCommunitySets {
|
||||
definedSets = append(definedSets, &api.DefinedSet{
|
||||
DefinedType: api.DefinedType_EXT_COMMUNITY,
|
||||
Name: es.ExtCommunitySetName,
|
||||
List: es.ExtCommunityList,
|
||||
})
|
||||
}
|
||||
|
||||
for _, ls := range bs.LargeCommunitySets {
|
||||
definedSets = append(definedSets, &api.DefinedSet{
|
||||
DefinedType: api.DefinedType_LARGE_COMMUNITY,
|
||||
Name: ls.LargeCommunitySetName,
|
||||
List: ls.LargeCommunityList,
|
||||
})
|
||||
}
|
||||
|
||||
for _, as := range bs.AsPathSets {
|
||||
definedSets = append(definedSets, &api.DefinedSet{
|
||||
DefinedType: api.DefinedType_AS_PATH,
|
||||
Name: as.AsPathSetName,
|
||||
List: as.AsPathList,
|
||||
})
|
||||
}
|
||||
|
||||
return definedSets, nil
|
||||
}
|
||||
|
||||
204
vendor/github.com/osrg/gobgp/internal/pkg/table/adj.go
generated
vendored
204
vendor/github.com/osrg/gobgp/internal/pkg/table/adj.go
generated
vendored
@@ -23,16 +23,16 @@ import (
|
||||
|
||||
type AdjRib struct {
|
||||
accepted map[bgp.RouteFamily]int
|
||||
table map[bgp.RouteFamily]map[string]*Path
|
||||
table map[bgp.RouteFamily]*Table
|
||||
}
|
||||
|
||||
func NewAdjRib(rfList []bgp.RouteFamily) *AdjRib {
|
||||
table := make(map[bgp.RouteFamily]map[string]*Path)
|
||||
for _, rf := range rfList {
|
||||
table[rf] = make(map[string]*Path)
|
||||
m := make(map[bgp.RouteFamily]*Table)
|
||||
for _, f := range rfList {
|
||||
m[f] = NewTable(f)
|
||||
}
|
||||
return &AdjRib{
|
||||
table: table,
|
||||
table: m,
|
||||
accepted: make(map[bgp.RouteFamily]int),
|
||||
}
|
||||
}
|
||||
@@ -43,56 +43,100 @@ func (adj *AdjRib) Update(pathList []*Path) {
|
||||
continue
|
||||
}
|
||||
rf := path.GetRouteFamily()
|
||||
key := fmt.Sprintf("%d:%s", path.GetNlri().PathIdentifier(), path.getPrefix())
|
||||
t := adj.table[path.GetRouteFamily()]
|
||||
d := t.getOrCreateDest(path.GetNlri(), 0)
|
||||
var old *Path
|
||||
idx := -1
|
||||
for i, p := range d.knownPathList {
|
||||
if p.GetNlri().PathIdentifier() == path.GetNlri().PathIdentifier() {
|
||||
idx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if idx != -1 {
|
||||
old = d.knownPathList[idx]
|
||||
}
|
||||
|
||||
old, found := adj.table[rf][key]
|
||||
if path.IsWithdraw {
|
||||
if found {
|
||||
delete(adj.table[rf], key)
|
||||
if !old.IsAsLooped() {
|
||||
if idx != -1 {
|
||||
d.knownPathList = append(d.knownPathList[:idx], d.knownPathList[idx+1:]...)
|
||||
if len(d.knownPathList) == 0 {
|
||||
t.deleteDest(d)
|
||||
}
|
||||
if !old.IsRejected() {
|
||||
adj.accepted[rf]--
|
||||
}
|
||||
}
|
||||
path.SetDropped(true)
|
||||
} else {
|
||||
if found {
|
||||
if old.IsAsLooped() && !path.IsAsLooped() {
|
||||
if idx != -1 {
|
||||
if old.IsRejected() && !path.IsRejected() {
|
||||
adj.accepted[rf]++
|
||||
} else if !old.IsAsLooped() && path.IsAsLooped() {
|
||||
} else if !old.IsRejected() && path.IsRejected() {
|
||||
adj.accepted[rf]--
|
||||
}
|
||||
if old.Equal(path) {
|
||||
path.setTimestamp(old.GetTimestamp())
|
||||
}
|
||||
d.knownPathList[idx] = path
|
||||
} else {
|
||||
if !path.IsAsLooped() {
|
||||
d.knownPathList = append(d.knownPathList, path)
|
||||
if !path.IsRejected() {
|
||||
adj.accepted[rf]++
|
||||
}
|
||||
}
|
||||
if found && old.Equal(path) {
|
||||
path.setTimestamp(old.GetTimestamp())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The provided pathList is expected to be the real candidate routes after policy evaluation.
|
||||
For routes that are filtered by policy, there could be a mismatch between display
|
||||
and actual rib sent to the peer (if softreset out was not run).
|
||||
Only used to display adj-out because we do not maintain a separate adj-out table
|
||||
*/
|
||||
func (adj *AdjRib) UpdateAdjRibOut(pathList []*Path) {
|
||||
for _, path := range pathList {
|
||||
if path == nil || path.IsEOR() {
|
||||
continue
|
||||
}
|
||||
t := adj.table[path.GetRouteFamily()]
|
||||
d := t.getOrCreateDest(path.GetNlri(), 0)
|
||||
d.knownPathList = append(d.knownPathList, path)
|
||||
}
|
||||
}
|
||||
|
||||
func (adj *AdjRib) walk(families []bgp.RouteFamily, fn func(*Destination) bool) {
|
||||
for _, f := range families {
|
||||
if t, ok := adj.table[f]; ok {
|
||||
for _, d := range t.destinations {
|
||||
if fn(d) {
|
||||
return
|
||||
}
|
||||
}
|
||||
adj.table[rf][key] = path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (adj *AdjRib) PathList(rfList []bgp.RouteFamily, accepted bool) []*Path {
|
||||
pathList := make([]*Path, 0, adj.Count(rfList))
|
||||
for _, rf := range rfList {
|
||||
for _, rr := range adj.table[rf] {
|
||||
if accepted && rr.IsAsLooped() {
|
||||
adj.walk(rfList, func(d *Destination) bool {
|
||||
for _, p := range d.knownPathList {
|
||||
if accepted && p.IsRejected() {
|
||||
continue
|
||||
}
|
||||
pathList = append(pathList, rr)
|
||||
pathList = append(pathList, p)
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
return pathList
|
||||
}
|
||||
|
||||
func (adj *AdjRib) Count(rfList []bgp.RouteFamily) int {
|
||||
count := 0
|
||||
for _, rf := range rfList {
|
||||
if table, ok := adj.table[rf]; ok {
|
||||
count += len(table)
|
||||
}
|
||||
}
|
||||
adj.walk(rfList, func(d *Destination) bool {
|
||||
count += len(d.knownPathList)
|
||||
return false
|
||||
})
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -106,70 +150,88 @@ func (adj *AdjRib) Accepted(rfList []bgp.RouteFamily) int {
|
||||
return count
|
||||
}
|
||||
|
||||
func (adj *AdjRib) Drop(rfList []bgp.RouteFamily) {
|
||||
for _, rf := range rfList {
|
||||
if _, ok := adj.table[rf]; ok {
|
||||
adj.table[rf] = make(map[string]*Path)
|
||||
adj.accepted[rf] = 0
|
||||
func (adj *AdjRib) Drop(rfList []bgp.RouteFamily) []*Path {
|
||||
l := make([]*Path, 0, adj.Count(rfList))
|
||||
adj.walk(rfList, func(d *Destination) bool {
|
||||
for _, p := range d.knownPathList {
|
||||
w := p.Clone(true)
|
||||
w.SetDropped(true)
|
||||
l = append(l, w)
|
||||
}
|
||||
return false
|
||||
})
|
||||
for _, rf := range rfList {
|
||||
adj.table[rf] = NewTable(rf)
|
||||
adj.accepted[rf] = 0
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (adj *AdjRib) DropStale(rfList []bgp.RouteFamily) []*Path {
|
||||
pathList := make([]*Path, 0, adj.Count(rfList))
|
||||
for _, rf := range rfList {
|
||||
if table, ok := adj.table[rf]; ok {
|
||||
for k, p := range table {
|
||||
if p.IsStale() {
|
||||
delete(table, k)
|
||||
if !p.IsAsLooped() {
|
||||
adj.accepted[rf]--
|
||||
}
|
||||
pathList = append(pathList, p.Clone(true))
|
||||
}
|
||||
adj.walk(rfList, func(d *Destination) bool {
|
||||
for _, p := range d.knownPathList {
|
||||
if p.IsStale() {
|
||||
w := p.Clone(true)
|
||||
w.SetDropped(true)
|
||||
pathList = append(pathList, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
adj.Update(pathList)
|
||||
return pathList
|
||||
}
|
||||
|
||||
func (adj *AdjRib) StaleAll(rfList []bgp.RouteFamily) []*Path {
|
||||
pathList := make([]*Path, 0)
|
||||
for _, rf := range rfList {
|
||||
if table, ok := adj.table[rf]; ok {
|
||||
l := make([]*Path, 0, len(table))
|
||||
for k, p := range table {
|
||||
n := p.Clone(false)
|
||||
n.MarkStale(true)
|
||||
table[k] = n
|
||||
l = append(l, n)
|
||||
}
|
||||
if len(l) > 0 {
|
||||
pathList = append(pathList, l...)
|
||||
pathList := make([]*Path, 0, adj.Count(rfList))
|
||||
adj.walk(rfList, func(d *Destination) bool {
|
||||
for i, p := range d.knownPathList {
|
||||
n := p.Clone(false)
|
||||
n.MarkStale(true)
|
||||
n.SetRejected(p.IsRejected())
|
||||
d.knownPathList[i] = n
|
||||
if !n.IsRejected() {
|
||||
pathList = append(pathList, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
return pathList
|
||||
}
|
||||
|
||||
func (adj *AdjRib) MarkLLGRStaleOrDrop(rfList []bgp.RouteFamily) []*Path {
|
||||
pathList := make([]*Path, 0, adj.Count(rfList))
|
||||
adj.walk(rfList, func(d *Destination) bool {
|
||||
for i, p := range d.knownPathList {
|
||||
if p.HasNoLLGR() {
|
||||
n := p.Clone(true)
|
||||
n.SetDropped(true)
|
||||
pathList = append(pathList, n)
|
||||
} else {
|
||||
n := p.Clone(false)
|
||||
n.SetRejected(p.IsRejected())
|
||||
n.SetCommunities([]uint32{uint32(bgp.COMMUNITY_LLGR_STALE)}, false)
|
||||
if p.IsRejected() {
|
||||
d.knownPathList[i] = n
|
||||
} else {
|
||||
pathList = append(pathList, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
adj.Update(pathList)
|
||||
return pathList
|
||||
}
|
||||
|
||||
func (adj *AdjRib) Select(family bgp.RouteFamily, accepted bool, option ...TableSelectOption) (*Table, error) {
|
||||
m := make(map[string][]*Path)
|
||||
pl := adj.PathList([]bgp.RouteFamily{family}, accepted)
|
||||
for _, path := range pl {
|
||||
key := path.GetNlri().String()
|
||||
if _, y := m[key]; y {
|
||||
m[key] = append(m[key], path)
|
||||
} else {
|
||||
m[key] = []*Path{path}
|
||||
}
|
||||
t, ok := adj.table[family]
|
||||
if !ok {
|
||||
t = NewTable(family)
|
||||
}
|
||||
d := make([]*Destination, 0, len(pl))
|
||||
for _, l := range m {
|
||||
d = append(d, NewDestination(l[0].GetNlri(), 0, l...))
|
||||
}
|
||||
tbl := NewTable(family, d...)
|
||||
option = append(option, TableSelectOption{adj: true})
|
||||
return tbl.Select(option...)
|
||||
return t.Select(option...)
|
||||
}
|
||||
|
||||
func (adj *AdjRib) TableInfo(family bgp.RouteFamily) (*TableInfo, error) {
|
||||
|
||||
51
vendor/github.com/osrg/gobgp/internal/pkg/table/destination.go
generated
vendored
51
vendor/github.com/osrg/gobgp/internal/pkg/table/destination.go
generated
vendored
@@ -74,38 +74,6 @@ func (r *BestPathReason) String() string {
|
||||
return BestPathReasonStringMap[*r]
|
||||
}
|
||||
|
||||
func IpToRadixkey(b []byte, max uint8) string {
|
||||
var buffer bytes.Buffer
|
||||
for i := 0; i < len(b) && i < int(max); i++ {
|
||||
fmt.Fprintf(&buffer, "%08b", b[i])
|
||||
}
|
||||
return buffer.String()[:max]
|
||||
}
|
||||
|
||||
func CidrToRadixkey(cidr string) string {
|
||||
_, n, _ := net.ParseCIDR(cidr)
|
||||
ones, _ := n.Mask.Size()
|
||||
return IpToRadixkey(n.IP, uint8(ones))
|
||||
}
|
||||
|
||||
func AddrToRadixkey(addr bgp.AddrPrefixInterface) string {
|
||||
var (
|
||||
ip net.IP
|
||||
size uint8
|
||||
)
|
||||
switch T := addr.(type) {
|
||||
case *bgp.IPAddrPrefix:
|
||||
mask := net.CIDRMask(int(T.Length), net.IPv4len*8)
|
||||
ip, size = T.Prefix.Mask(mask).To4(), uint8(T.Length)
|
||||
case *bgp.IPv6AddrPrefix:
|
||||
mask := net.CIDRMask(int(T.Length), net.IPv6len*8)
|
||||
ip, size = T.Prefix.Mask(mask).To16(), uint8(T.Length)
|
||||
default:
|
||||
return CidrToRadixkey(addr.String())
|
||||
}
|
||||
return IpToRadixkey(ip, size)
|
||||
}
|
||||
|
||||
type PeerInfo struct {
|
||||
AS uint32
|
||||
ID net.IP
|
||||
@@ -265,7 +233,7 @@ func (dest *Destination) Calculate(newPath *Path) *Update {
|
||||
|
||||
if newPath.IsWithdraw {
|
||||
p := dest.explicitWithdraw(newPath)
|
||||
if p != nil {
|
||||
if p != nil && newPath.IsDropped() {
|
||||
if id := p.GetNlri().PathLocalIdentifier(); id != 0 {
|
||||
dest.localIdMap.Unflag(uint(id))
|
||||
}
|
||||
@@ -405,17 +373,19 @@ func (dest *Destination) computeKnownBestPath() (*Path, BestPathReason, error) {
|
||||
}
|
||||
return dest.knownPathList[0], BPR_ONLY_PATH, nil
|
||||
}
|
||||
dest.sort()
|
||||
reason := dest.sort()
|
||||
newBest := dest.knownPathList[0]
|
||||
// If the first path has the invalidated next-hop, which evaluated by IGP,
|
||||
// returns no path with the reason of the next-hop reachability.
|
||||
if dest.knownPathList[0].IsNexthopInvalid {
|
||||
return nil, BPR_REACHABLE_NEXT_HOP, nil
|
||||
}
|
||||
return newBest, newBest.reason, nil
|
||||
return newBest, reason, nil
|
||||
}
|
||||
|
||||
func (dst *Destination) sort() {
|
||||
func (dst *Destination) sort() BestPathReason {
|
||||
reason := BPR_UNKNOWN
|
||||
|
||||
sort.SliceStable(dst.knownPathList, func(i, j int) bool {
|
||||
//Compares given paths and returns best path.
|
||||
//
|
||||
@@ -451,7 +421,6 @@ func (dst *Destination) sort() {
|
||||
path2 := dst.knownPathList[j]
|
||||
|
||||
var better *Path
|
||||
reason := BPR_UNKNOWN
|
||||
|
||||
// draft-uttaro-idr-bgp-persistence-02
|
||||
if better == nil {
|
||||
@@ -501,7 +470,7 @@ func (dst *Destination) sort() {
|
||||
reason = BPR_OLDER
|
||||
}
|
||||
if better == nil {
|
||||
var e error = nil
|
||||
var e error
|
||||
better, e = compareByRouterID(path1, path2)
|
||||
if e != nil {
|
||||
log.WithFields(log.Fields{
|
||||
@@ -515,11 +484,9 @@ func (dst *Destination) sort() {
|
||||
reason = BPR_UNKNOWN
|
||||
better = path1
|
||||
}
|
||||
|
||||
better.reason = reason
|
||||
|
||||
return better == path1
|
||||
})
|
||||
return reason
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
@@ -933,7 +900,7 @@ func compareByRouterID(path1, path2 *Path) (*Path, error) {
|
||||
}
|
||||
|
||||
if !SelectionOptions.ExternalCompareRouterId && path1.IsIBGP() != path2.IsIBGP() {
|
||||
return nil, fmt.Errorf("This method does not support comparing ebgp with ibgp path")
|
||||
return nil, fmt.Errorf("this method does not support comparing ebgp with ibgp path")
|
||||
}
|
||||
|
||||
// At least one path is not coming from NC, so we get local bgp id.
|
||||
|
||||
18
vendor/github.com/osrg/gobgp/internal/pkg/table/message.go
generated
vendored
18
vendor/github.com/osrg/gobgp/internal/pkg/table/message.go
generated
vendored
@@ -85,9 +85,9 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error {
|
||||
asAttrPos := 0
|
||||
as4AttrPos := 0
|
||||
for i, attr := range msg.PathAttributes {
|
||||
switch attr.(type) {
|
||||
switch a := attr.(type) {
|
||||
case *bgp.PathAttributeAsPath:
|
||||
asAttr = attr.(*bgp.PathAttributeAsPath)
|
||||
asAttr = a
|
||||
for j, param := range asAttr.Value {
|
||||
as2Param, ok := param.(*bgp.AsPathParam)
|
||||
if ok {
|
||||
@@ -103,7 +103,7 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error {
|
||||
msg.PathAttributes[i] = asAttr
|
||||
case *bgp.PathAttributeAs4Path:
|
||||
as4AttrPos = i
|
||||
as4Attr = attr.(*bgp.PathAttributeAs4Path)
|
||||
as4Attr = a
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +130,9 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error {
|
||||
}
|
||||
|
||||
as4Len := 0
|
||||
as4Params := make([]bgp.AsPathParamInterface, 0, len(as4Attr.Value))
|
||||
var as4Params []bgp.AsPathParamInterface
|
||||
if as4Attr != nil {
|
||||
as4Params = make([]bgp.AsPathParamInterface, 0, len(as4Attr.Value))
|
||||
for _, p := range as4Attr.Value {
|
||||
// RFC 6793 6. Error Handling
|
||||
//
|
||||
@@ -211,9 +212,8 @@ func UpdatePathAggregator2ByteAs(msg *bgp.BGPUpdate) {
|
||||
as := uint32(0)
|
||||
var addr string
|
||||
for i, attr := range msg.PathAttributes {
|
||||
switch attr.(type) {
|
||||
switch agg := attr.(type) {
|
||||
case *bgp.PathAttributeAggregator:
|
||||
agg := attr.(*bgp.PathAttributeAggregator)
|
||||
addr = agg.Value.Address.String()
|
||||
if agg.Value.AS > (1<<16)-1 {
|
||||
as = agg.Value.AS
|
||||
@@ -233,15 +233,15 @@ func UpdatePathAggregator4ByteAs(msg *bgp.BGPUpdate) error {
|
||||
var agg4Attr *bgp.PathAttributeAs4Aggregator
|
||||
agg4AttrPos := 0
|
||||
for i, attr := range msg.PathAttributes {
|
||||
switch attr.(type) {
|
||||
switch agg := attr.(type) {
|
||||
case *bgp.PathAttributeAggregator:
|
||||
attr := attr.(*bgp.PathAttributeAggregator)
|
||||
attr := agg
|
||||
if attr.Value.Askind == reflect.Uint16 {
|
||||
aggAttr = attr
|
||||
aggAttr.Value.Askind = reflect.Uint32
|
||||
}
|
||||
case *bgp.PathAttributeAs4Aggregator:
|
||||
agg4Attr = attr.(*bgp.PathAttributeAs4Aggregator)
|
||||
agg4Attr = agg
|
||||
agg4AttrPos = i
|
||||
}
|
||||
}
|
||||
|
||||
134
vendor/github.com/osrg/gobgp/internal/pkg/table/path.go
generated
vendored
134
vendor/github.com/osrg/gobgp/internal/pkg/table/path.go
generated
vendored
@@ -89,7 +89,6 @@ type originInfo struct {
|
||||
nlri bgp.AddrPrefixInterface
|
||||
source *PeerInfo
|
||||
timestamp int64
|
||||
validation *Validation
|
||||
noImplicitWithdraw bool
|
||||
isFromExternal bool
|
||||
eor bool
|
||||
@@ -138,15 +137,21 @@ type Path struct {
|
||||
pathAttrs []bgp.PathAttributeInterface
|
||||
dels []bgp.BGPAttrType
|
||||
attrsHash uint32
|
||||
aslooped bool
|
||||
reason BestPathReason
|
||||
rejected bool
|
||||
// doesn't exist in the adj
|
||||
dropped bool
|
||||
|
||||
// For BGP Nexthop Tracking, this field shows if nexthop is invalidated by IGP.
|
||||
IsNexthopInvalid bool
|
||||
IsWithdraw bool
|
||||
}
|
||||
|
||||
var localSource = &PeerInfo{}
|
||||
|
||||
func NewPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, pattrs []bgp.PathAttributeInterface, timestamp time.Time, noImplicitWithdraw bool) *Path {
|
||||
if source == nil {
|
||||
source = localSource
|
||||
}
|
||||
if !isWithdraw && pattrs == nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Table",
|
||||
@@ -323,7 +328,8 @@ func (path *Path) IsLocal() bool {
|
||||
}
|
||||
|
||||
func (path *Path) IsIBGP() bool {
|
||||
return path.GetSource().AS == path.GetSource().LocalAS
|
||||
as := path.GetSource().AS
|
||||
return (as == path.GetSource().LocalAS) && as != 0
|
||||
}
|
||||
|
||||
// create new PathAttributes
|
||||
@@ -352,22 +358,6 @@ func (path *Path) NoImplicitWithdraw() bool {
|
||||
return path.OriginInfo().noImplicitWithdraw
|
||||
}
|
||||
|
||||
func (path *Path) Validation() *Validation {
|
||||
return path.OriginInfo().validation
|
||||
}
|
||||
|
||||
func (path *Path) ValidationStatus() config.RpkiValidationResultType {
|
||||
if v := path.OriginInfo().validation; v != nil {
|
||||
return v.Status
|
||||
} else {
|
||||
return config.RPKI_VALIDATION_RESULT_TYPE_NONE
|
||||
}
|
||||
}
|
||||
|
||||
func (path *Path) SetValidation(v *Validation) {
|
||||
path.OriginInfo().validation = v
|
||||
}
|
||||
|
||||
func (path *Path) IsFromExternal() bool {
|
||||
return path.OriginInfo().isFromExternal
|
||||
}
|
||||
@@ -380,9 +370,6 @@ func (path *Path) GetRouteFamily() bgp.RouteFamily {
|
||||
return bgp.AfiSafiToRouteFamily(path.OriginInfo().nlri.AFI(), path.OriginInfo().nlri.SAFI())
|
||||
}
|
||||
|
||||
func (path *Path) SetSource(source *PeerInfo) {
|
||||
path.OriginInfo().source = source
|
||||
}
|
||||
func (path *Path) GetSource() *PeerInfo {
|
||||
return path.OriginInfo().source
|
||||
}
|
||||
@@ -395,12 +382,29 @@ func (path *Path) IsStale() bool {
|
||||
return path.OriginInfo().stale
|
||||
}
|
||||
|
||||
func (path *Path) IsAsLooped() bool {
|
||||
return path.aslooped
|
||||
func (path *Path) IsRejected() bool {
|
||||
return path.rejected
|
||||
}
|
||||
|
||||
func (path *Path) SetAsLooped(y bool) {
|
||||
path.aslooped = y
|
||||
func (path *Path) SetRejected(y bool) {
|
||||
path.rejected = y
|
||||
}
|
||||
|
||||
func (path *Path) IsDropped() bool {
|
||||
return path.dropped
|
||||
}
|
||||
|
||||
func (path *Path) SetDropped(y bool) {
|
||||
path.dropped = y
|
||||
}
|
||||
|
||||
func (path *Path) HasNoLLGR() bool {
|
||||
for _, c := range path.GetCommunities() {
|
||||
if c == uint32(bgp.COMMUNITY_NO_LLGR) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (path *Path) IsLLGRStale() bool {
|
||||
@@ -897,6 +901,12 @@ func (path *Path) GetLargeCommunities() []*bgp.LargeCommunity {
|
||||
}
|
||||
|
||||
func (path *Path) SetLargeCommunities(cs []*bgp.LargeCommunity, doReplace bool) {
|
||||
if len(cs) == 0 && doReplace {
|
||||
// clear large communities
|
||||
path.delPathAttr(bgp.BGP_ATTR_TYPE_LARGE_COMMUNITY)
|
||||
return
|
||||
}
|
||||
|
||||
a := path.getPathAttr(bgp.BGP_ATTR_TYPE_LARGE_COMMUNITY)
|
||||
if a == nil || doReplace {
|
||||
path.setPathAttr(bgp.NewPathAttributeLargeCommunities(cs))
|
||||
@@ -1016,7 +1026,6 @@ func (path *Path) MarshalJSON() ([]byte, error) {
|
||||
PathAttrs: path.GetPathAttrs(),
|
||||
Age: path.GetTimestamp().Unix(),
|
||||
Withdrawal: path.IsWithdraw,
|
||||
Validation: string(path.ValidationStatus()),
|
||||
SourceID: path.GetSource().ID,
|
||||
NeighborIP: path.GetSource().Address,
|
||||
Stale: path.IsStale(),
|
||||
@@ -1066,12 +1075,22 @@ func (v *Vrf) ToGlobalPath(path *Path) error {
|
||||
case bgp.RF_IPv4_UC:
|
||||
n := nlri.(*bgp.IPAddrPrefix)
|
||||
pathIdentifier := path.GetNlri().PathIdentifier()
|
||||
path.OriginInfo().nlri = bgp.NewLabeledVPNIPAddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(0), v.Rd)
|
||||
path.OriginInfo().nlri = bgp.NewLabeledVPNIPAddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(v.MplsLabel), v.Rd)
|
||||
path.GetNlri().SetPathIdentifier(pathIdentifier)
|
||||
case bgp.RF_FS_IPv4_UC:
|
||||
n := nlri.(*bgp.FlowSpecIPv4Unicast)
|
||||
pathIdentifier := path.GetNlri().PathIdentifier()
|
||||
path.OriginInfo().nlri = bgp.NewFlowSpecIPv4VPN(v.Rd, n.FlowSpecNLRI.Value)
|
||||
path.GetNlri().SetPathIdentifier(pathIdentifier)
|
||||
case bgp.RF_IPv6_UC:
|
||||
n := nlri.(*bgp.IPv6AddrPrefix)
|
||||
pathIdentifier := path.GetNlri().PathIdentifier()
|
||||
path.OriginInfo().nlri = bgp.NewLabeledVPNIPv6AddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(0), v.Rd)
|
||||
path.OriginInfo().nlri = bgp.NewLabeledVPNIPv6AddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(v.MplsLabel), v.Rd)
|
||||
path.GetNlri().SetPathIdentifier(pathIdentifier)
|
||||
case bgp.RF_FS_IPv6_UC:
|
||||
n := nlri.(*bgp.FlowSpecIPv6Unicast)
|
||||
pathIdentifier := path.GetNlri().PathIdentifier()
|
||||
path.OriginInfo().nlri = bgp.NewFlowSpecIPv6VPN(v.Rd, n.FlowSpecNLRI.Value)
|
||||
path.GetNlri().SetPathIdentifier(pathIdentifier)
|
||||
case bgp.RF_EVPN:
|
||||
n := nlri.(*bgp.EVPNNLRI)
|
||||
@@ -1095,11 +1114,11 @@ func (p *Path) ToGlobal(vrf *Vrf) *Path {
|
||||
switch rf := p.GetRouteFamily(); rf {
|
||||
case bgp.RF_IPv4_UC:
|
||||
n := nlri.(*bgp.IPAddrPrefix)
|
||||
nlri = bgp.NewLabeledVPNIPAddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(0), vrf.Rd)
|
||||
nlri = bgp.NewLabeledVPNIPAddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(vrf.MplsLabel), vrf.Rd)
|
||||
nlri.SetPathIdentifier(pathId)
|
||||
case bgp.RF_IPv6_UC:
|
||||
n := nlri.(*bgp.IPv6AddrPrefix)
|
||||
nlri = bgp.NewLabeledVPNIPv6AddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(0), vrf.Rd)
|
||||
nlri = bgp.NewLabeledVPNIPv6AddrPrefix(n.Length, n.Prefix.String(), *bgp.NewMPLSLabelStack(vrf.MplsLabel), vrf.Rd)
|
||||
nlri.SetPathIdentifier(pathId)
|
||||
case bgp.RF_EVPN:
|
||||
n := nlri.(*bgp.EVPNNLRI)
|
||||
@@ -1134,7 +1153,6 @@ func (p *Path) ToGlobal(vrf *Vrf) *Path {
|
||||
path.SetExtCommunities(vrf.ExportRt, false)
|
||||
path.delPathAttr(bgp.BGP_ATTR_TYPE_NEXT_HOP)
|
||||
path.setPathAttr(bgp.NewPathAttributeMpReachNLRI(nh.String(), []bgp.AddrPrefixInterface{nlri}))
|
||||
path.IsNexthopInvalid = p.IsNexthopInvalid
|
||||
return path
|
||||
}
|
||||
|
||||
@@ -1149,17 +1167,39 @@ func (p *Path) ToLocal() *Path {
|
||||
ones, _ := c.Mask.Size()
|
||||
nlri = bgp.NewIPAddrPrefix(uint8(ones), c.IP.String())
|
||||
nlri.SetPathLocalIdentifier(pathId)
|
||||
case bgp.RF_FS_IPv4_VPN:
|
||||
n := nlri.(*bgp.FlowSpecIPv4VPN)
|
||||
nlri = bgp.NewFlowSpecIPv4Unicast(n.FlowSpecNLRI.Value)
|
||||
nlri.SetPathLocalIdentifier(pathId)
|
||||
case bgp.RF_IPv6_VPN:
|
||||
n := nlri.(*bgp.LabeledVPNIPv6AddrPrefix)
|
||||
_, c, _ := net.ParseCIDR(n.IPPrefix())
|
||||
ones, _ := c.Mask.Size()
|
||||
nlri = bgp.NewIPv6AddrPrefix(uint8(ones), c.IP.String())
|
||||
nlri.SetPathLocalIdentifier(pathId)
|
||||
case bgp.RF_FS_IPv6_VPN:
|
||||
n := nlri.(*bgp.FlowSpecIPv6VPN)
|
||||
nlri = bgp.NewFlowSpecIPv6Unicast(n.FlowSpecNLRI.Value)
|
||||
nlri.SetPathLocalIdentifier(pathId)
|
||||
default:
|
||||
return p
|
||||
}
|
||||
path := NewPath(p.OriginInfo().source, nlri, p.IsWithdraw, p.GetPathAttrs(), p.GetTimestamp(), false)
|
||||
path.delPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES)
|
||||
switch f {
|
||||
case bgp.RF_IPv4_VPN, bgp.RF_IPv6_VPN:
|
||||
path.delPathAttr(bgp.BGP_ATTR_TYPE_EXTENDED_COMMUNITIES)
|
||||
case bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN:
|
||||
extcomms := path.GetExtCommunities()
|
||||
newExtComms := make([]bgp.ExtendedCommunityInterface, 0, len(extcomms))
|
||||
for _, extComm := range extcomms {
|
||||
_, subType := extComm.GetTypes()
|
||||
if subType == bgp.EC_SUBTYPE_ROUTE_TARGET {
|
||||
continue
|
||||
}
|
||||
newExtComms = append(newExtComms, extComm)
|
||||
}
|
||||
path.SetExtCommunities(newExtComms, true)
|
||||
}
|
||||
|
||||
if f == bgp.RF_IPv4_VPN {
|
||||
nh := path.GetNexthop()
|
||||
@@ -1177,3 +1217,29 @@ func (p *Path) SetHash(v uint32) {
|
||||
func (p *Path) GetHash() uint32 {
|
||||
return p.attrsHash
|
||||
}
|
||||
|
||||
func nlriToIPNet(nlri bgp.AddrPrefixInterface) *net.IPNet {
|
||||
switch T := nlri.(type) {
|
||||
case *bgp.IPAddrPrefix:
|
||||
return &net.IPNet{
|
||||
IP: net.IP(T.Prefix.To4()),
|
||||
Mask: net.CIDRMask(int(T.Length), 32),
|
||||
}
|
||||
case *bgp.IPv6AddrPrefix:
|
||||
return &net.IPNet{
|
||||
IP: net.IP(T.Prefix.To16()),
|
||||
Mask: net.CIDRMask(int(T.Length), 128),
|
||||
}
|
||||
case *bgp.LabeledIPAddrPrefix:
|
||||
return &net.IPNet{
|
||||
IP: net.IP(T.Prefix.To4()),
|
||||
Mask: net.CIDRMask(int(T.Length), 32),
|
||||
}
|
||||
case *bgp.LabeledIPv6AddrPrefix:
|
||||
return &net.IPNet{
|
||||
IP: net.IP(T.Prefix.To4()),
|
||||
Mask: net.CIDRMask(int(T.Length), 128),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
525
vendor/github.com/osrg/gobgp/internal/pkg/table/policy.go
generated
vendored
525
vendor/github.com/osrg/gobgp/internal/pkg/table/policy.go
generated
vendored
@@ -16,7 +16,6 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -27,17 +26,17 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/k-sone/critbitgo"
|
||||
api "github.com/osrg/gobgp/api"
|
||||
"github.com/osrg/gobgp/internal/pkg/config"
|
||||
"github.com/osrg/gobgp/pkg/packet/bgp"
|
||||
|
||||
radix "github.com/armon/go-radix"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type PolicyOptions struct {
|
||||
Info *PeerInfo
|
||||
ValidationResult *Validation
|
||||
OldNextHop net.IP
|
||||
Info *PeerInfo
|
||||
OldNextHop net.IP
|
||||
Validate func(*Path) *Validation
|
||||
}
|
||||
|
||||
type DefinedType int
|
||||
@@ -353,7 +352,7 @@ func NewPrefix(c config.Prefix) (*Prefix, error) {
|
||||
|
||||
type PrefixSet struct {
|
||||
name string
|
||||
tree *radix.Tree
|
||||
tree *critbitgo.Net
|
||||
family bgp.RouteFamily
|
||||
}
|
||||
|
||||
@@ -370,29 +369,25 @@ func (lhs *PrefixSet) Append(arg DefinedSet) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("type cast failed")
|
||||
}
|
||||
// if either is empty, family can be ignored.
|
||||
if lhs.tree.Len() != 0 && rhs.tree.Len() != 0 {
|
||||
_, w, _ := lhs.tree.Minimum()
|
||||
l := w.([]*Prefix)
|
||||
_, v, _ := rhs.tree.Minimum()
|
||||
r := v.([]*Prefix)
|
||||
if l[0].AddressFamily != r[0].AddressFamily {
|
||||
return fmt.Errorf("can't append different family")
|
||||
}
|
||||
|
||||
if rhs.tree.Size() == 0 {
|
||||
// if try to append an empty set, then return directly
|
||||
return nil
|
||||
} else if lhs.tree.Size() != 0 && rhs.family != lhs.family {
|
||||
return fmt.Errorf("can't append different family")
|
||||
}
|
||||
rhs.tree.Walk(func(key string, v interface{}) bool {
|
||||
w, ok := lhs.tree.Get(key)
|
||||
rhs.tree.Walk(nil, func(r *net.IPNet, v interface{}) bool {
|
||||
w, ok, _ := lhs.tree.Get(r)
|
||||
if ok {
|
||||
r := v.([]*Prefix)
|
||||
l := w.([]*Prefix)
|
||||
lhs.tree.Insert(key, append(l, r...))
|
||||
rp := v.([]*Prefix)
|
||||
lp := w.([]*Prefix)
|
||||
lhs.tree.Add(r, append(lp, rp...))
|
||||
} else {
|
||||
lhs.tree.Insert(key, v)
|
||||
lhs.tree.Add(r, v)
|
||||
}
|
||||
return false
|
||||
return true
|
||||
})
|
||||
_, w, _ := lhs.tree.Minimum()
|
||||
lhs.family = w.([]*Prefix)[0].AddressFamily
|
||||
lhs.family = rhs.family
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -401,17 +396,17 @@ func (lhs *PrefixSet) Remove(arg DefinedSet) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("type cast failed")
|
||||
}
|
||||
rhs.tree.Walk(func(key string, v interface{}) bool {
|
||||
w, ok := lhs.tree.Get(key)
|
||||
rhs.tree.Walk(nil, func(r *net.IPNet, v interface{}) bool {
|
||||
w, ok, _ := lhs.tree.Get(r)
|
||||
if !ok {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
r := v.([]*Prefix)
|
||||
l := w.([]*Prefix)
|
||||
new := make([]*Prefix, 0, len(l))
|
||||
for _, lp := range l {
|
||||
rp := v.([]*Prefix)
|
||||
lp := w.([]*Prefix)
|
||||
new := make([]*Prefix, 0, len(lp))
|
||||
for _, lp := range lp {
|
||||
delete := false
|
||||
for _, rp := range r {
|
||||
for _, rp := range rp {
|
||||
if lp.Equal(rp) {
|
||||
delete = true
|
||||
break
|
||||
@@ -422,11 +417,11 @@ func (lhs *PrefixSet) Remove(arg DefinedSet) error {
|
||||
}
|
||||
}
|
||||
if len(new) == 0 {
|
||||
lhs.tree.Delete(key)
|
||||
lhs.tree.Delete(r)
|
||||
} else {
|
||||
lhs.tree.Insert(key, new)
|
||||
lhs.tree.Add(r, new)
|
||||
}
|
||||
return false
|
||||
return true
|
||||
})
|
||||
return nil
|
||||
}
|
||||
@@ -443,24 +438,24 @@ func (lhs *PrefixSet) Replace(arg DefinedSet) error {
|
||||
|
||||
func (s *PrefixSet) List() []string {
|
||||
var list []string
|
||||
s.tree.Walk(func(s string, v interface{}) bool {
|
||||
s.tree.Walk(nil, func(_ *net.IPNet, v interface{}) bool {
|
||||
ps := v.([]*Prefix)
|
||||
for _, p := range ps {
|
||||
list = append(list, fmt.Sprintf("%s %d..%d", p.PrefixString(), p.MasklengthRangeMin, p.MasklengthRangeMax))
|
||||
}
|
||||
return false
|
||||
return true
|
||||
})
|
||||
return list
|
||||
}
|
||||
|
||||
func (s *PrefixSet) ToConfig() *config.PrefixSet {
|
||||
list := make([]config.Prefix, 0, s.tree.Len())
|
||||
s.tree.Walk(func(s string, v interface{}) bool {
|
||||
list := make([]config.Prefix, 0, s.tree.Size())
|
||||
s.tree.Walk(nil, func(_ *net.IPNet, v interface{}) bool {
|
||||
ps := v.([]*Prefix)
|
||||
for _, p := range ps {
|
||||
list = append(list, config.Prefix{IpPrefix: p.PrefixString(), MasklengthRange: fmt.Sprintf("%d..%d", p.MasklengthRangeMin, p.MasklengthRangeMax)})
|
||||
}
|
||||
return false
|
||||
return true
|
||||
})
|
||||
return &config.PrefixSet{
|
||||
PrefixSetName: s.name,
|
||||
@@ -480,7 +475,7 @@ func NewPrefixSetFromApiStruct(name string, prefixes []*Prefix) (*PrefixSet, err
|
||||
if name == "" {
|
||||
return nil, fmt.Errorf("empty prefix set name")
|
||||
}
|
||||
tree := radix.New()
|
||||
tree := critbitgo.NewNet()
|
||||
var family bgp.RouteFamily
|
||||
for i, x := range prefixes {
|
||||
if i == 0 {
|
||||
@@ -488,13 +483,12 @@ func NewPrefixSetFromApiStruct(name string, prefixes []*Prefix) (*PrefixSet, err
|
||||
} else if family != x.AddressFamily {
|
||||
return nil, fmt.Errorf("multiple families")
|
||||
}
|
||||
key := CidrToRadixkey(x.Prefix.String())
|
||||
d, ok := tree.Get(key)
|
||||
d, ok, _ := tree.Get(x.Prefix)
|
||||
if ok {
|
||||
ps := d.([]*Prefix)
|
||||
tree.Insert(key, append(ps, x))
|
||||
tree.Add(x.Prefix, append(ps, x))
|
||||
} else {
|
||||
tree.Insert(key, []*Prefix{x})
|
||||
tree.Add(x.Prefix, []*Prefix{x})
|
||||
}
|
||||
}
|
||||
return &PrefixSet{
|
||||
@@ -512,7 +506,7 @@ func NewPrefixSet(c config.PrefixSet) (*PrefixSet, error) {
|
||||
}
|
||||
return nil, fmt.Errorf("empty prefix set name")
|
||||
}
|
||||
tree := radix.New()
|
||||
tree := critbitgo.NewNet()
|
||||
var family bgp.RouteFamily
|
||||
for i, x := range c.PrefixList {
|
||||
y, err := NewPrefix(x)
|
||||
@@ -524,13 +518,12 @@ func NewPrefixSet(c config.PrefixSet) (*PrefixSet, error) {
|
||||
} else if family != y.AddressFamily {
|
||||
return nil, fmt.Errorf("multiple families")
|
||||
}
|
||||
key := CidrToRadixkey(y.Prefix.String())
|
||||
d, ok := tree.Get(key)
|
||||
d, ok, _ := tree.Get(y.Prefix)
|
||||
if ok {
|
||||
ps := d.([]*Prefix)
|
||||
tree.Insert(key, append(ps, y))
|
||||
tree.Add(y.Prefix, append(ps, y))
|
||||
} else {
|
||||
tree.Insert(key, []*Prefix{y})
|
||||
tree.Add(y.Prefix, []*Prefix{y})
|
||||
}
|
||||
}
|
||||
return &PrefixSet{
|
||||
@@ -819,7 +812,7 @@ func (m *singleAsPathMatch) Match(aspath []uint32) bool {
|
||||
}
|
||||
|
||||
var (
|
||||
_regexpLeftMostRe = regexp.MustCompile(`$\^([0-9]+)_^`)
|
||||
_regexpLeftMostRe = regexp.MustCompile(`^\^([0-9]+)_$`)
|
||||
_regexpOriginRe = regexp.MustCompile(`^_([0-9]+)\$$`)
|
||||
_regexpIncludeRe = regexp.MustCompile("^_([0-9]+)_$")
|
||||
_regexpOnlyRe = regexp.MustCompile(`^\^([0-9]+)\$$`)
|
||||
@@ -1446,33 +1439,15 @@ func (c *PrefixCondition) Option() MatchOption {
|
||||
// subsequent comparison is skipped if that matches the conditions.
|
||||
// If PrefixList's length is zero, return true.
|
||||
func (c *PrefixCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
|
||||
var key string
|
||||
var masklen uint8
|
||||
keyf := func(ip net.IP, ones int) string {
|
||||
var buffer bytes.Buffer
|
||||
for i := 0; i < len(ip) && i < ones; i++ {
|
||||
buffer.WriteString(fmt.Sprintf("%08b", ip[i]))
|
||||
}
|
||||
return buffer.String()[:ones]
|
||||
}
|
||||
family := path.GetRouteFamily()
|
||||
switch family {
|
||||
case bgp.RF_IPv4_UC:
|
||||
masklen = path.GetNlri().(*bgp.IPAddrPrefix).Length
|
||||
key = keyf(path.GetNlri().(*bgp.IPAddrPrefix).Prefix, int(masklen))
|
||||
case bgp.RF_IPv6_UC:
|
||||
masklen = path.GetNlri().(*bgp.IPv6AddrPrefix).Length
|
||||
key = keyf(path.GetNlri().(*bgp.IPv6AddrPrefix).Prefix, int(masklen))
|
||||
default:
|
||||
return false
|
||||
}
|
||||
if family != c.set.family {
|
||||
if path.GetRouteFamily() != c.set.family {
|
||||
return false
|
||||
}
|
||||
|
||||
r := nlriToIPNet(path.GetNlri())
|
||||
ones, _ := r.Mask.Size()
|
||||
masklen := uint8(ones)
|
||||
result := false
|
||||
_, ps, ok := c.set.tree.LongestPrefix(key)
|
||||
if ok {
|
||||
if _, ps, _ := c.set.tree.Match(r); ps != nil {
|
||||
for _, p := range ps.([]*Prefix) {
|
||||
if p.MasklengthRangeMin <= masklen && masklen <= p.MasklengthRangeMax {
|
||||
result = true
|
||||
@@ -1899,8 +1874,8 @@ func (c *RpkiValidationCondition) Type() ConditionType {
|
||||
}
|
||||
|
||||
func (c *RpkiValidationCondition) Evaluate(path *Path, options *PolicyOptions) bool {
|
||||
if options != nil && options.ValidationResult != nil {
|
||||
return c.result == options.ValidationResult.Status
|
||||
if options != nil && options.Validate != nil {
|
||||
return c.result == options.Validate(path).Status
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -2536,7 +2511,7 @@ func (a *AsPathPrependAction) Apply(path *Path, option *PolicyOptions) *Path {
|
||||
asn = a.asn
|
||||
}
|
||||
|
||||
confed := option != nil && option.Info.Confederation
|
||||
confed := option != nil && option.Info != nil && option.Info.Confederation
|
||||
path.PrependAsn(asn, a.repeat, confed)
|
||||
|
||||
return path
|
||||
@@ -2580,7 +2555,7 @@ func NewAsPathPrependAction(action config.SetAsPathPrepend) (*AsPathPrependActio
|
||||
default:
|
||||
asn, err := strconv.ParseUint(action.As, 10, 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("As number string invalid")
|
||||
return nil, fmt.Errorf("AS number string invalid")
|
||||
}
|
||||
a.asn = uint32(asn)
|
||||
}
|
||||
@@ -2686,39 +2661,28 @@ func (s *Statement) ToConfig() *config.Statement {
|
||||
Conditions: func() config.Conditions {
|
||||
cond := config.Conditions{}
|
||||
for _, c := range s.Conditions {
|
||||
switch c.(type) {
|
||||
switch v := c.(type) {
|
||||
case *PrefixCondition:
|
||||
v := c.(*PrefixCondition)
|
||||
cond.MatchPrefixSet = config.MatchPrefixSet{PrefixSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()}
|
||||
case *NeighborCondition:
|
||||
v := c.(*NeighborCondition)
|
||||
cond.MatchNeighborSet = config.MatchNeighborSet{NeighborSet: v.set.Name(), MatchSetOptions: v.option.ConvertToMatchSetOptionsRestrictedType()}
|
||||
case *AsPathLengthCondition:
|
||||
v := c.(*AsPathLengthCondition)
|
||||
cond.BgpConditions.AsPathLength = config.AsPathLength{Operator: config.IntToAttributeComparisonMap[int(v.operator)], Value: v.length}
|
||||
case *AsPathCondition:
|
||||
v := c.(*AsPathCondition)
|
||||
cond.BgpConditions.MatchAsPathSet = config.MatchAsPathSet{AsPathSet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]}
|
||||
case *CommunityCondition:
|
||||
v := c.(*CommunityCondition)
|
||||
cond.BgpConditions.MatchCommunitySet = config.MatchCommunitySet{CommunitySet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]}
|
||||
case *ExtCommunityCondition:
|
||||
v := c.(*ExtCommunityCondition)
|
||||
cond.BgpConditions.MatchExtCommunitySet = config.MatchExtCommunitySet{ExtCommunitySet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]}
|
||||
case *LargeCommunityCondition:
|
||||
v := c.(*LargeCommunityCondition)
|
||||
cond.BgpConditions.MatchLargeCommunitySet = config.MatchLargeCommunitySet{LargeCommunitySet: v.set.Name(), MatchSetOptions: config.IntToMatchSetOptionsTypeMap[int(v.option)]}
|
||||
case *NextHopCondition:
|
||||
v := c.(*NextHopCondition)
|
||||
cond.BgpConditions.NextHopInList = v.set.List()
|
||||
case *RpkiValidationCondition:
|
||||
v := c.(*RpkiValidationCondition)
|
||||
cond.BgpConditions.RpkiValidationResult = v.result
|
||||
case *RouteTypeCondition:
|
||||
v := c.(*RouteTypeCondition)
|
||||
cond.BgpConditions.RouteType = v.typ
|
||||
case *AfiSafiInCondition:
|
||||
v := c.(*AfiSafiInCondition)
|
||||
res := make([]config.AfiSafiType, 0, len(v.routeFamilies))
|
||||
for _, rf := range v.routeFamilies {
|
||||
res = append(res, config.AfiSafiType(rf.String()))
|
||||
@@ -2741,21 +2705,21 @@ func (s *Statement) ToConfig() *config.Statement {
|
||||
act.RouteDisposition = config.ROUTE_DISPOSITION_NONE
|
||||
}
|
||||
for _, a := range s.ModActions {
|
||||
switch a.(type) {
|
||||
switch v := a.(type) {
|
||||
case *AsPathPrependAction:
|
||||
act.BgpActions.SetAsPathPrepend = *a.(*AsPathPrependAction).ToConfig()
|
||||
act.BgpActions.SetAsPathPrepend = *v.ToConfig()
|
||||
case *CommunityAction:
|
||||
act.BgpActions.SetCommunity = *a.(*CommunityAction).ToConfig()
|
||||
act.BgpActions.SetCommunity = *v.ToConfig()
|
||||
case *ExtCommunityAction:
|
||||
act.BgpActions.SetExtCommunity = *a.(*ExtCommunityAction).ToConfig()
|
||||
act.BgpActions.SetExtCommunity = *v.ToConfig()
|
||||
case *LargeCommunityAction:
|
||||
act.BgpActions.SetLargeCommunity = *a.(*LargeCommunityAction).ToConfig()
|
||||
act.BgpActions.SetLargeCommunity = *v.ToConfig()
|
||||
case *MedAction:
|
||||
act.BgpActions.SetMed = a.(*MedAction).ToConfig()
|
||||
act.BgpActions.SetMed = v.ToConfig()
|
||||
case *LocalPrefAction:
|
||||
act.BgpActions.SetLocalPref = a.(*LocalPrefAction).ToConfig()
|
||||
act.BgpActions.SetLocalPref = v.ToConfig()
|
||||
case *NexthopAction:
|
||||
act.BgpActions.SetNextHop = a.(*NexthopAction).ToConfig()
|
||||
act.BgpActions.SetNextHop = v.ToConfig()
|
||||
}
|
||||
}
|
||||
return act
|
||||
@@ -3114,9 +3078,6 @@ type RoutingPolicy struct {
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path, options *PolicyOptions) *Path {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
if before == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -3126,6 +3087,10 @@ func (r *RoutingPolicy) ApplyPolicy(id string, dir PolicyDirection, before *Path
|
||||
}
|
||||
result := ROUTE_TYPE_NONE
|
||||
after := before
|
||||
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
for _, p := range r.getPolicy(id, dir) {
|
||||
result, after = p.Apply(after, options)
|
||||
if result != ROUTE_TYPE_NONE {
|
||||
@@ -3408,13 +3373,13 @@ func (r *RoutingPolicy) reload(c config.RoutingPolicy) error {
|
||||
return err
|
||||
}
|
||||
if _, ok := pmap[y.Name]; ok {
|
||||
return fmt.Errorf("duplicated policy name. policy name must be unique.")
|
||||
return fmt.Errorf("duplicated policy name. policy name must be unique")
|
||||
}
|
||||
pmap[y.Name] = y
|
||||
for _, s := range y.Statements {
|
||||
_, ok := smap[s.Name]
|
||||
if ok {
|
||||
return fmt.Errorf("duplicated statement name. statement name must be unique.")
|
||||
return fmt.Errorf("duplicated statement name. statement name must be unique")
|
||||
}
|
||||
smap[s.Name] = s
|
||||
}
|
||||
@@ -3445,18 +3410,24 @@ func (r *RoutingPolicy) reload(c config.RoutingPolicy) error {
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*config.DefinedSets, error) {
|
||||
r.mu.RLock()
|
||||
dl, err := func() (DefinedSetList, error) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
set, ok := r.definedSetMap[typ]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid defined-set type: %d", typ)
|
||||
}
|
||||
set, ok := r.definedSetMap[typ]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid defined-set type: %d", typ)
|
||||
}
|
||||
|
||||
var dl DefinedSetList
|
||||
for _, s := range set {
|
||||
dl = append(dl, s)
|
||||
var dl DefinedSetList
|
||||
for _, s := range set {
|
||||
dl = append(dl, s)
|
||||
}
|
||||
return dl, nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.mu.RUnlock()
|
||||
|
||||
sort.Sort(dl)
|
||||
|
||||
@@ -3474,19 +3445,19 @@ func (r *RoutingPolicy) GetDefinedSet(typ DefinedType, name string) (*config.Def
|
||||
if name != "" && s.Name() != name {
|
||||
continue
|
||||
}
|
||||
switch s.(type) {
|
||||
switch v := s.(type) {
|
||||
case *PrefixSet:
|
||||
sets.PrefixSets = append(sets.PrefixSets, *s.(*PrefixSet).ToConfig())
|
||||
sets.PrefixSets = append(sets.PrefixSets, *v.ToConfig())
|
||||
case *NeighborSet:
|
||||
sets.NeighborSets = append(sets.NeighborSets, *s.(*NeighborSet).ToConfig())
|
||||
sets.NeighborSets = append(sets.NeighborSets, *v.ToConfig())
|
||||
case *CommunitySet:
|
||||
sets.BgpDefinedSets.CommunitySets = append(sets.BgpDefinedSets.CommunitySets, *s.(*CommunitySet).ToConfig())
|
||||
sets.BgpDefinedSets.CommunitySets = append(sets.BgpDefinedSets.CommunitySets, *v.ToConfig())
|
||||
case *ExtCommunitySet:
|
||||
sets.BgpDefinedSets.ExtCommunitySets = append(sets.BgpDefinedSets.ExtCommunitySets, *s.(*ExtCommunitySet).ToConfig())
|
||||
sets.BgpDefinedSets.ExtCommunitySets = append(sets.BgpDefinedSets.ExtCommunitySets, *v.ToConfig())
|
||||
case *LargeCommunitySet:
|
||||
sets.BgpDefinedSets.LargeCommunitySets = append(sets.BgpDefinedSets.LargeCommunitySets, *s.(*LargeCommunitySet).ToConfig())
|
||||
sets.BgpDefinedSets.LargeCommunitySets = append(sets.BgpDefinedSets.LargeCommunitySets, *v.ToConfig())
|
||||
case *AsPathSet:
|
||||
sets.BgpDefinedSets.AsPathSets = append(sets.BgpDefinedSets.AsPathSets, *s.(*AsPathSet).ToConfig())
|
||||
sets.BgpDefinedSets.AsPathSets = append(sets.BgpDefinedSets.AsPathSets, *v.ToConfig())
|
||||
}
|
||||
}
|
||||
return sets, nil
|
||||
@@ -3591,16 +3562,19 @@ func (r *RoutingPolicy) DeleteStatement(st *Statement, all bool) (err error) {
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) GetPolicy(name string) []*config.PolicyDefinition {
|
||||
r.mu.RLock()
|
||||
ps := func() Policies {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
var ps Policies
|
||||
for _, p := range r.policyMap {
|
||||
if name != "" && name != p.Name {
|
||||
continue
|
||||
var ps Policies
|
||||
for _, p := range r.policyMap {
|
||||
if name != "" && name != p.Name {
|
||||
continue
|
||||
}
|
||||
ps = append(ps, p)
|
||||
}
|
||||
ps = append(ps, p)
|
||||
}
|
||||
r.mu.RUnlock()
|
||||
return ps
|
||||
}()
|
||||
|
||||
sort.Sort(ps)
|
||||
|
||||
@@ -3827,32 +3801,59 @@ func (r *RoutingPolicy) SetPolicyAssignment(id string, dir PolicyDirection, poli
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) Reset(rp *config.RoutingPolicy, ap map[string]config.ApplyPolicy) error {
|
||||
func (r *RoutingPolicy) Initialize() error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if rp != nil {
|
||||
if err := r.reload(*rp); err != nil {
|
||||
if err := r.reload(config.RoutingPolicy{}); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Policy",
|
||||
}).Errorf("failed to create routing policy: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) setPeerPolicy(id string, c config.ApplyPolicy) {
|
||||
for _, dir := range []PolicyDirection{POLICY_DIRECTION_IMPORT, POLICY_DIRECTION_EXPORT} {
|
||||
ps, def, err := r.getAssignmentFromConfig(dir, c)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Policy",
|
||||
}).Errorf("failed to create routing policy: %s", err)
|
||||
return err
|
||||
"Dir": dir,
|
||||
}).Errorf("failed to get policy info: %s", err)
|
||||
continue
|
||||
}
|
||||
r.setDefaultPolicy(id, dir, def)
|
||||
r.setPolicy(id, dir, ps)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) SetPeerPolicy(peerId string, c config.ApplyPolicy) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
r.setPeerPolicy(peerId, c)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RoutingPolicy) Reset(rp *config.RoutingPolicy, ap map[string]config.ApplyPolicy) error {
|
||||
if rp == nil {
|
||||
return fmt.Errorf("routing Policy is nil in call to Reset")
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if err := r.reload(*rp); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Policy",
|
||||
}).Errorf("failed to create routing policy: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
for id, c := range ap {
|
||||
for _, dir := range []PolicyDirection{POLICY_DIRECTION_IMPORT, POLICY_DIRECTION_EXPORT} {
|
||||
ps, def, err := r.getAssignmentFromConfig(dir, c)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Policy",
|
||||
"Dir": dir,
|
||||
}).Errorf("failed to get policy info: %s", err)
|
||||
continue
|
||||
}
|
||||
r.setDefaultPolicy(id, dir, def)
|
||||
r.setPolicy(id, dir, ps)
|
||||
}
|
||||
r.setPeerPolicy(id, c)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -3893,3 +3894,237 @@ type PolicyAssignment struct {
|
||||
Policies []*Policy
|
||||
Default RouteType
|
||||
}
|
||||
|
||||
var _regexpMedActionType = regexp.MustCompile(`([+-]?)(\d+)`)
|
||||
|
||||
func toStatementApi(s *config.Statement) *api.Statement {
|
||||
cs := &api.Conditions{}
|
||||
o, _ := NewMatchOption(s.Conditions.MatchPrefixSet.MatchSetOptions)
|
||||
if s.Conditions.MatchPrefixSet.PrefixSet != "" {
|
||||
cs.PrefixSet = &api.MatchSet{
|
||||
MatchType: api.MatchType(o),
|
||||
Name: s.Conditions.MatchPrefixSet.PrefixSet,
|
||||
}
|
||||
}
|
||||
if s.Conditions.MatchNeighborSet.NeighborSet != "" {
|
||||
o, _ := NewMatchOption(s.Conditions.MatchNeighborSet.MatchSetOptions)
|
||||
cs.NeighborSet = &api.MatchSet{
|
||||
MatchType: api.MatchType(o),
|
||||
Name: s.Conditions.MatchNeighborSet.NeighborSet,
|
||||
}
|
||||
}
|
||||
if s.Conditions.BgpConditions.AsPathLength.Operator != "" {
|
||||
cs.AsPathLength = &api.AsPathLength{
|
||||
Length: s.Conditions.BgpConditions.AsPathLength.Value,
|
||||
LengthType: api.AsPathLengthType(s.Conditions.BgpConditions.AsPathLength.Operator.ToInt()),
|
||||
}
|
||||
}
|
||||
if s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet != "" {
|
||||
cs.AsPathSet = &api.MatchSet{
|
||||
MatchType: api.MatchType(s.Conditions.BgpConditions.MatchAsPathSet.MatchSetOptions.ToInt()),
|
||||
Name: s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet,
|
||||
}
|
||||
}
|
||||
if s.Conditions.BgpConditions.MatchCommunitySet.CommunitySet != "" {
|
||||
cs.CommunitySet = &api.MatchSet{
|
||||
MatchType: api.MatchType(s.Conditions.BgpConditions.MatchCommunitySet.MatchSetOptions.ToInt()),
|
||||
Name: s.Conditions.BgpConditions.MatchCommunitySet.CommunitySet,
|
||||
}
|
||||
}
|
||||
if s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet != "" {
|
||||
cs.ExtCommunitySet = &api.MatchSet{
|
||||
MatchType: api.MatchType(s.Conditions.BgpConditions.MatchExtCommunitySet.MatchSetOptions.ToInt()),
|
||||
Name: s.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet,
|
||||
}
|
||||
}
|
||||
if s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet != "" {
|
||||
cs.LargeCommunitySet = &api.MatchSet{
|
||||
MatchType: api.MatchType(s.Conditions.BgpConditions.MatchLargeCommunitySet.MatchSetOptions.ToInt()),
|
||||
Name: s.Conditions.BgpConditions.MatchLargeCommunitySet.LargeCommunitySet,
|
||||
}
|
||||
}
|
||||
if s.Conditions.BgpConditions.RouteType != "" {
|
||||
cs.RouteType = api.Conditions_RouteType(s.Conditions.BgpConditions.RouteType.ToInt())
|
||||
}
|
||||
if len(s.Conditions.BgpConditions.NextHopInList) > 0 {
|
||||
cs.NextHopInList = s.Conditions.BgpConditions.NextHopInList
|
||||
}
|
||||
if s.Conditions.BgpConditions.AfiSafiInList != nil {
|
||||
afiSafiIn := make([]*api.Family, 0)
|
||||
for _, afiSafiType := range s.Conditions.BgpConditions.AfiSafiInList {
|
||||
if mapped, ok := bgp.AddressFamilyValueMap[string(afiSafiType)]; ok {
|
||||
afi, safi := bgp.RouteFamilyToAfiSafi(mapped)
|
||||
afiSafiIn = append(afiSafiIn, &api.Family{Afi: api.Family_Afi(afi), Safi: api.Family_Safi(safi)})
|
||||
}
|
||||
}
|
||||
cs.AfiSafiIn = afiSafiIn
|
||||
}
|
||||
cs.RpkiResult = int32(s.Conditions.BgpConditions.RpkiValidationResult.ToInt())
|
||||
as := &api.Actions{
|
||||
RouteAction: func() api.RouteAction {
|
||||
switch s.Actions.RouteDisposition {
|
||||
case config.ROUTE_DISPOSITION_ACCEPT_ROUTE:
|
||||
return api.RouteAction_ACCEPT
|
||||
case config.ROUTE_DISPOSITION_REJECT_ROUTE:
|
||||
return api.RouteAction_REJECT
|
||||
}
|
||||
return api.RouteAction_NONE
|
||||
}(),
|
||||
Community: func() *api.CommunityAction {
|
||||
if len(s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &api.CommunityAction{
|
||||
ActionType: api.CommunityActionType(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetCommunity.Options)]),
|
||||
Communities: s.Actions.BgpActions.SetCommunity.SetCommunityMethod.CommunitiesList}
|
||||
}(),
|
||||
Med: func() *api.MedAction {
|
||||
medStr := strings.TrimSpace(string(s.Actions.BgpActions.SetMed))
|
||||
if len(medStr) == 0 {
|
||||
return nil
|
||||
}
|
||||
matches := _regexpMedActionType.FindStringSubmatch(medStr)
|
||||
if len(matches) == 0 {
|
||||
return nil
|
||||
}
|
||||
action := api.MedActionType_MED_REPLACE
|
||||
switch matches[1] {
|
||||
case "+", "-":
|
||||
action = api.MedActionType_MED_MOD
|
||||
}
|
||||
value, err := strconv.ParseInt(matches[1]+matches[2], 10, 64)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return &api.MedAction{
|
||||
Value: value,
|
||||
ActionType: action,
|
||||
}
|
||||
}(),
|
||||
AsPrepend: func() *api.AsPrependAction {
|
||||
if len(s.Actions.BgpActions.SetAsPathPrepend.As) == 0 {
|
||||
return nil
|
||||
}
|
||||
var asn uint64
|
||||
useleft := false
|
||||
if s.Actions.BgpActions.SetAsPathPrepend.As != "last-as" {
|
||||
asn, _ = strconv.ParseUint(s.Actions.BgpActions.SetAsPathPrepend.As, 10, 32)
|
||||
} else {
|
||||
useleft = true
|
||||
}
|
||||
return &api.AsPrependAction{
|
||||
Asn: uint32(asn),
|
||||
Repeat: uint32(s.Actions.BgpActions.SetAsPathPrepend.RepeatN),
|
||||
UseLeftMost: useleft,
|
||||
}
|
||||
}(),
|
||||
ExtCommunity: func() *api.CommunityAction {
|
||||
if len(s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.CommunitiesList) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &api.CommunityAction{
|
||||
ActionType: api.CommunityActionType(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetExtCommunity.Options)]),
|
||||
Communities: s.Actions.BgpActions.SetExtCommunity.SetExtCommunityMethod.CommunitiesList,
|
||||
}
|
||||
}(),
|
||||
LargeCommunity: func() *api.CommunityAction {
|
||||
if len(s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &api.CommunityAction{
|
||||
ActionType: api.CommunityActionType(config.BgpSetCommunityOptionTypeToIntMap[config.BgpSetCommunityOptionType(s.Actions.BgpActions.SetLargeCommunity.Options)]),
|
||||
Communities: s.Actions.BgpActions.SetLargeCommunity.SetLargeCommunityMethod.CommunitiesList,
|
||||
}
|
||||
}(),
|
||||
Nexthop: func() *api.NexthopAction {
|
||||
if len(string(s.Actions.BgpActions.SetNextHop)) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if string(s.Actions.BgpActions.SetNextHop) == "self" {
|
||||
return &api.NexthopAction{
|
||||
Self: true,
|
||||
}
|
||||
}
|
||||
return &api.NexthopAction{
|
||||
Address: string(s.Actions.BgpActions.SetNextHop),
|
||||
}
|
||||
}(),
|
||||
LocalPref: func() *api.LocalPrefAction {
|
||||
if s.Actions.BgpActions.SetLocalPref == 0 {
|
||||
return nil
|
||||
}
|
||||
return &api.LocalPrefAction{Value: s.Actions.BgpActions.SetLocalPref}
|
||||
}(),
|
||||
}
|
||||
return &api.Statement{
|
||||
Name: s.Name,
|
||||
Conditions: cs,
|
||||
Actions: as,
|
||||
}
|
||||
}
|
||||
|
||||
func NewAPIPolicyFromTableStruct(p *Policy) *api.Policy {
|
||||
return ToPolicyApi(p.ToConfig())
|
||||
}
|
||||
|
||||
func ToPolicyApi(p *config.PolicyDefinition) *api.Policy {
|
||||
return &api.Policy{
|
||||
Name: p.Name,
|
||||
Statements: func() []*api.Statement {
|
||||
l := make([]*api.Statement, 0)
|
||||
for _, s := range p.Statements {
|
||||
l = append(l, toStatementApi(&s))
|
||||
}
|
||||
return l
|
||||
}(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewAPIPolicyAssignmentFromTableStruct(t *PolicyAssignment) *api.PolicyAssignment {
|
||||
return &api.PolicyAssignment{
|
||||
Direction: func() api.PolicyDirection {
|
||||
switch t.Type {
|
||||
case POLICY_DIRECTION_IMPORT:
|
||||
return api.PolicyDirection_IMPORT
|
||||
case POLICY_DIRECTION_EXPORT:
|
||||
return api.PolicyDirection_EXPORT
|
||||
}
|
||||
log.Errorf("invalid policy-type: %s", t.Type)
|
||||
return api.PolicyDirection_UNKNOWN
|
||||
}(),
|
||||
DefaultAction: func() api.RouteAction {
|
||||
switch t.Default {
|
||||
case ROUTE_TYPE_ACCEPT:
|
||||
return api.RouteAction_ACCEPT
|
||||
case ROUTE_TYPE_REJECT:
|
||||
return api.RouteAction_REJECT
|
||||
}
|
||||
return api.RouteAction_NONE
|
||||
}(),
|
||||
Name: t.Name,
|
||||
Policies: func() []*api.Policy {
|
||||
l := make([]*api.Policy, 0)
|
||||
for _, p := range t.Policies {
|
||||
l = append(l, NewAPIPolicyFromTableStruct(p))
|
||||
}
|
||||
return l
|
||||
}(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewAPIRoutingPolicyFromConfigStruct(c *config.RoutingPolicy) (*api.RoutingPolicy, error) {
|
||||
definedSets, err := config.NewAPIDefinedSetsFromConfigStruct(&c.DefinedSets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policies := make([]*api.Policy, 0, len(c.PolicyDefinitions))
|
||||
for _, policy := range c.PolicyDefinitions {
|
||||
policies = append(policies, ToPolicyApi(&policy))
|
||||
}
|
||||
|
||||
return &api.RoutingPolicy{
|
||||
DefinedSets: definedSets,
|
||||
Policies: policies,
|
||||
}, nil
|
||||
}
|
||||
|
||||
275
vendor/github.com/osrg/gobgp/internal/pkg/table/roa.go
generated
vendored
275
vendor/github.com/osrg/gobgp/internal/pkg/table/roa.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2016 Nippon Telegraph and Telephone Corporation.
|
||||
// Copyright (C) 2016-2019 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.
|
||||
@@ -16,35 +16,35 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
|
||||
"github.com/k-sone/critbitgo"
|
||||
"github.com/osrg/gobgp/internal/pkg/config"
|
||||
"github.com/osrg/gobgp/pkg/packet/bgp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type IPPrefix struct {
|
||||
Prefix net.IP
|
||||
Length uint8
|
||||
}
|
||||
|
||||
func (p *IPPrefix) String() string {
|
||||
return fmt.Sprintf("%s/%d", p.Prefix, p.Length)
|
||||
}
|
||||
|
||||
type ROA struct {
|
||||
Family int
|
||||
Prefix *IPPrefix
|
||||
MaxLen uint8
|
||||
AS uint32
|
||||
Src string
|
||||
Family int
|
||||
Network *net.IPNet
|
||||
MaxLen uint8
|
||||
AS uint32
|
||||
Src string
|
||||
}
|
||||
|
||||
func NewROA(family int, prefixByte []byte, prefixLen uint8, maxLen uint8, as uint32, src string) *ROA {
|
||||
p := make([]byte, len(prefixByte))
|
||||
bits := net.IPv4len * 8
|
||||
if family == bgp.AFI_IP6 {
|
||||
bits = net.IPv6len * 8
|
||||
}
|
||||
copy(p, prefixByte)
|
||||
return &ROA{
|
||||
Family: family,
|
||||
Prefix: &IPPrefix{
|
||||
Prefix: p,
|
||||
Length: prefixLen,
|
||||
Network: &net.IPNet{
|
||||
IP: p,
|
||||
Mask: net.CIDRMask(int(prefixLen), bits),
|
||||
},
|
||||
MaxLen: maxLen,
|
||||
AS: as,
|
||||
@@ -58,3 +58,240 @@ func (r *ROA) Equal(roa *ROA) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type roaBucket struct {
|
||||
network *net.IPNet
|
||||
entries []*ROA
|
||||
}
|
||||
|
||||
func (r *roaBucket) GetEntries() []*ROA {
|
||||
return r.entries
|
||||
}
|
||||
|
||||
type ROATable struct {
|
||||
trees map[bgp.RouteFamily]*critbitgo.Net
|
||||
}
|
||||
|
||||
func NewROATable() *ROATable {
|
||||
m := make(map[bgp.RouteFamily]*critbitgo.Net)
|
||||
m[bgp.RF_IPv4_UC] = critbitgo.NewNet()
|
||||
m[bgp.RF_IPv6_UC] = critbitgo.NewNet()
|
||||
return &ROATable{
|
||||
trees: m,
|
||||
}
|
||||
}
|
||||
|
||||
func (rt *ROATable) roa2tree(roa *ROA) *critbitgo.Net {
|
||||
tree := rt.trees[bgp.RF_IPv4_UC]
|
||||
if roa.Family == bgp.AFI_IP6 {
|
||||
tree = rt.trees[bgp.RF_IPv6_UC]
|
||||
}
|
||||
return tree
|
||||
}
|
||||
|
||||
func (rt *ROATable) getBucket(roa *ROA) *roaBucket {
|
||||
tree := rt.roa2tree(roa)
|
||||
b, ok, _ := tree.Get(roa.Network)
|
||||
if !ok {
|
||||
b := &roaBucket{
|
||||
network: roa.Network,
|
||||
entries: make([]*ROA, 0),
|
||||
}
|
||||
tree.Add(roa.Network, b)
|
||||
return b
|
||||
}
|
||||
return b.(*roaBucket)
|
||||
}
|
||||
|
||||
func (rt *ROATable) Add(roa *ROA) {
|
||||
b := rt.getBucket(roa)
|
||||
for _, r := range b.entries {
|
||||
if r.Equal(roa) {
|
||||
// we already have the same one
|
||||
return
|
||||
}
|
||||
}
|
||||
b.entries = append(b.entries, roa)
|
||||
sort.Slice(b.entries, func(i, j int) bool {
|
||||
r1 := b.entries[i]
|
||||
r2 := b.entries[j]
|
||||
|
||||
if r1.MaxLen < r2.MaxLen {
|
||||
return true
|
||||
} else if r1.MaxLen > r2.MaxLen {
|
||||
return false
|
||||
}
|
||||
|
||||
if r1.AS < r2.AS {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
func (rt *ROATable) Delete(roa *ROA) {
|
||||
tree := rt.roa2tree(roa)
|
||||
if b, ok, _ := tree.Get(roa.Network); ok {
|
||||
bucket := b.(*roaBucket)
|
||||
for i, r := range bucket.entries {
|
||||
if r.Equal(roa) {
|
||||
bucket.entries = append(bucket.entries[:i], bucket.entries[i+1:]...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "rpki",
|
||||
"Network": roa.Network.String(),
|
||||
"AS": roa.AS,
|
||||
"Max Length": roa.MaxLen,
|
||||
}).Info("Can't withdraw a ROA")
|
||||
}
|
||||
|
||||
func (rt *ROATable) DeleteAll(network string) {
|
||||
for _, tree := range rt.trees {
|
||||
deleteNetworks := make([]*net.IPNet, 0, tree.Size())
|
||||
tree.Walk(nil, func(n *net.IPNet, v interface{}) bool {
|
||||
b, _ := v.(*roaBucket)
|
||||
newEntries := make([]*ROA, 0, len(b.entries))
|
||||
for _, r := range b.entries {
|
||||
if r.Src != network {
|
||||
newEntries = append(newEntries, r)
|
||||
}
|
||||
}
|
||||
if len(newEntries) > 0 {
|
||||
b.entries = newEntries
|
||||
} else {
|
||||
deleteNetworks = append(deleteNetworks, n)
|
||||
}
|
||||
return true
|
||||
})
|
||||
for _, key := range deleteNetworks {
|
||||
tree.Delete(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (rt *ROATable) Validate(path *Path) *Validation {
|
||||
if path.IsWithdraw || path.IsEOR() {
|
||||
// RPKI isn't enabled or invalid path
|
||||
return nil
|
||||
}
|
||||
tree, ok := rt.trees[path.GetRouteFamily()]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
ownAs := path.OriginInfo().source.LocalAS
|
||||
asPath := path.GetAsPath()
|
||||
var as uint32
|
||||
|
||||
validation := &Validation{
|
||||
Status: config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND,
|
||||
Reason: RPKI_VALIDATION_REASON_TYPE_NONE,
|
||||
Matched: make([]*ROA, 0),
|
||||
UnmatchedLength: make([]*ROA, 0),
|
||||
UnmatchedAs: make([]*ROA, 0),
|
||||
}
|
||||
|
||||
if asPath == nil || len(asPath.Value) == 0 {
|
||||
as = ownAs
|
||||
} else {
|
||||
param := asPath.Value[len(asPath.Value)-1]
|
||||
switch param.GetType() {
|
||||
case bgp.BGP_ASPATH_ATTR_TYPE_SEQ:
|
||||
asList := param.GetAS()
|
||||
if len(asList) == 0 {
|
||||
as = ownAs
|
||||
} else {
|
||||
as = asList[len(asList)-1]
|
||||
}
|
||||
case bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET, bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ:
|
||||
as = ownAs
|
||||
default:
|
||||
return validation
|
||||
}
|
||||
}
|
||||
|
||||
r := nlriToIPNet(path.GetNlri())
|
||||
prefixLen, _ := r.Mask.Size()
|
||||
var bucket *roaBucket
|
||||
tree.WalkMatch(r, func(r *net.IPNet, v interface{}) bool {
|
||||
bucket, _ = v.(*roaBucket)
|
||||
for _, r := range bucket.entries {
|
||||
if prefixLen <= int(r.MaxLen) {
|
||||
if r.AS != 0 && r.AS == as {
|
||||
validation.Matched = append(validation.Matched, r)
|
||||
} else {
|
||||
validation.UnmatchedAs = append(validation.UnmatchedAs, r)
|
||||
}
|
||||
} else {
|
||||
validation.UnmatchedLength = append(validation.UnmatchedLength, r)
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if len(validation.Matched) != 0 {
|
||||
validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_VALID
|
||||
validation.Reason = RPKI_VALIDATION_REASON_TYPE_NONE
|
||||
} else if len(validation.UnmatchedAs) != 0 {
|
||||
validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_INVALID
|
||||
validation.Reason = RPKI_VALIDATION_REASON_TYPE_AS
|
||||
} else if len(validation.UnmatchedLength) != 0 {
|
||||
validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_INVALID
|
||||
validation.Reason = RPKI_VALIDATION_REASON_TYPE_LENGTH
|
||||
} else {
|
||||
validation.Status = config.RPKI_VALIDATION_RESULT_TYPE_NOT_FOUND
|
||||
validation.Reason = RPKI_VALIDATION_REASON_TYPE_NONE
|
||||
}
|
||||
|
||||
return validation
|
||||
}
|
||||
|
||||
func (rt *ROATable) Info(family bgp.RouteFamily) (map[string]uint32, map[string]uint32) {
|
||||
records := make(map[string]uint32)
|
||||
prefixes := make(map[string]uint32)
|
||||
|
||||
if tree, ok := rt.trees[family]; ok {
|
||||
tree.Walk(nil, func(_ *net.IPNet, v interface{}) bool {
|
||||
b, _ := v.(*roaBucket)
|
||||
tmpRecords := make(map[string]uint32)
|
||||
for _, roa := range b.entries {
|
||||
tmpRecords[roa.Src]++
|
||||
}
|
||||
|
||||
for src, r := range tmpRecords {
|
||||
if r > 0 {
|
||||
records[src] += r
|
||||
prefixes[src]++
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
return records, prefixes
|
||||
}
|
||||
|
||||
func (rt *ROATable) List(family bgp.RouteFamily) ([]*ROA, error) {
|
||||
var rfList []bgp.RouteFamily
|
||||
switch family {
|
||||
case bgp.RF_IPv4_UC:
|
||||
rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC}
|
||||
case bgp.RF_IPv6_UC:
|
||||
rfList = []bgp.RouteFamily{bgp.RF_IPv6_UC}
|
||||
default:
|
||||
rfList = []bgp.RouteFamily{bgp.RF_IPv4_UC, bgp.RF_IPv6_UC}
|
||||
}
|
||||
l := make([]*ROA, 0)
|
||||
for _, rf := range rfList {
|
||||
if tree, ok := rt.trees[rf]; ok {
|
||||
tree.Walk(nil, func(_ *net.IPNet, v interface{}) bool {
|
||||
b, _ := v.(*roaBucket)
|
||||
l = append(l, b.entries...)
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
return l, nil
|
||||
}
|
||||
|
||||
81
vendor/github.com/osrg/gobgp/internal/pkg/table/table.go
generated
vendored
81
vendor/github.com/osrg/gobgp/internal/pkg/table/table.go
generated
vendored
@@ -17,11 +17,12 @@ package table
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/bits"
|
||||
"net"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/armon/go-radix"
|
||||
"github.com/k-sone/critbitgo"
|
||||
"github.com/osrg/gobgp/pkg/packet/bgp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -75,13 +76,13 @@ func (t *Table) deletePathsByVrf(vrf *Vrf) []*Path {
|
||||
for _, p := range dest.knownPathList {
|
||||
var rd bgp.RouteDistinguisherInterface
|
||||
nlri := p.GetNlri()
|
||||
switch nlri.(type) {
|
||||
switch v := nlri.(type) {
|
||||
case *bgp.LabeledVPNIPAddrPrefix:
|
||||
rd = nlri.(*bgp.LabeledVPNIPAddrPrefix).RD
|
||||
rd = v.RD
|
||||
case *bgp.LabeledVPNIPv6AddrPrefix:
|
||||
rd = nlri.(*bgp.LabeledVPNIPv6AddrPrefix).RD
|
||||
rd = v.RD
|
||||
case *bgp.EVPNNLRI:
|
||||
rd = nlri.(*bgp.EVPNNLRI).RD()
|
||||
rd = v.RD()
|
||||
default:
|
||||
return pathList
|
||||
}
|
||||
@@ -117,15 +118,14 @@ func (t *Table) deleteRTCPathsByVrf(vrf *Vrf, vrfs map[string]*Vrf) []*Path {
|
||||
return pathList
|
||||
}
|
||||
|
||||
func (t *Table) deleteDestByNlri(nlri bgp.AddrPrefixInterface) *Destination {
|
||||
if dst := t.GetDestination(nlri); dst != nil {
|
||||
t.deleteDest(dst)
|
||||
return dst
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Table) deleteDest(dest *Destination) {
|
||||
count := 0
|
||||
for _, v := range dest.localIdMap.bitmap {
|
||||
count += bits.OnesCount64(v)
|
||||
}
|
||||
if len(dest.localIdMap.bitmap) != 0 && count != 1 {
|
||||
return
|
||||
}
|
||||
destinations := t.GetDestinations()
|
||||
delete(destinations, t.tableKey(dest.GetNlri()))
|
||||
if len(destinations) == 0 {
|
||||
@@ -175,7 +175,7 @@ func (t *Table) validatePath(path *Path) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Table) getOrCreateDest(nlri bgp.AddrPrefixInterface) *Destination {
|
||||
func (t *Table) getOrCreateDest(nlri bgp.AddrPrefixInterface, size int) *Destination {
|
||||
dest := t.GetDestination(nlri)
|
||||
// If destination for given prefix does not exist we create it.
|
||||
if dest == nil {
|
||||
@@ -183,7 +183,7 @@ func (t *Table) getOrCreateDest(nlri bgp.AddrPrefixInterface) *Destination {
|
||||
"Topic": "Table",
|
||||
"Nlri": nlri,
|
||||
}).Debugf("create Destination")
|
||||
dest = NewDestination(nlri, 64)
|
||||
dest = NewDestination(nlri, size)
|
||||
t.setDestination(dest)
|
||||
}
|
||||
return dest
|
||||
@@ -212,14 +212,13 @@ func (t *Table) GetLongerPrefixDestinations(key string) ([]*Destination, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
k := CidrToRadixkey(prefix.String())
|
||||
r := radix.New()
|
||||
r := critbitgo.NewNet()
|
||||
for _, dst := range t.GetDestinations() {
|
||||
r.Insert(AddrToRadixkey(dst.nlri), dst)
|
||||
r.Add(nlriToIPNet(dst.nlri), dst)
|
||||
}
|
||||
r.WalkPrefix(k, func(s string, v interface{}) bool {
|
||||
r.WalkPrefix(prefix, func(_ *net.IPNet, v interface{}) bool {
|
||||
results = append(results, v.(*Destination))
|
||||
return false
|
||||
return true
|
||||
})
|
||||
default:
|
||||
for _, dst := range t.GetDestinations() {
|
||||
@@ -435,13 +434,45 @@ type TableInfo struct {
|
||||
NumAccepted int
|
||||
}
|
||||
|
||||
func (t *Table) Info(id string, as uint32) *TableInfo {
|
||||
type TableInfoOptions struct {
|
||||
ID string
|
||||
AS uint32
|
||||
VRF *Vrf
|
||||
}
|
||||
|
||||
func (t *Table) Info(option ...TableInfoOptions) *TableInfo {
|
||||
var numD, numP int
|
||||
|
||||
id := GLOBAL_RIB_NAME
|
||||
var vrf *Vrf
|
||||
as := uint32(0)
|
||||
|
||||
for _, o := range option {
|
||||
if o.ID != "" {
|
||||
id = o.ID
|
||||
}
|
||||
if o.VRF != nil {
|
||||
vrf = o.VRF
|
||||
}
|
||||
as = o.AS
|
||||
}
|
||||
|
||||
for _, d := range t.destinations {
|
||||
ps := d.GetKnownPathList(id, as)
|
||||
if len(ps) > 0 {
|
||||
numD += 1
|
||||
numP += len(ps)
|
||||
paths := d.GetKnownPathList(id, as)
|
||||
n := len(paths)
|
||||
|
||||
if vrf != nil {
|
||||
ps := make([]*Path, 0, len(paths))
|
||||
for _, p := range paths {
|
||||
if CanImportToVrf(vrf, p) {
|
||||
ps = append(ps, p.ToLocal())
|
||||
}
|
||||
}
|
||||
n = len(ps)
|
||||
}
|
||||
if n != 0 {
|
||||
numD++
|
||||
numP += n
|
||||
}
|
||||
}
|
||||
return &TableInfo{
|
||||
|
||||
56
vendor/github.com/osrg/gobgp/internal/pkg/table/table_manager.go
generated
vendored
56
vendor/github.com/osrg/gobgp/internal/pkg/table/table_manager.go
generated
vendored
@@ -166,11 +166,12 @@ func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) {
|
||||
msgs = append(msgs, t.deletePathsByVrf(vrf)...)
|
||||
}
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Vrf",
|
||||
"Key": vrf.Name,
|
||||
"Rd": vrf.Rd,
|
||||
"ImportRt": vrf.ImportRt,
|
||||
"ExportRt": vrf.ExportRt,
|
||||
"Topic": "Vrf",
|
||||
"Key": vrf.Name,
|
||||
"Rd": vrf.Rd,
|
||||
"ImportRt": vrf.ImportRt,
|
||||
"ExportRt": vrf.ExportRt,
|
||||
"MplsLabel": vrf.MplsLabel,
|
||||
}).Debugf("delete vrf")
|
||||
delete(manager.Vrfs, name)
|
||||
rtcTable := manager.Tables[bgp.RF_RTC_UC]
|
||||
@@ -181,7 +182,7 @@ func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) {
|
||||
func (tm *TableManager) update(newPath *Path) *Update {
|
||||
t := tm.Tables[newPath.GetRouteFamily()]
|
||||
t.validatePath(newPath)
|
||||
dst := t.getOrCreateDest(newPath.GetNlri())
|
||||
dst := t.getOrCreateDest(newPath.GetNlri(), 64)
|
||||
u := dst.Calculate(newPath)
|
||||
if len(dst.knownPathList) == 0 {
|
||||
t.deleteDest(dst)
|
||||
@@ -189,21 +190,6 @@ func (tm *TableManager) update(newPath *Path) *Update {
|
||||
return u
|
||||
}
|
||||
|
||||
func (manager *TableManager) GetPathListByPeer(info *PeerInfo, rf bgp.RouteFamily) []*Path {
|
||||
if t, ok := manager.Tables[rf]; ok {
|
||||
pathList := make([]*Path, 0, len(t.destinations))
|
||||
for _, dst := range t.destinations {
|
||||
for _, p := range dst.knownPathList {
|
||||
if p.GetSource().Equal(info) {
|
||||
pathList = append(pathList, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
return pathList
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *TableManager) Update(newPath *Path) []*Update {
|
||||
if newPath == nil || newPath.IsEOR() {
|
||||
return nil
|
||||
@@ -232,6 +218,12 @@ func (manager *TableManager) Update(newPath *Path) []*Update {
|
||||
// different Ethernet segment identifier and a higher sequence number
|
||||
// than that which it had previously advertised withdraws its MAC/IP
|
||||
// Advertisement route.
|
||||
// ......
|
||||
// If the PE is the originator of the MAC route and it receives the same
|
||||
// MAC address with the same sequence number that it generated, it will
|
||||
// compare its own IP address with the IP address of the remote PE and
|
||||
// will select the lowest IP. If its own route is not the best one, it
|
||||
// will withdraw the route.
|
||||
func (manager *TableManager) handleMacMobility(path *Path) []*Path {
|
||||
pathList := make([]*Path, 0)
|
||||
nlri := path.GetNlri().(*bgp.EVPNNLRI)
|
||||
@@ -242,7 +234,7 @@ func (manager *TableManager) handleMacMobility(path *Path) []*Path {
|
||||
if !path2.IsLocal() || path2.GetNlri().(*bgp.EVPNNLRI).RouteType != bgp.EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT {
|
||||
continue
|
||||
}
|
||||
f := func(p *Path) (bgp.EthernetSegmentIdentifier, net.HardwareAddr, int) {
|
||||
f := func(p *Path) (bgp.EthernetSegmentIdentifier, uint32, net.HardwareAddr, int, net.IP) {
|
||||
nlri := p.GetNlri().(*bgp.EVPNNLRI)
|
||||
d := nlri.RouteTypeData.(*bgp.EVPNMacIPAdvertisementRoute)
|
||||
ecs := p.GetExtCommunities()
|
||||
@@ -253,12 +245,14 @@ func (manager *TableManager) handleMacMobility(path *Path) []*Path {
|
||||
break
|
||||
}
|
||||
}
|
||||
return d.ESI, d.MacAddress, seq
|
||||
return d.ESI, d.ETag, d.MacAddress, seq, p.info.source.Address
|
||||
}
|
||||
e1, m1, s1 := f(path)
|
||||
e2, m2, s2 := f(path2)
|
||||
if bytes.Equal(m1, m2) && !bytes.Equal(e1.Value, e2.Value) && s1 > s2 {
|
||||
pathList = append(pathList, path2.Clone(true))
|
||||
e1, et1, m1, s1, i1 := f(path)
|
||||
e2, et2, m2, s2, i2 := f(path2)
|
||||
if et1 == et2 && bytes.Equal(m1, m2) && !bytes.Equal(e1.Value, e2.Value) {
|
||||
if s1 > s2 || s1 == s2 && bytes.Compare(i1, i2) < 0 {
|
||||
pathList = append(pathList, path2.Clone(true))
|
||||
}
|
||||
}
|
||||
}
|
||||
return pathList
|
||||
@@ -360,11 +354,3 @@ func (manager *TableManager) GetDestination(path *Path) *Destination {
|
||||
}
|
||||
return t.GetDestination(path.GetNlri())
|
||||
}
|
||||
|
||||
func (manager *TableManager) TableInfo(id string, as uint32, family bgp.RouteFamily) (*TableInfo, error) {
|
||||
t, ok := manager.Tables[family]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("address family %s is not configured", family)
|
||||
}
|
||||
return t.Info(id, as), nil
|
||||
}
|
||||
|
||||
22
vendor/github.com/osrg/gobgp/internal/pkg/table/vrf.go
generated
vendored
22
vendor/github.com/osrg/gobgp/internal/pkg/table/vrf.go
generated
vendored
@@ -20,11 +20,12 @@ import (
|
||||
)
|
||||
|
||||
type Vrf struct {
|
||||
Name string
|
||||
Id uint32
|
||||
Rd bgp.RouteDistinguisherInterface
|
||||
ImportRt []bgp.ExtendedCommunityInterface
|
||||
ExportRt []bgp.ExtendedCommunityInterface
|
||||
Name string
|
||||
Id uint32
|
||||
Rd bgp.RouteDistinguisherInterface
|
||||
ImportRt []bgp.ExtendedCommunityInterface
|
||||
ExportRt []bgp.ExtendedCommunityInterface
|
||||
MplsLabel uint32
|
||||
}
|
||||
|
||||
func (v *Vrf) Clone() *Vrf {
|
||||
@@ -33,11 +34,12 @@ func (v *Vrf) Clone() *Vrf {
|
||||
return append(l, rt...)
|
||||
}
|
||||
return &Vrf{
|
||||
Name: v.Name,
|
||||
Id: v.Id,
|
||||
Rd: v.Rd,
|
||||
ImportRt: f(v.ImportRt),
|
||||
ExportRt: f(v.ExportRt),
|
||||
Name: v.Name,
|
||||
Id: v.Id,
|
||||
Rd: v.Rd,
|
||||
ImportRt: f(v.ImportRt),
|
||||
ExportRt: f(v.ExportRt),
|
||||
MplsLabel: v.MplsLabel,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
vendor/github.com/osrg/gobgp/internal/pkg/zebra/afi_string.go
generated
vendored
32
vendor/github.com/osrg/gobgp/internal/pkg/zebra/afi_string.go
generated
vendored
@@ -1,17 +1,27 @@
|
||||
// Code generated by "stringer -type=AFI"; DO NOT EDIT.
|
||||
// Code generated by "stringer -type=afi"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _AFI_name = "AFI_IPAFI_IP6AFI_ETHERAFI_MAX"
|
||||
|
||||
var _AFI_index = [...]uint8{0, 6, 13, 22, 29}
|
||||
|
||||
func (i AFI) String() string {
|
||||
i -= 1
|
||||
if i >= AFI(len(_AFI_index)-1) {
|
||||
return "AFI(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _AFI_name[_AFI_index[i]:_AFI_index[i+1]]
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[afiIP-1]
|
||||
_ = x[afiIP6-2]
|
||||
_ = x[afiEther-3]
|
||||
_ = x[afiMax-4]
|
||||
}
|
||||
|
||||
const _afi_name = "afiIPafiIP6afiEtherafiMax"
|
||||
|
||||
var _afi_index = [...]uint8{0, 5, 11, 19, 25}
|
||||
|
||||
func (i afi) String() string {
|
||||
i -= 1
|
||||
if i >= afi(len(_afi_index)-1) {
|
||||
return "afi(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _afi_name[_afi_index[i]:_afi_index[i+1]]
|
||||
}
|
||||
|
||||
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/api_type_string.go
generated
vendored
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/api_type_string.go
generated
vendored
@@ -1,16 +0,0 @@
|
||||
// Code generated by "stringer -type=API_TYPE"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _API_TYPE_name = "FRR_ZAPI5_INTERFACE_ADDFRR_ZAPI5_INTERFACE_DELETEFRR_ZAPI5_INTERFACE_ADDRESS_ADDFRR_ZAPI5_INTERFACE_ADDRESS_DELETEFRR_ZAPI5_INTERFACE_UPFRR_ZAPI5_INTERFACE_DOWNFRR_ZAPI5_INTERFACE_SET_MASTERFRR_ZAPI5_ROUTE_ADDFRR_ZAPI5_ROUTE_DELETEFRR_ZAPI5_ROUTE_NOTIFY_OWNERFRR_ZAPI5_IPV4_ROUTE_ADDFRR_ZAPI5_IPV4_ROUTE_DELETEFRR_ZAPI5_IPV6_ROUTE_ADDFRR_ZAPI5_IPV6_ROUTE_DELETEFRR_ZAPI5_REDISTRIBUTE_ADDFRR_ZAPI5_REDISTRIBUTE_DELETEFRR_ZAPI5_REDISTRIBUTE_DEFAULT_ADDFRR_ZAPI5_REDISTRIBUTE_DEFAULT_DELETEFRR_ZAPI5_ROUTER_ID_ADDFRR_ZAPI5_ROUTER_ID_DELETEFRR_ZAPI5_ROUTER_ID_UPDATEFRR_ZAPI5_HELLOFRR_ZAPI5_CAPABILITIESFRR_ZAPI5_NEXTHOP_REGISTERFRR_ZAPI5_NEXTHOP_UNREGISTERFRR_ZAPI5_NEXTHOP_UPDATEFRR_ZAPI5_INTERFACE_NBR_ADDRESS_ADDFRR_ZAPI5_INTERFACE_NBR_ADDRESS_DELETEFRR_ZAPI5_INTERFACE_BFD_DEST_UPDATEFRR_ZAPI5_IMPORT_ROUTE_REGISTERFRR_ZAPI5_IMPORT_ROUTE_UNREGISTERFRR_ZAPI5_IMPORT_CHECK_UPDATEFRR_ZAPI5_IPV4_ROUTE_IPV6_NEXTHOP_ADDFRR_ZAPI5_BFD_DEST_REGISTERFRR_ZAPI5_BFD_DEST_DEREGISTERFRR_ZAPI5_BFD_DEST_UPDATEFRR_ZAPI5_BFD_DEST_REPLAYFRR_ZAPI5_REDISTRIBUTE_ROUTE_ADDFRR_ZAPI5_REDISTRIBUTE_ROUTE_DELFRR_ZAPI5_VRF_UNREGISTERFRR_ZAPI5_VRF_ADDFRR_ZAPI5_VRF_DELETEFRR_ZAPI5_VRF_LABELFRR_ZAPI5_INTERFACE_VRF_UPDATEFRR_ZAPI5_BFD_CLIENT_REGISTERFRR_ZAPI5_INTERFACE_ENABLE_RADVFRR_ZAPI5_INTERFACE_DISABLE_RADVFRR_ZAPI5_IPV4_NEXTHOP_LOOKUP_MRIBFRR_ZAPI5_INTERFACE_LINK_PARAMSFRR_ZAPI5_MPLS_LABELS_ADDFRR_ZAPI5_MPLS_LABELS_DELETEFRR_ZAPI5_IPMR_ROUTE_STATSFRR_ZAPI5_LABEL_MANAGER_CONNECTFRR_ZAPI5_GET_LABEL_CHUNKFRR_ZAPI5_RELEASE_LABEL_CHUNKFRR_ZAPI5_FEC_REGISTERFRR_ZAPI5_FEC_UNREGISTERFRR_ZAPI5_FEC_UPDATEFRR_ZAPI5_ADVERTISE_DEFAULT_GWFRR_ZAPI5_ADVERTISE_SUBNETFRR_ZAPI5_ADVERTISE_ALL_VNIFRR_ZAPI5_VNI_ADDFRR_ZAPI5_VNI_DELFRR_ZAPI5_L3VNI_ADDFRR_ZAPI5_L3VNI_DELFRR_ZAPI5_REMOTE_VTEP_ADDFRR_ZAPI5_REMOTE_VTEP_DELFRR_ZAPI5_MACIP_ADDFRR_ZAPI5_MACIP_DELFRR_ZAPI5_IP_PREFIX_ROUTE_ADDFRR_ZAPI5_IP_PREFIX_ROUTE_DELFRR_ZAPI5_REMOTE_MACIP_ADDFRR_ZAPI5_REMOTE_MACIP_DELFRR_ZAPI5_PW_ADDFRR_ZAPI5_PW_DELETEFRR_ZAPI5_PW_SETFRR_ZAPI5_PW_UNSETFRR_ZAPI5_PW_STATUS_UPDATEFRR_ZAPI5_RULE_ADDFRR_ZAPI5_RULE_DELETEFRR_ZAPI5_RULE_NOTIFY_OWNERFRR_ZAPI5_TABLE_MANAGER_CONNECTFRR_ZAPI5_GET_TABLE_CHUNKFRR_ZAPI5_RELEASE_TABLE_CHUNKFRR_ZAPI5_IPSET_CREATEFRR_ZAPI5_IPSET_DESTROYFRR_ZAPI5_IPSET_ENTRY_ADDFRR_ZAPI5_IPSET_ENTRY_DELETEFRR_ZAPI5_IPSET_NOTIFY_OWNERFRR_ZAPI5_IPSET_ENTRY_NOTIFY_OWNERFRR_ZAPI5_IPTABLE_ADDFRR_ZAPI5_IPTABLE_DELETEFRR_ZAPI5_IPTABLE_NOTIFY_OWNER"
|
||||
|
||||
var _API_TYPE_index = [...]uint16{0, 23, 49, 80, 114, 136, 160, 190, 209, 231, 259, 283, 310, 334, 361, 387, 416, 450, 487, 510, 536, 562, 577, 599, 625, 653, 677, 712, 750, 785, 816, 849, 878, 915, 942, 971, 996, 1021, 1053, 1085, 1109, 1126, 1146, 1165, 1195, 1224, 1255, 1287, 1321, 1352, 1377, 1405, 1431, 1462, 1487, 1516, 1538, 1562, 1582, 1612, 1638, 1665, 1682, 1699, 1718, 1737, 1762, 1787, 1806, 1825, 1854, 1883, 1909, 1935, 1951, 1970, 1986, 2004, 2030, 2048, 2069, 2096, 2127, 2152, 2181, 2203, 2226, 2251, 2279, 2307, 2341, 2362, 2386, 2416}
|
||||
|
||||
func (i API_TYPE) String() string {
|
||||
if i >= API_TYPE(len(_API_TYPE_index)-1) {
|
||||
return "API_TYPE(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _API_TYPE_name[_API_TYPE_index[i]:_API_TYPE_index[i+1]]
|
||||
}
|
||||
224
vendor/github.com/osrg/gobgp/internal/pkg/zebra/apitype_string.go
generated
vendored
Normal file
224
vendor/github.com/osrg/gobgp/internal/pkg/zebra/apitype_string.go
generated
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
// Code generated by "stringer -type=APIType"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[interfaceAdd-0]
|
||||
_ = x[interfaceDelete-1]
|
||||
_ = x[interfaceAddressAdd-2]
|
||||
_ = x[interfaceAddressDelete-3]
|
||||
_ = x[interfaceUp-4]
|
||||
_ = x[interfaceDown-5]
|
||||
_ = x[_interfaceSetMaster-6]
|
||||
_ = x[_interfaceSetProtoDown-7]
|
||||
_ = x[RouteAdd-8]
|
||||
_ = x[RouteDelete-9]
|
||||
_ = x[_routeNotifyOwner-10]
|
||||
_ = x[redistributeAdd-11]
|
||||
_ = x[_redistributeDelete-12]
|
||||
_ = x[_redistributeDefaultAdd-13]
|
||||
_ = x[_redistributeDefaultDelete-14]
|
||||
_ = x[routerIDAdd-15]
|
||||
_ = x[_routerIDDelete-16]
|
||||
_ = x[routerIDUpdate-17]
|
||||
_ = x[hello-18]
|
||||
_ = x[_capabilities-19]
|
||||
_ = x[nexthopRegister-20]
|
||||
_ = x[nexthopUnregister-21]
|
||||
_ = x[nexthopUpdate-22]
|
||||
_ = x[_interfaceNBRAddressAdd-23]
|
||||
_ = x[_interfaceNBRAddressDelete-24]
|
||||
_ = x[_interfaceBFDDestUpdate-25]
|
||||
_ = x[_importRouteRegister-26]
|
||||
_ = x[_importRouteUnregister-27]
|
||||
_ = x[_importCheckUpdate-28]
|
||||
_ = x[_bfdDestRegister-29]
|
||||
_ = x[_bfdDestDeregister-30]
|
||||
_ = x[_bfdDestUpdate-31]
|
||||
_ = x[_bfdDestReplay-32]
|
||||
_ = x[redistributeRouteAdd-33]
|
||||
_ = x[redistributeRouteDel-34]
|
||||
_ = x[_vrfUnregister-35]
|
||||
_ = x[_vrfAdd-36]
|
||||
_ = x[_vrfDelete-37]
|
||||
_ = x[vrfLabel-38]
|
||||
_ = x[_interfaceVRFUpdate-39]
|
||||
_ = x[_bfdClientRegister-40]
|
||||
_ = x[_bfdClientDeregister-41]
|
||||
_ = x[_interfaceEnableRADV-42]
|
||||
_ = x[_interfaceDisableRADV-43]
|
||||
_ = x[ipv4NexthopLookupMRIB-44]
|
||||
_ = x[_interfaceLinkParams-45]
|
||||
_ = x[_mplsLabelsAdd-46]
|
||||
_ = x[_mplsLabelsDelete-47]
|
||||
_ = x[_mplsLabelsReplace-48]
|
||||
_ = x[_ipmrRouteStats-49]
|
||||
_ = x[labelManagerConnect-50]
|
||||
_ = x[labelManagerConnectAsync-51]
|
||||
_ = x[getLabelChunk-52]
|
||||
_ = x[releaseLabelChunk-53]
|
||||
_ = x[_fecRegister-54]
|
||||
_ = x[_fecUnregister-55]
|
||||
_ = x[_fecUpdate-56]
|
||||
_ = x[_advertiseDefaultGW-57]
|
||||
_ = x[_advertiseSviMACIP-58]
|
||||
_ = x[_advertiseSubnet-59]
|
||||
_ = x[_advertiseAllVNI-60]
|
||||
_ = x[_localESAdd-61]
|
||||
_ = x[_localESDel-62]
|
||||
_ = x[_vniAdd-63]
|
||||
_ = x[_vniDel-64]
|
||||
_ = x[_l3VNIAdd-65]
|
||||
_ = x[_l3VNIDel-66]
|
||||
_ = x[_remoteVTEPAdd-67]
|
||||
_ = x[_remoteVTEPDel-68]
|
||||
_ = x[_macIPAdd-69]
|
||||
_ = x[_macIPDel-70]
|
||||
_ = x[_ipPrefixRouteAdd-71]
|
||||
_ = x[_ipPrefixRouteDel-72]
|
||||
_ = x[_remoteMACIPAdd-73]
|
||||
_ = x[_remoteMACIPDel-74]
|
||||
_ = x[_duplicateAddrDetection-75]
|
||||
_ = x[_pwAdd-76]
|
||||
_ = x[_pwDelete-77]
|
||||
_ = x[_pwSet-78]
|
||||
_ = x[_pwUnset-79]
|
||||
_ = x[_pwStatusUpdate-80]
|
||||
_ = x[_ruleAdd-81]
|
||||
_ = x[_ruleDelete-82]
|
||||
_ = x[_ruleNotifyOwner-83]
|
||||
_ = x[_tableManagerConnect-84]
|
||||
_ = x[_getTableChunk-85]
|
||||
_ = x[_releaseTableChunk-86]
|
||||
_ = x[_ipSetCreate-87]
|
||||
_ = x[_ipSetDestroy-88]
|
||||
_ = x[_ipSetEntryAdd-89]
|
||||
_ = x[_ipSetEntryDelete-90]
|
||||
_ = x[_ipSetNotifyOwner-91]
|
||||
_ = x[_ipSetEntryNotifyOwner-92]
|
||||
_ = x[_ipTableAdd-93]
|
||||
_ = x[_ipTableDelete-94]
|
||||
_ = x[_ipTableNotifyOwner-95]
|
||||
_ = x[_vxlanFloodControl-96]
|
||||
_ = x[_vxlanSgAdd-97]
|
||||
_ = x[_vxlanSgDel-98]
|
||||
_ = x[_vxlanSgReplay-99]
|
||||
_ = x[_mlagProcessUp-100]
|
||||
_ = x[_mlagProcessDown-101]
|
||||
_ = x[_mlagClientRegister-102]
|
||||
_ = x[_mlagClientUnregister-103]
|
||||
_ = x[_mlagClientForwardMsg-104]
|
||||
_ = x[zebraError-105]
|
||||
_ = x[_clientCapabilities-106]
|
||||
_ = x[BackwardIPv6RouteAdd-107]
|
||||
_ = x[BackwardIPv6RouteDelete-108]
|
||||
_ = x[zapi6Frr7dot2MinDifferentAPIType-48]
|
||||
_ = x[zapi5ClMinDifferentAPIType-19]
|
||||
_ = x[zapi5MinDifferentAPIType-7]
|
||||
_ = x[zapi4MinDifferentAPIType-6]
|
||||
_ = x[zapi3MinDifferentAPIType-0]
|
||||
_ = x[zapi6Frr7dot2LabelManagerConnect-49]
|
||||
_ = x[zapi6Frr7dot2LabelManagerConnectAsync-50]
|
||||
_ = x[zapi6Frr7dot2GetLabelChunk-51]
|
||||
_ = x[zapi6Frr7dot2ReleaseLabelChunk-52]
|
||||
_ = x[zapi6Frr7RouteAdd-7]
|
||||
_ = x[zapi6Frr7RouteDelete-8]
|
||||
_ = x[zapi6Frr7RedistributAdd-10]
|
||||
_ = x[zapi6Frr7RouterIDAdd-14]
|
||||
_ = x[zapi6Frr7RouterIDUpdate-16]
|
||||
_ = x[zapi6Frr7Hello-17]
|
||||
_ = x[zapi6Frr7NexthopRegister-19]
|
||||
_ = x[zapi6Frr7NexthopUnregister-20]
|
||||
_ = x[zapi6Frr7NexthopUpdate-21]
|
||||
_ = x[zapi6Frr7RedistributeRouteAdd-32]
|
||||
_ = x[zapi6Frr7RedistributeRouteDel-33]
|
||||
_ = x[zapi6Frr7VrfLabel-37]
|
||||
_ = x[zapi6Frr7Ipv4NexthopLookupMRIB-43]
|
||||
_ = x[zapi6Frr7LabelManagerConnect-48]
|
||||
_ = x[zapi6Frr7LabelManagerConnectAsync-49]
|
||||
_ = x[zapi6Frr7GetLabelChunk-50]
|
||||
_ = x[zapi6Frr7ReleaseLabelChunk-51]
|
||||
_ = x[zapi5ClIpv4NexthopLookupMRIB-42]
|
||||
_ = x[zapi5ClLabelManagerConnect-47]
|
||||
_ = x[zapi5ClGetLabelChunk-48]
|
||||
_ = x[zapi5ClReleaseLabelChunk-49]
|
||||
_ = x[zapi5RedistributAdd-14]
|
||||
_ = x[zapi5RouterIDAdd-18]
|
||||
_ = x[zapi5RouterIDUpdate-20]
|
||||
_ = x[zapi5Hello-21]
|
||||
_ = x[zapi5Frr5NexthopRegister-23]
|
||||
_ = x[zapi5Frr5NexthopUnregister-24]
|
||||
_ = x[zapi5Frr5NexthopUpdate-25]
|
||||
_ = x[zapi5Frr5RedistributeRouteAdd-37]
|
||||
_ = x[zapi5Frr5RedistributeRouteDel-38]
|
||||
_ = x[zapi5Frr5VrfLabel-42]
|
||||
_ = x[zapi5Frr5Ipv4NexthopLookupMRIB-47]
|
||||
_ = x[zapi5Frr5LabelManagerConnect-52]
|
||||
_ = x[zapi5Frr5LabelManagerConnectAsync-53]
|
||||
_ = x[zapi5Frr5GetLabelChunk-54]
|
||||
_ = x[zapi5Frr5ReleaseLabelChunk-55]
|
||||
_ = x[zapi5Frr4NexthopRegister-22]
|
||||
_ = x[zapi5Frr4NexthopUnregister-23]
|
||||
_ = x[zapi5Frr4NexthopUpdate-24]
|
||||
_ = x[zapi5Frr4RedistributeRouteAdd-36]
|
||||
_ = x[zapi5Frr4RedistributeRouteDel-37]
|
||||
_ = x[zapi5Frr4Ipv4NexthopLookupMRIB-45]
|
||||
_ = x[zapi5Frr4LabelManagerConnect-50]
|
||||
_ = x[zapi5Frr4GetLabelChunk-51]
|
||||
_ = x[zapi5Frr4ReleaseLabelChunk-52]
|
||||
_ = x[zapi4IPv4RouteAdd-6]
|
||||
_ = x[zapi4IPv4RouteDelete-7]
|
||||
_ = x[zapi4IPv6RouteAdd-8]
|
||||
_ = x[zapi4IPv6RouteDelete-9]
|
||||
_ = x[zapi4RedistributAdd-10]
|
||||
_ = x[zapi4RouterIDAdd-14]
|
||||
_ = x[zapi4RouterIDUpdate-16]
|
||||
_ = x[zapi4Hello-17]
|
||||
_ = x[zapi4NexthopRegister-18]
|
||||
_ = x[zapi4NexthopUnregister-19]
|
||||
_ = x[zapi4NexthopUpdate-20]
|
||||
_ = x[zapi4RedistributeIPv4Add-32]
|
||||
_ = x[zapi4RedistributeIPv4Del-33]
|
||||
_ = x[zapi4RedistributeIPv6Add-34]
|
||||
_ = x[zapi4RedistributeIPv6Del-35]
|
||||
_ = x[zapi4LabelManagerConnect-52]
|
||||
_ = x[zapi4GetLabelChunk-53]
|
||||
_ = x[zapi4ReleaseLabelChunk-54]
|
||||
_ = x[zapi3InterfaceAdd-1]
|
||||
_ = x[zapi3InterfaceDelete-2]
|
||||
_ = x[zapi3InterfaceAddressAdd-3]
|
||||
_ = x[zapi3InterfaceAddressDelete-4]
|
||||
_ = x[zapi3InterfaceUp-5]
|
||||
_ = x[zapi3InterfaceDown-6]
|
||||
_ = x[zapi3IPv4RouteAdd-7]
|
||||
_ = x[zapi3IPv4RouteDelete-8]
|
||||
_ = x[zapi3IPv6RouteAdd-9]
|
||||
_ = x[zapi3IPv6RouteDelete-10]
|
||||
_ = x[zapi3RedistributeAdd-11]
|
||||
_ = x[zapi3IPv4NexthopLookup-15]
|
||||
_ = x[zapi3IPv6NexthopLookup-16]
|
||||
_ = x[zapi3IPv4ImportLookup-17]
|
||||
_ = x[zapi3RouterIDAdd-20]
|
||||
_ = x[zapi3RouterIDUpdate-22]
|
||||
_ = x[zapi3Hello-23]
|
||||
_ = x[zapi3Ipv4NexthopLookupMRIB-24]
|
||||
_ = x[zapi3NexthopRegister-27]
|
||||
_ = x[zapi3NexthopUnregister-28]
|
||||
_ = x[zapi3NexthopUpdate-29]
|
||||
}
|
||||
|
||||
const _APIType_name = "interfaceAddinterfaceDeleteinterfaceAddressAddinterfaceAddressDeleteinterfaceUpinterfaceDown_interfaceSetMaster_interfaceSetProtoDownRouteAddRouteDelete_routeNotifyOwnerredistributeAdd_redistributeDelete_redistributeDefaultAdd_redistributeDefaultDeleterouterIDAdd_routerIDDeleterouterIDUpdatehello_capabilitiesnexthopRegisternexthopUnregisternexthopUpdate_interfaceNBRAddressAdd_interfaceNBRAddressDelete_interfaceBFDDestUpdate_importRouteRegister_importRouteUnregister_importCheckUpdate_bfdDestRegister_bfdDestDeregister_bfdDestUpdate_bfdDestReplayredistributeRouteAddredistributeRouteDel_vrfUnregister_vrfAdd_vrfDeletevrfLabel_interfaceVRFUpdate_bfdClientRegister_bfdClientDeregister_interfaceEnableRADV_interfaceDisableRADVipv4NexthopLookupMRIB_interfaceLinkParams_mplsLabelsAdd_mplsLabelsDelete_mplsLabelsReplace_ipmrRouteStatslabelManagerConnectlabelManagerConnectAsyncgetLabelChunkreleaseLabelChunk_fecRegister_fecUnregister_fecUpdate_advertiseDefaultGW_advertiseSviMACIP_advertiseSubnet_advertiseAllVNI_localESAdd_localESDel_vniAdd_vniDel_l3VNIAdd_l3VNIDel_remoteVTEPAdd_remoteVTEPDel_macIPAdd_macIPDel_ipPrefixRouteAdd_ipPrefixRouteDel_remoteMACIPAdd_remoteMACIPDel_duplicateAddrDetection_pwAdd_pwDelete_pwSet_pwUnset_pwStatusUpdate_ruleAdd_ruleDelete_ruleNotifyOwner_tableManagerConnect_getTableChunk_releaseTableChunk_ipSetCreate_ipSetDestroy_ipSetEntryAdd_ipSetEntryDelete_ipSetNotifyOwner_ipSetEntryNotifyOwner_ipTableAdd_ipTableDelete_ipTableNotifyOwner_vxlanFloodControl_vxlanSgAdd_vxlanSgDel_vxlanSgReplay_mlagProcessUp_mlagProcessDown_mlagClientRegister_mlagClientUnregister_mlagClientForwardMsgzebraError_clientCapabilitiesBackwardIPv6RouteAddBackwardIPv6RouteDelete"
|
||||
|
||||
var _APIType_index = [...]uint16{0, 12, 27, 46, 68, 79, 92, 111, 133, 141, 152, 169, 184, 203, 226, 252, 263, 278, 292, 297, 310, 325, 342, 355, 378, 404, 427, 447, 469, 487, 503, 521, 535, 549, 569, 589, 603, 610, 620, 628, 647, 665, 685, 705, 726, 747, 767, 781, 798, 816, 831, 850, 874, 887, 904, 916, 930, 940, 959, 977, 993, 1009, 1020, 1031, 1038, 1045, 1054, 1063, 1077, 1091, 1100, 1109, 1126, 1143, 1158, 1173, 1196, 1202, 1211, 1217, 1225, 1240, 1248, 1259, 1275, 1295, 1309, 1327, 1339, 1352, 1366, 1383, 1400, 1422, 1433, 1447, 1466, 1484, 1495, 1506, 1520, 1534, 1550, 1569, 1590, 1611, 1621, 1640, 1660, 1683}
|
||||
|
||||
func (i APIType) String() string {
|
||||
if i >= APIType(len(_APIType_index)-1) {
|
||||
return "APIType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _APIType_name[_APIType_index[i]:_APIType_index[i+1]]
|
||||
}
|
||||
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/link_type_string.go
generated
vendored
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/link_type_string.go
generated
vendored
@@ -1,16 +0,0 @@
|
||||
// Code generated by "stringer -type=LINK_TYPE"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _LINK_TYPE_name = "LINK_TYPE_UNKNOWNLINK_TYPE_ETHERLINK_TYPE_EETHERLINK_TYPE_AX25LINK_TYPE_PRONETLINK_TYPE_IEEE802LINK_TYPE_ARCNETLINK_TYPE_APPLETLKLINK_TYPE_DLCILINK_TYPE_ATMLINK_TYPE_METRICOMLINK_TYPE_IEEE1394LINK_TYPE_EUI64LINK_TYPE_INFINIBANDLINK_TYPE_SLIPLINK_TYPE_CSLIPLINK_TYPE_SLIP6LINK_TYPE_CSLIP6LINK_TYPE_RSRVDLINK_TYPE_ADAPTLINK_TYPE_ROSELINK_TYPE_X25LINK_TYPE_PPPLINK_TYPE_CHDLCLINK_TYPE_LAPBLINK_TYPE_RAWHDLCLINK_TYPE_IPIPLINK_TYPE_IPIP6LINK_TYPE_FRADLINK_TYPE_SKIPLINK_TYPE_LOOPBACKLINK_TYPE_LOCALTLKLINK_TYPE_FDDILINK_TYPE_SITLINK_TYPE_IPDDPLINK_TYPE_IPGRELINK_TYPE_IP6GRELINK_TYPE_PIMREGLINK_TYPE_HIPPILINK_TYPE_ECONETLINK_TYPE_IRDALINK_TYPE_FCPPLINK_TYPE_FCALLINK_TYPE_FCPLLINK_TYPE_FCFABRICLINK_TYPE_IEEE802_TRLINK_TYPE_IEEE80211LINK_TYPE_IEEE80211_RADIOTAPLINK_TYPE_IEEE802154LINK_TYPE_IEEE802154_PHY"
|
||||
|
||||
var _LINK_TYPE_index = [...]uint16{0, 17, 32, 48, 62, 78, 95, 111, 129, 143, 156, 174, 192, 207, 227, 241, 256, 271, 287, 302, 317, 331, 344, 357, 372, 386, 403, 417, 432, 446, 460, 478, 496, 510, 523, 538, 553, 569, 585, 600, 616, 630, 644, 658, 672, 690, 710, 729, 757, 777, 801}
|
||||
|
||||
func (i LINK_TYPE) String() string {
|
||||
if i >= LINK_TYPE(len(_LINK_TYPE_index)-1) {
|
||||
return "LINK_TYPE(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _LINK_TYPE_name[_LINK_TYPE_index[i]:_LINK_TYPE_index[i+1]]
|
||||
}
|
||||
72
vendor/github.com/osrg/gobgp/internal/pkg/zebra/linktype_string.go
generated
vendored
Normal file
72
vendor/github.com/osrg/gobgp/internal/pkg/zebra/linktype_string.go
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
// Code generated by "stringer -type=linkType"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[linkTypeUnknown-0]
|
||||
_ = x[linkTypeEther-1]
|
||||
_ = x[linkTypeEEther-2]
|
||||
_ = x[linkTypeAX25-3]
|
||||
_ = x[linkTypePRONET-4]
|
||||
_ = x[linkTypeIeee802-5]
|
||||
_ = x[linkTypeARCNET-6]
|
||||
_ = x[linkTypeAPPLETLK-7]
|
||||
_ = x[linkTypeDLCI-8]
|
||||
_ = x[linkTypeATM-9]
|
||||
_ = x[linkTypeMetricOM-10]
|
||||
_ = x[linkTypeIeee1394-11]
|
||||
_ = x[linkTypeEUI64-12]
|
||||
_ = x[linkTypeINFINIBAND-13]
|
||||
_ = x[linkTypeSLIP-14]
|
||||
_ = x[linkTypeCSLIP-15]
|
||||
_ = x[linkTypeSLIP6-16]
|
||||
_ = x[linkTypeCSLIP6-17]
|
||||
_ = x[linkTypeRSRVD-18]
|
||||
_ = x[linkTypeADAPT-19]
|
||||
_ = x[linkTypeROSE-20]
|
||||
_ = x[linkTypeX25-21]
|
||||
_ = x[linkTypePPP-22]
|
||||
_ = x[linkTypeCHDLC-23]
|
||||
_ = x[linkTypeLAPB-24]
|
||||
_ = x[linkTypeRAWHDLC-25]
|
||||
_ = x[linkTypeIPIP-26]
|
||||
_ = x[linkTypeIPIP6-27]
|
||||
_ = x[linkTypeFRAD-28]
|
||||
_ = x[linkTypeSKIP-29]
|
||||
_ = x[linkTypeLOOPBACK-30]
|
||||
_ = x[linkTypeLOCALTLK-31]
|
||||
_ = x[linkTypeFDDI-32]
|
||||
_ = x[linkTypeSIT-33]
|
||||
_ = x[linkTypeIPDDP-34]
|
||||
_ = x[linkTypeIPGRE-35]
|
||||
_ = x[linkTypeIP6GRE-36]
|
||||
_ = x[linkTypePIMREG-37]
|
||||
_ = x[linkTypeHIPPI-38]
|
||||
_ = x[linkTypeECONET-39]
|
||||
_ = x[linkTypeIRDA-40]
|
||||
_ = x[linkTypeFCPP-41]
|
||||
_ = x[linkTypeFCAL-42]
|
||||
_ = x[linkTypeFCPL-43]
|
||||
_ = x[linkTypeFCFABRIC-44]
|
||||
_ = x[linkTypeIeee802Tr-45]
|
||||
_ = x[linkTypeIeee80211-46]
|
||||
_ = x[linkTypeIeee80211RadioTap-47]
|
||||
_ = x[linkTypeIeee802154-48]
|
||||
_ = x[linkTypeIeee802154Phy-49]
|
||||
}
|
||||
|
||||
const _linkType_name = "linkTypeUnknownlinkTypeEtherlinkTypeEEtherlinkTypeAX25linkTypePRONETlinkTypeIeee802linkTypeARCNETlinkTypeAPPLETLKlinkTypeDLCIlinkTypeATMlinkTypeMetricOMlinkTypeIeee1394linkTypeEUI64linkTypeINFINIBANDlinkTypeSLIPlinkTypeCSLIPlinkTypeSLIP6linkTypeCSLIP6linkTypeRSRVDlinkTypeADAPTlinkTypeROSElinkTypeX25linkTypePPPlinkTypeCHDLClinkTypeLAPBlinkTypeRAWHDLClinkTypeIPIPlinkTypeIPIP6linkTypeFRADlinkTypeSKIPlinkTypeLOOPBACKlinkTypeLOCALTLKlinkTypeFDDIlinkTypeSITlinkTypeIPDDPlinkTypeIPGRElinkTypeIP6GRElinkTypePIMREGlinkTypeHIPPIlinkTypeECONETlinkTypeIRDAlinkTypeFCPPlinkTypeFCALlinkTypeFCPLlinkTypeFCFABRIClinkTypeIeee802TrlinkTypeIeee80211linkTypeIeee80211RadioTaplinkTypeIeee802154linkTypeIeee802154Phy"
|
||||
|
||||
var _linkType_index = [...]uint16{0, 15, 28, 42, 54, 68, 83, 97, 113, 125, 136, 152, 168, 181, 199, 211, 224, 237, 251, 264, 277, 289, 300, 311, 324, 336, 351, 363, 376, 388, 400, 416, 432, 444, 455, 468, 481, 495, 509, 522, 536, 548, 560, 572, 584, 600, 617, 634, 659, 677, 698}
|
||||
|
||||
func (i linkType) String() string {
|
||||
if i >= linkType(len(_linkType_index)-1) {
|
||||
return "linkType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _linkType_name[_linkType_index[i]:_linkType_index[i+1]]
|
||||
}
|
||||
28
vendor/github.com/osrg/gobgp/internal/pkg/zebra/lsptype_string.go
generated
vendored
Normal file
28
vendor/github.com/osrg/gobgp/internal/pkg/zebra/lsptype_string.go
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// Code generated by "stringer -type=lspTYPE"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[lspNone-0]
|
||||
_ = x[lspStatic-1]
|
||||
_ = x[lspLDP-2]
|
||||
_ = x[lspBGP-3]
|
||||
_ = x[lspSR-4]
|
||||
_ = x[lspSHARP-5]
|
||||
}
|
||||
|
||||
const _lspTYPE_name = "lspNonelspStaticlspLDPlspBGPlspSRlspSHARP"
|
||||
|
||||
var _lspTYPE_index = [...]uint8{0, 7, 16, 22, 28, 33, 41}
|
||||
|
||||
func (i lspTYPE) String() string {
|
||||
if i >= lspTYPE(len(_lspTYPE_index)-1) {
|
||||
return "lspTYPE(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _lspTYPE_name[_lspTYPE_index[i]:_lspTYPE_index[i+1]]
|
||||
}
|
||||
41
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthop_flag_string.go
generated
vendored
41
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthop_flag_string.go
generated
vendored
@@ -1,41 +0,0 @@
|
||||
// Code generated by "stringer -type=NEXTHOP_FLAG"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const (
|
||||
_NEXTHOP_FLAG_name_0 = "NEXTHOP_FLAG_ACTIVENEXTHOP_FLAG_FIB"
|
||||
_NEXTHOP_FLAG_name_1 = "NEXTHOP_FLAG_RECURSIVE"
|
||||
_NEXTHOP_FLAG_name_2 = "NEXTHOP_FLAG_ONLINK"
|
||||
_NEXTHOP_FLAG_name_3 = "NEXTHOP_FLAG_MATCHED"
|
||||
_NEXTHOP_FLAG_name_4 = "NEXTHOP_FLAG_FILTERED"
|
||||
_NEXTHOP_FLAG_name_5 = "NEXTHOP_FLAG_DUPLICATE"
|
||||
_NEXTHOP_FLAG_name_6 = "NEXTHOP_FLAG_EVPN_RVTEP"
|
||||
)
|
||||
|
||||
var (
|
||||
_NEXTHOP_FLAG_index_0 = [...]uint8{0, 19, 35}
|
||||
)
|
||||
|
||||
func (i NEXTHOP_FLAG) String() string {
|
||||
switch {
|
||||
case 1 <= i && i <= 2:
|
||||
i -= 1
|
||||
return _NEXTHOP_FLAG_name_0[_NEXTHOP_FLAG_index_0[i]:_NEXTHOP_FLAG_index_0[i+1]]
|
||||
case i == 4:
|
||||
return _NEXTHOP_FLAG_name_1
|
||||
case i == 8:
|
||||
return _NEXTHOP_FLAG_name_2
|
||||
case i == 16:
|
||||
return _NEXTHOP_FLAG_name_3
|
||||
case i == 32:
|
||||
return _NEXTHOP_FLAG_name_4
|
||||
case i == 64:
|
||||
return _NEXTHOP_FLAG_name_5
|
||||
case i == 128:
|
||||
return _NEXTHOP_FLAG_name_6
|
||||
default:
|
||||
return "NEXTHOP_FLAG(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
}
|
||||
17
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthop_type_string.go
generated
vendored
17
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthop_type_string.go
generated
vendored
@@ -1,17 +0,0 @@
|
||||
// Code generated by "stringer -type=NEXTHOP_TYPE"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _NEXTHOP_TYPE_name = "FRR_NEXTHOP_TYPE_IFINDEXFRR_NEXTHOP_TYPE_IPV4FRR_NEXTHOP_TYPE_IPV4_IFINDEXFRR_NEXTHOP_TYPE_IPV6FRR_NEXTHOP_TYPE_IPV6_IFINDEXFRR_NEXTHOP_TYPE_BLACKHOLENEXTHOP_TYPE_IPV6_IFINDEXNEXTHOP_TYPE_IPV6_IFNAMENEXTHOP_TYPE_BLACKHOLE"
|
||||
|
||||
var _NEXTHOP_TYPE_index = [...]uint8{0, 24, 45, 74, 95, 124, 150, 175, 199, 221}
|
||||
|
||||
func (i NEXTHOP_TYPE) String() string {
|
||||
i -= 1
|
||||
if i >= NEXTHOP_TYPE(len(_NEXTHOP_TYPE_index)-1) {
|
||||
return "NEXTHOP_TYPE(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _NEXTHOP_TYPE_name[_NEXTHOP_TYPE_index[i]:_NEXTHOP_TYPE_index[i+1]]
|
||||
}
|
||||
55
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthopflag_string.go
generated
vendored
Normal file
55
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthopflag_string.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
// Code generated by "stringer -type=nexthopFlag"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[nexthopFlagActive-1]
|
||||
_ = x[nexthopFlagFIB-2]
|
||||
_ = x[nexthopFlagRecursive-4]
|
||||
_ = x[nexthopFlagOnlink-8]
|
||||
_ = x[nexthopFlagMatched-16]
|
||||
_ = x[nexthopFlagFiltered-32]
|
||||
_ = x[nexthopFlagDuplicate-64]
|
||||
_ = x[nexthopFlagEvpnRvtep-128]
|
||||
}
|
||||
|
||||
const (
|
||||
_nexthopFlag_name_0 = "nexthopFlagActivenexthopFlagFIB"
|
||||
_nexthopFlag_name_1 = "nexthopFlagRecursive"
|
||||
_nexthopFlag_name_2 = "nexthopFlagOnlink"
|
||||
_nexthopFlag_name_3 = "nexthopFlagMatched"
|
||||
_nexthopFlag_name_4 = "nexthopFlagFiltered"
|
||||
_nexthopFlag_name_5 = "nexthopFlagDuplicate"
|
||||
_nexthopFlag_name_6 = "nexthopFlagEvpnRvtep"
|
||||
)
|
||||
|
||||
var (
|
||||
_nexthopFlag_index_0 = [...]uint8{0, 17, 31}
|
||||
)
|
||||
|
||||
func (i nexthopFlag) String() string {
|
||||
switch {
|
||||
case 1 <= i && i <= 2:
|
||||
i -= 1
|
||||
return _nexthopFlag_name_0[_nexthopFlag_index_0[i]:_nexthopFlag_index_0[i+1]]
|
||||
case i == 4:
|
||||
return _nexthopFlag_name_1
|
||||
case i == 8:
|
||||
return _nexthopFlag_name_2
|
||||
case i == 16:
|
||||
return _nexthopFlag_name_3
|
||||
case i == 32:
|
||||
return _nexthopFlag_name_4
|
||||
case i == 64:
|
||||
return _nexthopFlag_name_5
|
||||
case i == 128:
|
||||
return _nexthopFlag_name_6
|
||||
default:
|
||||
return "nexthopFlag(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
}
|
||||
37
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthoptype_string.go
generated
vendored
Normal file
37
vendor/github.com/osrg/gobgp/internal/pkg/zebra/nexthoptype_string.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Code generated by "stringer -type=nexthopType"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[nexthopTypeIFIndex-1]
|
||||
_ = x[nexthopTypeIPv4-2]
|
||||
_ = x[nexthopTypeIPv4IFIndex-3]
|
||||
_ = x[nexthopTypeIPv6-4]
|
||||
_ = x[nexthopTypeIPv6IFIndex-5]
|
||||
_ = x[nexthopTypeBlackhole-6]
|
||||
_ = x[nexthopTypeIFName-2]
|
||||
_ = x[backwardNexthopTypeIPv4-3]
|
||||
_ = x[backwardNexthopTypeIPv4IFIndex-4]
|
||||
_ = x[nexthopTypeIPv4IFName-5]
|
||||
_ = x[backwardNexthopTypeIPv6-6]
|
||||
_ = x[backwardNexthopTypeIPv6IFIndex-7]
|
||||
_ = x[nexthopTypeIPv6IFName-8]
|
||||
_ = x[backwardNexthopTypeBlackhole-9]
|
||||
}
|
||||
|
||||
const _nexthopType_name = "nexthopTypeIFIndexnexthopTypeIPv4nexthopTypeIPv4IFIndexnexthopTypeIPv6nexthopTypeIPv6IFIndexnexthopTypeBlackholebackwardNexthopTypeIPv6IFIndexnexthopTypeIPv6IFNamebackwardNexthopTypeBlackhole"
|
||||
|
||||
var _nexthopType_index = [...]uint8{0, 18, 33, 55, 70, 92, 112, 142, 163, 191}
|
||||
|
||||
func (i nexthopType) String() string {
|
||||
i -= 1
|
||||
if i >= nexthopType(len(_nexthopType_index)-1) {
|
||||
return "nexthopType(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _nexthopType_name[_nexthopType_index[i]:_nexthopType_index[i+1]]
|
||||
}
|
||||
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptm_enable_string.go
generated
vendored
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptm_enable_string.go
generated
vendored
@@ -1,16 +0,0 @@
|
||||
// Code generated by "stringer -type=PTM_ENABLE"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _PTM_ENABLE_name = "PTM_ENABLE_OFFPTM_ENABLE_ONPTM_ENABLE_UNSPEC"
|
||||
|
||||
var _PTM_ENABLE_index = [...]uint8{0, 14, 27, 44}
|
||||
|
||||
func (i PTM_ENABLE) String() string {
|
||||
if i >= PTM_ENABLE(len(_PTM_ENABLE_index)-1) {
|
||||
return "PTM_ENABLE(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _PTM_ENABLE_name[_PTM_ENABLE_index[i]:_PTM_ENABLE_index[i+1]]
|
||||
}
|
||||
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptm_status_string.go
generated
vendored
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptm_status_string.go
generated
vendored
@@ -1,16 +0,0 @@
|
||||
// Code generated by "stringer -type=PTM_STATUS"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _PTM_STATUS_name = "PTM_STATUS_DOWNPTM_STATUS_UPPTM_STATUS_UNKNOWN"
|
||||
|
||||
var _PTM_STATUS_index = [...]uint8{0, 15, 28, 46}
|
||||
|
||||
func (i PTM_STATUS) String() string {
|
||||
if i >= PTM_STATUS(len(_PTM_STATUS_index)-1) {
|
||||
return "PTM_STATUS(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _PTM_STATUS_name[_PTM_STATUS_index[i]:_PTM_STATUS_index[i+1]]
|
||||
}
|
||||
25
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptmenable_string.go
generated
vendored
Normal file
25
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptmenable_string.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// Code generated by "stringer -type=ptmEnable"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[ptmEnableOff-0]
|
||||
_ = x[ptmEnableOn-1]
|
||||
_ = x[ptmEnableUnspec-2]
|
||||
}
|
||||
|
||||
const _ptmEnable_name = "ptmEnableOffptmEnableOnptmEnableUnspec"
|
||||
|
||||
var _ptmEnable_index = [...]uint8{0, 12, 23, 38}
|
||||
|
||||
func (i ptmEnable) String() string {
|
||||
if i >= ptmEnable(len(_ptmEnable_index)-1) {
|
||||
return "ptmEnable(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _ptmEnable_name[_ptmEnable_index[i]:_ptmEnable_index[i+1]]
|
||||
}
|
||||
25
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptmstatus_string.go
generated
vendored
Normal file
25
vendor/github.com/osrg/gobgp/internal/pkg/zebra/ptmstatus_string.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// Code generated by "stringer -type=ptmStatus"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[ptmStatusDown-0]
|
||||
_ = x[ptmStatusUp-1]
|
||||
_ = x[ptmStatusUnknown-2]
|
||||
}
|
||||
|
||||
const _ptmStatus_name = "ptmStatusDownptmStatusUpptmStatusUnknown"
|
||||
|
||||
var _ptmStatus_index = [...]uint8{0, 13, 24, 40}
|
||||
|
||||
func (i ptmStatus) String() string {
|
||||
if i >= ptmStatus(len(_ptmStatus_index)-1) {
|
||||
return "ptmStatus(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _ptmStatus_name[_ptmStatus_index[i]:_ptmStatus_index[i+1]]
|
||||
}
|
||||
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/route_type_string.go
generated
vendored
16
vendor/github.com/osrg/gobgp/internal/pkg/zebra/route_type_string.go
generated
vendored
@@ -1,16 +0,0 @@
|
||||
// Code generated by "stringer -type=ROUTE_TYPE"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _ROUTE_TYPE_name = "FRR_ZAPI5_ROUTE_SYSTEMFRR_ZAPI5_ROUTE_KERNELFRR_ZAPI5_ROUTE_CONNECTFRR_ZAPI5_ROUTE_STATICFRR_ZAPI5_ROUTE_RIPFRR_ZAPI5_ROUTE_RIPNGFRR_ZAPI5_ROUTE_OSPFFRR_ZAPI5_ROUTE_OSPF6FRR_ZAPI5_ROUTE_ISISFRR_ZAPI5_ROUTE_BGPFRR_ZAPI5_ROUTE_PIMFRR_ZAPI5_ROUTE_EIGRPFRR_ZAPI5_ROUTE_NHRPFRR_ZAPI5_ROUTE_HSLSFRR_ZAPI5_ROUTE_OLSRFRR_ZAPI5_ROUTE_TABLEFRR_ZAPI5_ROUTE_LDPFRR_ZAPI5_ROUTE_VNCFRR_ZAPI5_ROUTE_VNC_DIRECTFRR_ZAPI5_ROUTE_VNC_DIRECT_RHFRR_ZAPI5_ROUTE_BGP_DIRECTFRR_ZAPI5_ROUTE_BGP_DIRECT_EXTFRR_ZAPI5_ROUTE_BABELFRR_ZAPI5_ROUTE_SHARPFRR_ZAPI5_ROUTE_PBRFRR_ZAPI5_ROUTE_ALLFRR_ZAPI5_ROUTE_MAX"
|
||||
|
||||
var _ROUTE_TYPE_index = [...]uint16{0, 22, 44, 67, 89, 108, 129, 149, 170, 190, 209, 228, 249, 269, 289, 309, 330, 349, 368, 394, 423, 449, 479, 500, 521, 540, 559, 578}
|
||||
|
||||
func (i ROUTE_TYPE) String() string {
|
||||
if i >= ROUTE_TYPE(len(_ROUTE_TYPE_index)-1) {
|
||||
return "ROUTE_TYPE(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _ROUTE_TYPE_name[_ROUTE_TYPE_index[i]:_ROUTE_TYPE_index[i+1]]
|
||||
}
|
||||
73
vendor/github.com/osrg/gobgp/internal/pkg/zebra/routetype_string.go
generated
vendored
Normal file
73
vendor/github.com/osrg/gobgp/internal/pkg/zebra/routetype_string.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// Code generated by "stringer -type=RouteType"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[routeSystem-0]
|
||||
_ = x[routeKernel-1]
|
||||
_ = x[routeConnect-2]
|
||||
_ = x[RouteStatic-3]
|
||||
_ = x[routeRIP-4]
|
||||
_ = x[routeRIPNG-5]
|
||||
_ = x[routeOSPF-6]
|
||||
_ = x[routeOSPF6-7]
|
||||
_ = x[routeISIS-8]
|
||||
_ = x[RouteBGP-9]
|
||||
_ = x[routePIM-10]
|
||||
_ = x[routeEIGRP-11]
|
||||
_ = x[routeNHRP-12]
|
||||
_ = x[routeHSLS-13]
|
||||
_ = x[routeOLSR-14]
|
||||
_ = x[routeTABLE-15]
|
||||
_ = x[routeLDP-16]
|
||||
_ = x[routeVNC-17]
|
||||
_ = x[routeVNCDirect-18]
|
||||
_ = x[routeVNCDirectRH-19]
|
||||
_ = x[routeBGPDirect-20]
|
||||
_ = x[routeBGPDirectEXT-21]
|
||||
_ = x[routeBABEL-22]
|
||||
_ = x[routeSHARP-23]
|
||||
_ = x[routePBR-24]
|
||||
_ = x[routeBFD-25]
|
||||
_ = x[routeOpenfabric-26]
|
||||
_ = x[routeVRRP-27]
|
||||
_ = x[routeNHG-28]
|
||||
_ = x[routeAll-29]
|
||||
_ = x[routeMax-30]
|
||||
_ = x[zapi5Frr4RouteAll-24]
|
||||
_ = x[zapi5Frr5RouteAll-25]
|
||||
_ = x[zapi6Frr6RouteAll-26]
|
||||
_ = x[zapi6Frr7RouteAll-27]
|
||||
_ = x[zapi6Frr7dot2RouteAll-28]
|
||||
_ = x[zapi4RouteNHRP-11]
|
||||
_ = x[zapi4RouteHSLS-12]
|
||||
_ = x[zapi4RouteOLSR-13]
|
||||
_ = x[zapi4RouteTABLE-14]
|
||||
_ = x[zapi4RouteLDP-15]
|
||||
_ = x[zapi4RouteVNC-16]
|
||||
_ = x[zapi4RouteVNCDirect-17]
|
||||
_ = x[zapi4RouteVNCDirectRH-18]
|
||||
_ = x[zapi4RouteBGPDixrect-19]
|
||||
_ = x[zapi4RouteBGPDirectEXT-20]
|
||||
_ = x[zapi4RouteAll-21]
|
||||
_ = x[zapi3RouteHSLS-11]
|
||||
_ = x[zapi3RouteOLSR-12]
|
||||
_ = x[zapi3RouteBABEL-13]
|
||||
_ = x[zapi3RouteNHRP-14]
|
||||
}
|
||||
|
||||
const _RouteType_name = "routeSystemrouteKernelrouteConnectRouteStaticrouteRIProuteRIPNGrouteOSPFrouteOSPF6routeISISRouteBGProutePIMrouteEIGRProuteNHRProuteHSLSrouteOLSRrouteTABLErouteLDProuteVNCrouteVNCDirectrouteVNCDirectRHrouteBGPDirectrouteBGPDirectEXTrouteBABELrouteSHARProutePBRrouteBFDrouteOpenfabricrouteVRRProuteNHGrouteAllrouteMax"
|
||||
|
||||
var _RouteType_index = [...]uint16{0, 11, 22, 34, 45, 53, 63, 72, 82, 91, 99, 107, 117, 126, 135, 144, 154, 162, 170, 184, 200, 214, 231, 241, 251, 259, 267, 282, 291, 299, 307, 315}
|
||||
|
||||
func (i RouteType) String() string {
|
||||
if i >= RouteType(len(_RouteType_index)-1) {
|
||||
return "RouteType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _RouteType_name[_RouteType_index[i]:_RouteType_index[i+1]]
|
||||
}
|
||||
41
vendor/github.com/osrg/gobgp/internal/pkg/zebra/safi_string.go
generated
vendored
41
vendor/github.com/osrg/gobgp/internal/pkg/zebra/safi_string.go
generated
vendored
@@ -1,17 +1,36 @@
|
||||
// Code generated by "stringer -type=SAFI"; DO NOT EDIT.
|
||||
// Code generated by "stringer -type=Safi"; DO NOT EDIT.
|
||||
|
||||
package zebra
|
||||
|
||||
import "strconv"
|
||||
|
||||
const _SAFI_name = "SAFI_UNICASTSAFI_MULTICASTSAFI_RESERVED_3SAFI_MPLS_VPNSAFI_MAX"
|
||||
|
||||
var _SAFI_index = [...]uint8{0, 12, 26, 41, 54, 62}
|
||||
|
||||
func (i SAFI) String() string {
|
||||
i -= 1
|
||||
if i >= SAFI(len(_SAFI_index)-1) {
|
||||
return "SAFI(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _SAFI_name[_SAFI_index[i]:_SAFI_index[i+1]]
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[safiUnspec-0]
|
||||
_ = x[SafiUnicast-1]
|
||||
_ = x[safiMulticast-2]
|
||||
_ = x[safiMplsVpn-3]
|
||||
_ = x[safiEncap-4]
|
||||
_ = x[safiEvpn-5]
|
||||
_ = x[safiLabeledUnicast-6]
|
||||
_ = x[safiFlowspec-7]
|
||||
_ = x[safiMax-8]
|
||||
_ = x[zapi4SafiMplsVpn-3]
|
||||
_ = x[zapi3SafiMplsVpn-4]
|
||||
_ = x[zapi4SafiEncap-5]
|
||||
_ = x[zapi4SafiEvpn-6]
|
||||
_ = x[zapi3SafiEncap-7]
|
||||
}
|
||||
|
||||
const _Safi_name = "safiUnspecSafiUnicastsafiMulticastsafiMplsVpnsafiEncapsafiEvpnsafiLabeledUnicastsafiFlowspecsafiMax"
|
||||
|
||||
var _Safi_index = [...]uint8{0, 10, 21, 34, 45, 54, 62, 80, 92, 99}
|
||||
|
||||
func (i Safi) String() string {
|
||||
if i >= Safi(len(_Safi_index)-1) {
|
||||
return "Safi(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Safi_name[_Safi_index[i]:_Safi_index[i+1]]
|
||||
}
|
||||
|
||||
3910
vendor/github.com/osrg/gobgp/internal/pkg/zebra/zapi.go
generated
vendored
3910
vendor/github.com/osrg/gobgp/internal/pkg/zebra/zapi.go
generated
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user