コード例 #1
0
ファイル: client.go プロジェクト: osrg/gobgp
func (cli *GoBGPClient) GetPolicy() ([]*table.Policy, error) {
	ret, err := cli.cli.GetPolicy(context.Background(), &api.GetPolicyRequest{})
	if err != nil {
		return nil, err
	}
	pols := make([]*table.Policy, 0, len(ret.Policies))
	for _, p := range ret.Policies {
		pol, err := api.NewPolicyFromApiStruct(p)
		if err != nil {
			return nil, err
		}
		pols = append(pols, pol)
	}
	return pols, nil
}
コード例 #2
0
ファイル: client.go プロジェクト: osrg/gobgp
func (cli *GoBGPClient) getPolicyAssignment(name string, dir table.PolicyDirection) (*table.PolicyAssignment, error) {
	var typ api.PolicyType
	switch dir {
	case table.POLICY_DIRECTION_IN:
		typ = api.PolicyType_IN
	case table.POLICY_DIRECTION_IMPORT:
		typ = api.PolicyType_IMPORT
	case table.POLICY_DIRECTION_EXPORT:
		typ = api.PolicyType_EXPORT
	}
	resource := api.Resource_GLOBAL
	if name != "" {
		resource = api.Resource_LOCAL
	}

	ret, err := cli.cli.GetPolicyAssignment(context.Background(), &api.GetPolicyAssignmentRequest{
		Assignment: &api.PolicyAssignment{
			Name:     name,
			Resource: resource,
			Type:     typ,
		},
	})
	if err != nil {
		return nil, err
	}

	def := table.ROUTE_TYPE_ACCEPT
	if ret.Assignment.Default == api.RouteAction_REJECT {
		def = table.ROUTE_TYPE_REJECT
	}

	pols := make([]*table.Policy, 0, len(ret.Assignment.Policies))
	for _, p := range ret.Assignment.Policies {
		pol, err := api.NewPolicyFromApiStruct(p)
		if err != nil {
			return nil, err
		}
		pols = append(pols, pol)
	}
	return &table.PolicyAssignment{
		Name:     name,
		Type:     dir,
		Policies: pols,
		Default:  def,
	}, nil
}