diff options
author | Naoto Hanaue <hanaue.naoto@po.ntts.co.jp> | 2016-02-01 20:28:14 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-19 21:14:59 -0800 |
commit | bbd5a2cfae44425f026b8a4567367450cb96d8f4 (patch) | |
tree | 565e6eeba030df4cb07435f73d342cd8e7cce318 /openswitch/openswitch.go | |
parent | 4e03f6ae684b820a12c2b360b95d9ca19a23012d (diff) |
ops: add feature that monitoring route of gobgp
Diffstat (limited to 'openswitch/openswitch.go')
-rw-r--r-- | openswitch/openswitch.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/openswitch/openswitch.go b/openswitch/openswitch.go index 007b8178..4ed77f47 100644 --- a/openswitch/openswitch.go +++ b/openswitch/openswitch.go @@ -239,6 +239,12 @@ func (m *OpsManager) handleNeighborUpdate(update ovsdb.TableUpdate) []*server.Gr } func (m *OpsManager) Serve() error { + go m.OpsServe() + go m.GobgpServe() + return nil +} + +func (m *OpsManager) OpsServe() error { initial, err := m.client.MonitorAll("OpenSwitch", "") if err != nil { return err @@ -297,6 +303,42 @@ func (m *OpsManager) Serve() error { return nil } +func (m *OpsManager) GobgpServe() error { + family := bgp.RF_IPv4_UC + arg := &api.Arguments{ + Resource: api.Resource_GLOBAL, + Family: uint32(family), + } + + stream, err := client.MonitorBestChanged(context.Background(), arg) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + for { + d, err := stream.Recv() + if err == io.EOF { + break + } else if err != nil { + fmt.Println(err) + os.Exit(1) + } + p, err := ApiStruct2Path(d.Paths[0]) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + if globalOpts.Json { + j, _ := json.Marshal(p) + fmt.Println(string(j)) + } else { + ShowRoute(p, false, false, false, true, false) + } + } + return nil +} + func NewOpsManager(ch chan *server.GrpcRequest) (*OpsManager, error) { cli, err := ovsdb.ConnectUnix("") if err != nil { |