コード例 #1
0
ファイル: client.go プロジェクト: osrg/gobgp
func (cli *GoBGPClient) getNeighbor(name string, afi int, vrf string) ([]*config.Neighbor, error) {
	ret, err := cli.cli.GetNeighbor(context.Background(), &api.GetNeighborRequest{EnableAdvertised: name != ""})
	if err != nil {
		return nil, err
	}

	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
		}
		neighbors = append(neighbors, n)
	}
	return neighbors, nil
}
コード例 #2
0
ファイル: client.go プロジェクト: osrg/gobgp
func (c *MonitorNeighborStateClient) Recv() (*config.Neighbor, error) {
	p, err := c.stream.Recv()
	if err != nil {
		return nil, err
	}
	return api.NewNeighborFromAPIStruct(p)
}