diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-26 21:40:16 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-26 21:40:16 +0900 |
commit | d9cbb32c3e917d5a208e58f49785da8fe3863e1c (patch) | |
tree | e0a6460b9ca9c935ab2f947be74185f98e3aa6e2 /server/server.go | |
parent | 96002fd5c4344579b998558b3ad5f929b23ee650 (diff) |
server: add zebra api support to configure linux network stack
Install route information to linux network stack via quagga's zebra.
$ gobgpd --enable-zapi
By default, 'unix:/var/run/quagga/zserv.api' for is used for zapi
endpoint. It's not the case in your environment, use '--zapi-url'
option.
Note that only ipv4 support now.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go index a2f25391..ef0b2ce3 100644 --- a/server/server.go +++ b/server/server.go @@ -23,10 +23,12 @@ import ( "github.com/osrg/gobgp/packet" "github.com/osrg/gobgp/policy" "github.com/osrg/gobgp/table" + zebra "github.com/osrg/gozebra" "gopkg.in/tomb.v2" "net" "os" "strconv" + "strings" "time" ) @@ -76,6 +78,7 @@ type BgpServer struct { broadcastMsgs []broadcastMsg neighborMap map[string]*Peer localRibMap map[string]*LocalRib + zclient *zebra.Client } func NewBgpServer(port int) *BgpServer { @@ -191,6 +194,11 @@ func (server *BgpServer) Serve() { incoming := make(chan *fsmMsg, 4096) var senderMsgs []*SenderMsg + + var zapiMsgCh chan *zebra.Message + if server.zclient != nil { + zapiMsgCh = server.zclient.Recieve() + } for { var firstMsg *SenderMsg var sCh chan *SenderMsg @@ -206,6 +214,8 @@ func (server *BgpServer) Serve() { } select { + case zmsg := <-zapiMsgCh: + handleZapiMsg(zmsg) case conn := <-acceptCh: remoteAddr, _, _ := net.SplitHostPort(conn.RemoteAddr().String()) peer, found := server.neighborMap[remoteAddr] @@ -472,6 +482,11 @@ func applyPolicies(peer *Peer, loc *LocalRib, d Direction, pathList []*table.Pat func (server *BgpServer) broadcastBests(bests []*table.Path) { for _, path := range bests { + z := newBroadcastZapiBestMsg(server.zclient, path) + if z != nil { + server.broadcastMsgs = append(server.broadcastMsgs, z) + } + result := &GrpcResponse{ Data: path.ToApiStruct(), } @@ -2032,3 +2047,17 @@ func (server *BgpServer) mkMrtRibMsgs(rf bgp.RouteFamily, t uint32) ([]*bgp.MRTM } return msgs, nil } + +func (server *BgpServer) NewZclient(url string) error { + l := strings.SplitN(url, ":", 2) + if len(l) != 2 { + return fmt.Errorf("unsupported url: %s", url) + } + cli, err := zebra.NewClient(l[0], l[1], zebra.ROUTE_BGP) + if err != nil { + return err + } + cli.SendHello() + server.zclient = cli + return nil +} |