Skip to content

Commit

Permalink
e2e setup request app level type to ctrl msg
Browse files Browse the repository at this point in the history
  • Loading branch information
juagargi committed May 13, 2020
1 parent 658cca5 commit 35eda4d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions go/cs/reservation/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//go/lib/colibri/reservation:go_default_library",
"//go/lib/ctrl/colibri_mgmt:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/proto:go_default_library",
],
)

Expand Down
51 changes: 49 additions & 2 deletions go/cs/reservation/e2e/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ import (
"github.com/scionproto/scion/go/lib/colibri/reservation"
"github.com/scionproto/scion/go/lib/ctrl/colibri_mgmt"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/proto"
)

// SetupReq is the interface for an e2e setup request.
// Currently it's implemented by either SuccessSetupReq or FailureSetupReq.
type SetupReq interface {
Reservation() *Reservation
Timestamp() time.Time
ToCtrlMsg() (*colibri_mgmt.E2ESetup, error)
}

// BaseSetupReq is the common part of any e2e setup request.
Expand All @@ -35,8 +37,8 @@ type BaseSetupReq struct {
timestamp time.Time
}

func (s *BaseSetupReq) Timestamp() time.Time { return s.timestamp }
func (s *BaseSetupReq) Reservation() *Reservation { return s.reservation }
func (r *BaseSetupReq) Timestamp() time.Time { return r.timestamp }
func (r *BaseSetupReq) Reservation() *Reservation { return r.reservation }

// SuccessSetupReq is a successful e2e resevation setup request.
type SuccessSetupReq struct {
Expand All @@ -47,6 +49,30 @@ type SuccessSetupReq struct {

var _ SetupReq = (*SuccessSetupReq)(nil)

func (r *SuccessSetupReq) ToCtrlMsg() (*colibri_mgmt.E2ESetup, error) {
id := make([]byte, reservation.E2EIDLen)
_, err := r.ID.Read(id)
if err != nil {
return nil, err
}
token := make([]byte, r.Token.Len())
_, err = r.Token.Read(token)
if err != nil {
return nil, err
}
msg := &colibri_mgmt.E2ESetup{
Which: proto.E2ESetupData_Which_success,
Success: &colibri_mgmt.E2ESetupSuccess{
ReservationID: &colibri_mgmt.E2EReservationID{
ASID: id[:6],
Suffix: id[6:],
},
Token: token,
},
}
return msg, nil
}

// FailureSetupReq is a failing e2e resevation setup request.
type FailureSetupReq struct {
BaseSetupReq
Expand All @@ -57,6 +83,27 @@ type FailureSetupReq struct {

var _ SetupReq = (*FailureSetupReq)(nil)

func (r *FailureSetupReq) ToCtrlMsg() (*colibri_mgmt.E2ESetup, error) {
inf := make([]byte, reservation.InfoFieldLen)
_, err := r.InfoField.Read(inf)
if err != nil {
return nil, err
}
trail := make([]uint8, len(r.MaxBWTrail))
for i, bw := range r.MaxBWTrail {
trail[i] = uint8(bw)
}
msg := &colibri_mgmt.E2ESetup{
Which: proto.E2ESetupData_Which_failure,
Failure: &colibri_mgmt.E2ESetupFailure{
ErrorCode: uint8(r.ErrorCode),
InfoField: inf,
MaxBWs: trail,
},
}
return msg, nil
}

// NewRequestFromCtrlMsg will return a SuccessSetupReq or FailSetupReq depending on the
// success flag of the ctrl message.
func NewRequestFromCtrlMsg(setup *colibri_mgmt.E2ESetup, ts time.Time) (SetupReq, error) {
Expand Down
15 changes: 15 additions & 0 deletions go/cs/reservation/e2e/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ func TestNewRequestFromCtrlMsg(t *testing.T) {
checkRequest(t, setup, r, ts)
}

func TestRequestToCtrlMsg(t *testing.T) {
setup := newE2ESetupSuccess()
ts := time.Unix(1, 0)
r, _ := e2e.NewRequestFromCtrlMsg(setup, ts)
anotherSetup, err := r.ToCtrlMsg()
require.NoError(t, err)
require.Equal(t, setup, anotherSetup)

setup = newE2ESetupFailure()
r, _ = e2e.NewRequestFromCtrlMsg(setup, ts)
anotherSetup, err = r.ToCtrlMsg()
require.NoError(t, err)
require.Equal(t, setup, anotherSetup)
}

func newE2ESetupSuccess() *colibri_mgmt.E2ESetup {
return &colibri_mgmt.E2ESetup{
Which: proto.E2ESetupData_Which_success,
Expand Down

0 comments on commit 35eda4d

Please sign in to comment.