diff options
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 { |