diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-24 13:20:12 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-25 18:20:48 +0900 |
commit | b38d3f672303cbceaebc05d9711307ba2c9f06dc (patch) | |
tree | b91a4231b44d990621c54e9d4fbd454b4bce1103 | |
parent | 72113e364524297ab1caf62c8c62f0a4ff228849 (diff) |
zebra: enable to redistribute specific route type
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | server/server.go | 19 | ||||
-rw-r--r-- | test/scenario_test/lib/gobgp.py | 7 | ||||
-rw-r--r-- | test/scenario_test/lib/quagga.py | 4 | ||||
-rw-r--r-- | zebra/zapi.go | 43 |
4 files changed, 57 insertions, 16 deletions
diff --git a/server/server.go b/server/server.go index a147580c..a989e48d 100644 --- a/server/server.go +++ b/server/server.go @@ -171,7 +171,11 @@ func (server *BgpServer) Serve() { if g.Zebra.Url == "" { g.Zebra.Url = "unix:/var/run/quagga/zserv.api" } - err := server.NewZclient(g.Zebra.Url) + redists := make([]string, 0, len(g.Zebra.RedistributeRouteTypeList)) + for _, t := range g.Zebra.RedistributeRouteTypeList { + redists = append(redists, t.RouteType) + } + err := server.NewZclient(g.Zebra.Url, redists) if err != nil { log.Error(err) } @@ -2475,7 +2479,7 @@ func (server *BgpServer) mkMrtRibMsgs(tbl *table.Table, t uint32) ([]*bgp.MRTMes return msgs, nil } -func (server *BgpServer) NewZclient(url string) error { +func (server *BgpServer) NewZclient(url string, redistRouteTypes []string) error { l := strings.SplitN(url, ":", 2) if len(l) != 2 { return fmt.Errorf("unsupported url: %s", url) @@ -2487,7 +2491,16 @@ func (server *BgpServer) NewZclient(url string) error { cli.SendHello() cli.SendRouterIDAdd() cli.SendInterfaceAdd() - cli.SendRedistribute() + for _, typ := range redistRouteTypes { + t, err := zebra.RouteTypeFromString(typ) + if err != nil { + return err + } + cli.SendRedistribute(t) + } + if e := cli.SendCommand(zebra.REDISTRIBUTE_DEFAULT_ADD, nil); e != nil { + return e + } server.zclient = cli return nil } diff --git a/test/scenario_test/lib/gobgp.py b/test/scenario_test/lib/gobgp.py index 445c4205..f126047d 100644 --- a/test/scenario_test/lib/gobgp.py +++ b/test/scenario_test/lib/gobgp.py @@ -275,7 +275,8 @@ class GoBGPContainer(BGPContainer): config['PolicyDefinitions'] = {'PolicyDefinitionList': policy_list} if self.zebra: - config['Global']['Zebra'] = {'Enabled': True} + config['Global']['Zebra'] = {'Enabled': True, + 'RedistributeRouteTypeList':[{'RouteType': 'connect'}],} with open('{0}/gobgpd.conf'.format(self.config_dir), 'w') as f: print colors.yellow('[{0}\'s new config]'.format(self.name)) @@ -287,6 +288,10 @@ class GoBGPContainer(BGPContainer): c << 'hostname zebra' c << 'password zebra' c << 'log file {0}/zebra.log'.format(self.QUAGGA_VOLUME) + c << 'debug zebra packet' + c << 'debug zebra kernel' + c << 'debug zebra rib' + c << '' with open('{0}/zebra.conf'.format(self.config_dir), 'w') as f: print colors.yellow('[{0}\'s new config]'.format(self.name)) diff --git a/test/scenario_test/lib/quagga.py b/test/scenario_test/lib/quagga.py index 3cd29618..f36b56a8 100644 --- a/test/scenario_test/lib/quagga.py +++ b/test/scenario_test/lib/quagga.py @@ -225,6 +225,10 @@ class QuaggaBGPContainer(BGPContainer): c << 'hostname zebra' c << 'password zebra' c << 'log file {0}/zebra.log'.format(self.SHARED_VOLUME) + c << 'debug zebra packet' + c << 'debug zebra kernel' + c << 'debug zebra rib' + c << '' with open('{0}/zebra.conf'.format(self.config_dir), 'w') as f: print colors.yellow('[{0}\'s new config]'.format(self.name)) diff --git a/zebra/zapi.go b/zebra/zapi.go index da0c9e94..09b9107a 100644 --- a/zebra/zapi.go +++ b/zebra/zapi.go @@ -117,6 +117,30 @@ const ( ROUTE_MAX ) +var routeTypeValueMap = map[string]ROUTE_TYPE{ + "system": ROUTE_SYSTEM, + "kernel": ROUTE_KERNEL, + "connect": ROUTE_CONNECT, + "static": ROUTE_STATIC, + "rip": ROUTE_RIP, + "ripng": ROUTE_RIPNG, + "ospf": ROUTE_OSPF, + "ospf3": ROUTE_OSPF6, + "isis": ROUTE_ISIS, + "bgp": ROUTE_BGP, + "hsls": ROUTE_HSLS, + "olsr": ROUTE_OLSR, + "babel": ROUTE_BABEL, +} + +func RouteTypeFromString(typ string) (ROUTE_TYPE, error) { + t, ok := routeTypeValueMap[typ] + if ok { + return t, nil + } + return t, fmt.Errorf("unknown route type: %s", typ) +} + const ( MESSAGE_NEXTHOP = 0x01 MESSAGE_IFINDEX = 0x02 @@ -309,21 +333,16 @@ func (c *Client) SendInterfaceAdd() error { return c.SendCommand(INTERFACE_ADD, nil) } -func (c *Client) SendRedistribute() error { - for i := ROUTE_SYSTEM; i < ROUTE_MAX; i++ { - if c.redistDefault != i { - body := &RedistributeBody{ - Redist: i, - } - if e := c.SendCommand(REDISTRIBUTE_ADD, body); e != nil { - return e - } +func (c *Client) SendRedistribute(t ROUTE_TYPE) error { + if c.redistDefault != t { + body := &RedistributeBody{ + Redist: t, + } + if e := c.SendCommand(REDISTRIBUTE_ADD, body); e != nil { + return e } } - if e := c.SendCommand(REDISTRIBUTE_DEFAULT_ADD, nil); e != nil { - return e - } return nil } |