Add unit tests

This commit is contained in:
Mayuresh Gaitonde
2020-12-17 17:25:53 -08:00
parent 3702339f44
commit 6be4d69d02
705 changed files with 120529 additions and 150051 deletions

View File

@@ -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"`
}

View File

@@ -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

View File

@@ -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 {

View File

@@ -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
}