Skip to content

Commit

Permalink
router: make room for multiple underlay impls phase 1 (#4658)
Browse files Browse the repository at this point in the history
The goal is to eventually remove all underlay-specific code from the
main router code and place it in a plugin, such that there can then be
multiple underlay plugins. This PR isn't attempting to fully accomplish
that. It avoids moving some code, so that the diff is easier to read.
The price to pay is a few extra spaghetti left between main code and
plugin.

The code that should eventually move to the underlay is:
* runReceiver and runForwarder.
* likely some of the BFD code.
* opening of connections (currently done by connector.go)

Other changes being planned:
* Stop reusing the internal connection for sibling links (so we can take
advantage of bound connections).
* Add knowledge of multiple underlay into the configurator.
* Make underlay addresses opaque to the router.
* Demultiplex to links on ingest, so ifID and srcAddress (when they are
defined by the link) are obtained in the most efficient way (directly
from the link's fields for example).

Contributes to: #4593
  • Loading branch information
jiceatscion authored Feb 4, 2025
1 parent 09895b9 commit ca467d2
Show file tree
Hide file tree
Showing 13 changed files with 881 additions and 384 deletions.
2 changes: 2 additions & 0 deletions router/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
"metrics.go",
"serialize_proxy.go",
"svc.go",
"underlay.go",
],
importpath = "github.com/scionproto/scion/router",
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -69,6 +70,7 @@ go_test(
"//private/underlay/conn:go_default_library",
"//router/control:go_default_library",
"//router/mock_router:go_default_library",
"//router/underlayproviders:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
"@com_github_gopacket_gopacket//:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions router/bfd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
deps = [
"//pkg/log:go_default_library",
"//pkg/private/serrors:go_default_library",
"//router/control:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
],
Expand Down
30 changes: 30 additions & 0 deletions router/bfd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ package bfd

import (
"context"
"crypto/rand"
"fmt"
"math"
"math/big"
"sync"
"time"

"github.com/gopacket/gopacket/layers"

"github.com/scionproto/scion/pkg/log"
"github.com/scionproto/scion/pkg/private/serrors"
"github.com/scionproto/scion/router/control"
)

const (
Expand Down Expand Up @@ -161,6 +164,33 @@ type Session struct {
testLogger log.Logger
}

// NewSession returns a new BFD session, configured as specified and updating the
// given metrics. BFD packets are transmitted via the given Sender. Up to 10 incoming BFD packets
// per session can be queued waiting for processing; excess traffic will be blocked.
// A random discriminator is generated automatically. This can be used by the recipient to route
// packets to the correct session.
//
// TODO(jiceatscion): blocking incoming traffic (*all of it*) when the BFD queue is full is
// probably the wrong thing to do, but this is what we have been doing so far.
func NewSession(s Sender, cfg control.BFD, metrics Metrics) (*Session, error) {

// Generate random discriminator. It can't be zero.
discInt, err := rand.Int(rand.Reader, big.NewInt(0xfffffffe))
if err != nil {
return nil, err
}
disc := layers.BFDDiscriminator(uint32(discInt.Uint64()) + 1)
return &Session{
Sender: s,
DetectMult: layers.BFDDetectMultiplier(cfg.DetectMult),
DesiredMinTxInterval: cfg.DesiredMinTxInterval,
RequiredMinRxInterval: cfg.RequiredMinRxInterval,
LocalDiscriminator: disc,
ReceiveQueueSize: 10,
Metrics: metrics,
}, nil
}

func (s *Session) String() string {
return fmt.Sprintf("local_disc %v, remote_disc %v, sender %v",
s.LocalDiscriminator, s.getRemoteDiscriminator(), s.Sender)
Expand Down
1 change: 1 addition & 0 deletions router/cmd/router/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//router/config:go_default_library",
"//router/control:go_default_library",
"//router/mgmtapi:go_default_library",
"//router/underlayproviders:go_default_library",
"@com_github_go_chi_chi_v5//:go_default_library",
"@com_github_go_chi_cors//:go_default_library",
"@org_golang_x_sync//errgroup:go_default_library",
Expand Down
13 changes: 7 additions & 6 deletions router/cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/scionproto/scion/router/config"
"github.com/scionproto/scion/router/control"
api "github.com/scionproto/scion/router/mgmtapi"
_ "github.com/scionproto/scion/router/underlayproviders"
)

var globalCfg config.Config
Expand Down Expand Up @@ -64,6 +65,11 @@ func realMain(ctx context.Context) error {
DataPlane: router.DataPlane{
Metrics: metrics,
ExperimentalSCMPAuthentication: globalCfg.Features.ExperimentalSCMPAuthentication,
RunConfig: router.RunConfig{
NumProcessors: globalCfg.Router.NumProcessors,
NumSlowPathProcessors: globalCfg.Router.NumSlowPathProcessors,
BatchSize: globalCfg.Router.BatchSize,
},
},
ReceiveBufferSize: globalCfg.Router.ReceiveBufferSize,
SendBufferSize: globalCfg.Router.SendBufferSize,
Expand Down Expand Up @@ -131,12 +137,7 @@ func realMain(ctx context.Context) error {
})
g.Go(func() error {
defer log.HandlePanic()
runConfig := &router.RunConfig{
NumProcessors: globalCfg.Router.NumProcessors,
NumSlowPathProcessors: globalCfg.Router.NumSlowPathProcessors,
BatchSize: globalCfg.Router.BatchSize,
}
if err := dp.DataPlane.Run(errCtx, runConfig); err != nil {
if err := dp.DataPlane.Run(errCtx); err != nil {
return serrors.Wrap("running dataplane", err)
}
return nil
Expand Down
Loading

0 comments on commit ca467d2

Please sign in to comment.