Skip to content

Commit a4e8078

Browse files
committed
routeimport: set outport to external port in imported routes
Signed-off-by: Jaime Caamaño Ruiz <[email protected]>
1 parent 9456907 commit a4e8078

File tree

3 files changed

+64
-24
lines changed

3 files changed

+64
-24
lines changed

go-controller/pkg/libovsdb/ops/router.go

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -692,23 +692,53 @@ func PolicyEqualPredicate(p1, p2 *nbdb.LogicalRouterStaticRoutePolicy) bool {
692692
return *p1 == *p2
693693
}
694694

695-
// CreateOrReplaceLogicalRouterStaticRouteWithPredicate looks up a logical
696-
// router static route from the cache based on a given predicate. If it does not
697-
// exist, it creates the provided logical router static route. If it does, it
698-
// updates it. The logical router static route is added to the provided logical
699-
// router.
700-
// If more than one route matches the predicate on the router, the additional routes are removed.
701-
func CreateOrReplaceLogicalRouterStaticRouteWithPredicate(nbClient libovsdbclient.Client, routerName string,
702-
lrsr *nbdb.LogicalRouterStaticRoute, p logicalRouterStaticRoutePredicate, fields ...interface{}) error {
695+
// CreateOrReplaceLogicalRouterStaticRouteWithPredicateOps executes ops
696+
// according to the following logic:
697+
// - Looks up a logical router static route from the cache based on a given predicate.
698+
// - If the route does not exist, it creates the provided logical router static
699+
// route.
700+
// - If it does, it updates it.
701+
// - The logical router static route is added to the provided logical router.
702+
// - If more than one route matches the predicate on the router, the additional
703+
// routes are removed.
704+
func CreateOrReplaceLogicalRouterStaticRouteWithPredicate(
705+
nbClient libovsdbclient.Client,
706+
routerName string,
707+
lrsr *nbdb.LogicalRouterStaticRoute,
708+
p logicalRouterStaticRoutePredicate,
709+
fields ...interface{},
710+
) error {
711+
ops, err := CreateOrReplaceLogicalRouterStaticRouteWithPredicateOps(nbClient, nil, routerName, lrsr, p, fields...)
712+
if err != nil {
713+
return err
714+
}
715+
_, err = TransactAndCheck(nbClient, ops)
716+
return err
717+
}
703718

719+
// CreateOrReplaceLogicalRouterStaticRouteWithPredicateOps returns ops according
720+
// to the following logic:
721+
// - Looks up a logical router static route from the cache based on a given predicate.
722+
// - If the route does not exist, it creates the provided logical router static
723+
// route.
724+
// - If it does, it updates it.
725+
// - The logical router static route is added to the provided logical router.
726+
// - If more than one route matches the predicate on the router, the additional
727+
// routes are removed.
728+
func CreateOrReplaceLogicalRouterStaticRouteWithPredicateOps(
729+
nbClient libovsdbclient.Client,
730+
ops []ovsdb.Operation,
731+
routerName string,
732+
lrsr *nbdb.LogicalRouterStaticRoute,
733+
p logicalRouterStaticRoutePredicate,
734+
fields ...interface{},
735+
) ([]ovsdb.Operation, error) {
704736
lr := &nbdb.LogicalRouter{Name: routerName}
705737
routes, err := GetRouterLogicalRouterStaticRoutesWithPredicate(nbClient, lr, p)
706738
if err != nil {
707-
return fmt.Errorf("unable to get logical router static routes with predicate on router %s: %w", routerName, err)
739+
return nil, fmt.Errorf("unable to get logical router static routes with predicate on router %s: %w", routerName, err)
708740
}
709741

710-
var ops []ovsdb.Operation
711-
712742
if len(routes) > 0 {
713743
lrsr.UUID = routes[0].UUID
714744
}
@@ -718,16 +748,16 @@ func CreateOrReplaceLogicalRouterStaticRouteWithPredicate(nbClient libovsdbclien
718748
routes = routes[1:]
719749
ops, err = DeleteLogicalRouterStaticRoutesOps(nbClient, ops, routerName, routes...)
720750
if err != nil {
721-
return err
751+
return nil, err
722752
}
723753
}
724754

725755
ops, err = CreateOrUpdateLogicalRouterStaticRoutesWithPredicateOps(nbClient, ops, routerName, lrsr, nil, fields...)
726756
if err != nil {
727-
return fmt.Errorf("unable to get create or update logical router static routes on router %s: %w", routerName, err)
757+
return nil, fmt.Errorf("unable to get create or update logical router static routes on router %s: %w", routerName, err)
728758
}
729-
_, err = TransactAndCheck(nbClient, ops)
730-
return err
759+
760+
return ops, nil
731761
}
732762

733763
// DeleteLogicalRouterStaticRoutesWithPredicate looks up logical router static

go-controller/pkg/ovn/routeimport/route_import.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ func (c *controller) syncNetwork(network string) error {
356356
}
357357

358358
router := info.GetNetworkScopedGWRouterName(c.node)
359+
// we set the outport incase our IPv6 next hops are link local addresses
360+
outport := types.GWRouterToExtSwitchPrefix + router
359361
actual, uuids, err := c.getOVNRoutes(router)
360362
if err != nil {
361363
return fmt.Errorf("failed to get routes from OVN: %w", err)
@@ -380,10 +382,11 @@ func (c *controller) syncNetwork(network string) error {
380382
UUID: uuids[add],
381383
IPPrefix: add.dst,
382384
Nexthop: add.gw,
385+
OutputPort: &outport,
383386
ExternalIDs: map[string]string{controllerExternalIDKey: controllerName},
384387
}
385388
p := func(db *nbdb.LogicalRouterStaticRoute) bool { return p(lrsr, db) }
386-
ops, err = nbdbops.CreateOrUpdateLogicalRouterStaticRoutesWithPredicateOps(c.nbClient, ops, router, lrsr, p)
389+
ops, err = nbdbops.CreateOrReplaceLogicalRouterStaticRouteWithPredicateOps(c.nbClient, ops, router, lrsr, p)
387390
if err != nil {
388391
err := fmt.Errorf("failed to add routes on router %s: %w", router, err)
389392
errs = append(errs, err)

go-controller/pkg/ovn/routeimport/route_import_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func Test_controller_syncNetwork(t *testing.T) {
2727
node := "testnode"
2828

2929
defaultNetwork := &util.DefaultNetInfo{}
30+
defaultNetworkRouter := defaultNetwork.GetNetworkScopedGWRouterName(node)
31+
defaultNetworkRouterPort := types.GWRouterToExtSwitchPrefix + defaultNetworkRouter
3032

3133
udn := &multinetworkmocks.NetInfo{}
3234
udn.On("IsDefault").Return(false)
@@ -142,23 +144,28 @@ func Test_controller_syncNetwork(t *testing.T) {
142144
},
143145
link: &netlink.Vrf{Table: unix.RT_TABLE_MAIN},
144146
initial: []libovsdb.TestData{
145-
&nbdb.LogicalRouter{Name: defaultNetwork.GetNetworkScopedGWRouterName(node), StaticRoutes: []string{"keep-1", "keep-2", "remove"}},
146-
&nbdb.LogicalRouterStaticRoute{UUID: "keep-1", IPPrefix: "1.1.1.0/24", Nexthop: "1.1.1.1", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
147+
&nbdb.LogicalRouter{Name: defaultNetworkRouter, StaticRoutes: []string{"keep-1", "keep-2", "remove"}},
148+
&nbdb.LogicalRouterStaticRoute{UUID: "keep-1", IPPrefix: "1.1.1.0/24", Nexthop: "1.1.1.1", OutputPort: &defaultNetworkRouterPort, ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
147149
&nbdb.LogicalRouterStaticRoute{UUID: "keep-2", IPPrefix: "5.5.5.0/24", Nexthop: "5.5.5.1"},
148-
&nbdb.LogicalRouterStaticRoute{UUID: "remove", IPPrefix: "6.6.6.0/24", Nexthop: "6.6.6.1", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
150+
&nbdb.LogicalRouterStaticRoute{UUID: "remove", IPPrefix: "6.6.6.0/24", Nexthop: "6.6.6.1", OutputPort: &defaultNetworkRouterPort, ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
151+
&nbdb.LogicalRouter{UUID: "otherRouter", Name: "otherRouter", StaticRoutes: []string{"untouched-1"}},
152+
&nbdb.LogicalRouterStaticRoute{UUID: "untouched-1", IPPrefix: "3.3.3.0/24", Nexthop: "3.3.3.2", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
149153
},
150154
routes: []netlink.Route{
151155
{Dst: ovntesting.MustParseIPNet("1.1.1.0/24"), Gw: ovntesting.MustParseIP("1.1.1.1")},
152156
{Dst: ovntesting.MustParseIPNet("2.2.2.0/24"), Gw: ovntesting.MustParseIP("2.2.2.1")},
153157
{Dst: ovntesting.MustParseIPNet("3.3.3.0/24"), MultiPath: []*netlink.NexthopInfo{{Gw: ovntesting.MustParseIP("3.3.3.1")}, {Gw: ovntesting.MustParseIP("3.3.3.2")}}},
154158
},
155159
expected: []libovsdb.TestData{
156-
&nbdb.LogicalRouter{UUID: "router", Name: defaultNetwork.GetNetworkScopedGWRouterName(node), StaticRoutes: []string{"keep-1", "keep-2", "add-1", "add-2", "add-3"}},
157-
&nbdb.LogicalRouterStaticRoute{UUID: "keep-1", IPPrefix: "1.1.1.0/24", Nexthop: "1.1.1.1", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
160+
&nbdb.LogicalRouter{UUID: "router", Name: defaultNetworkRouter, StaticRoutes: []string{"keep-1", "keep-2", "add-1", "add-2", "add-3"}},
161+
&nbdb.LogicalRouterStaticRoute{UUID: "keep-1", IPPrefix: "1.1.1.0/24", Nexthop: "1.1.1.1", OutputPort: &defaultNetworkRouterPort, ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
158162
&nbdb.LogicalRouterStaticRoute{UUID: "keep-2", IPPrefix: "5.5.5.0/24", Nexthop: "5.5.5.1"},
159-
&nbdb.LogicalRouterStaticRoute{UUID: "add-1", IPPrefix: "2.2.2.0/24", Nexthop: "2.2.2.1", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
160-
&nbdb.LogicalRouterStaticRoute{UUID: "add-2", IPPrefix: "3.3.3.0/24", Nexthop: "3.3.3.1", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
161-
&nbdb.LogicalRouterStaticRoute{UUID: "add-3", IPPrefix: "3.3.3.0/24", Nexthop: "3.3.3.2", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
163+
&nbdb.LogicalRouterStaticRoute{UUID: "add-1", IPPrefix: "2.2.2.0/24", Nexthop: "2.2.2.1", OutputPort: &defaultNetworkRouterPort, ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
164+
&nbdb.LogicalRouterStaticRoute{UUID: "add-2", IPPrefix: "3.3.3.0/24", Nexthop: "3.3.3.1", OutputPort: &defaultNetworkRouterPort, ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
165+
&nbdb.LogicalRouterStaticRoute{UUID: "add-3", IPPrefix: "3.3.3.0/24", Nexthop: "3.3.3.2", OutputPort: &defaultNetworkRouterPort, ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
166+
&nbdb.LogicalRouter{UUID: "otherRouter", Name: "otherRouter", StaticRoutes: []string{"untouched-1"}},
167+
// this route should not be updated as it belongs to a different network
168+
&nbdb.LogicalRouterStaticRoute{UUID: "untouched-1", IPPrefix: "3.3.3.0/24", Nexthop: "3.3.3.2", ExternalIDs: map[string]string{controllerExternalIDKey: controllerName}},
162169
},
163170
},
164171
}

0 commit comments

Comments
 (0)