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

SIG: Dispatcher bypass #3646

Merged
merged 2 commits into from
Jan 30, 2020
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
1 change: 1 addition & 0 deletions go/sig/internal/sigcmn/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/scionproto/scion/go/sig/internal/sigcmn",
visibility = ["//visibility:public"],
deps = [
"//go/godispatcher/dispatcher:go_default_library",
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/env:go_default_library",
Expand Down
44 changes: 35 additions & 9 deletions go/sig/internal/sigcmn/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"time"

"github.com/scionproto/scion/go/godispatcher/dispatcher"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/env"
Expand Down Expand Up @@ -48,11 +49,12 @@ var (
IA addr.IA
Host addr.HostAddr

PathMgr pathmgr.Resolver
Network *snet.SCIONNetwork
CtrlConn snet.Conn
MgmtAddr *mgmt.Addr
encapPort uint16
PathMgr pathmgr.Resolver
Dispatcher reliable.Dispatcher
Network *snet.SCIONNetwork
CtrlConn snet.Conn
MgmtAddr *mgmt.Addr
encapPort uint16
)

func Init(cfg sigconfig.SigConf, sdCfg env.SciondClient) error {
Expand Down Expand Up @@ -81,6 +83,11 @@ func Init(cfg sigconfig.SigConf, sdCfg env.SciondClient) error {
func initNetwork(cfg sigconfig.SigConf,
sdCfg env.SciondClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) {

var err error
Dispatcher, err = newDispatcher(cfg)
if err != nil {
return nil, nil, serrors.WrapStr("unable to initialize SCION dispatcher", err)
}
if sdCfg.FakeData != "" {
return initNetworkWithFakeSCIOND(cfg, sdCfg)
}
Expand All @@ -90,13 +97,12 @@ func initNetwork(cfg sigconfig.SigConf,
func initNetworkWithFakeSCIOND(cfg sigconfig.SigConf,
sdCfg env.SciondClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) {

ds := reliable.NewDispatcher(cfg.Dispatcher)
sciondConn, err := fake.NewFromFile(sdCfg.FakeData)
if err != nil {
return nil, nil, serrors.WrapStr("unable to initialize fake SCIOND service", err)
}
pathResolver := pathmgr.New(sciondConn, pathmgr.Timers{})
network := snet.NewNetworkWithPR(cfg.IA, ds, &snetmigrate.PathQuerier{
network := snet.NewNetworkWithPR(cfg.IA, Dispatcher, &snetmigrate.PathQuerier{
Resolver: pathResolver,
IA: cfg.IA,
}, pathResolver)
Expand All @@ -106,14 +112,13 @@ func initNetworkWithFakeSCIOND(cfg sigconfig.SigConf,
func initNetworkWithRealSCIOND(cfg sigconfig.SigConf,
sdCfg env.SciondClient) (*snet.SCIONNetwork, pathmgr.Resolver, error) {

ds := reliable.NewDispatcher(cfg.Dispatcher)
// TODO(karampok). To be kept until https://github.com/scionproto/scion/issues/3377
deadline := time.Now().Add(sdCfg.InitialConnectPeriod.Duration)
var retErr error
for tries := 0; time.Now().Before(deadline); tries++ {
resolver, err := snetmigrate.ResolverFromSD(sdCfg.Path)
if err == nil {
return snet.NewNetworkWithPR(cfg.IA, ds, &snetmigrate.PathQuerier{
return snet.NewNetworkWithPR(cfg.IA, Dispatcher, &snetmigrate.PathQuerier{
Resolver: resolver,
IA: cfg.IA,
}, resolver), resolver, nil
Expand All @@ -125,6 +130,27 @@ func initNetworkWithRealSCIOND(cfg sigconfig.SigConf,
return nil, nil, retErr
}

func newDispatcher(cfg sigconfig.SigConf) (reliable.Dispatcher, error) {
if cfg.DispatcherBypass == "" {
log.Info("Regular SCION dispatcher", "addr", cfg.DispatcherBypass)
return reliable.NewDispatcher(cfg.Dispatcher), nil
}
// Initialize dispatcher bypass.
log.Info("Bypassing SCION dispatcher", "addr", cfg.DispatcherBypass)
dispServer, err := dispatcher.NewServer(cfg.DispatcherBypass)
if err != nil {
return nil, serrors.WrapStr("unable to initialize bypass dispatcher", err)
}
go func() {
defer log.LogPanicAndExit()
err := dispServer.Serve()
if err != nil {
log.Error("Bypass dispatcher failed", "err", err)
}
}()
return dispServer, nil
}

func EncapSnetAddr() *snet.UDPAddr {
return &snet.UDPAddr{IA: IA, Host: &net.UDPAddr{IP: Host.IP(), Port: int(encapPort)}}
}
Expand Down
4 changes: 4 additions & 0 deletions go/sig/internal/sigconfig/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ type SigConf struct {
SrcIP4 net.IP
// IPv6 source address hint to put into routing table.
SrcIP6 net.IP
// DispatcherBypass is the overlay address (e.g. ":30041") to use when bypassing SCION
// dispatcher. If the field is empty bypass is not done and SCION dispatcher is used
// instead.
DispatcherBypass string
}

// InitDefaults sets the default values to unset values.
Expand Down