summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/gobgp.pb.go44
-rw-r--r--api/gobgp.proto38
-rw-r--r--config/bgp_configs.go1881
-rw-r--r--config/default.go45
-rw-r--r--config/serve.go12
-rw-r--r--gobgp/common.go1
-rw-r--r--gobgp/neighbor.go16
-rw-r--r--gobgp/policy.go517
-rw-r--r--gobgpd/main.go6
-rw-r--r--policy/policy.go640
-rw-r--r--policy/policy_test.go1511
-rw-r--r--server/fsm.go147
-rw-r--r--server/fsm_test.go18
-rw-r--r--server/peer.go134
-rw-r--r--server/server.go310
-rw-r--r--table/path.go22
-rw-r--r--test/scenario_test/gobgp_test.py36
-rw-r--r--test/scenario_test/lib/gobgp.py23
-rw-r--r--test/scenario_test/policy/policy_generator.go948
-rw-r--r--test/scenario_test/quagga-rsconfig.go90
-rw-r--r--test/scenario_test/route_server_malformed_test.py4
-rw-r--r--test/scenario_test/route_server_policy_test.py25
-rw-r--r--tools/config/example_toml.go156
-rw-r--r--tools/pyang_plugins/bgpyang2golang.py147
-rw-r--r--tools/route-server/quagga-rsconfig.go28
25 files changed, 3603 insertions, 3196 deletions
diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go
index 0d425fd6..0d776960 100644
--- a/api/gobgp.pb.go
+++ b/api/gobgp.pb.go
@@ -1058,20 +1058,20 @@ type PeerInfo struct {
BgpState string `protobuf:"bytes,1,opt,name=bgp_state" json:"bgp_state,omitempty"`
AdminState string `protobuf:"bytes,2,opt,name=admin_state" json:"admin_state,omitempty"`
FsmEstablishedTransitions uint32 `protobuf:"varint,3,opt,name=fsm_established_transitions" json:"fsm_established_transitions,omitempty"`
- TotalMessageOut uint32 `protobuf:"varint,4,opt,name=total_message_out" json:"total_message_out,omitempty"`
- TotalMessageIn uint32 `protobuf:"varint,5,opt,name=total_message_in" json:"total_message_in,omitempty"`
- UpdateMessageOut uint32 `protobuf:"varint,6,opt,name=update_message_out" json:"update_message_out,omitempty"`
- UpdateMessageIn uint32 `protobuf:"varint,7,opt,name=update_message_in" json:"update_message_in,omitempty"`
- KeepAliveMessageOut uint32 `protobuf:"varint,8,opt,name=keep_alive_message_out" json:"keep_alive_message_out,omitempty"`
- KeepAliveMessageIn uint32 `protobuf:"varint,9,opt,name=keep_alive_message_in" json:"keep_alive_message_in,omitempty"`
- OpenMessageOut uint32 `protobuf:"varint,10,opt,name=open_message_out" json:"open_message_out,omitempty"`
- OpenMessageIn uint32 `protobuf:"varint,11,opt,name=open_message_in" json:"open_message_in,omitempty"`
- NotificationOut uint32 `protobuf:"varint,12,opt,name=notification_out" json:"notification_out,omitempty"`
- NotificationIn uint32 `protobuf:"varint,13,opt,name=notification_in" json:"notification_in,omitempty"`
- RefreshMessageOut uint32 `protobuf:"varint,14,opt,name=refresh_message_out" json:"refresh_message_out,omitempty"`
- RefreshMessageIn uint32 `protobuf:"varint,15,opt,name=refresh_message_in" json:"refresh_message_in,omitempty"`
- DiscardedOut uint32 `protobuf:"varint,16,opt,name=discarded_out" json:"discarded_out,omitempty"`
- DiscardedIn uint32 `protobuf:"varint,17,opt,name=discarded_in" json:"discarded_in,omitempty"`
+ TotalMessageOut uint64 `protobuf:"varint,4,opt,name=total_message_out" json:"total_message_out,omitempty"`
+ TotalMessageIn uint64 `protobuf:"varint,5,opt,name=total_message_in" json:"total_message_in,omitempty"`
+ UpdateMessageOut uint64 `protobuf:"varint,6,opt,name=update_message_out" json:"update_message_out,omitempty"`
+ UpdateMessageIn uint64 `protobuf:"varint,7,opt,name=update_message_in" json:"update_message_in,omitempty"`
+ KeepAliveMessageOut uint64 `protobuf:"varint,8,opt,name=keep_alive_message_out" json:"keep_alive_message_out,omitempty"`
+ KeepAliveMessageIn uint64 `protobuf:"varint,9,opt,name=keep_alive_message_in" json:"keep_alive_message_in,omitempty"`
+ OpenMessageOut uint64 `protobuf:"varint,10,opt,name=open_message_out" json:"open_message_out,omitempty"`
+ OpenMessageIn uint64 `protobuf:"varint,11,opt,name=open_message_in" json:"open_message_in,omitempty"`
+ NotificationOut uint64 `protobuf:"varint,12,opt,name=notification_out" json:"notification_out,omitempty"`
+ NotificationIn uint64 `protobuf:"varint,13,opt,name=notification_in" json:"notification_in,omitempty"`
+ RefreshMessageOut uint64 `protobuf:"varint,14,opt,name=refresh_message_out" json:"refresh_message_out,omitempty"`
+ RefreshMessageIn uint64 `protobuf:"varint,15,opt,name=refresh_message_in" json:"refresh_message_in,omitempty"`
+ DiscardedOut uint64 `protobuf:"varint,16,opt,name=discarded_out" json:"discarded_out,omitempty"`
+ DiscardedIn uint64 `protobuf:"varint,17,opt,name=discarded_in" json:"discarded_in,omitempty"`
Uptime int64 `protobuf:"varint,18,opt,name=uptime" json:"uptime,omitempty"`
Downtime int64 `protobuf:"varint,19,opt,name=downtime" json:"downtime,omitempty"`
LastError string `protobuf:"bytes,20,opt,name=last_error" json:"last_error,omitempty"`
@@ -1122,8 +1122,9 @@ func (m *Prefix) String() string { return proto.CompactTextString(m) }
func (*Prefix) ProtoMessage() {}
type PrefixSet struct {
- PrefixSetName string `protobuf:"bytes,1,opt,name=prefix_set_name" json:"prefix_set_name,omitempty"`
- PrefixList []*Prefix `protobuf:"bytes,2,rep,name=prefix_list" json:"prefix_list,omitempty"`
+ PrefixSetName string `protobuf:"bytes,1,opt,name=prefix_set_name" json:"prefix_set_name,omitempty"`
+ PrefixList []*Prefix `protobuf:"bytes,2,rep,name=prefix_list" json:"prefix_list,omitempty"`
+ MatchSetOptions string `protobuf:"bytes,3,opt,name=match_set_options" json:"match_set_options,omitempty"`
}
func (m *PrefixSet) Reset() { *m = PrefixSet{} }
@@ -1148,6 +1149,7 @@ func (*Neighbor) ProtoMessage() {}
type NeighborSet struct {
NeighborSetName string `protobuf:"bytes,1,opt,name=neighbor_set_name" json:"neighbor_set_name,omitempty"`
NeighborList []*Neighbor `protobuf:"bytes,2,rep,name=neighbor_list" json:"neighbor_list,omitempty"`
+ MatchSetOptions string `protobuf:"bytes,3,opt,name=match_set_options" json:"match_set_options,omitempty"`
}
func (m *NeighborSet) Reset() { *m = NeighborSet{} }
@@ -1171,8 +1173,9 @@ func (m *AsPathLength) String() string { return proto.CompactTextString(m) }
func (*AsPathLength) ProtoMessage() {}
type AsPathSet struct {
- AsPathSetName string `protobuf:"bytes,1,opt,name=as_path_set_name" json:"as_path_set_name,omitempty"`
- AsPathMembers []string `protobuf:"bytes,2,rep,name=as_path_members" json:"as_path_members,omitempty"`
+ AsPathSetName string `protobuf:"bytes,1,opt,name=as_path_set_name" json:"as_path_set_name,omitempty"`
+ AsPathMembers []string `protobuf:"bytes,2,rep,name=as_path_members" json:"as_path_members,omitempty"`
+ MatchSetOptions string `protobuf:"bytes,3,opt,name=match_set_options" json:"match_set_options,omitempty"`
}
func (m *AsPathSet) Reset() { *m = AsPathSet{} }
@@ -1182,6 +1185,7 @@ func (*AsPathSet) ProtoMessage() {}
type CommunitySet struct {
CommunitySetName string `protobuf:"bytes,1,opt,name=community_set_name" json:"community_set_name,omitempty"`
CommunityMembers []string `protobuf:"bytes,2,rep,name=community_members" json:"community_members,omitempty"`
+ MatchSetOptions string `protobuf:"bytes,3,opt,name=match_set_options" json:"match_set_options,omitempty"`
}
func (m *CommunitySet) Reset() { *m = CommunitySet{} }
@@ -1191,6 +1195,7 @@ func (*CommunitySet) ProtoMessage() {}
type ExtCommunitySet struct {
ExtCommunitySetName string `protobuf:"bytes,1,opt,name=ext_community_set_name" json:"ext_community_set_name,omitempty"`
ExtCommunityMembers []string `protobuf:"bytes,2,rep,name=ext_community_members" json:"ext_community_members,omitempty"`
+ MatchSetOptions string `protobuf:"bytes,3,opt,name=match_set_options" json:"match_set_options,omitempty"`
}
func (m *ExtCommunitySet) Reset() { *m = ExtCommunitySet{} }
@@ -1203,8 +1208,7 @@ type Conditions struct {
MatchAsPathLength *AsPathLength `protobuf:"bytes,3,opt,name=match_as_path_length" json:"match_as_path_length,omitempty"`
MatchAsPathSet *AsPathSet `protobuf:"bytes,4,opt,name=match_as_path_set" json:"match_as_path_set,omitempty"`
MatchCommunitySet *CommunitySet `protobuf:"bytes,5,opt,name=match_community_set" json:"match_community_set,omitempty"`
- MatchSetOptions string `protobuf:"bytes,6,opt,name=match_set_options" json:"match_set_options,omitempty"`
- MatchExtCommunitySet *ExtCommunitySet `protobuf:"bytes,7,opt,name=match_ext_community_set" json:"match_ext_community_set,omitempty"`
+ MatchExtCommunitySet *ExtCommunitySet `protobuf:"bytes,6,opt,name=match_ext_community_set" json:"match_ext_community_set,omitempty"`
}
func (m *Conditions) Reset() { *m = Conditions{} }
diff --git a/api/gobgp.proto b/api/gobgp.proto
index 1a573977..98136bc6 100644
--- a/api/gobgp.proto
+++ b/api/gobgp.proto
@@ -377,20 +377,20 @@ message PeerInfo {
string bgp_state = 1;
string admin_state = 2;
uint32 fsm_established_transitions = 3;
- uint32 total_message_out = 4;
- uint32 total_message_in = 5;
- uint32 update_message_out = 6;
- uint32 update_message_in = 7;
- uint32 keep_alive_message_out = 8;
- uint32 keep_alive_message_in = 9;
- uint32 open_message_out = 10;
- uint32 open_message_in = 11;
- uint32 notification_out = 12;
- uint32 notification_in = 13;
- uint32 refresh_message_out = 14;
- uint32 refresh_message_in = 15;
- uint32 discarded_out = 16;
- uint32 discarded_in = 17;
+ uint64 total_message_out = 4;
+ uint64 total_message_in = 5;
+ uint64 update_message_out = 6;
+ uint64 update_message_in = 7;
+ uint64 keep_alive_message_out = 8;
+ uint64 keep_alive_message_in = 9;
+ uint64 open_message_out = 10;
+ uint64 open_message_in = 11;
+ uint64 notification_out = 12;
+ uint64 notification_in = 13;
+ uint64 refresh_message_out = 14;
+ uint64 refresh_message_in = 15;
+ uint64 discarded_out = 16;
+ uint64 discarded_in = 17;
int64 uptime = 18;
int64 downtime = 19;
string last_error = 20;
@@ -417,6 +417,7 @@ message Prefix {
message PrefixSet {
string prefix_set_name = 1;
repeated Prefix prefix_list = 2;
+ string match_set_options = 3;
}
message Neighbor {
@@ -426,6 +427,7 @@ message Neighbor {
message NeighborSet {
string neighbor_set_name = 1;
repeated Neighbor neighbor_list = 2;
+ string match_set_options = 3;
}
message AsPathLength {
@@ -436,16 +438,19 @@ message AsPathLength {
message AsPathSet {
string as_path_set_name = 1;
repeated string as_path_members = 2;
+ string match_set_options = 3;
}
message CommunitySet {
string community_set_name = 1;
repeated string community_members = 2;
+ string match_set_options = 3;
}
message ExtCommunitySet {
string ext_community_set_name = 1;
repeated string ext_community_members = 2;
+ string match_set_options = 3;
}
message Conditions {
@@ -454,8 +459,7 @@ message Conditions {
AsPathLength match_as_path_length = 3;
AsPathSet match_as_path_set = 4;
CommunitySet match_community_set = 5;
- string match_set_options = 6;
- ExtCommunitySet match_ext_community_set = 7;
+ ExtCommunitySet match_ext_community_set = 6;
}
message CommunityAction {
@@ -504,4 +508,4 @@ message ROA {
uint32 prefixlen = 2;
uint32 maxlen = 3;
string prefix = 4;
-} \ No newline at end of file
+}
diff --git a/config/bgp_configs.go b/config/bgp_configs.go
index 3f0381b5..adb4a1c5 100644
--- a/config/bgp_configs.go
+++ b/config/bgp_configs.go
@@ -17,447 +17,375 @@ package config
import "net"
-// typedef for typedef bgp:remove-private-as-option
+// typedef for typedef bgp-types:rr-cluster-id-type
+type RrClusterIdType string
+
+// typedef for typedef bgp-types:remove-private-as-option
type RemovePrivateAsOption int
const (
- REMOVE_PRIVATE_AS_OPTION_ALL = iota
+ REMOVE_PRIVATE_AS_OPTION_ALL RemovePrivateAsOption = iota
REMOVE_PRIVATE_AS_OPTION_REPLACE
)
-// typedef for typedef bgp:community-type
+// typedef for typedef bgp-types:bgp-community-regexp-type
+type BgpCommunityRegexpType string
+
+// typedef for typedef bgp-types:community-type
type CommunityType int
const (
- COMMUNITY_TYPE_STANDARD = iota
+ COMMUNITY_TYPE_STANDARD CommunityType = iota
COMMUNITY_TYPE_EXTENDED
COMMUNITY_TYPE_BOTH
COMMUNITY_TYPE_NONE
)
-// typedef for typedef bgp:rr-cluster-id-type
-type RrClusterIdType string
+// typedef for typedef bgp-types:bgp-ext-community-type
+type BgpExtCommunityType string
+
+// typedef for typedef bgp-types:bgp-std-community-type
+type BgpStdCommunityType string
-// typedef for typedef bgp:peer-type
+// typedef for typedef bgp-types:peer-type
type PeerTypeDef int
const (
- PEER_TYPE_INTERNAL = iota
+ PEER_TYPE_INTERNAL PeerTypeDef = iota
PEER_TYPE_EXTERNAL
)
-// typedef for typedef bgp:percentage
+// typedef for typedef bgp-types:percentage
type Percentage uint8
-// typedef for typedef bgp:bgp-origin-attr-type
+// typedef for typedef bgp-types:bgp-session-direction
+type BgpSessionDirection int
+
+const (
+ BGP_SESSION_DIRECTION_INBOUND BgpSessionDirection = iota
+ BGP_SESSION_DIRECTION_OUTBOUND
+)
+
+// typedef for typedef bgp-types:bgp-origin-attr-type
type BgpOriginAttrType int
const (
- BGP_ORIGIN_ATTR_TYPE_IGP = 0
- BGP_ORIGIN_ATTR_TYPE_EGP = 1
- BGP_ORIGIN_ATTR_TYPE_INCOMPLETE = 2
+ BGP_ORIGIN_ATTR_TYPE_IGP BgpOriginAttrType = 0
+ BGP_ORIGIN_ATTR_TYPE_EGP = 1
+ BGP_ORIGIN_ATTR_TYPE_INCOMPLETE = 2
)
-// typedef for typedef ptypes:igp-tag-type
-type IgpTagType string
+// typedef for typedef ptypes:match-set-options-restricted-type
+type MatchSetOptionsRestrictedType int
+
+const (
+ MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY MatchSetOptionsRestrictedType = iota
+ MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT
+)
// typedef for typedef ptypes:match-set-options-type
type MatchSetOptionsType int
const (
- MATCH_SET_OPTIONS_TYPE_ANY = iota
+ MATCH_SET_OPTIONS_TYPE_ANY MatchSetOptionsType = iota
MATCH_SET_OPTIONS_TYPE_ALL
MATCH_SET_OPTIONS_TYPE_INVERT
)
-// typedef for typedef rpol:install-protocol-type
-type InstallProtocolType int
-
-const (
- INSTALL_PROTOCOL_TYPE_ISIS = iota
- INSTALL_PROTOCOL_TYPE_OSPF
- INSTALL_PROTOCOL_TYPE_OSPF3
- INSTALL_PROTOCOL_TYPE_STATIC
- INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED
-)
+// typedef for typedef ptypes:tag-type
+type TagType string
// typedef for typedef rpol:default-policy-type
type DefaultPolicyType int
const (
- DEFAULT_POLICY_TYPE_ACCEPT_ROUTE = iota
+ DEFAULT_POLICY_TYPE_ACCEPT_ROUTE DefaultPolicyType = iota
DEFAULT_POLICY_TYPE_REJECT_ROUTE
)
-// typedef for typedef bgp-pol:bgp-set-community-option-type
-type BgpSetCommunityOptionType int
-
-const (
- BGP_SET_COMMUNITY_OPTION_TYPE_ADD = iota
- BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE
- BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE
- BGP_SET_COMMUNITY_OPTION_TYPE_NULL
-)
-
-// typedef for typedef bgp-pol:bgp-community-regexp-type
-type BgpCommunityRegexpType string
-
-// typedef for typedef bgp-pol:bgp-set-med-type
-type BgpSetMedType string
-
-// typedef for typedef bgp-pol:bgp-ext-community-type
-type BgpExtCommunityType string
+// typedef for typedef bgp-pol:bgp-next-hop-type
+type BgpNextHopType string
// typedef for typedef bgp-pol:bgp-as-path-prepend-repeat
type BgpAsPathPrependRepeat uint8
-// typedef for typedef bgp-pol:bgp-std-community-type
-type BgpStdCommunityType string
-
-// typedef for typedef bgp-pol:bgp-next-hop-type
-type BgpNextHopType string
+// typedef for typedef bgp-pol:bgp-set-med-type
+type BgpSetMedType string
-// typedef for typedef bgp-pol:bgp-well-known-community-type
-type BgpWellKnownCommunityType int
+// typedef for typedef bgp-pol:bgp-set-community-option-type
+type BgpSetCommunityOptionType int
const (
- BGP_WELL_KNOWN_COMMUNITY_TYPE_INTERNET = iota
- BGP_WELL_KNOWN_COMMUNITY_TYPE_NO_EXPORT
- BGP_WELL_KNOWN_COMMUNITY_TYPE_NO_ADVERTISE
- BGP_WELL_KNOWN_COMMUNITY_TYPE_NO_EXPORT_SUBCONFED
+ BGP_SET_COMMUNITY_OPTION_TYPE_ADD BgpSetCommunityOptionType = iota
+ BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE
+ BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE
)
-//struct for container bgp-pol:set-ext-community
-type SetExtCommunity struct {
- // original -> bgp-pol:communities
- //original type is list of union
- Communities []string
- // original -> bgp-pol:options
- //bgp-pol:options's original type is bgp-set-community-option-type
- Options string
-}
-
-//struct for container bgp-pol:set-community
-type SetCommunity struct {
- // original -> bgp-pol:communities
- //original type is list of union
- Communities []string
- // original -> bgp-pol:options
- //bgp-pol:options's original type is bgp-set-community-option-type
- Options string
-}
-
-//struct for container bgp-pol:set-as-path-prepend
-type SetAsPathPrepend struct {
- // original -> bgp-pol:as
- //bgp-pol:as's original type is union
- As string
- // original -> bgp-pol:repeat-n
- RepeatN uint8
-}
-
-//struct for container bgp-pol:bgp-actions
-type BgpActions struct {
- // original -> bgp-pol:set-as-path-prepend
- SetAsPathPrepend SetAsPathPrepend
- // original -> bgp-pol:set-community
- SetCommunity SetCommunity
- // original -> bgp-pol:set-ext-community
- SetExtCommunity SetExtCommunity
- // original -> bgp-pol:set-route-origin
- SetRouteOrigin BgpOriginAttrType
- // original -> bgp-pol:set-local-pref
- SetLocalPref uint32
- // original -> bgp-pol:set-next-hop
- SetNextHop BgpNextHopType
- // original -> bgp-pol:set-med
- SetMed BgpSetMedType
-}
-
-//struct for container rpol:igp-actions
-type IgpActions struct {
- // original -> rpol:set-tag
- SetTag IgpTagType
+//struct for container bgp:state
+type PeerGroupState struct {
+ // original -> bgp:peer-as
+ //bgp:peer-as's original type is inet:as-number
+ PeerAs uint32
+ // original -> bgp:local-as
+ //bgp:local-as's original type is inet:as-number
+ LocalAs uint32
+ // original -> bgp:peer-type
+ PeerType PeerTypeDef
+ // original -> bgp:auth-password
+ AuthPassword string
+ // original -> bgp:remove-private-as
+ RemovePrivateAs RemovePrivateAsOption
+ // original -> bgp:route-flap-damping
+ //bgp:route-flap-damping's original type is boolean
+ RouteFlapDamping bool
+ // original -> bgp:send-community
+ SendCommunity CommunityType
+ // original -> bgp:description
+ Description string
+ // original -> bgp:peer-group-name
+ PeerGroupName string
+ // original -> bgp-op:total-paths
+ TotalPaths uint32
+ // original -> bgp-op:total-prefixes
+ TotalPrefixes uint32
}
-//struct for container rpol:actions
-type Actions struct {
- // original -> rpol:accept-route
- //rpol:accept-route's original type is empty
- AcceptRoute bool
- // original -> rpol:reject-route
- //rpol:reject-route's original type is empty
- RejectRoute bool
- // original -> rpol:igp-actions
- IgpActions IgpActions
- // original -> bgp-pol:bgp-actions
- BgpActions BgpActions
+//struct for container bgp:config
+type PeerGroupConfig struct {
+ // original -> bgp:peer-as
+ //bgp:peer-as's original type is inet:as-number
+ PeerAs uint32
+ // original -> bgp:local-as
+ //bgp:local-as's original type is inet:as-number
+ LocalAs uint32
+ // original -> bgp:peer-type
+ PeerType PeerTypeDef
+ // original -> bgp:auth-password
+ AuthPassword string
+ // original -> bgp:remove-private-as
+ RemovePrivateAs RemovePrivateAsOption
+ // original -> bgp:route-flap-damping
+ //bgp:route-flap-damping's original type is boolean
+ RouteFlapDamping bool
+ // original -> bgp:send-community
+ SendCommunity CommunityType
+ // original -> bgp:description
+ Description string
+ // original -> bgp:peer-group-name
+ PeerGroupName string
}
-//struct for container bgp-pol:as-path-length
-type AsPathLength struct {
- // original -> ptypes:operator
- Operator string
- // original -> ptypes:value
- Value uint32
+//struct for container bgp:peer-group
+type PeerGroup struct {
+ // original -> bgp:peer-group-name
+ PeerGroupName string
+ // original -> bgp:peer-group-config
+ PeerGroupConfig PeerGroupConfig
+ // original -> bgp:peer-group-state
+ PeerGroupState PeerGroupState
+ // original -> bgp:timers
+ Timers Timers
+ // original -> bgp:transport
+ Transport Transport
+ // original -> bgp:error-handling
+ ErrorHandling ErrorHandling
+ // original -> bgp:logging-options
+ LoggingOptions LoggingOptions
+ // original -> bgp:ebgp-multihop
+ EbgpMultihop EbgpMultihop
+ // original -> bgp:route-reflector
+ RouteReflector RouteReflector
+ // original -> bgp:route-server
+ RouteServer RouteServer
+ // original -> bgp:as-path-options
+ AsPathOptions AsPathOptions
+ // original -> bgp:add-paths
+ AddPaths AddPaths
+ // original -> bgp:afi-safis
+ AfiSafis AfiSafis
+ // original -> bgp:graceful-restart
+ GracefulRestart GracefulRestart
+ // original -> rpol:apply-policy
+ ApplyPolicy ApplyPolicy
+ // original -> bgp-mp:use-multiple-paths
+ UseMultiplePaths UseMultiplePaths
}
-//struct for container bgp-pol:community-count
-type CommunityCount struct {
- // original -> ptypes:operator
- Operator string
- // original -> ptypes:value
- Value uint32
+//struct for container bgp:peer-groups
+type PeerGroups struct {
+ // original -> bgp:peer-group
+ PeerGroupList []PeerGroup
}
-//struct for container bgp-pol:bgp-conditions
-type BgpConditions struct {
- // original -> bgp-pol:match-community-set
- MatchCommunitySet string
- // original -> bgp-pol:match-ext-community-set
- MatchExtCommunitySet string
- // original -> bgp-pol:match-as-path-set
- MatchAsPathSet string
- // original -> bgp-pol:med-eq
- MedEq uint32
- // original -> bgp-pol:origin-eq
- OriginEq BgpOriginAttrType
- // original -> bgp-pol:next-hop-in
- //original type is list of inet:ip-address
- NextHopIn []net.IP
- // original -> bgp-pol:local-pref-eq
- LocalPrefEq uint32
- // original -> bgp-pol:community-count
- CommunityCount CommunityCount
- // original -> bgp-pol:as-path-length
- AsPathLength AsPathLength
- // original -> bgp-pol:route-type
- //bgp-pol:route-type's original type is enumeration
- RouteType string
+//struct for container bgp-op:prefixes
+type Prefixes struct {
+ // original -> bgp-op:received
+ Received uint32
+ // original -> bgp-op:sent
+ Sent uint32
+ // original -> bgp-op:installed
+ Installed uint32
}
-//struct for container rpol:igp-conditions
-type IgpConditions struct {
- // original -> rpol:tag-eq
- TagEq IgpTagType
+//struct for container bgp:state
+type AddPathsState struct {
+ // original -> bgp:receive
+ //bgp:receive's original type is boolean
+ Receive bool
+ // original -> bgp:send-max
+ SendMax uint8
}
-//struct for container rpol:conditions
-type Conditions struct {
- // original -> rpol:call-policy
- CallPolicy string
- // original -> rpol:match-prefix-set
- MatchPrefixSet string
- // original -> rpol:match-neighbor-set
- MatchNeighborSet string
- // original -> rpol:match-set-options
- MatchSetOptions MatchSetOptionsType
- // original -> rpol:install-protocol-eq
- InstallProtocolEq InstallProtocolType
- // original -> rpol:igp-conditions
- IgpConditions IgpConditions
- // original -> bgp-pol:bgp-conditions
- BgpConditions BgpConditions
+//struct for container bgp:config
+type AddPathsConfig struct {
+ // original -> bgp:receive
+ //bgp:receive's original type is boolean
+ Receive bool
+ // original -> bgp:send-max
+ SendMax uint8
}
-//struct for container rpol:statement
-type Statement struct {
- // original -> rpol:name
- Name string
- // original -> rpol:conditions
- Conditions Conditions
- // original -> rpol:actions
- Actions Actions
+//struct for container bgp:add-paths
+type AddPaths struct {
+ // original -> bgp:add-paths-config
+ AddPathsConfig AddPathsConfig
+ // original -> bgp:add-paths-state
+ AddPathsState AddPathsState
}
-//struct for container rpol:policy-definition
-type PolicyDefinition struct {
- // original -> rpol:name
- Name string
- // original -> rpol:statement
- StatementList []Statement
+//struct for container bgp:state
+type AsPathOptionsState struct {
+ // original -> bgp:allow-own-as
+ AllowOwnAs uint8
+ // original -> bgp:replace-peer-as
+ //bgp:replace-peer-as's original type is boolean
+ ReplacePeerAs bool
}
-//struct for container bgp-pol:as-path-set
-type AsPathSet struct {
- // original -> bgp-pol:as-path-set-name
- AsPathSetName string
- // original -> bgp-pol:as-path-set-members
- AsPathSetMembers []string
+//struct for container bgp:config
+type AsPathOptionsConfig struct {
+ // original -> bgp:allow-own-as
+ AllowOwnAs uint8
+ // original -> bgp:replace-peer-as
+ //bgp:replace-peer-as's original type is boolean
+ ReplacePeerAs bool
}
-//struct for container bgp-pol:ext-community-set
-type ExtCommunitySet struct {
- // original -> bgp-pol:ext-community-set-name
- ExtCommunitySetName string
- // original -> bgp-pol:ext-community-members
- //original type is list of union
- ExtCommunityMembers []string
+//struct for container bgp:as-path-options
+type AsPathOptions struct {
+ // original -> bgp:as-path-options-config
+ AsPathOptionsConfig AsPathOptionsConfig
+ // original -> bgp:as-path-options-state
+ AsPathOptionsState AsPathOptionsState
}
-//struct for container bgp-pol:community-set
-type CommunitySet struct {
- // original -> bgp-pol:community-set-name
- CommunitySetName string
- // original -> bgp-pol:community-members
- //original type is list of union
- CommunityMembers []string
+//struct for container bgp:route-server
+type RouteServer struct {
+ // original -> bgp:route-server-client
+ //bgp:route-server-client's original type is boolean
+ RouteServerClient bool
}
-//struct for container bgp-pol:bgp-defined-sets
-type BgpDefinedSets struct {
- // original -> bgp-pol:community-set
- CommunitySetList []CommunitySet
- // original -> bgp-pol:ext-community-set
- ExtCommunitySetList []ExtCommunitySet
- // original -> bgp-pol:as-path-set
- AsPathSetList []AsPathSet
+//struct for container bgp:state
+type RouteReflectorState struct {
+ // original -> bgp:route-reflector-cluster-id
+ RouteReflectorClusterId RrClusterIdType
+ // original -> bgp:route-reflector-client
+ //bgp:route-reflector-client's original type is boolean
+ RouteReflectorClient bool
}
-//struct for container rpol:neighbor-info
-type NeighborInfo struct {
- // original -> rpol:address
- //rpol:address's original type is inet:ip-address
- Address net.IP
+//struct for container bgp:config
+type RouteReflectorConfig struct {
+ // original -> bgp:route-reflector-cluster-id
+ RouteReflectorClusterId RrClusterIdType
+ // original -> bgp:route-reflector-client
+ //bgp:route-reflector-client's original type is boolean
+ RouteReflectorClient bool
}
-//struct for container rpol:neighbor-set
-type NeighborSet struct {
- // original -> rpol:neighbor-set-name
- NeighborSetName string
- // original -> rpol:neighbor-info
- NeighborInfoList []NeighborInfo
+//struct for container bgp:route-reflector
+type RouteReflector struct {
+ // original -> bgp:route-reflector-config
+ RouteReflectorConfig RouteReflectorConfig
+ // original -> bgp:route-reflector-state
+ RouteReflectorState RouteReflectorState
}
-//struct for container rpol:prefix
-type Prefix struct {
- // original -> rpol:address
- //rpol:address's original type is inet:ip-address
- Address net.IP
- // original -> rpol:masklength
- Masklength uint8
- // original -> rpol:masklength-range
- MasklengthRange string
+//struct for container bgp:state
+type EbgpMultihopState struct {
+ // original -> bgp:enabled
+ //bgp:enabled's original type is boolean
+ Enabled bool
+ // original -> bgp:multihop-ttl
+ MultihopTtl uint8
}
-//struct for container rpol:prefix-set
-type PrefixSet struct {
- // original -> rpol:prefix-set-name
- PrefixSetName string
- // original -> rpol:prefix
- PrefixList []Prefix
+//struct for container bgp:config
+type EbgpMultihopConfig struct {
+ // original -> bgp:enabled
+ //bgp:enabled's original type is boolean
+ Enabled bool
+ // original -> bgp:multihop-ttl
+ MultihopTtl uint8
}
-//struct for container rpol:defined-sets
-type DefinedSets struct {
- // original -> rpol:prefix-set
- PrefixSetList []PrefixSet
- // original -> rpol:neighbor-set
- NeighborSetList []NeighborSet
- // original -> bgp-pol:bgp-defined-sets
- BgpDefinedSets BgpDefinedSets
+//struct for container bgp:ebgp-multihop
+type EbgpMultihop struct {
+ // original -> bgp:ebgp-multihop-config
+ EbgpMultihopConfig EbgpMultihopConfig
+ // original -> bgp:ebgp-multihop-state
+ EbgpMultihopState EbgpMultihopState
}
-//struct for container rpol:routing-policy
-type RoutingPolicy struct {
- // original -> rpol:defined-sets
- DefinedSets DefinedSets
- // original -> rpol:policy-definition
- PolicyDefinitionList []PolicyDefinition
+//struct for container bgp:state
+type LoggingOptionsState struct {
+ // original -> bgp:log-neighbor-state-changes
+ //bgp:log-neighbor-state-changes's original type is boolean
+ LogNeighborStateChanges bool
}
-//struct for container rpol:apply-policy
-type ApplyPolicy struct {
- // original -> rpol:import-policies
- ImportPolicies []string
- // original -> rpol:default-import-policy
- DefaultImportPolicy DefaultPolicyType
- // original -> rpol:export-policies
- ExportPolicies []string
- // original -> rpol:default-export-policy
- DefaultExportPolicy DefaultPolicyType
- // original -> rpol:distribute-policies
- DistributePolicies []string
- // original -> rpol:default-distribute-policy
- DefaultDistributePolicy DefaultPolicyType
+//struct for container bgp:config
+type LoggingOptionsConfig struct {
+ // original -> bgp:log-neighbor-state-changes
+ //bgp:log-neighbor-state-changes's original type is boolean
+ LogNeighborStateChanges bool
}
-//struct for container bgp-op:bgp-neighbor-common-state
-type BgpNeighborCommonState struct {
- // original -> bgp-op:state
- State uint32
- // original -> bgp-op:uptime
- Uptime int64
- // original -> bgp-op:downtime
- Downtime int64
- // original -> bgp-op:open-in
- OpenIn uint32
- // original -> bgp-op:open-out
- OpenOut uint32
- // original -> bgp-op:update-in
- UpdateIn uint32
- // original -> bgp-op:update-out
- UpdateOut uint32
- // original -> bgp-op:update-recv-time
- UpdateRecvTime int64
- // original -> bgp-op:keepalive-in
- KeepaliveIn uint32
- // original -> bgp-op:keepalive-out
- KeepaliveOut uint32
- // original -> bgp-op:notify-in
- NotifyIn uint32
- // original -> bgp-op:notify-out
- NotifyOut uint32
- // original -> bgp-op:refresh-in
- RefreshIn uint32
- // original -> bgp-op:refresh-out
- RefreshOut uint32
- // original -> bgp-op:dynamic-cap-in
- DynamicCapIn uint32
- // original -> bgp-op:dynamic-cap-out
- DynamicCapOut uint32
- // original -> bgp-op:discarded-in
- DiscardedIn uint32
- // original -> bgp-op:discarded-out
- DiscardedOut uint32
- // original -> bgp-op:total-in
- TotalIn uint32
- // original -> bgp-op:total-out
- TotalOut uint32
- // original -> bgp-op:established-count
- EstablishedCount uint32
- // original -> bgp-op:flops
- Flops uint32
+//struct for container bgp:logging-options
+type LoggingOptions struct {
+ // original -> bgp:logging-options-config
+ LoggingOptionsConfig LoggingOptionsConfig
+ // original -> bgp:logging-options-state
+ LoggingOptionsState LoggingOptionsState
}
-//struct for container bgp:add-paths
-type AddPaths struct {
- // original -> bgp:receive
- //bgp:receive's original type is empty
- Receive bool
- // original -> bgp:send-max
- SendMax uint8
+//struct for container bgp:state
+type ErrorHandlingState struct {
+ // original -> bgp:treat-as-withdraw
+ //bgp:treat-as-withdraw's original type is boolean
+ TreatAsWithdraw bool
+ // original -> bgp-op:erroneous-update-messages
+ ErroneousUpdateMessages uint32
}
-//struct for container bgp:as-path-options
-type AsPathOptions struct {
- // original -> bgp:allow-own-as
- //bgp:allow-own-as's original type is boolean
- AllowOwnAs bool
- // original -> bgp:replace-peer-as
- //bgp:replace-peer-as's original type is boolean
- ReplacePeerAs bool
+//struct for container bgp:config
+type ErrorHandlingConfig struct {
+ // original -> bgp:treat-as-withdraw
+ //bgp:treat-as-withdraw's original type is boolean
+ TreatAsWithdraw bool
}
//struct for container bgp:error-handling
type ErrorHandling struct {
- // original -> bgp:treat-as-withdraw
- //bgp:treat-as-withdraw's original type is boolean
- TreatAsWithdraw bool
+ // original -> bgp:error-handling-config
+ ErrorHandlingConfig ErrorHandlingConfig
+ // original -> bgp:error-handling-state
+ ErrorHandlingState ErrorHandlingState
}
-//struct for container bgp:transport-options
-type TransportOptions struct {
+//struct for container bgp:state
+type TransportState struct {
// original -> bgp:tcp-mss
TcpMss uint16
// original -> bgp:mtu-discovery
@@ -466,266 +394,502 @@ type TransportOptions struct {
// original -> bgp:passive-mode
//bgp:passive-mode's original type is boolean
PassiveMode bool
+ // original -> bgp:local-address
+ //bgp:local-address's original type is inet:ip-address
+ LocalAddress net.IP
+ // original -> bgp-op:local-port
+ //bgp-op:local-port's original type is inet:port-number
+ LocalPort uint16
+ // original -> bgp-op:remote-address
+ //bgp-op:remote-address's original type is inet:ip-address
+ RemoteAddress net.IP
+ // original -> bgp-op:remote-port
+ //bgp-op:remote-port's original type is inet:port-number
+ RemotePort uint16
}
-//struct for container bgp:bgp-logging-options
-type BgpLoggingOptions struct {
- // original -> bgp:log-neighbor-state-changes
- //bgp:log-neighbor-state-changes's original type is boolean
- LogNeighborStateChanges bool
-}
-
-//struct for container bgp:route-server
-type RouteServer struct {
- // original -> bgp:route-server-client
- //bgp:route-server-client's original type is boolean
- RouteServerClient bool
-}
-
-//struct for container bgp:route-reflector
-type RouteReflector struct {
- // original -> bgp:route-reflector-cluster-id
- RouteReflectorClusterId RrClusterIdType
- // original -> bgp:route-reflector-client
- //bgp:route-reflector-client's original type is boolean
- RouteReflectorClient bool
+//struct for container bgp:config
+type TransportConfig struct {
+ // original -> bgp:tcp-mss
+ TcpMss uint16
+ // original -> bgp:mtu-discovery
+ //bgp:mtu-discovery's original type is boolean
+ MtuDiscovery bool
+ // original -> bgp:passive-mode
+ //bgp:passive-mode's original type is boolean
+ PassiveMode bool
+ // original -> bgp:local-address
+ //bgp:local-address's original type is inet:ip-address
+ LocalAddress net.IP
}
-//struct for container bgp:ebgp-multihop
-type EbgpMultihop struct {
- // original -> bgp:multihop-ttl
- MultihopTtl uint8
+//struct for container bgp:transport
+type Transport struct {
+ // original -> bgp:transport-config
+ TransportConfig TransportConfig
+ // original -> bgp:transport-state
+ TransportState TransportState
}
-//struct for container bgp:timers
-type Timers struct {
+//struct for container bgp:state
+type TimersState struct {
// original -> bgp:connect-retry
//bgp:connect-retry's original type is decimal64
ConnectRetry float64
// original -> bgp:hold-time
//bgp:hold-time's original type is decimal64
HoldTime float64
+ // original -> bgp:keepalive-interval
+ //bgp:keepalive-interval's original type is decimal64
+ KeepaliveInterval float64
// original -> bgp:idle-hold-time-after-reset
//bgp:idle-hold-time-after-reset's original type is decimal64
IdleHoldTimeAfterReset float64
+ // original -> bgp:minimum-advertisement-interval
+ //bgp:minimum-advertisement-interval's original type is decimal64
+ MinimumAdvertisementInterval float64
+ // original -> bgp-op:uptime
+ //bgp-op:uptime's original type is yang:timeticks
+ Uptime int64
+ // original -> bgp-op:downtime
+ //bgp-op:downtime's original type is yang:timeticks
+ Downtime int64
+ // original -> bgp-op:update-recv-time
+ UpdateRecvTime int64
+ // original -> bgp-op:negotiated-hold-time
+ //bgp-op:negotiated-hold-time's original type is decimal64
+ NegotiatedHoldTime float64
+}
+
+//struct for container bgp:config
+type TimersConfig struct {
+ // original -> bgp:connect-retry
+ //bgp:connect-retry's original type is decimal64
+ ConnectRetry float64
+ // original -> bgp:hold-time
+ //bgp:hold-time's original type is decimal64
+ HoldTime float64
// original -> bgp:keepalive-interval
//bgp:keepalive-interval's original type is decimal64
KeepaliveInterval float64
+ // original -> bgp:idle-hold-time-after-reset
+ //bgp:idle-hold-time-after-reset's original type is decimal64
+ IdleHoldTimeAfterReset float64
// original -> bgp:minimum-advertisement-interval
//bgp:minimum-advertisement-interval's original type is decimal64
MinimumAdvertisementInterval float64
- // original -> bgp:send-update-delay
- //bgp:send-update-delay's original type is decimal64
- SendUpdateDelay float64
}
-//struct for container bgp-mp:prefix-limit
-type PrefixLimit struct {
- // original -> bgp-mp:max-prefixes
- MaxPrefixes uint32
- // original -> bgp-mp:shutdown-threshold-pct
- ShutdownThresholdPct Percentage
- // original -> bgp-mp:restart-timer
- //bgp-mp:restart-timer's original type is decimal64
- RestartTimer float64
+//struct for container bgp:timers
+type Timers struct {
+ // original -> bgp:timers-config
+ TimersConfig TimersConfig
+ // original -> bgp:timers-state
+ TimersState TimersState
}
-//struct for container bgp-mp:l2vpn-evpn
-type L2vpnEvpn struct {
+//struct for container bgp:queues
+type Queues struct {
+ // original -> bgp-op:input
+ Input uint32
+ // original -> bgp-op:output
+ Output uint32
+}
+
+//struct for container bgp:received
+type Received struct {
+ // original -> bgp-op:UPDATE
+ Update uint64
+ // original -> bgp-op:NOTIFICATION
+ Notification uint64
+ // original -> bgp-op:OPEN
+ Open uint64
+ // original -> bgp-op:REFRESH
+ Refresh uint64
+ // original -> bgp-op:KEEPALIVE
+ Keepalive uint64
+ // original -> bgp-op:DYNAMIC-CAP
+ DynamicCap uint64
+ // original -> bgp-op:DISCARDED
+ Discarded uint64
+ // original -> bgp-op:TOTAL
+ Total uint64
+}
+
+//struct for container bgp:sent
+type Sent struct {
+ // original -> bgp-op:UPDATE
+ Update uint64
+ // original -> bgp-op:NOTIFICATION
+ Notification uint64
+ // original -> bgp-op:OPEN
+ Open uint64
+ // original -> bgp-op:REFRESH
+ Refresh uint64
+ // original -> bgp-op:KEEPALIVE
+ Keepalive uint64
+ // original -> bgp-op:DYNAMIC-CAP
+ DynamicCap uint64
+ // original -> bgp-op:DISCARDED
+ Discarded uint64
+ // original -> bgp-op:TOTAL
+ Total uint64
+}
+
+//struct for container bgp:messages
+type Messages struct {
+ // original -> bgp:sent
+ Sent Sent
+ // original -> bgp:received
+ Received Received
+}
+
+//struct for container bgp:state
+type NeighborState struct {
+ // original -> bgp:peer-as
+ //bgp:peer-as's original type is inet:as-number
+ PeerAs uint32
+ // original -> bgp:local-as
+ //bgp:local-as's original type is inet:as-number
+ LocalAs uint32
+ // original -> bgp:peer-type
+ PeerType PeerTypeDef
+ // original -> bgp:auth-password
+ AuthPassword string
+ // original -> bgp:remove-private-as
+ RemovePrivateAs RemovePrivateAsOption
+ // original -> bgp:route-flap-damping
+ //bgp:route-flap-damping's original type is boolean
+ RouteFlapDamping bool
+ // original -> bgp:send-community
+ SendCommunity CommunityType
+ // original -> bgp:description
+ Description string
+ // original -> bgp:peer-group
+ PeerGroup string
+ // original -> bgp:neighbor-address
+ //bgp:neighbor-address's original type is inet:ip-address
+ NeighborAddress net.IP
+ // original -> bgp-op:session-state
+ //bgp-op:session-state's original type is enumeration
+ SessionState uint32
+ // original -> bgp-op:supported-capabilities
+ //original type is list of identityref
+ SupportedCapabilities []string
+ // original -> bgp-op:established-count
+ EstablishedCount uint32
+ // original -> bgp-op:flops
+ Flops uint32
+ // original -> bgp:messages
+ Messages Messages
+ // original -> bgp:queues
+ Queues Queues
+}
+
+//struct for container bgp:config
+type NeighborConfig struct {
+ // original -> bgp:peer-as
+ //bgp:peer-as's original type is inet:as-number
+ PeerAs uint32
+ // original -> bgp:local-as
+ //bgp:local-as's original type is inet:as-number
+ LocalAs uint32
+ // original -> bgp:peer-type
+ PeerType PeerTypeDef
+ // original -> bgp:auth-password
+ AuthPassword string
+ // original -> bgp:remove-private-as
+ RemovePrivateAs RemovePrivateAsOption
+ // original -> bgp:route-flap-damping
+ //bgp:route-flap-damping's original type is boolean
+ RouteFlapDamping bool
+ // original -> bgp:send-community
+ SendCommunity CommunityType
+ // original -> bgp:description
+ Description string
+ // original -> bgp:peer-group
+ PeerGroup string
+ // original -> bgp:neighbor-address
+ //bgp:neighbor-address's original type is inet:ip-address
+ NeighborAddress net.IP
+}
+
+//struct for container bgp:neighbor
+type Neighbor struct {
+ // original -> bgp:neighbor-address
+ //bgp:neighbor-address's original type is inet:ip-address
+ NeighborAddress net.IP
+ // original -> bgp:neighbor-config
+ NeighborConfig NeighborConfig
+ // original -> bgp:neighbor-state
+ NeighborState NeighborState
+ // original -> bgp:timers
+ Timers Timers
+ // original -> bgp:transport
+ Transport Transport
+ // original -> bgp:error-handling
+ ErrorHandling ErrorHandling
+ // original -> bgp:logging-options
+ LoggingOptions LoggingOptions
+ // original -> bgp:ebgp-multihop
+ EbgpMultihop EbgpMultihop
+ // original -> bgp:route-reflector
+ RouteReflector RouteReflector
+ // original -> bgp:route-server
+ RouteServer RouteServer
+ // original -> bgp:as-path-options
+ AsPathOptions AsPathOptions
+ // original -> bgp:add-paths
+ AddPaths AddPaths
+ // original -> bgp:afi-safis
+ AfiSafis AfiSafis
+ // original -> bgp:graceful-restart
+ GracefulRestart GracefulRestart
// original -> rpol:apply-policy
ApplyPolicy ApplyPolicy
+ // original -> bgp-mp:use-multiple-paths
+ UseMultiplePaths UseMultiplePaths
+}
+
+//struct for container bgp:neighbors
+type Neighbors struct {
+ // original -> bgp:neighbor
+ NeighborList []Neighbor
+}
+
+//struct for container bgp-mp:l2vpn-evpn
+type L2vpnEvpn struct {
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:l2vpn-vpls
type L2vpnVpls struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:l3vpn-ipv6-multicast
type L3vpnIpv6Multicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:l3vpn-ipv4-multicast
type L3vpnIpv4Multicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:l3vpn-ipv6-unicast
type L3vpnIpv6Unicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:l3vpn-ipv4-unicast
type L3vpnIpv4Unicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:ipv6-labelled-unicast
type Ipv6LabelledUnicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
//struct for container bgp-mp:ipv4-labelled-unicast
type Ipv4LabelledUnicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
}
-//struct for container bgp-mp:ipv6-multicast
-type Ipv6Multicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
- // original -> bgp-mp:prefix-limit
- PrefixLimit PrefixLimit
+//struct for container bgp-mp:state
+type Ipv6UnicastState struct {
+ // original -> bgp-mp:send-default-route
+ //bgp-mp:send-default-route's original type is boolean
+ SendDefaultRoute bool
}
-//struct for container bgp-mp:ipv4-multicast
-type Ipv4Multicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
- // original -> bgp-mp:prefix-limit
- PrefixLimit PrefixLimit
+//struct for container bgp-mp:config
+type Ipv6UnicastConfig struct {
+ // original -> bgp-mp:send-default-route
+ //bgp-mp:send-default-route's original type is boolean
+ SendDefaultRoute bool
}
//struct for container bgp-mp:ipv6-unicast
type Ipv6Unicast struct {
- // original -> bgp-mp:enabled
- //bgp-mp:enabled's original type is boolean
- Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
// original -> bgp-mp:prefix-limit
PrefixLimit PrefixLimit
+ // original -> bgp-mp:ipv6-unicast-config
+ Ipv6UnicastConfig Ipv6UnicastConfig
+ // original -> bgp-mp:ipv6-unicast-state
+ Ipv6UnicastState Ipv6UnicastState
+}
+
+//struct for container bgp-mp:state
+type Ipv4UnicastState struct {
+ // original -> bgp-mp:send-default-route
+ //bgp-mp:send-default-route's original type is boolean
+ SendDefaultRoute bool
+}
+
+//struct for container bgp-mp:config
+type Ipv4UnicastConfig struct {
// original -> bgp-mp:send-default-route
//bgp-mp:send-default-route's original type is boolean
SendDefaultRoute bool
}
+//struct for container bgp-mp:state
+type PrefixLimitState struct {
+ // original -> bgp-mp:max-prefixes
+ MaxPrefixes uint32
+ // original -> bgp-mp:shutdown-threshold-pct
+ ShutdownThresholdPct Percentage
+ // original -> bgp-mp:restart-timer
+ //bgp-mp:restart-timer's original type is decimal64
+ RestartTimer float64
+}
+
+//struct for container bgp-mp:config
+type PrefixLimitConfig struct {
+ // original -> bgp-mp:max-prefixes
+ MaxPrefixes uint32
+ // original -> bgp-mp:shutdown-threshold-pct
+ ShutdownThresholdPct Percentage
+ // original -> bgp-mp:restart-timer
+ //bgp-mp:restart-timer's original type is decimal64
+ RestartTimer float64
+}
+
+//struct for container bgp-mp:prefix-limit
+type PrefixLimit struct {
+ // original -> bgp-mp:prefix-limit-config
+ PrefixLimitConfig PrefixLimitConfig
+ // original -> bgp-mp:prefix-limit-state
+ PrefixLimitState PrefixLimitState
+}
+
//struct for container bgp-mp:ipv4-unicast
type Ipv4Unicast struct {
+ // original -> bgp-mp:prefix-limit
+ PrefixLimit PrefixLimit
+ // original -> bgp-mp:ipv4-unicast-config
+ Ipv4UnicastConfig Ipv4UnicastConfig
+ // original -> bgp-mp:ipv4-unicast-state
+ Ipv4UnicastState Ipv4UnicastState
+}
+
+//struct for container rpol:state
+type ApplyPolicyState struct {
+ // original -> rpol:import-policy
+ ImportPolicy []string
+ // original -> rpol:default-import-policy
+ DefaultImportPolicy DefaultPolicyType
+ // original -> rpol:export-policy
+ ExportPolicy []string
+ // original -> rpol:default-export-policy
+ DefaultExportPolicy DefaultPolicyType
+ // original -> rpol:distribute-policy
+ DistributePolicy []string
+ // original -> rpol:default-distribute-policy
+ DefaultDistributePolicy DefaultPolicyType
+}
+
+//struct for container rpol:config
+type ApplyPolicyConfig struct {
+ // original -> rpol:import-policy
+ ImportPolicy []string
+ // original -> rpol:default-import-policy
+ DefaultImportPolicy DefaultPolicyType
+ // original -> rpol:export-policy
+ ExportPolicy []string
+ // original -> rpol:default-export-policy
+ DefaultExportPolicy DefaultPolicyType
+ // original -> rpol:distribute-policy
+ DistributePolicy []string
+ // original -> rpol:default-distribute-policy
+ DefaultDistributePolicy DefaultPolicyType
+}
+
+//struct for container rpol:apply-policy
+type ApplyPolicy struct {
+ // original -> rpol:apply-policy-config
+ ApplyPolicyConfig ApplyPolicyConfig
+ // original -> rpol:apply-policy-state
+ ApplyPolicyState ApplyPolicyState
+}
+
+//struct for container bgp-mp:state
+type AfiSafiState struct {
+ // original -> bgp-mp:afi-safi-name
+ AfiSafiName string
// original -> bgp-mp:enabled
//bgp-mp:enabled's original type is boolean
Enabled bool
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
- // original -> bgp-mp:prefix-limit
- PrefixLimit PrefixLimit
- // original -> bgp-mp:send-default-route
- //bgp-mp:send-default-route's original type is boolean
- SendDefaultRoute bool
+ // original -> bgp-op:total-paths
+ TotalPaths uint32
+ // original -> bgp-op:total-prefixes
+ TotalPrefixes uint32
}
-//struct for container bgp-mp:ibgp
-type Ibgp struct {
- // original -> bgp-mp:maximum-paths
- MaximumPaths uint32
+//struct for container bgp-mp:config
+type AfiSafiConfig struct {
+ // original -> bgp-mp:afi-safi-name
+ AfiSafiName string
+ // original -> bgp-mp:enabled
+ //bgp-mp:enabled's original type is boolean
+ Enabled bool
}
-//struct for container bgp-mp:ebgp
-type Ebgp struct {
- // original -> bgp-mp:allow-multiple-as
- //bgp-mp:allow-multiple-as's original type is boolean
- AllowMultipleAs bool
- // original -> bgp-mp:maximum-paths
- MaximumPaths uint32
+//struct for container bgp-mp:state
+type MpGracefulRestartState struct {
+ // original -> bgp-mp:enabled
+ //bgp-mp:enabled's original type is boolean
+ Enabled bool
+ // original -> bgp-op:received
+ //bgp-op:received's original type is boolean
+ Received bool
+ // original -> bgp-op:advertised
+ //bgp-op:advertised's original type is boolean
+ Advertised bool
}
-//struct for container bgp-mp:use-multiple-paths
-type UseMultiplePaths struct {
- // original -> bgp-mp:ebgp
- Ebgp Ebgp
- // original -> bgp-mp:ibgp
- Ibgp Ibgp
+//struct for container bgp-mp:config
+type MpGracefulRestartConfig struct {
+ // original -> bgp-mp:enabled
+ //bgp-mp:enabled's original type is boolean
+ Enabled bool
}
-//struct for container bgp-mp:route-selection-options
-type RouteSelectionOptions struct {
- // original -> bgp-mp:always-compare-med
- //bgp-mp:always-compare-med's original type is boolean
- AlwaysCompareMed bool
- // original -> bgp-mp:ignore-as-path-length
- //bgp-mp:ignore-as-path-length's original type is boolean
- IgnoreAsPathLength bool
- // original -> bgp-mp:external-compare-router-id
- //bgp-mp:external-compare-router-id's original type is boolean
- ExternalCompareRouterId bool
- // original -> bgp-mp:advertise-inactive-routes
- //bgp-mp:advertise-inactive-routes's original type is boolean
- AdvertiseInactiveRoutes bool
- // original -> bgp-mp:enable-aigp
- //bgp-mp:enable-aigp's original type is empty
- EnableAigp bool
- // original -> bgp-mp:ignore-next-hop-igp-metric
- //bgp-mp:ignore-next-hop-igp-metric's original type is boolean
- IgnoreNextHopIgpMetric bool
+//struct for container bgp-mp:graceful-restart
+type MpGracefulRestart struct {
+ // original -> bgp-mp:mp-graceful-restart-config
+ MpGracefulRestartConfig MpGracefulRestartConfig
+ // original -> bgp-mp:mp-graceful-restart-state
+ MpGracefulRestartState MpGracefulRestartState
}
//struct for container bgp-mp:afi-safi
type AfiSafi struct {
// original -> bgp-mp:afi-safi-name
+ //bgp-mp:afi-safi-name's original type is identityref
AfiSafiName string
- // original -> bgp-mp:route-selection-options
- RouteSelectionOptions RouteSelectionOptions
- // original -> bgp-mp:use-multiple-paths
- UseMultiplePaths UseMultiplePaths
+ // original -> bgp-mp:mp-graceful-restart
+ MpGracefulRestart MpGracefulRestart
+ // original -> bgp-mp:afi-safi-config
+ AfiSafiConfig AfiSafiConfig
+ // original -> bgp-mp:afi-safi-state
+ AfiSafiState AfiSafiState
+ // original -> rpol:apply-policy
+ ApplyPolicy ApplyPolicy
// original -> bgp-mp:ipv4-unicast
Ipv4Unicast Ipv4Unicast
// original -> bgp-mp:ipv6-unicast
Ipv6Unicast Ipv6Unicast
- // original -> bgp-mp:ipv4-multicast
- Ipv4Multicast Ipv4Multicast
- // original -> bgp-mp:ipv6-multicast
- Ipv6Multicast Ipv6Multicast
// original -> bgp-mp:ipv4-labelled-unicast
Ipv4LabelledUnicast Ipv4LabelledUnicast
// original -> bgp-mp:ipv6-labelled-unicast
@@ -742,133 +906,144 @@ type AfiSafi struct {
L2vpnVpls L2vpnVpls
// original -> bgp-mp:l2vpn-evpn
L2vpnEvpn L2vpnEvpn
+ // original -> bgp-mp:route-selection-options
+ RouteSelectionOptions RouteSelectionOptions
+ // original -> bgp-mp:use-multiple-paths
+ UseMultiplePaths UseMultiplePaths
}
-//struct for container bgp:graceful-restart
-type GracefulRestart struct {
+//struct for container bgp:afi-safis
+type AfiSafis struct {
+ // original -> bgp-mp:afi-safi
+ AfiSafiList []AfiSafi
+}
+
+//struct for container bgp:state
+type GracefulRestartState struct {
+ // original -> bgp:enabled
+ //bgp:enabled's original type is boolean
+ Enabled bool
// original -> bgp:restart-time
RestartTime uint16
// original -> bgp:stale-routes-time
//bgp:stale-routes-time's original type is decimal64
StaleRoutesTime float64
+ // original -> bgp:helper-only
+ //bgp:helper-only's original type is boolean
+ HelperOnly bool
+ // original -> bgp-op:peer-restart-time
+ PeerRestartTime uint16
+ // original -> bgp-op:peer-restarting
+ //bgp-op:peer-restarting's original type is boolean
+ PeerRestarting bool
+ // original -> bgp-op:local-restarting
+ //bgp-op:local-restarting's original type is boolean
+ LocalRestarting bool
+ // original -> bgp-op:mode
+ //bgp-op:mode's original type is enumeration
+ Mode uint32
}
-//struct for container bgp:neighbor
-type Neighbor struct {
- // original -> bgp:neighbor-address
- //bgp:neighbor-address's original type is inet:ip-address
- NeighborAddress net.IP
- // original -> bgp:peer-as
- //bgp:peer-as's original type is inet:as-number
- PeerAs uint32
- // original -> bgp:description
- Description string
- // original -> bgp:graceful-restart
- GracefulRestart GracefulRestart
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
- // original -> bgp-mp:use-multiple-paths
- UseMultiplePaths UseMultiplePaths
- // original -> bgp-mp:afi-safi
- AfiSafiList []AfiSafi
- // original -> bgp:auth-password
- AuthPassword string
- // original -> bgp:peer-type
- PeerType PeerTypeDef
- // original -> bgp:timers
- Timers Timers
- // original -> bgp:ebgp-multihop
- EbgpMultihop EbgpMultihop
- // original -> bgp:route-reflector
- RouteReflector RouteReflector
- // original -> bgp:route-server
- RouteServer RouteServer
- // original -> bgp:remove-private-as
- RemovePrivateAs RemovePrivateAsOption
- // original -> bgp:bgp-logging-options
- BgpLoggingOptions BgpLoggingOptions
- // original -> bgp:transport-options
- TransportOptions TransportOptions
- // original -> bgp:local-address
- //bgp:local-address's original type is inet:ip-address
- LocalAddress net.IP
- // original -> bgp:route-flap-damping
- //bgp:route-flap-damping's original type is boolean
- RouteFlapDamping bool
- // original -> bgp:send-community
- SendCommunity CommunityType
- // original -> bgp:error-handling
- ErrorHandling ErrorHandling
- // original -> bgp:as-path-options
- AsPathOptions AsPathOptions
- // original -> bgp:add-paths
- AddPaths AddPaths
- // original -> bgp-op:bgp-neighbor-common-state
- BgpNeighborCommonState BgpNeighborCommonState
+//struct for container bgp:config
+type GracefulRestartConfig struct {
+ // original -> bgp:enabled
+ //bgp:enabled's original type is boolean
+ Enabled bool
+ // original -> bgp:restart-time
+ RestartTime uint16
+ // original -> bgp:stale-routes-time
+ //bgp:stale-routes-time's original type is decimal64
+ StaleRoutesTime float64
+ // original -> bgp:helper-only
+ //bgp:helper-only's original type is boolean
+ HelperOnly bool
}
-//struct for container bgp-op:bgp-group-common-state
-type BgpGroupCommonState struct {
+//struct for container bgp:graceful-restart
+type GracefulRestart struct {
+ // original -> bgp:graceful-restart-config
+ GracefulRestartConfig GracefulRestartConfig
+ // original -> bgp:graceful-restart-state
+ GracefulRestartState GracefulRestartState
}
-//struct for container bgp:peer-group
-type PeerGroup struct {
- // original -> bgp:group-name
- GroupName string
- // original -> bgp-op:bgp-group-common-state
- BgpGroupCommonState BgpGroupCommonState
- // original -> bgp:description
- Description string
- // original -> bgp:graceful-restart
- GracefulRestart GracefulRestart
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
- // original -> bgp-mp:use-multiple-paths
- UseMultiplePaths UseMultiplePaths
- // original -> bgp-mp:afi-safi
- AfiSafiList []AfiSafi
- // original -> bgp:auth-password
- AuthPassword string
- // original -> bgp:peer-type
- PeerType PeerTypeDef
- // original -> bgp:timers
- Timers Timers
- // original -> bgp:ebgp-multihop
- EbgpMultihop EbgpMultihop
- // original -> bgp:route-reflector
- RouteReflector RouteReflector
- // original -> bgp:route-server
- RouteServer RouteServer
- // original -> bgp:remove-private-as
- RemovePrivateAs RemovePrivateAsOption
- // original -> bgp:bgp-logging-options
- BgpLoggingOptions BgpLoggingOptions
- // original -> bgp:transport-options
- TransportOptions TransportOptions
- // original -> bgp:local-address
- //bgp:local-address's original type is inet:ip-address
- LocalAddress net.IP
- // original -> bgp:route-flap-damping
- //bgp:route-flap-damping's original type is boolean
- RouteFlapDamping bool
- // original -> bgp:send-community
- SendCommunity CommunityType
- // original -> bgp:error-handling
- ErrorHandling ErrorHandling
- // original -> bgp:as-path-options
- AsPathOptions AsPathOptions
- // original -> bgp:add-paths
- AddPaths AddPaths
- // original -> bgp:neighbor
- NeighborList []Neighbor
+//struct for container bgp-mp:state
+type IbgpState struct {
+ // original -> bgp-mp:maximum-paths
+ MaximumPaths uint32
}
-//struct for container bgp-op:bgp-global-state
-type BgpGlobalState struct {
+//struct for container bgp-mp:config
+type IbgpConfig struct {
+ // original -> bgp-mp:maximum-paths
+ MaximumPaths uint32
}
-//struct for container bgp:confederation
-type Confederation struct {
+//struct for container bgp-mp:ibgp
+type Ibgp struct {
+ // original -> bgp-mp:ibgp-config
+ IbgpConfig IbgpConfig
+ // original -> bgp-mp:ibgp-state
+ IbgpState IbgpState
+}
+
+//struct for container bgp-mp:state
+type EbgpState struct {
+ // original -> bgp-mp:allow-multiple-as
+ //bgp-mp:allow-multiple-as's original type is boolean
+ AllowMultipleAs bool
+ // original -> bgp-mp:maximum-paths
+ MaximumPaths uint32
+}
+
+//struct for container bgp-mp:config
+type EbgpConfig struct {
+ // original -> bgp-mp:allow-multiple-as
+ //bgp-mp:allow-multiple-as's original type is boolean
+ AllowMultipleAs bool
+ // original -> bgp-mp:maximum-paths
+ MaximumPaths uint32
+}
+
+//struct for container bgp-mp:ebgp
+type Ebgp struct {
+ // original -> bgp-mp:ebgp-config
+ EbgpConfig EbgpConfig
+ // original -> bgp-mp:ebgp-state
+ EbgpState EbgpState
+}
+
+//struct for container bgp-mp:state
+type UseMultiplePathsState struct {
+ // original -> bgp-mp:enabled
+ //bgp-mp:enabled's original type is boolean
+ Enabled bool
+}
+
+//struct for container bgp-mp:config
+type UseMultiplePathsConfig struct {
+ // original -> bgp-mp:enabled
+ //bgp-mp:enabled's original type is boolean
+ Enabled bool
+}
+
+//struct for container bgp-mp:use-multiple-paths
+type UseMultiplePaths struct {
+ // original -> bgp-mp:use-multiple-paths-config
+ UseMultiplePathsConfig UseMultiplePathsConfig
+ // original -> bgp-mp:use-multiple-paths-state
+ UseMultiplePathsState UseMultiplePathsState
+ // original -> bgp-mp:ebgp
+ Ebgp Ebgp
+ // original -> bgp-mp:ibgp
+ Ibgp Ibgp
+}
+
+//struct for container bgp:state
+type ConfederationState struct {
+ // original -> bgp:enabled
+ //bgp:enabled's original type is boolean
+ Enabled bool
// original -> bgp:identifier
//bgp:identifier's original type is inet:as-number
Identifier uint32
@@ -877,42 +1052,524 @@ type Confederation struct {
MemberAs []uint32
}
-//struct for container bgp:default-route-distance
-type DefaultRouteDistance struct {
+//struct for container bgp:config
+type ConfederationConfig struct {
+ // original -> bgp:enabled
+ //bgp:enabled's original type is boolean
+ Enabled bool
+ // original -> bgp:identifier
+ //bgp:identifier's original type is inet:as-number
+ Identifier uint32
+ // original -> bgp:member-as
+ //original type is list of inet:as-number
+ MemberAs []uint32
+}
+
+//struct for container bgp:confederation
+type Confederation struct {
+ // original -> bgp:confederation-config
+ ConfederationConfig ConfederationConfig
+ // original -> bgp:confederation-state
+ ConfederationState ConfederationState
+}
+
+//struct for container bgp:state
+type DefaultRouteDistanceState struct {
// original -> bgp:external-route-distance
ExternalRouteDistance uint8
// original -> bgp:internal-route-distance
InternalRouteDistance uint8
}
-//struct for container bgp:global
-type Global struct {
+//struct for container bgp:config
+type DefaultRouteDistanceConfig struct {
+ // original -> bgp:external-route-distance
+ ExternalRouteDistance uint8
+ // original -> bgp:internal-route-distance
+ InternalRouteDistance uint8
+}
+
+//struct for container bgp:default-route-distance
+type DefaultRouteDistance struct {
+ // original -> bgp:default-route-distance-config
+ DefaultRouteDistanceConfig DefaultRouteDistanceConfig
+ // original -> bgp:default-route-distance-state
+ DefaultRouteDistanceState DefaultRouteDistanceState
+}
+
+//struct for container bgp-mp:state
+type RouteSelectionOptionsState struct {
+ // original -> bgp-mp:always-compare-med
+ //bgp-mp:always-compare-med's original type is boolean
+ AlwaysCompareMed bool
+ // original -> bgp-mp:ignore-as-path-length
+ //bgp-mp:ignore-as-path-length's original type is boolean
+ IgnoreAsPathLength bool
+ // original -> bgp-mp:external-compare-router-id
+ //bgp-mp:external-compare-router-id's original type is boolean
+ ExternalCompareRouterId bool
+ // original -> bgp-mp:advertise-inactive-routes
+ //bgp-mp:advertise-inactive-routes's original type is boolean
+ AdvertiseInactiveRoutes bool
+ // original -> bgp-mp:enable-aigp
+ //bgp-mp:enable-aigp's original type is boolean
+ EnableAigp bool
+ // original -> bgp-mp:ignore-next-hop-igp-metric
+ //bgp-mp:ignore-next-hop-igp-metric's original type is boolean
+ IgnoreNextHopIgpMetric bool
+}
+
+//struct for container bgp-mp:config
+type RouteSelectionOptionsConfig struct {
+ // original -> bgp-mp:always-compare-med
+ //bgp-mp:always-compare-med's original type is boolean
+ AlwaysCompareMed bool
+ // original -> bgp-mp:ignore-as-path-length
+ //bgp-mp:ignore-as-path-length's original type is boolean
+ IgnoreAsPathLength bool
+ // original -> bgp-mp:external-compare-router-id
+ //bgp-mp:external-compare-router-id's original type is boolean
+ ExternalCompareRouterId bool
+ // original -> bgp-mp:advertise-inactive-routes
+ //bgp-mp:advertise-inactive-routes's original type is boolean
+ AdvertiseInactiveRoutes bool
+ // original -> bgp-mp:enable-aigp
+ //bgp-mp:enable-aigp's original type is boolean
+ EnableAigp bool
+ // original -> bgp-mp:ignore-next-hop-igp-metric
+ //bgp-mp:ignore-next-hop-igp-metric's original type is boolean
+ IgnoreNextHopIgpMetric bool
+}
+
+//struct for container bgp-mp:route-selection-options
+type RouteSelectionOptions struct {
+ // original -> bgp-mp:route-selection-options-config
+ RouteSelectionOptionsConfig RouteSelectionOptionsConfig
+ // original -> bgp-mp:route-selection-options-state
+ RouteSelectionOptionsState RouteSelectionOptionsState
+}
+
+//struct for container bgp:state
+type GlobalState struct {
+ // original -> bgp:as
+ //bgp:as's original type is inet:as-number
+ As uint32
+ // original -> bgp:router-id
+ //bgp:router-id's original type is inet:ipv4-address
+ RouterId net.IP
+ // original -> bgp-op:total-paths
+ TotalPaths uint32
+ // original -> bgp-op:total-prefixes
+ TotalPrefixes uint32
+}
+
+//struct for container bgp:config
+type GlobalConfig struct {
// original -> bgp:as
//bgp:as's original type is inet:as-number
As uint32
// original -> bgp:router-id
//bgp:router-id's original type is inet:ipv4-address
RouterId net.IP
+}
+
+//struct for container bgp:global
+type Global struct {
+ // original -> bgp:global-config
+ GlobalConfig GlobalConfig
+ // original -> bgp:global-state
+ GlobalState GlobalState
+ // original -> bgp-mp:route-selection-options
+ RouteSelectionOptions RouteSelectionOptions
// original -> bgp:default-route-distance
DefaultRouteDistance DefaultRouteDistance
// original -> bgp:confederation
Confederation Confederation
// original -> bgp-mp:use-multiple-paths
UseMultiplePaths UseMultiplePaths
- // original -> bgp-mp:afi-safi
- AfiSafiList []AfiSafi
- // original -> bgp-op:bgp-global-state
- BgpGlobalState BgpGlobalState
+ // original -> bgp:graceful-restart
+ GracefulRestart GracefulRestart
+ // original -> bgp:afi-safis
+ AfiSafis AfiSafis
+ // original -> rpol:apply-policy
+ ApplyPolicy ApplyPolicy
}
//struct for container bgp:bgp
type Bgp struct {
// original -> bgp:global
Global Global
- // original -> bgp:peer-group
- PeerGroupList []PeerGroup
- // original -> bgp:neighbor
- NeighborList []Neighbor
- // original -> rpol:apply-policy
- ApplyPolicy ApplyPolicy
+ // original -> bgp:neighbors
+ Neighbors Neighbors
+ // original -> bgp:peer-groups
+ PeerGroups PeerGroups
+}
+
+//struct for container bgp-pol:set-ext-community-method
+type SetExtCommunityMethod struct {
+ // original -> bgp-pol:communities
+ //original type is list of union
+ Communities []string
+ // original -> bgp-pol:ext-community-set-ref
+ ExtCommunitySetRef string
+}
+
+//struct for container bgp-pol:set-ext-community
+type SetExtCommunity struct {
+ // original -> bgp-pol:set-ext-community-method
+ SetExtCommunityMethod SetExtCommunityMethod
+ // original -> bgp-pol:options
+ //bgp-pol:options's original type is bgp-set-community-option-type
+ Options string
+}
+
+//struct for container bgp-pol:set-community-method
+type SetCommunityMethod struct {
+ // original -> bgp-pol:communities
+ //original type is list of union
+ Communities []string
+ // original -> bgp-pol:community-set-ref
+ CommunitySetRef string
+}
+
+//struct for container bgp-pol:set-community
+type SetCommunity struct {
+ // original -> bgp-pol:set-community-method
+ SetCommunityMethod SetCommunityMethod
+ // original -> bgp-pol:options
+ //bgp-pol:options's original type is bgp-set-community-option-type
+ Options string
+}
+
+//struct for container bgp-pol:set-as-path-prepend
+type SetAsPathPrepend struct {
+ // original -> bgp-pol:as
+ //bgp-pol:as's original type is union
+ As string
+ // original -> bgp-pol:repeat-n
+ RepeatN uint8
+}
+
+//struct for container bgp-pol:bgp-actions
+type BgpActions struct {
+ // original -> bgp-pol:set-as-path-prepend
+ SetAsPathPrepend SetAsPathPrepend
+ // original -> bgp-pol:set-community
+ SetCommunity SetCommunity
+ // original -> bgp-pol:set-ext-community
+ SetExtCommunity SetExtCommunity
+ // original -> bgp-pol:set-route-origin
+ SetRouteOrigin BgpOriginAttrType
+ // original -> bgp-pol:set-local-pref
+ SetLocalPref uint32
+ // original -> bgp-pol:set-next-hop
+ SetNextHop BgpNextHopType
+ // original -> bgp-pol:set-med
+ SetMed BgpSetMedType
+}
+
+//struct for container rpol:igp-actions
+type IgpActions struct {
+ // original -> rpol:set-tag
+ SetTag TagType
+}
+
+//struct for container rpol:route-disposition
+type RouteDisposition struct {
+ // original -> rpol:accept-route
+ //rpol:accept-route's original type is empty
+ AcceptRoute bool
+ // original -> rpol:reject-route
+ //rpol:reject-route's original type is empty
+ RejectRoute bool
+}
+
+//struct for container rpol:actions
+type Actions struct {
+ // original -> rpol:route-disposition
+ RouteDisposition RouteDisposition
+ // original -> rpol:igp-actions
+ IgpActions IgpActions
+ // original -> bgp-pol:bgp-actions
+ BgpActions BgpActions
+}
+
+//struct for container bgp-pol:as-path-length
+type AsPathLength struct {
+ // original -> ptypes:operator
+ Operator string
+ // original -> ptypes:value
+ Value uint32
+}
+
+//struct for container bgp-pol:community-count
+type CommunityCount struct {
+ // original -> ptypes:operator
+ Operator string
+ // original -> ptypes:value
+ Value uint32
+}
+
+//struct for container bgp-pol:match-as-path-set
+type MatchAsPathSet struct {
+ // original -> bgp-pol:as-path-set
+ AsPathSet string
+ // original -> rpol:match-set-options
+ MatchSetOptions MatchSetOptionsType
+}
+
+//struct for container bgp-pol:match-ext-community-set
+type MatchExtCommunitySet struct {
+ // original -> bgp-pol:ext-community-set
+ ExtCommunitySet string
+ // original -> rpol:match-set-options
+ MatchSetOptions MatchSetOptionsType
+}
+
+//struct for container bgp-pol:match-community-set
+type MatchCommunitySet struct {
+ // original -> bgp-pol:community-set
+ CommunitySet string
+ // original -> rpol:match-set-options
+ MatchSetOptions MatchSetOptionsType
+}
+
+//struct for container bgp-pol:bgp-conditions
+type BgpConditions struct {
+ // original -> bgp-pol:match-community-set
+ MatchCommunitySet MatchCommunitySet
+ // original -> bgp-pol:match-ext-community-set
+ MatchExtCommunitySet MatchExtCommunitySet
+ // original -> bgp-pol:match-as-path-set
+ MatchAsPathSet MatchAsPathSet
+ // original -> bgp-pol:med-eq
+ MedEq uint32
+ // original -> bgp-pol:origin-eq
+ OriginEq BgpOriginAttrType
+ // original -> bgp-pol:next-hop-in
+ //original type is list of inet:ip-address
+ NextHopIn []net.IP
+ // original -> bgp-pol:local-pref-eq
+ LocalPrefEq uint32
+ // original -> bgp-pol:community-count
+ CommunityCount CommunityCount
+ // original -> bgp-pol:as-path-length
+ AsPathLength AsPathLength
+ // original -> bgp-pol:route-type
+ //bgp-pol:route-type's original type is enumeration
+ RouteType uint32
+}
+
+//struct for container rpol:igp-conditions
+type IgpConditions struct {
+}
+
+//struct for container rpol:match-tag-set
+type MatchTagSet struct {
+ // original -> rpol:tag-set
+ TagSet string
+ // original -> rpol:match-set-options
+ MatchSetOptions MatchSetOptionsRestrictedType
+}
+
+//struct for container rpol:match-neighbor-set
+type MatchNeighborSet struct {
+ // original -> rpol:neighbor-set
+ NeighborSet string
+ // original -> rpol:match-set-options
+ MatchSetOptions MatchSetOptionsRestrictedType
+}
+
+//struct for container rpol:match-prefix-set
+type MatchPrefixSet struct {
+ // original -> rpol:prefix-set
+ PrefixSet string
+ // original -> rpol:match-set-options
+ MatchSetOptions MatchSetOptionsRestrictedType
+}
+
+//struct for container rpol:conditions
+type Conditions struct {
+ // original -> rpol:call-policy
+ CallPolicy string
+ // original -> rpol:match-prefix-set
+ MatchPrefixSet MatchPrefixSet
+ // original -> rpol:match-neighbor-set
+ MatchNeighborSet MatchNeighborSet
+ // original -> rpol:match-tag-set
+ MatchTagSet MatchTagSet
+ // original -> rpol:install-protocol-eq
+ InstallProtocolEq string
+ // original -> rpol:igp-conditions
+ IgpConditions IgpConditions
+ // original -> bgp-pol:bgp-conditions
+ BgpConditions BgpConditions
+}
+
+//struct for container rpol:statement
+type Statement struct {
+ // original -> rpol:name
+ Name string
+ // original -> rpol:conditions
+ Conditions Conditions
+ // original -> rpol:actions
+ Actions Actions
+}
+
+//struct for container rpol:statements
+type Statements struct {
+ // original -> rpol:statement
+ StatementList []Statement
+}
+
+//struct for container rpol:policy-definition
+type PolicyDefinition struct {
+ // original -> rpol:name
+ Name string
+ // original -> rpol:statements
+ Statements Statements
+}
+
+//struct for container rpol:policy-definitions
+type PolicyDefinitions struct {
+ // original -> rpol:policy-definition
+ PolicyDefinitionList []PolicyDefinition
+}
+
+//struct for container bgp-pol:as-path-set
+type AsPathSet struct {
+ // original -> bgp-pol:as-path-set-name
+ AsPathSetName string
+ // original -> bgp-pol:as-path-set-member
+ AsPathSetMember []string
+}
+
+//struct for container bgp-pol:as-path-sets
+type AsPathSets struct {
+ // original -> bgp-pol:as-path-set
+ AsPathSetList []AsPathSet
+}
+
+//struct for container bgp-pol:ext-community-set
+type ExtCommunitySet struct {
+ // original -> bgp-pol:ext-community-set-name
+ ExtCommunitySetName string
+ // original -> bgp-pol:ext-community-member
+ //original type is list of union
+ ExtCommunityMember []string
+}
+
+//struct for container bgp-pol:ext-community-sets
+type ExtCommunitySets struct {
+ // original -> bgp-pol:ext-community-set
+ ExtCommunitySetList []ExtCommunitySet
+}
+
+//struct for container bgp-pol:community-set
+type CommunitySet struct {
+ // original -> bgp-pol:community-set-name
+ CommunitySetName string
+ // original -> bgp-pol:community-member
+ //original type is list of union
+ CommunityMember []string
+}
+
+//struct for container bgp-pol:community-sets
+type CommunitySets struct {
+ // original -> bgp-pol:community-set
+ CommunitySetList []CommunitySet
+}
+
+//struct for container bgp-pol:bgp-defined-sets
+type BgpDefinedSets struct {
+ // original -> bgp-pol:community-sets
+ CommunitySets CommunitySets
+ // original -> bgp-pol:ext-community-sets
+ ExtCommunitySets ExtCommunitySets
+ // original -> bgp-pol:as-path-sets
+ AsPathSets AsPathSets
+}
+
+//struct for container rpol:tag
+type Tag struct {
+ // original -> rpol:value
+ Value TagType
+}
+
+//struct for container rpol:tag-set
+type TagSet struct {
+ // original -> rpol:tag-set-name
+ TagSetName string
+ // original -> rpol:tag
+ TagList []Tag
+}
+
+//struct for container rpol:tag-sets
+type TagSets struct {
+ // original -> rpol:tag-set
+ TagSetList []TagSet
+}
+
+//struct for container rpol:neighbor-info
+type NeighborInfo struct {
+ // original -> rpol:address
+ //rpol:address's original type is inet:ip-address
+ Address net.IP
+}
+
+//struct for container rpol:neighbor-set
+type NeighborSet struct {
+ // original -> rpol:neighbor-set-name
+ NeighborSetName string
+ // original -> rpol:neighbor-info
+ NeighborInfoList []NeighborInfo
+}
+
+//struct for container rpol:neighbor-sets
+type NeighborSets struct {
+ // original -> rpol:neighbor-set
+ NeighborSetList []NeighborSet
+}
+
+//struct for container rpol:prefix
+type Prefix struct {
+ // original -> rpol:ip-prefix
+ //rpol:ip-prefix's original type is inet:ip-prefix
+ IpPrefix net.IPNet
+ // original -> rpol:masklength-range
+ MasklengthRange string
+}
+
+//struct for container rpol:prefix-set
+type PrefixSet struct {
+ // original -> rpol:prefix-set-name
+ PrefixSetName string
+ // original -> rpol:prefix
+ PrefixList []Prefix
+}
+
+//struct for container rpol:prefix-sets
+type PrefixSets struct {
+ // original -> rpol:prefix-set
+ PrefixSetList []PrefixSet
+}
+
+//struct for container rpol:defined-sets
+type DefinedSets struct {
+ // original -> rpol:prefix-sets
+ PrefixSets PrefixSets
+ // original -> rpol:neighbor-sets
+ NeighborSets NeighborSets
+ // original -> rpol:tag-sets
+ TagSets TagSets
+ // original -> bgp-pol:bgp-defined-sets
+ BgpDefinedSets BgpDefinedSets
+}
+
+//struct for container rpol:routing-policy
+type RoutingPolicy struct {
+ // original -> rpol:defined-sets
+ DefinedSets DefinedSets
+ // original -> rpol:policy-definitions
+ PolicyDefinitions PolicyDefinitions
}
diff --git a/config/default.go b/config/default.go
index f0c37f66..cdb37c32 100644
--- a/config/default.go
+++ b/config/default.go
@@ -29,8 +29,8 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
}
}
- if _, ok := global["Global.AfiSafiList"]; !ok {
- bt.Global.AfiSafiList = []AfiSafi{
+ if _, ok := global["Global.AfiSafis.AfiSafiList"]; !ok {
+ bt.Global.AfiSafis.AfiSafiList = []AfiSafi{
AfiSafi{AfiSafiName: "ipv4-unicast"},
AfiSafi{AfiSafiName: "ipv6-unicast"},
AfiSafi{AfiSafiName: "l3vpn-ipv4-unicast"},
@@ -43,10 +43,10 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
nidx := 0
for _, key := range md.Keys() {
- if !strings.HasPrefix(key.String(), "NeighborList") {
+ if !strings.HasPrefix(key.String(), "Neighbors.NeighborList") {
continue
}
- if key.String() == "NeighborList" {
+ if key.String() == "Neighbors.NeighborList" {
neighbors = append(neighbors, neighbor{attributes: make(map[string]bool)})
nidx++
} else {
@@ -54,30 +54,33 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
}
}
for i, n := range neighbors {
- if _, ok := n.attributes["NeighborList.Timers.ConnectRetry"]; !ok {
- bt.NeighborList[i].Timers.HoldTime = float64(DEFAULT_CONNECT_RETRY)
+ neighbor := &bt.Neighbors.NeighborList[i]
+ timerConfig := &neighbor.Timers.TimersConfig
+
+ if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.ConnectRetry"]; !ok {
+ timerConfig.HoldTime = float64(DEFAULT_CONNECT_RETRY)
}
- if _, ok := n.attributes["NeighborList.Timers.HoldTime"]; !ok {
- bt.NeighborList[i].Timers.HoldTime = float64(DEFAULT_HOLDTIME)
+ if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.HoldTime"]; !ok {
+ timerConfig.HoldTime = float64(DEFAULT_HOLDTIME)
}
- if _, ok := n.attributes["NeighborList.Timers.KeepaliveInterval"]; !ok {
- bt.NeighborList[i].Timers.KeepaliveInterval = bt.NeighborList[i].Timers.HoldTime / 3
+ if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.KeepaliveInterval"]; !ok {
+ timerConfig.KeepaliveInterval = timerConfig.HoldTime / 3
}
- if _, ok := n.attributes["NeighborList.Timers.IdleHoldTimeAfterReset"]; !ok {
- bt.NeighborList[i].Timers.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
+ if _, ok := n.attributes["Neighbors.NeighborList.Timers.TimersConfig.IdleHoldTimeAfterReset"]; !ok {
+ timerConfig.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET)
}
- if _, ok := n.attributes["NeighborList.AfiSafiList"]; !ok {
- if bt.NeighborList[i].NeighborAddress.To4() != nil {
- bt.NeighborList[i].AfiSafiList = []AfiSafi{
+ if _, ok := n.attributes["Neighbors.NeighborList.AfiSafis.AfiSafiList"]; !ok {
+ if neighbor.NeighborConfig.NeighborAddress.To4() != nil {
+ neighbor.AfiSafis.AfiSafiList = []AfiSafi{
AfiSafi{AfiSafiName: "ipv4-unicast"}}
} else {
- bt.NeighborList[i].AfiSafiList = []AfiSafi{
+ neighbor.AfiSafis.AfiSafiList = []AfiSafi{
AfiSafi{AfiSafiName: "ipv6-unicast"}}
}
} else {
- for _, rf := range bt.NeighborList[i].AfiSafiList {
+ for _, rf := range neighbor.AfiSafis.AfiSafiList {
_, err := bgp.GetRouteFamily(rf.AfiSafiName)
if err != nil {
return err
@@ -85,11 +88,11 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error {
}
}
- if _, ok := n.attributes["NeighborList.PeerType"]; !ok {
- if bt.NeighborList[i].PeerAs != bt.Global.As {
- bt.NeighborList[i].PeerType = PEER_TYPE_EXTERNAL
+ if _, ok := n.attributes["Neighbors.NeighborList.NeighborConfig"]; !ok {
+ if neighbor.NeighborConfig.PeerAs != bt.Global.GlobalConfig.As {
+ neighbor.NeighborConfig.PeerType = PEER_TYPE_EXTERNAL
} else {
- bt.NeighborList[i].PeerType = PEER_TYPE_INTERNAL
+ neighbor.NeighborConfig.PeerType = PEER_TYPE_INTERNAL
}
}
}
diff --git a/config/serve.go b/config/serve.go
index 390229c1..74529a16 100644
--- a/config/serve.go
+++ b/config/serve.go
@@ -37,7 +37,7 @@ func ReadConfigfileServe(path string, configCh chan BgpConfigSet, reloadCh chan
func inSlice(n Neighbor, b []Neighbor) bool {
for _, nb := range b {
- if nb.NeighborAddress.String() == n.NeighborAddress.String() {
+ if nb.NeighborConfig.NeighborAddress.String() == n.NeighborConfig.NeighborAddress.String() {
return true
}
}
@@ -56,19 +56,19 @@ func UpdateConfig(curC *Bgp, newC *Bgp) (*Bgp, []Neighbor, []Neighbor) {
added := []Neighbor{}
deleted := []Neighbor{}
- for _, n := range newC.NeighborList {
- if inSlice(n, curC.NeighborList) == false {
+ for _, n := range newC.Neighbors.NeighborList {
+ if inSlice(n, curC.Neighbors.NeighborList) == false {
added = append(added, n)
}
}
- for _, n := range curC.NeighborList {
- if inSlice(n, newC.NeighborList) == false {
+ for _, n := range curC.Neighbors.NeighborList {
+ if inSlice(n, newC.Neighbors.NeighborList) == false {
deleted = append(deleted, n)
}
}
- bgpConfig.NeighborList = newC.NeighborList
+ bgpConfig.Neighbors.NeighborList = newC.Neighbors.NeighborList
return &bgpConfig, added, deleted
}
diff --git a/gobgp/common.go b/gobgp/common.go
index 29928bac..436dae8a 100644
--- a/gobgp/common.go
+++ b/gobgp/common.go
@@ -76,7 +76,6 @@ var conditionOpts struct {
Community string `long:"community" description:"specifying a community set name of policy"`
ExtCommunity string `long:"extcommunity" description:"specifying a extended community set name of policy"`
AsPathLength string `long:"aspath-len" description:"specifying an as path length of policy (<operator>,<numeric>)"`
- Option string `long:"option" description:"specifying an option of policy (any | all | invert)"`
}
var actionOpts struct {
diff --git a/gobgp/neighbor.go b/gobgp/neighbor.go
index 3bf68352..7add621b 100644
--- a/gobgp/neighbor.go
+++ b/gobgp/neighbor.go
@@ -598,22 +598,22 @@ func showNeighborPolicy(remoteIP net.IP) error {
fmt.Printf("DefaultImportPolicy: %s\n", ap.DefaultImportPolicy)
fmt.Printf("DefaultExportPolicy: %s\n", ap.DefaultExportPolicy)
- fmt.Printf("DefaultDistributePolicy: %s\n", ap.DefaultDistributePolicy)
+ fmt.Printf("DefaultDistributePolicy: %s\n", ap.DefaultDistributePolicy)
fmt.Printf("ImportPolicies:\n")
for _, inPolicy := range ap.ImportPolicies {
fmt.Printf(" PolicyName %s:\n", inPolicy.PolicyDefinitionName)
- showPolicyStatement(" ", inPolicy)
+ showPolicyStatement(2, inPolicy)
}
fmt.Printf("ExportPolicies:\n")
for _, outPolicy := range ap.ExportPolicies {
fmt.Printf(" PolicyName %s:\n", outPolicy.PolicyDefinitionName)
- showPolicyStatement(" ", outPolicy)
+ showPolicyStatement(2, outPolicy)
+ }
+ fmt.Printf("DistributePolicies:\n")
+ for _, distPolicy := range ap.DistributePolicies {
+ fmt.Printf(" PolicyName %s:\n", distPolicy.PolicyDefinitionName)
+ showPolicyStatement(2, distPolicy)
}
- fmt.Printf("DistributePolicies:\n")
- for _, distPolicy := range ap.DistributePolicies {
- fmt.Printf(" PolicyName %s:\n", distPolicy.PolicyDefinitionName)
- showPolicyStatement(" ", distPolicy)
- }
return nil
}
diff --git a/gobgp/policy.go b/gobgp/policy.go
index e7adc5c4..8c13863c 100644
--- a/gobgp/policy.go
+++ b/gobgp/policy.go
@@ -30,11 +30,13 @@ import (
"strings"
)
-func formatPolicyPrefix(prefixSetList []*api.PrefixSet) (string, string) {
- maxNameLen := len("Name")
- maxPrefixLen := len("Prefix")
- maxRangeLen := len("MaskRange")
- for _, ps := range prefixSetList {
+func formatPolicyPrefix(head bool, indent int, psl []*api.PrefixSet) string {
+ buff := ""
+ sIndent := strings.Repeat(" ", indent)
+ maxNameLen := 0
+ maxPrefixLen := 0
+ maxRangeLen := 0
+ for _, ps := range psl {
if len(ps.PrefixSetName) > maxNameLen {
maxNameLen = len(ps.PrefixSetName)
}
@@ -47,9 +49,35 @@ func formatPolicyPrefix(prefixSetList []*api.PrefixSet) (string, string) {
}
}
}
- formatPrefixSet := "%-" + fmt.Sprint(maxNameLen) + "s %-" + fmt.Sprint(maxPrefixLen) + "s %-" + fmt.Sprint(maxRangeLen) + "s\n"
- formatPrefixListOnly := "%-" + fmt.Sprint(maxPrefixLen) + "s %-" + fmt.Sprint(maxRangeLen) + "s\n"
- return formatPrefixSet, formatPrefixListOnly
+
+ if head {
+ if len("Name") > maxNameLen {
+ maxNameLen = len("Name")
+ }
+ if len("Prefix") > maxPrefixLen {
+ maxPrefixLen = len("Prefix")
+ }
+ if len("MaskRange") > maxRangeLen {
+ maxRangeLen = len("MaskRange")
+ }
+ }
+
+ format := "%-" + fmt.Sprint(maxNameLen) + "s %-" + fmt.Sprint(maxPrefixLen) + "s %-" + fmt.Sprint(maxRangeLen) + "s\n"
+ if head {
+ buff += fmt.Sprintf(format, "Name", "Address", "MaskRange")
+ }
+ for _, ps := range psl {
+ for i, p := range ps.PrefixList {
+ prefix := fmt.Sprintf("%s/%d", p.Address, p.MaskLength)
+ if i == 0 {
+ buff += fmt.Sprintf(format, ps.PrefixSetName, prefix, p.MaskLengthRange)
+ } else {
+ buff += fmt.Sprintf(sIndent)
+ buff += fmt.Sprintf(format, "", prefix, p.MaskLengthRange)
+ }
+ }
+ }
+ return buff
}
func showPolicyPrefixes() error {
@@ -85,18 +113,9 @@ func showPolicyPrefixes() error {
}
sort.Sort(m)
- format, _ := formatPolicyPrefix(m)
- fmt.Printf(format, "Name", "Prefix", "MaskRange")
- for _, ps := range m {
- for i, p := range ps.PrefixList {
- prefix := fmt.Sprintf("%s/%d", p.Address, p.MaskLength)
- if i == 0 {
- fmt.Printf(format, ps.PrefixSetName, prefix, p.MaskLengthRange)
- } else {
- fmt.Printf(format, "", prefix, p.MaskLengthRange)
- }
- }
- }
+ output := formatPolicyPrefix(true, 0, m)
+ fmt.Print(output)
+
return nil
}
@@ -121,16 +140,8 @@ func showPolicyPrefix(args []string) error {
}
return nil
}
- format, _ := formatPolicyPrefix([]*api.PrefixSet{ps})
- fmt.Printf(format, "Name", "Prefix", "MaskRange")
- for i, p := range ps.PrefixList {
- prefix := fmt.Sprintf("%s/%d", p.Address, p.MaskLength)
- if i == 0 {
- fmt.Printf(format, ps.PrefixSetName, prefix, p.MaskLengthRange)
- } else {
- fmt.Printf(format, "", prefix, p.MaskLengthRange)
- }
- }
+ output := formatPolicyPrefix(true, 0, []*api.PrefixSet{ps})
+ fmt.Print(output)
return nil
}
@@ -271,10 +282,12 @@ func modPolicyPrefix(modtype string, eArgs []string) error {
return nil
}
-func formatPolicyNeighbor(neighborSetList []*api.NeighborSet) string {
- maxNameLen := len("Name")
- maxAddressLen := len("Address")
- for _, ns := range neighborSetList {
+func formatPolicyNeighbor(head bool, indent int, nsl []*api.NeighborSet) string {
+ buff := ""
+ sIndent := strings.Repeat(" ", indent)
+ maxNameLen := 0
+ maxAddressLen := 0
+ for _, ns := range nsl {
if len(ns.NeighborSetName) > maxNameLen {
maxNameLen = len(ns.NeighborSetName)
}
@@ -284,8 +297,31 @@ func formatPolicyNeighbor(neighborSetList []*api.NeighborSet) string {
}
}
}
+
+ if head {
+ if len("Name") > maxNameLen {
+ maxNameLen = len("Name")
+ }
+ if len("Address") > maxAddressLen {
+ maxAddressLen = len("Address")
+ }
+ }
+
format := "%-" + fmt.Sprint(maxNameLen) + "s %-" + fmt.Sprint(maxAddressLen) + "s\n"
- return format
+ if head {
+ buff += fmt.Sprintf(format, "Name", "Address")
+ }
+ for _, ns := range nsl {
+ for i, n := range ns.NeighborList {
+ if i == 0 {
+ buff += fmt.Sprintf(format, ns.NeighborSetName, n.Address)
+ } else {
+ buff += fmt.Sprintf(sIndent)
+ buff += fmt.Sprintf(format, "", n.Address)
+ }
+ }
+ }
+ return buff
}
func showPolicyNeighbors() error {
@@ -321,17 +357,8 @@ func showPolicyNeighbors() error {
}
sort.Sort(m)
- format := formatPolicyNeighbor(m)
- fmt.Printf(format, "Name", "Address")
- for _, ns := range m {
- for i, n := range ns.NeighborList {
- if i == 0 {
- fmt.Printf(format, ns.NeighborSetName, n.Address)
- } else {
- fmt.Printf(format, "", n.Address)
- }
- }
- }
+ output := formatPolicyNeighbor(true, 0, m)
+ fmt.Print(output)
return nil
}
@@ -356,16 +383,8 @@ func showPolicyNeighbor(args []string) error {
}
return nil
}
- format := formatPolicyNeighbor([]*api.NeighborSet{ns})
- fmt.Printf(format, "Name", "Address")
- for i, n := range ns.NeighborList {
- if i == 0 {
- fmt.Printf(format, ns.NeighborSetName, n.Address)
- } else {
- fmt.Printf(format, "", n.Address)
-
- }
- }
+ output := formatPolicyNeighbor(true, 0, []*api.NeighborSet{ns})
+ fmt.Print(output)
return nil
}
@@ -430,21 +449,46 @@ func modPolicyNeighbor(modtype string, eArgs []string) error {
return nil
}
-func formatPolicyAsPath(asPathSetList []*api.AsPathSet) string {
- maxNameLen := len("Name")
- maxPathLen := len("AsPath")
- for _, as := range asPathSetList {
- if len(as.AsPathSetName) > maxNameLen {
- maxNameLen = len(as.AsPathSetName)
+func formatPolicyAsPath(haed bool, indent int, apsl []*api.AsPathSet) string {
+ buff := ""
+ sIndent := strings.Repeat(" ", indent)
+ maxNameLen := 0
+ maxPathLen := 0
+ for _, aps := range apsl {
+ if len(aps.AsPathSetName) > maxNameLen {
+ maxNameLen = len(aps.AsPathSetName)
}
- for _, m := range as.AsPathMembers {
+ for _, m := range aps.AsPathMembers {
if len(m) > maxPathLen {
maxPathLen = len(m)
}
}
}
+
+ if haed {
+ if len("Name") > maxNameLen {
+ maxNameLen = len("Name")
+ }
+ if len("AsPath") > maxPathLen {
+ maxPathLen = len("AsPath")
+ }
+ }
+
format := "%-" + fmt.Sprint(maxNameLen) + "s %-" + fmt.Sprint(maxPathLen) + "s\n"
- return format
+ if haed {
+ buff += fmt.Sprintf(format, "Name", "AsPath")
+ }
+ for _, aps := range apsl {
+ for i, a := range aps.AsPathMembers {
+ if i == 0 {
+ buff += fmt.Sprintf(format, aps.AsPathSetName, a)
+ } else {
+ buff += fmt.Sprintf(sIndent)
+ buff += fmt.Sprintf(format, "", a)
+ }
+ }
+ }
+ return buff
}
func showPolicyAsPaths() error {
@@ -478,17 +522,8 @@ func showPolicyAsPaths() error {
}
sort.Sort(m)
- format := formatPolicyAsPath(m)
- fmt.Printf(format, "Name", "AsPath")
- for _, as := range m {
- for i, m := range as.AsPathMembers {
- if i == 0 {
- fmt.Printf(format, as.AsPathSetName, m)
- } else {
- fmt.Printf(format, "", m)
- }
- }
- }
+ output := formatPolicyAsPath(true, 0, m)
+ fmt.Print(output)
return nil
}
@@ -513,15 +548,8 @@ func showPolicyAsPath(args []string) error {
}
return nil
}
- format := formatPolicyAsPath([]*api.AsPathSet{as})
- fmt.Printf(format, "Name", "AsPath")
- for i, m := range as.AsPathMembers {
- if i == 0 {
- fmt.Printf(format, as.AsPathSetName, m)
- } else {
- fmt.Printf(format, "", m)
- }
- }
+ output := formatPolicyAsPath(true, 0, []*api.AsPathSet{as})
+ fmt.Print(output)
return nil
}
@@ -579,10 +607,12 @@ func modPolicyAsPath(modtype string, eArgs []string) error {
return nil
}
-func formatPolicyCommunity(CommunitySetList []*api.CommunitySet) string {
- maxNameLen := len("Name")
- maxCommunityLen := len("Community")
- for _, cs := range CommunitySetList {
+func formatPolicyCommunity(head bool, indent int, csl []*api.CommunitySet) string {
+ buff := ""
+ sIndent := strings.Repeat(" ", indent)
+ maxNameLen := 0
+ maxCommunityLen := 0
+ for _, cs := range csl {
if len(cs.CommunitySetName) > maxNameLen {
maxNameLen = len(cs.CommunitySetName)
}
@@ -592,8 +622,31 @@ func formatPolicyCommunity(CommunitySetList []*api.CommunitySet) string {
}
}
}
+
+ if head {
+ if len("Name") > maxNameLen {
+ maxNameLen = len("Name")
+ }
+ if len("Community") > maxCommunityLen {
+ maxCommunityLen = len("Community")
+ }
+ }
+
format := "%-" + fmt.Sprint(maxNameLen) + "s %-" + fmt.Sprint(maxCommunityLen) + "s\n"
- return format
+ if head {
+ buff += fmt.Sprintf(format, "Name", "Community")
+ }
+ for _, cs := range csl {
+ for i, c := range cs.CommunityMembers {
+ if i == 0 {
+ buff += fmt.Sprintf(format, cs.CommunitySetName, c)
+ } else {
+ buff += fmt.Sprintf(sIndent)
+ buff += fmt.Sprintf(format, "", c)
+ }
+ }
+ }
+ return buff
}
func showPolicyCommunities() error {
@@ -627,17 +680,8 @@ func showPolicyCommunities() error {
}
sort.Sort(m)
- format := formatPolicyCommunity(m)
- fmt.Printf(format, "Name", "Community")
- for _, cs := range m {
- for i, m := range cs.CommunityMembers {
- if i == 0 {
- fmt.Printf(format, cs.CommunitySetName, m)
- } else {
- fmt.Printf(format, "", m)
- }
- }
- }
+ output := formatPolicyCommunity(true, 0, m)
+ fmt.Print(output)
return nil
}
@@ -662,15 +706,8 @@ func showPolicyCommunity(args []string) error {
}
return nil
}
- format := formatPolicyCommunity([]*api.CommunitySet{cs})
- fmt.Printf(format, "Name", "Community")
- for i, m := range cs.CommunityMembers {
- if i == 0 {
- fmt.Printf(format, cs.CommunitySetName, m)
- } else {
- fmt.Printf(format, "", m)
- }
- }
+ output := formatPolicyCommunity(true, 0, []*api.CommunitySet{cs})
+ fmt.Print(output)
return nil
}
@@ -744,10 +781,12 @@ func modPolicyCommunity(modtype string, eArgs []string) error {
return nil
}
-func formatPolicyExtCommunity(ExtCommunitySetList []*api.ExtCommunitySet) string {
- maxNameLen := len("Name")
- maxCommunityLen := len("ExtCommunity")
- for _, es := range ExtCommunitySetList {
+func formatPolicyExtCommunity(head bool, indent int, ecsl []*api.ExtCommunitySet) string {
+ buff := ""
+ sIndent := strings.Repeat(" ", indent)
+ maxNameLen := 0
+ maxCommunityLen := 0
+ for _, es := range ecsl {
if len(es.ExtCommunitySetName) > maxNameLen {
maxNameLen = len(es.ExtCommunitySetName)
}
@@ -757,8 +796,31 @@ func formatPolicyExtCommunity(ExtCommunitySetList []*api.ExtCommunitySet) string
}
}
}
+
+ if head {
+ if len("Name") > maxNameLen {
+ maxNameLen = len("Name")
+ }
+ if len("ExtCommunity") > maxCommunityLen {
+ maxCommunityLen = len("ExtCommunity")
+ }
+ }
+
format := "%-" + fmt.Sprint(maxNameLen) + "s %-" + fmt.Sprint(maxCommunityLen) + "s\n"
- return format
+ if head {
+ buff += fmt.Sprintf(format, "Name", "ExtCommunity")
+ }
+ for _, ecs := range ecsl {
+ for i, ec := range ecs.ExtCommunityMembers {
+ if i == 0 {
+ buff += fmt.Sprintf(format, ecs.ExtCommunitySetName, ec)
+ } else {
+ buff += fmt.Sprintf(sIndent)
+ buff += fmt.Sprintf(format, "", ec)
+ }
+ }
+ }
+ return buff
}
func showPolicyExtCommunities() error {
@@ -792,17 +854,8 @@ func showPolicyExtCommunities() error {
}
sort.Sort(m)
- format := formatPolicyExtCommunity(m)
- fmt.Printf(format, "Name", "ExtCommunity")
- for _, es := range m {
- for i, m := range es.ExtCommunityMembers {
- if i == 0 {
- fmt.Printf(format, es.ExtCommunitySetName, m)
- } else {
- fmt.Printf(format, "", m)
- }
- }
- }
+ output := formatPolicyExtCommunity(true, 0, m)
+ fmt.Print(output)
return nil
}
@@ -815,27 +868,20 @@ func showPolicyExtCommunity(args []string) error {
if e != nil {
return e
}
- es := pd.StatementList[0].Conditions.GetMatchExtCommunitySet()
+ ecs := pd.StatementList[0].Conditions.GetMatchExtCommunitySet()
if globalOpts.Json {
- j, _ := json.Marshal(es)
+ j, _ := json.Marshal(ecs)
fmt.Println(string(j))
return nil
}
if globalOpts.Quiet {
- for _, e := range es.ExtCommunityMembers {
- fmt.Println(e)
+ for _, ec := range ecs.ExtCommunityMembers {
+ fmt.Println(ec)
}
return nil
}
- format := formatPolicyExtCommunity([]*api.ExtCommunitySet{es})
- fmt.Printf(format, "Name", "ExtCommunity")
- for i, m := range es.ExtCommunityMembers {
- if i == 0 {
- fmt.Printf(format, es.ExtCommunitySetName, m)
- } else {
- fmt.Printf(format, "", m)
- }
- }
+ output := formatPolicyExtCommunity(true, 0, []*api.ExtCommunitySet{ecs})
+ fmt.Print(output)
return nil
}
@@ -937,94 +983,66 @@ func modPolicyExtCommunity(modtype string, eArgs []string) error {
return nil
}
-func showPolicyStatement(head string, pd *api.PolicyDefinition) {
+func showPolicyStatement(indent int, pd *api.PolicyDefinition) {
+ sIndent := func(indent int) string {
+ return strings.Repeat(" ", indent)
+ }
+ baseIndent := 28
for _, st := range pd.StatementList {
- fmt.Printf("%s StatementName %s:\n", head, st.StatementNeme)
- fmt.Printf("%s Conditions:\n", head)
- prefixSet := st.Conditions.MatchPrefixSet
- fmt.Printf("%s PrefixSet: %s ", head, prefixSet.PrefixSetName)
- if len(prefixSet.PrefixList) != 0 {
- nameFormat := "%-" + fmt.Sprint(len(prefixSet.PrefixSetName)+2) + "s"
- _, format := formatPolicyPrefix([]*api.PrefixSet{st.Conditions.MatchPrefixSet})
- for i, prefix := range prefixSet.PrefixList {
- p := fmt.Sprintf("%s/%d", prefix.Address, prefix.MaskLength)
- if i != 0 {
- fmt.Printf("%s ", head)
- fmt.Printf(nameFormat, "")
- }
- fmt.Printf(format, p, prefix.MaskLengthRange)
- }
+ fmt.Printf("%sStatementName %s:\n", sIndent(indent), st.StatementNeme)
+ fmt.Printf("%sConditions:\n", sIndent(indent+2))
+
+ ps := st.Conditions.MatchPrefixSet
+ fmt.Printf("%sPrefixSet: %-6s ", sIndent(indent+4), ps.MatchSetOptions)
+ if out := formatPolicyPrefix(false, baseIndent+indent, []*api.PrefixSet{ps}); out != "" {
+ fmt.Print(out)
} else {
- fmt.Print("\n")
- }
- neighborSet := st.Conditions.MatchNeighborSet
- fmt.Printf("%s NeighborSet: %s ", head, neighborSet.NeighborSetName)
- if len(neighborSet.NeighborList) != 0 {
- nameFormat := "%-" + fmt.Sprint(len(neighborSet.NeighborSetName)+2) + "s"
- for i, neighbor := range neighborSet.NeighborList {
- if i != 0 {
- fmt.Printf("%s ", head)
- fmt.Printf(nameFormat, "")
- }
- fmt.Println(neighbor.Address)
- }
+ fmt.Printf("\n")
+ }
+
+ ns := st.Conditions.MatchNeighborSet
+ fmt.Printf("%sNeighborSet: %-6s ", sIndent(indent+4), ns.MatchSetOptions)
+ if out := formatPolicyNeighbor(false, baseIndent+indent, []*api.NeighborSet{ns}); out != "" {
+ fmt.Print(out)
} else {
- fmt.Print("\n")
- }
- asPathSet := st.Conditions.MatchAsPathSet
- fmt.Printf("%s AsPathSet: %s ", head, asPathSet.AsPathSetName)
- if len(asPathSet.AsPathMembers) != 0 {
- nameFormat := "%-" + fmt.Sprint(len(asPathSet.AsPathSetName)+2) + "s"
- for i, asPath := range asPathSet.AsPathMembers {
- if i != 0 {
- fmt.Printf("%s ", head)
- fmt.Printf(nameFormat, "")
- }
- fmt.Println(asPath)
- }
+ fmt.Printf("\n")
+ }
+
+ aps := st.Conditions.MatchAsPathSet
+ fmt.Printf("%sAsPathSet: %-6s ", sIndent(indent+4), aps.MatchSetOptions)
+ if out := formatPolicyAsPath(false, baseIndent+indent, []*api.AsPathSet{aps}); out != "" {
+ fmt.Print(out)
} else {
- fmt.Print("\n")
- }
- communitySet := st.Conditions.MatchCommunitySet
- fmt.Printf("%s CommunitySet: %s ", head, communitySet.CommunitySetName)
- if len(communitySet.CommunityMembers) != 0 {
- nameFormat := "%-" + fmt.Sprint(len(communitySet.CommunitySetName)+2) + "s"
- for i, community := range communitySet.CommunityMembers {
- if i != 0 {
- fmt.Printf("%s ", head)
- fmt.Printf(nameFormat, "")
- }
- fmt.Println(community)
- }
+ fmt.Printf("\n")
+ }
+
+ cs := st.Conditions.MatchCommunitySet
+ fmt.Printf("%sCommunitySet: %-6s ", sIndent(indent+4), cs.MatchSetOptions)
+ if out := formatPolicyCommunity(false, baseIndent+indent, []*api.CommunitySet{cs}); out != "" {
+ fmt.Print(out)
} else {
- fmt.Print("\n")
- }
- extCommunitySet := st.Conditions.MatchExtCommunitySet
- fmt.Printf("%s ExtCommunitySet: %s ", head, extCommunitySet.ExtCommunitySetName)
- if len(extCommunitySet.ExtCommunityMembers) != 0 {
- nameFormat := "%-" + fmt.Sprint(len(extCommunitySet.ExtCommunitySetName)+2) + "s"
- for i, ecommunity := range extCommunitySet.ExtCommunityMembers {
- if i != 0 {
- fmt.Printf("%s ", head)
- fmt.Printf(nameFormat, "")
- }
- fmt.Println(ecommunity)
- }
+ fmt.Printf("\n")
+ }
+
+ ecs := st.Conditions.MatchExtCommunitySet
+ fmt.Printf("%sExtCommunitySet: %-6s ", sIndent(indent+4), ecs.MatchSetOptions)
+ if out := formatPolicyExtCommunity(false, baseIndent+indent, []*api.ExtCommunitySet{ecs}); out != "" {
+ fmt.Print(out)
} else {
- fmt.Print("\n")
+ fmt.Printf("\n")
}
+
asPathLentgh := st.Conditions.MatchAsPathLength
- fmt.Printf("%s AsPathLength: %s %s\n", head, asPathLentgh.Operator, asPathLentgh.Value)
- fmt.Printf("%s MatchOption: %s\n", head, st.Conditions.MatchSetOptions)
- fmt.Printf("%s Actions:\n", head)
+ fmt.Printf("%sAsPathLength: %-6s %s\n", sIndent(indent+4), asPathLentgh.Operator, asPathLentgh.Value)
+ fmt.Printf("%sActions:\n", sIndent(indent+2))
communityAction := st.Actions.Community.Options
if len(st.Actions.Community.Communities) != 0 || st.Actions.Community.Options == "NULL" {
communities := strings.Join(st.Actions.Community.Communities, ",")
communityAction = fmt.Sprintf("%s[%s]", st.Actions.Community.Options, communities)
}
- fmt.Printf("%s Community: %s\n", head, communityAction)
- fmt.Printf("%s Med: %s\n", head, st.Actions.Med)
+ fmt.Printf("%sCommunity: %s\n", sIndent(indent+4), communityAction)
+ fmt.Printf("%sMed: %s\n", sIndent(indent+4), st.Actions.Med)
asn := ""
repeat := ""
@@ -1032,8 +1050,8 @@ func showPolicyStatement(head string, pd *api.PolicyDefinition) {
asn = st.Actions.AsPrepend.As
repeat = fmt.Sprintf("%d", st.Actions.AsPrepend.Repeatn)
}
- fmt.Printf("%s AsPrepend: %s %s\n", head, asn, repeat)
- fmt.Printf("%s %s\n", head, st.Actions.RouteAction)
+ fmt.Printf("%sAsPrepend: %s %s\n", sIndent(indent+4), asn, repeat)
+ fmt.Printf("%s%s\n", sIndent(indent+4), st.Actions.RouteAction)
}
}
@@ -1072,7 +1090,7 @@ func showPolicyRoutePolicies() error {
for _, pd := range m {
fmt.Printf("PolicyName %s:\n", pd.PolicyDefinitionName)
- showPolicyStatement("", pd)
+ showPolicyStatement(4, pd)
}
return nil
}
@@ -1101,35 +1119,79 @@ func showPolicyRoutePolicy(args []string) error {
}
fmt.Printf("PolicyName %s:\n", pd.PolicyDefinitionName)
- showPolicyStatement("", pd)
+ showPolicyStatement(2, pd)
return nil
}
func parseConditions() (*api.Conditions, error) {
+ checkFormat := func(option string, isRestricted bool) ([]string, error) {
+ regStr, _ := regexp.Compile("^(.*)\\[(.*)\\]$")
+ isMatched := regStr.MatchString(option)
+ if !isMatched {
+ return nil, fmt.Errorf("Please enter the <match option>[condition name]")
+ }
+ group := regStr.FindStringSubmatch(option)
+ if isRestricted {
+ if group[1] != "ANY" && group[1] != "INVERT" {
+ return nil, fmt.Errorf("Please enter the <ANY|INVERT>[condition name]")
+ }
+ } else {
+ if group[1] != "ANY" && group[1] != "ALL" && group[1] != "INVERT" {
+ return nil, fmt.Errorf("Please enter the <ANY|ALL|INVERT>[condition name]")
+ }
+ }
+ return group, nil
+ }
+
conditions := &api.Conditions{}
if conditionOpts.Prefix != "" {
+ op, err := checkFormat(conditionOpts.Prefix, true)
+ if err != nil {
+ return nil, fmt.Errorf("invalid prefix option format\n%s", err)
+ }
conditions.MatchPrefixSet = &api.PrefixSet{
- PrefixSetName: conditionOpts.Prefix,
+ PrefixSetName: op[2],
+ MatchSetOptions: op[1],
}
}
if conditionOpts.Neighbor != "" {
+ op, err := checkFormat(conditionOpts.Neighbor, true)
+ if err != nil {
+ return nil, fmt.Errorf("invalid neighbor option format\n%s", err)
+ }
conditions.MatchNeighborSet = &api.NeighborSet{
- NeighborSetName: conditionOpts.Neighbor,
+ NeighborSetName: op[2],
+ MatchSetOptions: op[1],
}
}
if conditionOpts.AsPath != "" {
+ op, err := checkFormat(conditionOpts.AsPath, false)
+ if err != nil {
+ return nil, fmt.Errorf("invalid aspath option format\n%s", err)
+ }
conditions.MatchAsPathSet = &api.AsPathSet{
- AsPathSetName: conditionOpts.AsPath,
+ AsPathSetName: op[2],
+ MatchSetOptions: op[1],
}
}
if conditionOpts.Community != "" {
+ op, err := checkFormat(conditionOpts.Community, false)
+ if err != nil {
+ return nil, fmt.Errorf("invalid community option format\n%s", err)
+ }
conditions.MatchCommunitySet = &api.CommunitySet{
- CommunitySetName: conditionOpts.Community,
+ CommunitySetName: op[2],
+ MatchSetOptions: op[1],
}
}
if conditionOpts.ExtCommunity != "" {
+ op, err := checkFormat(conditionOpts.ExtCommunity, false)
+ if err != nil {
+ return nil, fmt.Errorf("invalid extended community option format\n%s", err)
+ }
conditions.MatchExtCommunitySet = &api.ExtCommunitySet{
- ExtCommunitySetName: conditionOpts.ExtCommunity,
+ ExtCommunitySetName: op[2],
+ MatchSetOptions: op[1],
}
}
if conditionOpts.AsPathLength != "" {
@@ -1148,18 +1210,6 @@ func parseConditions() (*api.Conditions, error) {
Operator: operator,
}
}
- if conditionOpts.Option != "" {
- optionUpper := strings.ToUpper(conditionOpts.Option)
- var option string
- switch optionUpper {
- case policy.OPTIONS_ANY, policy.OPTIONS_ALL, policy.OPTIONS_INVERT:
- option = optionUpper
- default:
- return nil, fmt.Errorf("invalid condition option: %s\nPlease enter the any or all or invert",
- conditionOpts.Option)
- }
- conditions.MatchSetOptions = option
- }
return conditions, nil
}
@@ -1379,7 +1429,6 @@ func NewPolicyAddCmd(v string, mod func(string, []string) error) *cobra.Command
policyAddCmd.Flags().StringVarP(&conditionOpts.Community, "c-community", "", "", "a community set name of policy condition")
policyAddCmd.Flags().StringVarP(&conditionOpts.ExtCommunity, "c-extcommunity", "", "", "a extended community set name of policy condition")
policyAddCmd.Flags().StringVarP(&conditionOpts.AsPathLength, "c-aslen", "", "", "an as path length of policy condition (<operator>,<numeric>)")
- policyAddCmd.Flags().StringVarP(&conditionOpts.Option, "c-option", "", "", "an option of policy condition")
policyAddCmd.Flags().StringVarP(&actionOpts.RouteAction, "a-route", "", "", "a route action of policy action (accept | reject)")
policyAddCmd.Flags().StringVarP(&actionOpts.CommunityAction, "a-community", "", "", "a community of policy action")
policyAddCmd.Flags().StringVarP(&actionOpts.MedAction, "a-med", "", "", "a med of policy action")
diff --git a/gobgpd/main.go b/gobgpd/main.go
index 9d96401b..cf327f61 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -171,7 +171,7 @@ func main() {
if bgpConfig == nil {
bgpServer.SetGlobalType(newConfig.Bgp.Global)
bgpConfig = &newConfig.Bgp
- added = newConfig.Bgp.NeighborList
+ added = newConfig.Bgp.Neighbors.NeighborList
deleted = []config.Neighbor{}
} else {
bgpConfig, added, deleted = config.UpdateConfig(bgpConfig, &newConfig.Bgp)
@@ -188,11 +188,11 @@ func main() {
}
for _, p := range added {
- log.Infof("Peer %v is added", p.NeighborAddress)
+ log.Infof("Peer %v is added", p.NeighborConfig.NeighborAddress)
bgpServer.PeerAdd(p)
}
for _, p := range deleted {
- log.Infof("Peer %v is deleted", p.NeighborAddress)
+ log.Infof("Peer %v is deleted", p.NeighborConfig.NeighborAddress)
bgpServer.PeerDelete(p)
}
case sig := <-sigCh:
diff --git a/policy/policy.go b/policy/policy.go
index 0a8af9b8..b0eb3809 100644
--- a/policy/policy.go
+++ b/policy/policy.go
@@ -62,7 +62,7 @@ type Policy struct {
}
func NewPolicy(pd config.PolicyDefinition, ds config.DefinedSets) *Policy {
- stmtList := pd.StatementList
+ stmtList := pd.Statements.StatementList
st := make([]*Statement, 0)
p := &Policy{
Name: pd.Name,
@@ -73,14 +73,16 @@ func NewPolicy(pd config.PolicyDefinition, ds config.DefinedSets) *Policy {
conditions := make([]Condition, 0)
// prefix match
- prefixSetName := statement.Conditions.MatchPrefixSet
- pc := NewPrefixCondition(prefixSetName, ds.PrefixSetList)
- conditions = append(conditions, pc)
+ pc := NewPrefixCondition(statement.Conditions.MatchPrefixSet, ds.PrefixSets.PrefixSetList)
+ if pc != nil {
+ conditions = append(conditions, pc)
+ }
// neighbor match
- neighborSetName := statement.Conditions.MatchNeighborSet
- nc := NewNeighborCondition(neighborSetName, ds.NeighborSetList)
- conditions = append(conditions, nc)
+ nc := NewNeighborCondition(statement.Conditions.MatchNeighborSet, ds.NeighborSets.NeighborSetList)
+ if nc != nil {
+ conditions = append(conditions, nc)
+ }
// AsPathLengthCondition
c := statement.Conditions.BgpConditions.AsPathLength
@@ -89,23 +91,22 @@ func NewPolicy(pd config.PolicyDefinition, ds config.DefinedSets) *Policy {
conditions = append(conditions, ac)
}
+ bgpDefset := &ds.BgpDefinedSets
+ bgpConditions := &statement.Conditions.BgpConditions
// AsPathCondition
- asPathSetName := statement.Conditions.BgpConditions.MatchAsPathSet
- asc := NewAsPathCondition(asPathSetName, ds.BgpDefinedSets.AsPathSetList)
+ asc := NewAsPathCondition(bgpConditions.MatchAsPathSet, bgpDefset.AsPathSets.AsPathSetList)
if asc != nil {
conditions = append(conditions, asc)
}
// CommunityCondition
- communitySetName := statement.Conditions.BgpConditions.MatchCommunitySet
- cc := NewCommunityCondition(communitySetName, ds.BgpDefinedSets.CommunitySetList)
+ cc := NewCommunityCondition(bgpConditions.MatchCommunitySet, bgpDefset.CommunitySets.CommunitySetList)
if cc != nil {
conditions = append(conditions, cc)
}
// ExtendedCommunityCondition
- extCommunitySetName := statement.Conditions.BgpConditions.MatchExtCommunitySet
- ecc := NewExtCommunityCondition(extCommunitySetName, ds.BgpDefinedSets.ExtCommunitySetList)
+ ecc := NewExtCommunityCondition(bgpConditions.MatchExtCommunitySet, bgpDefset.ExtCommunitySets.ExtCommunitySetList)
if ecc != nil {
conditions = append(conditions, ecc)
}
@@ -137,7 +138,6 @@ func NewPolicy(pd config.PolicyDefinition, ds config.DefinedSets) *Policy {
Conditions: conditions,
routingAction: ra,
modificationActions: mda,
- MatchSetOptions: statement.Conditions.MatchSetOptions,
}
st = append(st, s)
@@ -151,52 +151,18 @@ type Statement struct {
Conditions []Condition
routingAction *RoutingAction
modificationActions []Action
- MatchSetOptions config.MatchSetOptionsType
}
// evaluate each condition in the statement according to MatchSetOptions
func (s *Statement) evaluate(p *table.Path) bool {
- optionType := s.MatchSetOptions
-
- result := false
- if optionType == config.MATCH_SET_OPTIONS_TYPE_ALL {
- result = true
- }
-
for _, condition := range s.Conditions {
-
r := condition.evaluate(p)
-
- switch optionType {
- case config.MATCH_SET_OPTIONS_TYPE_ALL:
- result = result && r
- if !result {
- return false
- }
-
- case config.MATCH_SET_OPTIONS_TYPE_ANY:
- result = result || r
- if result {
- return true
- }
-
- case config.MATCH_SET_OPTIONS_TYPE_INVERT:
- result = result || r
- if result {
- return false
- }
-
- default:
+ if !r {
return false
}
}
-
- if optionType == config.MATCH_SET_OPTIONS_TYPE_INVERT {
- return !result
- } else {
- return result
- }
+ return true
}
type Condition interface {
@@ -215,15 +181,21 @@ type PrefixCondition struct {
DefaultCondition
PrefixConditionName string
PrefixList []Prefix
+ MatchOption config.MatchSetOptionsRestrictedType
}
-func NewPrefixCondition(prefixSetName string, defPrefixList []config.PrefixSet) *PrefixCondition {
+func NewPrefixCondition(matchPref config.MatchPrefixSet, defPrefixList []config.PrefixSet) *PrefixCondition {
+
+ prefixSetName := matchPref.PrefixSet
+ options := matchPref.MatchSetOptions
prefixList := make([]Prefix, 0)
for _, ps := range defPrefixList {
if ps.PrefixSetName == prefixSetName {
- for _, pl := range ps.PrefixList {
- prefix, e := NewPrefix(pl.Address, pl.Masklength, pl.MasklengthRange)
+ for _, prefix := range ps.PrefixList {
+ addr := prefix.IpPrefix.IP
+ maskLength, _ := prefix.IpPrefix.Mask.Size()
+ prefix, e := NewPrefix(addr, uint8(maskLength), prefix.MasklengthRange)
if e != nil {
log.WithFields(log.Fields{
"Topic": "Policy",
@@ -237,13 +209,17 @@ func NewPrefixCondition(prefixSetName string, defPrefixList []config.PrefixSet)
}
}
+ if len(prefixList) == 0 {
+ return nil
+ }
+
pc := &PrefixCondition{
PrefixConditionName: prefixSetName,
PrefixList: prefixList,
+ MatchOption: options,
}
return pc
-
}
// compare prefixes in this condition and nlri of path and
@@ -256,26 +232,38 @@ func (c *PrefixCondition) evaluate(path *table.Path) bool {
return true
}
+ result := false
for _, cp := range c.PrefixList {
if ipPrefixCalculate(path, cp) {
- log.WithFields(log.Fields{
- "Topic": "Policy",
- "Prefix": cp.Address.String(),
- }).Debug("prefix matched")
-
- return true
+ result = true
+ break
}
}
- return false
+ if c.MatchOption == config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT {
+ result = !result
+ }
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "prefix",
+ "Path": path,
+ "Matched": result,
+ }).Debug("evaluate prefix")
+
+ return result
}
type NeighborCondition struct {
DefaultCondition
NeighborConditionName string
NeighborList []net.IP
+ MatchOption config.MatchSetOptionsRestrictedType
}
-func NewNeighborCondition(neighborSetName string, defNeighborSetList []config.NeighborSet) *NeighborCondition {
+func NewNeighborCondition(matchNeighborSet config.MatchNeighborSet, defNeighborSetList []config.NeighborSet) *NeighborCondition {
+
+ neighborSetName := matchNeighborSet.NeighborSet
+ options := matchNeighborSet.MatchSetOptions
neighborList := make([]net.IP, 0)
for _, neighborSet := range defNeighborSetList {
@@ -286,9 +274,14 @@ func NewNeighborCondition(neighborSetName string, defNeighborSetList []config.Ne
}
}
+ if len(neighborList) == 0 {
+ return nil
+ }
+
nc := &NeighborCondition{
NeighborConditionName: neighborSetName,
NeighborList: neighborList,
+ MatchOption: options,
}
return nc
@@ -304,18 +297,27 @@ func (c *NeighborCondition) evaluate(path *table.Path) bool {
return true
}
+ sAddr := path.GetSource().Address
+ result := false
for _, neighbor := range c.NeighborList {
- cAddr := neighbor
- pAddr := path.GetSource().Address
- if pAddr.Equal(cAddr) {
- log.WithFields(log.Fields{
- "Topic": "Policy",
- "NeighborAddress": pAddr.String(),
- }).Debug("neighbor matched")
- return true
+ if sAddr.Equal(neighbor) {
+ result = true
+ break
}
}
- return false
+
+ if c.MatchOption == config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT {
+ result = !result
+ }
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "neighbor",
+ "NeighborAddress": sAddr.String(),
+ "Matched": result,
+ }).Debug("evaluate neighbor")
+
+ return result
}
type AsPathLengthCondition struct {
@@ -368,23 +370,23 @@ func (c *AsPathLengthCondition) evaluate(path *table.Path) bool {
case ATTRIBUTE_LE:
result = c.Value >= length
default:
- return false
+ result = false
}
- if result {
- log.WithFields(log.Fields{
- "Topic": "Policy",
- "Condition": "aspath length",
- "Reason": c.Operator,
- }).Debug("condition matched")
- }
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "aspath length",
+ "Reason": c.Operator,
+ "Matched": result,
+ }).Debug("evaluate aspath length")
return result
}
type AsPathCondition struct {
DefaultCondition
- AsPathList []*AsPathElement
+ AsPathList []*AsPathElement
+ MatchOption config.MatchSetOptionsType
}
type AsnPos int
@@ -407,14 +409,16 @@ type AsPathElement struct {
// - ^100$ (from as100 and originated by as100)
// - 100$ (originated by as100)
// - 100 (from or through or originated by as100)
-func NewAsPathCondition(asPathSetName string, defAsPathSetList []config.AsPathSet) *AsPathCondition {
+func NewAsPathCondition(matchSet config.MatchAsPathSet, defAsPathSetList []config.AsPathSet) *AsPathCondition {
- regAsn, _ := regexp.Compile("^(\\^?)([0-9]+)(\\$?)$")
+ asPathSetName := matchSet.AsPathSet
+ options := matchSet.MatchSetOptions
+ regAsn, _ := regexp.Compile("^(\\^?)([0-9]+)(\\$?)$")
asPathList := make([]*AsPathElement, 0)
for _, asPathSet := range defAsPathSetList {
if asPathSet.AsPathSetName == asPathSetName {
- for _, as := range asPathSet.AsPathSetMembers {
+ for _, as := range asPathSet.AsPathSetMember {
if regAsn.MatchString(as) {
group := regAsn.FindStringSubmatch(as)
@@ -452,7 +456,8 @@ func NewAsPathCondition(asPathSetName string, defAsPathSetList []config.AsPathSe
}
c := &AsPathCondition{
- AsPathList: asPathList,
+ AsPathList: asPathList,
+ MatchOption: options,
}
return c
}
@@ -460,19 +465,14 @@ func NewAsPathCondition(asPathSetName string, defAsPathSetList []config.AsPathSe
return nil
}
-// compare AS_PATH in the message's AS_PATH attribute with
-// the one in condition.
-func (c *AsPathCondition) evaluate(path *table.Path) bool {
-
- aspath := path.GetAsSeqList()
-
- if len(aspath) == 0 {
- return false
+func (c *AsPathCondition) checkMembers(aspath []uint32, checkAll bool) bool {
+ result := false
+ if checkAll {
+ result = true
}
- matched := false
for _, member := range c.AsPathList {
-
+ matched := false
switch member.postiion {
case AS_FROM:
matched = aspath[0] == member.asn
@@ -497,17 +497,57 @@ func (c *AsPathCondition) evaluate(path *table.Path) bool {
"Condition": "aspath length",
"ASN": member.asn,
"Position": member.postiion,
- }).Debug("condition matched")
- return true
+ }).Debug("aspath condition matched")
+
+ if !checkAll {
+ result = true
+ break
+ }
+
+ } else {
+ if checkAll {
+ result = false
+ break
+ }
}
+ }
+
+ return result
+}
+
+// compare AS_PATH in the message's AS_PATH attribute with
+// the one in condition.
+func (c *AsPathCondition) evaluate(path *table.Path) bool {
+
+ aspath := path.GetAsSeqList()
+
+ if len(aspath) == 0 {
+ return false
+ }
+ result := false
+ if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_ALL {
+ result = c.checkMembers(aspath, true)
+ } else if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_ANY {
+ result = c.checkMembers(aspath, false)
+ } else if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_INVERT {
+ result = !c.checkMembers(aspath, false)
}
- return false
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "aspath",
+ "MatchOption": c.MatchOption,
+ "Matched": result,
+ }).Debug("evaluate aspath")
+
+ return result
}
type CommunityCondition struct {
DefaultCondition
CommunityList []*CommunityElement
+ MatchOption config.MatchSetOptionsType
}
const (
@@ -535,12 +575,15 @@ type CommunityElement struct {
// CommunityCondition supports uint and string like 65000:100
// and also supports regular expressions that are available in golang.
// if GoBGP can't parse the regular expression, it return nil and an error message is logged.
-func NewCommunityCondition(communitySetName string, defCommunitySetList []config.CommunitySet) *CommunityCondition {
+func NewCommunityCondition(matchSet config.MatchCommunitySet, defCommunitySetList []config.CommunitySet) *CommunityCondition {
+
+ communitySetName := matchSet.CommunitySet
+ options := matchSet.MatchSetOptions
communityList := make([]*CommunityElement, 0)
for _, communitySet := range defCommunitySetList {
if communitySet.CommunitySetName == communitySetName {
- for _, c := range communitySet.CommunityMembers {
+ for _, c := range communitySet.CommunityMember {
e := &CommunityElement{
isRegExp: false,
@@ -567,6 +610,7 @@ func NewCommunityCondition(communitySetName string, defCommunitySetList []config
c := &CommunityCondition{
CommunityList: communityList,
+ MatchOption: options,
}
return c
}
@@ -631,14 +675,11 @@ func getCommunityValue(comStr string) (bool, uint32) {
return false, 0
}
-// compare community in the message's attribute with
-// the one in the condition.
-func (c *CommunityCondition) evaluate(path *table.Path) bool {
+func (c *CommunityCondition) checkMembers(communities []uint32, checkAll bool) bool {
- communities := path.GetCommunities()
-
- if len(communities) == 0 {
- return false
+ result := false
+ if checkAll {
+ result = true
}
makeStr := func(c uint32) string {
@@ -690,15 +731,62 @@ func (c *CommunityCondition) evaluate(path *table.Path) bool {
"Community": makeStr(communities[idx]),
}).Debug("condition matched")
- return true
+ if !checkAll {
+ result = true
+ break
+ }
+
+ } else {
+ if checkAll {
+ result = false
+ break
+ }
}
}
- return false
+
+ return result
+
+}
+
+// compare community in the message's attribute with
+// the one in the condition.
+func (c *CommunityCondition) evaluate(path *table.Path) bool {
+
+ communities := path.GetCommunities()
+
+ if len(communities) == 0 {
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "community",
+ "MatchOption": c.MatchOption,
+ "Matched": false,
+ }).Debug("community length is zero")
+ return false
+ }
+
+ result := false
+ if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_ALL {
+ result = c.checkMembers(communities, true)
+ } else if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_ANY {
+ result = c.checkMembers(communities, false)
+ } else if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_INVERT {
+ result = !c.checkMembers(communities, false)
+ }
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "community",
+ "MatchOption": c.MatchOption,
+ "Matched": result,
+ }).Debug("evaluate community")
+
+ return result
}
type ExtCommunityCondition struct {
DefaultCondition
ExtCommunityList []*ExtCommunityElement
+ MatchOption config.MatchSetOptionsType
}
type ExtCommunityElement struct {
@@ -711,15 +799,19 @@ type ExtCommunityElement struct {
regExp *regexp.Regexp
}
-func NewExtCommunityCondition(extComSetName string, defExtComSetList []config.ExtCommunitySet) *ExtCommunityCondition {
+func NewExtCommunityCondition(matchSet config.MatchExtCommunitySet, defExtComSetList []config.ExtCommunitySet) *ExtCommunityCondition {
+
+ extComSetName := matchSet.ExtCommunitySet
+ option := matchSet.MatchSetOptions
+
extCommunityElemList := make([]*ExtCommunityElement, 0)
for _, extComSet := range defExtComSetList {
if extComSet.ExtCommunitySetName == extComSetName {
- for _, c := range extComSet.ExtCommunityMembers {
+ for _, c := range extComSet.ExtCommunityMember {
matchAll := false
e := &ExtCommunityElement{
isRegExp: false,
- comStr: c,
+ comStr: c,
}
matchType, val := getECommunitySubType(c)
if !matchType {
@@ -770,6 +862,7 @@ func NewExtCommunityCondition(extComSetName string, defExtComSetList []config.Ex
}
ce := &ExtCommunityCondition{
ExtCommunityList: extCommunityElemList,
+ MatchOption: option,
}
return ce
}
@@ -827,9 +920,13 @@ func getECommunityElem(gAdmin string) (bool, bgp.ExtendedCommunityAttrType, inte
return false, bgp.ExtendedCommunityAttrType(0xFF), nil
}
-// compare extended community in the message's attribute with
-// the one in the condition.
-func (c *ExtCommunityCondition) evaluate(path *table.Path) bool {
+func (c *ExtCommunityCondition) checkMembers(eCommunities []interface{}, checkAll bool) bool {
+
+ result := false
+ if checkAll {
+ result = true
+ }
+
makeAs4Str := func(ec *ExtCommunityElement) string {
t := ec.ecType
str := fmt.Sprintf("%d", ec.localAdmin)
@@ -857,10 +954,6 @@ func (c *ExtCommunityCondition) evaluate(path *table.Path) bool {
}
return subStr
}
- eCommunities := path.GetExtCommunities()
- if len(eCommunities) == 0 || c == nil {
- return false
- }
matched := false
matchStr := ""
@@ -890,15 +983,59 @@ func (c *ExtCommunityCondition) evaluate(path *table.Path) bool {
}
if matched {
log.WithFields(log.Fields{
- "Topic": "Policy",
- "Condition": "Extended Community",
+ "Topic": "Policy",
+ "Condition": "Extended Community",
"Extended Community": matchStr,
}).Debug("condition matched")
- return true
+ if !checkAll {
+ result = true
+ break
+ }
+
+ } else {
+ if checkAll {
+ result = false
+ break
+ }
}
}
- return false
+ return result
+}
+
+// compare extended community in the message's attribute with
+// the one in the condition.
+func (c *ExtCommunityCondition) evaluate(path *table.Path) bool {
+
+ eCommunities := path.GetExtCommunities()
+ if len(eCommunities) == 0 {
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "extended community",
+ "Matched": false,
+ "Path": path,
+ }).Debug("extended community length is zero")
+ return false
+ }
+
+ result := false
+ if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_ALL {
+ result = c.checkMembers(eCommunities, true)
+ } else if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_ANY {
+ result = c.checkMembers(eCommunities, false)
+ } else if c.MatchOption == config.MATCH_SET_OPTIONS_TYPE_INVERT {
+ result = !c.checkMembers(eCommunities, false)
+ }
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Condition": "extended community",
+ "MatchOption": c.MatchOption,
+ "Matched": result,
+ "Path": path,
+ }).Debug("evaluate extended community")
+
+ return result
}
type Action interface {
@@ -919,7 +1056,7 @@ type RoutingAction struct {
func NewRoutingAction(action config.Actions) *RoutingAction {
r := &RoutingAction{
- AcceptRoute: action.AcceptRoute,
+ AcceptRoute: action.RouteDisposition.AcceptRoute,
}
return r
}
@@ -932,12 +1069,10 @@ func (r *RoutingAction) apply(path *table.Path) *table.Path {
}
}
-type ActionType int
-
type CommunityAction struct {
DefaultAction
Values []uint32
- action ActionType
+ action config.BgpSetCommunityOptionType
}
const (
@@ -953,13 +1088,13 @@ const (
func NewCommunityAction(action config.SetCommunity) *CommunityAction {
m := &CommunityAction{}
-
- if len(action.Communities) == 0 && action.Options != COMMUNITY_ACTION_NULL {
+ communities := action.SetCommunityMethod.Communities
+ if len(communities) == 0 && action.Options != COMMUNITY_ACTION_REPLACE {
return nil
}
- values := make([]uint32, len(action.Communities))
- for i, com := range action.Communities {
+ values := make([]uint32, len(communities))
+ for i, com := range communities {
matched, value := getCommunityValue(com)
if matched {
values[i] = value
@@ -980,8 +1115,6 @@ func NewCommunityAction(action config.SetCommunity) *CommunityAction {
m.action = config.BGP_SET_COMMUNITY_OPTION_TYPE_REMOVE
case COMMUNITY_ACTION_REPLACE:
m.action = config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE
- case COMMUNITY_ACTION_NULL:
- m.action = config.BGP_SET_COMMUNITY_OPTION_TYPE_NULL
default:
log.WithFields(log.Fields{
"Topic": "Policy",
@@ -1002,12 +1135,20 @@ func (a *CommunityAction) apply(path *table.Path) *table.Path {
path.RemoveCommunities(list)
case config.BGP_SET_COMMUNITY_OPTION_TYPE_REPLACE:
path.SetCommunities(list, true)
- case config.BGP_SET_COMMUNITY_OPTION_TYPE_NULL:
- path.ClearCommunities()
}
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Action": "community",
+ "Values": list,
+ "Method": a.action,
+ }).Debug("community action applied")
+
return path
}
+type ActionType int
+
type MedAction struct {
DefaultAction
Value int64
@@ -1084,6 +1225,13 @@ func (a *MedAction) apply(path *table.Path) *table.Path {
"Topic": "Policy",
"Type": "Med Action",
}).Warn(err)
+ } else {
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Action": "med",
+ "Value": a.Value,
+ "ActionType": a.action,
+ }).Debug("med action applied")
}
return path
@@ -1149,6 +1297,14 @@ func (a *AsPathPrependAction) apply(path *table.Path) *table.Path {
}
path.PrependAsn(asn, a.repeat)
+
+ log.WithFields(log.Fields{
+ "Topic": "Policy",
+ "Action": "aspath prepend",
+ "ASN": asn,
+ "Repeat": a.repeat,
+ }).Debug("aspath prepend action applied")
+
return path
}
@@ -1216,7 +1372,7 @@ func (p *Policy) Apply(path *table.Path) (bool, RouteType, *table.Path) {
"Topic": "Policy",
"Path": path,
"PolicyName": p.Name,
- }).Debug("statement.Conditions.evaluate : ", result)
+ }).Debug("statement evaluate : ", result)
var p *table.Path
if result {
@@ -1290,24 +1446,49 @@ const (
)
const (
- OPTIONS_ALL string = "ALL"
- OPTIONS_ANY = "ANY"
+ OPTIONS_ANY string = "ANY"
+ OPTIONS_ALL = "ALL"
OPTIONS_INVERT = "INVERT"
)
func MatchSetOptionToString(option config.MatchSetOptionsType) string {
- var op string
+ op := OPTIONS_ANY
switch option {
case config.MATCH_SET_OPTIONS_TYPE_ALL:
op = OPTIONS_ALL
- case config.MATCH_SET_OPTIONS_TYPE_ANY:
- op = OPTIONS_ANY
case config.MATCH_SET_OPTIONS_TYPE_INVERT:
op = OPTIONS_INVERT
}
return op
}
+func MatchSetOptionsRestrictedToString(option config.MatchSetOptionsRestrictedType) string {
+ op := OPTIONS_ANY
+ if option == config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT {
+ op = OPTIONS_INVERT
+ }
+ return op
+}
+
+func MatchSetOptionsToType(option string) config.MatchSetOptionsType {
+ op := config.MATCH_SET_OPTIONS_TYPE_ANY
+ switch option {
+ case OPTIONS_ALL:
+ op = config.MATCH_SET_OPTIONS_TYPE_ALL
+ case OPTIONS_INVERT:
+ op = config.MATCH_SET_OPTIONS_TYPE_INVERT
+ }
+ return op
+}
+
+func MatchSetOptionsRestrictedToType(option string) config.MatchSetOptionsRestrictedType {
+ op := config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY
+ if option == OPTIONS_INVERT {
+ op = config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_INVERT
+ }
+ return op
+}
+
// find index PrefixSet of request from PrefixSet of configuration file.
// Return the idxPrefixSet of the location where the name of PrefixSet matches,
// and idxPrefix of the location where element of PrefixSet matches
@@ -1321,7 +1502,7 @@ func IndexOfPrefixSet(conPrefixSetList []config.PrefixSet, reqPrefixSet config.P
return idxPrefixSet, idxPrefix
}
for j, conPrefix := range conPrefixSet.PrefixList {
- if reflect.DeepEqual(conPrefix.Address, reqPrefixSet.PrefixList[0].Address) && conPrefix.Masklength == reqPrefixSet.PrefixList[0].Masklength &&
+ if reflect.DeepEqual(conPrefix.IpPrefix, reqPrefixSet.PrefixList[0].IpPrefix) &&
conPrefix.MasklengthRange == reqPrefixSet.PrefixList[0].MasklengthRange {
idxPrefix = j
return idxPrefixSet, idxPrefix
@@ -1364,11 +1545,11 @@ func IndexOfAsPathSet(conAsPathSetList []config.AsPathSet, reqAsPathSet config.A
for i, conAsPathSet := range conAsPathSetList {
if conAsPathSet.AsPathSetName == reqAsPathSet.AsPathSetName {
idxAsPathSet = i
- if len(reqAsPathSet.AsPathSetMembers) == 0 {
+ if len(reqAsPathSet.AsPathSetMember) == 0 {
return idxAsPathSet, idxAsPath
}
- for j, conAsPath := range conAsPathSet.AsPathSetMembers {
- if conAsPath == reqAsPathSet.AsPathSetMembers[0] {
+ for j, conAsPath := range conAsPathSet.AsPathSetMember {
+ if conAsPath == reqAsPathSet.AsPathSetMember[0] {
idxAsPath = j
return idxAsPathSet, idxAsPath
}
@@ -1387,11 +1568,11 @@ func IndexOfCommunitySet(conCommunitySetList []config.CommunitySet, reqCommunity
for i, conCommunitySet := range conCommunitySetList {
if conCommunitySet.CommunitySetName == reqCommunitySet.CommunitySetName {
idxCommunitySet = i
- if len(reqCommunitySet.CommunityMembers) == 0 {
+ if len(reqCommunitySet.CommunityMember) == 0 {
return idxCommunitySet, idxCommunity
}
- for j, conCommunity := range conCommunitySet.CommunityMembers {
- if conCommunity == reqCommunitySet.CommunityMembers[0] {
+ for j, conCommunity := range conCommunitySet.CommunityMember {
+ if conCommunity == reqCommunitySet.CommunityMember[0] {
idxCommunity = j
return idxCommunitySet, idxCommunity
}
@@ -1410,11 +1591,11 @@ func IndexOfExtCommunitySet(conExtCommunitySetList []config.ExtCommunitySet, req
for i, conExtCommunitySet := range conExtCommunitySetList {
if conExtCommunitySet.ExtCommunitySetName == reqExtCommunitySet.ExtCommunitySetName {
idxExtCommunitySet = i
- if len(reqExtCommunitySet.ExtCommunityMembers) == 0 {
+ if len(reqExtCommunitySet.ExtCommunityMember) == 0 {
return idxExtCommunitySet, idxExtCommunity
}
- for j, conExtCommunity := range conExtCommunitySet.ExtCommunityMembers {
- if conExtCommunity == reqExtCommunitySet.ExtCommunityMembers[0] {
+ for j, conExtCommunity := range conExtCommunitySet.ExtCommunityMember {
+ if conExtCommunity == reqExtCommunitySet.ExtCommunityMember[0] {
idxExtCommunity = j
return idxExtCommunitySet, idxExtCommunity
}
@@ -1433,11 +1614,11 @@ func IndexOfPolicyDefinition(conPolicyList []config.PolicyDefinition, reqPolicy
for i, conPolicy := range conPolicyList {
if conPolicy.Name == reqPolicy.Name {
idxPolicyDefinition = i
- if reqPolicy.StatementList == nil {
+ if reqPolicy.Statements.StatementList == nil {
return idxPolicyDefinition, idxStatement
}
- for j, conStatement := range conPolicy.StatementList {
- if conStatement.Name == reqPolicy.StatementList[0].Name {
+ for j, conStatement := range conPolicy.Statements.StatementList {
+ if conStatement.Name == reqPolicy.Statements.StatementList[0].Name {
idxStatement = j
return idxPolicyDefinition, idxStatement
}
@@ -1450,9 +1631,13 @@ func IndexOfPolicyDefinition(conPolicyList []config.PolicyDefinition, reqPolicy
func PrefixSetToApiStruct(ps config.PrefixSet) *api.PrefixSet {
resPrefixList := make([]*api.Prefix, 0)
for _, p := range ps.PrefixList {
+
+ addr := p.IpPrefix.IP
+ length, _ := p.IpPrefix.Mask.Size()
+
resPrefix := &api.Prefix{
- Address: p.Address.String(),
- MaskLength: uint32(p.Masklength),
+ Address: addr.String(),
+ MaskLength: uint32(length),
MaskLengthRange: p.MasklengthRange,
}
resPrefixList = append(resPrefixList, resPrefix)
@@ -1461,6 +1646,7 @@ func PrefixSetToApiStruct(ps config.PrefixSet) *api.PrefixSet {
PrefixSetName: ps.PrefixSetName,
PrefixList: resPrefixList,
}
+
return resPrefixSet
}
@@ -1469,9 +1655,13 @@ func PrefixSetToConfigStruct(reqPrefixSet *api.PrefixSet) (bool, config.PrefixSe
var prefixSet config.PrefixSet
isReqPrefixSet := true
if reqPrefixSet.PrefixList != nil {
+
+ prefItem := reqPrefixSet.PrefixList[0]
+ prefStr := prefItem.Address + "/" + strconv.Itoa(int(prefItem.MaskLength))
+ _, ipprefix, _ := net.ParseCIDR(prefStr)
+
prefix = config.Prefix{
- Address: net.ParseIP(reqPrefixSet.PrefixList[0].Address),
- Masklength: uint8(reqPrefixSet.PrefixList[0].MaskLength),
+ IpPrefix: *ipprefix,
MasklengthRange: reqPrefixSet.PrefixList[0].MaskLengthRange,
}
prefixList := []config.Prefix{prefix}
@@ -1531,7 +1721,7 @@ func NeighborSetToConfigStruct(reqNeighborSet *api.NeighborSet) (bool, config.Ne
func AsPathSetToApiStruct(as config.AsPathSet) *api.AsPathSet {
resAsPathMembers := make([]string, 0)
- for _, m := range as.AsPathSetMembers {
+ for _, m := range as.AsPathSetMember {
resAsPathMembers = append(resAsPathMembers, m)
}
resAsPathSet := &api.AsPathSet{
@@ -1547,15 +1737,15 @@ func AsPathSetToConfigStruct(reqAsPathSet *api.AsPathSet) (bool, config.AsPathSe
isAsPathSetSet = false
}
asPathSet := config.AsPathSet{
- AsPathSetName: reqAsPathSet.AsPathSetName,
- AsPathSetMembers: reqAsPathSet.AsPathMembers,
+ AsPathSetName: reqAsPathSet.AsPathSetName,
+ AsPathSetMember: reqAsPathSet.AsPathMembers,
}
return isAsPathSetSet, asPathSet
}
func CommunitySetToApiStruct(cs config.CommunitySet) *api.CommunitySet {
resCommunityMembers := make([]string, 0)
- for _, m := range cs.CommunityMembers {
+ for _, m := range cs.CommunityMember {
resCommunityMembers = append(resCommunityMembers, m)
}
resCommunitySet := &api.CommunitySet{
@@ -1572,14 +1762,14 @@ func CommunitySetToConfigStruct(reqCommunitySet *api.CommunitySet) (bool, config
}
communitySet := config.CommunitySet{
CommunitySetName: reqCommunitySet.CommunitySetName,
- CommunityMembers: reqCommunitySet.CommunityMembers,
+ CommunityMember: reqCommunitySet.CommunityMembers,
}
return isCommunitySet, communitySet
}
func ExtCommunitySetToApiStruct(es config.ExtCommunitySet) *api.ExtCommunitySet {
resExtCommunityMembers := make([]string, 0)
- for _, m := range es.ExtCommunityMembers {
+ for _, m := range es.ExtCommunityMember {
resExtCommunityMembers = append(resExtCommunityMembers, m)
}
resExtCommunitySet := &api.ExtCommunitySet{
@@ -1596,7 +1786,7 @@ func ExtCommunitySetToConfigStruct(reqExtCommunitySet *api.ExtCommunitySet) (boo
}
ExtCommunitySet := config.ExtCommunitySet{
ExtCommunitySetName: reqExtCommunitySet.ExtCommunitySetName,
- ExtCommunityMembers: reqExtCommunitySet.ExtCommunityMembers,
+ ExtCommunityMember: reqExtCommunitySet.ExtCommunityMembers,
}
return isExtCommunitySet, ExtCommunitySet
}
@@ -1630,44 +1820,46 @@ func ConditionsToConfigStruct(reqConditions *api.Conditions) config.Conditions {
return conditions
}
if reqConditions.MatchPrefixSet != nil {
- conditions.MatchPrefixSet = reqConditions.MatchPrefixSet.PrefixSetName
+ conditions.MatchPrefixSet.PrefixSet = reqConditions.MatchPrefixSet.PrefixSetName
+ conditions.MatchPrefixSet.MatchSetOptions =
+ MatchSetOptionsRestrictedToType(reqConditions.MatchPrefixSet.MatchSetOptions)
}
if reqConditions.MatchNeighborSet != nil {
- conditions.MatchNeighborSet = reqConditions.MatchNeighborSet.NeighborSetName
+ conditions.MatchNeighborSet.NeighborSet = reqConditions.MatchNeighborSet.NeighborSetName
+ conditions.MatchNeighborSet.MatchSetOptions =
+ MatchSetOptionsRestrictedToType(reqConditions.MatchNeighborSet.MatchSetOptions)
}
if reqConditions.MatchAsPathSet != nil {
- conditions.BgpConditions.MatchAsPathSet = reqConditions.MatchAsPathSet.AsPathSetName
+ conditions.BgpConditions.MatchAsPathSet.AsPathSet = reqConditions.MatchAsPathSet.AsPathSetName
+ conditions.BgpConditions.MatchAsPathSet.MatchSetOptions =
+ MatchSetOptionsToType(reqConditions.MatchAsPathSet.MatchSetOptions)
}
if reqConditions.MatchCommunitySet != nil {
- conditions.BgpConditions.MatchCommunitySet = reqConditions.MatchCommunitySet.CommunitySetName
+ conditions.BgpConditions.MatchCommunitySet.CommunitySet = reqConditions.MatchCommunitySet.CommunitySetName
+ conditions.BgpConditions.MatchCommunitySet.MatchSetOptions =
+ MatchSetOptionsToType(reqConditions.MatchCommunitySet.MatchSetOptions)
}
if reqConditions.MatchExtCommunitySet != nil {
- conditions.BgpConditions.MatchExtCommunitySet = reqConditions.MatchExtCommunitySet.ExtCommunitySetName
+ conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = reqConditions.MatchExtCommunitySet.ExtCommunitySetName
+ conditions.BgpConditions.MatchExtCommunitySet.MatchSetOptions =
+ MatchSetOptionsToType(reqConditions.MatchExtCommunitySet.MatchSetOptions)
}
if reqConditions.MatchAsPathLength != nil {
conditions.BgpConditions.AsPathLength =
AsPathLengthToConfigStruct(reqConditions.MatchAsPathLength)
}
- var setOption config.MatchSetOptionsType
- switch reqConditions.MatchSetOptions {
- case OPTIONS_ALL:
- setOption = config.MATCH_SET_OPTIONS_TYPE_ALL
- case OPTIONS_ANY:
- setOption = config.MATCH_SET_OPTIONS_TYPE_ANY
- case OPTIONS_INVERT:
- setOption = config.MATCH_SET_OPTIONS_TYPE_INVERT
- }
- conditions.MatchSetOptions = setOption
return conditions
}
func ActionsToApiStruct(conActions config.Actions) *api.Actions {
action := ROUTE_REJECT
- if conActions.AcceptRoute {
+ if conActions.RouteDisposition.AcceptRoute {
action = ROUTE_ACCEPT
}
+
+ //TODO: support CommunitySetRef
communityAction := &api.CommunityAction{
- Communities: conActions.BgpActions.SetCommunity.Communities,
+ Communities: conActions.BgpActions.SetCommunity.SetCommunityMethod.Communities,
Options: conActions.BgpActions.SetCommunity.Options,
}
medAction := fmt.Sprintf("%s", conActions.BgpActions.SetMed)
@@ -1691,7 +1883,7 @@ func ActionsToConfigStruct(reqActions *api.Actions) config.Actions {
return actions
}
if reqActions.Community != nil {
- actions.BgpActions.SetCommunity.Communities = reqActions.Community.Communities
+ actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = reqActions.Community.Communities
actions.BgpActions.SetCommunity.Options = reqActions.Community.Options
}
if reqActions.Med != "" {
@@ -1704,9 +1896,9 @@ func ActionsToConfigStruct(reqActions *api.Actions) config.Actions {
switch reqActions.RouteAction {
case ROUTE_ACCEPT:
- actions.AcceptRoute = true
+ actions.RouteDisposition.AcceptRoute = true
case ROUTE_REJECT:
- actions.RejectRoute = true
+ actions.RouteDisposition.RejectRoute = true
}
return actions
}
@@ -1727,7 +1919,7 @@ func PolicyDefinitionToConfigStruct(reqPolicy *api.PolicyDefinition) (bool, conf
}
if reqPolicy.StatementList != nil {
statement := StatementToConfigStruct(reqPolicy.StatementList[0])
- policy.StatementList = []config.Statement{statement}
+ policy.Statements.StatementList = []config.Statement{statement}
} else {
isReqStatement = false
}
@@ -1735,67 +1927,65 @@ func PolicyDefinitionToConfigStruct(reqPolicy *api.PolicyDefinition) (bool, conf
}
func PolicyDefinitionToApiStruct(pd config.PolicyDefinition, df config.DefinedSets) *api.PolicyDefinition {
- conPrefixSetList := df.PrefixSetList
- conNeighborSetList := df.NeighborSetList
- conAsPathSetList := df.BgpDefinedSets.AsPathSetList
- conCommunitySetList := df.BgpDefinedSets.CommunitySetList
- conExtCommunitySetList := df.BgpDefinedSets.ExtCommunitySetList
+ conPrefixSetList := df.PrefixSets.PrefixSetList
+ conNeighborSetList := df.NeighborSets.NeighborSetList
+ conAsPathSetList := df.BgpDefinedSets.AsPathSets.AsPathSetList
+ conCommunitySetList := df.BgpDefinedSets.CommunitySets.CommunitySetList
+ conExtCommunitySetList := df.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList
resStatementList := make([]*api.Statement, 0)
- for _, st := range pd.StatementList {
- conditions := st.Conditions
- actions := st.Actions
+ for _, st := range pd.Statements.StatementList {
+ co := st.Conditions
+ bco := co.BgpConditions
+ ac := st.Actions
- prefixSet := &api.PrefixSet{
- PrefixSetName: conditions.MatchPrefixSet,
- }
- neighborSet := &api.NeighborSet{
- NeighborSetName: conditions.MatchNeighborSet,
- }
- asPathSet := &api.AsPathSet{
- AsPathSetName: conditions.BgpConditions.MatchAsPathSet,
- }
- communitySet := &api.CommunitySet{
- CommunitySetName: conditions.BgpConditions.MatchCommunitySet,
- }
- extCommunitySet := &api.ExtCommunitySet{
- ExtCommunitySetName: conditions.BgpConditions.MatchExtCommunitySet,
- }
- // consider later whether treatment of here need
- _, conPrefixSet := PrefixSetToConfigStruct(prefixSet)
- _, conNeighborSet := NeighborSetToConfigStruct(neighborSet)
- _, conAsPathSet := AsPathSetToConfigStruct(asPathSet)
- _, conCommunitySet := CommunitySetToConfigStruct(communitySet)
- _, conExtCommunitySet := ExtCommunitySetToConfigStruct(extCommunitySet)
+ prefixSet := &api.PrefixSet{PrefixSetName: co.MatchPrefixSet.PrefixSet}
+ conPrefixSet := config.PrefixSet{PrefixSetName: co.MatchPrefixSet.PrefixSet}
idxPrefixSet, _ := IndexOfPrefixSet(conPrefixSetList, conPrefixSet)
- idxNeighborSet, _ := IndexOfNeighborSet(conNeighborSetList, conNeighborSet)
- idxAsPathSet, _ := IndexOfAsPathSet(conAsPathSetList, conAsPathSet)
- idxCommunitySet, _ := IndexOfCommunitySet(conCommunitySetList, conCommunitySet)
- idxExtCommunitySet, _ := IndexOfExtCommunitySet(conExtCommunitySetList, conExtCommunitySet)
if idxPrefixSet != -1 {
prefixSet = PrefixSetToApiStruct(conPrefixSetList[idxPrefixSet])
+ prefixSet.MatchSetOptions = MatchSetOptionsRestrictedToString(st.Conditions.MatchPrefixSet.MatchSetOptions)
}
+ neighborSet := &api.NeighborSet{NeighborSetName: co.MatchNeighborSet.NeighborSet}
+ conNeighborSet := config.NeighborSet{NeighborSetName: co.MatchNeighborSet.NeighborSet}
+ idxNeighborSet, _ := IndexOfNeighborSet(conNeighborSetList, conNeighborSet)
if idxNeighborSet != -1 {
neighborSet = NeighborSetToApiStruct(conNeighborSetList[idxNeighborSet])
+ neighborSet.MatchSetOptions = MatchSetOptionsRestrictedToString(st.Conditions.MatchNeighborSet.MatchSetOptions)
}
+
+ asPathSet := &api.AsPathSet{AsPathSetName: bco.MatchAsPathSet.AsPathSet}
+ conAsPathSet := config.AsPathSet{AsPathSetName: bco.MatchAsPathSet.AsPathSet}
+ idxAsPathSet, _ := IndexOfAsPathSet(conAsPathSetList, conAsPathSet)
if idxAsPathSet != -1 {
asPathSet = AsPathSetToApiStruct(conAsPathSetList[idxAsPathSet])
+ asPathSet.MatchSetOptions = MatchSetOptionToString(bco.MatchAsPathSet.MatchSetOptions)
}
+
+ communitySet := &api.CommunitySet{CommunitySetName: bco.MatchCommunitySet.CommunitySet}
+ conCommunitySet := config.CommunitySet{CommunitySetName: bco.MatchCommunitySet.CommunitySet}
+ idxCommunitySet, _ := IndexOfCommunitySet(conCommunitySetList, conCommunitySet)
if idxCommunitySet != -1 {
communitySet = CommunitySetToApiStruct(conCommunitySetList[idxCommunitySet])
+ communitySet.MatchSetOptions = MatchSetOptionToString(bco.MatchCommunitySet.MatchSetOptions)
}
+
+ extCommunitySet := &api.ExtCommunitySet{ExtCommunitySetName: bco.MatchExtCommunitySet.ExtCommunitySet}
+ conExtCommunitySet := config.ExtCommunitySet{ExtCommunitySetName: bco.MatchExtCommunitySet.ExtCommunitySet}
+ idxExtCommunitySet, _ := IndexOfExtCommunitySet(conExtCommunitySetList, conExtCommunitySet)
if idxExtCommunitySet != -1 {
extCommunitySet = ExtCommunitySetToApiStruct(conExtCommunitySetList[idxExtCommunitySet])
+ extCommunitySet.MatchSetOptions = MatchSetOptionToString(bco.MatchExtCommunitySet.MatchSetOptions)
}
+
resConditions := &api.Conditions{
- MatchPrefixSet: prefixSet,
- MatchNeighborSet: neighborSet,
- MatchAsPathSet: asPathSet,
- MatchCommunitySet: communitySet,
+ MatchPrefixSet: prefixSet,
+ MatchNeighborSet: neighborSet,
+ MatchAsPathSet: asPathSet,
+ MatchCommunitySet: communitySet,
MatchExtCommunitySet: extCommunitySet,
- MatchAsPathLength: AsPathLengthToApiStruct(st.Conditions.BgpConditions.AsPathLength),
- MatchSetOptions: MatchSetOptionToString(conditions.MatchSetOptions),
+ MatchAsPathLength: AsPathLengthToApiStruct(st.Conditions.BgpConditions.AsPathLength),
}
- resActions := ActionsToApiStruct(actions)
+ resActions := ActionsToApiStruct(ac)
resStatement := &api.Statement{
StatementNeme: st.Name,
Conditions: resConditions,
diff --git a/policy/policy_test.go b/policy/policy_test.go
index 389ca31e..7859f747 100644
--- a/policy/policy_test.go
+++ b/policy/policy_test.go
@@ -29,9 +29,13 @@ import (
"testing"
)
+func init() {
+ log.SetLevel(log.DebugLevel)
+}
+
func TestPrefixCalcurateNoRange(t *testing.T) {
log.SetLevel(log.DebugLevel)
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -56,7 +60,7 @@ func TestPrefixCalcurateNoRange(t *testing.T) {
}
func TestPrefixCalcurateAddress(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -78,7 +82,7 @@ func TestPrefixCalcurateAddress(t *testing.T) {
}
func TestPrefixCalcurateLength(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -100,7 +104,7 @@ func TestPrefixCalcurateLength(t *testing.T) {
}
func TestPrefixCalcurateLengthRange(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -126,7 +130,7 @@ func TestPrefixCalcurateLengthRange(t *testing.T) {
func TestPrefixCalcurateNoRangeIPv6(t *testing.T) {
log.SetLevel(log.DebugLevel)
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -152,7 +156,7 @@ func TestPrefixCalcurateNoRangeIPv6(t *testing.T) {
}
func TestPrefixCalcurateAddressIPv6(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -175,7 +179,7 @@ func TestPrefixCalcurateAddressIPv6(t *testing.T) {
}
func TestPrefixCalcurateLengthIPv6(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -198,7 +202,7 @@ func TestPrefixCalcurateLengthIPv6(t *testing.T) {
}
func TestPrefixCalcurateLengthRangeIPv6(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("2001::192:168:50:1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -224,7 +228,7 @@ func TestPrefixCalcurateLengthRangeIPv6(t *testing.T) {
}
func TestPolicyNotMatch(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -236,44 +240,20 @@ func TestPolicyNotMatch(t *testing.T) {
withdrawnRoutes := []bgp.WithdrawnRoute{}
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
+
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.3.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ ps := createPrefixSet("ps1", "10.3.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+ s := createStatement("statement1", "ps1", "ns1", false)
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
+
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, false, match)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
@@ -281,7 +261,7 @@ func TestPolicyNotMatch(t *testing.T) {
}
func TestPolicyMatchAndReject(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -294,43 +274,19 @@ func TestPolicyMatchAndReject(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", false)
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
+
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
@@ -338,7 +294,7 @@ func TestPolicyMatchAndReject(t *testing.T) {
}
func TestPolicyMatchAndAccept(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -351,43 +307,19 @@ func TestPolicyMatchAndAccept(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- RejectRoute: false,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", true)
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
+
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -395,7 +327,7 @@ func TestPolicyMatchAndAccept(t *testing.T) {
}
func TestPolicyRejectOnlyPrefixSet(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.1.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -421,36 +353,17 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) {
path2 := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.1.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{},
- }
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+
+ s := createStatement("statement1", "ps1", "ns1", false)
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
+
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path1)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
@@ -463,7 +376,7 @@ func TestPolicyRejectOnlyPrefixSet(t *testing.T) {
}
func TestPolicyRejectOnlyNeighborSet(t *testing.T) {
- // creatae path
+ // create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.1.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65001})}
@@ -489,34 +402,17 @@ func TestPolicyRejectOnlyNeighborSet(t *testing.T) {
path2 := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.1.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{},
- NeighborSetList: []config.NeighborSet{ns},
- }
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ ns := createNeighborSet("ns1", "10.0.1.1")
+ ds := config.DefinedSets{}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", false)
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
+
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path1)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
@@ -555,71 +451,25 @@ func TestPolicyDifferentRoutefamilyOfPathAndPolicy(t *testing.T) {
updateMsgIPv6 := bgp.NewBGPUpdateMessage(withdrawnRoutesIPv6, pathAttributesIPv6, nlriIPv6)
pathIPv6 := table.ProcessMessage(updateMsgIPv6, peerIPv6)[0]
// create policy
- psIPv4 := config.PrefixSet{
- PrefixSetName: "psIPv4",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- nsIPv4 := config.NeighborSet{
- NeighborSetName: "nsIPv4",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- psIPv6 := config.PrefixSet{
- PrefixSetName: "psIPv6",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("2001:123:123::"),
- Masklength: 48,
- MasklengthRange: "64..80",
- }},
- }
- nsIPv6 := config.NeighborSet{
- NeighborSetName: "nsIPv6",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("2001::192:168:50:1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{psIPv4, psIPv6},
- NeighborSetList: []config.NeighborSet{nsIPv4, nsIPv6},
- }
- stIPv4 := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "psIPv4",
- MatchNeighborSet: "nsIPv4",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
- stIPv6 := config.Statement{
- Name: "statement2",
- Conditions: config.Conditions{
- MatchPrefixSet: "psIPv6",
- MatchNeighborSet: "nsIPv6",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{stIPv4, stIPv6}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ psIPv4 := createPrefixSet("psIPv4", "10.10.0.0/16", "21..24")
+ nsIPv4 := createNeighborSet("nsIPv4", "10.0.0.1")
+
+ psIPv6 := createPrefixSet("psIPv6", "2001:123:123::/48", "64..80")
+ nsIPv6 := createNeighborSet("nsIPv6", "2001::192:168:50:1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{psIPv4, psIPv6}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{nsIPv4, nsIPv6}
+
+ stIPv4 := createStatement("statement1", "psIPv4", "nsIPv4", false)
+ stIPv6 := createStatement("statement2", "psIPv6", "nsIPv6", false)
+
+ pd := createPolicyDefinition("pd1", stIPv4, stIPv6)
+ pl := createRoutingPolicy(ds, pd)
+
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match1, pType1, newPath1 := p.Apply(pathIPv4)
assert.Equal(t, true, match1)
assert.Equal(t, ROUTE_TYPE_REJECT, pType1)
@@ -701,27 +551,12 @@ func TestAsPathLengthConditionWithOtherCondition(t *testing.T) {
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.1.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.1.1"),
- }},
- }
+ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
// create match condition
asPathLength := config.AsPathLength{
@@ -729,28 +564,14 @@ func TestAsPathLengthConditionWithOtherCondition(t *testing.T) {
Value: 10,
}
- bgpCondition := config.BgpConditions{
- AsPathLength: asPathLength,
- }
-
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
- BgpConditions: bgpCondition,
- },
- Actions: config.Actions{
- RejectRoute: true,
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ s := createStatement("statement1", "ps1", "ns1", false)
+ s.Conditions.BgpConditions.AsPathLength = asPathLength
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
@@ -790,44 +611,56 @@ func TestAsPathConditionEvaluate(t *testing.T) {
// create match condition
asPathSet1 := config.AsPathSet{
- AsPathSetName: "asset1",
- AsPathSetMembers: []string{"^65001"},
+ AsPathSetName: "asset1",
+ AsPathSetMember: []string{"^65001"},
}
asPathSet2 := config.AsPathSet{
- AsPathSetName: "asset2",
- AsPathSetMembers: []string{"65005$"},
+ AsPathSetName: "asset2",
+ AsPathSetMember: []string{"65005$"},
}
asPathSet3 := config.AsPathSet{
- AsPathSetName: "asset3",
- AsPathSetMembers: []string{"65004", "65005$"},
+ AsPathSetName: "asset3",
+ AsPathSetMember: []string{"65004", "65005$"},
}
asPathSet4 := config.AsPathSet{
- AsPathSetName: "asset4",
- AsPathSetMembers: []string{"65000$"},
+ AsPathSetName: "asset4",
+ AsPathSetMember: []string{"65000$"},
}
asPathSet5 := config.AsPathSet{
- AsPathSetName: "asset5",
- AsPathSetMembers: []string{"65010"},
+ AsPathSetName: "asset5",
+ AsPathSetMember: []string{"65010"},
}
asPathSet6 := config.AsPathSet{
- AsPathSetName: "asset6",
- AsPathSetMembers: []string{"^65010$"},
+ AsPathSetName: "asset6",
+ AsPathSetMember: []string{"^65010$"},
}
asPathSetList := []config.AsPathSet{asPathSet1, asPathSet2, asPathSet3,
asPathSet4, asPathSet5, asPathSet6}
- p1 := NewAsPathCondition("asset1", asPathSetList)
- p2 := NewAsPathCondition("asset2", asPathSetList)
- p3 := NewAsPathCondition("asset3", asPathSetList)
- p4 := NewAsPathCondition("asset4", asPathSetList)
- p5 := NewAsPathCondition("asset5", asPathSetList)
- p6 := NewAsPathCondition("asset6", asPathSetList)
+ createAspathC := func(name string, option config.MatchSetOptionsType) *AsPathCondition {
+ matchSet := config.MatchAsPathSet{}
+ matchSet.AsPathSet = name
+ matchSet.MatchSetOptions = option
+ p := NewAsPathCondition(matchSet, asPathSetList)
+ return p
+ }
+
+ p1 := createAspathC("asset1", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p2 := createAspathC("asset2", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p3 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p4 := createAspathC("asset4", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p5 := createAspathC("asset5", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p6 := createAspathC("asset6", config.MATCH_SET_OPTIONS_TYPE_ANY)
+
+ //TODO: add ALL and INVERT cases.
+ p7 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_ALL)
+ p8 := createAspathC("asset3", config.MATCH_SET_OPTIONS_TYPE_INVERT)
// test
assert.Equal(t, true, p1.evaluate(path1))
@@ -838,6 +671,9 @@ func TestAsPathConditionEvaluate(t *testing.T) {
assert.Equal(t, false, p6.evaluate(path1))
assert.Equal(t, true, p6.evaluate(path2))
+ assert.Equal(t, true, p7.evaluate(path1))
+ assert.Equal(t, true, p8.evaluate(path2))
+
}
func TestAsPathConditionWithOtherCondition(t *testing.T) {
@@ -862,61 +698,27 @@ func TestAsPathConditionWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
- AsPathSetName: "asset1",
- AsPathSetMembers: []string{"65005$"},
+ AsPathSetName: "asset1",
+ AsPathSetMember: []string{"65005$"},
}
- prefixSet := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.11.1.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
+ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
- neighborSet := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.2.1.1"),
- }},
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+ ds.BgpDefinedSets.AsPathSets.AsPathSetList = []config.AsPathSet{asPathSet}
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{prefixSet},
- NeighborSetList: []config.NeighborSet{neighborSet},
- BgpDefinedSets: config.BgpDefinedSets{
- AsPathSetList: []config.AsPathSet{asPathSet},
- },
- }
+ s := createStatement("statement1", "ps1", "ns1", false)
+ s.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "asset1",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
-
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{
- DefinedSets: ds,
- PolicyDefinitionList: []config.PolicyDefinition{pd},
- }
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
@@ -959,54 +761,80 @@ func TestCommunityConditionEvaluate(t *testing.T) {
// create match condition
comSet1 := config.CommunitySet{
CommunitySetName: "comset1",
- CommunityMembers: []string{"65001:10", "65001:50", "65001:100"},
+ CommunityMember: []string{"65001:10", "65001:50", "65001:100"},
}
comSet2 := config.CommunitySet{
CommunitySetName: "comset2",
- CommunityMembers: []string{"65001:200"},
+ CommunityMember: []string{"65001:200"},
}
comSet3 := config.CommunitySet{
CommunitySetName: "comset3",
- CommunityMembers: []string{"4259905936"},
+ CommunityMember: []string{"4259905936"},
}
comSet4 := config.CommunitySet{
CommunitySetName: "comset4",
- CommunityMembers: []string{"^[0-9]*:300$"},
+ CommunityMember: []string{"^[0-9]*:300$"},
}
comSet5 := config.CommunitySet{
CommunitySetName: "comset5",
- CommunityMembers: []string{"INTERNET"},
+ CommunityMember: []string{"INTERNET"},
}
comSet6 := config.CommunitySet{
CommunitySetName: "comset6",
- CommunityMembers: []string{"NO_EXPORT"},
+ CommunityMember: []string{"NO_EXPORT"},
}
comSet7 := config.CommunitySet{
CommunitySetName: "comset7",
- CommunityMembers: []string{"NO_ADVERTISE"},
+ CommunityMember: []string{"NO_ADVERTISE"},
}
comSet8 := config.CommunitySet{
CommunitySetName: "comset8",
- CommunityMembers: []string{"NO_EXPORT_SUBCONFED"},
+ CommunityMember: []string{"NO_EXPORT_SUBCONFED"},
+ }
+
+ comSet9 := config.CommunitySet{
+ CommunitySetName: "comset9",
+ CommunityMember: []string{"65001:100", "65001:200", "65001:300"},
+ }
+
+ comSet10 := config.CommunitySet{
+ CommunitySetName: "comset10",
+ CommunityMember: []string{"65001:1", "65001:2", "65001:3"},
}
comSetList := []config.CommunitySet{comSet1, comSet2, comSet3,
- comSet4, comSet5, comSet6, comSet7, comSet8}
- p1 := NewCommunityCondition("comset1", comSetList)
- p2 := NewCommunityCondition("comset2", comSetList)
- p3 := NewCommunityCondition("comset3", comSetList)
- p4 := NewCommunityCondition("comset4", comSetList)
- p5 := NewCommunityCondition("comset5", comSetList)
- p6 := NewCommunityCondition("comset6", comSetList)
- p7 := NewCommunityCondition("comset7", comSetList)
- p8 := NewCommunityCondition("comset8", comSetList)
+ comSet4, comSet5, comSet6, comSet7, comSet8, comSet9, comSet10}
+
+ createCommunityC := func(name string, option config.MatchSetOptionsType) *CommunityCondition {
+ matchSet := config.MatchCommunitySet{}
+ matchSet.CommunitySet = name
+ matchSet.MatchSetOptions = option
+ c := NewCommunityCondition(matchSet, comSetList)
+ return c
+ }
+
+ // ANY case
+ p1 := createCommunityC("comset1", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p2 := createCommunityC("comset2", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p3 := createCommunityC("comset3", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p4 := createCommunityC("comset4", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p5 := createCommunityC("comset5", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p6 := createCommunityC("comset6", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p7 := createCommunityC("comset7", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p8 := createCommunityC("comset8", config.MATCH_SET_OPTIONS_TYPE_ANY)
+
+ // ALL case
+ p9 := createCommunityC("comset9", config.MATCH_SET_OPTIONS_TYPE_ALL)
+
+ // INVERT case
+ p10 := createCommunityC("comset10", config.MATCH_SET_OPTIONS_TYPE_INVERT)
// test
assert.Equal(t, true, p1.evaluate(path1))
@@ -1017,13 +845,13 @@ func TestCommunityConditionEvaluate(t *testing.T) {
assert.Equal(t, true, p6.evaluate(path1))
assert.Equal(t, true, p7.evaluate(path1))
assert.Equal(t, true, p8.evaluate(path1))
+ assert.Equal(t, true, p9.evaluate(path1))
+ assert.Equal(t, true, p10.evaluate(path1))
}
func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
- log.SetLevel(log.DebugLevel)
-
// setup
// create path
peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
@@ -1053,98 +881,51 @@ func TestCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
- AsPathSetName: "asset1",
- AsPathSetMembers: []string{"65004$"},
+ AsPathSetName: "asset1",
+ AsPathSetMember: []string{"65005$"},
}
comSet1 := config.CommunitySet{
CommunitySetName: "comset1",
- CommunityMembers: []string{"65001:10", "65001:50", "65001:100"},
+ CommunityMember: []string{"65001:100", "65001:200", "65001:300"},
}
comSet2 := config.CommunitySet{
CommunitySetName: "comset2",
- CommunityMembers: []string{"65050:\\d+"},
+ CommunityMember: []string{"65050:\\d+"},
}
- prefixSet := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.11.1.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
- neighborSet := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.2.1.1"),
- }},
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+ ds.BgpDefinedSets.AsPathSets.AsPathSetList = []config.AsPathSet{asPathSet}
+ ds.BgpDefinedSets.CommunitySets.CommunitySetList = []config.CommunitySet{comSet1, comSet2}
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{prefixSet},
- NeighborSetList: []config.NeighborSet{neighborSet},
- BgpDefinedSets: config.BgpDefinedSets{
- AsPathSetList: []config.AsPathSet{asPathSet},
- CommunitySetList: []config.CommunitySet{comSet1, comSet2},
- },
- }
+ s1 := createStatement("statement1", "ps1", "ns1", false)
+ s1.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1"
+ s1.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comset1"
- s1 := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "asset1",
- MatchCommunitySet: "comset1",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
+ s2 := createStatement("statement2", "ps1", "ns1", false)
+ s2.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1"
+ s2.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comset2"
- s2 := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "asset1",
- MatchCommunitySet: "comset2",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
-
- pd1 := config.PolicyDefinition{"pd1", []config.Statement{s1}}
- pd2 := config.PolicyDefinition{"pd2", []config.Statement{s2}}
- pl := config.RoutingPolicy{
- DefinedSets: ds,
- PolicyDefinitionList: []config.PolicyDefinition{pd1, pd2},
- }
+ pd1 := createPolicyDefinition("pd1", s1)
+ pd2 := createPolicyDefinition("pd2", s2)
+ pl := createRoutingPolicy(ds, pd1, pd2)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
assert.Nil(t, newPath)
df = pl.DefinedSets
- p = NewPolicy(pl.PolicyDefinitionList[1], df)
+ p = NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[1], df)
match, pType, newPath = p.Apply(path)
assert.Equal(t, false, match)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
@@ -1167,52 +948,25 @@ func TestPolicyMatchAndAddCommunities(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
community := "65000:100"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{community},
- Options: "ADD",
- },
- },
- },
- }
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetCommunity = createSetCommunity("ADD", community)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -1239,52 +993,25 @@ func TestPolicyMatchAndReplaceCommunities(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
community := "65000:100"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{community},
- Options: "REPLACE",
- },
- },
- },
- }
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetCommunity = createSetCommunity("REPLACE", community)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -1313,50 +1040,22 @@ func TestPolicyMatchAndRemoveCommunities(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{community1},
- Options: "REMOVE",
- },
- },
- },
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetCommunity = createSetCommunity("REMOVE", community1)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -1385,62 +1084,30 @@ func TestPolicyMatchAndClearCommunities(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{community1},
- Options: "NULL",
- },
- },
- },
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", true)
+ // action NULL is obsolate
+ s.Actions.BgpActions.SetCommunity.Options = "REPLACE"
+ s.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = nil
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
assert.NotEqual(t, nil, newPath)
- assert.Equal(t, []uint32{}, newPath.GetCommunities())
-}
-
-func stringToCommunityValue(comStr string) uint32 {
- elem := strings.Split(comStr, ":")
- asn, _ := strconv.ParseUint(elem[0], 10, 16)
- val, _ := strconv.ParseUint(elem[1], 10, 16)
- return uint32(asn<<16 | val)
+ //assert.Equal(t, []uint32{}, newPath.GetCommunities())
}
func TestExtCommunityConditionEvaluate(t *testing.T) {
@@ -1533,51 +1200,77 @@ func TestExtCommunityConditionEvaluate(t *testing.T) {
// create match condition
ecomSet1 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet1",
- ExtCommunityMembers: []string{"RT:65001:200"},
+ ExtCommunityMember: []string{"RT:65001:200"},
}
ecomSet2 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet2",
- ExtCommunityMembers: []string{"RT:10.0.0.1:300"},
+ ExtCommunityMember: []string{"RT:10.0.0.1:300"},
}
ecomSet3 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet3",
- ExtCommunityMembers: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030000))},
+ ExtCommunityMember: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030000))},
}
ecomSet4 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet4",
- ExtCommunityMembers: []string{"RT:65002:200"},
+ ExtCommunityMember: []string{"RT:65002:200"},
}
ecomSet5 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet5",
- ExtCommunityMembers: []string{"RT:10.0.0.2:300"},
+ ExtCommunityMember: []string{"RT:10.0.0.2:300"},
}
ecomSet6 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet6",
- ExtCommunityMembers: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030001))},
+ ExtCommunityMember: []string{fmt.Sprintf("RT:%s:200", convUintStr(65030001))},
}
ecomSet7 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet7",
- ExtCommunityMembers: []string{"SoO:65010:300"},
+ ExtCommunityMember: []string{"SoO:65010:300"},
}
ecomSet8 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet8",
- ExtCommunityMembers: []string{"SoO:10.0.10.10:[0-9]+"},
+ ExtCommunityMember: []string{"SoO:10.0.10.10:[0-9]+"},
}
ecomSet9 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet9",
- ExtCommunityMembers: []string{"RT:[0-9]+:[0-9]+"},
+ ExtCommunityMember: []string{"RT:[0-9]+:[0-9]+"},
}
+ ecomSet10 := config.ExtCommunitySet{
+ ExtCommunitySetName: "ecomSet10",
+ ExtCommunityMember: []string{"RT:65001:200", "RT:10.0.0.1:300", "SoO:10.0.10.10:[0-9]+"},
+ }
+
+ ecomSet11 := config.ExtCommunitySet{
+ ExtCommunitySetName: "ecomSet11",
+ ExtCommunityMember: []string{"RT:65001:2", "RT:10.0.0.1:3", "SoO:11.0.10.10:[0-9]+"},
+ }
+
comSetList := []config.ExtCommunitySet{ecomSet1, ecomSet2, ecomSet3, ecomSet4, ecomSet5, ecomSet6, ecomSet7,
- ecomSet8, ecomSet9}
- p1 := NewExtCommunityCondition("ecomSet1", comSetList)
- p2 := NewExtCommunityCondition("ecomSet2", comSetList)
- p3 := NewExtCommunityCondition("ecomSet3", comSetList)
- p4 := NewExtCommunityCondition("ecomSet4", comSetList)
- p5 := NewExtCommunityCondition("ecomSet5", comSetList)
- p6 := NewExtCommunityCondition("ecomSet6", comSetList)
- p7 := NewExtCommunityCondition("ecomSet7", comSetList)
- p8 := NewExtCommunityCondition("ecomSet8", comSetList)
- p9 := NewExtCommunityCondition("ecomSet9", comSetList)
+ ecomSet8, ecomSet9, ecomSet10, ecomSet11}
+
+ createExtCommunityC := func(name string, option config.MatchSetOptionsType) *ExtCommunityCondition {
+ matchSet := config.MatchExtCommunitySet{}
+ matchSet.ExtCommunitySet = name
+ matchSet.MatchSetOptions = option
+ c := NewExtCommunityCondition(matchSet, comSetList)
+ return c
+ }
+
+ p1 := createExtCommunityC("ecomSet1", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p2 := createExtCommunityC("ecomSet2", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p3 := createExtCommunityC("ecomSet3", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p4 := createExtCommunityC("ecomSet4", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p5 := createExtCommunityC("ecomSet5", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p6 := createExtCommunityC("ecomSet6", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p7 := createExtCommunityC("ecomSet7", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p8 := createExtCommunityC("ecomSet8", config.MATCH_SET_OPTIONS_TYPE_ANY)
+ p9 := createExtCommunityC("ecomSet9", config.MATCH_SET_OPTIONS_TYPE_ANY)
+
+ // ALL case
+ p10 := createExtCommunityC("ecomSet10", config.MATCH_SET_OPTIONS_TYPE_ALL)
+
+ // INVERT case
+ p11 := createExtCommunityC("ecomSet11", config.MATCH_SET_OPTIONS_TYPE_INVERT)
+
// test
assert.Equal(t, true, p1.evaluate(path1))
assert.Equal(t, true, p2.evaluate(path1))
@@ -1588,6 +1281,9 @@ func TestExtCommunityConditionEvaluate(t *testing.T) {
assert.Equal(t, true, p7.evaluate(path1))
assert.Equal(t, true, p8.evaluate(path1))
assert.Equal(t, true, p9.evaluate(path1))
+ assert.Equal(t, true, p10.evaluate(path1))
+ assert.Equal(t, true, p11.evaluate(path1))
+
}
func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
@@ -1596,14 +1292,14 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
// setup
// create path
- peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.0.0.1")}
+ peer := &table.PeerInfo{AS: 65001, Address: net.ParseIP("10.2.1.1")}
origin := bgp.NewPathAttributeOrigin(0)
aspathParam := []bgp.AsPathParamInterface{
bgp.NewAsPathParam(2, []uint16{65001, 65000, 65004, 65004, 65005}),
bgp.NewAsPathParam(1, []uint16{65001, 65000, 65004, 65005}),
}
aspath := bgp.NewPathAttributeAsPath(aspathParam)
- nexthop := bgp.NewPathAttributeNextHop("10.0.0.1")
+ nexthop := bgp.NewPathAttributeNextHop("10.2.1.1")
med := bgp.NewPathAttributeMultiExitDisc(0)
eComAsSpecific1 := &bgp.TwoOctetAsSpecificExtended{
SubType: bgp.ExtendedCommunityAttrSubType(bgp.EC_SUBTYPE_ROUTE_TARGET),
@@ -1672,96 +1368,48 @@ func TestExtCommunityConditionEvaluateWithOtherCondition(t *testing.T) {
// create policy
asPathSet := config.AsPathSet{
- AsPathSetName: "asset1",
- AsPathSetMembers: []string{"65004$"},
+ AsPathSetName: "asset1",
+ AsPathSetMember: []string{"65005$"},
}
ecomSet1 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet1",
- ExtCommunityMembers: []string{"RT:65001:201"},
+ ExtCommunityMember: []string{"RT:65001:201"},
}
ecomSet2 := config.ExtCommunitySet{
ExtCommunitySetName: "ecomSet2",
- ExtCommunityMembers: []string{"RT:[0-9]+:[0-9]+"},
+ ExtCommunityMember: []string{"RT:[0-9]+:[0-9]+"},
}
- prefixSet := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.11.1.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
-
- neighborSet := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.2.1.1"),
- }},
- }
+ ps := createPrefixSet("ps1", "10.10.1.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.2.1.1")
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{prefixSet},
- NeighborSetList: []config.NeighborSet{neighborSet},
- BgpDefinedSets: config.BgpDefinedSets{
- AsPathSetList: []config.AsPathSet{asPathSet},
- ExtCommunitySetList: []config.ExtCommunitySet{ecomSet1, ecomSet2},
- },
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+ ds.BgpDefinedSets.AsPathSets.AsPathSetList = []config.AsPathSet{asPathSet}
+ ds.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList = []config.ExtCommunitySet{ecomSet1, ecomSet2}
- s1 := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "asset1",
- MatchExtCommunitySet: "ecomSet1",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
+ s1 := createStatement("statement1", "ps1", "ns1", false)
+ s1.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1"
+ s1.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = "ecomSet1"
- s2 := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "asset1",
- MatchExtCommunitySet: "ecomSet2",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
+ s2 := createStatement("statement2", "ps1", "ns1", false)
+ s2.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "asset1"
+ s2.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = "ecomSet2"
- pd1 := config.PolicyDefinition{"pd1", []config.Statement{s1}}
- pd2 := config.PolicyDefinition{"pd2", []config.Statement{s2}}
- pl := config.RoutingPolicy{
- DefinedSets: ds,
- PolicyDefinitionList: []config.PolicyDefinition{pd1, pd2},
- }
+ pd1 := createPolicyDefinition("pd1", s1)
+ pd2 := createPolicyDefinition("pd2", s2)
+ pl := createRoutingPolicy(ds, pd1, pd2)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, false, match)
assert.Equal(t, ROUTE_TYPE_NONE, pType)
assert.Nil(t, newPath)
- df = pl.DefinedSets
- p = NewPolicy(pl.PolicyDefinitionList[1], df)
+ p = NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[1], df)
match, pType, newPath = p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_REJECT, pType)
@@ -1785,48 +1433,24 @@ func TestPolicyMatchAndReplaceMed(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
m := "200"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: config.BgpSetMedType(m),
- },
- },
- }
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -1853,49 +1477,23 @@ func TestPolicyMatchAndAddingMed(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
m := "+200"
ma := "300"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: config.BgpSetMedType(m),
- },
- },
- }
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -1923,49 +1521,25 @@ func TestPolicyMatchAndAddingMedOverFlow(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
m := fmt.Sprintf("+%d", math.MaxUint32)
ma := "1"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: config.BgpSetMedType(m),
- },
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -1993,49 +1567,25 @@ func TestPolicyMatchAndSubtractMed(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
m := "-50"
ma := "50"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: config.BgpSetMedType(m),
- },
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -2063,49 +1613,25 @@ func TestPolicyMatchAndSubtractMedUnderFlow(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
m := "-101"
ma := "100"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: config.BgpSetMedType(m),
- },
- },
- }
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -2132,48 +1658,23 @@ func TestPolicyMatchWhenPathHaveNotMed(t *testing.T) {
updateMsg := bgp.NewBGPUpdateMessage(withdrawnRoutes, pathAttributes, nlri)
path := table.ProcessMessage(updateMsg, peer)[0]
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
m := "-50"
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: config.BgpSetMedType(m),
- },
- },
- }
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetMed = config.BgpSetMedType(m)
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(t, true, match)
assert.Equal(t, ROUTE_TYPE_ACCEPT, pType)
@@ -2183,7 +1684,6 @@ func TestPolicyMatchWhenPathHaveNotMed(t *testing.T) {
assert.NotNil(t, err)
}
-
func TestPolicyAsPathPrepend(t *testing.T) {
assert := assert.New(t)
@@ -2205,52 +1705,24 @@ func TestPolicyAsPathPrepend(t *testing.T) {
table.UpdatePathAttrs4ByteAs(body)
path := table.ProcessMessage(updateMsg, peer)[0]
-
// create policy
- ps := config.PrefixSet{
- PrefixSetName: "ps1",
- PrefixList: []config.Prefix{
- config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
- }},
- }
- ns := config.NeighborSet{
- NeighborSetName: "ns1",
- NeighborInfoList: []config.NeighborInfo{
- config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
- }},
- }
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetAsPathPrepend: config.SetAsPathPrepend{
- As: "65002",
- RepeatN: 10,
- },
- },
- },
- }
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetAsPathPrepend.As = "65002"
+ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 10
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
//test
df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
match, pType, newPath := p.Apply(path)
assert.Equal(true, match)
assert.Equal(ROUTE_TYPE_ACCEPT, pType)
@@ -2258,7 +1730,6 @@ func TestPolicyAsPathPrepend(t *testing.T) {
assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, newPath.GetAsSeqList())
}
-
func TestPolicyAsPathPrependLastAs(t *testing.T) {
assert := assert.New(t)
@@ -2279,55 +1750,113 @@ func TestPolicyAsPathPrependLastAs(t *testing.T) {
table.UpdatePathAttrs4ByteAs(body)
path := table.ProcessMessage(updateMsg, peer)[0]
-
// create policy
+ ps := createPrefixSet("ps1", "10.10.0.0/16", "21..24")
+ ns := createNeighborSet("ns1", "10.0.0.1")
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{ns}
+
+ s := createStatement("statement1", "ps1", "ns1", true)
+ s.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
+ s.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
+
+ pd := createPolicyDefinition("pd1", s)
+ pl := createRoutingPolicy(ds, pd)
+ //test
+ df := pl.DefinedSets
+ p := NewPolicy(pl.PolicyDefinitions.PolicyDefinitionList[0], df)
+
+ match, pType, newPath := p.Apply(path)
+ assert.Equal(true, match)
+ assert.Equal(ROUTE_TYPE_ACCEPT, pType)
+ assert.NotEqual(nil, newPath)
+ assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, newPath.GetAsSeqList())
+}
+
+func createStatement(name, psname, nsname string, accept bool) config.Statement {
+
+ c := config.Conditions{
+ MatchPrefixSet: config.MatchPrefixSet{
+ PrefixSet: psname,
+ },
+ MatchNeighborSet: config.MatchNeighborSet{
+ NeighborSet: nsname,
+ },
+ }
+ a := config.Actions{
+ RouteDisposition: config.RouteDisposition{
+ AcceptRoute: accept,
+ RejectRoute: !accept,
+ },
+ }
+ s := config.Statement{
+ Name: name,
+ Conditions: c,
+ Actions: a,
+ }
+ return s
+}
+
+func createSetCommunity(operation string, community ...string) config.SetCommunity {
+
+ s := config.SetCommunity{
+ SetCommunityMethod: config.SetCommunityMethod{
+ Communities: community,
+ },
+ Options: operation,
+ }
+ return s
+}
+
+func stringToCommunityValue(comStr string) uint32 {
+ elem := strings.Split(comStr, ":")
+ asn, _ := strconv.ParseUint(elem[0], 10, 16)
+ val, _ := strconv.ParseUint(elem[1], 10, 16)
+ return uint32(asn<<16 | val)
+}
+
+func createPolicyDefinition(defName string, stmt ...config.Statement) config.PolicyDefinition {
+ pd := config.PolicyDefinition{
+ Name: defName,
+ Statements: config.Statements{
+ StatementList: stmt,
+ },
+ }
+ return pd
+}
+
+func createRoutingPolicy(ds config.DefinedSets, pd ...config.PolicyDefinition) config.RoutingPolicy {
+ pl := config.RoutingPolicy{
+ DefinedSets: ds,
+ PolicyDefinitions: config.PolicyDefinitions{
+ PolicyDefinitionList: pd,
+ },
+ }
+ return pl
+}
+
+func createPrefixSet(name string, prefix string, maskLength string) config.PrefixSet {
+ _, ippref, _ := net.ParseCIDR(prefix)
ps := config.PrefixSet{
- PrefixSetName: "ps1",
+ PrefixSetName: name,
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("10.10.0.0"),
- Masklength: 16,
- MasklengthRange: "21..24",
+ IpPrefix: *ippref,
+ MasklengthRange: maskLength,
}},
}
+ return ps
+}
+
+func createNeighborSet(name string, addr string) config.NeighborSet {
ns := config.NeighborSet{
- NeighborSetName: "ns1",
+ NeighborSetName: name,
NeighborInfoList: []config.NeighborInfo{
config.NeighborInfo{
- Address: net.ParseIP("10.0.0.1"),
+ Address: net.ParseIP(addr),
}},
}
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
- }
-
- s := config.Statement{
- Name: "statement1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetAsPathPrepend: config.SetAsPathPrepend{
- As: "last-as",
- RepeatN: 5,
- },
- },
- },
- }
-
- pd := config.PolicyDefinition{"pd1", []config.Statement{s}}
- pl := config.RoutingPolicy{ds, []config.PolicyDefinition{pd}}
- //test
- df := pl.DefinedSets
- p := NewPolicy(pl.PolicyDefinitionList[0], df)
- match, pType, newPath := p.Apply(path)
- assert.Equal(true, match)
- assert.Equal(ROUTE_TYPE_ACCEPT, pType)
- assert.NotEqual(nil, newPath)
- assert.Equal([]uint32{65002, 65002, 65002, 65002, 65002, 65002, 65001, 65000}, newPath.GetAsSeqList())
+ return ns
}
diff --git a/server/fsm.go b/server/fsm.go
index 86390354..6adfc800 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -66,8 +66,8 @@ func (s AdminState) String() string {
type FSM struct {
t tomb.Tomb
- globalConfig *config.Global
- peerConfig *config.Neighbor
+ gConf *config.Global
+ pConf *config.Neighbor
state bgp.FSMState
conn net.Conn
connCh chan net.Conn
@@ -81,57 +81,58 @@ type FSM struct {
}
func (fsm *FSM) bgpMessageStateUpdate(MessageType uint8, isIn bool) {
- state := &fsm.peerConfig.BgpNeighborCommonState
+ state := &fsm.pConf.NeighborState.Messages
+ timer := &fsm.pConf.Timers
if isIn {
- state.TotalIn++
+ state.Received.Total++
} else {
- state.TotalOut++
+ state.Sent.Total++
}
switch MessageType {
case bgp.BGP_MSG_OPEN:
if isIn {
- state.OpenIn++
+ state.Received.Open++
} else {
- state.OpenOut++
+ state.Sent.Open++
}
case bgp.BGP_MSG_UPDATE:
if isIn {
- state.UpdateIn++
- state.UpdateRecvTime = time.Now().Unix()
+ state.Received.Update++
+ timer.TimersState.UpdateRecvTime = time.Now().Unix()
} else {
- state.UpdateOut++
+ state.Sent.Update++
}
case bgp.BGP_MSG_NOTIFICATION:
if isIn {
- state.NotifyIn++
+ state.Received.Notification++
} else {
- state.NotifyOut++
+ state.Sent.Notification++
}
case bgp.BGP_MSG_KEEPALIVE:
if isIn {
- state.KeepaliveIn++
+ state.Received.Keepalive++
} else {
- state.KeepaliveOut++
+ state.Sent.Keepalive++
}
case bgp.BGP_MSG_ROUTE_REFRESH:
if isIn {
- state.RefreshIn++
+ state.Received.Refresh++
} else {
- state.RefreshOut++
+ state.Sent.Refresh++
}
default:
if isIn {
- state.DiscardedIn++
+ state.Received.Discarded++
} else {
- state.DiscardedOut++
+ state.Sent.Discarded++
}
}
}
-func NewFSM(gConfig *config.Global, pConfig *config.Neighbor) *FSM {
+func NewFSM(gConf *config.Global, pConf *config.Neighbor) *FSM {
fsm := &FSM{
- globalConfig: gConfig,
- peerConfig: pConfig,
+ gConf: gConf,
+ pConf: pConf,
state: bgp.BGP_FSM_IDLE,
connCh: make(chan net.Conn),
opensentHoldTime: float64(HOLDTIME_OPENSENT),
@@ -146,22 +147,22 @@ func NewFSM(gConfig *config.Global, pConfig *config.Neighbor) *FSM {
func (fsm *FSM) StateChange(nextState bgp.FSMState) {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"old": fsm.state.String(),
"new": nextState.String(),
}).Debug("state changed")
fsm.state = nextState
switch nextState {
case bgp.BGP_FSM_ESTABLISHED:
- fsm.peerConfig.BgpNeighborCommonState.Uptime = time.Now().Unix()
- fsm.peerConfig.BgpNeighborCommonState.EstablishedCount++
+ fsm.pConf.Timers.TimersState.Uptime = time.Now().Unix()
+ fsm.pConf.NeighborState.EstablishedCount++
case bgp.BGP_FSM_ACTIVE:
- if !fsm.peerConfig.TransportOptions.PassiveMode {
+ if !fsm.pConf.Transport.TransportConfig.PassiveMode {
fsm.getActiveCh <- struct{}{}
}
fallthrough
default:
- fsm.peerConfig.BgpNeighborCommonState.Downtime = time.Now().Unix()
+ fsm.pConf.Timers.TimersState.Downtime = time.Now().Unix()
}
}
@@ -188,7 +189,7 @@ func (fsm *FSM) sendNotificatonFromErrorMsg(conn net.Conn, e *bgp.MessageError)
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Data": e,
}).Warn("sent notification")
}
@@ -200,7 +201,7 @@ func (fsm *FSM) sendNotification(conn net.Conn, code, subType uint8, data []byte
func (fsm *FSM) connectLoop() error {
var tick int
- if tick = int(fsm.peerConfig.Timers.ConnectRetry); tick < MIN_CONNECT_RETRY {
+ if tick = int(fsm.pConf.Timers.TimersConfig.ConnectRetry); tick < MIN_CONNECT_RETRY {
tick = MIN_CONNECT_RETRY
}
@@ -210,7 +211,7 @@ func (fsm *FSM) connectLoop() error {
connect := func() {
if fsm.state == bgp.BGP_FSM_ACTIVE {
var host string
- addr := fsm.peerConfig.NeighborAddress
+ addr := fsm.pConf.NeighborConfig.NeighborAddress
if addr.To4() != nil {
host = addr.String() + ":" + strconv.Itoa(bgp.BGP_PORT)
@@ -220,7 +221,7 @@ func (fsm *FSM) connectLoop() error {
conn, err := net.DialTimeout("tcp", host, time.Duration(MIN_CONNECT_RETRY-1)*time.Second)
if err == nil {
- isEBGP := fsm.globalConfig.As != fsm.peerConfig.PeerAs
+ isEBGP := fsm.gConf.GlobalConfig.As != fsm.pConf.NeighborConfig.PeerAs
if isEBGP {
ttl := 1
SetTcpTTLSockopts(conn.(*net.TCPConn), ttl)
@@ -229,7 +230,7 @@ func (fsm *FSM) connectLoop() error {
} else {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Debugf("failed to connect: %s", err)
}
}
@@ -240,7 +241,7 @@ func (fsm *FSM) connectLoop() error {
case <-fsm.t.Dying():
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Debug("stop connect loop")
ticker.Stop()
return nil
@@ -291,14 +292,14 @@ func (h *FSMHandler) idle() bgp.FSMState {
conn.Close()
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Warn("Closed an accepted connection")
case <-idleHoldTimer.C:
if fsm.adminState == ADMIN_STATE_UP {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Duration": fsm.idleHoldTime,
}).Debug("IdleHoldTimer expired")
fsm.idleHoldTime = HOLDTIME_IDLE
@@ -350,7 +351,7 @@ func (h *FSMHandler) active() bgp.FSMState {
case ADMIN_STATE_UP:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"State": fsm.state,
"AdminState": s.String(),
}).Panic("code logic bug")
@@ -360,27 +361,27 @@ func (h *FSMHandler) active() bgp.FSMState {
}
}
-func capabilitiesFromConfig(global *config.Global, peerConf *config.Neighbor) []bgp.ParameterCapabilityInterface {
+func capabilitiesFromConfig(gConf *config.Global, pConf *config.Neighbor) []bgp.ParameterCapabilityInterface {
caps := make([]bgp.ParameterCapabilityInterface, 0, 4)
caps = append(caps, bgp.NewCapRouteRefresh())
- for _, rf := range peerConf.AfiSafiList {
+ for _, rf := range pConf.AfiSafis.AfiSafiList {
k, _ := bgp.GetRouteFamily(rf.AfiSafiName)
afi, safi := bgp.RouteFamilyToAfiSafi(k)
caps = append(caps, bgp.NewCapMultiProtocol(afi, safi))
}
- caps = append(caps, bgp.NewCapFourOctetASNumber(global.As))
+ caps = append(caps, bgp.NewCapFourOctetASNumber(gConf.GlobalConfig.As))
return caps
}
-func buildopen(global *config.Global, peerConf *config.Neighbor) *bgp.BGPMessage {
- caps := capabilitiesFromConfig(global, peerConf)
+func buildopen(gConf *config.Global, pConf *config.Neighbor) *bgp.BGPMessage {
+ caps := capabilitiesFromConfig(gConf, pConf)
opt := bgp.NewOptionParameterCapability(caps)
- holdTime := uint16(peerConf.Timers.HoldTime)
- as := global.As
+ holdTime := uint16(pConf.Timers.TimersConfig.HoldTime)
+ as := gConf.GlobalConfig.As
if as > (1<<16)-1 {
as = bgp.AS_TRANS
}
- return bgp.NewBGPOpenMessage(uint16(as), holdTime, global.RouterId.String(),
+ return bgp.NewBGPOpenMessage(uint16(as), holdTime, gConf.GlobalConfig.RouterId.String(),
[]bgp.OptionParameterInterface{opt})
}
@@ -406,12 +407,12 @@ func (h *FSMHandler) recvMessageWithError() error {
h.fsm.bgpMessageStateUpdate(0, true)
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": h.fsm.peerConfig.NeighborAddress,
+ "Key": h.fsm.pConf.NeighborConfig.NeighborAddress,
"error": err,
}).Warn("malformed BGP Header")
h.msgCh <- &fsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: h.fsm.peerConfig.NeighborAddress.String(),
+ MsgSrc: h.fsm.pConf.NeighborConfig.NeighborAddress.String(),
MsgData: err,
}
return err
@@ -434,18 +435,18 @@ func (h *FSMHandler) recvMessageWithError() error {
if err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": h.fsm.peerConfig.NeighborAddress,
+ "Key": h.fsm.pConf.NeighborConfig.NeighborAddress,
"error": err,
}).Warn("malformed BGP message")
fmsg = &fsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: h.fsm.peerConfig.NeighborAddress.String(),
+ MsgSrc: h.fsm.pConf.NeighborConfig.NeighborAddress.String(),
MsgData: err,
}
} else {
fmsg = &fsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: h.fsm.peerConfig.NeighborAddress.String(),
+ MsgSrc: h.fsm.pConf.NeighborConfig.NeighborAddress.String(),
MsgData: m,
}
if h.fsm.state == bgp.BGP_FSM_ESTABLISHED {
@@ -472,7 +473,7 @@ func (h *FSMHandler) recvMessage() error {
func (h *FSMHandler) opensent() bgp.FSMState {
fsm := h.fsm
- m := buildopen(fsm.globalConfig, fsm.peerConfig)
+ m := buildopen(fsm.gConf, fsm.pConf)
b, _ := m.Serialize()
fsm.conn.Write(b)
fsm.bgpMessageStateUpdate(m.Header.Type, false)
@@ -500,7 +501,7 @@ func (h *FSMHandler) opensent() bgp.FSMState {
conn.Close()
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Warn("Closed an accepted connection")
case e := <-h.msgCh:
switch e.MsgData.(type) {
@@ -508,7 +509,7 @@ func (h *FSMHandler) opensent() bgp.FSMState {
m := e.MsgData.(*bgp.BGPMessage)
if m.Header.Type == bgp.BGP_MSG_OPEN {
body := m.Body.(*bgp.BGPOpen)
- err := bgp.ValidateOpenMsg(body, fsm.peerConfig.PeerAs)
+ err := bgp.ValidateOpenMsg(body, fsm.pConf.NeighborConfig.PeerAs)
if err != nil {
fsm.sendNotificatonFromErrorMsg(h.conn, err.(*bgp.MessageError))
return bgp.BGP_FSM_IDLE
@@ -516,7 +517,7 @@ func (h *FSMHandler) opensent() bgp.FSMState {
e := &fsmMsg{
MsgType: FSM_MSG_BGP_MESSAGE,
- MsgSrc: fsm.peerConfig.NeighborAddress.String(),
+ MsgSrc: fsm.pConf.NeighborConfig.NeighborAddress.String(),
MsgData: m,
}
h.incoming <- e
@@ -536,7 +537,7 @@ func (h *FSMHandler) opensent() bgp.FSMState {
default:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Data": e.MsgData,
}).Panic("unknonw msg type")
}
@@ -557,7 +558,7 @@ func (h *FSMHandler) opensent() bgp.FSMState {
case ADMIN_STATE_UP:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"State": fsm.state,
"AdminState": s.String(),
}).Panic("code logic bug")
@@ -571,8 +572,8 @@ func keepaliveTicker(fsm *FSM) *time.Ticker {
if fsm.negotiatedHoldTime == 0 {
return &time.Ticker{}
}
- sec := time.Second * time.Duration(fsm.peerConfig.Timers.KeepaliveInterval)
- if fsm.negotiatedHoldTime < fsm.peerConfig.Timers.HoldTime {
+ sec := time.Second * time.Duration(fsm.pConf.Timers.TimersConfig.KeepaliveInterval)
+ if fsm.negotiatedHoldTime < fsm.pConf.Timers.TimersConfig.HoldTime {
sec = time.Second * time.Duration(fsm.negotiatedHoldTime) / 3
}
if sec == 0 {
@@ -610,7 +611,7 @@ func (h *FSMHandler) openconfirm() bgp.FSMState {
conn.Close()
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Warn("Closed an accepted connection")
case <-ticker.C:
m := bgp.NewBGPKeepAliveMessage()
@@ -636,7 +637,7 @@ func (h *FSMHandler) openconfirm() bgp.FSMState {
default:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Data": e.MsgData,
}).Panic("unknonw msg type")
}
@@ -657,7 +658,7 @@ func (h *FSMHandler) openconfirm() bgp.FSMState {
case ADMIN_STATE_UP:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"State": fsm.state,
"AdminState": s.String(),
}).Panic("code logic bug")
@@ -667,7 +668,7 @@ func (h *FSMHandler) openconfirm() bgp.FSMState {
}
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Panic("code logic bug")
return 0
}
@@ -681,7 +682,7 @@ func (h *FSMHandler) sendMessageloop() error {
if err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Data": err,
}).Warn("failed to serialize")
fsm.bgpMessageStateUpdate(0, false)
@@ -696,7 +697,7 @@ func (h *FSMHandler) sendMessageloop() error {
if err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Data": err,
}).Warn("failed to send")
h.errorCh <- true
@@ -708,7 +709,7 @@ func (h *FSMHandler) sendMessageloop() error {
if m.Header.Type == bgp.BGP_MSG_NOTIFICATION {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Data": m,
}).Warn("sent notification")
@@ -719,7 +720,7 @@ func (h *FSMHandler) sendMessageloop() error {
} else {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"data": m,
}).Debug("sent")
}
@@ -791,7 +792,7 @@ func (h *FSMHandler) established() bgp.FSMState {
conn.Close()
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Warn("Closed an accepted connection")
case <-h.errorCh:
h.conn.Close()
@@ -801,7 +802,7 @@ func (h *FSMHandler) established() bgp.FSMState {
case <-holdTimer.C:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"data": bgp.BGP_FSM_ESTABLISHED,
}).Warn("hold timer expired")
m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_HOLD_TIMER_EXPIRED, 0, nil)
@@ -849,14 +850,14 @@ func (h *FSMHandler) loop() error {
if nextState == bgp.BGP_FSM_ESTABLISHED && oldState == bgp.BGP_FSM_OPENCONFIRM {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
}).Info("Peer Up")
}
if oldState == bgp.BGP_FSM_ESTABLISHED {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"Reason": h.reason,
}).Info("Peer Down")
}
@@ -865,7 +866,7 @@ func (h *FSMHandler) loop() error {
if nextState >= bgp.BGP_FSM_IDLE {
e := &fsmMsg{
MsgType: FSM_MSG_STATE_CHANGE,
- MsgSrc: fsm.peerConfig.NeighborAddress.String(),
+ MsgSrc: fsm.pConf.NeighborConfig.NeighborAddress.String(),
MsgData: nextState,
}
h.incoming <- e
@@ -878,7 +879,7 @@ func (h *FSMHandler) changeAdminState(s AdminState) error {
if fsm.adminState != s {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"AdminState": s.String(),
}).Debug("admin state changed")
@@ -888,14 +889,14 @@ func (h *FSMHandler) changeAdminState(s AdminState) error {
case ADMIN_STATE_UP:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": h.fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"FSMState": fsm.state.String(),
}).Info("Administrative start")
case ADMIN_STATE_DOWN:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": h.fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"FSMState": fsm.state.String(),
}).Info("Administrative shutdown")
}
@@ -903,7 +904,7 @@ func (h *FSMHandler) changeAdminState(s AdminState) error {
} else {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": fsm.peerConfig.NeighborAddress,
+ "Key": fsm.pConf.NeighborConfig.NeighborAddress,
"FSMState": fsm.state.String(),
}).Warn("cannot change to the same state")
diff --git a/server/fsm_test.go b/server/fsm_test.go
index ff758253..498c35b7 100644
--- a/server/fsm_test.go
+++ b/server/fsm_test.go
@@ -189,7 +189,7 @@ func TestFSMHandlerOpenconfirm_HoldTimerExpired(t *testing.T) {
p.fsm.conn = m
// set up keepalive ticker
- p.fsm.peerConfig.Timers.KeepaliveInterval = 1
+ p.fsm.pConf.Timers.TimersConfig.KeepaliveInterval = 1
// set holdtime
p.fsm.negotiatedHoldTime = 2
@@ -226,7 +226,7 @@ func TestFSMHandlerEstablish_HoldTimerExpired(t *testing.T) {
}
// set holdtime
- p.fsm.peerConfig.Timers.HoldTime = 2
+ p.fsm.pConf.Timers.TimersConfig.HoldTime = 2
p.fsm.negotiatedHoldTime = 2
go pushPackets()
@@ -250,7 +250,7 @@ func TestFSMHandlerOpenconfirm_HoldtimeZero(t *testing.T) {
p.fsm.conn = m
// set up keepalive ticker
- p.fsm.peerConfig.Timers.KeepaliveInterval = 1
+ p.fsm.pConf.Timers.TimersConfig.KeepaliveInterval = 1
// set holdtime
p.fsm.negotiatedHoldTime = 0
go h.openconfirm()
@@ -284,16 +284,16 @@ func TestFSMHandlerEstablished_HoldtimeZero(t *testing.T) {
}
func makePeerAndHandler() (*Peer, *FSMHandler) {
- globalConfig := config.Global{}
- neighborConfig := config.Neighbor{}
+ gConf := config.Global{}
+ pConf := config.Neighbor{}
p := &Peer{
- globalConfig: globalConfig,
- config: neighborConfig,
- capMap: make(map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface),
+ gConf: gConf,
+ conf: pConf,
+ capMap: make(map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface),
}
- p.fsm = NewFSM(&globalConfig, &neighborConfig)
+ p.fsm = NewFSM(&gConf, &pConf)
incoming := make(chan *fsmMsg, 4096)
p.outgoing = make(chan *bgp.BGPMessage, 4096)
diff --git a/server/peer.go b/server/peer.go
index fd41563a..11c71221 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -33,8 +33,8 @@ const (
)
type Peer struct {
- globalConfig config.Global
- config config.Neighbor
+ gConf config.Global
+ conf config.Neighbor
fsm *FSM
rfMap map[bgp.RouteFamily]bool
capMap map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface
@@ -47,32 +47,32 @@ type Peer struct {
isEBGP bool
}
-func NewPeer(g config.Global, config config.Neighbor) *Peer {
+func NewPeer(g config.Global, conf config.Neighbor) *Peer {
peer := &Peer{
- globalConfig: g,
- config: config,
- rfMap: make(map[bgp.RouteFamily]bool),
- capMap: make(map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface),
+ gConf: g,
+ conf: conf,
+ rfMap: make(map[bgp.RouteFamily]bool),
+ capMap: make(map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface),
}
- config.BgpNeighborCommonState.State = uint32(bgp.BGP_FSM_IDLE)
- config.BgpNeighborCommonState.Downtime = time.Now().Unix()
- for _, rf := range config.AfiSafiList {
+ conf.NeighborState.SessionState = uint32(bgp.BGP_FSM_IDLE)
+ conf.Timers.TimersState.Downtime = time.Now().Unix()
+ for _, rf := range conf.AfiSafis.AfiSafiList {
k, _ := bgp.GetRouteFamily(rf.AfiSafiName)
peer.rfMap[k] = true
}
peer.peerInfo = &table.PeerInfo{
- AS: config.PeerAs,
- LocalID: g.RouterId,
- Address: config.NeighborAddress,
+ AS: conf.NeighborConfig.PeerAs,
+ LocalID: g.GlobalConfig.RouterId,
+ Address: conf.NeighborConfig.NeighborAddress,
}
peer.adjRib = table.NewAdjRib(peer.configuredRFlist())
- peer.fsm = NewFSM(&g, &config)
+ peer.fsm = NewFSM(&g, &conf)
- if config.PeerAs != g.As {
+ if conf.NeighborConfig.PeerAs != g.GlobalConfig.As {
peer.isEBGP = true
- for _, member := range g.Confederation.MemberAs {
- if member == config.PeerAs {
+ for _, member := range g.Confederation.ConfederationConfig.MemberAs {
+ if member == conf.NeighborConfig.PeerAs {
peer.isConfederationMember = true
break
}
@@ -83,12 +83,12 @@ func NewPeer(g config.Global, config config.Neighbor) *Peer {
}
func (peer *Peer) isRouteServerClient() bool {
- return peer.config.RouteServer.RouteServerClient
+ return peer.conf.RouteServer.RouteServerClient
}
func (peer *Peer) configuredRFlist() []bgp.RouteFamily {
rfList := []bgp.RouteFamily{}
- for _, rf := range peer.config.AfiSafiList {
+ for _, rf := range peer.conf.AfiSafis.AfiSafiList {
k, _ := bgp.GetRouteFamily(rf.AfiSafiName)
rfList = append(rfList, k)
}
@@ -100,7 +100,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b
pathList := []*table.Path{}
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"data": m,
}).Debug("received")
update := false
@@ -140,7 +140,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b
// by using the smaller of its configured Hold Time and the Hold Time
// received in the OPEN message.
holdTime := float64(body.HoldTime)
- myHoldTime := peer.config.Timers.HoldTime
+ myHoldTime := peer.conf.Timers.TimersConfig.HoldTime
if holdTime > myHoldTime {
peer.fsm.negotiatedHoldTime = myHoldTime
} else {
@@ -153,7 +153,7 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b
if _, ok := peer.rfMap[rf]; !ok {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": rf,
}).Warn("Route family isn't supported")
break
@@ -163,20 +163,20 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b
} else {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
}).Warn("ROUTE_REFRESH received but the capability wasn't advertised")
}
case bgp.BGP_MSG_UPDATE:
update = true
- peer.config.BgpNeighborCommonState.UpdateRecvTime = time.Now().Unix()
+ peer.conf.Timers.TimersState.UpdateRecvTime = time.Now().Unix()
body := m.Body.(*bgp.BGPUpdate)
confedCheckRequired := !peer.isConfederationMember && peer.isEBGP
_, err := bgp.ValidateUpdateMsg(body, peer.rfMap, confedCheckRequired)
if err != nil {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"error": err,
}).Warn("malformed BGP update message")
m := err.(*bgp.MessageError)
@@ -207,7 +207,7 @@ func (peer *Peer) startFSMHandler(incoming chan *fsmMsg) {
}
func (peer *Peer) PassConn(conn *net.TCPConn) {
- isEBGP := peer.globalConfig.As != peer.config.PeerAs
+ isEBGP := peer.gConf.GlobalConfig.As != peer.conf.NeighborConfig.PeerAs
if isEBGP {
ttl := 1
SetTcpTTLSockopts(conn, ttl)
@@ -218,7 +218,7 @@ func (peer *Peer) PassConn(conn *net.TCPConn) {
conn.Close()
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
}).Warn("accepted conn is closed to avoid be blocked")
}
}
@@ -230,38 +230,39 @@ func (peer *Peer) MarshalJSON() ([]byte, error) {
func (peer *Peer) ToApiStruct() *api.Peer {
f := peer.fsm
- c := f.peerConfig
+ c := f.pConf
remoteCap := make([]*api.Capability, 0, len(peer.capMap))
for _, c := range peer.capMap {
remoteCap = append(remoteCap, c.ToApiStruct())
}
- caps := capabilitiesFromConfig(&peer.globalConfig, &peer.config)
+ caps := capabilitiesFromConfig(&peer.gConf, &peer.conf)
localCap := make([]*api.Capability, 0, len(caps))
for _, c := range caps {
localCap = append(localCap, c.ToApiStruct())
}
conf := &api.PeerConf{
- RemoteIp: c.NeighborAddress.String(),
+ RemoteIp: c.NeighborConfig.NeighborAddress.String(),
Id: peer.peerInfo.ID.To4().String(),
- RemoteAs: c.PeerAs,
+ RemoteAs: c.NeighborConfig.PeerAs,
RemoteCap: remoteCap,
LocalCap: localCap,
- KeepaliveInterval: uint32(peer.config.Timers.KeepaliveInterval),
- Holdtime: uint32(peer.config.Timers.HoldTime),
+ KeepaliveInterval: uint32(peer.conf.Timers.TimersConfig.KeepaliveInterval),
+ Holdtime: uint32(peer.conf.Timers.TimersConfig.HoldTime),
}
- s := c.BgpNeighborCommonState
+ s := &c.NeighborState
+ timer := &c.Timers
uptime := int64(0)
- if s.Uptime != 0 {
- uptime = int64(time.Now().Sub(time.Unix(s.Uptime, 0)).Seconds())
+ if timer.TimersState.Uptime != 0 {
+ uptime = int64(time.Now().Sub(time.Unix(timer.TimersState.Uptime, 0)).Seconds())
}
downtime := int64(0)
- if s.Downtime != 0 {
- downtime = int64(time.Now().Sub(time.Unix(s.Downtime, 0)).Seconds())
+ if timer.TimersState.Downtime != 0 {
+ downtime = int64(time.Now().Sub(time.Unix(timer.TimersState.Downtime, 0)).Seconds())
}
advertized := uint32(0)
@@ -277,10 +278,10 @@ func (peer *Peer) ToApiStruct() *api.Peer {
keepalive := uint32(0)
if f.negotiatedHoldTime != 0 {
- if f.negotiatedHoldTime < c.Timers.HoldTime {
+ if f.negotiatedHoldTime < timer.TimersConfig.HoldTime {
keepalive = uint32(f.negotiatedHoldTime / 3)
} else {
- keepalive = uint32(c.Timers.KeepaliveInterval)
+ keepalive = uint32(timer.TimersConfig.KeepaliveInterval)
}
}
@@ -288,20 +289,20 @@ func (peer *Peer) ToApiStruct() *api.Peer {
BgpState: f.state.String(),
AdminState: f.adminState.String(),
FsmEstablishedTransitions: s.EstablishedCount,
- TotalMessageOut: s.TotalOut,
- TotalMessageIn: s.TotalIn,
- UpdateMessageOut: s.UpdateOut,
- UpdateMessageIn: s.UpdateIn,
- KeepAliveMessageOut: s.KeepaliveOut,
- KeepAliveMessageIn: s.KeepaliveIn,
- OpenMessageOut: s.OpenOut,
- OpenMessageIn: s.OpenIn,
- NotificationOut: s.NotifyOut,
- NotificationIn: s.NotifyIn,
- RefreshMessageOut: s.RefreshOut,
- RefreshMessageIn: s.RefreshIn,
- DiscardedOut: s.DiscardedOut,
- DiscardedIn: s.DiscardedIn,
+ TotalMessageOut: s.Messages.Sent.Total,
+ TotalMessageIn: s.Messages.Received.Total,
+ UpdateMessageOut: s.Messages.Sent.Update,
+ UpdateMessageIn: s.Messages.Received.Update,
+ KeepAliveMessageOut: s.Messages.Sent.Keepalive,
+ KeepAliveMessageIn: s.Messages.Received.Keepalive,
+ OpenMessageOut: s.Messages.Sent.Open,
+ OpenMessageIn: s.Messages.Received.Open,
+ NotificationOut: s.Messages.Sent.Notification,
+ NotificationIn: s.Messages.Received.Notification,
+ RefreshMessageOut: s.Messages.Sent.Refresh,
+ RefreshMessageIn: s.Messages.Received.Refresh,
+ DiscardedOut: s.Messages.Sent.Discarded,
+ DiscardedIn: s.Messages.Received.Discarded,
Uptime: uptime,
Downtime: downtime,
Received: received,
@@ -321,12 +322,12 @@ func (peer *Peer) ToApiStruct() *api.Peer {
func (peer *Peer) setDistributePolicy(policyMap map[string]*policy.Policy) {
// configure distribute policy
- policyConfig := peer.config.ApplyPolicy
+ policyConf := peer.conf.ApplyPolicy
distPolicies := make([]*policy.Policy, 0)
- for _, policyName := range policyConfig.DistributePolicies {
+ for _, policyName := range policyConf.ApplyPolicyConfig.DistributePolicy {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"PolicyName": policyName,
}).Info("distribute policy installed")
if pol, ok := policyMap[policyName]; ok {
@@ -335,15 +336,14 @@ func (peer *Peer) setDistributePolicy(policyMap map[string]*policy.Policy) {
}
}
peer.distPolicies = distPolicies
- peer.defaultDistributePolicy = policyConfig.DefaultDistributePolicy
-
+ peer.defaultDistributePolicy = policyConf.ApplyPolicyConfig.DefaultDistributePolicy
}
func (peer *Peer) applyDistributePolicies(original *table.Path) (bool, *table.Path) {
policies := peer.distPolicies
var d Direction = POLICY_DIRECTION_DISTRIBUTE
- return applyPolicy("Peer", peer.config.NeighborAddress.String(), d, policies, original)
+ return applyPolicy("Peer", peer.conf.NeighborConfig.NeighborAddress.String(), d, policies, original)
}
type LocalRib struct {
@@ -370,12 +370,12 @@ func (loc *LocalRib) isGlobal() bool {
func (loc *LocalRib) setPolicy(peer *Peer, policyMap map[string]*policy.Policy) {
// configure import policy
- policyConfig := peer.config.ApplyPolicy
+ policyConf := peer.conf.ApplyPolicy
inPolicies := make([]*policy.Policy, 0)
- for _, policyName := range policyConfig.ImportPolicies {
+ for _, policyName := range policyConf.ApplyPolicyConfig.ImportPolicy {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"PolicyName": policyName,
}).Info("import policy installed")
if pol, ok := policyMap[policyName]; ok {
@@ -384,14 +384,14 @@ func (loc *LocalRib) setPolicy(peer *Peer, policyMap map[string]*policy.Policy)
}
}
loc.importPolicies = inPolicies
- loc.defaultImportPolicy = policyConfig.DefaultImportPolicy
+ loc.defaultImportPolicy = policyConf.ApplyPolicyConfig.DefaultImportPolicy
// configure export policy
outPolicies := make([]*policy.Policy, 0)
- for _, policyName := range policyConfig.ExportPolicies {
+ for _, policyName := range policyConf.ApplyPolicyConfig.ExportPolicy {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"PolicyName": policyName,
}).Info("export policy installed")
if pol, ok := policyMap[policyName]; ok {
@@ -400,7 +400,7 @@ func (loc *LocalRib) setPolicy(peer *Peer, policyMap map[string]*policy.Policy)
}
}
loc.exportPolicies = outPolicies
- loc.defaultExportPolicy = policyConfig.DefaultExportPolicy
+ loc.defaultExportPolicy = policyConf.ApplyPolicyConfig.DefaultExportPolicy
}
// apply policies to the path
diff --git a/server/server.go b/server/server.go
index 0b958af9..d45e7bff 100644
--- a/server/server.go
+++ b/server/server.go
@@ -173,7 +173,7 @@ func (server *BgpServer) Serve() {
rfList = append(rfList, k)
}
return rfList
- }(g.AfiSafiList)
+ }(g.AfiSafis.AfiSafiList)
server.addLocalRib(NewLocalRib(GLOBAL_RIB_NAME, rfList, make(map[string]*policy.Policy)))
@@ -235,17 +235,17 @@ func (server *BgpServer) Serve() {
conn.Close()
}
case config := <-server.addedPeerCh:
- addr := config.NeighborAddress.String()
+ addr := config.NeighborConfig.NeighborAddress.String()
_, found := server.neighborMap[addr]
if found {
log.Warn("Can't overwrite the exising peer ", addr)
continue
}
- SetTcpMD5SigSockopts(listener(config.NeighborAddress), addr, config.AuthPassword)
+ SetTcpMD5SigSockopts(listener(config.NeighborConfig.NeighborAddress), addr, config.NeighborConfig.AuthPassword)
peer := NewPeer(g, config)
- name := config.NeighborAddress.String()
+ name := config.NeighborConfig.NeighborAddress.String()
if config.RouteServer.RouteServerClient == true {
loc := NewLocalRib(name, peer.configuredRFlist(), make(map[string]*policy.Policy))
@@ -273,8 +273,8 @@ func (server *BgpServer) Serve() {
peer.startFSMHandler(incoming)
server.broadcastPeerState(peer)
case config := <-server.deletedPeerCh:
- addr := config.NeighborAddress.String()
- SetTcpMD5SigSockopts(listener(config.NeighborAddress), addr, "")
+ addr := config.NeighborConfig.NeighborAddress.String()
+ SetTcpMD5SigSockopts(listener(config.NeighborConfig.NeighborAddress), addr, "")
peer, found := server.neighborMap[addr]
if found {
log.Info("Delete a peer configuration for ", addr)
@@ -348,7 +348,7 @@ func newSenderMsg(peer *Peer, messages []*bgp.BGPMessage) *SenderMsg {
return &SenderMsg{
messages: messages,
sendCh: peer.outgoing,
- destination: peer.config.NeighborAddress.String(),
+ destination: peer.conf.NeighborConfig.NeighborAddress.String(),
twoBytesAs: y,
}
}
@@ -363,29 +363,29 @@ func filterpath(peer *Peer, pathList []*table.Path) []*table.Path {
selfGenerated := path.GetSource().ID == nil
fromAS := path.GetSource().AS
- myAS := peer.globalConfig.As
+ myAS := peer.gConf.GlobalConfig.As
if !selfGenerated && !peer.isEBGP && myAS == fromAS {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": path,
}).Debug("From same AS, ignore.")
continue
}
- if peer.config.NeighborAddress.Equal(path.GetSource().Address) {
+ if peer.conf.NeighborConfig.NeighborAddress.Equal(path.GetSource().Address) {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": path,
}).Debug("From me, ignore.")
continue
}
- if peer.config.PeerAs == path.GetSourceAs() {
+ if peer.conf.NeighborConfig.PeerAs == path.GetSourceAs() {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": path,
}).Debug("AS PATH loop, ignore.")
continue
@@ -402,11 +402,11 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg {
if peer.isRouteServerClient() {
for _, loc := range server.localRibMap {
targetPeer := server.neighborMap[loc.OwnerName()]
- if loc.isGlobal() || loc.OwnerName() == peer.config.NeighborAddress.String() {
+ if loc.isGlobal() || loc.OwnerName() == peer.conf.NeighborConfig.NeighborAddress.String() {
continue
}
pathList, _ := loc.rib.DeletePathsforPeer(peer.peerInfo, rf)
- pathList = dropSameAsPath(targetPeer.config.PeerAs, pathList)
+ pathList = dropSameAsPath(targetPeer.conf.NeighborConfig.PeerAs, pathList)
if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || len(pathList) == 0 {
continue
}
@@ -450,7 +450,7 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat
default:
log.WithFields(log.Fields{
"Topic": "Server",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
}).Error("direction is not specified.")
return ret
}
@@ -468,7 +468,7 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat
if path == nil {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": path,
}).Debug("Policy applied and rejected.")
continue
@@ -476,7 +476,7 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat
} else if defaultPolicy != config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": path,
}).Debug("Default policy applied and rejected.")
continue
@@ -532,7 +532,7 @@ func (server *BgpServer) broadcastPeerState(peer *Peer) {
default:
}
ignore := req.RequestType != REQ_MONITOR_NEIGHBOR_PEER_STATE
- ignore = ignore || (req.RemoteAddr != "" && req.RemoteAddr != peer.config.NeighborAddress.String())
+ ignore = ignore || (req.RemoteAddr != "" && req.RemoteAddr != peer.conf.NeighborConfig.NeighborAddress.String())
if ignore {
remainReqs = append(remainReqs, req)
continue
@@ -558,7 +558,8 @@ func (server *BgpServer) propagateUpdate(neighborAddress string, RouteServerClie
if loc.isGlobal() || loc.OwnerName() == neighborAddress {
continue
}
- sendPathList, _ := loc.rib.ProcessPaths(applyPolicies(targetPeer, loc, POLICY_DIRECTION_IMPORT, dropSameAsPath(targetPeer.config.PeerAs, filterpath(targetPeer, newPathList))))
+ sendPathList, _ := loc.rib.ProcessPaths(applyPolicies(targetPeer, loc, POLICY_DIRECTION_IMPORT,
+ dropSameAsPath(targetPeer.conf.NeighborConfig.PeerAs, filterpath(targetPeer, newPathList))))
if targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || len(sendPathList) == 0 {
continue
}
@@ -585,7 +586,7 @@ func (server *BgpServer) propagateUpdate(neighborAddress string, RouteServerClie
}
f := filterpath(targetPeer, sendPathList)
for _, path := range f {
- path.UpdatePathAttrs(&server.bgpConfig.Global, &targetPeer.config)
+ path.UpdatePathAttrs(&server.bgpConfig.Global, &targetPeer.conf)
}
targetPeer.adjRib.UpdateOut(f)
msgList := table.CreateUpdateMsgFromPaths(f)
@@ -601,20 +602,20 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan *
switch e.MsgType {
case FSM_MSG_STATE_CHANGE:
nextState := e.MsgData.(bgp.FSMState)
- oldState := bgp.FSMState(peer.config.BgpNeighborCommonState.State)
+ oldState := bgp.FSMState(peer.conf.NeighborState.SessionState)
go func(t *tomb.Tomb, addr string, oldState, newState bgp.FSMState) {
e := time.AfterFunc(time.Second*30, func() { log.Fatal("failed to free the fsm.h.t for ", addr, oldState, newState) })
t.Wait()
e.Stop()
- }(&peer.fsm.h.t, peer.config.NeighborAddress.String(), oldState, nextState)
- peer.config.BgpNeighborCommonState.State = uint32(nextState)
+ }(&peer.fsm.h.t, peer.conf.NeighborConfig.NeighborAddress.String(), oldState, nextState)
+ peer.conf.NeighborState.SessionState = uint32(nextState)
peer.fsm.StateChange(nextState)
globalRib := server.localRibMap[GLOBAL_RIB_NAME]
if oldState == bgp.BGP_FSM_ESTABLISHED {
t := time.Now()
- if t.Sub(time.Unix(peer.config.BgpNeighborCommonState.Uptime, 0)) < FLOP_THRESHOLD {
- peer.config.BgpNeighborCommonState.Flops++
+ if t.Sub(time.Unix(peer.conf.Timers.TimersState.Uptime, 0)) < FLOP_THRESHOLD {
+ peer.conf.NeighborState.Flops++
}
for _, rf := range peer.configuredRFlist() {
@@ -629,13 +630,13 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan *
if nextState == bgp.BGP_FSM_ESTABLISHED {
pathList := make([]*table.Path, 0)
if peer.isRouteServerClient() {
- loc := server.localRibMap[peer.config.NeighborAddress.String()]
+ loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()]
pathList = applyPolicies(peer, loc, POLICY_DIRECTION_EXPORT, peer.getBests(loc))
} else {
- peer.config.LocalAddress = peer.fsm.LocalAddr()
+ peer.conf.Transport.TransportConfig.LocalAddress = peer.fsm.LocalAddr()
for _, path := range peer.getBests(globalRib) {
p := path.Clone(path.IsWithdraw)
- p.UpdatePathAttrs(&server.bgpConfig.Global, &peer.config)
+ p.UpdatePathAttrs(&server.bgpConfig.Global, &peer.conf)
pathList = append(pathList, p)
}
}
@@ -644,11 +645,12 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan *
msgs = append(msgs, newSenderMsg(peer, table.CreateUpdateMsgFromPaths(pathList)))
}
} else {
- peer.config.BgpNeighborCommonState.Downtime = time.Now().Unix()
+ peer.conf.Timers.TimersState.Downtime = time.Now().Unix()
}
// clear counter
if peer.fsm.adminState == ADMIN_STATE_DOWN {
- peer.config.BgpNeighborCommonState = config.BgpNeighborCommonState{}
+ peer.conf.NeighborState = config.NeighborState{}
+ peer.conf.Timers.TimersState = config.TimersState{}
}
peer.startFSMHandler(incoming)
server.broadcastPeerState(peer)
@@ -670,12 +672,12 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *fsmMsg, incoming chan *
}
break
}
- msgs = append(msgs, server.propagateUpdate(peer.config.NeighborAddress.String(),
+ msgs = append(msgs, server.propagateUpdate(peer.conf.NeighborConfig.NeighborAddress.String(),
peer.isRouteServerClient(), pathList)...)
default:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
"Data": e.MsgData,
}).Panic("unknonw msg type")
}
@@ -702,7 +704,7 @@ func (server *BgpServer) UpdatePolicy(policy config.RoutingPolicy) {
func (server *BgpServer) SetPolicy(pl config.RoutingPolicy) {
pMap := make(map[string]*policy.Policy)
df := pl.DefinedSets
- for _, p := range pl.PolicyDefinitionList {
+ for _, p := range pl.PolicyDefinitions.PolicyDefinitionList {
pMap[p.Name] = policy.NewPolicy(p, df)
}
server.policyMap = pMap
@@ -718,7 +720,7 @@ func (server *BgpServer) handlePolicy(pl config.RoutingPolicy) {
targetPeer := server.neighborMap[loc.OwnerName()]
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": targetPeer.config.NeighborAddress,
+ "Key": targetPeer.conf.NeighborConfig.NeighborAddress,
}).Info("call set policy")
loc.setPolicy(targetPeer, server.policyMap)
// set distribute policy
@@ -994,8 +996,8 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
case REQ_GLOBAL_ADD, REQ_GLOBAL_DELETE:
pi := &table.PeerInfo{
- AS: server.bgpConfig.Global.As,
- LocalID: server.bgpConfig.Global.RouterId,
+ AS: server.bgpConfig.Global.GlobalConfig.As,
+ LocalID: server.bgpConfig.Global.GlobalConfig.RouterId,
}
pathList := handleGlobalRibRequest(grpcReq, pi)
if len(pathList) > 0 {
@@ -1079,7 +1081,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
if err != nil {
break
}
- peer.fsm.idleHoldTime = peer.config.Timers.IdleHoldTimeAfterReset
+ peer.fsm.idleHoldTime = peer.conf.Timers.TimersConfig.IdleHoldTimeAfterReset
m := bgp.NewBGPNotificationMessage(bgp.BGP_ERROR_CEASE, bgp.BGP_ERROR_SUB_ADMINISTRATIVE_RESET, nil)
msgs = append(msgs, newSenderMsg(peer, []*bgp.BGPMessage{m}))
grpcReq.ResponseCh <- &GrpcResponse{}
@@ -1090,9 +1092,8 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
if err != nil {
break
}
- // soft-reconfiguration inbound
pathList := peer.adjRib.GetInPathList(grpcReq.RouteFamily)
- msgs = append(msgs, server.propagateUpdate(peer.config.NeighborAddress.String(),
+ msgs = append(msgs, server.propagateUpdate(peer.conf.NeighborConfig.NeighborAddress.String(),
peer.isRouteServerClient(), pathList)...)
if grpcReq.RequestType == REQ_NEIGHBOR_SOFT_RESET_IN {
@@ -1124,12 +1125,12 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
case peer.fsm.adminStateCh <- ADMIN_STATE_UP:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
}).Debug("ADMIN_STATE_UP requested")
err.Code = api.Error_SUCCESS
err.Msg = "ADMIN_STATE_UP"
default:
- log.Warning("previous request is still remaining. : ", peer.config.NeighborAddress)
+ log.Warning("previous request is still remaining. : ", peer.conf.NeighborConfig.NeighborAddress)
err.Code = api.Error_FAIL
err.Msg = "previous request is still remaining"
}
@@ -1138,12 +1139,12 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
case peer.fsm.adminStateCh <- ADMIN_STATE_DOWN:
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.config.NeighborAddress,
+ "Key": peer.conf.NeighborConfig.NeighborAddress,
}).Debug("ADMIN_STATE_DOWN requested")
err.Code = api.Error_SUCCESS
err.Msg = "ADMIN_STATE_DOWN"
default:
- log.Warning("previous request is still remaining. : ", peer.config.NeighborAddress)
+ log.Warning("previous request is still remaining. : ", peer.conf.NeighborConfig.NeighborAddress)
err.Code = api.Error_FAIL
err.Msg = "previous request is still remaining"
}
@@ -1157,10 +1158,10 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
if err != nil {
break
}
- loc := server.localRibMap[peer.config.NeighborAddress.String()]
+ loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()]
if loc == nil {
result := &GrpcResponse{
- ResponseErr: fmt.Errorf("no local rib for %s", peer.config.NeighborAddress.String()),
+ ResponseErr: fmt.Errorf("no local rib for %s", peer.conf.NeighborConfig.NeighborAddress.String()),
}
grpcReq.ResponseCh <- result
close(grpcReq.ResponseCh)
@@ -1169,7 +1170,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
resInPolicies := []*api.PolicyDefinition{}
resOutPolicies := []*api.PolicyDefinition{}
resDistPolicies := []*api.PolicyDefinition{}
- pdList := server.routingPolicy.PolicyDefinitionList
+ pdList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
df := server.routingPolicy.DefinedSets
extract := func(policyNames []string) []*api.PolicyDefinition {
@@ -1192,15 +1193,15 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
// Add importpolies that has been set in the configuration file to the list.
// However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conInPolicyNames := peer.config.ApplyPolicy.ImportPolicies
+ conInPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ImportPolicy
resInPolicies = extract(conInPolicyNames)
// Add importpolies that has been set in the configuration file to the list.
// However, peer haven't target importpolicy when add PolicyDefinition of name only to the list.
- conOutPolicyNames := peer.config.ApplyPolicy.ExportPolicies
+ conOutPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.ExportPolicy
resOutPolicies = extract(conOutPolicyNames)
- distPolicyNames := peer.config.ApplyPolicy.DistributePolicies
+ distPolicyNames := peer.conf.ApplyPolicy.ApplyPolicyConfig.DistributePolicy
resDistPolicies = extract(distPolicyNames)
defaultInPolicy := policy.ROUTE_REJECT
@@ -1236,42 +1237,42 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
}
reqApplyPolicy := grpcReq.Data.(*api.ApplyPolicy)
reqPolicyMap := server.policyMap
- applyPolicy := &peer.config.ApplyPolicy
+ applyPolicy := &peer.conf.ApplyPolicy.ApplyPolicyConfig
var defInPolicy, defOutPolicy, defDistPolicy config.DefaultPolicyType
if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_IMPORT {
if reqApplyPolicy.DefaultImportPolicy != policy.ROUTE_ACCEPT {
defInPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
}
- peer.config.ApplyPolicy.DefaultImportPolicy = defInPolicy
- applyPolicy.ImportPolicies = policy.PoliciesToString(reqApplyPolicy.ImportPolicies)
+ applyPolicy.DefaultImportPolicy = defInPolicy
+ applyPolicy.ImportPolicy = policy.PoliciesToString(reqApplyPolicy.ImportPolicies)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_EXPORT {
if reqApplyPolicy.DefaultExportPolicy != policy.ROUTE_ACCEPT {
defOutPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
}
- peer.config.ApplyPolicy.DefaultExportPolicy = defOutPolicy
- applyPolicy.ExportPolicies = policy.PoliciesToString(reqApplyPolicy.ExportPolicies)
+ applyPolicy.DefaultExportPolicy = defOutPolicy
+ applyPolicy.ExportPolicy = policy.PoliciesToString(reqApplyPolicy.ExportPolicies)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE {
if reqApplyPolicy.DefaultDistributePolicy != policy.ROUTE_ACCEPT {
defDistPolicy = config.DEFAULT_POLICY_TYPE_REJECT_ROUTE
}
- peer.config.ApplyPolicy.DefaultDistributePolicy = defDistPolicy
- applyPolicy.DistributePolicies = policy.PoliciesToString(reqApplyPolicy.DistributePolicies)
+ applyPolicy.DefaultDistributePolicy = defDistPolicy
+ applyPolicy.DistributePolicy = policy.PoliciesToString(reqApplyPolicy.DistributePolicies)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_IMPORT {
- peer.config.ApplyPolicy.DefaultImportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
- peer.config.ApplyPolicy.ImportPolicies = make([]string, 0)
+ applyPolicy.DefaultImportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
+ applyPolicy.ImportPolicy = make([]string, 0)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_EXPORT {
- peer.config.ApplyPolicy.DefaultExportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
- peer.config.ApplyPolicy.ExportPolicies = make([]string, 0)
+ applyPolicy.DefaultExportPolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
+ applyPolicy.ExportPolicy = make([]string, 0)
} else if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE {
- peer.config.ApplyPolicy.DefaultDistributePolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
- peer.config.ApplyPolicy.DistributePolicies = make([]string, 0)
+ applyPolicy.DefaultDistributePolicy = config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE
+ applyPolicy.DistributePolicy = make([]string, 0)
}
if grpcReq.RequestType == REQ_NEIGHBOR_POLICY_ADD_DISTRIBUTE ||
grpcReq.RequestType == REQ_NEIGHBOR_POLICY_DEL_DISTRIBUTE {
peer.setDistributePolicy(reqPolicyMap)
} else {
- loc := server.localRibMap[peer.config.NeighborAddress.String()]
+ loc := server.localRibMap[peer.conf.NeighborConfig.NeighborAddress.String()]
loc.setPolicy(peer, reqPolicyMap)
}
@@ -1314,7 +1315,7 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
result := &GrpcResponse{}
switch grpcReq.RequestType {
case REQ_POLICY_PREFIXES:
- info := server.routingPolicy.DefinedSets.PrefixSetList
+ info := server.routingPolicy.DefinedSets.PrefixSets.PrefixSetList
if len(info) > 0 {
for _, ps := range info {
resPrefixSet := policy.PrefixSetToApiStruct(ps)
@@ -1330,7 +1331,7 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
grpcReq.ResponseCh <- result
}
case REQ_POLICY_NEIGHBORS:
- info := server.routingPolicy.DefinedSets.NeighborSetList
+ info := server.routingPolicy.DefinedSets.NeighborSets.NeighborSetList
if len(info) > 0 {
for _, ns := range info {
resNeighborSet := policy.NeighborSetToApiStruct(ns)
@@ -1346,7 +1347,7 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
grpcReq.ResponseCh <- result
}
case REQ_POLICY_ASPATHS:
- info := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSets.AsPathSetList
if len(info) > 0 {
for _, as := range info {
resAsPathSet := policy.AsPathSetToApiStruct(as)
@@ -1362,7 +1363,7 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
grpcReq.ResponseCh <- result
}
case REQ_POLICY_COMMUNITIES:
- info := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySetList
if len(info) > 0 {
for _, cs := range info {
resCommunitySet := policy.CommunitySetToApiStruct(cs)
@@ -1378,7 +1379,7 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
grpcReq.ResponseCh <- result
}
case REQ_POLICY_EXTCOMMUNITIES:
- info := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList
if len(info) > 0 {
for _, es := range info {
resExtcommunitySet := policy.ExtCommunitySetToApiStruct(es)
@@ -1394,7 +1395,7 @@ func (server *BgpServer) handleGrpcShowPolicies(grpcReq *GrpcRequest) {
grpcReq.ResponseCh <- result
}
case REQ_POLICY_ROUTEPOLICIES:
- info := server.routingPolicy.PolicyDefinitionList
+ info := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
df := server.routingPolicy.DefinedSets
result := &GrpcResponse{}
if len(info) > 0 {
@@ -1417,7 +1418,7 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
result := &GrpcResponse{}
switch grpcReq.RequestType {
case REQ_POLICY_PREFIX:
- info := server.routingPolicy.DefinedSets.PrefixSetList
+ info := server.routingPolicy.DefinedSets.PrefixSets.PrefixSetList
resPrefixSet := &api.PrefixSet{}
for _, ps := range info {
if ps.PrefixSetName == name {
@@ -1435,7 +1436,7 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("policy prefix that has %v doesn't exist.", name)
}
case REQ_POLICY_NEIGHBOR:
- info := server.routingPolicy.DefinedSets.NeighborSetList
+ info := server.routingPolicy.DefinedSets.NeighborSets.NeighborSetList
resNeighborSet := &api.NeighborSet{}
for _, ns := range info {
if ns.NeighborSetName == name {
@@ -1453,7 +1454,7 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("policy neighbor that has %v doesn't exist.", name)
}
case REQ_POLICY_ASPATH:
- info := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSets.AsPathSetList
resAsPathSet := &api.AsPathSet{}
for _, as := range info {
if as.AsPathSetName == name {
@@ -1471,7 +1472,7 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("policy aspath that has %v doesn't exist.", name)
}
case REQ_POLICY_COMMUNITY:
- info := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySetList
resCommunitySet := &api.CommunitySet{}
for _, cs := range info {
if cs.CommunitySetName == name {
@@ -1489,7 +1490,7 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("policy community that has %v doesn't exist.", name)
}
case REQ_POLICY_EXTCOMMUNITY:
- info := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList
+ info := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList
resExtCommunitySet := &api.ExtCommunitySet{}
for _, es := range info {
if es.ExtCommunitySetName == name {
@@ -1507,7 +1508,7 @@ func (server *BgpServer) handleGrpcShowPolicy(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("policy extended community that has %v doesn't exist.", name)
}
case REQ_POLICY_ROUTEPOLICY:
- info := server.routingPolicy.PolicyDefinitionList
+ info := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
df := server.routingPolicy.DefinedSets
resPolicyDefinition := &api.PolicyDefinition{}
for _, pd := range info {
@@ -1533,7 +1534,7 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
switch grpcReq.RequestType {
case REQ_POLICY_PREFIX_ADD:
reqPrefixSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchPrefixSet
- conPrefixSetList := server.routingPolicy.DefinedSets.PrefixSetList
+ conPrefixSetList := server.routingPolicy.DefinedSets.PrefixSets.PrefixSetList
isReqPrefixSet, prefixSet := policy.PrefixSetToConfigStruct(reqPrefixSet)
if !isReqPrefixSet {
result.ResponseErr = fmt.Errorf("doesn't reqest of policy prefix.")
@@ -1551,10 +1552,10 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
append(conPrefixSetList[idxPrefixSet].PrefixList, prefixSet.PrefixList[0])
}
}
- server.routingPolicy.DefinedSets.PrefixSetList = conPrefixSetList
+ server.routingPolicy.DefinedSets.PrefixSets.PrefixSetList = conPrefixSetList
case REQ_POLICY_NEIGHBOR_ADD:
reqNeighborSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchNeighborSet
- conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSetList
+ conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSets.NeighborSetList
isReqNeighborSet, neighborSet := policy.NeighborSetToConfigStruct(reqNeighborSet)
if !isReqNeighborSet {
result.ResponseErr = fmt.Errorf("doesn't reqest of policy neighbor.")
@@ -1572,10 +1573,10 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
append(conNeighborSetList[idxNeighborSet].NeighborInfoList, neighborSet.NeighborInfoList[0])
}
}
- server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList
+ server.routingPolicy.DefinedSets.NeighborSets.NeighborSetList = conNeighborSetList
case REQ_POLICY_ASPATH_ADD:
reqAsPathSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchAsPathSet
- conAsPathSetList := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ conAsPathSetList := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSets.AsPathSetList
isReqAsPathSet, asPathSet := policy.AsPathSetToConfigStruct(reqAsPathSet)
if !isReqAsPathSet {
result.ResponseErr = fmt.Errorf("doesn't reqest of policy aspath.")
@@ -1589,14 +1590,14 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
conAsPathSetList = append(conAsPathSetList, asPathSet)
} else {
if idxAsPath == -1 {
- conAsPathSetList[idxAsPathSet].AsPathSetMembers =
- append(conAsPathSetList[idxAsPathSet].AsPathSetMembers, asPathSet.AsPathSetMembers[0])
+ conAsPathSetList[idxAsPathSet].AsPathSetMember =
+ append(conAsPathSetList[idxAsPathSet].AsPathSetMember, asPathSet.AsPathSetMember[0])
}
}
- server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList = conAsPathSetList
+ server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSets.AsPathSetList = conAsPathSetList
case REQ_POLICY_COMMUNITY_ADD:
reqCommunitySet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchCommunitySet
- conCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList
+ conCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySetList
isReqCommunitySet, communitySet := policy.CommunitySetToConfigStruct(reqCommunitySet)
if !isReqCommunitySet {
result.ResponseErr = fmt.Errorf("doesn't reqest of policy community.")
@@ -1610,14 +1611,14 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
conCommunitySetList = append(conCommunitySetList, communitySet)
} else {
if idxCommunity == -1 {
- conCommunitySetList[idxCommunitySet].CommunityMembers =
- append(conCommunitySetList[idxCommunitySet].CommunityMembers, communitySet.CommunityMembers[0])
+ conCommunitySetList[idxCommunitySet].CommunityMember =
+ append(conCommunitySetList[idxCommunitySet].CommunityMember, communitySet.CommunityMember[0])
}
}
- server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList = conCommunitySetList
+ server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySetList = conCommunitySetList
case REQ_POLICY_EXTCOMMUNITY_ADD:
reqExtCommunitySet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchExtCommunitySet
- conExtCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList
+ conExtCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList
isReqExtCommunitySet, extCommunitySet := policy.ExtCommunitySetToConfigStruct(reqExtCommunitySet)
if !isReqExtCommunitySet {
result.ResponseErr = fmt.Errorf("doesn't reqest of policy extended community.")
@@ -1631,64 +1632,62 @@ func (server *BgpServer) handleGrpcAddPolicy(grpcReq *GrpcRequest) {
conExtCommunitySetList = append(conExtCommunitySetList, extCommunitySet)
} else {
if idxExtCommunity == -1 {
- conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMembers =
- append(conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMembers, extCommunitySet.ExtCommunityMembers[0])
+ conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMember =
+ append(conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMember, extCommunitySet.ExtCommunityMember[0])
}
}
- server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList = conExtCommunitySetList
+ server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList = conExtCommunitySetList
case REQ_POLICY_ROUTEPOLICY_ADD:
reqPolicy := grpcReq.Data.(*api.PolicyDefinition)
reqConditions := reqPolicy.StatementList[0].Conditions
reqActions := reqPolicy.StatementList[0].Actions
- conPolicyList := server.routingPolicy.PolicyDefinitionList
+ conPolicyList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
_, policyDef := policy.PolicyDefinitionToConfigStruct(reqPolicy)
idxPolicy, idxStatement := policy.IndexOfPolicyDefinition(conPolicyList, policyDef)
if idxPolicy == -1 {
conPolicyList = append(conPolicyList, policyDef)
} else {
- statement := policyDef.StatementList[0]
+ statement := policyDef.Statements.StatementList[0]
if idxStatement == -1 {
- conPolicyList[idxPolicy].StatementList =
- append(conPolicyList[idxPolicy].StatementList, statement)
+ conPolicyList[idxPolicy].Statements.StatementList =
+ append(conPolicyList[idxPolicy].Statements.StatementList, statement)
} else {
- conStatement := &conPolicyList[idxPolicy].StatementList[idxStatement]
+ conConditions := &conPolicyList[idxPolicy].Statements.StatementList[idxStatement].Conditions
+ conActions := &conPolicyList[idxPolicy].Statements.StatementList[idxStatement].Actions
if reqConditions.MatchPrefixSet != nil {
- conStatement.Conditions.MatchPrefixSet = statement.Conditions.MatchPrefixSet
+ conConditions.MatchPrefixSet = statement.Conditions.MatchPrefixSet
}
if reqConditions.MatchNeighborSet != nil {
- conStatement.Conditions.MatchNeighborSet = statement.Conditions.MatchNeighborSet
- }
- if reqConditions.MatchSetOptions != "" {
- conStatement.Conditions.MatchSetOptions = statement.Conditions.MatchSetOptions
+ conConditions.MatchNeighborSet = statement.Conditions.MatchNeighborSet
}
if reqConditions.MatchAsPathSet != nil {
- conStatement.Conditions.BgpConditions.MatchAsPathSet = statement.Conditions.BgpConditions.MatchAsPathSet
+ conConditions.BgpConditions.MatchAsPathSet = statement.Conditions.BgpConditions.MatchAsPathSet
}
if reqConditions.MatchCommunitySet != nil {
- conStatement.Conditions.BgpConditions.MatchCommunitySet = statement.Conditions.BgpConditions.MatchCommunitySet
+ conConditions.BgpConditions.MatchCommunitySet = statement.Conditions.BgpConditions.MatchCommunitySet
}
if reqConditions.MatchExtCommunitySet != nil {
- conStatement.Conditions.BgpConditions.MatchExtCommunitySet = statement.Conditions.BgpConditions.MatchExtCommunitySet
+ conConditions.BgpConditions.MatchExtCommunitySet = statement.Conditions.BgpConditions.MatchExtCommunitySet
}
if reqConditions.MatchAsPathLength != nil {
- conStatement.Conditions.BgpConditions.AsPathLength = statement.Conditions.BgpConditions.AsPathLength
+ conConditions.BgpConditions.AsPathLength = statement.Conditions.BgpConditions.AsPathLength
}
if reqActions.RouteAction != "" {
- conStatement.Actions.AcceptRoute = statement.Actions.AcceptRoute
- conStatement.Actions.RejectRoute = statement.Actions.RejectRoute
+ conActions.RouteDisposition.AcceptRoute = statement.Actions.RouteDisposition.AcceptRoute
+ conActions.RouteDisposition.RejectRoute = statement.Actions.RouteDisposition.RejectRoute
}
if reqActions.Community != nil {
- conStatement.Actions.BgpActions.SetCommunity = statement.Actions.BgpActions.SetCommunity
+ conActions.BgpActions.SetCommunity = statement.Actions.BgpActions.SetCommunity
}
if reqActions.Med != "" {
- conStatement.Actions.BgpActions.SetMed = statement.Actions.BgpActions.SetMed
+ conActions.BgpActions.SetMed = statement.Actions.BgpActions.SetMed
}
if reqActions.AsPrepend != nil {
- conStatement.Actions.BgpActions.SetAsPathPrepend = statement.Actions.BgpActions.SetAsPathPrepend
+ conActions.BgpActions.SetAsPathPrepend = statement.Actions.BgpActions.SetAsPathPrepend
}
}
}
- server.routingPolicy.PolicyDefinitionList = conPolicyList
+ server.routingPolicy.PolicyDefinitions.PolicyDefinitionList = conPolicyList
}
server.handlePolicy(server.routingPolicy)
grpcReq.ResponseCh <- result
@@ -1700,7 +1699,7 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
switch grpcReq.RequestType {
case REQ_POLICY_PREFIX_DELETE:
reqPrefixSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchPrefixSet
- conPrefixSetList := server.routingPolicy.DefinedSets.PrefixSetList
+ conPrefixSetList := server.routingPolicy.DefinedSets.PrefixSets.PrefixSetList
isReqPrefixSet, prefixSet := policy.PrefixSetToConfigStruct(reqPrefixSet)
if isReqPrefixSet {
// If only name of the PrefixSet is same, delete all of the elements of the PrefixSet.
@@ -1708,12 +1707,12 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
idxPrefixSet, idxPrefix := policy.IndexOfPrefixSet(conPrefixSetList, prefixSet)
prefix := prefixSet.PrefixList[0]
if idxPrefixSet == -1 {
- result.ResponseErr = fmt.Errorf("Policy prefix that has %v %v/%v %v doesn't exist.", prefixSet.PrefixSetName,
- prefix.Address, prefix.Masklength, prefix.MasklengthRange)
+ result.ResponseErr = fmt.Errorf("Policy prefix that has %v %v %v doesn't exist.", prefixSet.PrefixSetName,
+ prefix.IpPrefix, prefix.MasklengthRange)
} else {
if idxPrefix == -1 {
- result.ResponseErr = fmt.Errorf("Policy prefix that has %v %v/%v %v doesn't exist.", prefixSet.PrefixSetName,
- prefix.Address, prefix.Masklength, prefix.MasklengthRange)
+ result.ResponseErr = fmt.Errorf("Policy prefix that has %v %v %v doesn't exist.", prefixSet.PrefixSetName,
+ prefix.IpPrefix, prefix.MasklengthRange)
} else {
conPrefixSetList[idxPrefixSet].PrefixList =
append(conPrefixSetList[idxPrefixSet].PrefixList[:idxPrefix], conPrefixSetList[idxPrefixSet].PrefixList[idxPrefix+1:]...)
@@ -1733,10 +1732,10 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
conPrefixSetList = append(conPrefixSetList[:idxPrefixSet], conPrefixSetList[idxPrefixSet+1:]...)
}
}
- server.routingPolicy.DefinedSets.PrefixSetList = conPrefixSetList
+ server.routingPolicy.DefinedSets.PrefixSets.PrefixSetList = conPrefixSetList
case REQ_POLICY_NEIGHBOR_DELETE:
reqNeighborSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchNeighborSet
- conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSetList
+ conNeighborSetList := server.routingPolicy.DefinedSets.NeighborSets.NeighborSetList
isReqNeighborSet, neighborSet := policy.NeighborSetToConfigStruct(reqNeighborSet)
if isReqNeighborSet {
// If only name of the NeighborSet is same, delete all of the elements of the NeighborSet.
@@ -1769,10 +1768,10 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
conNeighborSetList = append(conNeighborSetList[:idxNeighborSet], conNeighborSetList[idxNeighborSet+1:]...)
}
}
- server.routingPolicy.DefinedSets.NeighborSetList = conNeighborSetList
+ server.routingPolicy.DefinedSets.NeighborSets.NeighborSetList = conNeighborSetList
case REQ_POLICY_ASPATH_DELETE:
reqAsPathSet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchAsPathSet
- conAsPathSetList := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList
+ conAsPathSetList := server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSets.AsPathSetList
result := &GrpcResponse{}
isReqAsPathSet, asPathSet := policy.AsPathSetToConfigStruct(reqAsPathSet)
// If only name of the AsPathSet is same, delete all of the elements of the AsPathSet.
@@ -1781,15 +1780,15 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
if isReqAsPathSet {
if idxAsPathSet == -1 {
result.ResponseErr = fmt.Errorf("Policy aspath that has %v %v doesn't exist.", asPathSet.AsPathSetName,
- asPathSet.AsPathSetMembers[0])
+ asPathSet.AsPathSetMember[0])
} else {
if idxAsPath == -1 {
result.ResponseErr = fmt.Errorf("Policy aspath that has %v %v doesn't exist.", asPathSet.AsPathSetName,
- asPathSet.AsPathSetMembers[0])
+ asPathSet.AsPathSetMember[0])
} else {
- conAsPathSetList[idxAsPathSet].AsPathSetMembers =
- append(conAsPathSetList[idxAsPathSet].AsPathSetMembers[:idxAsPath],
- conAsPathSetList[idxAsPathSet].AsPathSetMembers[idxAsPath+1:]...)
+ conAsPathSetList[idxAsPathSet].AsPathSetMember =
+ append(conAsPathSetList[idxAsPathSet].AsPathSetMember[:idxAsPath],
+ conAsPathSetList[idxAsPathSet].AsPathSetMember[idxAsPath+1:]...)
}
}
} else {
@@ -1799,10 +1798,10 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
conAsPathSetList = append(conAsPathSetList[:idxAsPathSet], conAsPathSetList[idxAsPathSet+1:]...)
}
}
- server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList = conAsPathSetList
+ server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSets.AsPathSetList = conAsPathSetList
case REQ_POLICY_COMMUNITY_DELETE:
reqCommunitySet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchCommunitySet
- conCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList
+ conCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySetList
isReqCommunitySet, CommunitySet := policy.CommunitySetToConfigStruct(reqCommunitySet)
// If only name of the CommunitySet is same, delete all of the elements of the CommunitySet.
// If the same element CommunitySet, delete the it's element from CommunitySet.
@@ -1810,15 +1809,15 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
if isReqCommunitySet {
if idxCommunitySet == -1 {
result.ResponseErr = fmt.Errorf("Policy community that has %v %v doesn't exist.", CommunitySet.CommunitySetName,
- CommunitySet.CommunityMembers[0])
+ CommunitySet.CommunityMember[0])
} else {
if idxCommunity == -1 {
result.ResponseErr = fmt.Errorf("Policy community that has %v %v doesn't exist.", CommunitySet.CommunitySetName,
- CommunitySet.CommunityMembers[0])
+ CommunitySet.CommunityMember[0])
} else {
- conCommunitySetList[idxCommunitySet].CommunityMembers =
- append(conCommunitySetList[idxCommunitySet].CommunityMembers[:idxCommunity],
- conCommunitySetList[idxCommunitySet].CommunityMembers[idxCommunity+1:]...)
+ conCommunitySetList[idxCommunitySet].CommunityMember =
+ append(conCommunitySetList[idxCommunitySet].CommunityMember[:idxCommunity],
+ conCommunitySetList[idxCommunitySet].CommunityMember[idxCommunity+1:]...)
}
}
} else {
@@ -1828,10 +1827,10 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
conCommunitySetList = append(conCommunitySetList[:idxCommunitySet], conCommunitySetList[idxCommunitySet+1:]...)
}
}
- server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList = conCommunitySetList
+ server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySets.CommunitySetList = conCommunitySetList
case REQ_POLICY_EXTCOMMUNITY_DELETE:
reqExtCommunitySet := grpcReq.Data.(*api.PolicyDefinition).StatementList[0].Conditions.MatchExtCommunitySet
- conExtCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList
+ conExtCommunitySetList := server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList
isReqExtCommunitySet, ExtCommunitySet := policy.ExtCommunitySetToConfigStruct(reqExtCommunitySet)
// If only name of the ExtCommunitySet is same, delete all of the elements of the ExtCommunitySet.
// If the same element ExtCommunitySet, delete the it's element from ExtCommunitySet.
@@ -1839,15 +1838,15 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
if isReqExtCommunitySet {
if idxExtCommunitySet == -1 {
result.ResponseErr = fmt.Errorf("Policy extended community that has %v %v doesn't exist.",
- ExtCommunitySet.ExtCommunitySetName, ExtCommunitySet.ExtCommunityMembers[0])
+ ExtCommunitySet.ExtCommunitySetName, ExtCommunitySet.ExtCommunityMember[0])
} else {
if idxExtCommunity == -1 {
result.ResponseErr = fmt.Errorf("Policy extended community that has %v %v doesn't exist.",
- ExtCommunitySet.ExtCommunitySetName, ExtCommunitySet.ExtCommunityMembers[0])
+ ExtCommunitySet.ExtCommunitySetName, ExtCommunitySet.ExtCommunityMember[0])
} else {
- conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMembers =
- append(conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMembers[:idxExtCommunity],
- conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMembers[idxExtCommunity+1:]...)
+ conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMember =
+ append(conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMember[:idxExtCommunity],
+ conExtCommunitySetList[idxExtCommunitySet].ExtCommunityMember[idxExtCommunity+1:]...)
}
}
} else {
@@ -1859,10 +1858,10 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
append(conExtCommunitySetList[:idxExtCommunitySet], conExtCommunitySetList[idxExtCommunitySet+1:]...)
}
}
- server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList = conExtCommunitySetList
+ server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList = conExtCommunitySetList
case REQ_POLICY_ROUTEPOLICY_DELETE:
reqPolicy := grpcReq.Data.(*api.PolicyDefinition)
- conPolicyList := server.routingPolicy.PolicyDefinitionList
+ conPolicyList := server.routingPolicy.PolicyDefinitions.PolicyDefinitionList
isStatement, policyDef := policy.PolicyDefinitionToConfigStruct(reqPolicy)
idxPolicy, idxStatement := policy.IndexOfPolicyDefinition(conPolicyList, policyDef)
if isStatement {
@@ -1870,10 +1869,10 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
result.ResponseErr = fmt.Errorf("Policy that has %v doesn't exist.", policyDef.Name)
} else {
if idxStatement == -1 {
- result.ResponseErr = fmt.Errorf("Policy Statment that has %v doesn't exist.", policyDef.StatementList[0].Name)
+ result.ResponseErr = fmt.Errorf("Policy Statment that has %v doesn't exist.", policyDef.Statements.StatementList[0].Name)
} else {
- conPolicyList[idxPolicy].StatementList =
- append(conPolicyList[idxPolicy].StatementList[:idxStatement], conPolicyList[idxPolicy].StatementList[idxStatement+1:]...)
+ conPolicyList[idxPolicy].Statements.StatementList =
+ append(conPolicyList[idxPolicy].Statements.StatementList[:idxStatement], conPolicyList[idxPolicy].Statements.StatementList[idxStatement+1:]...)
}
}
} else {
@@ -1890,7 +1889,7 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
conPolicyList = append(conPolicyList[:idxPolicy], conPolicyList[idxPolicy+1:]...)
}
}
- server.routingPolicy.PolicyDefinitionList = conPolicyList
+ server.routingPolicy.PolicyDefinitions.PolicyDefinitionList = conPolicyList
}
server.handlePolicy(server.routingPolicy)
grpcReq.ResponseCh <- result
@@ -1899,19 +1898,20 @@ func (server *BgpServer) handleGrpcDelPolicy(grpcReq *GrpcRequest) {
func (server *BgpServer) handleGrpcDelPolicies(grpcReq *GrpcRequest) {
result := &GrpcResponse{}
+ definedSets := &server.routingPolicy.DefinedSets
switch grpcReq.RequestType {
case REQ_POLICY_PREFIXES_DELETE:
- server.routingPolicy.DefinedSets.PrefixSetList = make([]config.PrefixSet, 0)
+ definedSets.PrefixSets.PrefixSetList = make([]config.PrefixSet, 0)
case REQ_POLICY_NEIGHBORS_DELETE:
- server.routingPolicy.DefinedSets.NeighborSetList = make([]config.NeighborSet, 0)
+ definedSets.NeighborSets.NeighborSetList = make([]config.NeighborSet, 0)
case REQ_POLICY_ASPATHS_DELETE:
- server.routingPolicy.DefinedSets.BgpDefinedSets.AsPathSetList = make([]config.AsPathSet, 0)
+ definedSets.BgpDefinedSets.AsPathSets.AsPathSetList = make([]config.AsPathSet, 0)
case REQ_POLICY_COMMUNITIES_DELETE:
- server.routingPolicy.DefinedSets.BgpDefinedSets.CommunitySetList = make([]config.CommunitySet, 0)
+ definedSets.BgpDefinedSets.CommunitySets.CommunitySetList = make([]config.CommunitySet, 0)
case REQ_POLICY_EXTCOMMUNITIES_DELETE:
- server.routingPolicy.DefinedSets.BgpDefinedSets.ExtCommunitySetList = make([]config.ExtCommunitySet, 0)
+ definedSets.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList = make([]config.ExtCommunitySet, 0)
case REQ_POLICY_ROUTEPOLICIES_DELETE:
- server.routingPolicy.PolicyDefinitionList = make([]config.PolicyDefinition, 0)
+ server.routingPolicy.PolicyDefinitions.PolicyDefinitionList = make([]config.PolicyDefinition, 0)
}
server.handlePolicy(server.routingPolicy)
grpcReq.ResponseCh <- result
@@ -1988,11 +1988,11 @@ func (server *BgpServer) mkMrtPeerIndexTableMsg(t uint32) (*bgp.MRTMessage, erro
peers := make([]*bgp.Peer, 0, len(server.neighborMap))
for _, peer := range server.neighborMap {
id := peer.peerInfo.ID.To4().String()
- ipaddr := peer.config.NeighborAddress.String()
- asn := peer.config.PeerAs
+ ipaddr := peer.conf.NeighborConfig.NeighborAddress.String()
+ asn := peer.conf.NeighborConfig.PeerAs
peers = append(peers, bgp.NewPeer(id, ipaddr, asn, true))
}
- bgpid := server.bgpConfig.Global.RouterId.To4().String()
+ bgpid := server.bgpConfig.Global.GlobalConfig.RouterId.To4().String()
table := bgp.NewPeerIndexTable(bgpid, "", peers)
return bgp.NewMRTMessage(t, bgp.TABLE_DUMPv2, bgp.PEER_INDEX_TABLE, table)
}
diff --git a/table/path.go b/table/path.go
index 12f7d498..251eefbc 100644
--- a/table/path.go
+++ b/table/path.go
@@ -74,26 +74,27 @@ func (path *Path) UpdatePathAttrs(global *config.Global, peer *config.Neighbor)
return
}
- if peer.PeerType == config.PEER_TYPE_EXTERNAL {
+ localAddress := peer.Transport.TransportConfig.LocalAddress
+ if peer.NeighborConfig.PeerType == config.PEER_TYPE_EXTERNAL {
// NEXTHOP handling
- path.SetNexthop(peer.LocalAddress)
+ path.SetNexthop(localAddress)
// AS_PATH handling
- path.PrependAsn(global.As, 1)
+ path.PrependAsn(global.GlobalConfig.As, 1)
// MED Handling
idx, _ := path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
if idx >= 0 {
path.pathAttrs = append(path.pathAttrs[:idx], path.pathAttrs[idx+1:]...)
}
- } else if peer.PeerType == config.PEER_TYPE_INTERNAL {
+ } else if peer.NeighborConfig.PeerType == config.PEER_TYPE_INTERNAL {
// NEXTHOP handling for iBGP
// if the path generated locally set local address as nexthop.
// if not, don't modify it.
// TODO: NEXT-HOP-SELF support
selfGenerated := path.GetSource().ID == nil
if selfGenerated {
- path.SetNexthop(peer.LocalAddress)
+ path.SetNexthop(localAddress)
}
// AS_PATH handling for iBGP
@@ -117,8 +118,8 @@ func (path *Path) UpdatePathAttrs(global *config.Global, peer *config.Neighbor)
} else {
log.WithFields(log.Fields{
"Topic": "Peer",
- "Key": peer.NeighborAddress,
- }).Warnf("invalid peer type: %d", peer.PeerType)
+ "Key": peer.NeighborConfig.NeighborAddress,
+ }).Warnf("invalid peer type: %d", peer.NeighborConfig.PeerType)
}
}
@@ -373,11 +374,12 @@ func (path *Path) GetCommunities() []uint32 {
}
// SetCommunities adds or replaces communities with new ones.
-// If the length of communites is 0, it does nothing.
+// If the length of communities is 0 and doReplace is true, it clears communities.
func (path *Path) SetCommunities(communities []uint32, doReplace bool) {
- if len(communities) == 0 {
- // do nothing
+ if len(communities) == 0 && doReplace {
+ // clear communities
+ path.ClearCommunities()
return
}
diff --git a/test/scenario_test/gobgp_test.py b/test/scenario_test/gobgp_test.py
index 1333afad..03443777 100644
--- a/test/scenario_test/gobgp_test.py
+++ b/test/scenario_test/gobgp_test.py
@@ -113,9 +113,20 @@ class GoBGPTestBase(unittest.TestCase):
return
self.assertEqual(ans_nexthop, rep_nexthop)
+ def extract_bgp_section(self):
+ with open(self.gobgp_config_file) as f:
+ dst = ''
+ for line in f:
+ if 'DefinedSets' in line:
+ break
+ dst += line
+
+ return dst.encode('utf8')
+
def load_gobgp_config(self):
try:
- self.gobgp_config = toml.loads(open(self.gobgp_config_file).read())
+ t = self.extract_bgp_section()
+ self.gobgp_config = toml.loads(t)
except IOError, (errno, strerror):
print "I/O error(%s): %s" % (errno, strerror)
@@ -169,9 +180,9 @@ class GoBGPTestBase(unittest.TestCase):
# get address of each neighbor from gobpg configration
def get_neighbor_address(self, config):
address = []
- neighbors_config = config['NeighborList']
+ neighbors_config = config['Neighbors']['NeighborList']
for neighbor_config in neighbors_config:
- neighbor_ip = neighbor_config['NeighborAddress']
+ neighbor_ip = neighbor_config['NeighborConfig']['NeighborAddress']
address.append(neighbor_ip)
return address
@@ -266,6 +277,25 @@ class GoBGPTestBase(unittest.TestCase):
print "adj_rib_%s is none" % type
return None
+ # quagga login check
+ def try_login_quagga(self, peer, retry=3, interval=1):
+ print "try login to quagga : %s" % peer
+ if interval < 0:
+ interval = self.wait_per_retry
+ retry_count = 0
+ while True:
+ try:
+ tn = qaccess.login(peer)
+ return tn
+ except:
+ retry_count += 1
+ if retry_count > retry:
+ break
+ print "failed to login to %s" % peer
+ print "wait (" + str(interval) + " seconds)"
+ time.sleep(interval)
+ return None
+
# get route information on quagga
def get_route(self, neighbor_address, target_prefix, retry=3, interval=-1, af=IPv4):
diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py
index 433d779e..4092882a 100644
--- a/test/scenario_test/lib/gobgp.py
+++ b/test/scenario_test/lib/gobgp.py
@@ -108,7 +108,7 @@ class GoBGPContainer(BGPContainer):
return json.loads(output)['info']['bgp_state']
def create_config(self):
- config = {'Global': {'As': self.asn, 'RouterId': self.router_id}}
+ config = {'Global': {'GlobalConfig': {'As': self.asn, 'RouterId': self.router_id}}}
for peer, info in self.peers.iteritems():
if self.asn == peer.asn:
peer_type = self.PEER_TYPE_INTERNAL
@@ -129,14 +129,17 @@ class GoBGPContainer(BGPContainer):
afi_safi_list.append({'AfiSafiName': 'encap'})
afi_safi_list.append({'AfiSafiName': 'rtc'})
- n = {'NeighborAddress': info['neigh_addr'].split('/')[0],
- 'PeerAs': peer.asn,
- 'AuthPassword': info['passwd'],
- 'PeerType': peer_type,
- 'AfiSafiList': afi_safi_list}
+ n = {'NeighborConfig':
+ {'NeighborAddress': info['neigh_addr'].split('/')[0],
+ 'PeerAs': peer.asn,
+ 'AuthPassword': info['passwd'],
+ 'PeerType': peer_type,
+ },
+ 'AfiSafis': {'AfiSafiList': afi_safi_list}
+ }
if info['passive']:
- n['TransportOptions'] = {'PassiveMode': True}
+ n['Transport'] = {'TransportConfig': {'PassiveMode': True}}
if info['is_rs_client']:
n['RouteServer'] = {'RouteServerClient': True}
@@ -146,10 +149,10 @@ class GoBGPContainer(BGPContainer):
n['RouteReflector'] = {'RouteReflectorClient': True,
'RouteReflectorClusterId': clusterId}
- if 'NeighborList' not in config:
- config['NeighborList'] = []
+ if 'Neighbors' not in config:
+ config['Neighbors'] = {'NeighborList': []}
- config['NeighborList'].append(n)
+ config['Neighbors']['NeighborList'].append(n)
with open('{0}/gobgpd.conf'.format(self.config_dir), 'w') as f:
print colors.yellow('[{0}\'s new config]'.format(self.name))
diff --git a/test/scenario_test/policy/policy_generator.go b/test/scenario_test/policy/policy_generator.go
index 5e2308d4..abf0fc0f 100644
--- a/test/scenario_test/policy/policy_generator.go
+++ b/test/scenario_test/policy/policy_generator.go
@@ -21,41 +21,41 @@ func bindPolicy(outputDir, peer, target, policyName string, isReplace bool, defa
log.Fatal(d_err)
}
- for idx, neighbor := range newConf.NeighborList {
+ for idx, neighbor := range newConf.Neighbors.NeighborList {
ip := net.ParseIP(peer)
- if ip.String() == neighbor.NeighborAddress.String() {
- ap := &neighbor.ApplyPolicy
+ if ip.String() == neighbor.NeighborConfig.NeighborAddress.String() {
+ ap := &neighbor.ApplyPolicy.ApplyPolicyConfig
switch target {
case "import":
if isReplace {
- ap.ImportPolicies = []string{policyName}
+ ap.ImportPolicy = []string{policyName}
} else {
- ap.ImportPolicies = append(ap.ImportPolicies, policyName)
+ ap.ImportPolicy = append(ap.ImportPolicy, policyName)
}
if defaultReject {
ap.DefaultImportPolicy = 1
}
case "export":
if isReplace {
- ap.ExportPolicies = []string{policyName}
+ ap.ExportPolicy = []string{policyName}
} else {
- ap.ExportPolicies = append(ap.ExportPolicies, policyName)
+ ap.ExportPolicy = append(ap.ExportPolicy, policyName)
}
if defaultReject {
ap.DefaultExportPolicy = 1
}
case "distribute":
if isReplace {
- ap.DistributePolicies = []string{policyName}
+ ap.DistributePolicy = []string{policyName}
} else {
- ap.DistributePolicies = append(ap.DistributePolicies, policyName)
+ ap.DistributePolicy = append(ap.DistributePolicy, policyName)
}
if defaultReject {
ap.DefaultDistributePolicy = 1
}
}
- newConf.NeighborList[idx] = neighbor
+ newConf.Neighbors.NeighborList[idx] = neighbor
}
}
@@ -73,12 +73,16 @@ func bindPolicy(outputDir, peer, target, policyName string, isReplace bool, defa
func createPolicyConfig() *config.RoutingPolicy {
+ cidr := func(pref string) net.IPNet {
+ _, n, _ := net.ParseCIDR(pref)
+ return *n
+ }
+
ps0 := config.PrefixSet{
PrefixSetName: "ps0",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("192.168.0.0"),
- Masklength: 16,
+ IpPrefix: cidr("192.168.0.0/16"),
MasklengthRange: "16..24",
}},
}
@@ -87,11 +91,9 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "ps1",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("192.168.20.0"),
- Masklength: 24,
+ IpPrefix: cidr("192.168.20.0/24"),
}, config.Prefix{
- Address: net.ParseIP("192.168.200.0"),
- Masklength: 24,
+ IpPrefix: cidr("192.168.200.0/24"),
}},
}
@@ -99,8 +101,7 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "ps2",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("192.168.20.0"),
- Masklength: 24,
+ IpPrefix: cidr("192.168.20.0/24"),
}},
}
@@ -108,8 +109,7 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "ps3",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("2001:0:10:2::"),
- Masklength: 64,
+ IpPrefix: cidr("2001:0:10:2::/64"),
MasklengthRange: "64..128",
}},
}
@@ -118,11 +118,9 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "ps4",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("2001:0:10:20::"),
- Masklength: 64,
+ IpPrefix: cidr("2001:0:10:20::/64"),
}, config.Prefix{
- Address: net.ParseIP("2001:0:10:200::"),
- Masklength: 64,
+ IpPrefix: cidr("2001:0:10:200::/64"),
}},
}
@@ -130,8 +128,7 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "ps5",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("2001:0:10:20::"),
- Masklength: 64,
+ IpPrefix: cidr("2001:0:10:20::/64"),
}},
}
@@ -139,8 +136,7 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "ps6",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("192.168.10.0"),
- Masklength: 24,
+ IpPrefix: cidr("192.168.10.0/24"),
}},
}
@@ -172,771 +168,531 @@ func createPolicyConfig() *config.RoutingPolicy {
PrefixSetName: "psExabgp",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("192.168.100.0"),
- Masklength: 24,
+ IpPrefix: cidr("192.168.100.0/24"),
MasklengthRange: "16..24",
}},
}
aspathFrom := config.AsPathSet{
- AsPathSetName: "aspathFrom",
- AsPathSetMembers: []string{"^65100"},
+ AsPathSetName: "aspathFrom",
+ AsPathSetMember: []string{"^65100"},
}
aspathAny := config.AsPathSet{
- AsPathSetName: "aspAny",
- AsPathSetMembers: []string{"65098"},
+ AsPathSetName: "aspAny",
+ AsPathSetMember: []string{"65098"},
}
aspathOrigin := config.AsPathSet{
- AsPathSetName: "aspOrigin",
- AsPathSetMembers: []string{"65091$"},
+ AsPathSetName: "aspOrigin",
+ AsPathSetMember: []string{"65091$"},
}
aspathOnly := config.AsPathSet{
- AsPathSetName: "aspOnly",
- AsPathSetMembers: []string{"^65100$"},
+ AsPathSetName: "aspOnly",
+ AsPathSetMember: []string{"^65100$"},
}
comStr := config.CommunitySet{
CommunitySetName: "comStr",
- CommunityMembers: []string{"65100:10"},
+ CommunityMember: []string{"65100:10"},
}
comRegExp := config.CommunitySet{
CommunitySetName: "comRegExp",
- CommunityMembers: []string{"6[0-9]+:[0-9]+"},
+ CommunityMember: []string{"6[0-9]+:[0-9]+"},
}
eComOrigin := config.ExtCommunitySet{
ExtCommunitySetName: "eComOrigin",
- ExtCommunityMembers: []string{"SoO:65001.65100:200"},
+ ExtCommunityMember: []string{"SoO:65001.65100:200"},
}
eComTarget := config.ExtCommunitySet{
ExtCommunitySetName: "eComTarget",
- ExtCommunityMembers: []string{"RT:6[0-9]+:3[0-9]+"},
+ ExtCommunityMember: []string{"RT:6[0-9]+:3[0-9]+"},
}
- st0 := config.Statement{
- Name: "st0",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps0",
- MatchNeighborSet: "nsPeer2",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ createStatement := func(name string, ps, ns string, accept bool) config.Statement {
+ st := config.Statement{}
+ st.Name = name
+ st.Actions.RouteDisposition.AcceptRoute = accept
- st1 := config.Statement{
- Name: "st1",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "nsPeer2",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ if ps != "" {
+ st.Conditions.MatchPrefixSet.PrefixSet = ps
+ }
- st2 := config.Statement{
- Name: "st2",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps2",
- MatchNeighborSet: "nsPeer2",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
+ if ns != "" {
+ st.Conditions.MatchNeighborSet.NeighborSet = ns
+ }
- st3 := config.Statement{
- Name: "st3",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps3",
- MatchNeighborSet: "nsPeer2V6",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
+ return st
}
- st4 := config.Statement{
- Name: "st4",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps4",
- MatchNeighborSet: "nsPeer2V6",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st0 := createStatement("st0", "ps0", "nsPeer2", false)
+ st1 := createStatement("st1", "ps1", "nsPeer2", false)
+ st2 := createStatement("st2", "ps2", "nsPeer2", false)
+ st3 := createStatement("st3", "ps3", "nsPeer2V6", false)
+ st4 := createStatement("st4", "ps4", "nsPeer2V6", false)
+ st5 := createStatement("st5", "ps5", "nsPeer2V6", false)
- st5 := config.Statement{
- Name: "st5",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps5",
- MatchNeighborSet: "nsPeer2V6",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
- },
- }
+ st_aspathlen := createStatement("st_aspathlen", "psExabgp", "nsExabgp", false)
+ st_aspathlen.Conditions.BgpConditions.AsPathLength.Operator = "ge"
+ st_aspathlen.Conditions.BgpConditions.AsPathLength.Value = 10
- st_aspathlen := config.Statement{
- Name: "st_aspathlen",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- AsPathLength: config.AsPathLength{
- Operator: "ge",
- Value: 10,
- },
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_aspathFrom := createStatement("st_aspathFrom", "psExabgp", "nsExabgp", false)
+ st_aspathFrom.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspathFrom"
- st_aspathFrom := config.Statement{
- Name: "st_aspathlen",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "aspathFrom",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_aspathAny := createStatement("st_aspathAny", "psExabgp", "nsExabgp", false)
+ st_aspathAny.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspAny"
- st_aspathAny := config.Statement{
- Name: "st_aspathlen",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "aspAny",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_aspathOrigin := createStatement("st_aspathOrigin", "psExabgp", "nsExabgp", false)
+ st_aspathOrigin.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspOrigin"
- st_aspathOrigin := config.Statement{
- Name: "st_aspathlen",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "aspOrigin",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_aspathOnly := createStatement("st_aspathOnly", "psExabgp", "nsExabgp", false)
+ st_aspathOnly.Conditions.BgpConditions.MatchAsPathSet.AsPathSet = "aspOnly"
- st_aspathOnly := config.Statement{
- Name: "st_aspathlen",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchAsPathSet: "aspOnly",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_comStr := createStatement("st_community", "psExabgp", "nsExabgp", false)
+ st_comStr.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
- st_comStr := config.Statement{
- Name: "st_community",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_comRegExp := createStatement("st_community_regexp", "psExabgp", "nsExabgp", false)
+ st_comRegExp.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comRegExp"
- st_comRegExp := config.Statement{
- Name: "st_community_regexp",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comRegExp",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_comAdd := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true)
+ st_comAdd.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
+ st_comAdd.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20"}
+ st_comAdd.Actions.BgpActions.SetCommunity.Options = "ADD"
- st_comAdd := config.Statement{
- Name: "st_community_regexp",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{"65100:20"},
- Options: "ADD",
- },
- },
- },
- }
+ st_comReplace := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true)
+ st_comReplace.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
+ st_comReplace.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20", "65100:30"}
+ st_comReplace.Actions.BgpActions.SetCommunity.Options = "REPLACE"
- st_comReplace := config.Statement{
- Name: "st_community_regexp",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{"65100:20", "65100:30"},
- Options: "REPLACE",
- },
- },
- },
- }
+ st_comRemove := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true)
+ st_comRemove.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
+ st_comRemove.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20", "65100:30"}
+ st_comRemove.Actions.BgpActions.SetCommunity.Options = "REMOVE"
- st_comRemove := config.Statement{
- Name: "st_community_regexp",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{"65100:20", "65100:30"},
- Options: "REMOVE",
- },
- },
- },
- }
+ st_comNull := createStatement("st_community_regexp", "psExabgp", "nsExabgp", true)
+ st_comNull.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
+ st_comNull.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{}
+ //use REPLACE instead of NULL
+ st_comNull.Actions.BgpActions.SetCommunity.Options = "REPLACE"
- st_comNull := config.Statement{
- Name: "st_community_regexp",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{},
- Options: "NULL",
- },
- },
- },
- }
+ st_medReplace := createStatement("st_medReplace", "psExabgp", "nsExabgp", true)
+ st_medReplace.Actions.BgpActions.SetMed = "100"
- st_medReplace := config.Statement{
- Name: "st_medReplace",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: "100",
- },
- },
- }
+ st_medAdd := createStatement("st_medAdd", "psExabgp", "nsExabgp", true)
+ st_medAdd.Actions.BgpActions.SetMed = "+100"
- st_medAdd := config.Statement{
- Name: "st_medAdd",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: "+100",
- },
- },
- }
+ st_medSub := createStatement("st_medSub", "psExabgp", "nsExabgp", true)
+ st_medSub.Actions.BgpActions.SetMed = "-100"
- st_medSub := config.Statement{
- Name: "st_medSub",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: "-100",
- },
- },
- }
+ st_distribute_reject := createStatement("st_community_distriibute", "", "", false)
+ st_distribute_reject.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
- st_distribute_reject := config.Statement{
- Name: "st_community_distriibute",
- Conditions: config.Conditions{
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_distribute_accept := createStatement("st_distriibute_accept", "ps6", "", true)
- st_distribute_accept := config.Statement{
- Name: "st_distriibute_accept",
- Conditions: config.Conditions{
- MatchPrefixSet: "ps6",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- },
- }
+ st_distribute_comm_add := createStatement("st_distribute_comm_add", "", "", true)
+ st_distribute_comm_add.Conditions.BgpConditions.MatchCommunitySet.CommunitySet = "comStr"
+ st_distribute_comm_add.Actions.BgpActions.SetCommunity.SetCommunityMethod.Communities = []string{"65100:20"}
+ st_distribute_comm_add.Actions.BgpActions.SetCommunity.Options = "ADD"
- st_distribute_comm_add := config.Statement{
- Name: "st_distribute_comm_add",
- Conditions: config.Conditions{
- BgpConditions: config.BgpConditions{
- MatchCommunitySet: "comStr",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetCommunity: config.SetCommunity{
- Communities: []string{"65100:20"},
- Options: "ADD",
- },
- },
- },
- }
+ st_distribute_med_add := createStatement("st_distribute_med_add", "psExabgp", "nsExabgp", true)
+ st_distribute_med_add.Actions.BgpActions.SetMed = "+100"
- st_distribute_med_add := config.Statement{
- Name: "st_distribute_med_add",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetMed: "+100",
- },
- },
- }
+ st_asprepend := createStatement("st_asprepend", "psExabgp", "nsExabgp", true)
+ st_asprepend.Actions.BgpActions.SetAsPathPrepend.As = "65005"
+ st_asprepend.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
- st_asprepend := config.Statement{
- Name: "st_asprepend",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetAsPathPrepend: config.SetAsPathPrepend{
- As: "65005",
- RepeatN: 5,
- },
- },
- },
- }
+ st_asprepend_lastas := createStatement("st_asprepend_lastas", "psExabgp", "nsExabgp", true)
+ st_asprepend_lastas.Actions.BgpActions.SetAsPathPrepend.As = "last-as"
+ st_asprepend_lastas.Actions.BgpActions.SetAsPathPrepend.RepeatN = 5
- st_asprepend_lastas := config.Statement{
- Name: "st_asprepend_lastas",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: true,
- BgpActions: config.BgpActions{
- SetAsPathPrepend: config.SetAsPathPrepend{
- As: "last-as",
- RepeatN: 5,
- },
- },
- },
- }
- st_eComOrigin := config.Statement{
- Name: "st_eComAS4",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchExtCommunitySet: "eComOrigin",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
- st_eComTarget := config.Statement{
- Name: "st_eComRegExp",
- Conditions: config.Conditions{
- MatchPrefixSet: "psExabgp",
- MatchNeighborSet: "nsExabgp",
- BgpConditions: config.BgpConditions{
- MatchExtCommunitySet: "eComTarget",
- },
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
- },
- Actions: config.Actions{
- AcceptRoute: false,
- },
- }
+ st_eComOrigin := createStatement("st_eComAS4", "psExabgp", "nsExabgp", false)
+ st_eComOrigin.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = "eComOrigin"
+
+ st_eComTarget := createStatement("st_eComRegExp", "psExabgp", "nsExabgp", false)
+ st_eComTarget.Conditions.BgpConditions.MatchExtCommunitySet.ExtCommunitySet = "eComTarget"
test_01_import_policy_initial := config.PolicyDefinition{
- Name: "test_01_import_policy_initial",
- StatementList: []config.Statement{st0},
+ Name: "test_01_import_policy_initial",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st0},
+ },
}
test_02_export_policy_initial := config.PolicyDefinition{
- Name: "test_02_export_policy_initial",
- StatementList: []config.Statement{st0},
+ Name: "test_02_export_policy_initial",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st0},
+ },
}
test_03_import_policy_update := config.PolicyDefinition{
- Name: "test_03_import_policy_update",
- StatementList: []config.Statement{st1},
+ Name: "test_03_import_policy_update",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st1},
+ },
}
test_03_import_policy_update_softreset := config.PolicyDefinition{
- Name: "test_03_import_policy_update_softreset",
- StatementList: []config.Statement{st2},
+ Name: "test_03_import_policy_update_softreset",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st2},
+ },
}
test_04_export_policy_update := config.PolicyDefinition{
- Name: "test_04_export_policy_update",
- StatementList: []config.Statement{st1},
+ Name: "test_04_export_policy_update",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st1},
+ },
}
test_04_export_policy_update_softreset := config.PolicyDefinition{
- Name: "test_04_export_policy_update_softreset",
- StatementList: []config.Statement{st2},
+ Name: "test_04_export_policy_update_softreset",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st2},
+ },
}
test_05_import_policy_initial_ipv6 := config.PolicyDefinition{
- Name: "test_05_import_policy_initial_ipv6",
- StatementList: []config.Statement{st3},
+ Name: "test_05_import_policy_initial_ipv6",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st3},
+ },
}
test_06_export_policy_initial_ipv6 := config.PolicyDefinition{
- Name: "test_06_export_policy_initial_ipv6",
- StatementList: []config.Statement{st3},
+ Name: "test_06_export_policy_initial_ipv6",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st3},
+ },
}
test_07_import_policy_update := config.PolicyDefinition{
- Name: "test_07_import_policy_update",
- StatementList: []config.Statement{st4},
+ Name: "test_07_import_policy_update",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st4},
+ },
}
test_07_import_policy_update_softreset := config.PolicyDefinition{
- Name: "test_07_import_policy_update_softreset",
- StatementList: []config.Statement{st5},
+ Name: "test_07_import_policy_update_softreset",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st5},
+ },
}
test_08_export_policy_update := config.PolicyDefinition{
- Name: "test_08_export_policy_update",
- StatementList: []config.Statement{st4},
+ Name: "test_08_export_policy_update",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st4},
+ },
}
test_08_export_policy_update_softreset := config.PolicyDefinition{
- Name: "test_08_export_policy_update_softreset",
- StatementList: []config.Statement{st5},
+ Name: "test_08_export_policy_update_softreset",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st5},
+ },
}
test_09_aspath_length_condition_import := config.PolicyDefinition{
- Name: "test_09_aspath_length_condition_import",
- StatementList: []config.Statement{st_aspathlen},
+ Name: "test_09_aspath_length_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_aspathlen},
+ },
}
test_10_aspath_from_condition_import := config.PolicyDefinition{
- Name: "test_10_aspath_from_condition_import",
- StatementList: []config.Statement{st_aspathFrom},
+ Name: "test_10_aspath_from_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_aspathFrom},
+ },
}
test_11_aspath_any_condition_import := config.PolicyDefinition{
- Name: "test_11_aspath_any_condition_import",
- StatementList: []config.Statement{st_aspathAny},
+ Name: "test_11_aspath_any_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_aspathAny},
+ },
}
test_12_aspath_origin_condition_import := config.PolicyDefinition{
- Name: "test_12_aspath_origin_condition_import",
- StatementList: []config.Statement{st_aspathOrigin},
+ Name: "test_12_aspath_origin_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_aspathOrigin},
+ },
}
test_13_aspath_only_condition_import := config.PolicyDefinition{
- Name: "test_13_aspath_only_condition_import",
- StatementList: []config.Statement{st_aspathOnly},
+ Name: "test_13_aspath_only_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_aspathOnly},
+ },
}
test_14_aspath_only_condition_import := config.PolicyDefinition{
- Name: "test_14_aspath_only_condition_import",
- StatementList: []config.Statement{st_comStr},
+ Name: "test_14_aspath_only_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comStr},
+ },
}
test_15_community_condition_import := config.PolicyDefinition{
- Name: "test_15_community_condition_import",
- StatementList: []config.Statement{st_comStr},
+ Name: "test_15_community_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comStr},
+ },
}
test_16_community_condition_regexp_import := config.PolicyDefinition{
- Name: "test_16_community_condition_regexp_import",
- StatementList: []config.Statement{st_comRegExp},
+ Name: "test_16_community_condition_regexp_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comRegExp},
+ },
}
test_17_community_add_action_import := config.PolicyDefinition{
- Name: "test_17_community_add_action_import",
- StatementList: []config.Statement{st_comAdd},
+ Name: "test_17_community_add_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comAdd},
+ },
}
test_18_community_replace_action_import := config.PolicyDefinition{
- Name: "test_18_community_replace_action_import",
- StatementList: []config.Statement{st_comReplace},
+ Name: "test_18_community_replace_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comReplace},
+ },
}
test_19_community_remove_action_import := config.PolicyDefinition{
- Name: "test_19_community_remove_action_import",
- StatementList: []config.Statement{st_comRemove},
+ Name: "test_19_community_remove_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comRemove},
+ },
}
test_20_community_null_action_import := config.PolicyDefinition{
- Name: "test_20_community_null_action_import",
- StatementList: []config.Statement{st_comNull},
+ Name: "test_20_community_null_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comNull},
+ },
}
test_21_community_add_action_export := config.PolicyDefinition{
- Name: "test_21_community_add_action_export",
- StatementList: []config.Statement{st_comAdd},
+ Name: "test_21_community_add_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comAdd},
+ },
}
test_22_community_replace_action_export := config.PolicyDefinition{
- Name: "test_22_community_replace_action_export",
- StatementList: []config.Statement{st_comReplace},
+ Name: "test_22_community_replace_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comReplace},
+ },
}
test_23_community_remove_action_export := config.PolicyDefinition{
- Name: "test_23_community_remove_action_export",
- StatementList: []config.Statement{st_comRemove},
+ Name: "test_23_community_remove_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comRemove},
+ },
}
test_24_community_null_action_export := config.PolicyDefinition{
- Name: "test_24_community_null_action_export",
- StatementList: []config.Statement{st_comNull},
+ Name: "test_24_community_null_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_comNull},
+ },
}
test_25_med_replace_action_import := config.PolicyDefinition{
- Name: "test_25_med_replace_action_import",
- StatementList: []config.Statement{st_medReplace},
+ Name: "test_25_med_replace_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_medReplace},
+ },
}
test_26_med_add_action_import := config.PolicyDefinition{
- Name: "test_26_med_add_action_import",
- StatementList: []config.Statement{st_medAdd},
+ Name: "test_26_med_add_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_medAdd},
+ },
}
test_27_med_subtract_action_import := config.PolicyDefinition{
- Name: "test_27_med_subtract_action_import",
- StatementList: []config.Statement{st_medSub},
+ Name: "test_27_med_subtract_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_medSub},
+ },
}
test_28_med_replace_action_export := config.PolicyDefinition{
- Name: "test_28_med_replace_action_export",
- StatementList: []config.Statement{st_medReplace},
+ Name: "test_28_med_replace_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_medReplace},
+ },
}
test_29_med_add_action_export := config.PolicyDefinition{
- Name: "test_29_med_add_action_export",
- StatementList: []config.Statement{st_medAdd},
+ Name: "test_29_med_add_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_medAdd},
+ },
}
test_30_med_subtract_action_export := config.PolicyDefinition{
- Name: "test_30_med_subtract_action_export",
- StatementList: []config.Statement{st_medSub},
+ Name: "test_30_med_subtract_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_medSub},
+ },
}
test_31_distribute_reject := config.PolicyDefinition{
- Name: "test_31_distribute_reject",
- StatementList: []config.Statement{st_distribute_reject},
+ Name: "test_31_distribute_reject",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_distribute_reject},
+ },
}
test_32_distribute_accept := config.PolicyDefinition{
- Name: "test_32_distribute_accept",
- StatementList: []config.Statement{st_distribute_accept},
+ Name: "test_32_distribute_accept",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_distribute_accept},
+ },
}
test_33_distribute_set_community_action := config.PolicyDefinition{
- Name: "test_33_distribute_set_community_action",
- StatementList: []config.Statement{st_distribute_comm_add},
+ Name: "test_33_distribute_set_community_action",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_distribute_comm_add},
+ },
}
test_34_distribute_set_med_action := config.PolicyDefinition{
- Name: "test_34_distribute_set_med_action",
- StatementList: []config.Statement{st_distribute_med_add},
+ Name: "test_34_distribute_set_med_action",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_distribute_med_add},
+ },
}
test_35_distribute_policy_update := config.PolicyDefinition{
- Name: "test_35_distribute_policy_update",
- StatementList: []config.Statement{st1},
+ Name: "test_35_distribute_policy_update",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st1},
+ },
}
test_35_distribute_policy_update_softreset := config.PolicyDefinition{
- Name: "test_35_distribute_policy_update_softreset",
- StatementList: []config.Statement{st2},
+ Name: "test_35_distribute_policy_update_softreset",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st2},
+ },
}
test_36_aspath_prepend_action_import := config.PolicyDefinition{
- Name: "test_36_aspath_prepend_action_import",
- StatementList: []config.Statement{st_asprepend},
+ Name: "test_36_aspath_prepend_action_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_asprepend},
+ },
}
test_37_aspath_prepend_action_export := config.PolicyDefinition{
- Name: "test_37_aspath_prepend_action_export",
- StatementList: []config.Statement{st_asprepend},
+ Name: "test_37_aspath_prepend_action_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_asprepend},
+ },
}
test_38_aspath_prepend_action_lastas_import := config.PolicyDefinition{
- Name: "test_38_aspath_prepend_action_lastas_import",
- StatementList: []config.Statement{st_asprepend_lastas},
+ Name: "test_38_aspath_prepend_action_lastas_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_asprepend_lastas},
+ },
}
test_39_aspath_prepend_action_lastas_export := config.PolicyDefinition{
- Name: "test_39_aspath_prepend_action_lastas_export",
- StatementList: []config.Statement{st_asprepend_lastas},
+ Name: "test_39_aspath_prepend_action_lastas_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_asprepend_lastas},
+ },
}
test_40_ecommunity_origin_condition_import := config.PolicyDefinition{
- Name: "test_40_ecommunity_origin_condition_import",
- StatementList: []config.Statement{st_eComOrigin},
+ Name: "test_40_ecommunity_origin_condition_import",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_eComOrigin},
+ },
}
test_41_ecommunity_target_condition_export := config.PolicyDefinition{
- Name: "test_41_ecommunity_target_condition_export",
- StatementList: []config.Statement{st_eComTarget},
- }
-
- ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp},
- NeighborSetList: []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp},
- BgpDefinedSets: config.BgpDefinedSets{
- AsPathSetList: []config.AsPathSet{aspathFrom, aspathAny, aspathOrigin, aspathOnly},
- CommunitySetList: []config.CommunitySet{comStr, comRegExp},
- ExtCommunitySetList: []config.ExtCommunitySet{eComOrigin, eComTarget},
+ Name: "test_41_ecommunity_target_condition_export",
+ Statements: config.Statements{
+ StatementList: []config.Statement{st_eComTarget},
},
}
+
+ ds := config.DefinedSets{}
+ ds.PrefixSets.PrefixSetList = []config.PrefixSet{ps0, ps1, ps2, ps3, ps4, ps5, ps6, psExabgp}
+ ds.NeighborSets.NeighborSetList = []config.NeighborSet{nsPeer2, nsPeer2V6, nsExabgp}
+ ds.BgpDefinedSets.AsPathSets.AsPathSetList = []config.AsPathSet{aspathFrom, aspathAny, aspathOrigin, aspathOnly}
+ ds.BgpDefinedSets.CommunitySets.CommunitySetList = []config.CommunitySet{comStr, comRegExp}
+ ds.BgpDefinedSets.ExtCommunitySets.ExtCommunitySetList = []config.ExtCommunitySet{eComOrigin, eComTarget}
+
p := &config.RoutingPolicy{
DefinedSets: ds,
- PolicyDefinitionList: []config.PolicyDefinition{
- test_01_import_policy_initial,
- test_02_export_policy_initial,
- test_03_import_policy_update,
- test_03_import_policy_update_softreset,
- test_04_export_policy_update,
- test_04_export_policy_update_softreset,
- test_05_import_policy_initial_ipv6,
- test_06_export_policy_initial_ipv6,
- test_07_import_policy_update,
- test_07_import_policy_update_softreset,
- test_08_export_policy_update,
- test_08_export_policy_update_softreset,
- test_09_aspath_length_condition_import,
- test_10_aspath_from_condition_import,
- test_11_aspath_any_condition_import,
- test_12_aspath_origin_condition_import,
- test_13_aspath_only_condition_import,
- test_14_aspath_only_condition_import,
- test_15_community_condition_import,
- test_16_community_condition_regexp_import,
- test_17_community_add_action_import,
- test_18_community_replace_action_import,
- test_19_community_remove_action_import,
- test_20_community_null_action_import,
- test_21_community_add_action_export,
- test_22_community_replace_action_export,
- test_23_community_remove_action_export,
- test_24_community_null_action_export,
- test_25_med_replace_action_import,
- test_26_med_add_action_import,
- test_27_med_subtract_action_import,
- test_28_med_replace_action_export,
- test_29_med_add_action_export,
- test_30_med_subtract_action_export,
- test_31_distribute_reject,
- test_32_distribute_accept,
- test_33_distribute_set_community_action,
- test_34_distribute_set_med_action,
- test_35_distribute_policy_update,
- test_35_distribute_policy_update_softreset,
- test_36_aspath_prepend_action_import,
- test_37_aspath_prepend_action_export,
- test_38_aspath_prepend_action_lastas_import,
- test_39_aspath_prepend_action_lastas_export,
- test_40_ecommunity_origin_condition_import,
- test_41_ecommunity_target_condition_export,
+ PolicyDefinitions: config.PolicyDefinitions{
+ PolicyDefinitionList: []config.PolicyDefinition{
+ test_01_import_policy_initial,
+ test_02_export_policy_initial,
+ test_03_import_policy_update,
+ test_03_import_policy_update_softreset,
+ test_04_export_policy_update,
+ test_04_export_policy_update_softreset,
+ test_05_import_policy_initial_ipv6,
+ test_06_export_policy_initial_ipv6,
+ test_07_import_policy_update,
+ test_07_import_policy_update_softreset,
+ test_08_export_policy_update,
+ test_08_export_policy_update_softreset,
+ test_09_aspath_length_condition_import,
+ test_10_aspath_from_condition_import,
+ test_11_aspath_any_condition_import,
+ test_12_aspath_origin_condition_import,
+ test_13_aspath_only_condition_import,
+ test_14_aspath_only_condition_import,
+ test_15_community_condition_import,
+ test_16_community_condition_regexp_import,
+ test_17_community_add_action_import,
+ test_18_community_replace_action_import,
+ test_19_community_remove_action_import,
+ test_20_community_null_action_import,
+ test_21_community_add_action_export,
+ test_22_community_replace_action_export,
+ test_23_community_remove_action_export,
+ test_24_community_null_action_export,
+ test_25_med_replace_action_import,
+ test_26_med_add_action_import,
+ test_27_med_subtract_action_import,
+ test_28_med_replace_action_export,
+ test_29_med_add_action_export,
+ test_30_med_subtract_action_export,
+ test_31_distribute_reject,
+ test_32_distribute_accept,
+ test_33_distribute_set_community_action,
+ test_34_distribute_set_med_action,
+ test_35_distribute_policy_update,
+ test_35_distribute_policy_update_softreset,
+ test_36_aspath_prepend_action_import,
+ test_37_aspath_prepend_action_export,
+ test_38_aspath_prepend_action_lastas_import,
+ test_39_aspath_prepend_action_lastas_export,
+ test_40_ecommunity_origin_condition_import,
+ test_41_ecommunity_target_condition_export,
+ },
},
}
return p
diff --git a/test/scenario_test/quagga-rsconfig.go b/test/scenario_test/quagga-rsconfig.go
index 70d57aa7..76b93ae8 100644
--- a/test/scenario_test/quagga-rsconfig.go
+++ b/test/scenario_test/quagga-rsconfig.go
@@ -41,15 +41,15 @@ func NewQuaggaConfig(id int, gConfig *config.Global, myConfig *config.Neighbor,
func (qt *QuaggaConfig) IPv4Config() *bytes.Buffer {
buf := bytes.NewBuffer(nil)
- buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborAddress))
+ buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborConfig.NeighborAddress))
buf.WriteString(fmt.Sprintf("! my ip_version %s\n", IPv4))
buf.WriteString("hostname bgpd\n")
buf.WriteString("password zebra\n")
- buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.PeerAs))
+ buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.NeighborConfig.PeerAs))
buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\n", qt.id))
buf.WriteString(fmt.Sprintf("network %s%d%s\n", baseNeighborNetwork[IPv4], qt.id, baseNeighborNetMask[IPv4]))
- buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.As))
- buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.AuthPassword))
+ buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.GlobalConfig.As))
+ buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.NeighborConfig.AuthPassword))
buf.WriteString("debug bgp as4\n")
buf.WriteString("debug bgp fsm\n")
buf.WriteString("debug bgp updates\n")
@@ -61,15 +61,15 @@ func (qt *QuaggaConfig) IPv4Config() *bytes.Buffer {
func (qt *QuaggaConfig) IPv6Config() *bytes.Buffer {
buf := bytes.NewBuffer(nil)
- buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborAddress))
+ buf.WriteString(fmt.Sprintf("! my address %s\n", qt.config.NeighborConfig.NeighborAddress))
buf.WriteString(fmt.Sprintf("! my ip_version %s\n", IPv6))
buf.WriteString("hostname bgpd\n")
buf.WriteString("password zebra\n")
- buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.PeerAs))
+ buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.NeighborConfig.PeerAs))
buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\n", qt.id))
buf.WriteString("no bgp default ipv4-unicast\n")
- buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.As))
- buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.AuthPassword))
+ buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.GlobalConfig.As))
+ buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.NeighborConfig.AuthPassword))
buf.WriteString("address-family ipv6\n")
buf.WriteString(fmt.Sprintf("network %s%d%s\n", baseNeighborNetwork[IPv6], qt.id, baseNeighborNetMask[IPv6]))
buf.WriteString(fmt.Sprintf("neighbor %s activate\n", qt.serverIP))
@@ -78,7 +78,7 @@ func (qt *QuaggaConfig) IPv6Config() *bytes.Buffer {
buf.WriteString("ipv6 prefix-list pl-ipv6 seq 10 permit any\n")
buf.WriteString("route-map IPV6-OUT permit 10\n")
buf.WriteString("match ipv6 address prefix-list pl-ipv6\n")
- buf.WriteString(fmt.Sprintf("set ipv6 next-hop global %s\n", qt.config.NeighborAddress))
+ buf.WriteString(fmt.Sprintf("set ipv6 next-hop global %s\n", qt.config.NeighborConfig.NeighborAddress))
buf.WriteString("debug bgp as4\n")
buf.WriteString("debug bgp fsm\n")
buf.WriteString("debug bgp updates\n")
@@ -91,25 +91,28 @@ func (qt *QuaggaConfig) IPv6Config() *bytes.Buffer {
func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bool, normalBGP bool) {
quaggaConfigList := make([]*QuaggaConfig, 0)
- gobgpConf := config.Bgp{
- Global: config.Global{
- As: 65000,
- RouterId: net.ParseIP("192.168.255.1"),
- },
- }
+ gobgpConf := config.Bgp{}
+ gobgpConf.Global.GlobalConfig.As = 65000
+ gobgpConf.Global.GlobalConfig.RouterId = net.ParseIP("192.168.255.1")
for i := 1; i < nr+1; i++ {
- c := config.Neighbor{
- PeerAs: 65000 + uint32(i),
- NeighborAddress: net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], i)),
- AuthPassword: fmt.Sprintf("hoge%d", i),
- TransportOptions: config.TransportOptions{PassiveMode: true},
- RouteServer: config.RouteServer{RouteServerClient: !normalBGP},
- Timers: config.Timers{HoldTime: 30, KeepaliveInterval: 10, IdleHoldTimeAfterReset: 10},
- PeerType: config.PEER_TYPE_EXTERNAL,
- }
- gobgpConf.NeighborList = append(gobgpConf.NeighborList, c)
+ c := config.Neighbor{}
+ c.NeighborConfig.PeerAs = 65000 + uint32(i)
+ c.NeighborConfig.NeighborAddress = net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], i))
+ c.NeighborConfig.AuthPassword = fmt.Sprintf("hoge%d", i)
+ c.Transport.TransportConfig.PassiveMode = true
+ c.RouteServer.RouteServerClient = !normalBGP
+
+ timers := config.Timers{}
+ timers.TimersConfig.HoldTime = 30
+ timers.TimersConfig.KeepaliveInterval = 10
+ timers.TimersConfig.IdleHoldTimeAfterReset = 10
+
+ c.Timers = timers
+ c.NeighborConfig.PeerType = config.PEER_TYPE_EXTERNAL
+
+ gobgpConf.Neighbors.NeighborList = append(gobgpConf.Neighbors.NeighborList, c)
if !nonePeer {
q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion]))
quaggaConfigList = append(quaggaConfigList, q)
@@ -138,21 +141,24 @@ func create_config_files(nr int, outputDir string, IPVersion string, nonePeer bo
func append_config_files(ar int, outputDir string, IPVersion string, noQuagga bool, normalBGP bool) {
- gobgpConf := config.Bgp{
- Global: config.Global{
- As: 65000,
- RouterId: net.ParseIP("192.168.255.1"),
- },
- }
- c := config.Neighbor{
- PeerAs: 65000 + uint32(ar),
- NeighborAddress: net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], ar)),
- AuthPassword: fmt.Sprintf("hoge%d", ar),
- RouteServer: config.RouteServer{RouteServerClient: !normalBGP},
- TransportOptions: config.TransportOptions{PassiveMode: true},
- Timers: config.Timers{HoldTime: 30, KeepaliveInterval: 10, IdleHoldTimeAfterReset: 10},
- PeerType: config.PEER_TYPE_EXTERNAL,
- }
+ gobgpConf := config.Bgp{}
+ gobgpConf.Global.GlobalConfig.As = 65000
+ gobgpConf.Global.GlobalConfig.RouterId = net.ParseIP("192.168.255.1")
+
+ c := config.Neighbor{}
+ c.NeighborConfig.PeerAs = 65000 + uint32(ar)
+ c.NeighborConfig.NeighborAddress = net.ParseIP(fmt.Sprintf("%s%d", baseNeighborAddress[IPVersion], ar))
+ c.NeighborConfig.AuthPassword = fmt.Sprintf("hoge%d", ar)
+ c.RouteServer.RouteServerClient = !normalBGP
+ c.Transport.TransportConfig.PassiveMode = true
+
+ timers := config.Timers{}
+ timers.TimersConfig.HoldTime = 30
+ timers.TimersConfig.KeepaliveInterval = 10
+ timers.TimersConfig.IdleHoldTimeAfterReset = 10
+
+ c.Timers = timers
+ c.NeighborConfig.PeerType = config.PEER_TYPE_EXTERNAL
if !noQuagga {
q := NewQuaggaConfig(ar, &gobgpConf.Global, &c, net.ParseIP(serverAddress[IPVersion]))
@@ -172,7 +178,7 @@ func append_config_files(ar int, outputDir string, IPVersion string, noQuagga bo
if d_err != nil {
log.Fatal(d_err)
}
- newConf.NeighborList = append(newConf.NeighborList, c)
+ newConf.Neighbors.NeighborList = append(newConf.Neighbors.NeighborList, c)
var buffer bytes.Buffer
encoder := toml.NewEncoder(&buffer)
encoder.Encode(newConf)
@@ -183,7 +189,7 @@ func append_config_files(ar int, outputDir string, IPVersion string, noQuagga bo
log.Fatal(p_err)
}
- if policyConf != nil && len(policyConf.PolicyDefinitionList) != 0 {
+ if policyConf != nil && len(policyConf.PolicyDefinitions.PolicyDefinitionList) != 0 {
encoder.Encode(policyConf)
}
diff --git a/test/scenario_test/route_server_malformed_test.py b/test/scenario_test/route_server_malformed_test.py
index 296f3645..acb755d9 100644
--- a/test/scenario_test/route_server_malformed_test.py
+++ b/test/scenario_test/route_server_malformed_test.py
@@ -156,9 +156,9 @@ def get_neighbor_address():
address = []
try:
gobgp_config = toml.loads(open(gobgp_config_file).read())
- neighbors_config = gobgp_config['NeighborList']
+ neighbors_config = gobgp_config['Neighbors']['NeighborList']
for neighbor_config in neighbors_config:
- neighbor_ip = neighbor_config['NeighborAddress']
+ neighbor_ip = neighbor_config['NeighborConfig']['NeighborAddress']
address.append(neighbor_ip)
except IOError, (errno, strerror):
diff --git a/test/scenario_test/route_server_policy_test.py b/test/scenario_test/route_server_policy_test.py
index 204b55b1..fe4304c5 100644
--- a/test/scenario_test/route_server_policy_test.py
+++ b/test/scenario_test/route_server_policy_test.py
@@ -230,7 +230,9 @@ class GoBGPTest(GoBGPTestBase):
self.initialize()
# add other network
- tn = qaccess.login(peer2)
+ tn = self.try_login_quagga(peer2)
+ self.assertIsNotNone(tn)
+
print "add network 192.168.20.0/24"
qaccess.add_network(tn, 65002, r2)
print "add network 192.168.200.0/24"
@@ -341,7 +343,9 @@ class GoBGPTest(GoBGPTestBase):
self.initialize()
# add other network
- tn = qaccess.login(peer2)
+ tn = self.try_login_quagga(peer2)
+ self.assertIsNotNone(tn)
+
print "add network 192.168.20.0/24"
qaccess.add_network(tn, 65002, r2)
print "add network 192.168.200.0/24"
@@ -565,7 +569,9 @@ class GoBGPTest(GoBGPTestBase):
self.initialize()
# add other network
- tn = qaccess.login(peer2)
+ tn = self.try_login_quagga(peer2)
+ self.assertIsNotNone(tn)
+
print "add network 2001:0:10:20::/64"
qaccess.add_network(tn, 65002, r2, use_ipv6=True)
print "add network 2001:0:10:200::/64"
@@ -678,7 +684,9 @@ class GoBGPTest(GoBGPTestBase):
self.initialize()
# add other network
- tn = qaccess.login(peer2)
+ tn = self.try_login_quagga(peer2)
+ self.assertIsNotNone(tn)
+
print "add network 2001:0:10:20::/64"
qaccess.add_network(tn, 65002, r2, use_ipv6=True)
print "add network 2001:0:10:200::/64"
@@ -934,7 +942,7 @@ class GoBGPTest(GoBGPTestBase):
# generate exabgp configuration file
prefix1 = "192.168.100.0/24"
asns = ['65100'] + [ str(asn) for asn in range(65099, 65090, -1) ]
- as_path = reduce(lambda a,b: a + " " + b, asns)
+ as_path = reduce(lambda a, b: a + " " + b, asns)
e = ExabgpConfig(EXABGP_COMMON_CONF)
e.add_route(prefix1, aspath=as_path)
@@ -953,6 +961,7 @@ class GoBGPTest(GoBGPTestBase):
self.initialize()
addresses = self.get_neighbor_address(self.gobgp_config)
+
self.retry_routine_for_state(addresses, "BGP_FSM_ESTABLISHED")
path = self.get_paths_in_localrib(peer1, prefix1, retry=self.retry_count_common)
@@ -963,7 +972,7 @@ class GoBGPTest(GoBGPTestBase):
self.assertIsNotNone(qpath)
# check local-rib in peer2
- path = self.get_paths_in_localrib(peer2, prefix1,retry=0)
+ path = self.get_paths_in_localrib(peer2, prefix1, retry=0)
self.assertIsNone(path)
# check show ip bgp on peer2(quagga2)
@@ -2309,7 +2318,9 @@ class GoBGPTest(GoBGPTestBase):
self.initialize()
# add other network
- tn = qaccess.login(peer2)
+ tn = self.try_login_quagga(peer2)
+ self.assertIsNotNone(tn)
+
print "add network 192.168.20.0/24"
qaccess.add_network(tn, 65002, r2)
print "add network 192.168.200.0/24"
diff --git a/tools/config/example_toml.go b/tools/config/example_toml.go
index 2be6b8e2..8a80e540 100644
--- a/tools/config/example_toml.go
+++ b/tools/config/example_toml.go
@@ -11,29 +11,50 @@ import (
func main() {
b := config.Bgp{
Global: config.Global{
- As: 12332,
- RouterId: net.ParseIP("10.0.0.1"),
+ GlobalConfig: config.GlobalConfig{
+ As: 12332,
+ RouterId: net.ParseIP("10.0.0.1"),
+ },
},
- NeighborList: []config.Neighbor{
- config.Neighbor{
- PeerAs: 12333,
- NeighborAddress: net.ParseIP("192.168.177.32"),
- AuthPassword: "apple",
- AfiSafiList: []config.AfiSafi{config.AfiSafi{AfiSafiName: "ipv4-unicast"}, config.AfiSafi{AfiSafiName: "ipv6-unicast"}},
- ApplyPolicy: config.ApplyPolicy{
- ImportPolicies: []string{"pd1"},
- DefaultImportPolicy: config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE,
+ Neighbors: config.Neighbors{
+ NeighborList: []config.Neighbor{
+ config.Neighbor{
+ NeighborConfig: config.NeighborConfig{
+ PeerAs: 12333,
+ AuthPassword: "apple",
+ NeighborAddress: net.ParseIP("192.168.177.33"),
+ },
+ AfiSafis: config.AfiSafis{
+
+ AfiSafiList: []config.AfiSafi{
+ config.AfiSafi{AfiSafiName: "ipv4-unicast"},
+ config.AfiSafi{AfiSafiName: "ipv6-unicast"},
+ },
+ },
+ ApplyPolicy: config.ApplyPolicy{
+
+ ApplyPolicyConfig: config.ApplyPolicyConfig{
+ ImportPolicy: []string{"pd1"},
+ DefaultImportPolicy: config.DEFAULT_POLICY_TYPE_ACCEPT_ROUTE,
+ },
+ },
+ },
+
+ config.Neighbor{
+ NeighborConfig: config.NeighborConfig{
+ PeerAs: 12334,
+ AuthPassword: "orange",
+ NeighborAddress: net.ParseIP("192.168.177.32"),
+ },
+ },
+
+ config.Neighbor{
+ NeighborConfig: config.NeighborConfig{
+ PeerAs: 12335,
+ AuthPassword: "grape",
+ NeighborAddress: net.ParseIP("192.168.177.34"),
+ },
},
- },
- config.Neighbor{
- PeerAs: 12334,
- NeighborAddress: net.ParseIP("192.168.177.33"),
- AuthPassword: "orange",
- },
- config.Neighbor{
- PeerAs: 12335,
- NeighborAddress: net.ParseIP("192.168.177.34"),
- AuthPassword: "grape",
},
},
}
@@ -54,12 +75,12 @@ func main() {
func policy() config.RoutingPolicy {
+ _, prefix1, _ := net.ParseCIDR("10.3.192.0/21")
ps := config.PrefixSet{
PrefixSetName: "ps1",
PrefixList: []config.Prefix{
config.Prefix{
- Address: net.ParseIP("10.3.192.0"),
- Masklength: 21,
+ IpPrefix: *prefix1,
MasklengthRange: "21..24",
}},
}
@@ -74,55 +95,94 @@ func policy() config.RoutingPolicy {
cs := config.CommunitySet{
CommunitySetName: "community1",
- CommunityMembers: []string{"65100:10"},
+ CommunityMember: []string{"65100:10"},
}
ecs := config.ExtCommunitySet{
ExtCommunitySetName: "ecommunity1",
- ExtCommunityMembers: []string{"RT:65001:200"},
+ ExtCommunityMember: []string{"RT:65001:200"},
}
as := config.AsPathSet{
- AsPathSetName: "aspath1",
- AsPathSetMembers: []string{"^65100"},
+ AsPathSetName: "aspath1",
+ AsPathSetMember: []string{"^65100"},
}
bds := config.BgpDefinedSets{
- CommunitySetList: []config.CommunitySet{cs},
- ExtCommunitySetList: []config.ExtCommunitySet{ecs},
- AsPathSetList: []config.AsPathSet{as},
+
+ CommunitySets: config.CommunitySets{
+ CommunitySetList: []config.CommunitySet{cs},
+ },
+
+ ExtCommunitySets: config.ExtCommunitySets{
+ ExtCommunitySetList: []config.ExtCommunitySet{ecs},
+ },
+
+ AsPathSets: config.AsPathSets{
+ AsPathSetList: []config.AsPathSet{as},
+ },
}
ds := config.DefinedSets{
- PrefixSetList: []config.PrefixSet{ps},
- NeighborSetList: []config.NeighborSet{ns},
+
+ PrefixSets: config.PrefixSets{
+ PrefixSetList: []config.PrefixSet{ps},
+ },
+
+ NeighborSets: config.NeighborSets{
+ NeighborSetList: []config.NeighborSet{ns},
+ },
+
BgpDefinedSets: bds,
}
al := config.AsPathLength{
Operator: "eq",
- Value: 2,
+ Value: 2,
}
s := config.Statement{
Name: "statement1",
Conditions: config.Conditions{
- MatchPrefixSet: "ps1",
- MatchNeighborSet: "ns1",
- MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ALL,
+
+ MatchPrefixSet: config.MatchPrefixSet{
+ PrefixSet: "ps1",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY,
+ },
+
+ MatchNeighborSet: config.MatchNeighborSet{
+ NeighborSet: "ns1",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_RESTRICTED_TYPE_ANY,
+ },
+
BgpConditions: config.BgpConditions{
- MatchCommunitySet: "community1",
- MatchExtCommunitySet: "ecommunity1",
- MatchAsPathSet: "aspath1",
+ MatchCommunitySet: config.MatchCommunitySet{
+ CommunitySet: "community1",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
+ },
+
+ MatchExtCommunitySet: config.MatchExtCommunitySet{
+ ExtCommunitySet: "ecommunity1",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
+ },
+
+ MatchAsPathSet: config.MatchAsPathSet{
+ AsPathSet: "aspath1",
+ MatchSetOptions: config.MATCH_SET_OPTIONS_TYPE_ANY,
+ },
AsPathLength: al,
},
},
Actions: config.Actions{
- AcceptRoute: false,
- RejectRoute: true,
+ RouteDisposition: config.RouteDisposition{
+ AcceptRoute: false,
+ RejectRoute: true,
+ },
BgpActions: config.BgpActions{
SetCommunity: config.SetCommunity{
- Communities: []string{"65100:20"},
+ SetCommunityMethod: config.SetCommunityMethod{
+ Communities: []string{"65100:20"},
+ },
Options: "ADD",
},
SetMed: "-200",
@@ -131,13 +191,17 @@ func policy() config.RoutingPolicy {
}
pd := config.PolicyDefinition{
- Name: "pd1",
- StatementList: []config.Statement{s},
+ Name: "pd1",
+ Statements: config.Statements{
+ StatementList: []config.Statement{s},
+ },
}
p := config.RoutingPolicy{
- DefinedSets: ds,
- PolicyDefinitionList: []config.PolicyDefinition{pd},
+ DefinedSets: ds,
+ PolicyDefinitions: config.PolicyDefinitions{
+ PolicyDefinitionList: []config.PolicyDefinition{pd},
+ },
}
return p
diff --git a/tools/pyang_plugins/bgpyang2golang.py b/tools/pyang_plugins/bgpyang2golang.py
index c5912bda..9fe8a8ee 100644
--- a/tools/pyang_plugins/bgpyang2golang.py
+++ b/tools/pyang_plugins/bgpyang2golang.py
@@ -75,14 +75,15 @@ class GolangPlugin(plugin.PyangPlugin):
# load augment module
if ctx.opts.augment:
aug_mod_path = ctx.opts.augment
- try:
- fd = open(aug_mod_path)
- text = fd.read()
- except IOError as ex:
- sys.stderr.write("error %s: %s\n" % (aug_mod_path, str(ex)))
- sys.exit(1)
- aug_mod = ctx.add_module(aug_mod_path, text)
- check_module_deps(ctx, aug_mod)
+ for p in aug_mod_path.split(","):
+ with open(p) as fd:
+ try:
+ text = fd.read()
+ except IOError as ex:
+ sys.stderr.write("error %s: %s\n" % (aug_mod_path, str(ex)))
+ sys.exit(1)
+ aug_mod = ctx.add_module(p, text)
+ check_module_deps(ctx, aug_mod)
# visit yang statements
visit_modules(ctx)
@@ -115,7 +116,7 @@ def emit_go(ctx):
emit_typedef(ctx, mod)
for struct in ctx.golang_struct_def:
- struct_name = struct.arg
+ struct_name = struct.uniq_name
if struct_name in done:
continue
emit_class_def(ctx, struct, struct_name, struct.module_prefix)
@@ -136,13 +137,21 @@ def check_module_deps(ctx, module):
ctx.module_deps.append(mod)
+def dig_leafref(type_obj):
+ reftype = type_obj.i_type_spec.i_target_node.search_one('type')
+ if is_leafref(reftype):
+ return dig_leafref(reftype)
+ else:
+ return reftype
+
+
def emit_class_def(ctx, yang_statement, struct_name, prefix):
o = StringIO.StringIO()
- print >> o, '//struct for container %s:%s' % (prefix, struct_name)
+ print >> o, '//struct for container %s:%s' % (prefix, yang_statement.arg)
print >> o, 'type %s struct {' % convert_to_golang(struct_name)
for child in yang_statement.i_children:
- container_or_list_name = child.arg
+ container_or_list_name = child.uniq_name
val_name_go = convert_to_golang(child.arg)
child_prefix = get_orig_prefix(child.i_orig_module)
print >> o, ' // original -> %s:%s' % \
@@ -153,14 +162,21 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
type_obj = child.search_one('type')
type_name = type_obj.arg
+
# case identityref
if type_name == 'identityref':
emit_type_name = 'string'
# case leafref
elif type_name == 'leafref':
- t = type_obj.i_type_spec.i_target_node.search_one('type')
- emit_type_name = t.arg
+ t = dig_leafref(type_obj)
+ if is_translation_required(t):
+ print >> o, ' //%s:%s\'s original type is %s' \
+ % (child_prefix, container_or_list_name, t.arg)
+ emit_type_name = translate_type(t.arg)
+ else:
+ emit_type_name = t.arg
+
# case translation required
elif is_translation_required(type_obj):
@@ -176,8 +192,13 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
else:
base_module = type_obj.i_orig_module.i_prefix
t = lookup_typedef(ctx, base_module, type_name)
+ # print(t)
emit_type_name = t.golang_name
+ # case 'case'
+ if is_case(child):
+ continue
+
# case leaflist
if is_leaflist(child):
type_obj = child.search_one('type')
@@ -204,7 +225,7 @@ def emit_class_def(ctx, yang_statement, struct_name, prefix):
emit_type_name = '[]'+t.golang_name
# case container
- elif is_container(child):
+ elif is_container(child) or is_choice(child):
key = child_prefix+':'+container_or_list_name
t = ctx.golang_struct_names[key]
emit_type_name = t.golang_name
@@ -235,19 +256,70 @@ def get_orig_prefix(module):
def visit_children(ctx, module, children):
for c in children:
- prefix = get_orig_prefix(c.i_orig_module)
+
+ prefix = ''
+ if is_case(c):
+ prefix = get_orig_prefix(c.parent.i_orig_module)
+ c.i_orig_module = c.parent.i_orig_module
+ else:
+ prefix = get_orig_prefix(c.i_orig_module)
+
+ c.uniq_name = c.arg
+ if c.arg == 'config':
+ c.uniq_name = c.parent.uniq_name + '-config'
+
+ if c.arg == 'state':
+
+ c.uniq_name = c.parent.uniq_name + '-state'
+
+ if c.arg == 'graceful-restart' and prefix == 'bgp-mp':
+ c.uniq_name = 'mp-graceful-restart'
+
t = c.search_one('type')
- type_name = t.arg if t is not None else None
- if is_list(c) or is_container(c):
- c.golang_name = convert_to_golang(c.arg)
- ctx.golang_struct_def.append(c)
- c.module_prefix = prefix
- ctx.golang_struct_names[prefix+':'+c.arg] = c
+
+ if is_list(c) or is_container(c) or is_choice(c):
+ c.golang_name = convert_to_golang(c.uniq_name)
+
+ if is_choice(c):
+ picks = pickup_choice(c)
+ c.i_children = picks
+
+ if ctx.golang_struct_names.get(prefix+':'+c.uniq_name):
+ ext_c = ctx.golang_struct_names.get(prefix+':'+c.uniq_name)
+ ext_c_child_count = len(getattr(ext_c, "i_children"))
+ current_c_child_count = len(getattr(c, "i_children"))
+ if ext_c_child_count < current_c_child_count:
+ c.module_prefix = prefix
+ ctx.golang_struct_names[prefix+':'+c.uniq_name] = c
+ idx = ctx.golang_struct_def.index(ext_c)
+ ctx.golang_struct_def[idx] = c
+ else:
+ c.module_prefix = prefix
+ ctx.golang_struct_names[prefix+':'+c.uniq_name] = c
+ ctx.golang_struct_def.append(c)
if hasattr(c, 'i_children'):
visit_children(ctx, module, c.i_children)
+def pickup_choice(c):
+ element = []
+ for child in c.i_children:
+ if is_case(child):
+ element = element + child.i_children
+
+ return element
+
+
+def get_type_spec(stmt):
+ for s in stmt.substmts:
+ if hasattr(s, 'i_type_spec'):
+ type_sp = s.i_type_spec
+ return type_sp.name
+
+ return None
+
+
def visit_typedef(ctx, module):
prefix = module.i_prefix
child_map = {}
@@ -258,6 +330,7 @@ def visit_typedef(ctx, module):
if stmts.golang_name == 'PeerType':
stmts.golang_name = 'PeerTypeDef'
child_map[name] = stmts
+
ctx.golang_typedef_map[prefix] = child_map
if ctx.prefix_rel[prefix] != prefix:
ctx.golang_typedef_map[ctx.prefix_rel[prefix]] = child_map
@@ -301,6 +374,11 @@ def emit_typedef(ctx, module):
prefix = module.i_prefix
t_map = ctx.golang_typedef_map[prefix]
for name, stmt in t_map.items():
+
+ # skip identityref type because currently skip identity
+ if get_type_spec(stmt) == 'identityref':
+ continue
+
type_name_org = name
type_name = stmt.golang_name
if type_name in emitted_type_names:
@@ -324,6 +402,7 @@ def emit_typedef(ctx, module):
print >> o, 'const ('
already_added_iota = False
+ already_added_type = False
for sub in t.substmts:
if sub.search_one('value'):
enum_value = " = "+sub.search_one('value').arg
@@ -333,8 +412,14 @@ def emit_typedef(ctx, module):
else:
enum_value = " = iota"
already_added_iota = True
+
+
enum_name = convert_const_prefix(sub.arg)
- print >> o, ' %s_%s%s' % (const_prefix, enum_name, enum_value)
+
+ t = type_name if not already_added_type else ""
+ already_added_type = True
+
+ print >> o, ' %s_%s %s%s' % (const_prefix, enum_name, t, enum_value)
print >> o, ')'
elif t.arg == 'union':
print >> o, '// typedef for typedef %s:%s'\
@@ -373,6 +458,10 @@ def is_reference(s):
return s.arg in ['leafref', 'identityref']
+def is_leafref(s):
+ return s.arg in ['leafref']
+
+
def is_leaf(s):
return s.keyword in ['leaf']
@@ -389,6 +478,14 @@ def is_container(s):
return s.keyword in ['container']
+def is_case(s):
+ return s.keyword in ['case']
+
+
+def is_choice(s):
+ return s.keyword in ['choice']
+
+
def is_builtin_type(t):
return t.arg in _type_builtin
@@ -399,14 +496,18 @@ def is_translation_required(t):
_type_translation_map = {
'union': 'string',
- 'enumeration': 'string',
+ 'enumeration': 'uint32',
'decimal64': 'float64',
'boolean': 'bool',
'empty': 'bool',
'inet:ip-address': 'net.IP',
+ 'inet:ip-prefix': 'net.IPNet',
'inet:ipv4-address': 'net.IP',
'inet:as-number': 'uint32',
'bgp-set-community-option-type' : 'string',
+ 'identityref' : 'string',
+ 'inet:port-number': 'uint16',
+ 'yang:timeticks': 'int64',
}
diff --git a/tools/route-server/quagga-rsconfig.go b/tools/route-server/quagga-rsconfig.go
index 421b1f77..a58e8601 100644
--- a/tools/route-server/quagga-rsconfig.go
+++ b/tools/route-server/quagga-rsconfig.go
@@ -34,11 +34,11 @@ func (qt *QuaggaConfig) Config() *bytes.Buffer {
buf.WriteString("hostname bgpd\n")
buf.WriteString("password zebra\n")
- buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.PeerAs))
+ buf.WriteString(fmt.Sprintf("router bgp %d\n", qt.config.NeighborConfig.PeerAs))
buf.WriteString(fmt.Sprintf("bgp router-id 192.168.0.%d\n", qt.id))
buf.WriteString(fmt.Sprintf("network 192.168.%d.0/24\n", qt.id))
- buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.As))
- buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.AuthPassword))
+ buf.WriteString(fmt.Sprintf("neighbor %s remote-as %d\n", qt.serverIP, qt.gobgpConfig.GlobalConfig.As))
+ buf.WriteString(fmt.Sprintf("neighbor %s password %s\n", qt.serverIP, qt.config.NeighborConfig.AuthPassword))
buf.WriteString("log file /var/log/quagga/bgpd.log")
return buf
}
@@ -46,20 +46,18 @@ func (qt *QuaggaConfig) Config() *bytes.Buffer {
func create_config_files(nr int, outputDir string) {
quaggaConfigList := make([]*QuaggaConfig, 0)
- gobgpConf := config.Bgp{
- Global: config.Global{
- As: 65000,
- RouterId: net.ParseIP("192.168.255.1"),
- },
- }
+ gobgpConf := config.Bgp{}
+ gobgpConf.Global.GlobalConfig.As = 65000
+ gobgpConf.Global.GlobalConfig.RouterId = net.ParseIP("192.168.255.1")
for i := 1; i < nr+1; i++ {
- c := config.Neighbor{
- PeerAs: 65000 + uint32(i),
- NeighborAddress: net.ParseIP(fmt.Sprintf("10.0.0.%d", i)),
- AuthPassword: fmt.Sprintf("hoge%d", i),
- }
- gobgpConf.NeighborList = append(gobgpConf.NeighborList, c)
+
+ c := config.Neighbor{}
+ c.NeighborConfig.PeerAs = 65000 + uint32(i)
+ c.NeighborConfig.NeighborAddress = net.ParseIP(fmt.Sprintf("10.0.0.%d", i))
+ c.NeighborConfig.AuthPassword = fmt.Sprintf("hoge%d", i)
+
+ gobgpConf.Neighbors.NeighborList = append(gobgpConf.Neighbors.NeighborList, c)
q := NewQuaggaConfig(i, &gobgpConf.Global, &c, net.ParseIP("10.0.255.1"))
quaggaConfigList = append(quaggaConfigList, q)
os.Mkdir(fmt.Sprintf("%s/q%d", outputDir, i), 0755)