Skip to content

Commit

Permalink
colibri: e2e admission (#3863)
Browse files Browse the repository at this point in the history
Do the end to end admission.
This PR also introduces some small changes to the app messages and capnp for e2e setup messages.
  • Loading branch information
juagargi authored Sep 28, 2020
1 parent 070192f commit fb4a0f7
Show file tree
Hide file tree
Showing 22 changed files with 891 additions and 278 deletions.
5 changes: 4 additions & 1 deletion go/cs/reservation/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ go_library(

go_test(
name = "go_default_test",
srcs = ["reservation_test.go"],
srcs = [
"request_test.go",
"reservation_test.go",
],
embed = [":go_default_library"],
deps = [
"//go/cs/reservation/segment:go_default_library",
Expand Down
123 changes: 120 additions & 3 deletions go/cs/reservation/e2e/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,115 @@ func NewRequest(ts time.Time, id *reservation.E2EID, idx reservation.IndexNumber
}, nil
}

// SetupRequest represents all possible e2e setup requests.
type SetupRequest interface {
IsSuccessful() bool
GetCommonSetupReq() *SetupReq // return the underlying basic SetupReq (common for all)
}

// SetupReq is an e2e setup/renewal request, that has been so far accepted.
type SetupReq struct {
Request
SegmentRsvs []reservation.SegmentID
RequestedBW reservation.BWCls
AllocationTrail []reservation.BWCls
SegmentRsvs []reservation.SegmentID
SegmentRsvASCount []uint8 // how many ASes per segment reservation
RequestedBW reservation.BWCls
AllocationTrail []reservation.BWCls
totalASCount int
currentASSegmentRsvIndex int // the index in SegmentRsv for the current AS
isTransfer bool
}

// NewSetupRequest creates and initializes an e2e setup request common for both success and failure.
func NewSetupRequest(r *Request, segRsvs []reservation.SegmentID, segRsvCount []uint8,
requestedBW reservation.BWCls, allocTrail []reservation.BWCls) (*SetupReq, error) {

if len(segRsvs) != len(segRsvCount) || len(segRsvs) == 0 {
return nil, serrors.New("e2e setup request invalid", "seg_rsv_len", len(segRsvs),
"seg_rsv_count_len", len(segRsvCount))
}
totalASCount := 0
currASindex := -1
isTransfer := false
n := len(allocTrail) - 1
for i, c := range segRsvCount {
totalASCount += int(c)
n -= int(c) - 1
if i == len(segRsvCount)-1 {
n-- // the last segment spans 1 more AS
}
if n < 0 && currASindex < 0 {
currASindex = i
isTransfer = i < len(segRsvCount)-1 && n == -1 // dst AS is no transfer
}
}
totalASCount -= len(segRsvCount) - 1
if currASindex < 0 {
return nil, serrors.New("error initializing e2e request",
"alloc_trail_len", len(allocTrail), "seg_rsv_count", segRsvCount)
}
return &SetupReq{
Request: *r,
SegmentRsvs: segRsvs,
SegmentRsvASCount: segRsvCount,
RequestedBW: requestedBW,
AllocationTrail: allocTrail,
totalASCount: totalASCount,
currentASSegmentRsvIndex: currASindex,
isTransfer: isTransfer,
}, nil
}

// GetCommonSetupReq returns the pointer to the data structure.
func (r *SetupReq) GetCommonSetupReq() *SetupReq {
return r
}

func (r *SetupReq) Transfer() bool {
return r.isTransfer
}

type PathLocation int

const (
Source PathLocation = iota
Transit
Destination
)

func (l PathLocation) String() string {
switch l {
case Source:
return "source"
case Transit:
return "trantit"
case Destination:
return "destination"
}
return "unknown path location"
}

// Location returns the location of this node in the path of the request.
func (r *SetupReq) Location() PathLocation {
switch len(r.AllocationTrail) {
case 0:
return Source
case r.totalASCount:
return Destination
default:
return Transit
}
}

// SegmentRsvIDsForThisAS returns the segment reservation ID this AS belongs to. Iff this
// AS is a transfer AS (stitching point), there will be two reservation IDs returned, in the
// order of traversal.
func (r *SetupReq) SegmentRsvIDsForThisAS() []reservation.SegmentID {
indices := make([]reservation.SegmentID, 1, 2)
indices[0] = r.SegmentRsvs[r.currentASSegmentRsvIndex]
if r.isTransfer {
indices = append(indices, r.SegmentRsvs[r.currentASSegmentRsvIndex+1])
}
return indices
}

// SetupReqSuccess is a successful e2e setup request traveling along the reservation path.
Expand All @@ -66,12 +169,26 @@ type SetupReqSuccess struct {
Token reservation.Token
}

var _ SetupRequest = (*SetupReqSuccess)(nil)

// IsSuccessful returns true.
func (s *SetupReqSuccess) IsSuccessful() bool {
return true
}

// SetupReqFailure is a failed e2e setup request also traveling along the reservation path.
type SetupReqFailure struct {
SetupReq
ErrorCode uint8
}

var _ SetupRequest = (*SetupReqFailure)(nil)

// IsSuccessful returns false, as this is a failed setup.
func (s *SetupReqFailure) IsSuccessful() bool {
return false
}

// CleanupReq is a cleaup request for an e2e index.
type CleanupReq struct {
Request
Expand Down
220 changes: 220 additions & 0 deletions go/cs/reservation/e2e/request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
// Copyright 2020 ETH Zurich, Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package e2e

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/scionproto/scion/go/cs/reservation/segmenttest"
"github.com/scionproto/scion/go/lib/colibri/reservation"
"github.com/scionproto/scion/go/lib/util"
"github.com/scionproto/scion/go/lib/xtest"
)

func TestNewRequest(t *testing.T) {
_, err := NewRequest(util.SecsToTime(1), nil, 1, nil)
require.Error(t, err)
_, err = NewRequest(util.SecsToTime(1), nil, 1, segmenttest.NewTestPath())
require.Error(t, err)
id, err := reservation.NewE2EID(xtest.MustParseAS("ff00:0:111"),
xtest.MustParseHexString("beefcafebeefcafebeef"))
require.NoError(t, err)
r, err := NewRequest(util.SecsToTime(1), id, 1, segmenttest.NewTestPath())
require.NoError(t, err)
require.Equal(t, util.SecsToTime(1), r.Timestamp)
require.Equal(t, id, &r.ID)
require.Equal(t, reservation.IndexNumber(1), r.Index)
require.Equal(t, segmenttest.NewTestPath(), r.RequestMetadata.Path())
}

func TestNewSetupRequest(t *testing.T) {
_, err := NewSetupRequest(nil, nil, nil, 5, nil)
require.Error(t, err)
id, err := reservation.NewE2EID(xtest.MustParseAS("ff00:0:111"),
xtest.MustParseHexString("beefcafebeefcafebeef"))
require.NoError(t, err)
path := segmenttest.NewTestPath()
baseReq, err := NewRequest(util.SecsToTime(1), id, 1, path)
require.NoError(t, err)
_, err = NewSetupRequest(baseReq, nil, nil, 5, nil)
require.Error(t, err)

segmentRsvs := make([]reservation.SegmentID, 0)
_, err = NewSetupRequest(baseReq, segmentRsvs, nil, 5, nil)
require.Error(t, err)
segmentASCount := make([]uint8, 0)
_, err = NewSetupRequest(baseReq, segmentRsvs, segmentASCount, 5, nil)
require.Error(t, err)
trail := make([]reservation.BWCls, 0)
_, err = NewSetupRequest(baseReq, segmentRsvs, segmentASCount, 5, trail)
require.Error(t, err)

cases := map[string]struct {
ASCountPerSegment []uint8
TrailLength int
TotalASCount int
SegmentIndex int
PathLocation PathLocation
IsTransfer bool
}{
// "3-2-4 at 0" means:
// 3 segments, with 3 ASes in the first one, 2 and 4 in the others. Trail has 0 components
"2 at 0": {
ASCountPerSegment: []uint8{2},
TrailLength: 0,
TotalASCount: 2,
SegmentIndex: 0,
PathLocation: Source,
IsTransfer: false,
},
"2 at 1": {
ASCountPerSegment: []uint8{2},
TrailLength: 1,
TotalASCount: 2,
SegmentIndex: 0,
PathLocation: Transit,
IsTransfer: false,
},
"2 at 2": {
ASCountPerSegment: []uint8{2},
TrailLength: 2,
TotalASCount: 2,
SegmentIndex: 0,
PathLocation: Destination,
IsTransfer: false,
},
"3-4-5 at 0": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 0,
TotalASCount: 10,
SegmentIndex: 0,
PathLocation: Source,
IsTransfer: false,
},
"3-4-5 at 1": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 1,
TotalASCount: 10,
SegmentIndex: 0,
PathLocation: Transit,
IsTransfer: false,
},
"3-4-5 at 2": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 2,
TotalASCount: 10,
SegmentIndex: 0,
PathLocation: Transit,
IsTransfer: true,
},
"3-4-5 at 3": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 3,
TotalASCount: 10,
SegmentIndex: 1,
PathLocation: Transit,
IsTransfer: false,
},
"3-4-5 at 5": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 5,
TotalASCount: 10,
SegmentIndex: 1,
PathLocation: Transit,
IsTransfer: true,
},
"3-4-5 at 6": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 6,
TotalASCount: 10,
SegmentIndex: 2,
PathLocation: Transit,
IsTransfer: false,
},
"3-4-5 at 9": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 9,
TotalASCount: 10,
SegmentIndex: 2,
PathLocation: Transit,
IsTransfer: false,
},
"3-4-5 at 10": {
ASCountPerSegment: []uint8{3, 4, 5},
TrailLength: 10,
TotalASCount: 10,
SegmentIndex: 2,
PathLocation: Destination,
IsTransfer: false,
},
}
for name, tc := range cases {
name, tc := name, tc
t.Run(name, func(t *testing.T) {
t.Parallel()
segmentRsvs := make([]reservation.SegmentID, len(tc.ASCountPerSegment))
for i := range segmentRsvs {
segmentRsvs[i] = *newTestSegmentID(t)
}
trail := make([]reservation.BWCls, tc.TrailLength)
for i := range trail {
trail[i] = 5
}
r, err := NewSetupRequest(baseReq, segmentRsvs, tc.ASCountPerSegment, 5, trail)
require.NoError(t, err)
require.Equal(t, tc.TotalASCount, r.totalASCount)
require.Equal(t, tc.SegmentIndex, r.currentASSegmentRsvIndex)
require.Equal(t, tc.PathLocation, r.Location())
require.Equal(t, tc.IsTransfer, r.Transfer())
})
}
}

