summaryrefslogtreecommitdiffhomepage
path: root/client/client.go
diff options
context:
space:
mode:
authorWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-11-12 12:50:28 +0000
committerWataru Ishida <ishida.wataru@lab.ntt.co.jp>2016-11-14 02:15:48 +0000
commitee8ce99e2df1f732ef515e20fb3054c0cff0249b (patch)
tree56f8c51a7100e0864edc01396154dcd592e358e3 /client/client.go
parent1e22e529c92fe7b2e1576ceea96d827f16a76654 (diff)
client: support neighbor filtering
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'client/client.go')
-rw-r--r--client/client.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/client/client.go b/client/client.go
index 53a822c5..7a7b4606 100644
--- a/client/client.go
+++ b/client/client.go
@@ -97,7 +97,7 @@ func (cli *GoBGPClient) GetServer() (*config.Global, error) {
}, nil
}
-func (cli *GoBGPClient) GetNeighbor() ([]*config.Neighbor, error) {
+func (cli *GoBGPClient) getNeighbor(name string, afi int, vrf string) ([]*config.Neighbor, error) {
ret, err := cli.cli.GetNeighbor(context.Background(), &api.GetNeighborRequest{})
if err != nil {
return nil, err
@@ -106,6 +106,18 @@ func (cli *GoBGPClient) GetNeighbor() ([]*config.Neighbor, error) {
neighbors := make([]*config.Neighbor, 0, len(ret.Peers))
for _, p := range ret.Peers {
+ if name != "" && name != p.Conf.NeighborAddress {
+ continue
+ }
+ if vrf != "" && name != p.Conf.Vrf {
+ continue
+ }
+ if afi > 0 {
+ v6 := net.ParseIP(p.Conf.NeighborAddress).To4() == nil
+ if afi == bgp.AFI_IP && v6 || afi == bgp.AFI_IP6 && !v6 {
+ continue
+ }
+ }
n, err := api.NewNeighborFromAPIStruct(p)
if err != nil {
return nil, err
@@ -115,6 +127,26 @@ func (cli *GoBGPClient) GetNeighbor() ([]*config.Neighbor, error) {
return neighbors, nil
}
+func (cli *GoBGPClient) ListNeighbor() ([]*config.Neighbor, error) {
+ return cli.getNeighbor("", 0, "")
+}
+
+func (cli *GoBGPClient) ListNeighborByTransport(afi int) ([]*config.Neighbor, error) {
+ return cli.getNeighbor("", afi, "")
+}
+
+func (cli *GoBGPClient) ListNeighborByVRF(vrf string) ([]*config.Neighbor, error) {
+ return cli.getNeighbor("", 0, vrf)
+}
+
+func (cli *GoBGPClient) GetNeighbor(name string) (*config.Neighbor, error) {
+ ns, err := cli.getNeighbor(name, 0, "")
+ if err != nil {
+ return nil, err
+ }
+ return ns[0], nil
+}
+
func (cli *GoBGPClient) AddNeighbor(c *config.Neighbor) error {
peer := api.NewPeerFromConfigStruct(c)
_, err := cli.cli.AddNeighbor(context.Background(), &api.AddNeighborRequest{peer})