diff --git a/go/cs/segutil/filter.go b/go/cs/segutil/filter.go index b40ca0f8e2..b5a3df242f 100644 --- a/go/cs/segutil/filter.go +++ b/go/cs/segutil/filter.go @@ -18,7 +18,6 @@ import ( "fmt" "strings" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl/seg" "github.com/scionproto/scion/go/lib/pathpol" @@ -58,7 +57,7 @@ func segsToPs(segs seg.Segments, dir Direction) pathpol.PathSet { ps := make(pathpol.PathSet, len(segs)) for _, seg := range segs { sw := wrap(seg, dir) - ps[sw.Fingerprint()] = sw + ps[sw.key] = sw } return ps } @@ -92,9 +91,9 @@ func wrap(seg *seg.PathSegment, dir Direction) segWrap { for _, ifid := range interfaces { if ifid != 0 { - intfs = append(intfs, pathInterface{ - ia: asEntry.Local, - ifid: common.IFIDType(ifid), + intfs = append(intfs, snet.PathInterface{ + IA: asEntry.Local, + ID: common.IFIDType(ifid), }) keyParts = append(keyParts, fmt.Sprintf("%s#%d", asEntry.Local, ifid)) } @@ -113,13 +112,4 @@ func wrap(seg *seg.PathSegment, dir Direction) segWrap { } } -func (s segWrap) Interfaces() []snet.PathInterface { return s.intfs } -func (s segWrap) Fingerprint() snet.PathFingerprint { return s.key } - -type pathInterface struct { - ia addr.IA - ifid common.IFIDType -} - -func (i pathInterface) IA() addr.IA { return i.ia } -func (i pathInterface) ID() common.IFIDType { return i.ifid } +func (s segWrap) Interfaces() []snet.PathInterface { return s.intfs } diff --git a/go/cs/segutil/router.go b/go/cs/segutil/router.go index 8c75326350..c9aae0e10f 100644 --- a/go/cs/segutil/router.go +++ b/go/cs/segutil/router.go @@ -84,13 +84,13 @@ func (r *Router) translate(comb *combinator.Path, dst addr.IA) (path, error) { } else { sp = spath.NewV2(buf.Bytes(), false) } - nextHop, ok := r.Pather.TopoProvider.Get().UnderlayNextHop(comb.Interfaces[0].IfID) + nextHop, ok := r.Pather.TopoProvider.Get().UnderlayNextHop(comb.Interfaces[0].ID) if !ok { return path{}, serrors.New("Unable to find first-hop BR for path", - "ifid", comb.Interfaces[0].IfID) + "ifid", comb.Interfaces[0].ID) } p := path{ - interfaces: make([]pathInterface, 0, len(comb.Interfaces)), + interfaces: make([]snet.PathInterface, len(comb.Interfaces)), underlay: nextHop, spath: sp, metadata: pathMetadata{ @@ -98,14 +98,12 @@ func (r *Router) translate(comb *combinator.Path, dst addr.IA) (path, error) { expiry: comb.ComputeExpTime(), }, } - for _, intf := range comb.Interfaces { - p.interfaces = append(p.interfaces, pathInterface{ia: intf.IA(), ifid: intf.ID()}) - } + copy(p.interfaces, comb.Interfaces) return p, nil } type path struct { - interfaces []pathInterface + interfaces []snet.PathInterface underlay *net.UDPAddr spath *spath.Path dst addr.IA @@ -150,7 +148,7 @@ func (p path) Destination() addr.IA { if len(p.interfaces) == 0 { return p.dst } - return p.interfaces[len(p.interfaces)-1].IA() + return p.interfaces[len(p.interfaces)-1].IA } func (p path) Metadata() snet.PathMetadata { @@ -178,14 +176,14 @@ func (p path) fmtInterfaces() []string { return hops } intf := p.interfaces[0] - hops = append(hops, fmt.Sprintf("%s %d", intf.IA(), intf.ID())) + hops = append(hops, fmt.Sprintf("%s %d", intf.IA, intf.ID)) for i := 1; i < len(p.interfaces)-1; i += 2 { inIntf := p.interfaces[i] outIntf := p.interfaces[i+1] - hops = append(hops, fmt.Sprintf("%d %s %d", inIntf.ID(), inIntf.IA(), outIntf.ID())) + hops = append(hops, fmt.Sprintf("%d %s %d", inIntf.ID, inIntf.IA, outIntf.ID)) } intf = p.interfaces[len(p.interfaces)-1] - hops = append(hops, fmt.Sprintf("%d %s", intf.ID(), intf.IA())) + hops = append(hops, fmt.Sprintf("%d %s", intf.ID, intf.IA)) return hops } diff --git a/go/lib/infra/modules/combinator/BUILD.bazel b/go/lib/infra/modules/combinator/BUILD.bazel index 56d806bcfe..382d0fc135 100644 --- a/go/lib/infra/modules/combinator/BUILD.bazel +++ b/go/lib/infra/modules/combinator/BUILD.bazel @@ -13,10 +13,10 @@ go_library( "//go/lib/addr:go_default_library", "//go/lib/common:go_default_library", "//go/lib/ctrl/seg:go_default_library", - "//go/lib/sciond:go_default_library", "//go/lib/serrors:go_default_library", "//go/lib/slayers/path:go_default_library", "//go/lib/slayers/path/scion:go_default_library", + "//go/lib/snet:go_default_library", "//go/lib/spath:go_default_library", "//go/lib/util:go_default_library", "//go/proto:go_default_library", diff --git a/go/lib/infra/modules/combinator/combinator.go b/go/lib/infra/modules/combinator/combinator.go index e5728767e0..8b9bc60e0d 100644 --- a/go/lib/infra/modules/combinator/combinator.go +++ b/go/lib/infra/modules/combinator/combinator.go @@ -32,10 +32,10 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl/seg" - "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/serrors" "github.com/scionproto/scion/go/lib/slayers/path" "github.com/scionproto/scion/go/lib/slayers/path/scion" + "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/spath" "github.com/scionproto/scion/go/lib/util" "github.com/scionproto/scion/go/proto" @@ -95,7 +95,7 @@ type Path struct { Segments []*Segment Weight int Mtu uint16 - Interfaces []sciond.PathInterface + Interfaces []snet.PathInterface StaticInfo *PathMetadata HeaderV2 bool @@ -124,7 +124,7 @@ func (p *Path) reverseDownSegment() { } func (p *Path) aggregateInterfaces() { - p.Interfaces = []sciond.PathInterface{} + p.Interfaces = []snet.PathInterface{} for _, segment := range p.Segments { p.Interfaces = append(p.Interfaces, segment.Interfaces...) } @@ -228,7 +228,7 @@ type Segment struct { InfoField *InfoField HopFields []*HopField Type proto.PathSegType - Interfaces []sciond.PathInterface + Interfaces []snet.PathInterface } // initInfoFieldFrom copies the info field in pathSegment, and sets it as the @@ -336,8 +336,8 @@ func FilterLongPaths(paths []*Path) []*Path { long := false iaCounts := make(map[addr.IA]int) for _, iface := range path.Interfaces { - iaCounts[iface.IA()]++ - if iaCounts[iface.IA()] > 2 { + iaCounts[iface.IA]++ + if iaCounts[iface.IA] > 2 { long = true break } diff --git a/go/lib/infra/modules/combinator/graph.go b/go/lib/infra/modules/combinator/graph.go index ab10c6f64f..3268607968 100644 --- a/go/lib/infra/modules/combinator/graph.go +++ b/go/lib/infra/modules/combinator/graph.go @@ -23,7 +23,7 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/ctrl/seg" - "github.com/scionproto/scion/go/lib/sciond" + "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/proto" ) @@ -288,7 +288,7 @@ func (solution *PathSolution) getFwdPathMetadata() *Path { } for _, solEdge := range solution.edges { var hops []*HopField - var intfs []sciond.PathInterface + var intfs []snet.PathInterface // Go through each ASEntry, starting from the last one, until we // find a shortcut (which can be 0, meaning the end of the segment). @@ -327,16 +327,16 @@ func (solution *PathSolution) getFwdPathMetadata() *Path { // Segment is traversed in reverse construction direction. // Only include non-zero interfaces. if hopField.ConsEgress != 0 { - intfs = append(intfs, sciond.PathInterface{ - RawIsdas: asEntry.Local.IAInt(), - IfID: common.IFIDType(hopField.ConsEgress), + intfs = append(intfs, snet.PathInterface{ + IA: asEntry.Local, + ID: common.IFIDType(hopField.ConsEgress), }) } // In a non-peer shortcut the AS is not traversed completely. if hopField.ConsIngress != 0 && (!isShortcut || isPeer) { - intfs = append(intfs, sciond.PathInterface{ - RawIsdas: asEntry.Local.IAInt(), - IfID: common.IFIDType(hopField.ConsIngress), + intfs = append(intfs, snet.PathInterface{ + IA: asEntry.Local, + ID: common.IFIDType(hopField.ConsIngress), }) } hops = append(hops, hopField) @@ -549,15 +549,15 @@ func minUint16(x, y uint16) uint16 { return y } -func getPathInterfaces(ia addr.IA, inIFID, outIFID common.IFIDType) []sciond.PathInterface { - var result []sciond.PathInterface +func getPathInterfaces(ia addr.IA, inIFID, outIFID common.IFIDType) []snet.PathInterface { + var result []snet.PathInterface if inIFID != 0 { result = append(result, - sciond.PathInterface{RawIsdas: ia.IAInt(), IfID: inIFID}) + snet.PathInterface{IA: ia, ID: inIFID}) } if outIFID != 0 { result = append(result, - sciond.PathInterface{RawIsdas: ia.IAInt(), IfID: outIFID}) + snet.PathInterface{IA: ia, ID: outIFID}) } return result } diff --git a/go/lib/infra/modules/segfetcher/pather.go b/go/lib/infra/modules/segfetcher/pather.go index 8a70ef7ec7..9bc4820966 100644 --- a/go/lib/infra/modules/segfetcher/pather.go +++ b/go/lib/infra/modules/segfetcher/pather.go @@ -126,7 +126,7 @@ func (p *Pather) filterRevoked(ctx context.Context, for _, iface := range path.Interfaces { // cache automatically expires outdated revocations every second, // so a cache hit implies revocation is still active. - revs, err := p.RevCache.Get(ctx, revcache.SingleKey(iface.IA(), iface.IfID)) + revs, err := p.RevCache.Get(ctx, revcache.SingleKey(iface.IA, iface.ID)) if err != nil { logger.Error("[segfetcher.Pather] Failed to get revocation", "err", err) // continue, the client might still get some usable paths like this. diff --git a/go/lib/pathmgr/pathmgr.go b/go/lib/pathmgr/pathmgr.go index 30a65420b8..ba8d9c4900 100644 --- a/go/lib/pathmgr/pathmgr.go +++ b/go/lib/pathmgr/pathmgr.go @@ -225,8 +225,7 @@ func (r *resolver) Revoke(ctx context.Context, sRevInfo *path_mgmt.SignedRevInfo } // Each watcher contains a cache; purge paths matched by the revocation // immediately from each cache. - pi := sciond.PathInterface{RawIsdas: revInfo.IA().IAInt(), - IfID: common.IFIDType(revInfo.IfID)} + pi := snet.PathInterface{IA: revInfo.IA(), ID: revInfo.IfID} f := func(w *WatchRunner) { pathsBeforeRev := w.sp.Load().APS pathsAfterRev := dropRevoked(pathsBeforeRev, pi) @@ -242,7 +241,7 @@ func (r *resolver) logger(ctx context.Context) log.Logger { return log.FromCtx(ctx).New("lib", "PathResolver") } -func dropRevoked(aps spathmeta.AppPathSet, pi sciond.PathInterface) spathmeta.AppPathSet { +func dropRevoked(aps spathmeta.AppPathSet, pi snet.PathInterface) spathmeta.AppPathSet { other := make(spathmeta.AppPathSet) for key, path := range aps { if !matches(path, pi) { @@ -252,9 +251,9 @@ func dropRevoked(aps spathmeta.AppPathSet, pi sciond.PathInterface) spathmeta.Ap return other } -func matches(path snet.Path, predicatePI sciond.PathInterface) bool { +func matches(path snet.Path, predicatePI snet.PathInterface) bool { for _, pi := range path.Interfaces() { - if pi.IA().Equal(predicatePI.IA()) && pi.ID() == predicatePI.ID() { + if pi.IA.Equal(predicatePI.IA) && pi.ID == predicatePI.ID { return true } } diff --git a/go/lib/pathmgr/pathmgr_test.go b/go/lib/pathmgr/pathmgr_test.go index 0233c6f12d..ee9a294be7 100644 --- a/go/lib/pathmgr/pathmgr_test.go +++ b/go/lib/pathmgr/pathmgr_test.go @@ -225,7 +225,7 @@ func TestWatchFilter(t *testing.T) { replySet := make(pathpol.PathSet) for key, v := range ps { for _, intf := range v.Interfaces() { - if intf.IA().Equal(src) && intf.ID() == 105 { + if intf.IA.Equal(src) && intf.ID == 105 { replySet[key] = v break } diff --git a/go/lib/pathmgr/util_test.go b/go/lib/pathmgr/util_test.go index f05518b4fb..24e12aeda9 100644 --- a/go/lib/pathmgr/util_test.go +++ b/go/lib/pathmgr/util_test.go @@ -22,7 +22,6 @@ import ( "github.com/golang/mock/gomock" - "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/snet/mock_snet" @@ -46,9 +45,9 @@ func createPath(t testing.TB, ctrl *gomock.Controller, desc string) snet.Path { if len(tokens) != 2 { t.Fatalf("Invalid path description: %s", desc) } - interfaces = append(interfaces, intf{ - ia: xtest.MustParseIA(tokens[0]), - id: mustIfID(t, tokens[1]), + interfaces = append(interfaces, snet.PathInterface{ + IA: xtest.MustParseIA(tokens[0]), + ID: mustIfID(t, tokens[1]), }) } path.EXPECT().Interfaces().Return(interfaces).AnyTimes() @@ -62,11 +61,3 @@ func mustIfID(t testing.TB, s string) common.IFIDType { } return common.IFIDType(ifID) } - -type intf struct { - ia addr.IA - id common.IFIDType -} - -func (i intf) IA() addr.IA { return i.ia } -func (i intf) ID() common.IFIDType { return i.id } diff --git a/go/lib/pathpol/hop_pred.go b/go/lib/pathpol/hop_pred.go index 509ad12a63..ace8316828 100644 --- a/go/lib/pathpol/hop_pred.go +++ b/go/lib/pathpol/hop_pred.go @@ -88,10 +88,10 @@ func HopPredicateFromString(str string) (*HopPredicate, error) { // pathIFMatch takes a PathInterface and a bool indicating if the ingress // interface needs to be matching. It returns true if the HopPredicate matches the PathInterface func (hp *HopPredicate) pathIFMatch(pi snet.PathInterface, in bool) bool { - if hp.ISD != 0 && pi.IA().I != hp.ISD { + if hp.ISD != 0 && pi.IA.I != hp.ISD { return false } - if hp.AS != 0 && pi.IA().A != hp.AS { + if hp.AS != 0 && pi.IA.A != hp.AS { return false } ifInd := 0 @@ -101,7 +101,7 @@ func (hp *HopPredicate) pathIFMatch(pi snet.PathInterface, in bool) bool { if len(hp.IfIDs) == 2 && !in { ifInd = 1 } - if hp.IfIDs[ifInd] != 0 && hp.IfIDs[ifInd] != pi.ID() { + if hp.IfIDs[ifInd] != 0 && hp.IfIDs[ifInd] != pi.ID { return false } return true diff --git a/go/lib/pathpol/policy_test.go b/go/lib/pathpol/policy_test.go index 8d94c0c7ee..dd869aef29 100644 --- a/go/lib/pathpol/policy_test.go +++ b/go/lib/pathpol/policy_test.go @@ -26,7 +26,6 @@ import ( "github.com/stretchr/testify/require" "github.com/scionproto/scion/go/lib/addr" - "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/xtest" "github.com/scionproto/scion/go/lib/xtest/graph" @@ -634,7 +633,7 @@ func (p PathProvider) GetPaths(src, dst addr.IA) PathSet { var key strings.Builder for _, ifid := range ifids { ia := p.g.GetParent(ifid) - pathIntfs = append(pathIntfs, testPathIntf{ia: ia, ifid: ifid}) + pathIntfs = append(pathIntfs, snet.PathInterface{IA: ia, ID: ifid}) key.WriteString(fmt.Sprintf("%s-%d", ia, ifid)) } result[snet.PathFingerprint(key.String())] = &testPath{ @@ -652,14 +651,6 @@ func (p *testPath) Interfaces() []snet.PathInterface { return p.interfaces } -type testPathIntf struct { - ia addr.IA - ifid common.IFIDType -} - -func (i testPathIntf) ID() common.IFIDType { return i.ifid } -func (i testPathIntf) IA() addr.IA { return i.ia } - func mustHopPredicate(t *testing.T, str string) *HopPredicate { hp, err := HopPredicateFromString(str) xtest.FailOnErr(t, err) diff --git a/go/lib/pathpol/sequence.go b/go/lib/pathpol/sequence.go index d140caeff0..7a674b4303 100644 --- a/go/lib/pathpol/sequence.go +++ b/go/lib/pathpol/sequence.go @@ -91,13 +91,13 @@ func (s *Sequence) Eval(inputSet PathSet) PathSet { // one element in form #,, // e.g. 64-ff00:0:112#3,5. For the source AS, the inbound interface will be // zero. For destination AS, outbound interface will be zero. - p := fmt.Sprintf("%s#0,%d ", ifaces[0].IA(), ifaces[0].ID()) + p := fmt.Sprintf("%s#0,%d ", ifaces[0].IA, ifaces[0].ID) for i := 1; i < len(ifaces)-1; i += 2 { - p += fmt.Sprintf("%s#%d,%d ", ifaces[i].IA(), - ifaces[i].ID(), ifaces[i+1].ID()) + p += fmt.Sprintf("%s#%d,%d ", ifaces[i].IA, + ifaces[i].ID, ifaces[i+1].ID) } - p += fmt.Sprintf("%s#%d,0 ", ifaces[len(ifaces)-1].IA(), - ifaces[len(ifaces)-1].ID()) + p += fmt.Sprintf("%s#%d,0 ", ifaces[len(ifaces)-1].IA, + ifaces[len(ifaces)-1].ID) // Check whether the string matches the sequence regexp. //fmt.Printf("EVAL: %s\n", p) if s.re.MatchString(p) { diff --git a/go/lib/sciond/apitypes.go b/go/lib/sciond/apitypes.go index b28bb333a7..946eaa0091 100644 --- a/go/lib/sciond/apitypes.go +++ b/go/lib/sciond/apitypes.go @@ -107,7 +107,7 @@ func protoSVCToAddr(svc proto.ServiceType) addr.HostSVC { } type Path struct { - interfaces []pathInterface + interfaces []snet.PathInterface underlay *net.UDPAddr spath *spath.Path mtu uint16 @@ -115,54 +115,6 @@ type Path struct { dst addr.IA } -func pathReplyToPaths(pathReply *PathReply, dst addr.IA) ([]snet.Path, error) { - if pathReply.ErrorCode != ErrorOk { - return nil, serrors.New("Path lookup had an error", "err_code", pathReply.ErrorCode) - } - paths := make([]snet.Path, 0, len(pathReply.Entries)) - for _, pe := range pathReply.Entries { - p, err := pathReplyEntryToPath(pe, dst) - if err != nil { - return nil, serrors.WrapStr("invalid path received", err) - } - paths = append(paths, p) - } - return paths, nil -} - -func pathReplyEntryToPath(pe PathReplyEntry, dst addr.IA) (Path, error) { - if len(pe.Path.Interfaces) == 0 { - return Path{ - dst: dst, - mtu: pe.Path.Mtu, - expiry: pe.Path.Expiry(), - }, nil - } - - var sp *spath.Path - if !pe.Path.HeaderV2 { - sp = spath.New(pe.Path.FwdPath) - if err := sp.InitOffsets(); err != nil { - return Path{}, serrors.WrapStr("path error", err) - } - } else { - sp = spath.NewV2(pe.Path.FwdPath, false) - } - - underlayAddr := pe.HostInfo.Underlay() - p := Path{ - interfaces: make([]pathInterface, 0, len(pe.Path.Interfaces)), - underlay: underlayAddr, - spath: sp, - mtu: pe.Path.Mtu, - expiry: pe.Path.Expiry(), - } - for _, intf := range pe.Path.Interfaces { - p.interfaces = append(p.interfaces, pathInterface{ia: intf.IA(), id: intf.ID()}) - } - return p, nil -} - func (p Path) UnderlayNextHop() *net.UDPAddr { if p.underlay == nil { return nil @@ -196,7 +148,7 @@ func (p Path) Destination() addr.IA { if len(p.interfaces) == 0 { return p.dst } - return p.interfaces[len(p.interfaces)-1].IA() + return p.interfaces[len(p.interfaces)-1].IA } func (p Path) Metadata() snet.PathMetadata { @@ -233,21 +185,13 @@ func (p Path) fmtInterfaces() []string { return hops } intf := p.interfaces[0] - hops = append(hops, fmt.Sprintf("%s %d", intf.IA(), intf.ID())) + hops = append(hops, fmt.Sprintf("%s %d", intf.IA, intf.ID)) for i := 1; i < len(p.interfaces)-1; i += 2 { inIntf := p.interfaces[i] outIntf := p.interfaces[i+1] - hops = append(hops, fmt.Sprintf("%d %s %d", inIntf.ID(), inIntf.IA(), outIntf.ID())) + hops = append(hops, fmt.Sprintf("%d %s %d", inIntf.ID, inIntf.IA, outIntf.ID)) } intf = p.interfaces[len(p.interfaces)-1] - hops = append(hops, fmt.Sprintf("%d %s", intf.ID(), intf.IA())) + hops = append(hops, fmt.Sprintf("%d %s", intf.ID, intf.IA)) return hops } - -type pathInterface struct { - id common.IFIDType - ia addr.IA -} - -func (i pathInterface) ID() common.IFIDType { return i.id } -func (i pathInterface) IA() addr.IA { return i.ia } diff --git a/go/lib/sciond/fake/fake.go b/go/lib/sciond/fake/fake.go index fe18f58f14..2fac0ffb92 100644 --- a/go/lib/sciond/fake/fake.go +++ b/go/lib/sciond/fake/fake.go @@ -100,14 +100,14 @@ func DummyPath() *spath.Path { func (p Path) Interfaces() []snet.PathInterface { ifaces := make([]snet.PathInterface, len(p.JSONInterfaces)) - for i := range p.JSONInterfaces { - ifaces[i] = p.JSONInterfaces[i] + for i, jsonIface := range p.JSONInterfaces { + ifaces[i] = snet.PathInterface{IA: jsonIface.IA, ID: jsonIface.ID} } return ifaces } func (p Path) Destination() addr.IA { - return p.JSONInterfaces[len(p.JSONInterfaces)-1].JSONIA + return p.JSONInterfaces[len(p.JSONInterfaces)-1].IA } func (p Path) Metadata() snet.PathMetadata { @@ -133,16 +133,8 @@ func (p Path) String() string { } type PathInterface struct { - JSONIA addr.IA `json:"ia"` - JSONID common.IFIDType `json:"id"` -} - -func (i PathInterface) ID() common.IFIDType { - return i.JSONID -} - -func (i PathInterface) IA() addr.IA { - return i.JSONIA + IA addr.IA `json:"ia"` + ID common.IFIDType `json:"id"` } type pathMetadata struct { diff --git a/go/lib/sciond/fake/fake_test.go b/go/lib/sciond/fake/fake_test.go index 6f1f4fb27a..e3e8ae23ae 100644 --- a/go/lib/sciond/fake/fake_test.go +++ b/go/lib/sciond/fake/fake_test.go @@ -32,8 +32,8 @@ func TestJSONConversion(t *testing.T) { Paths: []*fake.Path{ { JSONInterfaces: []fake.PathInterface{ - {JSONIA: xtest.MustParseIA("1-ff00:0:ffff"), JSONID: 1}, - {JSONIA: xtest.MustParseIA("1-ff00:0:1"), JSONID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:ffff"), ID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:1"), ID: 1}, }, JSONNextHop: &fake.UDPAddr{ IP: net.IP{192, 168, 0, 1}, @@ -73,8 +73,8 @@ func TestPaths(t *testing.T) { Paths: []*fake.Path{ { JSONInterfaces: []fake.PathInterface{ - {JSONIA: xtest.MustParseIA("1-ff00:0:ffff"), JSONID: 1}, - {JSONIA: xtest.MustParseIA("1-ff00:0:1"), JSONID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:ffff"), ID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:1"), ID: 1}, }, JSONNextHop: &fake.UDPAddr{ IP: net.IP{10, 0, 0, 1}, @@ -89,8 +89,8 @@ func TestPaths(t *testing.T) { Paths: []*fake.Path{ { JSONInterfaces: []fake.PathInterface{ - {JSONIA: xtest.MustParseIA("1-ff00:0:ffff"), JSONID: 1}, - {JSONIA: xtest.MustParseIA("2-ff00:0:2"), JSONID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:ffff"), ID: 1}, + {IA: xtest.MustParseIA("2-ff00:0:2"), ID: 1}, }, JSONNextHop: &fake.UDPAddr{ IP: net.IP{10, 0, 0, 2}, @@ -118,7 +118,7 @@ func TestPaths(t *testing.T) { assert.Equal(t, &net.UDPAddr{IP: net.IP{10, 0, 0, 1}, Port: 80}, paths[0].UnderlayNextHop()) assert.Equal(t, fake.DummyPath(), paths[0].Path()) assert.Equal(t, 2, len(paths[0].Interfaces())) - assert.Equal(t, paths[0].Destination(), paths[0].Interfaces()[1].IA()) + assert.Equal(t, paths[0].Destination(), paths[0].Interfaces()[1].IA) assert.Equal(t, xtest.MustParseIA("1-ff00:0:1"), paths[0].Destination()) assert.Equal(t, uint16(1472), paths[0].Metadata().MTU()) // path valid for more than an hour, but less than three @@ -141,7 +141,7 @@ func TestPaths(t *testing.T) { assert.Equal(t, &net.UDPAddr{IP: net.IP{10, 0, 0, 2}, Port: 80}, paths[0].UnderlayNextHop()) assert.Equal(t, fake.DummyPath(), paths[0].Path()) assert.Equal(t, 2, len(paths[0].Interfaces())) - assert.Equal(t, paths[0].Destination(), paths[0].Interfaces()[1].IA()) + assert.Equal(t, paths[0].Destination(), paths[0].Interfaces()[1].IA) assert.Equal(t, xtest.MustParseIA("2-ff00:0:2"), paths[0].Destination()) assert.Equal(t, uint16(1472), paths[0].Metadata().MTU()) // path valid for more than two hours, but less than four @@ -152,8 +152,8 @@ func TestPaths(t *testing.T) { func TestPathCopy(t *testing.T) { path := fake.Path{ JSONInterfaces: []fake.PathInterface{ - {JSONIA: xtest.MustParseIA("1-ff00:0:ffff"), JSONID: 1}, - {JSONIA: xtest.MustParseIA("1-ff00:0:1"), JSONID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:ffff"), ID: 1}, + {IA: xtest.MustParseIA("1-ff00:0:1"), ID: 1}, }, JSONNextHop: &fake.UDPAddr{ IP: net.IP{192, 168, 0, 1}, diff --git a/go/lib/sciond/grpc.go b/go/lib/sciond/grpc.go index 7d60296729..88c9f6eef6 100644 --- a/go/lib/sciond/grpc.go +++ b/go/lib/sciond/grpc.go @@ -209,11 +209,11 @@ func convertPath(path *sdpb.Path, dst addr.IA) (Path, error) { if err != nil { return Path{}, serrors.WrapStr("resolving underlay", err) } - interfaces := make([]pathInterface, 0, len(path.Interfaces)) + interfaces := make([]snet.PathInterface, 0, len(path.Interfaces)) for _, pi := range path.Interfaces { - interfaces = append(interfaces, pathInterface{ - id: common.IFIDType(pi.Id), - ia: addr.IAInt(pi.IsdAs).IA(), + interfaces = append(interfaces, snet.PathInterface{ + ID: common.IFIDType(pi.Id), + IA: addr.IAInt(pi.IsdAs).IA(), }) } return Path{ diff --git a/go/lib/sciond/types.go b/go/lib/sciond/types.go index 977ba2d592..6aad5a630c 100644 --- a/go/lib/sciond/types.go +++ b/go/lib/sciond/types.go @@ -23,6 +23,7 @@ import ( "github.com/scionproto/scion/go/lib/addr" "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/hostinfo" + "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/util" ) @@ -107,7 +108,7 @@ func (e *PathReplyEntry) String() string { type FwdPathMeta struct { FwdPath []byte Mtu uint16 - Interfaces []PathInterface + Interfaces []snet.PathInterface ExpTime uint32 HeaderV2 bool @@ -118,7 +119,7 @@ func (fpm *FwdPathMeta) SrcIA() addr.IA { if len(ifaces) == 0 { return addr.IA{} } - return ifaces[0].IA() + return ifaces[0].IA } func (fpm *FwdPathMeta) DstIA() addr.IA { @@ -126,7 +127,7 @@ func (fpm *FwdPathMeta) DstIA() addr.IA { if len(ifaces) == 0 { return addr.IA{} } - return ifaces[len(ifaces)-1].IA() + return ifaces[len(ifaces)-1].IA } func (fpm *FwdPathMeta) Expiry() time.Time { @@ -140,7 +141,7 @@ func (fpm *FwdPathMeta) Copy() *FwdPathMeta { res := &FwdPathMeta{Mtu: fpm.Mtu, ExpTime: fpm.ExpTime, HeaderV2: fpm.HeaderV2} res.FwdPath = common.CloneByteSlice(fpm.FwdPath) if fpm.Interfaces != nil { - res.Interfaces = make([]PathInterface, len(fpm.Interfaces)) + res.Interfaces = make([]snet.PathInterface, len(fpm.Interfaces)) copy(res.Interfaces, fpm.Interfaces) } return res @@ -157,41 +158,17 @@ func (fpm *FwdPathMeta) fmtIfaces() []string { return hops } intf := fpm.Interfaces[0] - hops = append(hops, fmt.Sprintf("%s %d", intf.IA(), intf.IfID)) + hops = append(hops, fmt.Sprintf("%s %d", intf.IA, intf.ID)) for i := 1; i < len(fpm.Interfaces)-1; i += 2 { inIntf := fpm.Interfaces[i] outIntf := fpm.Interfaces[i+1] - hops = append(hops, fmt.Sprintf("%d %s %d", inIntf.IfID, inIntf.IA(), outIntf.IfID)) + hops = append(hops, fmt.Sprintf("%d %s %d", inIntf.ID, inIntf.IA, outIntf.ID)) } intf = fpm.Interfaces[len(fpm.Interfaces)-1] - hops = append(hops, fmt.Sprintf("%d %s", intf.IfID, intf.IA())) + hops = append(hops, fmt.Sprintf("%d %s", intf.ID, intf.IA)) return hops } -type PathInterface struct { - RawIsdas addr.IAInt - IfID common.IFIDType -} - -func (iface PathInterface) IA() addr.IA { - return iface.RawIsdas.IA() -} - -func (iface PathInterface) ID() common.IFIDType { - return iface.IfID -} - -func (iface *PathInterface) Equal(other *PathInterface) bool { - if iface == nil || other == nil { - return iface == other - } - return iface.RawIsdas == other.RawIsdas && iface.IfID == other.IfID -} - -func (iface PathInterface) String() string { - return fmt.Sprintf("%s#%d", iface.IA(), iface.IfID) -} - type RevReply struct { Result RevResult } diff --git a/go/lib/snet/mock_snet/snet.go b/go/lib/snet/mock_snet/snet.go index ef2afadad6..ee2230f20a 100644 --- a/go/lib/snet/mock_snet/snet.go +++ b/go/lib/snet/mock_snet/snet.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/scionproto/scion/go/lib/snet (interfaces: PacketDispatcherService,Network,PacketConn,Path,PathInterface,PathMetadata,PathQuerier,Router,RevocationHandler) +// Source: github.com/scionproto/scion/go/lib/snet (interfaces: PacketDispatcherService,Network,PacketConn,Path,PathMetadata,PathQuerier,Router,RevocationHandler) // Package mock_snet is a generated GoMock package. package mock_snet @@ -322,57 +322,6 @@ func (mr *MockPathMockRecorder) UnderlayNextHop() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UnderlayNextHop", reflect.TypeOf((*MockPath)(nil).UnderlayNextHop)) } -// MockPathInterface is a mock of PathInterface interface -type MockPathInterface struct { - ctrl *gomock.Controller - recorder *MockPathInterfaceMockRecorder -} - -// MockPathInterfaceMockRecorder is the mock recorder for MockPathInterface -type MockPathInterfaceMockRecorder struct { - mock *MockPathInterface -} - -// NewMockPathInterface creates a new mock instance -func NewMockPathInterface(ctrl *gomock.Controller) *MockPathInterface { - mock := &MockPathInterface{ctrl: ctrl} - mock.recorder = &MockPathInterfaceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use -func (m *MockPathInterface) EXPECT() *MockPathInterfaceMockRecorder { - return m.recorder -} - -// IA mocks base method -func (m *MockPathInterface) IA() addr.IA { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IA") - ret0, _ := ret[0].(addr.IA) - return ret0 -} - -// IA indicates an expected call of IA -func (mr *MockPathInterfaceMockRecorder) IA() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IA", reflect.TypeOf((*MockPathInterface)(nil).IA)) -} - -// ID mocks base method -func (m *MockPathInterface) ID() common.IFIDType { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ID") - ret0, _ := ret[0].(common.IFIDType) - return ret0 -} - -// ID indicates an expected call of ID -func (mr *MockPathInterfaceMockRecorder) ID() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ID", reflect.TypeOf((*MockPathInterface)(nil).ID)) -} - // MockPathMetadata is a mock of PathMetadata interface type MockPathMetadata struct { ctrl *gomock.Controller diff --git a/go/lib/snet/path.go b/go/lib/snet/path.go index aa5aae4d1f..71ae0bc434 100644 --- a/go/lib/snet/path.go +++ b/go/lib/snet/path.go @@ -55,14 +55,16 @@ type Path interface { Copy() Path } -// PathInterface is an interface of the path. This is currently an interface so -// that packages which can not depend on snet can still implement the snet.Path -// interface. -type PathInterface interface { +// PathInterface is an interface of the path. +type PathInterface struct { // ID is the ID of the interface. - ID() common.IFIDType + ID common.IFIDType // IA is the ISD AS identifier of the interface. - IA() addr.IA + IA addr.IA +} + +func (iface PathInterface) String() string { + return fmt.Sprintf("%s#%d", iface.IA, iface.ID) } // PathMetadata contains supplementary information about a path. @@ -94,8 +96,8 @@ func Fingerprint(path Fingerprinter) PathFingerprint { } h := sha256.New() for _, intf := range interfaces { - binary.Write(h, binary.BigEndian, intf.IA().IAInt()) - binary.Write(h, binary.BigEndian, intf.ID()) + binary.Write(h, binary.BigEndian, intf.IA.IAInt()) + binary.Write(h, binary.BigEndian, intf.ID) } return PathFingerprint(h.Sum(nil)) } diff --git a/go/pkg/app/path.go b/go/pkg/app/path.go index afc8499951..9decc56100 100644 --- a/go/pkg/app/path.go +++ b/go/pkg/app/path.go @@ -33,10 +33,10 @@ func SortPaths(paths []snet.Path) { return len(intfA) < len(intfB) } for i := range intfA { - if iaA, iaB := intfA[i].IA().IAInt(), intfA[i].IA().IAInt(); iaA != iaB { + if iaA, iaB := intfA[i].IA.IAInt(), intfA[i].IA.IAInt(); iaA != iaB { return iaA < iaB } - if idA, idB := intfA[i].ID(), intfB[i].ID(); idA != idB { + if idA, idB := intfA[i].ID, intfB[i].ID; idA != idB { return idA < idB } } @@ -105,22 +105,22 @@ func coloredHops(path snet.Path, opts colorOptions) []string { var hops []string intf := intfs[0] hops = append(hops, opts.values.Sprintf("%s %s", - opts.values.Sprint(intf.IA()), - opts.intf.Sprint(intf.ID()), + opts.values.Sprint(intf.IA), + opts.intf.Sprint(intf.ID), )) for i := 1; i < len(intfs)-1; i += 2 { inIntf := intfs[i] outIntf := intfs[i+1] hops = append(hops, opts.values.Sprintf("%s %s %s", - opts.intf.Sprint(inIntf.ID()), - opts.values.Sprint(inIntf.IA()), - opts.intf.Sprint(outIntf.ID()), + opts.intf.Sprint(inIntf.ID), + opts.values.Sprint(inIntf.IA), + opts.intf.Sprint(outIntf.ID), )) } intf = intfs[len(intfs)-1] hops = append(hops, opts.values.Sprintf("%s %s", - opts.intf.Sprint(intf.ID()), - opts.values.Sprint(intf.IA()), + opts.intf.Sprint(intf.ID), + opts.values.Sprint(intf.IA), )) return hops } diff --git a/go/pkg/sciond/fetcher/fetcher.go b/go/pkg/sciond/fetcher/fetcher.go index f0338c43ba..74672c10ca 100644 --- a/go/pkg/sciond/fetcher/fetcher.go +++ b/go/pkg/sciond/fetcher/fetcher.go @@ -34,6 +34,7 @@ import ( "github.com/scionproto/scion/go/lib/revcache" "github.com/scionproto/scion/go/lib/sciond" "github.com/scionproto/scion/go/lib/serrors" + "github.com/scionproto/scion/go/lib/snet" "github.com/scionproto/scion/go/lib/spath" "github.com/scionproto/scion/go/lib/topology" "github.com/scionproto/scion/go/lib/util" @@ -162,7 +163,7 @@ func (f *fetcher) translate(path *combinator.Path) (sciond.PathReplyEntry, error Path: &sciond.FwdPathMeta{ FwdPath: []byte{}, Mtu: f.pather.TopoProvider.Get().MTU(), - Interfaces: []sciond.PathInterface{}, + Interfaces: []snet.PathInterface{}, ExpTime: util.TimeToSecs(time.Now().Add(spath.MaxTTL * time.Second)), HeaderV2: path.HeaderV2, }, @@ -175,10 +176,10 @@ func (f *fetcher) translate(path *combinator.Path) (sciond.PathReplyEntry, error // In-memory write should never fail panic(err) } - nextHop, ok := f.pather.TopoProvider.Get().UnderlayNextHop(path.Interfaces[0].IfID) + nextHop, ok := f.pather.TopoProvider.Get().UnderlayNextHop(path.Interfaces[0].ID) if !ok { return sciond.PathReplyEntry{}, serrors.New("unable to find first-hop BR for path", - "ifid", path.Interfaces[0].IfID) + "ifid", path.Interfaces[0].ID) } entry := sciond.PathReplyEntry{ Path: &sciond.FwdPathMeta{ diff --git a/go/pkg/sciond/fetcher/filter.go b/go/pkg/sciond/fetcher/filter.go index ddac1f9acc..f4c6eac1a5 100644 --- a/go/pkg/sciond/fetcher/filter.go +++ b/go/pkg/sciond/fetcher/filter.go @@ -62,7 +62,7 @@ func newPathWrap(p *combinator.Path) pathWrap { keyParts := make([]string, 0, len(p.Interfaces)) for _, intf := range p.Interfaces { intfs = append(intfs, intf) - keyParts = append(keyParts, fmt.Sprintf("%s#%d", intf.IA(), intf.ID())) + keyParts = append(keyParts, fmt.Sprintf("%s#%d", intf.IA, intf.ID)) } return pathWrap{ key: snet.PathFingerprint(strings.Join(keyParts, " ")), diff --git a/go/pkg/sciond/internal/servers/grpc.go b/go/pkg/sciond/internal/servers/grpc.go index 3a022d2e0b..594ad51d18 100644 --- a/go/pkg/sciond/internal/servers/grpc.go +++ b/go/pkg/sciond/internal/servers/grpc.go @@ -98,8 +98,8 @@ func (s DaemonServer) paths(ctx context.Context, var interfaces []*sdpb.PathInterface for _, intf := range p.Path.Interfaces { interfaces = append(interfaces, &sdpb.PathInterface{ - Id: uint64(intf.IfID), - IsdAs: uint64(intf.RawIsdas), + Id: uint64(intf.ID), + IsdAs: uint64(intf.IA.IAInt()), }) } reply.Paths = append(reply.Paths, &sdpb.Path{ diff --git a/go/pkg/showpaths/showpaths.go b/go/pkg/showpaths/showpaths.go index 8671411a93..91be907ed3 100644 --- a/go/pkg/showpaths/showpaths.go +++ b/go/pkg/showpaths/showpaths.go @@ -218,7 +218,7 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) { Hops: []Hop{}, } for _, hop := range path.Interfaces() { - rpath.Hops = append(rpath.Hops, Hop{IA: hop.IA(), IfID: hop.ID()}) + rpath.Hops = append(rpath.Hops, Hop{IA: hop.IA, IfID: hop.ID}) } if status, ok := statuses[pathprobe.PathKey(path)]; ok { rpath.Status = strings.ToLower(string(status.Status)) diff --git a/go/pkg/traceroute/traceroute_legacy.go b/go/pkg/traceroute/traceroute_legacy.go index 0a5e956c70..7528d3b1e7 100644 --- a/go/pkg/traceroute/traceroute_legacy.go +++ b/go/pkg/traceroute/traceroute_legacy.go @@ -241,7 +241,7 @@ func validate(pkt *spkt.ScnPkt, path snet.Path, id uint64) (*scmp.Hdr, return scmpHdr, info, nil } for _, e := range path.Interfaces() { - if info.IA == e.IA() && info.IfID == e.ID() { + if info.IA == e.IA && info.IfID == e.ID { return scmpHdr, info, nil } } diff --git a/tools/gomocks b/tools/gomocks index 164bcb6ff4..4a040e96c0 100755 --- a/tools/gomocks +++ b/tools/gomocks @@ -30,7 +30,7 @@ MOCK_TARGETS = [ ("go/lib/revcache", "RevCache"), ("go/lib/sciond", "Connector"), ("go/lib/snet", - "PacketDispatcherService,Network,PacketConn,Path,PathInterface," + + "PacketDispatcherService,Network,PacketConn,Path," + "PathMetadata,PathQuerier,Router,RevocationHandler"), ("go/lib/sock/reliable", "Dispatcher"), ("go/lib/sock/reliable/reconnect", "IOOperation,Reconnecter"),