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

spath: drop old header code #3909

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 2 deletions go/cs/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ go_library(
"//go/lib/log:go_default_library",
"//go/lib/prom:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/tracing:go_default_library",
"//go/lib/util:go_default_library",
"//go/pkg/proto/control_plane:go_default_library",
Expand Down Expand Up @@ -55,7 +54,6 @@ go_test(
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/hiddenpath:go_default_library",
"//go/lib/hiddenpath/hiddenpathtest:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/util:go_default_library",
"//go/lib/xtest:go_default_library",
"//go/lib/xtest/graph:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion go/cs/beacon/beacondbtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go_library(
"//go/lib/ctrl/path_mgmt:go_default_library",
"//go/lib/ctrl/seg:go_default_library",
"//go/lib/infra:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/slayers/path:go_default_library",
"//go/lib/util:go_default_library",
"//go/lib/xtest/graph:go_default_library",
"//go/proto:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions go/cs/beacon/beacondbtest/beacondbtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/slayers/path"
"github.com/scionproto/scion/go/lib/util"
"github.com/scionproto/scion/go/lib/xtest/graph"
"github.com/scionproto/scion/go/proto"
Expand Down Expand Up @@ -356,7 +356,7 @@ func testDeleteExpiredBeacons(t *testing.T, ctrl *gomock.Controller, db beacon.D
ts1 := uint32(10)
ts2 := uint32(20)
// defaultExp is the default expiry of the hopfields.
defaultExp := spath.DefaultHopFExpiry.ToDuration()
defaultExp := path.ExpTimeToDuration(63)
ctx, cancelF := context.WithTimeout(context.Background(), timeout)
defer cancelF()
InsertBeacon(t, ctrl, db, Info3, 12, ts1, beacon.UsageProp)
Expand Down Expand Up @@ -787,7 +787,7 @@ func AllocBeacon(t *testing.T, ctrl *gomock.Controller, ases []IfInfo, inIfId co
PeerInterface: 1337,
PeerMTU: 1500,
HopField: seg.HopField{
ExpTime: uint8(spath.DefaultHopFExpiry),
ExpTime: 63,
ConsIngress: uint16(peer.Ingress),
ConsEgress: uint16(as.Egress),
MAC: bytes.Repeat([]byte{0xff}, 6),
Expand All @@ -801,7 +801,7 @@ func AllocBeacon(t *testing.T, ctrl *gomock.Controller, ases []IfInfo, inIfId co
HopEntry: seg.HopEntry{
IngressMTU: mtu,
HopField: seg.HopField{
ExpTime: uint8(spath.DefaultHopFExpiry),
ExpTime: 63,
ConsIngress: uint16(as.Ingress),
ConsEgress: uint16(as.Egress),
MAC: bytes.Repeat([]byte{0xff}, 6),
Expand Down
5 changes: 2 additions & 3 deletions go/cs/beacon/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
)

// PolicyType is the policy type.
Expand All @@ -47,7 +46,7 @@ const (
// DefaultMaxHopsLength is the default MaxHopsLength value.
DefaultMaxHopsLength = 10
// DefaultMaxExpTime is the default MaxExpTime value.
DefaultMaxExpTime = spath.DefaultHopFExpiry
DefaultMaxExpTime = uint8(63)
)

// Policies keeps track of all policies for a non-core beacon store.
Expand Down Expand Up @@ -184,7 +183,7 @@ type Policy struct {
CandidateSetSize int `yaml:"CandidateSetSize"`
// MaxExpTime indicates the maximum value for the expiration time when
// extending the segment.
MaxExpTime *spath.ExpTimeType `yaml:"MaxExpTime"`
MaxExpTime *uint8 `yaml:"MaxExpTime"`
// Filter is the filter applied to segments.
Filter Filter `yaml:"Filter"`
// Type is the policy type.
Expand Down
3 changes: 1 addition & 2 deletions go/cs/beacon/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/scionproto/scion/go/cs/beacon"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/xtest"
)

Expand Down Expand Up @@ -71,7 +70,7 @@ func TestLoadPolicyFromYaml(t *testing.T) {
assert.Equal(t, 6, p.BestSetSize)
assert.Equal(t, 20, p.CandidateSetSize)
assert.Equal(t, test.Type, p.Type)
assert.Equal(t, spath.ExpTimeType(42), *p.MaxExpTime)
assert.Equal(t, uint8(42), *p.MaxExpTime)
assert.Equal(t, 8, p.Filter.MaxHopsLength)
assert.Equal(t, []addr.AS{ia110.A, ia111.A}, p.Filter.AsBlackList)
assert.Equal(t, []addr.ISD{1, 2, 3}, p.Filter.IsdBlackList)
Expand Down
5 changes: 2 additions & 3 deletions go/cs/beacon/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
)

const maxResultChanSize = 32
Expand Down Expand Up @@ -102,7 +101,7 @@ func (s *Store) getBeacons(ctx context.Context, policy *Policy) (<-chan BeaconOr
}

// MaxExpTime returns the segment maximum expiration time for the given policy.
func (s *Store) MaxExpTime(policyType PolicyType) spath.ExpTimeType {
func (s *Store) MaxExpTime(policyType PolicyType) uint8 {
switch policyType {
case UpRegPolicy:
return *s.policies.UpReg.MaxExpTime
Expand Down Expand Up @@ -200,7 +199,7 @@ func (s *CoreStore) getBeacons(ctx context.Context, policy *Policy) (<-chan Beac
}

// MaxExpTime returns the segment maximum expiration time for the given policy.
func (s *CoreStore) MaxExpTime(policyType PolicyType) spath.ExpTimeType {
func (s *CoreStore) MaxExpTime(policyType PolicyType) uint8 {
switch policyType {
case CoreRegPolicy:
return *s.policies.CoreReg.MaxExpTime
Expand Down
1 change: 0 additions & 1 deletion go/cs/beaconing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ go_library(
"//go/lib/serrors:go_default_library",
"//go/lib/slayers/path:go_default_library",
"//go/lib/snet:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/topology:go_default_library",
"//go/lib/tracing:go_default_library",
"//go/lib/util:go_default_library",
Expand Down
3 changes: 1 addition & 2 deletions go/cs/beaconing/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/slayers/path"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/topology"
"github.com/scionproto/scion/go/lib/util"
)
Expand Down Expand Up @@ -258,7 +257,7 @@ func intfActive(intfs *ifstate.Interfaces, ifid common.IFIDType) bool {
return intf != nil && intf.State() == ifstate.Active
}

func min(a, b spath.ExpTimeType) spath.ExpTimeType {
func min(a, b uint8) uint8 {
if a > b {
return b
}
Expand Down
5 changes: 2 additions & 3 deletions go/cs/beaconing/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/scionproto/scion/go/lib/ctrl/seg"
"github.com/scionproto/scion/go/lib/infra/modules/itopo/itopotest"
"github.com/scionproto/scion/go/lib/scrypto"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/xtest/graph"
cryptopb "github.com/scionproto/scion/go/pkg/proto/crypto"
)
Expand Down Expand Up @@ -276,8 +275,8 @@ func (f *failSigner) Sign(context.Context, []byte, ...[]byte) (*cryptopb.SignedM
return nil, errors.New("fail")
}

func maxExpTimeFactory(max spath.ExpTimeType) func() spath.ExpTimeType {
return func() spath.ExpTimeType {
func maxExpTimeFactory(max uint8) func() uint8 {
return func() uint8 {
return max
}
}
Expand Down
21 changes: 7 additions & 14 deletions go/cs/beaconing/grpc/creation_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,14 @@ func (s SegmentCreationServer) Beacon(ctx context.Context,
}

// extractIngressIfID extracts the ingress interface ID from a path.
func extractIngressIfID(path *spath.Path) (common.IFIDType, error) {
if path.IsHeaderV2() {
var sp scion.Raw
if err := sp.DecodeFromBytes(path.Raw); err != nil {
return 0, serrors.WrapStr("decoding path (v2)", err)
}
hf, err := sp.GetCurrentHopField()
if err != nil {
return 0, serrors.WrapStr("getting current hop field", err)
}
return common.IFIDType(hf.ConsIngress), nil
func extractIngressIfID(path spath.Path) (common.IFIDType, error) {
var sp scion.Raw
if err := sp.DecodeFromBytes(path.Raw); err != nil {
return 0, serrors.WrapStr("decoding path (v2)", err)
}
hopF, err := path.GetHopField(path.HopOff)
hf, err := sp.GetCurrentHopField()
if err != nil {
return 0, serrors.WrapStr("extracting hop field", err)
return 0, serrors.WrapStr("getting current hop field", err)
}
return hopF.ConsIngress, nil
return common.IFIDType(hf.ConsIngress), nil
}
10 changes: 2 additions & 8 deletions go/cs/beaconing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,8 @@ func testSegment(g *graph.Graph, ifids []common.IFIDType) *seg.PathSegment {
return pseg
}

func testPath(ingressIfid common.IFIDType) *spath.Path {
path := &spath.Path{
Raw: make(common.RawBytes, spath.InfoFieldLength+spath.HopFieldLength),
HopOff: spath.InfoFieldLength,
}
(&spath.InfoField{Hops: 1}).Write(path.Raw[:spath.InfoFieldLength])
(&spath.HopField{ConsIngress: ingressIfid}).Write(path.Raw[spath.InfoFieldLength:])
return path
func testPath(ingressIfid common.IFIDType) spath.Path {
return spath.Path{}
}

func testInterfaces(topo topology.Topology) *ifstate.Interfaces {
Expand Down
12 changes: 6 additions & 6 deletions go/cs/onehop/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *Sender) CreatePkt(msg *Msg) (*snet.Packet, error) {
IA: s.IA,
Host: addr.HostFromIP(s.Addr.IP),
},
Path: (*spath.Path)(path),
Path: (spath.Path)(path),
Payload: snet.UDPPayload{
SrcPort: uint16(s.Addr.Port),
Payload: msg.Pld,
Expand All @@ -94,15 +94,15 @@ func (s *Sender) CreatePkt(msg *Msg) (*snet.Packet, error) {
}

// CreatePath creates the one-hop path and initializes it.
func (s *Sender) CreatePath(ifid common.IFIDType, now time.Time) (*Path, error) {
func (s *Sender) CreatePath(ifid common.IFIDType, now time.Time) (Path, error) {
s.macMtx.Lock()
defer s.macMtx.Unlock()

path, err := spath.NewOneHopV2(s.IA.I, ifid, now, spath.DefaultHopFExpiry, s.MAC)
path, err := spath.NewOneHop(s.IA.I, uint16(ifid), now, 63, s.MAC)
if err != nil {
return nil, err
return Path{}, err
}
return (*Path)(path), nil
return (Path)(path), nil
}

// RPC is used to send beacons.
Expand Down Expand Up @@ -130,7 +130,7 @@ func (s *BeaconSender) Send(ctx context.Context, bseg *seg.PathSegment, ia addr.

svc := &snet.SVCAddr{
IA: ia,
Path: (*spath.Path)(path),
Path: (spath.Path)(path),
NextHop: ov,
SVC: addr.SvcCS,
}
Expand Down
2 changes: 1 addition & 1 deletion go/hidden_path_srv/internal/registration/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestSegReg(t *testing.T) {
Recs: []*seg.Meta{seg110_133},
},
}
peer := &snet.UDPAddr{IA: addr.IA{}, Path: &spath.Path{}}
peer := &snet.UDPAddr{IA: addr.IA{}, Path: spath.Path{}}
req := infra.NewRequest(ctx, msg, nil, peer, 0)
ack := ack.Ack{
Err: proto.Ack_ErrCode_reject,
Expand Down
8 changes: 3 additions & 5 deletions go/integration/end2end/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@ func (s server) run() {
}
log.Debug(fmt.Sprintf("Ping received from %s, sending pong.", p.Source))
// reverse path
if p.Path != nil {
if err := p.Path.Reverse(); err != nil {
log.Debug(fmt.Sprintf("Error reversing path, err = %v", err))
continue
}
if err := p.Path.Reverse(); err != nil {
log.Debug(fmt.Sprintf("Error reversing path, err = %v", err))
continue
}
// Send pong
if err := conn.WriteTo(&p, &ov); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions go/lib/ctrl/seg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ go_library(
"//go/lib/common:go_default_library",
"//go/lib/scrypto/signed:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/slayers/path:go_default_library",
"//go/lib/util:go_default_library",
"//go/pkg/proto/control_plane:go_default_library",
"//go/pkg/proto/crypto:go_default_library",
Expand All @@ -38,10 +38,8 @@ go_test(
embed = [":go_default_library"],
deps = [
"//go/lib/addr:go_default_library",
"//go/lib/common:go_default_library",
"//go/lib/scrypto/signed:go_default_library",
"//go/lib/serrors:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/xtest:go_default_library",
"//go/pkg/proto/crypto:go_default_library",
"@com_github_golang_mock//gomock:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions go/lib/ctrl/seg/seg.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/scrypto/signed"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/slayers/path"
"github.com/scionproto/scion/go/lib/util"
cppb "github.com/scionproto/scion/go/pkg/proto/control_plane"
cryptopb "github.com/scionproto/scion/go/pkg/proto/crypto"
Expand Down Expand Up @@ -213,7 +213,7 @@ func (ps *PathSegment) MaxExpiry() time.Time {
// MinExpiry returns the minimum expiry of all hop fields.
// Assumes segment is validated.
func (ps *PathSegment) MinExpiry() time.Time {
return ps.expiry(spath.MaxTTL*time.Second, func(hfTtl time.Duration, ttl time.Duration) bool {
return ps.expiry(path.MaxTTL*time.Second, func(hfTtl time.Duration, ttl time.Duration) bool {
return hfTtl < ttl
})
}
Expand All @@ -223,12 +223,12 @@ func (ps *PathSegment) expiry(initTTL time.Duration,

ttl := initTTL
for _, asEntry := range ps.ASEntries {
hfTTL := spath.ExpTimeType(asEntry.HopEntry.HopField.ExpTime).ToDuration()
hfTTL := path.ExpTimeToDuration(asEntry.HopEntry.HopField.ExpTime)
if compare(hfTTL, ttl) {
ttl = hfTTL
}
for _, peer := range asEntry.PeerEntries {
hfTTL := spath.ExpTimeType(peer.HopField.ExpTime).ToDuration()
hfTTL := path.ExpTimeToDuration(peer.HopField.ExpTime)
if compare(hfTTL, ttl) {
ttl = hfTTL
}
Expand Down
7 changes: 3 additions & 4 deletions go/lib/ctrl/seg/seg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/scionproto/scion/go/lib/scrypto/signed"
"github.com/scionproto/scion/go/lib/serrors"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/lib/xtest"
cryptopb "github.com/scionproto/scion/go/pkg/proto/crypto"
)
Expand All @@ -51,7 +50,7 @@ func TestPathSegmentAddASEntry(t *testing.T) {
HopField: HopField{
ConsIngress: 0,
ConsEgress: 1,
ExpTime: uint8(spath.DefaultHopFExpiry),
ExpTime: 63,
MAC: bytes.Repeat([]byte{0x11}, 6),
},
IngressMTU: 0,
Expand All @@ -65,7 +64,7 @@ func TestPathSegmentAddASEntry(t *testing.T) {
HopField: HopField{
ConsIngress: 10,
ConsEgress: 11,
ExpTime: uint8(spath.DefaultHopFExpiry),
ExpTime: 63,
MAC: bytes.Repeat([]byte{0x22}, 6),
},
IngressMTU: 1337,
Expand All @@ -79,7 +78,7 @@ func TestPathSegmentAddASEntry(t *testing.T) {
HopField: HopField{
ConsIngress: 20,
ConsEgress: 21,
ExpTime: uint8(spath.DefaultHopFExpiry),
ExpTime: 63,
MAC: bytes.Repeat([]byte{0x33}, 6),
},
IngressMTU: 1442,
Expand Down
Loading