Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router: make room for multiple underlay impls phase 1 #4658

Merged
merged 15 commits into from
Feb 4, 2025
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
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
Loading