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

Add AllRoutes function to snet.Router #3221

Merged
merged 1 commit into from
Oct 4, 2019
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/lib/snet/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ go_library(
"//go/lib/snet/internal/pathsource:go_default_library",
"//go/lib/sock/reliable:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/spath/spathmeta:go_default_library",
"//go/lib/spkt:go_default_library",
],
)
Expand Down
15 changes: 15 additions & 0 deletions go/lib/snet/mock_snet/snet.go

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

34 changes: 30 additions & 4 deletions go/lib/snet/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/scionproto/scion/go/lib/pathmgr"
"github.com/scionproto/scion/go/lib/sciond"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/spath/spathmeta"
)

// Router performs path resolution for SCION-speaking applications.
Expand All @@ -35,6 +36,8 @@ type Router interface {
// Route returns a path from the local AS to dst. If dst matches the local
// AS, an empty path is returned.
Route(ctx context.Context, dst addr.IA) (Path, error)
// AllRoutes is similar to Route except that it returns multiple paths.
AllRoutes(ctx context.Context, dst addr.IA) ([]Path, error)
// LocalIA returns the IA from which this router routes.
LocalIA() addr.IA
}
Expand Down Expand Up @@ -62,19 +65,42 @@ func (r *BaseRouter) Route(ctx context.Context, dst addr.IA) (Path, error) {
if len(aps) == 0 {
return nil, common.NewBasicError("unable to find paths", nil)
}
ap := aps.GetAppPath("")
return r.appPathToPath(ap)
}

// AllRoutes is the same as Route except that it returns multiple paths.
func (r *BaseRouter) AllRoutes(ctx context.Context, dst addr.IA) ([]Path, error) {
if r.PathResolver == nil || dst.Equal(r.IA) {
return []Path{&path{}}, nil
}
aps := r.PathResolver.Query(ctx, r.IA, dst, sciond.PathReqFlags{})
if len(aps) == 0 {
return nil, common.NewBasicError("unable to find paths", nil)
}
paths := make([]Path, 0, len(aps))
for _, ap := range aps {
p, err := r.appPathToPath(ap)
if err != nil {
return nil, err
}
paths = append(paths, p)
}
return paths, nil
}

pathEntry := aps.GetAppPath("").Entry
p := spath.New(pathEntry.Path.FwdPath)
func (r *BaseRouter) appPathToPath(ap *spathmeta.AppPath) (Path, error) {
p := spath.New(ap.Entry.Path.FwdPath)
// Preinitialize offsets, we don't want to propagate unusable paths
if err := p.InitOffsets(); err != nil {
return nil, common.NewBasicError("path error", err)
}
overlayAddr, err := pathEntry.HostInfo.Overlay()
overlayAddr, err := ap.Entry.HostInfo.Overlay()
if err != nil {
return nil, common.NewBasicError("path error", err)
}
return &path{
sciondPath: pathEntry,
sciondPath: ap.Entry,
spath: p,
overlay: overlayAddr,
source: r.IA,
Expand Down