func TestInterface(t *testing.T) {
id, err := reservation.NewE2EID(xtest.MustParseAS("ff00:0:111"),
xtest.MustParseHexString("beefcafebeefcafebeef"))
require.NoError(t, err)
path := segmenttest.NewTestPath()
baseReq, err := NewRequest(util.SecsToTime(1), id, 1, path)
require.NoError(t, err)
segmentIDs := []reservation.SegmentID{*newTestSegmentID(t)}

r, err := NewSetupRequest(baseReq, segmentIDs, []uint8{2}, 5, nil)
require.NoError(t, err)
tok, err := reservation.TokenFromRaw(xtest.MustParseHexString(
"16ebdb4f0d042500003f001002bad1ce003f001002facade"))
require.NoError(t, err)
success := SetupReqSuccess{
SetupReq: *r,
Token: *tok,
}
require.Equal(t, r, success.GetCommonSetupReq())
failure := SetupReqFailure{
SetupReq: *r,
ErrorCode: 6,
}
require.Equal(t, r, failure.GetCommonSetupReq())
}

// this fcn is helpful here to add segment reservations in the e2e setup request.
func newTestSegmentID(t *testing.T) *reservation.SegmentID {
t.Helper()
id, err := reservation.NewSegmentID(xtest.MustParseAS("ff00:0:1"),
xtest.MustParseHexString("deadbeef"))
require.NoError(t, err)
return id
}
Loading

0 comments on commit fb4a0f7

Please sign in to comment.