Skip to content

Commit

Permalink
encap accumulation
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 committed Jan 27, 2025
1 parent ed3ea50 commit 0b924fe
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 97 deletions.
58 changes: 29 additions & 29 deletions proto/sysrib/sysrib.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/sysrib/sysrib.proto
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ message Nexthop {
//int32 ifindex = 3;
string address = 3;
uint64 weight = 4;
routing.Headers headers = 5;
routing.Headers encap = 5;
}

message SetRouteResponse {
Expand Down
1 change: 1 addition & 0 deletions sysrib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ go_test(
"//gnmi/oc",
"//gnmi/oc/ocpath",
"//proto/dataplane",
"//proto/routing",
"//proto/sysrib",
"@com_github_google_go_cmp//cmp",
"@com_github_google_go_cmp//cmp/cmpopts",
Expand Down
13 changes: 8 additions & 5 deletions sysrib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,18 @@ func (s *Server) SetRoute(ctx context.Context, req *sysribpb.SetRouteRequest) (*
return nil, err
}

nexthops := []*afthelper.NextHopSummary{}
nexthops := []*ResolvedNexthop{}
for _, nh := range req.GetNexthops() {
if nh.GetType() != sysribpb.Nexthop_TYPE_IPV4 && nh.GetType() != sysribpb.Nexthop_TYPE_IPV6 {
return nil, status.Errorf(codes.Unimplemented, "Unrecognized nexthop type: %s", nh.GetType())
}
nexthops = append(nexthops, &afthelper.NextHopSummary{
Weight: nh.GetWeight(),
Address: nh.GetAddress(),
NetworkInstance: vrfIDToNiName(nh.GetVrfId()),
nexthops = append(nexthops, &ResolvedNexthop{
NextHopSummary: afthelper.NextHopSummary{
Weight: nh.GetWeight(),
Address: nh.GetAddress(),
NetworkInstance: vrfIDToNiName(nh.GetVrfId()),
},
Headers: nh.GetEncap().GetHeaders(),
})
}

Expand Down
101 changes: 101 additions & 0 deletions sysrib/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/openconfig/lemming/gnmi/oc/ocpath"

dpb "github.com/openconfig/lemming/proto/dataplane"
"github.com/openconfig/lemming/proto/routing"
pb "github.com/openconfig/lemming/proto/sysrib"
)

Expand Down Expand Up @@ -1076,6 +1077,106 @@ func TestServer(t *testing.T) {
},
},
}},
}, {
desc: "Encap",
inSetRouteRequests: []*SetRouteRequestAction{{
Desc: "2nd level indirect route",
RouteReq: &pb.SetRouteRequest{
AdminDistance: 10,
Metric: 10,
Prefix: &pb.Prefix{
Family: pb.Prefix_FAMILY_IPV4,
Address: "20.0.0.0",
MaskLength: 8,
},
Nexthops: []*pb.Nexthop{{
Type: pb.Nexthop_TYPE_IPV4,
Address: "10.10.10.10",
Encap: &routing.Headers{
Headers: []*routing.Header{{
Type: routing.HeaderType_HEADER_TYPE_MPLS,
Labels: []uint32{100},
}},
},
}},
},
}, {
Desc: "1st level indirect route",
RouteReq: &pb.SetRouteRequest{
AdminDistance: 5,
Metric: 5,
Prefix: &pb.Prefix{
Family: pb.Prefix_FAMILY_IPV4,
Address: "10.0.0.0",
MaskLength: 8,
},
Nexthops: []*pb.Nexthop{{
Type: pb.Nexthop_TYPE_IPV4,
Address: "192.168.5.42",
Encap: &routing.Headers{
Headers: []*routing.Header{{
Type: routing.HeaderType_HEADER_TYPE_IP4,
SrcIp: "10.0.0.10",
DstIp: "192.168.5.42",
}},
},
}},
},
}},
wantRoutes: []*dpb.Route{{
Prefix: &dpb.RoutePrefix{
NetworkInstance: "DEFAULT",
Cidr: "10.0.0.0/8",
},
Hop: &dpb.Route_NextHops{
NextHops: &dpb.NextHopList{
Weights: []uint64{0},
Hops: []*dpb.NextHop{{
NextHopIp: "192.168.5.42",
Interface: &dpb.OCInterface{
Interface: "eth4",
},
Encap: &dpb.NextHop_Headers{
Headers: &routing.Headers{
Headers: []*routing.Header{{
Type: routing.HeaderType_HEADER_TYPE_IP4,
SrcIp: "10.0.0.10",
DstIp: "192.168.5.42",
}},
},
},
}},
},
},
}, {
Prefix: &dpb.RoutePrefix{
NetworkInstance: "DEFAULT",
Cidr: "20.0.0.0/8",
},
Hop: &dpb.Route_NextHops{
NextHops: &dpb.NextHopList{
Weights: []uint64{0},
Hops: []*dpb.NextHop{{
NextHopIp: "192.168.5.42",
Interface: &dpb.OCInterface{
Interface: "eth4",
},
Encap: &dpb.NextHop_Headers{
Headers: &routing.Headers{
Headers: []*routing.Header{{
Type: routing.HeaderType_HEADER_TYPE_MPLS,
Labels: []uint32{100},
}, {
Type: routing.HeaderType_HEADER_TYPE_IP4,
SrcIp: "10.0.0.10",
DstIp: "192.168.5.42",
}},
},
},
}},
},
},
}},
}}

