From f32673bbec2541226657653af1042d0500a52d00 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Thu, 9 Nov 2017 10:04:13 +0900 Subject: api: Activate address family using Peer.AfiSafis Currently, to configure per AFI-SAFI settings when adding neighbor via gRPC API, it is require to specify the both Peer.Families and Peer.AfiSafis fields. If Peer.Families is omitted, settings in Peer.AfiSafis are ignored and the given address families are not activated. This patch enables to configure per AFI-SAFI settings and activate the address family with only Peer.AfiSafis (without Peer.Families). Note: For the backward compatibility, if only Peer.Families is specified, this patch creates per AFI-SAFI settings with the default settings. Signed-off-by: IWASE Yusuke --- api/gobgp.pb.go | 5 +++- api/gobgp.proto | 5 +++- api/grpc_server.go | 72 ++++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 59 insertions(+), 23 deletions(-) (limited to 'api') diff --git a/api/gobgp.pb.go b/api/gobgp.pb.go index 61cfd2fc..5e0c3461 100644 --- a/api/gobgp.pb.go +++ b/api/gobgp.pb.go @@ -2769,6 +2769,9 @@ func (*ValidateRibResponse) ProtoMessage() {} func (*ValidateRibResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{104} } type Peer struct { + // Note: Regarding to the consistency with OpenConfig model, a list of + // address family should be removed from here, and should be configured with + // the list of AfiSafi instead. Families []uint32 `protobuf:"varint,1,rep,packed,name=families" json:"families,omitempty"` ApplyPolicy *ApplyPolicy `protobuf:"bytes,2,opt,name=apply_policy,json=applyPolicy" json:"apply_policy,omitempty"` Conf *PeerConf `protobuf:"bytes,3,opt,name=conf" json:"conf,omitempty"` @@ -2950,7 +2953,7 @@ type PeerConf struct { RemoteCap [][]byte `protobuf:"bytes,11,rep,name=remote_cap,json=remoteCap,proto3" json:"remote_cap,omitempty"` LocalCap [][]byte `protobuf:"bytes,12,rep,name=local_cap,json=localCap,proto3" json:"local_cap,omitempty"` Id string `protobuf:"bytes,13,opt,name=id" json:"id,omitempty"` - // Note: Regarding to the consistency with OpenConfig mode, list of + // Note: Regarding to the consistency with OpenConfig model, list of // PrefixLimit should be removed from here, and list of PrefixLimit in // AfiSafi should be used instead. PrefixLimits []*PrefixLimit `protobuf:"bytes,14,rep,name=prefix_limits,json=prefixLimits" json:"prefix_limits,omitempty"` diff --git a/api/gobgp.proto b/api/gobgp.proto index dd58e003..39dc1b52 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -623,6 +623,9 @@ message ValidateRibResponse { } message Peer { + // Note: Regarding to the consistency with OpenConfig model, a list of + // address family should be removed from here, and should be configured with + // the list of AfiSafi instead. repeated uint32 families = 1; ApplyPolicy apply_policy = 2; PeerConf conf = 3; @@ -668,7 +671,7 @@ message PeerConf { repeated bytes remote_cap = 11; repeated bytes local_cap = 12; string id = 13; - // Note: Regarding to the consistency with OpenConfig mode, list of + // Note: Regarding to the consistency with OpenConfig model, list of // PrefixLimit should be removed from here, and list of PrefixLimit in // AfiSafi should be used instead. repeated PrefixLimit prefix_limits = 14; diff --git a/api/grpc_server.go b/api/grpc_server.go index 21b9d260..18e4e4d4 100644 --- a/api/grpc_server.go +++ b/api/grpc_server.go @@ -1033,9 +1033,18 @@ func ReadAfiSafiConfigFromAPIStruct(c *config.AfiSafiConfig, a *AfiSafiConfig) { if c == nil || a == nil { return } + c.AfiSafiName = config.AfiSafiType(bgp.RouteFamily(a.Family).String()) c.Enabled = a.Enabled } +func ReadAfiSafiStateFromAPIStruct(s *config.AfiSafiState, a *AfiSafiConfig) { + if s == nil || a == nil { + return + } + // Store only address family value for the convenience + s.Family = bgp.RouteFamily(a.Family) +} + func ReadPrefixLimitFromAPIStruct(c *config.PrefixLimit, a *PrefixLimit) { if c == nil || a == nil { return @@ -1182,32 +1191,53 @@ func NewNeighborFromAPIStruct(a *Peer) (*config.Neighbor, error) { pconf.State.RemoteRouterId = a.Conf.Id + for _, af := range a.AfiSafis { + afiSafi := config.AfiSafi{} + ReadMpGracefulRestartFromAPIStruct(&afiSafi.MpGracefulRestart, af.MpGracefulRestart) + ReadAfiSafiConfigFromAPIStruct(&afiSafi.Config, af.Config) + ReadAfiSafiStateFromAPIStruct(&afiSafi.State, af.Config) + ReadApplyPolicyFromAPIStruct(&afiSafi.ApplyPolicy, af.ApplyPolicy) + ReadRouteSelectionOptionsFromAPIStruct(&afiSafi.RouteSelectionOptions, af.RouteSelectionOptions) + ReadUseMultiplePathsFromAPIStruct(&afiSafi.UseMultiplePaths, af.UseMultiplePaths) + ReadPrefixLimitFromAPIStruct(&afiSafi.PrefixLimit, af.PrefixLimits) + ReadRouteTargetMembershipFromAPIStruct(&afiSafi.RouteTargetMembership, af.RouteTargetMembership) + ReadLongLivedGracefulRestartFromAPIStruct(&afiSafi.LongLivedGracefulRestart, af.LongLivedGracefulRestart) + ReadAddPathsFromAPIStruct(&afiSafi.AddPaths, af.AddPaths) + pconf.AfiSafis = append(pconf.AfiSafis, afiSafi) + } + // For the backward compatibility, we override AfiSafi configurations + // with Peer.Families. for _, family := range a.Families { - afiSafi := config.AfiSafi{ - Config: config.AfiSafiConfig{ - AfiSafiName: config.AfiSafiType(bgp.RouteFamily(family).String()), - Enabled: true, - }, - } - for _, pl := range a.Conf.PrefixLimits { - if family == pl.Family { - ReadPrefixLimitFromAPIStruct(&afiSafi.PrefixLimit, pl) + found := false + for _, afiSafi := range pconf.AfiSafis { + if uint32(afiSafi.State.Family) == family { + // If Peer.Families contains the same address family, + // we enable this address family. + afiSafi.Config.Enabled = true + found = true } } - for _, a := range a.AfiSafis { - if a.Config != nil && family == a.Config.Family { - ReadMpGracefulRestartFromAPIStruct(&afiSafi.MpGracefulRestart, a.MpGracefulRestart) - ReadAfiSafiConfigFromAPIStruct(&afiSafi.Config, a.Config) - ReadApplyPolicyFromAPIStruct(&afiSafi.ApplyPolicy, a.ApplyPolicy) - ReadRouteSelectionOptionsFromAPIStruct(&afiSafi.RouteSelectionOptions, a.RouteSelectionOptions) - ReadUseMultiplePathsFromAPIStruct(&afiSafi.UseMultiplePaths, a.UseMultiplePaths) - ReadPrefixLimitFromAPIStruct(&afiSafi.PrefixLimit, a.PrefixLimits) - ReadRouteTargetMembershipFromAPIStruct(&afiSafi.RouteTargetMembership, a.RouteTargetMembership) - ReadLongLivedGracefulRestartFromAPIStruct(&afiSafi.LongLivedGracefulRestart, a.LongLivedGracefulRestart) - ReadAddPathsFromAPIStruct(&afiSafi.AddPaths, a.AddPaths) + if !found { + // If Peer.Families does not contain the same address family, + // we append AfiSafi structure with the default value. + pconf.AfiSafis = append(pconf.AfiSafis, config.AfiSafi{ + Config: config.AfiSafiConfig{ + AfiSafiName: config.AfiSafiType(bgp.RouteFamily(family).String()), + Enabled: true, + }, + }) + } + } + // For the backward compatibility, we override AfiSafi configurations + // with Peer.Conf.PrefixLimits. + for _, prefixLimit := range a.Conf.PrefixLimits { + for _, afiSafi := range pconf.AfiSafis { + // If Peer.Conf.PrefixLimits contains the configuration for + // the same address family, we override AfiSafi.PrefixLimit. + if uint32(afiSafi.State.Family) == prefixLimit.Family { + ReadPrefixLimitFromAPIStruct(&afiSafi.PrefixLimit, prefixLimit) } } - pconf.AfiSafis = append(pconf.AfiSafis, afiSafi) } } -- cgit v1.2.3