diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2017-11-09 10:04:13 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-11-16 09:59:45 +0900 |
commit | f32673bbec2541226657653af1042d0500a52d00 (patch) | |
tree | a7a603a77328fdc36ec5aa388119c424a2f72de3 /api/grpc_server.go | |
parent | 6c6cd6efad2cf0201a6bf4665e3a647cc07b6bbc (diff) |
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 <iwase.yusuke0@gmail.com>
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r-- | api/grpc_server.go | 72 |
1 files changed, 51 insertions, 21 deletions
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) } } |