grpcServer := grpc.NewServer()
Expand Down
12 changes: 7 additions & 5 deletions sysrib/server_zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ func (s *Server) setZebraRoute(ctx context.Context, niName string, zroute *zebra

// convertZebraRoute converts a zebra route to a Sysrib route.
func convertZebraRoute(niName string, zroute *zebra.IPRouteBody) *Route {
var nexthops []*afthelper.NextHopSummary
var nexthops []*ResolvedNexthop
for _, znh := range zroute.Nexthops {
nexthops = append(nexthops, &afthelper.NextHopSummary{
Weight: 1,
Address: znh.Gate.String(),
NetworkInstance: niName,
nexthops = append(nexthops, &ResolvedNexthop{
NextHopSummary: afthelper.NextHopSummary{
Weight: 1,
Address: znh.Gate.String(),
NetworkInstance: niName,
},
})
}
var routePref RoutePreference
Expand Down
15 changes: 9 additions & 6 deletions sysrib/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,30 @@ import (

log "github.com/golang/glog"
"github.com/openconfig/gribigo/afthelper"
"github.com/openconfig/ygnmi/ygnmi"

"github.com/openconfig/lemming/gnmi/fakedevice"
"github.com/openconfig/lemming/gnmi/gnmiclient"
"github.com/openconfig/lemming/gnmi/oc"
"github.com/openconfig/lemming/gnmi/oc/ocpath"
"github.com/openconfig/ygnmi/ygnmi"
)

// convertStaticRoute converts an OC static route to a sysrib Route
func convertStaticRoute(prefix string, sroute *oc.NetworkInstance_Protocol_Static) *Route {
var nexthops []*afthelper.NextHopSummary
var nexthops []*ResolvedNexthop
if sroute != nil {
for _, snh := range sroute.NextHop {
// TODO(wenbli): Implement recurse option.
snh.SetRecurse(true)
switch nh := snh.NextHop.(type) {
case nil:
case oc.UnionString:
nexthops = append(nexthops, &afthelper.NextHopSummary{
Weight: 1,
Address: string(nh),
NetworkInstance: fakedevice.DefaultNetworkInstance,
nexthops = append(nexthops, &ResolvedNexthop{
NextHopSummary: afthelper.NextHopSummary{
Weight: 1,
Address: string(nh),
NetworkInstance: fakedevice.DefaultNetworkInstance,
},
})
default:
log.Warningf("sysrib: Unhandled static route nexthop type (%T): %v", nh, nh)
Expand Down
3 changes: 2 additions & 1 deletion sysrib/sysrib.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ type Route struct {
Connected *Interface `json:"connected"`
// NextHops is the set of IP nexthops that the route uses if
// it is not a connected route.
NextHops []*afthelper.NextHopSummary `json:"nexthops"`
NextHops []*ResolvedNexthop `json:"nexthops"`
RoutePref RoutePreference
}

Expand Down Expand Up @@ -608,6 +608,7 @@ func (sr *SysRIB) egressNexthopsInternal(inputNI string, ip *net.IPNet, interfac
case rnh.HasGUE():
return nil, nil, fmt.Errorf("route %v resolves over another route that has a BGP-triggered GUE action, the behaviour is undefined, nexthop: %v, recursive nexthop: %v", cr, nh, rnh)
}
rnh.Headers = append(nh.Headers, rnh.Headers...)
rnh.GUEHeaders = encapHeaders
// TODO(wenbli): Implement WCMP: there could be a merger of two nexthops, in which case we add their weights.
allEgressNhs[cr.RoutePref] = append(allEgressNhs[cr.RoutePref], rnh)
Expand Down
Loading

0 comments on commit 0b924fe

Please sign in to comment.