summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-05-17 08:50:55 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-05-17 08:52:28 +0900
commit8fd25af4ce9ab902e24eb06644ef2e9c42cee7e0 (patch)
treefca38cf5df338ca0abae36c4579fb551fef2a66d
parent949c58fbf6d5ccb79ee87a5105968d3fe591a3a9 (diff)
zebra: make zebra config consistent with the rests
- split config and state - move to Bgp structure (aligned with Rpki, Bmp, and Mrt) Also makes zebra configured via GRPC channel. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--config/bgp_configs.go124
-rw-r--r--config/default.go4
-rw-r--r--config/serve.go1
-rw-r--r--docs/sources/configuration.md10
-rw-r--r--docs/sources/zebra.md9
-rw-r--r--gobgpd/main.go3
-rw-r--r--server/grpc_server.go1
-rw-r--r--server/server.go33
-rw-r--r--test/lib/gobgp.py4
-rw-r--r--tools/pyang_plugins/gobgp.yang44
10 files changed, 160 insertions, 73 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go
index 57866339..2054efec 100644
--- a/config/bgp_configs.go
+++ b/config/bgp_configs.go
@@ -870,6 +870,88 @@ func (v RpkiValidationResultType) Validate() error {
return nil
}
+//struct for container gobgp:state
+type ZebraState struct {
+ // original -> gobgp:enabled
+ //gobgp:enabled's original type is boolean
+ Enabled bool `mapstructure:"enabled"`
+ // original -> gobgp:url
+ Url string `mapstructure:"url"`
+ // original -> gobgp:redistribute-route-type
+ RedistributeRouteTypeList []InstallProtocolType `mapstructure:"redistribute-route-type-list"`
+}
+
+func (lhs *ZebraState) Equal(rhs *ZebraState) bool {
+ if lhs == nil || rhs == nil {
+ return false
+ }
+ if lhs.Enabled != rhs.Enabled {
+ return false
+ }
+ if lhs.Url != rhs.Url {
+ return false
+ }
+ if len(lhs.RedistributeRouteTypeList) != len(rhs.RedistributeRouteTypeList) {
+ return false
+ }
+ for idx, l := range lhs.RedistributeRouteTypeList {
+ if l != rhs.RedistributeRouteTypeList[idx] {
+ return false
+ }
+ }
+ return true
+}
+
+//struct for container gobgp:config
+type ZebraConfig struct {
+ // original -> gobgp:enabled
+ //gobgp:enabled's original type is boolean
+ Enabled bool `mapstructure:"enabled"`
+ // original -> gobgp:url
+ Url string `mapstructure:"url"`
+ // original -> gobgp:redistribute-route-type
+ RedistributeRouteTypeList []InstallProtocolType `mapstructure:"redistribute-route-type-list"`
+}
+
+func (lhs *ZebraConfig) Equal(rhs *ZebraConfig) bool {
+ if lhs == nil || rhs == nil {
+ return false
+ }
+ if lhs.Enabled != rhs.Enabled {
+ return false
+ }
+ if lhs.Url != rhs.Url {
+ return false
+ }
+ if len(lhs.RedistributeRouteTypeList) != len(rhs.RedistributeRouteTypeList) {
+ return false
+ }
+ for idx, l := range lhs.RedistributeRouteTypeList {
+ if l != rhs.RedistributeRouteTypeList[idx] {
+ return false
+ }
+ }
+ return true
+}
+
+//struct for container gobgp:zebra
+type Zebra struct {
+ // original -> gobgp:zebra-config
+ Config ZebraConfig `mapstructure:"config"`
+ // original -> gobgp:zebra-state
+ State ZebraState `mapstructure:"state"`
+}
+
+func (lhs *Zebra) Equal(rhs *Zebra) bool {
+ if lhs == nil || rhs == nil {
+ return false
+ }
+ if !lhs.Config.Equal(&(rhs.Config)) {
+ return false
+ }
+ return true
+}
+
//struct for container gobgp:mrt
type Mrt struct {
// original -> gobgp:dump-type
@@ -2470,38 +2552,6 @@ func (lhs *MplsLabelRange) Equal(rhs *MplsLabelRange) bool {
return true
}
-//struct for container gobgp:zebra
-type Zebra struct {
- // original -> gobgp:enabled
- //gobgp:enabled's original type is boolean
- Enabled bool `mapstructure:"enabled"`
- // original -> gobgp:url
- Url string `mapstructure:"url"`
- // original -> gobgp:redistribute-route-type
- RedistributeRouteTypeList []InstallProtocolType `mapstructure:"redistribute-route-type-list"`
-}
-
-func (lhs *Zebra) Equal(rhs *Zebra) bool {
- if lhs == nil || rhs == nil {
- return false
- }
- if lhs.Enabled != rhs.Enabled {
- return false
- }
- if lhs.Url != rhs.Url {
- return false
- }
- if len(lhs.RedistributeRouteTypeList) != len(rhs.RedistributeRouteTypeList) {
- return false
- }
- for idx, l := range lhs.RedistributeRouteTypeList {
- if l != rhs.RedistributeRouteTypeList[idx] {
- return false
- }
- }
- return true
-}
-
//struct for container gobgp:state
type RouteTargetMembershipState struct {
// original -> gobgp:deferral-time
@@ -3881,8 +3931,6 @@ type Global struct {
AfiSafis []AfiSafi `mapstructure:"afi-safis"`
// original -> rpol:apply-policy
ApplyPolicy ApplyPolicy `mapstructure:"apply-policy"`
- // original -> gobgp:zebra
- Zebra Zebra `mapstructure:"zebra"`
// original -> gobgp:mpls-label-range
MplsLabelRange MplsLabelRange `mapstructure:"mpls-label-range"`
}
@@ -3928,9 +3976,6 @@ func (lhs *Global) Equal(rhs *Global) bool {
if !lhs.ApplyPolicy.Equal(&(rhs.ApplyPolicy)) {
return false
}
- if !lhs.Zebra.Equal(&(rhs.Zebra)) {
- return false
- }
if !lhs.MplsLabelRange.Equal(&(rhs.MplsLabelRange)) {
return false
}
@@ -3951,6 +3996,8 @@ type Bgp struct {
BmpServers []BmpServer `mapstructure:"bmp-servers"`
// original -> gobgp:mrt-dump
MrtDump []Mrt `mapstructure:"mrt-dump"`
+ // original -> gobgp:zebra
+ Zebra Zebra `mapstructure:"zebra"`
}
func (lhs *Bgp) Equal(rhs *Bgp) bool {
@@ -4040,6 +4087,9 @@ func (lhs *Bgp) Equal(rhs *Bgp) bool {
}
}
}
+ if !lhs.Zebra.Equal(&(rhs.Zebra)) {
+ return false
+ }
return true
}
diff --git a/config/default.go b/config/default.go
index 24dc08c7..02ec5784 100644
--- a/config/default.go
+++ b/config/default.go
@@ -34,8 +34,8 @@ func SetDefaultConfigValues(v *viper.Viper, b *BgpConfigSet) error {
}
}
- if b.Global.Zebra.Url == "" {
- b.Global.Zebra.Url = "unix:/var/run/quagga/zserv.api"
+ if b.Zebra.Config.Url == "" {
+ b.Zebra.Config.Url = "unix:/var/run/quagga/zserv.api"
}
if len(b.Global.AfiSafis) == 0 {
diff --git a/config/serve.go b/config/serve.go
index 70a4e896..a8f67725 100644
--- a/config/serve.go
+++ b/config/serve.go
@@ -15,6 +15,7 @@ type BgpConfigSet struct {
RpkiServers []RpkiServer `mapstructure:"rpki-servers"`
BmpServers []BmpServer `mapstructure:"bmp-servers"`
MrtDump []Mrt `mapstructure:"mrt-dump"`
+ Zebra Zebra `mapstructure:"zebra"`
DefinedSets DefinedSets `mapstructure:"defined-sets"`
PolicyDefinitions []PolicyDefinition `mapstructure:"policy-definitions"`
}
diff --git a/docs/sources/configuration.md b/docs/sources/configuration.md
index 44830c58..ef2025c0 100644
--- a/docs/sources/configuration.md
+++ b/docs/sources/configuration.md
@@ -17,10 +17,6 @@
default-import-policy = "reject-route"
export-policy-list = ["policy2"]
default-export-policy = "accept-route"
- [global.zebra]
- enabled = true
- url = "unix:/var/run/quagga/zserv.api"
- redistribute-route-type-list = ["connect"]
[global.mpls-label-range]
min-label = 1000
max-label = 2000
@@ -40,6 +36,12 @@
file-name = "/tmp/log/2006/01/02.1504.dump"
interval = 180
+[zebra]
+ [zebra.config]
+ enabled = true
+ url = "unix:/var/run/quagga/zserv.api"
+ redistribute-route-type-list = ["connect"]
+
[[neighbors]]
[neighbors.config]
peer-as = 2
diff --git a/docs/sources/zebra.md b/docs/sources/zebra.md
index 9b1233e1..b5b431d1 100644
--- a/docs/sources/zebra.md
+++ b/docs/sources/zebra.md
@@ -17,10 +17,11 @@ Assume you finished [Getting Started](https://github.com/osrg/gobgp/blob/master/
You need to enable the zebra feature in the Global configuration as follows.
```toml
-[globa.zebra]
- enabled = true
- url = "unix:/var/run/quagga/zserv.api"
- redistribute-route-type-list = ["connect"]
+[zebra]
+ [zebra.config]
+ enabled = true
+ url = "unix:/var/run/quagga/zserv.api"
+ redistribute-route-type-list = ["connect"]
```
You can skip Url. If it's skipped, GoBGP uses "unix:/var/run/quagga/zserv.api" as the Url.
diff --git a/gobgpd/main.go b/gobgpd/main.go
index fc0d6e2c..7a04eef7 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -205,6 +205,9 @@ func main() {
if err := bgpServer.SetGlobalType(newConfig.Global); err != nil {
log.Fatalf("failed to set global config: %s", err)
}
+ if err := bgpServer.SetZebraConfig(newConfig.Zebra); err != nil {
+ log.Fatalf("failed to set zebra config: %s", err)
+ }
if err := bgpServer.SetRpkiConfig(newConfig.RpkiServers); err != nil {
log.Fatalf("failed to set rpki config: %s", err)
}
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 6a4a98cc..e2757d87 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -96,6 +96,7 @@ const (
REQ_BMP_ADJ_IN
REQ_DEFERRAL_TIMER_EXPIRED
REQ_RELOAD_POLICY
+ REQ_INITIALIZE_ZEBRA
)
type Server struct {
diff --git a/server/server.go b/server/server.go
index ce18f2a2..81d678b9 100644
--- a/server/server.go
+++ b/server/server.go
@@ -990,13 +990,21 @@ func (server *BgpServer) SetGlobalType(g config.Global) error {
if err := (<-ch).Err(); err != nil {
return err
}
- if g.Zebra.Enabled {
- cli, err := NewZclient(g.Zebra.Url, g.Zebra.RedistributeRouteTypeList)
- if err != nil {
- return err
- }
- server.zclient = cli
- server.zapiMsgCh = server.zclient.Receive()
+ return nil
+}
+
+func (server *BgpServer) SetZebraConfig(z config.Zebra) error {
+ if !z.Config.Enabled {
+ return nil
+ }
+ ch := make(chan *GrpcResponse)
+ server.GrpcReqCh <- &GrpcRequest{
+ RequestType: REQ_INITIALIZE_ZEBRA,
+ Data: &z.Config,
+ ResponseCh: ch,
+ }
+ if err := (<-ch).Err(); err != nil {
+ return err
}
return nil
}
@@ -2338,6 +2346,17 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg {
ResponseErr: err,
}
close(grpcReq.ResponseCh)
+ case REQ_INITIALIZE_ZEBRA:
+ c := grpcReq.Data.(*config.ZebraConfig)
+ cli, err := NewZclient(c.Url, c.RedistributeRouteTypeList)
+ if err == nil {
+ server.zclient = cli
+ server.zapiMsgCh = server.zclient.Receive()
+ }
+ grpcReq.ResponseCh <- &GrpcResponse{
+ ResponseErr: err,
+ }
+ close(grpcReq.ResponseCh)
default:
err = fmt.Errorf("Unknown request type: %v", grpcReq.RequestType)
goto ERROR
diff --git a/test/lib/gobgp.py b/test/lib/gobgp.py
index 459e2c5f..7faa2198 100644
--- a/test/lib/gobgp.py
+++ b/test/lib/gobgp.py
@@ -327,8 +327,8 @@ class GoBGPContainer(BGPContainer):
config['policy-definitions'] = policy_list
if self.zebra:
- config['global']['zebra'] = {'enabled': True,
- 'redistribute-route-type-list':['connect']}
+ config['zebra'] = {'config':{'enabled': True,
+ 'redistribute-route-type-list':['connect']}}
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/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang
index c15f3bc6..325942f2 100644
--- a/tools/pyang_plugins/gobgp.yang
+++ b/tools/pyang_plugins/gobgp.yang
@@ -775,29 +775,39 @@ module gobgp {
uses gobgp-mrt;
}
- augment "/bgp:bgp/bgp:global" {
- description "zebra configuration";
- container zebra {
- description
- "Configure connection to zebra";
- leaf enabled {
- type boolean;
- description
- "Configure enabling to connect to zebra.";
+ grouping zebra-config {
+ leaf enabled {
+ type boolean;
+ description
+ "Configure enabling to connect to zebra.";
+ }
+ leaf url {
+ type string;
+ description
+ "Configure url for zebra.";
+ }
+ leaf-list redistribute-route-type {
+ type identityref {
+ base ptypes:install-protocol-type;
}
- leaf url {
- type string;
- description
- "Configure url for zebra.";
+ }
+ }
+
+ grouping zebra-set {
+ container zebra {
+ container config {
+ uses zebra-config;
}
- leaf-list redistribute-route-type {
- type identityref {
- base ptypes:install-protocol-type;
- }
+ container state {
+ uses zebra-config;
}
}
}
+ augment "/bgp:bgp" {
+ uses zebra-set;
+ }
+
augment "/bgp:bgp/bgp:global" {
container mpls-label-range {
description "mpls labal range";