Skip to content
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: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ buildfile:
bazel run //:gazelle -- update-repos -to_macro=repositories.bzl%go_repositories -from_file=go.mod
bazel run //:gazelle

.PHONY: genprotos
genprotos:
tools/genproto.sh

.PHONY: load-debug
load-debug:
DOCKER_BUILDKIT=1 docker build . --target debug -f Dockerfile.lemming -t "us-west1-docker.pkg.dev/openconfig-lemming/release/lemming:ga"
Expand Down
20 changes: 14 additions & 6 deletions bgp/gobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ func (t *bgpDeclTask) startGoBGPFuncDecl(_ context.Context, yclient *ygnmi.Clien
BGPPath.NeighborAny().PeerAs().Config().PathStruct(),
BGPPath.NeighborAny().NeighborAddress().Config().PathStruct(),
BGPPath.NeighborAny().NeighborPort().Config().PathStruct(),
BGPPath.NeighborAny().Transport().LocalAddress().Config().PathStruct(),
// BGP Policy statements
RoutingPolicyPath.PolicyDefinitionAny().Name().Config().PathStruct(),
RoutingPolicyPath.PolicyDefinitionAny().StatementMap().Config().PathStruct(),
BGPPath.NeighborAny().ApplyPolicy().DefaultImportPolicy().Config().PathStruct(),
BGPPath.NeighborAny().ApplyPolicy().DefaultExportPolicy().Config().PathStruct(),
Expand Down Expand Up @@ -236,7 +238,9 @@ func (t *bgpDeclTask) startGoBGPFuncDecl(_ context.Context, yclient *ygnmi.Clien
}, func(d *api.Destination) {
log.V(1).Infof("%s: GoBGP global table path: %v", t.targetName, d)
}); err != nil {
log.Errorf("GoBGP ListPath call failed (global table): %v", err)
if err.Error() != "bgp server hasn't started yet" {
log.Errorf("GoBGP ListPath call failed (global table): %v", err)
}
} else {
log.V(1).Info("GoBGP ListPath call completed (global table)")
}
Expand All @@ -255,7 +259,7 @@ func (t *bgpDeclTask) startGoBGPFuncDecl(_ context.Context, yclient *ygnmi.Clien
// TODO: For locally-originated routes figure out how to get the originating protocol.
origin = oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_UNSET
} else {
origin = oc.UnionString(path.SourceId)
origin = oc.UnionString(path.NeighborIp)
}
// TODO: this ID should match the ID in adj-rib-in-post.
locRib.GetOrCreateRoute(route.Prefix, origin, uint32(j))
Expand All @@ -272,6 +276,7 @@ func (t *bgpDeclTask) startGoBGPFuncDecl(_ context.Context, yclient *ygnmi.Clien
t.queryTable(neigh, "adj-rib-in", api.TableType_ADJ_IN, func(routes []*api.Destination) {
for _, route := range routes {
for j, path := range route.Paths {
// TODO: this ID should be retrieved from the update message.
neighContainer.GetOrCreateAdjRibInPre().GetOrCreateRoute(route.Prefix, uint32(j))
if !path.Filtered {
neighContainer.GetOrCreateAdjRibInPost().GetOrCreateRoute(route.Prefix, uint32(j))
Expand Down Expand Up @@ -325,7 +330,9 @@ func (t *bgpDeclTask) queryTable(neighbor, tableName string, tableType api.Table
routes = append(routes, d)
log.V(0).Infof("%s: GoBGP %s table path (neighbor if applicable: %q): %v", t.targetName, tableName, neighbor, d)
}); err != nil {
log.Errorf("GoBGP ListPath call failed (%s table): %v", tableType, err)
if err.Error() != "bgp server hasn't started yet" {
log.Errorf("GoBGP ListPath call failed (%s table): %v", tableType, err)
}
} else {
log.V(1).Info("GoBGP ListPath call completed (%s table)", tableName)
f(routes)
Expand Down Expand Up @@ -390,9 +397,10 @@ func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.Routin
bgpConfig.Global.Config.RouterId = global.GetRouterId()
bgpConfig.Global.Config.Port = int32(listenPort)

localAddress := ""
if localAddr, err := netip.ParseAddr(global.GetRouterId()); err == nil && localAddr.IsLoopback() {
localAddress = localAddr.String()
// Have GoBGP listen only on local address instead of all
// addresses when testing BGP server on localhost.
bgpConfig.Global.Config.LocalAddressList = []string{localAddr.String()}
}

for neighAddr, neigh := range bgpoc.Neighbor {
Expand All @@ -415,7 +423,7 @@ func intendedToGoBGP(bgpoc *oc.NetworkInstance_Protocol_Bgp, policyoc *oc.Routin
},
Transport: bgpconfig.Transport{
Config: bgpconfig.TransportConfig{
LocalAddress: localAddress,
LocalAddress: neigh.GetTransport().GetLocalAddress(),
RemotePort: neigh.GetNeighborPort(),
},
},
Expand Down
29 changes: 14 additions & 15 deletions bgp/tests/local_tests/community_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/openconfig/lemming/bgp"
"github.com/openconfig/lemming/gnmi/oc"
"github.com/openconfig/lemming/gnmi/oc/ocpath"
"github.com/openconfig/ygnmi/ygnmi"

valpb "github.com/openconfig/lemming/bgp/tests/proto/policyval"
)
Expand All @@ -43,16 +42,18 @@ func TestCommunitySet(t *testing.T) {
Input: &valpb.TestRoute{
ReachPrefix: "10.33.0.0/16",
},
ExpectedResult: valpb.RouteTestResult_ROUTE_TEST_RESULT_DISCARD,
ExpectedResultBeforePolicy: valpb.RouteTestResult_ROUTE_TEST_RESULT_ACCEPT,
ExpectedResult: valpb.RouteTestResult_ROUTE_TEST_RESULT_DISCARD,
}, {
Description: "Accepted route",
Input: &valpb.TestRoute{
ReachPrefix: "10.3.0.0/16",
},
ExpectedResult: valpb.RouteTestResult_ROUTE_TEST_RESULT_ACCEPT,
ExpectedResultBeforePolicy: valpb.RouteTestResult_ROUTE_TEST_RESULT_ACCEPT,
ExpectedResult: valpb.RouteTestResult_ROUTE_TEST_RESULT_ACCEPT,
}},
},
installSetPolicies: func(t *testing.T, dut2 *ygnmi.Client) {
installPolicies: func(t *testing.T, dut1, dut2, dut3, dut4, dut5 *Device) {
if debug {
fmt.Println("Installing test policies")
}
Expand All @@ -64,6 +65,7 @@ func TestCommunitySet(t *testing.T) {
// Create prefix set
prefixSetName := "accept-" + prefix1
prefix1Path := ocpath.Root().RoutingPolicy().DefinedSets().PrefixSet(prefixSetName).Prefix(prefix1, "exact").IpPrefix()
Replace(t, dut1, prefix1Path.Config(), prefix1)
Replace(t, dut2, prefix1Path.Config(), prefix1)

policy := &oc.RoutingPolicy_PolicyDefinition_Statement_OrderedMap{}
Expand All @@ -84,16 +86,13 @@ func TestCommunitySet(t *testing.T) {
// Accept the route so that it may be advertised.
stmt.GetOrCreateActions().SetPolicyResult(oc.RoutingPolicy_PolicyResultType_ACCEPT_ROUTE)
// Install policy
Replace(t, dut2, ocpath.Root().RoutingPolicy().PolicyDefinition(policyName).Config(), &oc.RoutingPolicy_PolicyDefinition{Statement: policy})
Replace(t, dut2, bgp.BGPPath.Neighbor(dut1spec.RouterID).ApplyPolicy().ImportPolicy().Config(), []string{policyName})
},
installPolicies: func(t *testing.T, dut2 *ygnmi.Client) {
if debug {
fmt.Println("Installing test policies")
}
Replace(t, dut1, ocpath.Root().RoutingPolicy().PolicyDefinition(policyName).Config(), &oc.RoutingPolicy_PolicyDefinition{Statement: policy})
Replace(t, dut1, bgp.BGPPath.Neighbor(dut2.RouterID).ApplyPolicy().ExportPolicy().Config(), []string{policyName})

//////////////////////

// Policy to reject routes with the given community set
policyName := "def2"
policyName = "def2"

// Create community set
rejectCommSetName := "reject-community-set"
Expand All @@ -103,8 +102,8 @@ func TestCommunitySet(t *testing.T) {
})
Replace(t, dut2, ocpath.Root().RoutingPolicy().DefinedSets().BgpDefinedSets().CommunitySet(rejectCommSetName).MatchSetOptions().Config(), oc.RoutingPolicy_MatchSetOptionsType_ANY)

policy := &oc.RoutingPolicy_PolicyDefinition_Statement_OrderedMap{}
stmt, err := policy.AppendNew("stmt2")
policy = &oc.RoutingPolicy_PolicyDefinition_Statement_OrderedMap{}
stmt, err = policy.AppendNew("stmt2")
if err != nil {
t.Fatalf("Cannot append new BGP policy statement: %v", err)
}
Expand All @@ -113,7 +112,7 @@ func TestCommunitySet(t *testing.T) {
stmt.GetOrCreateActions().SetPolicyResult(oc.RoutingPolicy_PolicyResultType_REJECT_ROUTE)
// Install policy
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})
Replace(t, dut2, bgp.BGPPath.Neighbor(dut1.RouterID).ApplyPolicy().ImportPolicy().Config(), []string{policyName})
},
})
}
Loading