Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ygnmi #231

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bgp/gobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ func (t *bgpDeclTask) startGoBGPFuncDecl(_ context.Context, yclient *ygnmi.Clien
// BGP Policy paths
RoutingPolicyPath.DefinedSets().PrefixSetAny().PrefixAny().IpPrefix().Config().PathStruct(),
RoutingPolicyPath.DefinedSets().PrefixSetAny().PrefixAny().MasklengthRange().Config().PathStruct(),
RoutingPolicyPath.PolicyDefinitionAny().StatementAny().Conditions().MatchPrefixSet().PrefixSet().Config().PathStruct(),
RoutingPolicyPath.PolicyDefinitionAny().StatementAny().Conditions().MatchPrefixSet().MatchSetOptions().Config().PathStruct(),
RoutingPolicyPath.PolicyDefinitionAny().StatementAny().Actions().PolicyResult().Config().PathStruct(),
RoutingPolicyPath.PolicyDefinitionAny().StatementMap().Config().PathStruct(),
BGPPath.NeighborAny().ApplyPolicy().DefaultImportPolicy().Config().PathStruct(),
BGPPath.NeighborAny().ApplyPolicy().DefaultExportPolicy().Config().PathStruct(),
BGPPath.NeighborAny().ApplyPolicy().ImportPolicy().Config().PathStruct(),
Expand Down
2 changes: 1 addition & 1 deletion bgp/ocgobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func convertPolicyNames(neighAddr string, ocPolicyNames []string) []string {
// single apply-policy list.
func convertPolicyDefinition(policy *oc.RoutingPolicy_PolicyDefinition, neighAddr string) bgpconfig.PolicyDefinition {
var statements []bgpconfig.Statement
for _, statement := range policy.Statement {
for _, statement := range policy.Statement.Values() {
statements = append(statements, bgpconfig.Statement{
Name: statement.GetName(),
Conditions: bgpconfig.Conditions{
Expand Down
2 changes: 1 addition & 1 deletion bgp/tests/local_tests/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func testPolicy(t *testing.T, testspec PolicyTestCase, installPolicyAfterRoutes
establishSessionPair(t, dut2, dut3, dut2spec, dut3spec)

for _, routeTest := range testspec.spec.RouteTests {
// Install both prefixes into DUT2.
// Install all test routes into DUT1.
route := &oc.NetworkInstance_Protocol_Static{
Prefix: ygot.String(routeTest.GetInput().GetReachPrefix()),
NextHop: map[string]*oc.NetworkInstance_Protocol_Static_NextHop{
Expand Down
12 changes: 9 additions & 3 deletions bgp/tests/local_tests/prefix_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ func TestPrefixSet(t *testing.T) {
Replace(t, dut2, prefix1Path.Config(), prefix1)

policyName := "def1"
Replace(t, dut2, ocpath.Root().RoutingPolicy().PolicyDefinition(policyName).Statement("stmt1").Conditions().MatchPrefixSet().PrefixSet().Config(), prefixSetName)
Replace(t, dut2, ocpath.Root().RoutingPolicy().PolicyDefinition(policyName).Statement("stmt1").Conditions().MatchPrefixSet().MatchSetOptions().Config(), oc.RoutingPolicy_MatchSetOptionsRestrictedType_ANY)
Replace(t, dut2, ocpath.Root().RoutingPolicy().PolicyDefinition(policyName).Statement("stmt1").Actions().PolicyResult().Config(), oc.RoutingPolicy_PolicyResultType_REJECT_ROUTE)
policy := &oc.RoutingPolicy_PolicyDefinition_Statement_OrderedMap{}
stmt, err := policy.AppendNew("stmt1")
if err != nil {
t.Fatalf("Cannot append new BGP policy statement: %v", err)
}
stmt.GetOrCreateConditions().GetOrCreateMatchPrefixSet().SetPrefixSet(prefixSetName)
stmt.GetOrCreateConditions().GetOrCreateMatchPrefixSet().SetMatchSetOptions(oc.RoutingPolicy_MatchSetOptionsRestrictedType_ANY)
stmt.GetOrCreateActions().SetPolicyResult(oc.RoutingPolicy_PolicyResultType_REJECT_ROUTE)
Replace(t, dut2, ocpath.Root().RoutingPolicy().PolicyDefinition(policyName).Config(), &oc.RoutingPolicy_PolicyDefinition{Statement: policy})
Replace(t, dut2, bgp.BGPPath.Neighbor(dut3spec.RouterID).ApplyPolicy().ExportPolicy().Config(), []string{policyName})
},
}
Expand Down
5 changes: 4 additions & 1 deletion bgp/tests/local_tests/ygnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ func isContextErr(err error) bool {
GRPCStatus() *status.Status
}
ok := errors.As(err, &st)
return ok && (st.GRPCStatus().Code() == codes.DeadlineExceeded || st.GRPCStatus().Code() == codes.Canceled)
if !ok {
return errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled)
}
return st.GRPCStatus().Code() == codes.DeadlineExceeded || st.GRPCStatus().Code() == codes.Canceled
}

// Await waits for the watch to finish and returns the last received value
Expand Down
1 change: 1 addition & 0 deletions gnmi/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ go run github.com/openconfig/ygnmi/app/ygnmi generator \
--trim_module_prefix=openconfig \
--exclude_modules="${EXCLUDE_MODULES}" \
--base_package_path=github.com/openconfig/lemming/gnmi/oc \
--split_package_paths="/network-instances/network-instance/protocols/protocol/isis=netinstisis,/network-instances/network-instance/protocols/protocol/bgp=netinstbgp" \
--output_dir=oc \
--paths=public/release/models/...,public/third_party/ietf/...,gnsi/... \
"${YANG_FILES[@]}"
Expand Down
7 changes: 0 additions & 7 deletions gnmi/gnmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,6 @@ func TestSetYGNMI(t *testing.T) {
return err
},
wantErr: `"24" does not match regular expression pattern`,
}, {
desc: "fail due to value restriction",
inOp: func(c *ygnmi.Client) error {
_, err := ygnmi.Update(context.Background(), c, ocpath.Root().RoutingPolicy().PolicyDefinition("test").Statement("test").Actions().BgpActions().SetAsPathPrepend().RepeatN().Config(), 0)
return err
},
wantErr: "value 0 is outside specified ranges",
}}

gnmiServer, err := newServer(context.Background(), "local", true)
Expand Down
Loading