osrg / gobgp

BGP implemented in the Go Programming Language
https://osrg.github.io/gobgp/
Apache License 2.0
3.66k stars 699 forks source link

ListDefinedSet error: invalid defined-set type #2826

Closed AbhishekRamamurthy closed 3 months ago

AbhishekRamamurthy commented 3 months ago

I'm trying to run ListDefinedSet via API and Command line, I keep getting invalid defined-set type: 0.

Command line:

root@057c3bdb9958:/# ./gobgp policy prefix
rpc error: code = Unknown desc = invalid defined-set type: 0
~/gobgp/cmd/gobgp# git status
HEAD detached at v3.21.0 (tried verion till latest)
nothing to commit, working tree clean
~/gobgp/cmd/gobgp# go build .
~/gobgp/cmd/gobgp# ./gobgp -p 50051 policy prefix add nbr-sv-pf1 10.10.10.0/24 24..32
rpc error: code = Unknown desc = invalid defined-set type: 0
~gobgp/cmd/gobgp#

Sample golang code:

bgpClient, err := bgp.NewGoBGP(ctx, "172.17.0.3", 50051)
    require.NoError(t, err)

    policy := &api.AddPolicyRequest{
        Policy: &api.Policy{
            Name: fmt.Sprintf("%s::%s_prefix", "test", "policy"),
        },
    }
    require.NoError(t, bgpClient.AddPolicy(ctx, policy))

    req := &api.AddDefinedSetRequest{
        DefinedSet: &api.DefinedSet{
            DefinedType: api.DefinedType_PREFIX,
            Name:        fmt.Sprintf("%s::%s_prefix1", "test", "policy"),
            Prefixes: []*api.Prefix{
                {
                    IpPrefix:      "10.1.0.0/24",
                    MaskLengthMax: 24,
                    MaskLengthMin: 29,
                },
            },
        },
    }
    err = bgpClient.AddDefinedSet(ctx, req)
    require.NoError(t, err)

Note: No defined set added, just trying to run the command on against a fresh gobgp daemon.

AbhishekRamamurthy commented 3 months ago

Screenshot 2024-07-29 at 7 22 13 PM

o/p from debugger, looks like RoutingPolicy.definedSetMap is not initialized.

AbhishekRamamurthy commented 3 months ago

looks like without bgp.conf RoutingPolicy.definedSetMap doesn't get initialize. To make it work, started bgpd with a default config.

./gobgpd -f bgp.conf