Example #1
0
File: client.go Project: osrg/gobgp
func (c *AddPathByStreamClient) Send(paths ...*table.Path) error {
	ps := make([]*api.Path, 0, len(paths))
	for _, p := range paths {
		ps = append(ps, api.ToPathApi(p))
	}
	return c.stream.Send(&api.InjectMrtRequest{
		Resource: api.Resource_GLOBAL,
		Paths:    ps,
	})
}
Example #2
0
File: path.go Project: osrg/gobgp
//export serialize_path
func serialize_path(rf C.int, input *C.char) *C.path {
	args := strings.Split(C.GoString(input), " ")
	pp, err := cmd.ParsePath(bgp.RouteFamily(rf), args)
	if err != nil {
		return nil
	}
	path := C.new_path()
	p := api.ToPathApi(pp)
	if len(p.Nlri) > 0 {
		path.nlri.len = C.int(len(p.Nlri))
		path.nlri.value = C.CString(string(p.Nlri))
	}
	for _, attr := range p.Pattrs {
		C.append_path_attribute(path, C.int(len(attr)), C.CString(string(attr)))
	}
	return path
}
Example #3
0
File: client.go Project: osrg/gobgp
func (cli *GoBGPClient) addPath(vrfID string, pathList []*table.Path) ([]byte, error) {
	resource := api.Resource_GLOBAL
	if vrfID != "" {
		resource = api.Resource_VRF
	}
	var uuid []byte
	for _, path := range pathList {
		r, err := cli.cli.AddPath(context.Background(), &api.AddPathRequest{
			Resource: resource,
			VrfId:    vrfID,
			Path:     api.ToPathApi(path),
		})
		if err != nil {
			return nil, err
		}
		uuid = r.Uuid
	}
	return uuid, nil
}