From eea6875095de3c0fef8a0980456f43d9dae28a1b Mon Sep 17 00:00:00 2001 From: Jean-Christophe Hugly Date: Wed, 17 Jul 2024 11:13:19 +0200 Subject: [PATCH] IfID Spelling, take two. --- control/beacon/beacon.go | 12 +- control/beacon/beacondbtest/beacondbtest.go | 16 +- control/beacon/store_test.go | 6 +- control/beaconing/export_test.go | 4 +- control/beaconing/extender.go | 22 +-- control/beaconing/grpc/beacon_sender.go | 4 +- control/beaconing/grpc/creation_server.go | 8 +- control/beaconing/handler.go | 10 +- control/beaconing/handler_test.go | 14 +- control/beaconing/originator.go | 8 +- control/beaconing/originator_test.go | 8 +- control/beaconing/propagator.go | 22 +-- control/beaconing/propagator_test.go | 18 +-- control/beaconing/staticinfo_config.go | 136 ++++++++-------- control/beaconing/staticinfo_config_test.go | 134 ++++++++-------- control/beaconing/util.go | 20 +-- control/beaconing/writer.go | 14 +- control/beaconing/writer_test.go | 6 +- control/cmd/control/main.go | 2 +- control/ifstate/ifstate.go | 16 +- control/ifstate/ifstate_test.go | 2 +- control/mgmtapi/api.go | 4 +- control/mgmtapi/api_test.go | 4 +- control/revhandler.go | 2 +- daemon/internal/servers/grpc.go | 8 +- doc/dev/style/go.rst | 10 +- gateway/pathhealth/revocations.go | 4 +- gateway/pathhealth/revocations_test.go | 8 +- pkg/daemon/grpc.go | 8 +- pkg/experimental/hiddenpath/beaconwriter.go | 12 +- .../hiddenpath/beaconwriter_test.go | 8 +- .../hiddenpath/registrationpolicy.go | 20 +-- pkg/private/common/defs.go | 20 +-- pkg/private/common/defs_test.go | 16 +- pkg/private/ctrl/path_mgmt/rev_info.go | 6 +- pkg/private/xtest/graph/graph.go | 148 +++++++++--------- pkg/private/xtest/matchers/matchers.go | 2 +- .../extensions/staticinfo/staticinfo.go | 78 ++++----- .../extensions/staticinfo/staticinfo_test.go | 10 +- pkg/slayers/scmp_msg.go | 6 +- pkg/slayers/scmp_msg_test.go | 4 +- pkg/slayers/scmp_test.go | 2 +- pkg/slayers/slayers_test.go | 2 +- pkg/snet/addrutil/addrutil.go | 6 +- pkg/snet/packet.go | 4 +- pkg/snet/packet_conn.go | 18 +-- pkg/snet/path.go | 2 +- pkg/snet/scmp.go | 4 +- private/path/combinator/combinator_test.go | 20 +-- private/path/combinator/graph.go | 16 +- .../path/combinator/staticinfo_accumulator.go | 34 ++-- .../combinator/staticinfo_accumulator_test.go | 50 +++--- private/path/pathpol/acl_test.go | 8 +- private/path/pathpol/hop_pred.go | 44 +++--- private/path/pathpol/hop_pred_test.go | 30 ++-- private/path/pathpol/policy_test.go | 10 +- private/path/pathpol/sequence.go | 2 +- private/pathdb/query/query.go | 2 +- private/revcache/memrevcache/memrevcache.go | 2 +- .../revcache/memrevcache/memrevcache_test.go | 2 +- private/revcache/revcache.go | 12 +- private/revcache/revcachetest/revcachetest.go | 66 ++++---- private/revcache/util.go | 4 +- private/revcache/util_test.go | 6 +- private/segment/segfetcher/pather.go | 2 +- private/segment/segfetcher/resolver_test.go | 6 +- private/storage/beacon/sqlite/db.go | 16 +- private/storage/path/dbtest/dbtest.go | 16 +- private/storage/path/sqlite/sqlite.go | 2 +- private/topology/interface.go | 16 +- private/topology/json/json.go | 8 +- private/topology/json/json_test.go | 4 +- private/topology/mock_topology/mock.go | 6 +- private/topology/reload.go | 6 +- private/topology/topology.go | 36 ++--- private/topology/topology_test.go | 10 +- router/connector.go | 10 +- router/control/conf.go | 20 +-- router/control/internal/metrics/metrics.go | 6 +- router/dataplane.go | 122 +++++++-------- router/dataplane_test.go | 16 +- scion/cmd/scion/common.go | 2 +- scion/cmd/scion/showpaths.go | 4 +- scion/cmd/scion/traceroute.go | 2 +- scion/showpaths/showpaths.go | 4 +- tools/end2end/main.go | 2 +- 86 files changed, 762 insertions(+), 760 deletions(-) diff --git a/control/beacon/beacon.go b/control/beacon/beacon.go index ccaecad1a9..6378247870 100644 --- a/control/beacon/beacon.go +++ b/control/beacon/beacon.go @@ -25,8 +25,8 @@ import ( type Beacon struct { // Segment is the path segment. Segment *seg.PathSegment - // InIfId is the interface the beacon is received on. - InIfId uint16 + // InIfID is the interface the beacon is received on. + InIfID uint16 } // Diversity returns the link diversity between this and the other beacon. The @@ -39,11 +39,11 @@ func (b Beacon) Diversity(other Beacon) int { } var diff int for _, asEntry := range b.Segment.ASEntries { - ia, ifId := link(asEntry) + ia, ifID := link(asEntry) var found bool for _, otherEntry := range other.Segment.ASEntries { - oia, oifId := link(otherEntry) - if ia.Equal(oia) && ifId == oifId { + oia, oifID := link(otherEntry) + if ia.Equal(oia) && ifID == oifID { found = true break } @@ -56,7 +56,7 @@ func (b Beacon) Diversity(other Beacon) int { } func (b Beacon) String() string { - return fmt.Sprintf("Ingress: %d Segment: [ %s ]", b.InIfId, b.Segment) + return fmt.Sprintf("Ingress: %d Segment: [ %s ]", b.InIfID, b.Segment) } func link(entry seg.ASEntry) (addr.IA, uint16) { diff --git a/control/beacon/beacondbtest/beacondbtest.go b/control/beacon/beacondbtest/beacondbtest.go index 5dbef04d4b..4b3af82017 100644 --- a/control/beacon/beacondbtest/beacondbtest.go +++ b/control/beacon/beacondbtest/beacondbtest.go @@ -318,13 +318,13 @@ func CheckResults(t *testing.T, results []beacon.Beacon, expectedBeacons []beaco } assert.Equal(t, expected, actual) } - assert.Equal(t, expected.InIfId, res.InIfId, "InIfId %d should match", i) + assert.Equal(t, expected.InIfID, res.InIfID, "InIfID %d should match", i) } } func InsertBeacon(t *testing.T, db beacon.DB, ases []IfInfo, - inIfId uint16, infoTS uint32, allowed beacon.Usage) beacon.Beacon { - b, _ := AllocBeacon(t, ases, inIfId, infoTS) + inIfID uint16, infoTS uint32, allowed beacon.Usage) beacon.Beacon { + b, _ := AllocBeacon(t, ases, inIfID, infoTS) ctx, cancelF := context.WithTimeout(context.Background(), timeout) defer cancelF() _, err := db.InsertBeacon(ctx, b, allowed) @@ -334,21 +334,21 @@ func InsertBeacon(t *testing.T, db beacon.DB, ases []IfInfo, type PeerEntry struct { IA addr.IA - Ingress common.IfIdType + Ingress common.IfIDType } type IfInfo struct { IA addr.IA Next addr.IA - Ingress common.IfIdType - Egress common.IfIdType + Ingress common.IfIDType + Egress common.IfIDType Peers []PeerEntry } func AllocBeacon( t *testing.T, ases []IfInfo, - inIfId uint16, + inIfID uint16, infoTS uint32, ) (beacon.Beacon, []byte) { @@ -401,5 +401,5 @@ func AllocBeacon( err := pseg.AddASEntry(context.Background(), entry, signer) require.NoError(t, err) } - return beacon.Beacon{Segment: pseg, InIfId: inIfId}, pseg.ID() + return beacon.Beacon{Segment: pseg, InIfID: inIfID}, pseg.ID() } diff --git a/control/beacon/store_test.go b/control/beacon/store_test.go index ccf856991c..3dc5d53ee3 100644 --- a/control/beacon/store_test.go +++ b/control/beacon/store_test.go @@ -269,13 +269,13 @@ func testBeacon(g *graph.Graph, desc ...uint16) beacon.Beacon { pseg := testSegment(g, desc) asEntry := pseg.ASEntries[pseg.MaxIdx()] return beacon.Beacon{ - InIfId: asEntry.HopEntry.HopField.ConsIngress, + InIfID: asEntry.HopEntry.HopField.ConsIngress, Segment: pseg, } } -func testSegment(g *graph.Graph, ifIds []uint16) *seg.PathSegment { - pseg := g.Beacon(ifIds) +func testSegment(g *graph.Graph, ifIDs []uint16) *seg.PathSegment { + pseg := g.Beacon(ifIDs) pseg.ASEntries = pseg.ASEntries[:len(pseg.ASEntries)-1] return pseg } diff --git a/control/beaconing/export_test.go b/control/beaconing/export_test.go index 7485df6bb1..76db29854c 100644 --- a/control/beaconing/export_test.go +++ b/control/beaconing/export_test.go @@ -20,7 +20,7 @@ import ( "github.com/scionproto/scion/private/topology" ) -func (cfg StaticInfoCfg) TestGenerate(ifType map[common.IfIdType]topology.LinkType, - ingress, egress common.IfIdType) *staticinfo.Extension { +func (cfg StaticInfoCfg) TestGenerate(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) *staticinfo.Extension { return cfg.generate(ifType, ingress, egress) } diff --git a/control/beaconing/extender.go b/control/beaconing/extender.go index 30bd729ba5..34374f2d10 100644 --- a/control/beaconing/extender.go +++ b/control/beaconing/extender.go @@ -252,7 +252,7 @@ func (s *DefaultExtender) createHopEntry( func (s *DefaultExtender) createPeerEntry(ingress, egress uint16, expTime uint8, ts time.Time, beta uint16) (seg.PeerEntry, []byte, error) { - remoteInIA, remoteInIfId, remoteInMTU, err := s.remoteInfo(ingress) + remoteInIA, remoteInIfID, remoteInMTU, err := s.remoteInfo(ingress) if err != nil { return seg.PeerEntry{}, nil, serrors.WrapStr("checking remote ingress interface", err, "ingress_interface", ingress) @@ -261,7 +261,7 @@ func (s *DefaultExtender) createPeerEntry(ingress, egress uint16, expTime uint8, return seg.PeerEntry{ PeerMTU: int(remoteInMTU), Peer: remoteInIA, - PeerInterface: remoteInIfId, + PeerInterface: remoteInIfID, HopField: seg.HopField{ ConsIngress: hopF.ConsIngress, ConsEgress: hopF.ConsEgress, @@ -271,11 +271,11 @@ func (s *DefaultExtender) createPeerEntry(ingress, egress uint16, expTime uint8, }, epicMac, nil } -func (s *DefaultExtender) remoteIA(ifId uint16) (addr.IA, error) { - if ifId == 0 { +func (s *DefaultExtender) remoteIA(ifID uint16) (addr.IA, error) { + if ifID == 0 { return 0, nil } - intf := s.Intfs.Get(ifId) + intf := s.Intfs.Get(ifID) if intf == nil { return 0, serrors.New("interface not found") } @@ -286,11 +286,11 @@ func (s *DefaultExtender) remoteIA(ifId uint16) (addr.IA, error) { return topoInfo.IA, nil } -func (s *DefaultExtender) remoteMTU(ifId uint16) (uint16, error) { - if ifId == 0 { +func (s *DefaultExtender) remoteMTU(ifID uint16) (uint16, error) { + if ifID == 0 { return 0, nil } - intf := s.Intfs.Get(ifId) + intf := s.Intfs.Get(ifID) if intf == nil { return 0, serrors.New("interface not found") } @@ -298,13 +298,13 @@ func (s *DefaultExtender) remoteMTU(ifId uint16) (uint16, error) { return topoInfo.MTU, nil } -func (s *DefaultExtender) remoteInfo(ifId uint16) ( +func (s *DefaultExtender) remoteInfo(ifID uint16) ( addr.IA, uint16, uint16, error) { - if ifId == 0 { + if ifID == 0 { return 0, 0, 0, nil } - intf := s.Intfs.Get(ifId) + intf := s.Intfs.Get(ifID) if intf == nil { return 0, 0, 0, serrors.New("interface not found") } diff --git a/control/beaconing/grpc/beacon_sender.go b/control/beaconing/grpc/beacon_sender.go index df7fd85b5e..2f8cb96ed8 100644 --- a/control/beaconing/grpc/beacon_sender.go +++ b/control/beaconing/grpc/beacon_sender.go @@ -39,12 +39,12 @@ type BeaconSenderFactory struct { func (f *BeaconSenderFactory) NewSender( ctx context.Context, dstIA addr.IA, - egIfId uint16, + egIfID uint16, nextHop *net.UDPAddr, ) (beaconing.Sender, error) { addr := &onehop.Addr{ IA: dstIA, - Egress: egIfId, + Egress: egIfID, SVC: addr.SvcCS, NextHop: nextHop, } diff --git a/control/beaconing/grpc/creation_server.go b/control/beaconing/grpc/creation_server.go index 6336ff9e59..26c3440caa 100644 --- a/control/beaconing/grpc/creation_server.go +++ b/control/beaconing/grpc/creation_server.go @@ -56,7 +56,7 @@ func (s SegmentCreationServer) Beacon(ctx context.Context, logger.Debug("peer must be *snet.UDPAddr", "actual", fmt.Sprintf("%T", gPeer)) return nil, serrors.New("peer must be *snet.UDPAddr", "actual", fmt.Sprintf("%T", gPeer)) } - ingress, err := extractIngressIfId(peer.Path) + ingress, err := extractIngressIfID(peer.Path) if err != nil { logger.Debug("Failed to extract ingress interface", "peer", peer, "err", err) return nil, status.Error(codes.InvalidArgument, "failed to extract ingress interface") @@ -68,7 +68,7 @@ func (s SegmentCreationServer) Beacon(ctx context.Context, } b := beacon.Beacon{ Segment: ps, - InIfId: ingress, + InIfID: ingress, } if err := s.Handler.HandleBeacon(ctx, b, peer); err != nil { logger.Debug("Failed to handle beacon", "peer", peer, "err", err) @@ -79,8 +79,8 @@ func (s SegmentCreationServer) Beacon(ctx context.Context, } -// extractIngressIfId extracts the ingress interface ID from a path. -func extractIngressIfId(path snet.DataplanePath) (uint16, error) { +// extractIngressIfID extracts the ingress interface ID from a path. +func extractIngressIfID(path snet.DataplanePath) (uint16, error) { invertedPath, ok := path.(snet.RawReplyPath) if !ok { return 0, serrors.New("unexpected path", "type", common.TypeOf(path)) diff --git a/control/beaconing/handler.go b/control/beaconing/handler.go index 31d7974301..886ffee737 100644 --- a/control/beaconing/handler.go +++ b/control/beaconing/handler.go @@ -54,19 +54,19 @@ type Handler struct { // HandleBeacon handles a baeacon received from peer. func (h Handler) HandleBeacon(ctx context.Context, b beacon.Beacon, peer *snet.UDPAddr) error { span := opentracing.SpanFromContext(ctx) - labels := handlerLabels{Ingress: b.InIfId} + labels := handlerLabels{Ingress: b.InIfID} - intf := h.Interfaces.Get(b.InIfId) + intf := h.Interfaces.Get(b.InIfID) if intf == nil { err := serrors.New("received beacon on non-existent interface", - "ingress_interface", b.InIfId) + "ingress_interface", b.InIfID) h.updateMetric(span, labels.WithResult(prom.ErrNotClassified), err) return err } upstream := intf.TopoInfo().IA if span != nil { - span.SetTag("ingress_interface", b.InIfId) + span.SetTag("ingress_interface", b.InIfID) span.SetTag("upstream", upstream) } labels.Neighbor = upstream @@ -106,7 +106,7 @@ func (h Handler) validateASEntry(b beacon.Beacon, intf *ifstate.Interface) error topoInfo := intf.TopoInfo() if topoInfo.LinkType != topology.Parent && topoInfo.LinkType != topology.Core { return serrors.New("beacon received on invalid link", - "ingress_interface", b.InIfId, "link_type", topoInfo.LinkType) + "ingress_interface", b.InIfID, "link_type", topoInfo.LinkType) } asEntry := b.Segment.ASEntries[b.Segment.MaxIdx()] if !asEntry.Local.Equal(topoInfo.IA) { diff --git a/control/beaconing/handler_test.go b/control/beaconing/handler_test.go index c0c8fce246..4e7a9af575 100644 --- a/control/beaconing/handler_test.go +++ b/control/beaconing/handler_test.go @@ -51,7 +51,7 @@ func TestHandlerHandleBeacon(t *testing.T) { g := graph.NewDefaultGraph(mctrl) return beacon.Beacon{ Segment: testSegment(g, []uint16{graph.If_220_X_120_B, graph.If_120_A_110_X}), - InIfId: localIF, + InIfID: localIF, } }() @@ -104,7 +104,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: 12, + InIfID: 12, } }, Peer: func() *snet.UDPAddr { @@ -130,7 +130,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: 42, + InIfID: 42, } }, Peer: func() *snet.UDPAddr { @@ -156,7 +156,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: localIF, + InIfID: localIF, } b.Segment.ASEntries[b.Segment.MaxIdx()].Local = addr.MustParseIA("1-ff00:0:111") return b @@ -185,7 +185,7 @@ func TestHandlerHandleBeacon(t *testing.T) { Segment: testSegment(g, []uint16{ graph.If_220_X_120_B, graph.If_120_A_110_X, }), - InIfId: localIF, + InIfID: localIF, } b.Segment.ASEntries[b.Segment.MaxIdx()].Next = addr.MustParseIA("1-ff00:0:111") return b @@ -276,8 +276,8 @@ func TestHandlerHandleBeacon(t *testing.T) { } } -func testSegment(g *graph.Graph, ifIds []uint16) *seg.PathSegment { - pseg := g.Beacon(ifIds) +func testSegment(g *graph.Graph, ifIDs []uint16) *seg.PathSegment { + pseg := g.Beacon(ifIDs) pseg.ASEntries = pseg.ASEntries[:len(pseg.ASEntries)-1] return pseg } diff --git a/control/beaconing/originator.go b/control/beaconing/originator.go index 55dfb18991..7219c6c1ba 100644 --- a/control/beaconing/originator.go +++ b/control/beaconing/originator.go @@ -140,11 +140,11 @@ func (o *Originator) needBeacon(active []*ifstate.Interface) []*ifstate.Interfac func (o *Originator) logSummary(logger log.Logger, s *summary) { if o.Tick.Passed() { - logger.Debug("Originated beacons", "egress_interfaces", s.IfIds()) + logger.Debug("Originated beacons", "egress_interfaces", s.IfIDs()) return } if s.count > 0 { - logger.Debug("Originated beacons on stale interfaces", "egress_interfaces", s.IfIds()) + logger.Debug("Originated beacons on stale interfaces", "egress_interfaces", s.IfIDs()) } } @@ -156,7 +156,7 @@ type beaconOriginator struct { summary *summary } -// originateBeacon originates a beacon on the given ifId. +// originateBeacon originates a beacon on the given ifID. func (o *beaconOriginator) originateBeacon(ctx context.Context) error { labels := originatorLabels{intf: o.intf} topoInfo := o.intf.TopoInfo() @@ -213,7 +213,7 @@ func (o *beaconOriginator) createBeacon(ctx context.Context) (*seg.PathSegment, func (o *beaconOriginator) onSuccess(intf *ifstate.Interface) { intf.Originate(o.Tick.Now()) - o.summary.AddIfId(o.intf.TopoInfo().ID) + o.summary.AddIfID(o.intf.TopoInfo().ID) o.summary.Inc() } diff --git a/control/beaconing/originator_test.go b/control/beaconing/originator_test.go index e3ad2bab24..e7d64673a5 100644 --- a/control/beaconing/originator_test.go +++ b/control/beaconing/originator_test.go @@ -61,7 +61,7 @@ func TestOriginatorRun(t *testing.T) { } return false } - t.Run("run originates ifId packets on all active interfaces", func(t *testing.T) { + t.Run("run originates ifID packets on all active interfaces", func(t *testing.T) { mctrl := gomock.NewController(t) defer mctrl.Finish() intfs := ifstate.NewInterfaces(interfaceInfos(topo), ifstate.Config{}) @@ -90,7 +90,7 @@ func TestOriginatorRun(t *testing.T) { senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(4).DoAndReturn( - func(_ context.Context, dstIA addr.IA, egIfId uint16, + func(_ context.Context, dstIA addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) @@ -103,9 +103,9 @@ func TestOriginatorRun(t *testing.T) { // Extract the hop field from the current AS entry to compare. hopF := b.ASEntries[b.MaxIdx()].HopEntry.HopField // Check the interface matches. - assert.Equal(t, hopF.ConsEgress, egIfId) + assert.Equal(t, hopF.ConsEgress, egIfID) // Check that the beacon is sent to the correct border router. - br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr) + br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfID].InternalAddr) assert.Equal(t, br, nextHop) return nil }, diff --git a/control/beaconing/propagator.go b/control/beaconing/propagator.go index f2d0e27190..588ea9acaf 100644 --- a/control/beaconing/propagator.go +++ b/control/beaconing/propagator.go @@ -169,7 +169,7 @@ func (p *Propagator) beaconsPerInterface( } var beacons []beacon.Beacon for _, b := range allBeacons { - if p.AllInterfaces.Get(b.InIfId) == nil { + if p.AllInterfaces.Get(b.InIfID) == nil { continue } beacons = append(beacons, b) @@ -185,7 +185,7 @@ func (p *Propagator) beaconsPerInterface( if err != nil { return nil, err } - toPropagate = append(toPropagate, beacon.Beacon{Segment: ps, InIfId: b.InIfId}) + toPropagate = append(toPropagate, beacon.Beacon{Segment: ps, InIfID: b.InIfID}) } r[intf] = toPropagate } @@ -223,7 +223,7 @@ func (p *Propagator) logCandidateBeacons( for _, b := range beacons { infos = append(infos, Beacon{ ID: b.Segment.GetLoggingID(), - Ingress: b.InIfId, + Ingress: b.InIfID, Segment: hopsDescription(b.Segment.ASEntries), }) } @@ -271,7 +271,7 @@ func (p *propagator) Propagate(ctx context.Context) error { ) if err != nil { for _, b := range p.beacons { - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, prom.ErrNetwork) + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.ErrNetwork) } return serrors.WrapStr("getting beacon sender", err, "waited_for", time.Since(senderStart).String(), @@ -295,14 +295,14 @@ func (p *propagator) Propagate(ctx context.Context) error { id = b.Segment.GetLoggingID() } - if err := p.extender.Extend(ctx, b.Segment, b.InIfId, egress, p.peers); err != nil { + if err := p.extender.Extend(ctx, b.Segment, b.InIfID, egress, p.peers); err != nil { logger.Error("Unable to extend beacon", "egress_interface", egress, - "beacon.ingress_interface", b.InIfId, + "beacon.ingress_interface", b.InIfID, "beacon.segment", hopsDescription(b.Segment.ASEntries), "err", err, ) - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, "err_create") + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, "err_create") return } @@ -310,24 +310,24 @@ func (p *propagator) Propagate(ctx context.Context) error { if err := sender.Send(ctx, b.Segment); err != nil { logger.Info("Unable to send beacon", "egress_interface", egress, - "beacon.ingress_interface", b.InIfId, + "beacon.ingress_interface", b.InIfID, "beacon.segment", hopsDescription(b.Segment.ASEntries), "waited_for", time.Since(sendStart).String(), "err", err, ) - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, prom.ErrNetwork) + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.ErrNetwork) return } setSuccess() - p.incMetric(b.Segment.FirstIA(), b.InIfId, egress, prom.Success) + p.incMetric(b.Segment.FirstIA(), b.InIfID, egress, prom.Success) p.intf.Propagate(p.now) if debugEnabled { logger.Debug("Propagated beacon", "egress_interface", egress, "candidate_id", id, - "beacon.ingress_interface", b.InIfId, + "beacon.ingress_interface", b.InIfID, "beacon.segment", hopsDescription(b.Segment.ASEntries), "waited_for", time.Since(sendStart).String(), "err", err, diff --git a/control/beaconing/propagator_test.go b/control/beaconing/propagator_test.go index 5634e20eea..83ddfc73f6 100644 --- a/control/beaconing/propagator_test.go +++ b/control/beaconing/propagator_test.go @@ -95,13 +95,13 @@ func TestPropagatorRunNonCore(t *testing.T) { senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Times(1).DoAndReturn( - func(_ context.Context, _ addr.IA, egIfId uint16, + func(_ context.Context, _ addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(3).DoAndReturn( func(_ context.Context, b *seg.PathSegment) error { - validateSend(t, b, egIfId, nextHop, pub, topo) + validateSend(t, b, egIfID, nextHop, pub, topo) return nil }, ) @@ -168,13 +168,13 @@ func TestPropagatorRunCore(t *testing.T) { senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), uint16(1121), gomock.Any()).DoAndReturn( - func(_ context.Context, _ addr.IA, egIfId uint16, + func(_ context.Context, _ addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(2).DoAndReturn( func(_ context.Context, b *seg.PathSegment) error { - validateSend(t, b, egIfId, nextHop, pub, topo) + validateSend(t, b, egIfID, nextHop, pub, topo) return nil }, ) @@ -184,13 +184,13 @@ func TestPropagatorRunCore(t *testing.T) { ) senderFactory.EXPECT().NewSender(gomock.Any(), gomock.Any(), uint16(1113), gomock.Any()).DoAndReturn( - func(_ context.Context, _ addr.IA, egIfId uint16, + func(_ context.Context, _ addr.IA, egIfID uint16, nextHop *net.UDPAddr) (beaconing.Sender, error) { sender := mock_beaconing.NewMockSender(mctrl) sender.EXPECT().Send(gomock.Any(), gomock.Any()).Times(1).DoAndReturn( func(_ context.Context, b *seg.PathSegment) error { - validateSend(t, b, egIfId, nextHop, pub, topo) + validateSend(t, b, egIfID, nextHop, pub, topo) return nil }, ) @@ -280,7 +280,7 @@ func TestPropagatorFastRecovery(t *testing.T) { func validateSend( t *testing.T, b *seg.PathSegment, - egIfId uint16, + egIfID uint16, nextHop *net.UDPAddr, pub crypto.PublicKey, topo topology.Topology, @@ -292,8 +292,8 @@ func validateSend( // Extract the hop field from the current AS entry to compare. hopF := b.ASEntries[b.MaxIdx()].HopEntry.HopField // Check the interface matches. - assert.Equal(t, hopF.ConsEgress, egIfId) + assert.Equal(t, hopF.ConsEgress, egIfID) // Check that the beacon is sent to the correct border router. - br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfId].InternalAddr) + br := net.UDPAddrFromAddrPort(interfaceInfos(topo)[egIfID].InternalAddr) assert.Equal(t, br, nextHop) } diff --git a/control/beaconing/staticinfo_config.go b/control/beaconing/staticinfo_config.go index 82d7bb720c..aa8c4f8a3d 100644 --- a/control/beaconing/staticinfo_config.go +++ b/control/beaconing/staticinfo_config.go @@ -30,12 +30,12 @@ import ( type InterfaceLatencies struct { Inter util.DurWrap `json:"Inter"` - Intra map[common.IfIdType]util.DurWrap `json:"Intra"` + Intra map[common.IfIDType]util.DurWrap `json:"Intra"` } type InterfaceBandwidths struct { Inter uint64 `json:"Inter"` - Intra map[common.IfIdType]uint64 `json:"Intra"` + Intra map[common.IfIDType]uint64 `json:"Intra"` } type InterfaceGeodata struct { @@ -45,7 +45,7 @@ type InterfaceGeodata struct { } type InterfaceHops struct { - Intra map[common.IfIdType]uint32 `json:"Intra"` + Intra map[common.IfIDType]uint32 `json:"Intra"` } type LinkType staticinfo.LinkType @@ -79,11 +79,11 @@ func (l *LinkType) UnmarshalText(text []byte) error { // StaticInfoCfg is used to parse data from config.json. type StaticInfoCfg struct { - Latency map[common.IfIdType]InterfaceLatencies `json:"Latency"` - Bandwidth map[common.IfIdType]InterfaceBandwidths `json:"Bandwidth"` - LinkType map[common.IfIdType]LinkType `json:"LinkType"` - Geo map[common.IfIdType]InterfaceGeodata `json:"Geo"` - Hops map[common.IfIdType]InterfaceHops `json:"Hops"` + Latency map[common.IfIDType]InterfaceLatencies `json:"Latency"` + Bandwidth map[common.IfIDType]InterfaceBandwidths `json:"Bandwidth"` + LinkType map[common.IfIDType]LinkType `json:"LinkType"` + Geo map[common.IfIDType]InterfaceGeodata `json:"Geo"` + Hops map[common.IfIDType]InterfaceHops `json:"Hops"` Note string `json:"Note"` } @@ -133,7 +133,7 @@ func (cfg *StaticInfoCfg) clean() { } // symmetrizeLatency makes the Intra latency values symmetric -func symmetrizeLatency(latency map[common.IfIdType]InterfaceLatencies) { +func symmetrizeLatency(latency map[common.IfIDType]InterfaceLatencies) { for i, sub := range latency { delete(sub.Intra, i) // Remove loopy entry for j, v := range sub.Intra { @@ -143,7 +143,7 @@ func symmetrizeLatency(latency map[common.IfIdType]InterfaceLatencies) { if latency[j].Intra == nil { latency[j] = InterfaceLatencies{ Inter: latency[j].Inter, - Intra: make(map[common.IfIdType]util.DurWrap), + Intra: make(map[common.IfIDType]util.DurWrap), } } vTransposed, ok := latency[j].Intra[i] @@ -156,7 +156,7 @@ func symmetrizeLatency(latency map[common.IfIdType]InterfaceLatencies) { } // symmetrizeBandwidth makes the Intra bandwidth values symmetric -func symmetrizeBandwidth(bandwidth map[common.IfIdType]InterfaceBandwidths) { +func symmetrizeBandwidth(bandwidth map[common.IfIDType]InterfaceBandwidths) { for i, sub := range bandwidth { delete(sub.Intra, i) // Remove loopy entry for j, v := range sub.Intra { @@ -166,7 +166,7 @@ func symmetrizeBandwidth(bandwidth map[common.IfIdType]InterfaceBandwidths) { if bandwidth[j].Intra == nil { bandwidth[j] = InterfaceBandwidths{ Inter: bandwidth[j].Inter, - Intra: make(map[common.IfIdType]uint64), + Intra: make(map[common.IfIDType]uint64), } } vTransposed, ok := bandwidth[j].Intra[i] @@ -179,13 +179,13 @@ func symmetrizeBandwidth(bandwidth map[common.IfIdType]InterfaceBandwidths) { } // symmetrizeHops makes the Intra hops values symmetric -func symmetrizeHops(hops map[common.IfIdType]InterfaceHops) { +func symmetrizeHops(hops map[common.IfIDType]InterfaceHops) { for i, sub := range hops { delete(sub.Intra, i) // Remove loopy entry for j, v := range sub.Intra { if _, ok := hops[j]; !ok { hops[j] = InterfaceHops{ - Intra: make(map[common.IfIdType]uint32), + Intra: make(map[common.IfIDType]uint32), } } vTransposed, ok := hops[j].Intra[i] @@ -203,11 +203,11 @@ func (cfg StaticInfoCfg) Generate(intfs *ifstate.Interfaces, ingress, egress uint16) *staticinfo.Extension { ifType := interfaceTypeTable(intfs) - return cfg.generate(ifType, common.IfIdType(ingress), common.IfIdType(egress)) + return cfg.generate(ifType, common.IfIDType(ingress), common.IfIDType(egress)) } -func (cfg StaticInfoCfg) generate(ifType map[common.IfIdType]topology.LinkType, - ingress, egress common.IfIdType) *staticinfo.Extension { +func (cfg StaticInfoCfg) generate(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) *staticinfo.Extension { return &staticinfo.Extension{ Latency: cfg.generateLatency(ifType, ingress, egress), @@ -221,22 +221,22 @@ func (cfg StaticInfoCfg) generate(ifType map[common.IfIdType]topology.LinkType, // generateLatency creates the LatencyInfo by extracting the relevant values from // the config. -func (cfg StaticInfoCfg) generateLatency(ifType map[common.IfIdType]topology.LinkType, - ingress, egress common.IfIdType) staticinfo.LatencyInfo { +func (cfg StaticInfoCfg) generateLatency(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.LatencyInfo { l := staticinfo.LatencyInfo{ - Intra: make(map[common.IfIdType]time.Duration), - Inter: make(map[common.IfIdType]time.Duration), + Intra: make(map[common.IfIDType]time.Duration), + Inter: make(map[common.IfIDType]time.Duration), } - for ifId, v := range cfg.Latency[egress].Intra { - if includeIntraInfo(ifType, ifId, ingress, egress) { - l.Intra[ifId] = v.Duration + for ifID, v := range cfg.Latency[egress].Intra { + if includeIntraInfo(ifType, ifID, ingress, egress) { + l.Intra[ifID] = v.Duration } } - for ifId, v := range cfg.Latency { - t := ifType[ifId] - if ifId == egress || t == topology.Peer { - l.Inter[ifId] = v.Inter.Duration + for ifID, v := range cfg.Latency { + t := ifType[ifID] + if ifID == egress || t == topology.Peer { + l.Inter[ifID] = v.Inter.Duration } } return l @@ -244,22 +244,22 @@ func (cfg StaticInfoCfg) generateLatency(ifType map[common.IfIdType]topology.Lin // generateBandwidth creates the BandwidthInfo by extracting the relevant values // from the config. -func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IfIdType]topology.LinkType, - ingress, egress common.IfIdType) staticinfo.BandwidthInfo { +func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.BandwidthInfo { bw := staticinfo.BandwidthInfo{ - Intra: make(map[common.IfIdType]uint64), - Inter: make(map[common.IfIdType]uint64), + Intra: make(map[common.IfIDType]uint64), + Inter: make(map[common.IfIDType]uint64), } - for ifId, v := range cfg.Bandwidth[egress].Intra { - if includeIntraInfo(ifType, ifId, ingress, egress) { - bw.Intra[ifId] = v + for ifID, v := range cfg.Bandwidth[egress].Intra { + if includeIntraInfo(ifType, ifID, ingress, egress) { + bw.Intra[ifID] = v } } - for ifId, v := range cfg.Bandwidth { - t := ifType[ifId] - if ifId == egress || t == topology.Peer { - bw.Inter[ifId] = v.Inter + for ifID, v := range cfg.Bandwidth { + t := ifType[ifID] + if ifID == egress || t == topology.Peer { + bw.Inter[ifID] = v.Inter } } return bw @@ -267,14 +267,14 @@ func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IfIdType]topology.L // generateLinkType creates the LinkTypeInfo by extracting the relevant values from // the config. -func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IfIdType]topology.LinkType, - egress common.IfIdType) staticinfo.LinkTypeInfo { +func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IfIDType]topology.LinkType, + egress common.IfIDType) staticinfo.LinkTypeInfo { lt := make(staticinfo.LinkTypeInfo) - for ifId, intfLT := range cfg.LinkType { - t := ifType[ifId] - if ifId == egress || t == topology.Peer { - lt[ifId] = staticinfo.LinkType(intfLT) + for ifID, intfLT := range cfg.LinkType { + t := ifType[ifID] + if ifID == egress || t == topology.Peer { + lt[ifID] = staticinfo.LinkType(intfLT) } } return lt @@ -282,13 +282,13 @@ func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IfIdType]topology.Li // generateInternalHops creates the InternalHopsInfo by extracting the relevant // values from the config. -func (cfg StaticInfoCfg) generateInternalHops(ifType map[common.IfIdType]topology.LinkType, - ingress, egress common.IfIdType) staticinfo.InternalHopsInfo { +func (cfg StaticInfoCfg) generateInternalHops(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.InternalHopsInfo { ihi := make(staticinfo.InternalHopsInfo) - for ifId, v := range cfg.Hops[egress].Intra { - if includeIntraInfo(ifType, ifId, ingress, egress) { - ihi[ifId] = v + for ifID, v := range cfg.Hops[egress].Intra { + if includeIntraInfo(ifType, ifID, ingress, egress) { + ihi[ifID] = v } } return ihi @@ -296,14 +296,14 @@ func (cfg StaticInfoCfg) generateInternalHops(ifType map[common.IfIdType]topolog // generateGeo creates the GeoInfo by extracting the relevant values from // the config. -func (cfg StaticInfoCfg) generateGeo(ifType map[common.IfIdType]topology.LinkType, - ingress, egress common.IfIdType) staticinfo.GeoInfo { +func (cfg StaticInfoCfg) generateGeo(ifType map[common.IfIDType]topology.LinkType, + ingress, egress common.IfIDType) staticinfo.GeoInfo { gi := staticinfo.GeoInfo{} - for ifId, loc := range cfg.Geo { - t := ifType[ifId] - if ifId == egress || ifId == ingress || t == topology.Peer { - gi[ifId] = staticinfo.GeoCoordinates{ + for ifID, loc := range cfg.Geo { + t := ifType[ifID] + if ifID == egress || ifID == ingress || t == topology.Peer { + gi[ifID] = staticinfo.GeoCoordinates{ Longitude: loc.Longitude, Latitude: loc.Latitude, Address: loc.Address, @@ -314,7 +314,7 @@ func (cfg StaticInfoCfg) generateGeo(ifType map[common.IfIdType]topology.LinkTyp } // includeIntraInfo determines if the intra-AS metadata info for the interface -// pair (ifId, egress) should be included in this beacon: +// pair (ifID, egress) should be included in this beacon: // Include information between the egress interface and // - ingress interface // - sibling child interfaces, @@ -322,34 +322,34 @@ func (cfg StaticInfoCfg) generateGeo(ifType map[common.IfIdType]topology.LinkTyp // - peer interfaces // For core/sibling child interfaces, we can skip some entries to avoid // redundancy: by consistently only including latency to interfaces with -// ifId > egress, we ensure that for each cross-over, the latency from +// ifID > egress, we ensure that for each cross-over, the latency from // this AS Entry's egress interface to the other AS Entry's egress // interface will be available in exactly one of the two AS Entries. // Note that the choice of < or > is arbitrary. At least each separate // AS needs to pick one consistently (or decide to just include the full // information all the time), otherwise information for cross-overs may // be missing. -func includeIntraInfo(ifType map[common.IfIdType]topology.LinkType, - ifId, ingress, egress common.IfIdType) bool { +func includeIntraInfo(ifType map[common.IfIDType]topology.LinkType, + ifID, ingress, egress common.IfIDType) bool { isCoreIngress := (ifType[ingress] == topology.Core || ingress == 0) isCoreEgress := (ifType[egress] == topology.Core || egress == 0) isCoreSeg := isCoreIngress && isCoreEgress if isCoreSeg { - return ifId == ingress + return ifID == ingress } - t := ifType[ifId] - return ifId == ingress || - t == topology.Child && ifId > egress || + t := ifType[ifID] + return ifID == ingress || + t == topology.Child && ifID > egress || t == topology.Core || t == topology.Peer } -func interfaceTypeTable(intfs *ifstate.Interfaces) map[common.IfIdType]topology.LinkType { +func interfaceTypeTable(intfs *ifstate.Interfaces) map[common.IfIDType]topology.LinkType { ifMap := intfs.All() - ifTypes := make(map[common.IfIdType]topology.LinkType, len(ifMap)) - for ifId, ifInfo := range ifMap { - ifTypes[common.IfIdType(ifId)] = ifInfo.TopoInfo().LinkType + ifTypes := make(map[common.IfIDType]topology.LinkType, len(ifMap)) + for ifID, ifInfo := range ifMap { + ifTypes[common.IfIDType(ifID)] = ifInfo.TopoInfo().LinkType } return ifTypes } diff --git a/control/beaconing/staticinfo_config_test.go b/control/beaconing/staticinfo_config_test.go index eb4240f91b..50dc57f9a1 100644 --- a/control/beaconing/staticinfo_config_test.go +++ b/control/beaconing/staticinfo_config_test.go @@ -95,10 +95,10 @@ func getTestConfigData() *beaconing.StaticInfoCfg { } return &beaconing.StaticInfoCfg{ - Latency: map[common.IfIdType]beaconing.InterfaceLatencies{ + Latency: map[common.IfIDType]beaconing.InterfaceLatencies{ 1: { Inter: w(latency_inter_1), - Intra: map[common.IfIdType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 2: w(latency_intra_1_2), 3: w(latency_intra_1_3), 5: w(latency_intra_1_5), @@ -106,7 +106,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 2: { Inter: w(latency_inter_2), - Intra: map[common.IfIdType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 1: w(latency_intra_1_2), 3: w(latency_intra_2_3), 5: w(latency_intra_2_5), @@ -114,7 +114,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 3: { Inter: w(latency_inter_3), - Intra: map[common.IfIdType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 1: w(latency_intra_1_3), 2: w(latency_intra_2_3), 5: w(latency_intra_3_5), @@ -122,17 +122,17 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 5: { Inter: w(latency_inter_5), - Intra: map[common.IfIdType]util.DurWrap{ + Intra: map[common.IfIDType]util.DurWrap{ 1: w(latency_intra_1_5), 2: w(latency_intra_2_5), 3: w(latency_intra_3_5), }, }, }, - Bandwidth: map[common.IfIdType]beaconing.InterfaceBandwidths{ + Bandwidth: map[common.IfIDType]beaconing.InterfaceBandwidths{ 1: { Inter: bandwidth_inter_1, - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 2: bandwidth_intra_1_2, 3: bandwidth_intra_1_3, 5: bandwidth_intra_1_5, @@ -140,7 +140,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 2: { Inter: bandwidth_inter_2, - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_2, 3: bandwidth_intra_2_3, 5: bandwidth_intra_2_5, @@ -148,7 +148,7 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 3: { Inter: bandwidth_inter_3, - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_3, 2: bandwidth_intra_2_3, 5: bandwidth_intra_3_5, @@ -156,49 +156,49 @@ func getTestConfigData() *beaconing.StaticInfoCfg { }, 5: { Inter: bandwidth_inter_5, - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_5, 2: bandwidth_intra_2_5, 3: bandwidth_intra_3_5, }, }, }, - LinkType: map[common.IfIdType]beaconing.LinkType{ + LinkType: map[common.IfIDType]beaconing.LinkType{ 1: beaconing.LinkType(link_type_1), 2: beaconing.LinkType(link_type_2), 3: beaconing.LinkType(link_type_3), 5: beaconing.LinkType(link_type_5), }, - Geo: map[common.IfIdType]beaconing.InterfaceGeodata{ + Geo: map[common.IfIDType]beaconing.InterfaceGeodata{ 1: {geo_1.Longitude, geo_1.Latitude, geo_1.Address}, 2: {geo_2.Longitude, geo_2.Latitude, geo_2.Address}, 3: {geo_3.Longitude, geo_3.Latitude, geo_3.Address}, 5: {geo_5.Longitude, geo_5.Latitude, geo_5.Address}, }, - Hops: map[common.IfIdType]beaconing.InterfaceHops{ + Hops: map[common.IfIDType]beaconing.InterfaceHops{ 1: { - Intra: map[common.IfIdType]uint32{ + Intra: map[common.IfIDType]uint32{ 2: hops_intra_1_2, 3: hops_intra_1_3, 5: hops_intra_1_5, }, }, 2: { - Intra: map[common.IfIdType]uint32{ + Intra: map[common.IfIDType]uint32{ 1: hops_intra_1_2, 3: hops_intra_2_3, 5: hops_intra_2_5, }, }, 3: { - Intra: map[common.IfIdType]uint32{ + Intra: map[common.IfIDType]uint32{ 1: hops_intra_1_3, 2: hops_intra_2_3, 5: hops_intra_3_5, }, }, 5: { - Intra: map[common.IfIdType]uint32{ + Intra: map[common.IfIDType]uint32{ 1: hops_intra_1_5, 2: hops_intra_2_5, 3: hops_intra_3_5, @@ -221,14 +221,14 @@ func TestGenerateStaticInfo(t *testing.T) { cfg := getTestConfigData() // "topology" information for a non-core AS: - ifTypeNoncore := map[common.IfIdType]topology.LinkType{ + ifTypeNoncore := map[common.IfIDType]topology.LinkType{ 1: topology.Child, 2: topology.Child, 3: topology.Parent, 5: topology.Peer, } // "topology" information for a core AS: - ifTypeCore := map[common.IfIdType]topology.LinkType{ + ifTypeCore := map[common.IfIDType]topology.LinkType{ 1: topology.Core, 2: topology.Child, 3: topology.Core, @@ -237,9 +237,9 @@ func TestGenerateStaticInfo(t *testing.T) { testCases := []struct { name string - ingress common.IfIdType - egress common.IfIdType - ifType map[common.IfIdType]topology.LinkType + ingress common.IfIDType + egress common.IfIDType + ifType map[common.IfIDType]topology.LinkType expected staticinfo.Extension }{ { @@ -249,23 +249,23 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 2: latency_intra_1_2, 3: latency_intra_1_3, 5: latency_intra_1_5, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 2: bandwidth_intra_1_2, 3: bandwidth_intra_1_3, 5: bandwidth_intra_1_5, }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, 5: bandwidth_inter_5, }, @@ -279,7 +279,7 @@ func TestGenerateStaticInfo(t *testing.T) { 1: link_type_1, 5: link_type_5, }, - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 2: hops_intra_1_2, 3: hops_intra_1_3, 5: hops_intra_1_5, @@ -294,21 +294,21 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 3: latency_intra_2_3, 5: latency_intra_2_5, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 2: latency_inter_2, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 3: bandwidth_intra_2_3, 5: bandwidth_intra_2_5, }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 2: bandwidth_inter_2, 5: bandwidth_inter_5, }, @@ -322,7 +322,7 @@ func TestGenerateStaticInfo(t *testing.T) { 2: link_type_2, 5: link_type_5, }, - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 3: hops_intra_2_3, 5: hops_intra_2_5, }, @@ -336,14 +336,14 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{}, - Inter: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{}, + Inter: map[common.IfIDType]time.Duration{ 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{}, - Inter: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{}, + Inter: map[common.IfIDType]uint64{ 5: bandwidth_inter_5, }, }, @@ -354,7 +354,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 5: link_type_5, }, - InternalHops: map[common.IfIdType]uint32{}, + InternalHops: map[common.IfIDType]uint32{}, Note: note, }, }, @@ -365,21 +365,21 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 2: latency_intra_1_2, 5: latency_intra_1_5, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 2: bandwidth_intra_1_2, 5: bandwidth_intra_1_5, }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, 5: bandwidth_inter_5, }, @@ -392,7 +392,7 @@ func TestGenerateStaticInfo(t *testing.T) { 1: link_type_1, 5: link_type_5, }, - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 2: hops_intra_1_2, 5: hops_intra_1_5, }, @@ -406,19 +406,19 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeNoncore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 5: latency_intra_2_5, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 2: latency_inter_2, 5: latency_inter_5, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 5: bandwidth_intra_2_5, }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 2: bandwidth_inter_2, 5: bandwidth_inter_5, }, @@ -431,7 +431,7 @@ func TestGenerateStaticInfo(t *testing.T) { 2: link_type_2, 5: link_type_5, }, - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 5: hops_intra_2_5, }, Note: note, @@ -444,22 +444,22 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 1: latency_intra_1_2, 3: latency_intra_2_3, 5: latency_intra_2_5, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 2: latency_inter_2, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 1: bandwidth_intra_1_2, 3: bandwidth_intra_2_3, 5: bandwidth_intra_2_5, }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 2: bandwidth_inter_2, }, }, @@ -469,7 +469,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 2: link_type_2, }, - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 1: hops_intra_1_2, 3: hops_intra_2_3, 5: hops_intra_2_5, @@ -484,14 +484,14 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{}, - Inter: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{}, + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{}, - Inter: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{}, + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, }, }, @@ -501,7 +501,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 1: link_type_1, }, - InternalHops: map[common.IfIdType]uint32{}, + InternalHops: map[common.IfIDType]uint32{}, Note: note, }, }, @@ -512,18 +512,18 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 3: latency_intra_1_3, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 1: latency_inter_1, }, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 3: bandwidth_intra_1_3, }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 1: bandwidth_inter_1, }, }, @@ -534,7 +534,7 @@ func TestGenerateStaticInfo(t *testing.T) { LinkType: staticinfo.LinkTypeInfo{ 1: link_type_1, }, - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 3: hops_intra_1_3, }, Note: note, @@ -547,18 +547,18 @@ func TestGenerateStaticInfo(t *testing.T) { ifType: ifTypeCore, expected: staticinfo.Extension{ Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{}, - Inter: map[common.IfIdType]time.Duration{}, + Intra: map[common.IfIDType]time.Duration{}, + Inter: map[common.IfIDType]time.Duration{}, }, Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{}, - Inter: map[common.IfIdType]uint64{}, + Intra: map[common.IfIDType]uint64{}, + Inter: map[common.IfIDType]uint64{}, }, Geo: staticinfo.GeoInfo{ 3: geo_3, }, LinkType: staticinfo.LinkTypeInfo{}, - InternalHops: map[common.IfIdType]uint32{}, + InternalHops: map[common.IfIDType]uint32{}, Note: note, }, }, diff --git a/control/beaconing/util.go b/control/beaconing/util.go index 5d9daa22d1..8bcb02f10d 100644 --- a/control/beaconing/util.go +++ b/control/beaconing/util.go @@ -32,12 +32,12 @@ import ( // ID. func sortedIntfs(intfs *ifstate.Interfaces, linkType topology.LinkType) []uint16 { var result []uint16 - for ifId, intf := range intfs.All() { + for ifID, intf := range intfs.All() { topoInfo := intf.TopoInfo() if topoInfo.LinkType != linkType { continue } - result = append(result, ifId) + result = append(result, ifID) } sort.Slice(result, func(i, j int) bool { return result[i] < result[j] }) return result @@ -46,14 +46,14 @@ func sortedIntfs(intfs *ifstate.Interfaces, linkType topology.LinkType) []uint16 type summary struct { mu sync.Mutex srcs map[addr.IA]struct{} - ifIds map[uint16]struct{} + ifIDs map[uint16]struct{} count int } func newSummary() *summary { return &summary{ srcs: make(map[addr.IA]struct{}), - ifIds: make(map[uint16]struct{}), + ifIDs: make(map[uint16]struct{}), } } @@ -63,10 +63,10 @@ func (s *summary) AddSrc(ia addr.IA) { s.srcs[ia] = struct{}{} } -func (s *summary) AddIfId(ifId uint16) { +func (s *summary) AddIfID(ifID uint16) { s.mu.Lock() defer s.mu.Unlock() - s.ifIds[ifId] = struct{}{} + s.ifIDs[ifID] = struct{}{} } func (s *summary) Inc() { @@ -75,12 +75,12 @@ func (s *summary) Inc() { s.count++ } -func (s *summary) IfIds() []uint16 { +func (s *summary) IfIDs() []uint16 { s.mu.Lock() defer s.mu.Unlock() - list := make([]uint16, 0, len(s.ifIds)) - for ifId := range s.ifIds { - list = append(list, ifId) + list := make([]uint16, 0, len(s.ifIDs)) + for ifID := range s.ifIDs { + list = append(list, ifID) } sort.Slice(list, func(i, j int) bool { return list[i] < list[j] }) return list diff --git a/control/beaconing/writer.go b/control/beaconing/writer.go index 70dcde0eae..52dd7a2b3c 100644 --- a/control/beaconing/writer.go +++ b/control/beaconing/writer.go @@ -165,10 +165,10 @@ func (r *RemoteWriter) Write( var expected int var wg sync.WaitGroup for _, b := range segments { - if r.Intfs.Get(b.InIfId) == nil { + if r.Intfs.Get(b.InIfID) == nil { continue } - err := r.Extender.Extend(ctx, b.Segment, b.InIfId, 0, peers) + err := r.Extender.Extend(ctx, b.Segment, b.InIfID, 0, peers) if err != nil { logger.Error("Unable to terminate beacon", "beacon", b, "err", err) metrics.CounterInc(r.InternalErrors) @@ -223,10 +223,10 @@ func (r *LocalWriter) Write( beacons := make(map[string]beacon.Beacon) var toRegister []*seg.Meta for _, b := range segments { - if r.Intfs.Get(b.InIfId) == nil { + if r.Intfs.Get(b.InIfID) == nil { continue } - err := r.Extender.Extend(ctx, b.Segment, b.InIfId, 0, peers) + err := r.Extender.Extend(ctx, b.Segment, b.InIfID, 0, peers) if err != nil { logger.Error("Unable to terminate beacon", "beacon", b, "err", err) metrics.CounterInc(r.InternalErrors) @@ -266,7 +266,7 @@ func (r *LocalWriter) updateMetricsFromStat(s seghandler.SegStats, b map[string] for _, id := range s.InsertedSegs { metrics.CounterInc(metrics.CounterWith(r.Registered, writerLabels{ StartIA: b[id].Segment.FirstIA(), - Ingress: b[id].InIfId, + Ingress: b[id].InIfID, SegType: r.Type.String(), Result: "ok_new", }.Expand()...)) @@ -274,7 +274,7 @@ func (r *LocalWriter) updateMetricsFromStat(s seghandler.SegStats, b map[string] for _, id := range s.UpdatedSegs { metrics.CounterInc(metrics.CounterWith(r.Registered, writerLabels{ StartIA: b[id].Segment.FirstIA(), - Ingress: b[id].InIfId, + Ingress: b[id].InIfID, SegType: r.Type.String(), Result: "ok_updated", }.Expand()...)) @@ -315,7 +315,7 @@ func (r *remoteWriter) startSendSegReg(ctx context.Context, bseg beacon.Beacon, labels := writerLabels{ StartIA: bseg.Segment.FirstIA(), - Ingress: bseg.InIfId, + Ingress: bseg.InIfID, SegType: r.writer.Type.String(), } diff --git a/control/beaconing/writer_test.go b/control/beaconing/writer_test.go index 4cb5005c43..3a73fe9748 100644 --- a/control/beaconing/writer_test.go +++ b/control/beaconing/writer_test.go @@ -316,7 +316,7 @@ func TestRegistrarRun(t *testing.T) { func(_, _ interface{}) (<-chan beacon.Beacon, error) { res := make(chan beacon.Beacon, 1) b := testBeacon(g, []uint16{graph.If_120_X_111_B}) - b.InIfId = 10 + b.InIfID = 10 res <- b close(res) return res, nil @@ -331,7 +331,7 @@ func testBeacon(g *graph.Graph, desc []uint16) beacon.Beacon { bseg.ASEntries = bseg.ASEntries[:len(bseg.ASEntries)-1] return beacon.Beacon{ - InIfId: asEntry.HopEntry.HopField.ConsIngress, + InIfID: asEntry.HopEntry.HopField.ConsIngress, Segment: bseg, } } @@ -377,7 +377,7 @@ type topoWrap struct { } func (w topoWrap) UnderlayNextHop(id uint16) *net.UDPAddr { - a, _ := w.Topo.UnderlayNextHop(common.IfIdType(id)) + a, _ := w.Topo.UnderlayNextHop(common.IfIDType(id)) return a } diff --git a/control/cmd/control/main.go b/control/cmd/control/main.go index e51cf41845..e4142f4f9d 100644 --- a/control/cmd/control/main.go +++ b/control/cmd/control/main.go @@ -844,7 +844,7 @@ func createBeaconStore( return store, *policies.Prop.Filter.AllowIsdLoop, err } -func adaptInterfaceMap(in map[common.IfIdType]topology.IFInfo) map[uint16]ifstate.InterfaceInfo { +func adaptInterfaceMap(in map[common.IfIDType]topology.IFInfo) map[uint16]ifstate.InterfaceInfo { converted := make(map[uint16]ifstate.InterfaceInfo, len(in)) for id, info := range in { converted[uint16(id)] = ifstate.InterfaceInfo{ diff --git a/control/ifstate/ifstate.go b/control/ifstate/ifstate.go index aa163f390b..53aa464d2a 100644 --- a/control/ifstate/ifstate.go +++ b/control/ifstate/ifstate.go @@ -86,12 +86,12 @@ func (intfs *Interfaces) Update(ifInfomap map[uint16]InterfaceInfo) { intfs.mu.Lock() defer intfs.mu.Unlock() m := make(map[uint16]*Interface, len(intfs.intfs)) - for ifId, info := range ifInfomap { - if intf, ok := intfs.intfs[ifId]; ok { + for ifID, info := range ifInfomap { + if intf, ok := intfs.intfs[ifID]; ok { intf.updateTopoInfo(info) - m[ifId] = intf + m[ifID] = intf } else { - m[ifId] = &Interface{ + m[ifID] = &Interface{ topoInfo: info, cfg: intfs.cfg, } @@ -128,17 +128,17 @@ func (intfs *Interfaces) All() map[uint16]*Interface { intfs.mu.RLock() defer intfs.mu.RUnlock() res := make(map[uint16]*Interface, len(intfs.intfs)) - for ifId, intf := range intfs.intfs { - res[ifId] = intf + for ifID, intf := range intfs.intfs { + res[ifID] = intf } return res } // Get returns the interface for the specified id, or nil if not present. -func (intfs *Interfaces) Get(ifId uint16) *Interface { +func (intfs *Interfaces) Get(ifID uint16) *Interface { intfs.mu.RLock() defer intfs.mu.RUnlock() - return intfs.intfs[ifId] + return intfs.intfs[ifID] } // Interface keeps track of the interface state. diff --git a/control/ifstate/ifstate_test.go b/control/ifstate/ifstate_test.go index 7bd8e530d6..7b144f15be 100644 --- a/control/ifstate/ifstate_test.go +++ b/control/ifstate/ifstate_test.go @@ -33,7 +33,7 @@ func TestInterfacesUpdate(t *testing.T) { // The topo info should come from the updated map. assert.Equal(t, uint16(1401), intfs.Get(1).TopoInfo().MTU) assert.Equal(t, uint16(1402), intfs.Get(2).TopoInfo().MTU) - // The remote ifId should be kept + // The remote ifID should be kept assert.EqualValues(t, 11, intfs.Get(1).TopoInfo().RemoteID) assert.EqualValues(t, 22, intfs.Get(2).TopoInfo().RemoteID) }) diff --git a/control/mgmtapi/api.go b/control/mgmtapi/api.go index 539edf9f6d..a18993ffe8 100644 --- a/control/mgmtapi/api.go +++ b/control/mgmtapi/api.go @@ -213,7 +213,7 @@ func (s *Server) GetBeacons(w http.ResponseWriter, r *http.Request, params GetBe } rep = append(rep, &Beacon{ Usages: usage, - IngressInterface: int(result.Beacon.InIfId), + IngressInterface: int(result.Beacon.InIfID), Id: segapi.SegID(s), LastUpdated: result.LastUpdated, Timestamp: s.Info.Timestamp.UTC(), @@ -362,7 +362,7 @@ func (s *Server) GetBeacon(w http.ResponseWriter, r *http.Request, segmentId Seg res := map[string]Beacon{ "beacon": { Usages: usage, - IngressInterface: int(results[0].Beacon.InIfId), + IngressInterface: int(results[0].Beacon.InIfID), Id: segapi.SegID(seg), LastUpdated: results[0].LastUpdated, Timestamp: seg.Info.Timestamp.UTC(), diff --git a/control/mgmtapi/api_test.go b/control/mgmtapi/api_test.go index c31cc20d17..d4e3e650b6 100644 --- a/control/mgmtapi/api_test.go +++ b/control/mgmtapi/api_test.go @@ -945,7 +945,7 @@ func createBeacons(t *testing.T) []beacon.Beacon { }, }, }, - InIfId: 2, + InIfID: 2, }, Usage: beaconlib.UsageUpReg | beaconlib.UsageDownReg, LastUpdated: time.Date(2021, 1, 2, 8, 0, 0, 0, time.UTC), @@ -979,7 +979,7 @@ func createBeacons(t *testing.T) []beacon.Beacon { }, }, }, - InIfId: 1, + InIfID: 1, }, Usage: beaconlib.UsageCoreReg, LastUpdated: time.Date(2021, 2, 2, 8, 0, 0, 0, time.UTC), diff --git a/control/revhandler.go b/control/revhandler.go index cbb65aac32..141eb06aa8 100644 --- a/control/revhandler.go +++ b/control/revhandler.go @@ -32,7 +32,7 @@ func (h RevocationHandler) Revoke(ctx context.Context, revInfo *path_mgmt.RevInf if _, err := h.RevCache.Insert(ctx, revInfo); err != nil { return serrors.WrapStr("inserting revocation", err, "isd_as", revInfo.IA(), - "interface_id", revInfo.IfId, + "interface_id", revInfo.IfID, "expiration", revInfo.Expiration(), ) } diff --git a/daemon/internal/servers/grpc.go b/daemon/internal/servers/grpc.go index f6ad899cb6..6f050dff79 100644 --- a/daemon/internal/servers/grpc.go +++ b/daemon/internal/servers/grpc.go @@ -277,12 +277,12 @@ func (s *DaemonServer) interfaces(ctx context.Context, Interfaces: make(map[uint64]*sdpb.Interface), } topo := s.Topology - for _, ifId := range topo.InterfaceIDs() { - nextHop := topo.UnderlayNextHop(ifId) + for _, ifID := range topo.InterfaceIDs() { + nextHop := topo.UnderlayNextHop(ifID) if nextHop == nil { continue } - reply.Interfaces[uint64(ifId)] = &sdpb.Interface{ + reply.Interfaces[uint64(ifID)] = &sdpb.Interface{ Address: &sdpb.Underlay{ Address: nextHop.String(), }, @@ -337,7 +337,7 @@ func (s *DaemonServer) notifyInterfaceDown(ctx context.Context, revInfo := &path_mgmt.RevInfo{ RawIsdas: addr.IA(req.IsdAs), - IfId: common.IfIdType(req.Id), + IfID: common.IfIDType(req.Id), LinkType: proto.LinkType_core, RawTTL: 10, RawTimestamp: util.TimeToSecs(time.Now()), diff --git a/doc/dev/style/go.rst b/doc/dev/style/go.rst index e3be4d6659..f96a349f30 100644 --- a/doc/dev/style/go.rst +++ b/doc/dev/style/go.rst @@ -13,12 +13,14 @@ Naming ------ We use mixedCaps notation as recommended by `Effective Go -`__. The following rules apply (note -that a significant part of the code base uses other notations; these should be -refactored, however): +`__. Perhaps unintuitively, Go +treats ``ID`` as an initialism, and we treat ``If`` as a word. The following +rules apply (note that a significant part of the code base uses other +notations; these should be refactored, however): - Use ``sd`` or ``SD`` to refer to the SCION Daemon, not ``Sciond`` or ``SCIOND``. -- Use ``IfID`` or ``ifID`` for SCION Interface Identifiers, not ``IFID`` or ``InterfaceID``. +- Use ``IfID`` or ``ifID`` for SCION Interface Identifiers, not ``IFID`` nor ``InterfaceID`` nor ``intfID``. +- Use ``IfIDSomething`` or ``ifIDSomething`` when concatenating ``ifID`` with ``something``. - Use ``Svc`` or ``svc`` for SCION Service Addresses, not ``SVC`` or ``Service``. - Use ``TRC`` or ``trc`` for Trust Root Configurations, not ``Trc``. diff --git a/gateway/pathhealth/revocations.go b/gateway/pathhealth/revocations.go index d0038a6be1..caab23b017 100644 --- a/gateway/pathhealth/revocations.go +++ b/gateway/pathhealth/revocations.go @@ -41,7 +41,7 @@ func (s *MemoryRevocationStore) AddRevocation(ctx context.Context, rev *path_mgm if rev == nil { return } - iface := snet.PathInterface{IA: rev.RawIsdas, ID: rev.IfId} + iface := snet.PathInterface{IA: rev.RawIsdas, ID: rev.IfID} if _, ok := s.revs[iface]; !ok { logger.Debug("Revocation added", "isd_as", iface.IA, "intf", iface.ID) } @@ -60,7 +60,7 @@ func (s *MemoryRevocationStore) Cleanup(ctx context.Context) { now := time.Now() for k, rev := range s.revs { if rev.Expiration().Before(now) { - logger.Debug("Revocation expired", "isd_as", rev.RawIsdas, "intf", rev.IfId) + logger.Debug("Revocation expired", "isd_as", rev.RawIsdas, "intf", rev.IfID) delete(s.revs, k) } } diff --git a/gateway/pathhealth/revocations_test.go b/gateway/pathhealth/revocations_test.go index d1056e5d32..8698fe891f 100644 --- a/gateway/pathhealth/revocations_test.go +++ b/gateway/pathhealth/revocations_test.go @@ -69,18 +69,18 @@ func TestExpiredRevocation(t *testing.T) { s.Cleanup(context.Background()) } -func createMockPath(ctrl *gomock.Controller, ia addr.IA, ifId common.IfIdType) snet.Path { +func createMockPath(ctrl *gomock.Controller, ia addr.IA, ifID common.IfIDType) snet.Path { path := mock_snet.NewMockPath(ctrl) path.EXPECT().Metadata().Return(&snet.PathMetadata{ - Interfaces: []snet.PathInterface{{IA: ia, ID: ifId}}, + Interfaces: []snet.PathInterface{{IA: ia, ID: ifID}}, }) return path } -func createRevInfo(ia addr.IA, ifId common.IfIdType, expired bool) *path_mgmt.RevInfo { +func createRevInfo(ia addr.IA, ifID common.IfIDType, expired bool) *path_mgmt.RevInfo { ri := &path_mgmt.RevInfo{ RawIsdas: ia, - IfId: ifId, + IfID: ifID, // Revocation was issued a minute ago. RawTimestamp: util.TimeToSecs(time.Now().Add(-time.Minute)), } diff --git a/pkg/daemon/grpc.go b/pkg/daemon/grpc.go index 040e3078c3..0b5ff34736 100644 --- a/pkg/daemon/grpc.go +++ b/pkg/daemon/grpc.go @@ -93,13 +93,13 @@ func (c grpcConn) Interfaces(ctx context.Context) (map[uint16]netip.AddrPort, er return nil, err } result := make(map[uint16]netip.AddrPort, len(response.Interfaces)) - for ifId, intf := range response.Interfaces { + for ifID, intf := range response.Interfaces { a, err := netip.ParseAddrPort(intf.Address.Address) if err != nil { c.metrics.incInterface(err) return nil, serrors.WrapStr("parsing reply", err, "raw_uri", intf.Address.Address) } - result[uint16(ifId)] = a + result[uint16(ifID)] = a } c.metrics.incInterface(nil) return result, nil @@ -168,7 +168,7 @@ func (c grpcConn) SVCInfo( func (c grpcConn) RevNotification(ctx context.Context, revInfo *path_mgmt.RevInfo) error { client := sdpb.NewDaemonServiceClient(c.conn) _, err := client.NotifyInterfaceDown(ctx, &sdpb.NotifyInterfaceDownRequest{ - Id: uint64(revInfo.IfId), + Id: uint64(revInfo.IfID), IsdAs: uint64(revInfo.RawIsdas), }) c.metrics.incIfDown(err) @@ -260,7 +260,7 @@ func convertPath(p *sdpb.Path, dst addr.IA) (path.Path, error) { interfaces := make([]snet.PathInterface, len(p.Interfaces)) for i, pi := range p.Interfaces { interfaces[i] = snet.PathInterface{ - ID: common.IfIdType(pi.Id), + ID: common.IfIDType(pi.Id), IA: addr.IA(pi.IsdAs), } } diff --git a/pkg/experimental/hiddenpath/beaconwriter.go b/pkg/experimental/hiddenpath/beaconwriter.go index 917ac03c80..3fd2b802db 100644 --- a/pkg/experimental/hiddenpath/beaconwriter.go +++ b/pkg/experimental/hiddenpath/beaconwriter.go @@ -80,17 +80,17 @@ func (w *BeaconWriter) Write(ctx context.Context, segments []beacon.Beacon, var wg sync.WaitGroup for _, b := range segments { - if w.Intfs.Get(b.InIfId) == nil { - logger.Error("Received beacon for non-existing interface", "interface", b.InIfId) + if w.Intfs.Get(b.InIfID) == nil { + logger.Error("Received beacon for non-existing interface", "interface", b.InIfID) metrics.CounterInc(w.InternalErrors) continue } - regPolicy, ok := w.RegistrationPolicy[uint64(b.InIfId)] + regPolicy, ok := w.RegistrationPolicy[uint64(b.InIfID)] if !ok { - logger.Info("no HP nor public registration policy for beacon", "interface", b.InIfId) + logger.Info("no HP nor public registration policy for beacon", "interface", b.InIfID) continue } - err := w.Extender.Extend(ctx, b.Segment, b.InIfId, 0, peers) + err := w.Extender.Extend(ctx, b.Segment, b.InIfID, 0, peers) if err != nil { logger.Error("Unable to terminate beacon", "beacon", b, "err", err) metrics.CounterInc(w.InternalErrors) @@ -161,7 +161,7 @@ func (w *remoteWriter) run(ctx context.Context, bseg beacon.Beacon) { labels := writerLabels{ StartIA: bseg.Segment.FirstIA(), - Ingress: bseg.InIfId, + Ingress: bseg.InIfID, SegType: w.segTypeString(), } diff --git a/pkg/experimental/hiddenpath/beaconwriter_test.go b/pkg/experimental/hiddenpath/beaconwriter_test.go index d46746f118..6b04b7ef3b 100644 --- a/pkg/experimental/hiddenpath/beaconwriter_test.go +++ b/pkg/experimental/hiddenpath/beaconwriter_test.go @@ -231,7 +231,7 @@ func testBeacon(g *graph.Graph, desc []uint16) beacon.Beacon { bseg.ASEntries = bseg.ASEntries[:len(bseg.ASEntries)-1] return beacon.Beacon{ - InIfId: asEntry.HopEntry.HopField.ConsIngress, + InIfID: asEntry.HopEntry.HopField.ConsIngress, Segment: bseg, } } @@ -274,12 +274,12 @@ func (v segVerifier) Verify(_ context.Context, signedMsg *cryptopb.SignedMessage // ID. func sortedIntfs(intfs *ifstate.Interfaces, linkType topology.LinkType) []uint16 { var result []uint16 - for ifId, intf := range intfs.All() { + for ifID, intf := range intfs.All() { topoInfo := intf.TopoInfo() if topoInfo.LinkType != linkType { continue } - result = append(result, ifId) + result = append(result, ifID) } sort.Slice(result, func(i, j int) bool { return result[i] < result[j] }) return result @@ -348,7 +348,7 @@ type topoWrap struct { } func (w topoWrap) UnderlayNextHop(id uint16) *net.UDPAddr { - a, _ := w.Topo.UnderlayNextHop(common.IfIdType(id)) + a, _ := w.Topo.UnderlayNextHop(common.IfIDType(id)) return a } diff --git a/pkg/experimental/hiddenpath/registrationpolicy.go b/pkg/experimental/hiddenpath/registrationpolicy.go index 4b472f12e6..5187f64cc5 100644 --- a/pkg/experimental/hiddenpath/registrationpolicy.go +++ b/pkg/experimental/hiddenpath/registrationpolicy.go @@ -37,10 +37,10 @@ type RegistrationPolicy map[uint64]InterfacePolicy // Validate validates the registration policy. func (p RegistrationPolicy) Validate() error { - for ifId, p := range p { + for ifID, p := range p { for id, group := range p.Groups { if err := group.Validate(); err != nil { - return serrors.WrapStr("validating group", err, "group_id", id, "interface", ifId) + return serrors.WrapStr("validating group", err, "group_id", id, "interface", ifID) } } } @@ -51,15 +51,15 @@ func (p RegistrationPolicy) Validate() error { func (p RegistrationPolicy) MarshalYAML() (interface{}, error) { collectedGroups := make(Groups) policies := make(map[uint64][]string, len(p)) - for ifId, ip := range p { + for ifID, ip := range p { for id, group := range ip.Groups { collectedGroups[id] = group - policies[ifId] = append(policies[ifId], id.String()) + policies[ifID] = append(policies[ifID], id.String()) } if ip.Public { - policies[ifId] = append(policies[ifId], "public") + policies[ifID] = append(policies[ifID], "public") } - sort.Strings(policies[ifId]) + sort.Strings(policies[ifID]) } return ®istrationPolicyInfo{ Groups: marshalGroups(collectedGroups), @@ -81,8 +81,8 @@ func (p RegistrationPolicy) UnmarshalYAML(unmarshal func(interface{}) error) err if err != nil { return err } - for ifId, pol := range parsed { - p[ifId] = pol + for ifID, pol := range parsed { + p[ifID] = pol } return nil } @@ -127,7 +127,7 @@ type registrationPolicyInfo struct { func parsePolicies(groups Groups, rawPolicies map[uint64][]string) (RegistrationPolicy, error) { result := make(RegistrationPolicy) - for ifId, groupIDs := range rawPolicies { + for ifID, groupIDs := range rawPolicies { pol := InterfacePolicy{ Groups: make(map[GroupID]*Group), } @@ -146,7 +146,7 @@ func parsePolicies(groups Groups, rawPolicies map[uint64][]string) (Registration } pol.Groups[id] = group } - result[ifId] = pol + result[ifID] = pol } return result, nil } diff --git a/pkg/private/common/defs.go b/pkg/private/common/defs.go index bb3fbeb54a..ae00ad94c7 100644 --- a/pkg/private/common/defs.go +++ b/pkg/private/common/defs.go @@ -32,28 +32,28 @@ const ( TimeFmtSecs = "2006-01-02 15:04:05-0700" ) -// IfIdType is the type for interface IDs. +// IfIDType is the type for interface IDs. // // Deprecated: with version 2 of the SCION header, there is no interface ID type anymore. // Use the appropriate type depending on the path type. -type IfIdType uint64 +type IfIDType uint64 -func (ifId IfIdType) String() string { - return strconv.FormatUint(uint64(ifId), 10) +func (ifID IfIDType) String() string { + return strconv.FormatUint(uint64(ifID), 10) } -// UnmarshalJSON unmarshals the JSON data into the IfId. -func (ifId *IfIdType) UnmarshalJSON(data []byte) error { - return ifId.UnmarshalText(data) +// UnmarshalJSON unmarshals the JSON data into the IfID. +func (ifID *IfIDType) UnmarshalJSON(data []byte) error { + return ifID.UnmarshalText(data) } -// UnmarshalText unmarshals the text into the IfId. -func (ifId *IfIdType) UnmarshalText(text []byte) error { +// UnmarshalText unmarshals the text into the IfID. +func (ifID *IfIDType) UnmarshalText(text []byte) error { i, err := strconv.ParseUint(strings.ReplaceAll(string(text), "\"", ""), 10, 64) if err != nil { return err } - *ifId = IfIdType(i) + *ifID = IfIDType(i) return nil } diff --git a/pkg/private/common/defs_test.go b/pkg/private/common/defs_test.go index bff7e77d27..218181b201 100644 --- a/pkg/private/common/defs_test.go +++ b/pkg/private/common/defs_test.go @@ -41,29 +41,29 @@ func TestTypeOf(t *testing.T) { } } -func TestIfIdTypeUnmarshalJSON(t *testing.T) { +func TestIfIDTypeUnmarshalJSON(t *testing.T) { t.Run("Simple Value", func(t *testing.T) { type exampleStruct struct { - IfId common.IfIdType `json:"if_id"` + IfID common.IfIDType `json:"if_id"` } j := `{"if_id": 5}` var f exampleStruct require.NoError(t, json.Unmarshal([]byte(j), &f)) - assert.Equal(t, exampleStruct{IfId: 5}, f) + assert.Equal(t, exampleStruct{IfID: 5}, f) }) t.Run("Map keys", func(t *testing.T) { type exampleStruct struct { - IfMap map[common.IfIdType]string `json:"if_map"` + IfMap map[common.IfIDType]string `json:"if_map"` } j := `{"if_map": {"5": "foo"}}` var f exampleStruct require.NoError(t, json.Unmarshal([]byte(j), &f)) - assert.Equal(t, exampleStruct{IfMap: map[common.IfIdType]string{5: "foo"}}, f) + assert.Equal(t, exampleStruct{IfMap: map[common.IfIDType]string{5: "foo"}}, f) }) } -func TestIfIdTypeUnmarshalText(t *testing.T) { - var id common.IfIdType +func TestIfIDTypeUnmarshalText(t *testing.T) { + var id common.IfIDType assert.NoError(t, id.UnmarshalText([]byte("1"))) - assert.Equal(t, common.IfIdType(1), id) + assert.Equal(t, common.IfIDType(1), id) } diff --git a/pkg/private/ctrl/path_mgmt/rev_info.go b/pkg/private/ctrl/path_mgmt/rev_info.go index 409a033de3..45b75ff82f 100644 --- a/pkg/private/ctrl/path_mgmt/rev_info.go +++ b/pkg/private/ctrl/path_mgmt/rev_info.go @@ -47,7 +47,7 @@ func (ee RevTimeError) Error() string { } type RevInfo struct { - IfId common.IfIdType + IfID common.IfIDType RawIsdas addr.IA // LinkType of revocation LinkType proto.LinkType @@ -92,7 +92,7 @@ func (r *RevInfo) Active() error { } func (r *RevInfo) String() string { - return fmt.Sprintf("IA: %s IfId: %d Link type: %s Timestamp: %s TTL: %s", r.IA(), r.IfId, + return fmt.Sprintf("IA: %s IfID: %d Link type: %s Timestamp: %s TTL: %s", r.IA(), r.IfID, r.LinkType, util.TimeToCompact(r.Timestamp()), r.TTL()) } @@ -117,7 +117,7 @@ func (r *RevInfo) Equal(other *RevInfo) bool { // SameIntf returns true if r and other both apply to the same interface. func (r *RevInfo) SameIntf(other *RevInfo) bool { - return r.IfId == other.IfId && + return r.IfID == other.IfID && r.RawIsdas == other.RawIsdas && r.LinkType == other.LinkType } diff --git a/pkg/private/xtest/graph/graph.go b/pkg/private/xtest/graph/graph.go index 65792ff0a1..a114ba9c61 100644 --- a/pkg/private/xtest/graph/graph.go +++ b/pkg/private/xtest/graph/graph.go @@ -89,7 +89,7 @@ func NewFromDescription(ctrl *gomock.Controller, desc *Description) *Graph { graph.Add(node) } for _, edge := range desc.Edges { - graph.AddLink(edge.Xia, edge.XifId, edge.Yia, edge.YifId, edge.Peer) + graph.AddLink(edge.Xia, edge.XifID, edge.Yia, edge.YifID, edge.Peer) } return graph } @@ -152,29 +152,29 @@ func (g *Graph) AddLink(xIA string, xIFID uint16, g.ases[y].IFIDs[yIFID] = struct{}{} } -// RemoveLink deletes the edge containing ifId from the graph. -func (g *Graph) RemoveLink(ifId uint16) { +// RemoveLink deletes the edge containing ifID from the graph. +func (g *Graph) RemoveLink(ifID uint16) { g.lock.Lock() defer g.lock.Unlock() - ia := g.parents[ifId] - neighborIFID := g.links[ifId] + ia := g.parents[ifID] + neighborIFID := g.links[ifID] neighborIA := g.parents[neighborIFID] - delete(g.links, ifId) + delete(g.links, ifID) delete(g.links, neighborIFID) - delete(g.isPeer, ifId) + delete(g.isPeer, ifID) delete(g.isPeer, neighborIFID) - delete(g.parents, ifId) + delete(g.parents, ifID) delete(g.parents, neighborIFID) - g.ases[ia].Delete(ifId) + g.ases[ia].Delete(ifID) g.ases[neighborIA].Delete(neighborIFID) } -// GetParent returns the parent AS of ifId. -func (g *Graph) GetParent(ifId uint16) addr.IA { +// GetParent returns the parent AS of ifID. +func (g *Graph) GetParent(ifID uint16) addr.IA { g.lock.Lock() defer g.lock.Unlock() - return g.parents[ifId] + return g.parents[ifID] } // GetPaths returns all the minimum-length paths. If xIA = yIA, a 1-length @@ -215,15 +215,15 @@ func (g *Graph) GetPaths(xIA string, yIA string) [][]uint16 { } // Explore neighboring ASes, if not visited yet. - for ifId := range g.ases[curSolution.CurrentIA].IFIDs { - nextIFID := g.links[ifId] + for ifID := range g.ases[curSolution.CurrentIA].IFIDs { + nextIFID := g.links[ifID] nextIA := g.parents[nextIFID] if curSolution.Visited(nextIA) { continue } // Copy to avoid mutating the trails of other explorations. nextTrail := curSolution.Copy() - nextTrail.Add(ifId, nextIFID, nextIA) + nextTrail.Add(ifID, nextIFID, nextIA) nextTrail.CurrentIA = nextIA queue = append(queue, nextTrail) } @@ -231,35 +231,35 @@ func (g *Graph) GetPaths(xIA string, yIA string) [][]uint16 { return solution } -// Beacon constructs path segments across a series of egress ifIds. The parent +// Beacon constructs path segments across a series of egress ifIDs. The parent // AS of the first IFID is the origin of the beacon, and the beacon propagates // down to the parent AS of the remote counterpart of the last IFID. The // constructed segment includes peering links. The hop fields in the returned // segment do not contain valid MACs. -func (g *Graph) Beacon(ifIds []uint16) *seg.PathSegment { - return g.beacon(ifIds, false) +func (g *Graph) Beacon(ifIDs []uint16) *seg.PathSegment { + return g.beacon(ifIDs, false) } -func (g *Graph) BeaconWithStaticInfo(ifIds []uint16) *seg.PathSegment { - return g.beacon(ifIds, true) +func (g *Graph) BeaconWithStaticInfo(ifIDs []uint16) *seg.PathSegment { + return g.beacon(ifIDs, true) } -// beacon constructs path segments across a series of egress ifIds. The parent +// beacon constructs path segments across a series of egress ifIDs. The parent // AS of the first IFID is the origin of the beacon, and the beacon propagates // down to the parent AS of the remote counterpart of the last IFID. The // constructed segment includes peering links. The hop fields in the returned // segment do not contain valid MACs. -func (g *Graph) beacon(ifIds []uint16, addStaticInfo bool) *seg.PathSegment { +func (g *Graph) beacon(ifIDs []uint16, addStaticInfo bool) *seg.PathSegment { var inIF, outIF, remoteOutIF uint16 var currIA, outIA addr.IA var segment *seg.PathSegment - if len(ifIds) == 0 { + if len(ifIDs) == 0 { return segment } - if _, ok := g.parents[ifIds[0]]; !ok { - panic(fmt.Sprintf("%d unknown ifId", ifIds[0])) + if _, ok := g.parents[ifIDs[0]]; !ok { + panic(fmt.Sprintf("%d unknown ifID", ifIDs[0])) } segment, err := seg.CreateSegment(time.Now(), uint16(rand.Int())) @@ -267,17 +267,17 @@ func (g *Graph) beacon(ifIds []uint16, addStaticInfo bool) *seg.PathSegment { panic(err) } - currIA = g.parents[ifIds[0]] - for i := 0; i <= len(ifIds); i++ { + currIA = g.parents[ifIDs[0]] + for i := 0; i <= len(ifIDs); i++ { switch { - case i < len(ifIds): + case i < len(ifIDs): var ok bool - outIF = ifIds[i] + outIF = ifIDs[i] if remoteOutIF, ok = g.links[outIF]; !ok { - panic(fmt.Sprintf("%d unknown ifId", outIF)) + panic(fmt.Sprintf("%d unknown ifID", outIF)) } outIA = g.parents[remoteOutIF] - case i == len(ifIds): + case i == len(ifIDs): outIF = 0 remoteOutIF = 0 outIA = 0 @@ -302,13 +302,13 @@ func (g *Graph) beacon(ifIds []uint16, addStaticInfo bool) *seg.PathSegment { as := g.ases[currIA] // use int to avoid implementing sort.Interface - var ifIds []int + var ifIDs []int for peeringLocalIF := range as.IFIDs { - ifIds = append(ifIds, int(peeringLocalIF)) + ifIDs = append(ifIDs, int(peeringLocalIF)) } - sort.Ints(ifIds) + sort.Ints(ifIDs) - for _, intIFID := range ifIds { + for _, intIFID := range ifIDs { peeringLocalIF := uint16(intIFID) if g.isPeer[peeringLocalIF] { peeringRemoteIF := g.links[peeringLocalIF] @@ -337,10 +337,10 @@ func (g *Graph) beacon(ifIds []uint16, addStaticInfo bool) *seg.PathSegment { return segment } -// DeleteInterface removes ifId from the graph without deleting its remote +// DeleteInterface removes ifID from the graph without deleting its remote // counterpart. This is useful for testing IFID misconfigurations. -func (g *Graph) DeleteInterface(ifId uint16) { - delete(g.links, ifId) +func (g *Graph) DeleteInterface(ifID uint16) { + delete(g.links, ifID) } // Latency returns an arbitrary test latency value between two interfaces. The @@ -373,15 +373,15 @@ func (g *Graph) Bandwidth(a, b uint16) uint64 { } // GeoCoordinates returns an arbitrary test GeoCoordinate for the interface -func (g *Graph) GeoCoordinates(ifId uint16) staticinfo.GeoCoordinates { - ia, ok := g.parents[ifId] +func (g *Graph) GeoCoordinates(ifID uint16) staticinfo.GeoCoordinates { + ia, ok := g.parents[ifID] if !ok { panic("unknown interface") } return staticinfo.GeoCoordinates{ - Latitude: float32(ifId), - Longitude: float32(ifId), - Address: fmt.Sprintf("Location %s#%d", ia, ifId), + Latitude: float32(ifID), + Longitude: float32(ifID), + Address: fmt.Sprintf("Location %s#%d", ia, ifID), } } @@ -502,12 +502,12 @@ type AS struct { IFIDs map[uint16]struct{} } -// Delete removes ifId from as. -func (as *AS) Delete(ifId uint16) { - if _, ok := as.IFIDs[ifId]; !ok { - panic("ifId not found") +// Delete removes ifID from as. +func (as *AS) Delete(ifID uint16) { + if _, ok := as.IFIDs[ifID]; !ok { + panic("ifID not found") } - delete(as.IFIDs, ifId) + delete(as.IFIDs, ifID) } // solution tracks the state of a candidate solution for the graph @@ -575,9 +575,9 @@ type Description struct { // EdgeDesc is used in Descriptions to describe the links between ASes. type EdgeDesc struct { Xia string - XifId uint16 + XifID uint16 Yia string - YifId uint16 + YifID uint16 Peer bool } @@ -590,7 +590,7 @@ func NewDefaultGraph(ctrl *gomock.Controller) *Graph { // It then uses that interface to generate characteristic StaticInfo for said interface, // such that testcases can be written by looking only at the interfaces // that send/receive beacons across the path. -// Characteristic StaticInfo is generated by simply taking the ifId of the interface and +// Characteristic StaticInfo is generated by simply taking the ifID of the interface and // converting it to a format that fits the kind of StaticInfo that is being stored // (e.g. typecast to uint16 for Latency). With this method, the StaticInfo for every // interface has a unique value. @@ -603,55 +603,55 @@ func generateStaticInfo(g *Graph, ia addr.IA, inIF, outIF uint16) *staticinfo.Ex latency := staticinfo.LatencyInfo{} if outIF != 0 { - latency.Intra = make(map[common.IfIdType]time.Duration) - latency.Inter = make(map[common.IfIdType]time.Duration) - for ifId := range as.IFIDs { - if ifId != outIF { + latency.Intra = make(map[common.IfIDType]time.Duration) + latency.Inter = make(map[common.IfIDType]time.Duration) + for ifID := range as.IFIDs { + if ifID != outIF { // Note: the test graph does not distinguish between parent/child or // core interfaces. // Otherwise, we could skip the parent interfaces and half of the // sibling interfaces here. - latency.Intra[common.IfIdType(ifId)] = g.Latency(ifId, outIF) + latency.Intra[common.IfIDType(ifID)] = g.Latency(ifID, outIF) } - if ifId == outIF || g.isPeer[ifId] { - latency.Inter[common.IfIdType(ifId)] = g.Latency(ifId, g.links[ifId]) + if ifID == outIF || g.isPeer[ifID] { + latency.Inter[common.IfIDType(ifID)] = g.Latency(ifID, g.links[ifID]) } } } bandwidth := staticinfo.BandwidthInfo{} if outIF != 0 { - bandwidth.Intra = make(map[common.IfIdType]uint64) - bandwidth.Inter = make(map[common.IfIdType]uint64) - for ifId := range as.IFIDs { - if ifId != outIF { - bandwidth.Intra[common.IfIdType(ifId)] = g.Bandwidth(ifId, outIF) + bandwidth.Intra = make(map[common.IfIDType]uint64) + bandwidth.Inter = make(map[common.IfIDType]uint64) + for ifID := range as.IFIDs { + if ifID != outIF { + bandwidth.Intra[common.IfIDType(ifID)] = g.Bandwidth(ifID, outIF) } - if ifId == outIF || g.isPeer[ifId] { - bandwidth.Inter[common.IfIdType(ifId)] = g.Bandwidth(ifId, g.links[ifId]) + if ifID == outIF || g.isPeer[ifID] { + bandwidth.Inter[common.IfIDType(ifID)] = g.Bandwidth(ifID, g.links[ifID]) } } } geo := make(staticinfo.GeoInfo) - for ifId := range as.IFIDs { - geo[common.IfIdType(ifId)] = g.GeoCoordinates(ifId) + for ifID := range as.IFIDs { + geo[common.IfIDType(ifID)] = g.GeoCoordinates(ifID) } linkType := make(staticinfo.LinkTypeInfo) - for ifId := range as.IFIDs { - linkType[common.IfIdType(ifId)] = g.LinkType(ifId, g.links[ifId]) + for ifID := range as.IFIDs { + linkType[common.IfIDType(ifID)] = g.LinkType(ifID, g.links[ifID]) } var internalHops staticinfo.InternalHopsInfo if outIF != 0 { - internalHops = make(map[common.IfIdType]uint32) + internalHops = make(map[common.IfIDType]uint32) if inIF != 0 { - internalHops[common.IfIdType(inIF)] = g.InternalHops(inIF, outIF) + internalHops[common.IfIDType(inIF)] = g.InternalHops(inIF, outIF) } - for ifId := range as.IFIDs { - if ifId != outIF && ifId != inIF { - internalHops[common.IfIdType(ifId)] = g.InternalHops(ifId, outIF) + for ifID := range as.IFIDs { + if ifID != outIF && ifID != inIF { + internalHops[common.IfIDType(ifID)] = g.InternalHops(ifID, outIF) } } } diff --git a/pkg/private/xtest/matchers/matchers.go b/pkg/private/xtest/matchers/matchers.go index e77a891584..995b235fe1 100644 --- a/pkg/private/xtest/matchers/matchers.go +++ b/pkg/private/xtest/matchers/matchers.go @@ -81,7 +81,7 @@ func (m *QueryParams) Matches(x interface{}) bool { sort.Slice(query.Intfs, func(i, j int) bool { return (query.Intfs[i].IA < query.Intfs[j].IA) || (query.Intfs[i].IA == query.Intfs[j].IA && - query.Intfs[i].IfId < query.Intfs[j].IfId) + query.Intfs[i].IfID < query.Intfs[j].IfID) }) sort.Slice(query.StartsAt, func(i, j int) bool { return query.StartsAt[i] < query.StartsAt[j] diff --git a/pkg/segment/extensions/staticinfo/staticinfo.go b/pkg/segment/extensions/staticinfo/staticinfo.go index 7e81c34c8b..83c7073151 100644 --- a/pkg/segment/extensions/staticinfo/staticinfo.go +++ b/pkg/segment/extensions/staticinfo/staticinfo.go @@ -39,20 +39,20 @@ type Extension struct { // LatencyInfo is the internal repesentation of `latency` in the // StaticInfoExtension. type LatencyInfo struct { - Intra map[common.IfIdType]time.Duration - Inter map[common.IfIdType]time.Duration + Intra map[common.IfIDType]time.Duration + Inter map[common.IfIDType]time.Duration } // BandwidthInfo is the internal repesentation of `bandwidth` in the // StaticInfoExtension. type BandwidthInfo struct { - Intra map[common.IfIdType]uint64 - Inter map[common.IfIdType]uint64 + Intra map[common.IfIDType]uint64 + Inter map[common.IfIDType]uint64 } // GeoInfo is the internal repesentation of `geo` in the // StaticInfoExtension. -type GeoInfo map[common.IfIdType]GeoCoordinates +type GeoInfo map[common.IfIDType]GeoCoordinates // GeoCoordinates is the internal repesentation of the GeoCoordinates in the // StaticInfoExtension. @@ -76,11 +76,11 @@ const ( // LinkTypeInfo is the internal representation of `link_type` in the // StaticInfoExtension. -type LinkTypeInfo map[common.IfIdType]LinkType +type LinkTypeInfo map[common.IfIDType]LinkType // InternalHopsInfo is the internal representation of `internal_hops` in the // StaticInfoExtension. -type InternalHopsInfo map[common.IfIdType]uint32 +type InternalHopsInfo map[common.IfIDType]uint32 // FromPB creates the staticinfo Extension from the protobuf representation. func FromPB(pb *cppb.StaticInfoExtension) *Extension { @@ -101,13 +101,13 @@ func latencyInfoFromPB(pb *cppb.LatencyInfo) LatencyInfo { if pb == nil || len(pb.Intra) == 0 && len(pb.Inter) == 0 { return LatencyInfo{} } - intra := make(map[common.IfIdType]time.Duration, len(pb.Intra)) - for ifId, v := range pb.Intra { - intra[common.IfIdType(ifId)] = time.Duration(v) * time.Microsecond + intra := make(map[common.IfIDType]time.Duration, len(pb.Intra)) + for ifID, v := range pb.Intra { + intra[common.IfIDType(ifID)] = time.Duration(v) * time.Microsecond } - inter := make(map[common.IfIdType]time.Duration, len(pb.Inter)) - for ifId, v := range pb.Inter { - inter[common.IfIdType(ifId)] = time.Duration(v) * time.Microsecond + inter := make(map[common.IfIDType]time.Duration, len(pb.Inter)) + for ifID, v := range pb.Inter { + inter[common.IfIDType(ifID)] = time.Duration(v) * time.Microsecond } return LatencyInfo{ Intra: intra, @@ -119,13 +119,13 @@ func bandwidthInfoFromPB(pb *cppb.BandwidthInfo) BandwidthInfo { if pb == nil || len(pb.Intra) == 0 && len(pb.Inter) == 0 { return BandwidthInfo{} } - intra := make(map[common.IfIdType]uint64, len(pb.Intra)) - for ifId, v := range pb.Intra { - intra[common.IfIdType(ifId)] = v + intra := make(map[common.IfIDType]uint64, len(pb.Intra)) + for ifID, v := range pb.Intra { + intra[common.IfIDType(ifID)] = v } - inter := make(map[common.IfIdType]uint64, len(pb.Inter)) - for ifId, v := range pb.Inter { - inter[common.IfIdType(ifId)] = v + inter := make(map[common.IfIDType]uint64, len(pb.Inter)) + for ifID, v := range pb.Inter { + inter[common.IfIDType(ifID)] = v } return BandwidthInfo{ Intra: intra, @@ -138,8 +138,8 @@ func geoInfoFromPB(pb map[uint64]*cppb.GeoCoordinates) GeoInfo { return nil } gi := make(GeoInfo, len(pb)) - for ifId, v := range pb { - gi[common.IfIdType(ifId)] = GeoCoordinates{ + for ifID, v := range pb { + gi[common.IfIDType(ifID)] = GeoCoordinates{ Latitude: v.Latitude, Longitude: v.Longitude, Address: v.Address, @@ -153,7 +153,7 @@ func linkTypeInfoFromPB(pb map[uint64]cppb.LinkType) LinkTypeInfo { return nil } lti := make(LinkTypeInfo, len(pb)) - for ifId, vpb := range pb { + for ifID, vpb := range pb { var v LinkType switch vpb { case cppb.LinkType_LINK_TYPE_UNSPECIFIED: @@ -167,7 +167,7 @@ func linkTypeInfoFromPB(pb map[uint64]cppb.LinkType) LinkTypeInfo { default: continue } - lti[common.IfIdType(ifId)] = v + lti[common.IfIDType(ifID)] = v } return lti } @@ -177,8 +177,8 @@ func internalHopsInfoFromPB(pb map[uint64]uint32) InternalHopsInfo { return nil } ihi := make(InternalHopsInfo, len(pb)) - for ifId, v := range pb { - ihi[common.IfIdType(ifId)] = v + for ifID, v := range pb { + ihi[common.IfIDType(ifID)] = v } return ihi } @@ -204,12 +204,12 @@ func latencyInfoToPB(li LatencyInfo) *cppb.LatencyInfo { return nil } intra := make(map[uint64]uint32, len(li.Intra)) - for ifId, v := range li.Intra { - intra[uint64(ifId)] = uint32(v.Microseconds()) + for ifID, v := range li.Intra { + intra[uint64(ifID)] = uint32(v.Microseconds()) } inter := make(map[uint64]uint32, len(li.Inter)) - for ifId, v := range li.Inter { - inter[uint64(ifId)] = uint32(v.Microseconds()) + for ifID, v := range li.Inter { + inter[uint64(ifID)] = uint32(v.Microseconds()) } return &cppb.LatencyInfo{ Intra: intra, @@ -222,12 +222,12 @@ func bandwidthInfoToPB(bwi BandwidthInfo) *cppb.BandwidthInfo { return nil } intra := make(map[uint64]uint64, len(bwi.Intra)) - for ifId, v := range bwi.Intra { - intra[uint64(ifId)] = v + for ifID, v := range bwi.Intra { + intra[uint64(ifID)] = v } inter := make(map[uint64]uint64, len(bwi.Inter)) - for ifId, v := range bwi.Inter { - inter[uint64(ifId)] = v + for ifID, v := range bwi.Inter { + inter[uint64(ifID)] = v } return &cppb.BandwidthInfo{ Intra: intra, @@ -240,8 +240,8 @@ func geoInfoToPB(gi GeoInfo) map[uint64]*cppb.GeoCoordinates { return nil } pb := make(map[uint64]*cppb.GeoCoordinates, len(gi)) - for ifId, v := range gi { - pb[uint64(ifId)] = &cppb.GeoCoordinates{ + for ifID, v := range gi { + pb[uint64(ifID)] = &cppb.GeoCoordinates{ Latitude: v.Latitude, Longitude: v.Longitude, Address: v.Address, @@ -255,7 +255,7 @@ func linkTypeInfoToPB(lti LinkTypeInfo) map[uint64]cppb.LinkType { return nil } pb := make(map[uint64]cppb.LinkType, len(lti)) - for ifId, v := range lti { + for ifID, v := range lti { var vpb cppb.LinkType switch v { case LinkTypeDirect: @@ -267,7 +267,7 @@ func linkTypeInfoToPB(lti LinkTypeInfo) map[uint64]cppb.LinkType { default: continue } - pb[uint64(ifId)] = vpb + pb[uint64(ifID)] = vpb } return pb } @@ -277,8 +277,8 @@ func internalHopsInfoToPB(ihi InternalHopsInfo) map[uint64]uint32 { return nil } pb := make(map[uint64]uint32, len(ihi)) - for ifId, v := range ihi { - pb[uint64(ifId)] = v + for ifID, v := range ihi { + pb[uint64(ifID)] = v } return pb } diff --git a/pkg/segment/extensions/staticinfo/staticinfo_test.go b/pkg/segment/extensions/staticinfo/staticinfo_test.go index ef62e4e9dc..42c9bff6bf 100644 --- a/pkg/segment/extensions/staticinfo/staticinfo_test.go +++ b/pkg/segment/extensions/staticinfo/staticinfo_test.go @@ -34,22 +34,22 @@ func TestRoundtripStaticInfoExtension(t *testing.T) { }, "latency": { Latency: staticinfo.LatencyInfo{ - Intra: map[common.IfIdType]time.Duration{ + Intra: map[common.IfIDType]time.Duration{ 10: 10 * time.Millisecond, 11: 11 * time.Millisecond, }, - Inter: map[common.IfIdType]time.Duration{ + Inter: map[common.IfIDType]time.Duration{ 11: 111 * time.Millisecond, }, }, }, "bandwidth": { Bandwidth: staticinfo.BandwidthInfo{ - Intra: map[common.IfIdType]uint64{ + Intra: map[common.IfIDType]uint64{ 10: 1, // 1Kbit/s 11: 10_000_000_000, // 10Tbit/s }, - Inter: map[common.IfIdType]uint64{ + Inter: map[common.IfIDType]uint64{ 11: 2_000_000, }, }, @@ -71,7 +71,7 @@ func TestRoundtripStaticInfoExtension(t *testing.T) { }, }, "internal_hops": { - InternalHops: map[common.IfIdType]uint32{ + InternalHops: map[common.IfIDType]uint32{ 10: 2, 11: 3, }, diff --git a/pkg/slayers/scmp_msg.go b/pkg/slayers/scmp_msg.go index 287b5e0f73..5969a3cfe7 100644 --- a/pkg/slayers/scmp_msg.go +++ b/pkg/slayers/scmp_msg.go @@ -41,7 +41,7 @@ const scmpRawInterfaceLen = 8 type SCMPExternalInterfaceDown struct { BaseLayer IA addr.IA - IfId uint64 + IfID uint64 } // LayerType returns LayerTypeSCMPExternalInterfaceDown. @@ -66,7 +66,7 @@ func (i *SCMPExternalInterfaceDown) DecodeFromBytes(data []byte, offset := 0 i.IA = addr.IA(binary.BigEndian.Uint64(data[offset:])) offset += addr.IABytes - i.IfId = binary.BigEndian.Uint64(data[offset : offset+scmpRawInterfaceLen]) + i.IfID = binary.BigEndian.Uint64(data[offset : offset+scmpRawInterfaceLen]) offset += scmpRawInterfaceLen i.BaseLayer = BaseLayer{ Contents: data[:offset], @@ -87,7 +87,7 @@ func (i *SCMPExternalInterfaceDown) SerializeTo(b gopacket.SerializeBuffer, offset := 0 binary.BigEndian.PutUint64(buf[offset:], uint64(i.IA)) offset += addr.IABytes - binary.BigEndian.PutUint64(buf[offset:offset+scmpRawInterfaceLen], i.IfId) + binary.BigEndian.PutUint64(buf[offset:offset+scmpRawInterfaceLen], i.IfID) return nil } diff --git a/pkg/slayers/scmp_msg_test.go b/pkg/slayers/scmp_msg_test.go index af50717873..5b7976e835 100644 --- a/pkg/slayers/scmp_msg_test.go +++ b/pkg/slayers/scmp_msg_test.go @@ -40,7 +40,7 @@ func TestSCMPExternalInterfaceDownDecodeFromBytes(t *testing.T) { }, bytes.Repeat([]byte{0xff}, 10)...), decoded: &slayers.SCMPExternalInterfaceDown{ IA: addr.MustParseIA("1-ff00:0:111"), - IfId: uint64(5), + IfID: uint64(5), }, assertFunc: assert.NoError, }, @@ -83,7 +83,7 @@ func TestSCMPExternalInterfaceDownSerializeTo(t *testing.T) { }, bytes.Repeat([]byte{0xff}, 10)...), decoded: &slayers.SCMPExternalInterfaceDown{ IA: addr.MustParseIA("1-ff00:0:111"), - IfId: uint64(5), + IfID: uint64(5), }, assertFunc: assert.NoError, }, diff --git a/pkg/slayers/scmp_test.go b/pkg/slayers/scmp_test.go index 39cf4a5f4b..32638c831f 100644 --- a/pkg/slayers/scmp_test.go +++ b/pkg/slayers/scmp_test.go @@ -314,7 +314,7 @@ func TestSCMP(t *testing.T) { Payload: bytes.Repeat([]byte{0xff}, 15), }, IA: addr.MustParseIA("1-ff00:0:111"), - IfId: uint64(5), + IfID: uint64(5), }, gopacket.Payload(bytes.Repeat([]byte{0xff}, 15)), }, diff --git a/pkg/slayers/slayers_test.go b/pkg/slayers/slayers_test.go index 44dea063b0..34dcffc641 100644 --- a/pkg/slayers/slayers_test.go +++ b/pkg/slayers/slayers_test.go @@ -83,7 +83,7 @@ func TestSCIONSCMP(t *testing.T) { }, &slayers.SCMPExternalInterfaceDown{ IA: addr.MustParseIA("1-ff00:0:111"), - IfId: uint64(5), + IfID: uint64(5), }, gopacket.Payload(bytes.Repeat([]byte{0xff}, 18)), }, diff --git a/pkg/snet/addrutil/addrutil.go b/pkg/snet/addrutil/addrutil.go index ea4e87f7fa..aa6e65c270 100644 --- a/pkg/snet/addrutil/addrutil.go +++ b/pkg/snet/addrutil/addrutil.go @@ -83,10 +83,10 @@ func (p Pather) GetPath(svc addr.SVC, ps *seg.PathSegment) (*snet.SVCAddr, error if err != nil { return nil, serrors.WrapStr("serializing path", err) } - ifId := dec.HopFields[0].ConsIngress - nextHop := p.NextHopper.UnderlayNextHop(ifId) + ifID := dec.HopFields[0].ConsIngress + nextHop := p.NextHopper.UnderlayNextHop(ifID) if nextHop == nil { - return nil, serrors.New("first-hop border router not found", "intf_id", ifId) + return nil, serrors.New("first-hop border router not found", "intf_id", ifID) } return &snet.SVCAddr{ IA: ps.FirstIA(), diff --git a/pkg/snet/packet.go b/pkg/snet/packet.go index b8babb0607..31f7592398 100644 --- a/pkg/snet/packet.go +++ b/pkg/snet/packet.go @@ -145,7 +145,7 @@ func (m SCMPExternalInterfaceDown) toLayers(scn *slayers.SCION) []gopacket.Seria return toLayers(m, scn, &slayers.SCMPExternalInterfaceDown{ IA: m.IA, - IfId: m.Interface, + IfID: m.Interface, }, m.Payload, ) @@ -472,7 +472,7 @@ func (p *Packet) Decode() error { } p.Payload = SCMPExternalInterfaceDown{ IA: v.IA, - Interface: v.IfId, + Interface: v.IfID, Payload: v.Payload, } case slayers.SCMPTypeInternalConnectivityDown: diff --git a/pkg/snet/packet_conn.go b/pkg/snet/packet_conn.go index b040b6912d..ef2a159f03 100644 --- a/pkg/snet/packet_conn.go +++ b/pkg/snet/packet_conn.go @@ -282,11 +282,11 @@ func (c *SCIONPacketConn) lastHop(p *Packet) (*net.UDPAddr, error) { if err := path.DecodeFromBytes(rpath.Raw); err != nil { return nil, err } - ifId := path.SecondHop.ConsIngress + ifID := path.SecondHop.ConsIngress if !path.Info.ConsDir { - ifId = path.SecondHop.ConsEgress + ifID = path.SecondHop.ConsEgress } - return c.interfaceMap.get(ifId) + return c.interfaceMap.get(ifID) case epic.PathType: var path epic.Path if err := path.DecodeFromBytes(rpath.Raw); err != nil { @@ -300,11 +300,11 @@ func (c *SCIONPacketConn) lastHop(p *Packet) (*net.UDPAddr, error) { if err != nil { return nil, err } - ifId := hf.ConsIngress + ifID := hf.ConsIngress if !infoField.ConsDir { - ifId = hf.ConsEgress + ifID = hf.ConsEgress } - return c.interfaceMap.get(ifId) + return c.interfaceMap.get(ifID) case scion.PathType: var path scion.Raw if err := path.DecodeFromBytes(rpath.Raw); err != nil { @@ -318,11 +318,11 @@ func (c *SCIONPacketConn) lastHop(p *Packet) (*net.UDPAddr, error) { if err != nil { return nil, err } - ifId := hf.ConsIngress + ifID := hf.ConsIngress if !infoField.ConsDir { - ifId = hf.ConsEgress + ifID = hf.ConsEgress } - return c.interfaceMap.get(ifId) + return c.interfaceMap.get(ifID) default: return nil, serrors.New("unknown path type", "type", rpath.PathType.String()) } diff --git a/pkg/snet/path.go b/pkg/snet/path.go index fc06e33c76..b6c48df30f 100644 --- a/pkg/snet/path.go +++ b/pkg/snet/path.go @@ -70,7 +70,7 @@ type Path 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 } diff --git a/pkg/snet/scmp.go b/pkg/snet/scmp.go index 7f11a04f06..e759d057c0 100644 --- a/pkg/snet/scmp.go +++ b/pkg/snet/scmp.go @@ -73,7 +73,7 @@ func (h DefaultSCMPHandler) Handle(pkt *Packet) error { case slayers.SCMPTypeExternalInterfaceDown: msg := pkt.Payload.(SCMPExternalInterfaceDown) return h.handleSCMPRev(typeCode, &path_mgmt.RevInfo{ - IfId: common.IfIdType(msg.Interface), + IfID: common.IfIDType(msg.Interface), RawIsdas: msg.IA, RawTimestamp: util.TimeToSecs(time.Now()), RawTTL: 10, @@ -81,7 +81,7 @@ func (h DefaultSCMPHandler) Handle(pkt *Packet) error { case slayers.SCMPTypeInternalConnectivityDown: msg := pkt.Payload.(SCMPInternalConnectivityDown) return h.handleSCMPRev(typeCode, &path_mgmt.RevInfo{ - IfId: common.IfIdType(msg.Egress), + IfID: common.IfIDType(msg.Egress), RawIsdas: msg.IA, RawTimestamp: util.TimeToSecs(time.Now()), RawTTL: 10, diff --git a/private/path/combinator/combinator_test.go b/private/path/combinator/combinator_test.go index 5fa8797887..15bb1b6d4e 100644 --- a/private/path/combinator/combinator_test.go +++ b/private/path/combinator/combinator_test.go @@ -547,20 +547,20 @@ func TestFilterDuplicates(t *testing.T) { // These look somewhat valid, but that doesn't matter at all -- we only look // at the fingerprint anyway. path0 := []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIdType(10)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIdType(10)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(10)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(10)}, } path1 := []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIdType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIdType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIdType(12)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIdType(12)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(12)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(12)}, } path2 := []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIdType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIdType(11)}, - {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIdType(22)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIdType(22)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(11)}, + {IA: addr.MustParseIA("1-ff00:0:112"), ID: common.IfIDType(22)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(22)}, } // Define two expiry times for the paths: paths with latest expiry will be kept diff --git a/private/path/combinator/graph.go b/private/path/combinator/graph.go index abbd4ba62d..51736715b7 100644 --- a/private/path/combinator/graph.go +++ b/private/path/combinator/graph.go @@ -146,8 +146,8 @@ func (g *dmg) traverseSegment(segment *inputSegment) { } for peerEntryIdx, peer := range asEntries[asEntryIndex].PeerEntries { - ingress := common.IfIdType(peer.HopField.ConsIngress) - remote := common.IfIdType(peer.PeerInterface) + ingress := common.IfIDType(peer.HopField.ConsIngress) + remote := common.IfIDType(peer.PeerInterface) tuples = append(tuples, Tuple{ Src: vertexFromIA(pinnedIA), Dst: vertexFromPeering(currentIA, ingress, peer.Peer, remote), @@ -259,17 +259,17 @@ func (s *inputSegment) IsDownSeg() bool { type vertex struct { IA addr.IA UpIA addr.IA - UpIFID common.IfIdType + UpIFID common.IfIDType DownIA addr.IA - DownIFID common.IfIdType + DownIFID common.IfIDType } func vertexFromIA(ia addr.IA) vertex { return vertex{IA: ia} } -func vertexFromPeering(upIA addr.IA, upIFID common.IfIdType, - downIA addr.IA, downIFID common.IfIdType) vertex { +func vertexFromPeering(upIA addr.IA, upIFID common.IfIDType, + downIA addr.IA, downIFID common.IfIDType) vertex { return vertex{UpIA: upIA, UpIFID: upIFID, DownIA: downIA, DownIFID: downIFID} } @@ -365,14 +365,14 @@ func (solution *pathSolution) Path() Path { if hopField.ConsEgress != 0 { intfs = append(intfs, snet.PathInterface{ IA: asEntry.Local, - ID: common.IfIdType(hopField.ConsEgress), + 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, snet.PathInterface{ IA: asEntry.Local, - ID: common.IfIdType(hopField.ConsIngress), + ID: common.IfIDType(hopField.ConsIngress), }) } hops = append(hops, hopField) diff --git a/private/path/combinator/staticinfo_accumulator.go b/private/path/combinator/staticinfo_accumulator.go index 93b838b81f..383bead4e0 100644 --- a/private/path/combinator/staticinfo_accumulator.go +++ b/private/path/combinator/staticinfo_accumulator.go @@ -85,17 +85,17 @@ func collectLatency(p pathInfo) []time.Duration { } egIF := snet.PathInterface{ IA: asEntry.Local, - ID: common.IfIdType(asEntry.HopEntry.HopField.ConsEgress), + ID: common.IfIDType(asEntry.HopEntry.HopField.ConsEgress), } latency := staticInfo.Latency // Egress to sibling child, core or peer interfaces - for ifId, v := range latency.Intra { - otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifId} + for ifID, v := range latency.Intra { + otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopLatency(hopLatencies, egIF, otherIF, v) } // Local peer to remote peer interface - for ifId, v := range latency.Inter { - localIF := snet.PathInterface{IA: asEntry.Local, ID: ifId} + for ifID, v := range latency.Inter { + localIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopLatency(hopLatencies, localIF, p.RemoteIF[localIF], v) } } @@ -140,17 +140,17 @@ func collectBandwidth(p pathInfo) []uint64 { } egIF := snet.PathInterface{ IA: asEntry.Local, - ID: common.IfIdType(asEntry.HopEntry.HopField.ConsEgress), + ID: common.IfIDType(asEntry.HopEntry.HopField.ConsEgress), } bandwidth := staticInfo.Bandwidth // Egress to other local interfaces - for ifId, v := range bandwidth.Intra { - otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifId} + for ifID, v := range bandwidth.Intra { + otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopBandwidth(hopBandwidths, egIF, otherIF, v) } // Local peer to remote peer interface - for ifId, v := range bandwidth.Inter { - localIF := snet.PathInterface{IA: asEntry.Local, ID: ifId} + for ifID, v := range bandwidth.Inter { + localIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopBandwidth(hopBandwidths, localIF, p.RemoteIF[localIF], v) } } @@ -187,8 +187,8 @@ func collectGeo(p pathInfo) []snet.GeoCoordinates { if staticInfo == nil { continue } - for ifId, v := range staticInfo.Geo { - iface := snet.PathInterface{IA: asEntry.Local, ID: ifId} + for ifID, v := range staticInfo.Geo { + iface := snet.PathInterface{IA: asEntry.Local, ID: ifID} ifaceGeos[iface] = snet.GeoCoordinates{ Longitude: v.Longitude, Latitude: v.Latitude, @@ -213,9 +213,9 @@ func collectLinkType(p pathInfo) []snet.LinkType { if staticInfo == nil { continue } - for ifId, rawLinkType := range staticInfo.LinkType { + for ifID, rawLinkType := range staticInfo.LinkType { linkType := convertLinkType(rawLinkType) - localIF := snet.PathInterface{IA: asEntry.Local, ID: ifId} + localIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} hop := makeHopKey(localIF, p.RemoteIF[localIF]) if prevLinkType, duplicate := hopLinkTypes[hop]; duplicate { // Handle conflicts by using LinkTypeUnset @@ -265,11 +265,11 @@ func collectInternalHops(p pathInfo) []uint32 { } egIF := snet.PathInterface{ IA: asEntry.Local, - ID: common.IfIdType(asEntry.HopEntry.HopField.ConsEgress), + ID: common.IfIDType(asEntry.HopEntry.HopField.ConsEgress), } internalHops := staticInfo.InternalHops - for ifId, v := range internalHops { - otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifId} + for ifID, v := range internalHops { + otherIF := snet.PathInterface{IA: asEntry.Local, ID: ifID} addHopInternalHops(hopInternalHops, egIF, otherIF, v) } } diff --git a/private/path/combinator/staticinfo_accumulator_test.go b/private/path/combinator/staticinfo_accumulator_test.go index d430b7e7b2..1bfe056356 100644 --- a/private/path/combinator/staticinfo_accumulator_test.go +++ b/private/path/combinator/staticinfo_accumulator_test.go @@ -42,12 +42,12 @@ func TestStaticinfo(t *testing.T) { { Name: "#0 simple up-core-down", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIdType(graph.If_131_X_130_A)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIdType(graph.If_130_A_131_X)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIdType(graph.If_130_B_120_A)}, - {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IfIdType(graph.If_120_A_130_B)}, - {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IfIdType(graph.If_120_X_111_B)}, - {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIdType(graph.If_111_B_120_X)}, + {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIDType(graph.If_131_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_131_X)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_B_120_A)}, + {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IfIDType(graph.If_120_A_130_B)}, + {IA: addr.MustParseIA("1-ff00:0:120"), ID: common.IfIDType(graph.If_120_X_111_B)}, + {IA: addr.MustParseIA("1-ff00:0:111"), ID: common.IfIDType(graph.If_111_B_120_X)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_130_A_131_X}, @@ -58,10 +58,10 @@ func TestStaticinfo(t *testing.T) { { Name: "#1 simple up-core", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIdType(graph.If_131_X_130_A)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIdType(graph.If_130_A_131_X)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIdType(graph.If_130_A_110_X)}, - {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIdType(graph.If_110_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIDType(graph.If_131_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_131_X)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_110_X)}, + {IA: addr.MustParseIA("1-ff00:0:110"), ID: common.IfIDType(graph.If_110_X_130_A)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_130_A_131_X}, @@ -72,8 +72,8 @@ func TestStaticinfo(t *testing.T) { { Name: "#2 simple up only", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIdType(graph.If_131_X_130_A)}, - {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIdType(graph.If_130_A_131_X)}, + {IA: addr.MustParseIA("1-ff00:0:131"), ID: common.IfIDType(graph.If_131_X_130_A)}, + {IA: addr.MustParseIA("1-ff00:0:130"), ID: common.IfIDType(graph.If_130_A_131_X)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_130_A_131_X}, @@ -84,10 +84,10 @@ func TestStaticinfo(t *testing.T) { { Name: "#14 shortcut, common upstream", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IfIdType(graph.If_212_X_211_A1)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIdType(graph.If_211_A1_212_X)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIdType(graph.If_211_A_222_X)}, - {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IfIdType(graph.If_222_X_211_A)}, + {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IfIDType(graph.If_212_X_211_A1)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A1_212_X)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A_222_X)}, + {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IfIDType(graph.If_222_X_211_A)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_210_X1_211_A, graph.If_211_A1_212_X}, @@ -98,12 +98,12 @@ func TestStaticinfo(t *testing.T) { { Name: "#15 go through peer", Path: []snet.PathInterface{ - {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IfIdType(graph.If_212_X_211_A1)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIdType(graph.If_211_A1_212_X)}, - {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIdType(graph.If_211_A_221_X)}, - {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IfIdType(graph.If_221_X_211_A)}, - {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IfIdType(graph.If_221_X_222_X)}, - {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IfIdType(graph.If_222_X_221_X)}, + {IA: addr.MustParseIA("2-ff00:0:212"), ID: common.IfIDType(graph.If_212_X_211_A1)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A1_212_X)}, + {IA: addr.MustParseIA("2-ff00:0:211"), ID: common.IfIDType(graph.If_211_A_221_X)}, + {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IfIDType(graph.If_221_X_211_A)}, + {IA: addr.MustParseIA("2-ff00:0:221"), ID: common.IfIDType(graph.If_221_X_222_X)}, + {IA: addr.MustParseIA("2-ff00:0:222"), ID: common.IfIDType(graph.If_222_X_221_X)}, }, ASEntries: concatBeaconASEntries(g, []uint16{graph.If_210_X1_211_A, graph.If_211_A1_212_X}, @@ -228,11 +228,11 @@ func checkNotes(t *testing.T, g *graph.Graph, path []snet.PathInterface, notes [ } func concatBeaconASEntries(g *graph.Graph, - upIfIds, coreIfIds, downIfIds []uint16) []seg.ASEntry { + upIfIDs, coreIfIDs, downIfIDs []uint16) []seg.ASEntry { r := []seg.ASEntry{} - for _, ifIds := range [][]uint16{upIfIds, coreIfIds, downIfIds} { - seg := g.BeaconWithStaticInfo(ifIds) + for _, ifIDs := range [][]uint16{upIfIDs, coreIfIDs, downIfIDs} { + seg := g.BeaconWithStaticInfo(ifIDs) if seg != nil { r = append(r, seg.ASEntries...) } diff --git a/private/path/pathpol/acl_test.go b/private/path/pathpol/acl_test.go index d9fc228f6f..1bdb412832 100644 --- a/private/path/pathpol/acl_test.go +++ b/private/path/pathpol/acl_test.go @@ -113,7 +113,7 @@ func TestACLEntryLoadFromString(t *testing.T) { String: "+ 0", ACLEntry: ACLEntry{ Action: Allow, - Rule: &HopPredicate{IfIds: []common.IfIdType{0}}, + Rule: &HopPredicate{IfIDs: []common.IfIDType{0}}, }, ErrorAssertion: assert.NoError, }, @@ -121,7 +121,7 @@ func TestACLEntryLoadFromString(t *testing.T) { String: "+ 1-2#3", ACLEntry: ACLEntry{ Action: Allow, - Rule: &HopPredicate{ISD: 1, AS: 2, IfIds: []common.IfIdType{3}}, + Rule: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{3}}, }, ErrorAssertion: assert.NoError, }, @@ -134,7 +134,7 @@ func TestACLEntryLoadFromString(t *testing.T) { String: "- 0", ACLEntry: ACLEntry{ Action: Deny, - Rule: &HopPredicate{IfIds: []common.IfIdType{0}}, + Rule: &HopPredicate{IfIDs: []common.IfIDType{0}}, }, ErrorAssertion: assert.NoError, }, @@ -161,7 +161,7 @@ func TestACLEntryLoadFromString(t *testing.T) { func TestACLEntryString(t *testing.T) { aclEntryString := "+ 0-0#0" - aclEntry := &ACLEntry{Action: true, Rule: &HopPredicate{IfIds: []common.IfIdType{0}}} + aclEntry := &ACLEntry{Action: true, Rule: &HopPredicate{IfIDs: []common.IfIDType{0}}} assert.Equal(t, aclEntryString, aclEntry.String()) } diff --git a/private/path/pathpol/hop_pred.go b/private/path/pathpol/hop_pred.go index 718d214a75..d1159b071c 100644 --- a/private/path/pathpol/hop_pred.go +++ b/private/path/pathpol/hop_pred.go @@ -32,11 +32,11 @@ import ( type HopPredicate struct { ISD addr.ISD AS addr.AS - IfIds []common.IfIdType + IfIDs []common.IfIDType } func NewHopPredicate() *HopPredicate { - return &HopPredicate{IfIds: make([]common.IfIdType, 1)} + return &HopPredicate{IfIDs: make([]common.IfIDType, 1)} } func HopPredicateFromString(str string) (*HopPredicate, error) { @@ -44,7 +44,7 @@ func HopPredicateFromString(str string) (*HopPredicate, error) { if err = validateHopPredStr(str); err != nil { return &HopPredicate{}, err } - var ifIds = make([]common.IfIdType, 1) + var ifIDs = make([]common.IfIDType, 1) // Parse ISD dashParts := strings.Split(str, "-") isd, err := addr.ParseISD(dashParts[0]) @@ -52,7 +52,7 @@ func HopPredicateFromString(str string) (*HopPredicate, error) { return &HopPredicate{}, serrors.WrapStr("Failed to parse ISD", err, "value", str) } if len(dashParts) == 1 { - return &HopPredicate{ISD: isd, IfIds: ifIds}, nil + return &HopPredicate{ISD: isd, IfIDs: ifIDs}, nil } // Parse AS if present hashParts := strings.Split(dashParts[1], "#") @@ -61,26 +61,26 @@ func HopPredicateFromString(str string) (*HopPredicate, error) { return &HopPredicate{}, serrors.WrapStr("Failed to parse AS", err, "value", str) } if len(hashParts) == 1 { - return &HopPredicate{ISD: isd, AS: as, IfIds: ifIds}, nil + return &HopPredicate{ISD: isd, AS: as, IfIDs: ifIDs}, nil } - // Parse IfIds if present + // Parse IfIDs if present commaParts := strings.Split(hashParts[1], ",") - if ifIds[0], err = parseIfId(commaParts[0]); err != nil { - return &HopPredicate{}, serrors.WrapStr("Failed to parse ifIds", err, "value", str) + if ifIDs[0], err = parseIfID(commaParts[0]); err != nil { + return &HopPredicate{}, serrors.WrapStr("Failed to parse ifIDs", err, "value", str) } if len(commaParts) == 2 { - ifId, err := parseIfId(commaParts[1]) + ifID, err := parseIfID(commaParts[1]) if err != nil { - return &HopPredicate{}, serrors.WrapStr("Failed to parse ifIds", err, "value", str) + return &HopPredicate{}, serrors.WrapStr("Failed to parse ifIDs", err, "value", str) } - ifIds = append(ifIds, ifId) + ifIDs = append(ifIDs, ifID) } - // IfId cannot be set when the AS is a wildcard - if as == 0 && (ifIds[0] != 0 || (len(ifIds) > 1 && ifIds[1] != 0)) { - return &HopPredicate{}, serrors.New("Failed to parse hop predicate, IfIds must be 0", + // IfID cannot be set when the AS is a wildcard + if as == 0 && (ifIDs[0] != 0 || (len(ifIDs) > 1 && ifIDs[1] != 0)) { + return &HopPredicate{}, serrors.New("Failed to parse hop predicate, IfIDs must be 0", "value", str) } - return &HopPredicate{ISD: isd, AS: as, IfIds: ifIds}, nil + return &HopPredicate{ISD: isd, AS: as, IfIDs: ifIDs}, nil } // pathIFMatch takes a PathInterface and a bool indicating if the ingress @@ -96,10 +96,10 @@ func (hp *HopPredicate) pathIFMatch(pi snet.PathInterface, in bool) bool { // the IF index is set to 1 if // - there are two IFIDs and // - the ingress interface should not be matched - if len(hp.IfIds) == 2 && !in { + 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 @@ -115,8 +115,8 @@ func (hp *HopPredicate) matchesAll() bool { func (hp HopPredicate) String() string { var s []string - for _, ifId := range hp.IfIds { - s = append(s, ifId.String()) + for _, ifID := range hp.IfIDs { + s = append(s, ifID.String()) } return fmt.Sprintf("%d-%s#%s", hp.ISD, hp.AS, strings.Join(s, ",")) } @@ -136,12 +136,12 @@ func (hp *HopPredicate) UnmarshalJSON(b []byte) error { return err } -func parseIfId(str string) (common.IfIdType, error) { - ifId, err := strconv.ParseUint(str, 10, 64) +func parseIfID(str string) (common.IfIDType, error) { + ifID, err := strconv.ParseUint(str, 10, 64) if err != nil { return 0, err } - return common.IfIdType(ifId), nil + return common.IfIDType(ifID), nil } // validateHopPredStr checks if str has the correct amount of delimiters diff --git a/private/path/pathpol/hop_pred_test.go b/private/path/pathpol/hop_pred_test.go index 84c3835c04..fa2cd76e70 100644 --- a/private/path/pathpol/hop_pred_test.go +++ b/private/path/pathpol/hop_pred_test.go @@ -32,22 +32,22 @@ func TestNewHopPredicate(t *testing.T) { }{ "ISD wildcard": { In: "0", - HP: &HopPredicate{ISD: 0, AS: 0, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 0, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "AS, IF wildcard omitted": { In: "1", - HP: &HopPredicate{ISD: 1, AS: 0, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "IF wildcard omitted": { In: "1-0", - HP: &HopPredicate{ISD: 1, AS: 0, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "basic wildcard": { In: "1-0#0", - HP: &HopPredicate{ISD: 1, AS: 0, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 1, AS: 0, IfIDs: []common.IfIDType{0}}, Valid: true, }, "AS wildcard, interface set": { @@ -56,30 +56,30 @@ func TestNewHopPredicate(t *testing.T) { }, "ISD wildcard, AS set": { In: "0-1#0", - HP: &HopPredicate{ISD: 0, AS: 1, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IfIDType{0}}, Valid: true, }, "ISD wildcard, AS set, interface set": { In: "0-1#2", - HP: &HopPredicate{ISD: 0, AS: 1, IfIds: []common.IfIdType{2}}, + HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IfIDType{2}}, Valid: true, }, "ISD wildcard, AS set and interface omitted": { In: "0-1", - HP: &HopPredicate{ISD: 0, AS: 1, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 0, AS: 1, IfIDs: []common.IfIDType{0}}, Valid: true, }, "IF wildcard omitted, AS set": { In: "1-2", - HP: &HopPredicate{ISD: 1, AS: 2, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{0}}, Valid: true, }, - "two IfIds": { + "two IfIDs": { In: "1-2#3,4", - HP: &HopPredicate{ISD: 1, AS: 2, IfIds: []common.IfIdType{3, 4}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{3, 4}}, Valid: true, }, - "three IfIds": { + "three IfIDs": { In: "1-2#3,4,5", Valid: false, }, @@ -140,13 +140,13 @@ func TestJsonConversion(t *testing.T) { HP *HopPredicate }{ "Normal predicate": { - HP: &HopPredicate{ISD: 1, AS: 2, IfIds: []common.IfIdType{1, 2}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{1, 2}}, }, "wildcard predicate": { - HP: &HopPredicate{ISD: 1, AS: 2, IfIds: []common.IfIdType{0}}, + HP: &HopPredicate{ISD: 1, AS: 2, IfIDs: []common.IfIDType{0}}, }, - "only ifIds": { - HP: &HopPredicate{IfIds: []common.IfIdType{0}}, + "only ifIDs": { + HP: &HopPredicate{IfIDs: []common.IfIDType{0}}, }, } for name, test := range tests { diff --git a/private/path/pathpol/policy_test.go b/private/path/pathpol/policy_test.go index 82f519dbea..5e07e38508 100644 --- a/private/path/pathpol/policy_test.go +++ b/private/path/pathpol/policy_test.go @@ -642,13 +642,13 @@ func NewPathProvider(ctrl *gomock.Controller) PathProvider { func (p PathProvider) GetPaths(src, dst addr.IA) []snet.Path { result := []snet.Path{} paths := p.g.GetPaths(src.String(), dst.String()) - for _, ifIds := range paths { - pathIntfs := make([]snet.PathInterface, 0, len(ifIds)) - for _, ifId := range ifIds { - ia := p.g.GetParent(ifId) + for _, ifIDs := range paths { + pathIntfs := make([]snet.PathInterface, 0, len(ifIDs)) + for _, ifID := range ifIDs { + ia := p.g.GetParent(ifID) pathIntfs = append(pathIntfs, snet.PathInterface{ IA: ia, - ID: common.IfIdType(ifId), + ID: common.IfIDType(ifID), }) } var srcIA, dstIA addr.IA diff --git a/private/path/pathpol/sequence.go b/private/path/pathpol/sequence.go index 0c832b48c6..011bb2e088 100644 --- a/private/path/pathpol/sequence.go +++ b/private/path/pathpol/sequence.go @@ -293,7 +293,7 @@ func (l *sequenceListener) ExitIFace(c *sequence.IFaceContext) { l.push(re) } -func hop(ia addr.IA, ingress, egress common.IfIdType) string { +func hop(ia addr.IA, ingress, egress common.IfIDType) string { return fmt.Sprintf("%s#%d,%d", ia, ingress, egress) } diff --git a/private/pathdb/query/query.go b/private/pathdb/query/query.go index 61e9071639..d8013fb606 100644 --- a/private/pathdb/query/query.go +++ b/private/pathdb/query/query.go @@ -26,7 +26,7 @@ import ( type IntfSpec struct { IA addr.IA - IfId common.IfIdType + IfID common.IfIDType } type Params struct { diff --git a/private/revcache/memrevcache/memrevcache.go b/private/revcache/memrevcache/memrevcache.go index 4366f4bc35..5f64a0520c 100644 --- a/private/revcache/memrevcache/memrevcache.go +++ b/private/revcache/memrevcache/memrevcache.go @@ -84,7 +84,7 @@ func (c *memRevCache) Insert(_ context.Context, rev *path_mgmt.RevInfo) (bool, e if ttl <= 0 { return false, nil } - k := revcache.NewKey(rev.IA(), rev.IfId) + k := revcache.NewKey(rev.IA(), rev.IfID) key := k.String() val, ok := c.get(key) if !ok { diff --git a/private/revcache/memrevcache/memrevcache_test.go b/private/revcache/memrevcache/memrevcache_test.go index d7e0e5c79b..1ee2ff5095 100644 --- a/private/revcache/memrevcache/memrevcache_test.go +++ b/private/revcache/memrevcache/memrevcache_test.go @@ -37,7 +37,7 @@ func (c *testRevCache) InsertExpired(t *testing.T, _ context.Context, if ttl >= 0 { panic("Should only be used for expired elements") } - k := revcache.NewKey(rev.IA(), rev.IfId) + k := revcache.NewKey(rev.IA(), rev.IfID) key := k.String() c.c.Set(key, rev, time.Microsecond) // Unfortunately inserting with negative TTL makes entries available forever, diff --git a/private/revcache/revcache.go b/private/revcache/revcache.go index d2cd8d8ef7..0e8f061080 100644 --- a/private/revcache/revcache.go +++ b/private/revcache/revcache.go @@ -28,27 +28,27 @@ import ( // Key denotes the key for the revocation cache. type Key struct { IA addr.IA - IfId common.IfIdType + IfID common.IfIDType } // NewKey creates a new key for the revocation cache. -func NewKey(ia addr.IA, ifId common.IfIdType) Key { +func NewKey(ia addr.IA, ifID common.IfIDType) Key { return Key{ IA: ia, - IfId: ifId, + IfID: ifID, } } func (k Key) String() string { - return fmt.Sprintf("%s#%s", k.IA, k.IfId) + return fmt.Sprintf("%s#%s", k.IA, k.IfID) } // KeySet is a set of keys. type KeySet map[Key]struct{} // SingleKey is a convenience function to return a KeySet with a single key. -func SingleKey(ia addr.IA, ifId common.IfIdType) KeySet { - return KeySet{Key{IA: ia, IfId: ifId}: {}} +func SingleKey(ia addr.IA, ifID common.IfIDType) KeySet { + return KeySet{Key{IA: ia, IfID: ifID}: {}} } // RevOrErr is either a revocation or an error. diff --git a/private/revcache/revcachetest/revcachetest.go b/private/revcache/revcachetest/revcachetest.go index f7ce269d16..76e02c2044 100644 --- a/private/revcache/revcachetest/revcachetest.go +++ b/private/revcache/revcachetest/revcachetest.go @@ -34,8 +34,8 @@ import ( var ( ia110 = addr.MustParseIA("1-ff00:0:110") ia120 = addr.MustParseIA("1-ff00:0:120") - ifId15 = common.IfIdType(15) - ifId19 = common.IfIdType(19) + ifID15 = common.IfIDType(15) + ifID19 = common.IfIDType(19) TimeOut = 5 * time.Second ) @@ -78,13 +78,13 @@ func TestRevCache(t *testing.T, revCache TestableRevCache) { } func testInsertGet(t *testing.T, revCache TestableRevCache) { - rev := defaultRevInfo(ia110, ifId15) + rev := defaultRevInfo(ia110, ifID15) ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() inserted, err := revCache.Insert(ctx, rev) assert.True(t, inserted, "Insert should return true for a new entry") assert.NoError(t, err, "Insert a new entry should not err") - key1 := revcache.NewKey(ia110, ifId15) + key1 := revcache.NewKey(ia110, ifID15) revs, err := revCache.Get(ctx, revcache.KeySet{key1: {}}) assert.NoError(t, err, "Get should not err for existing entry") assert.NotEmpty(t, revs, "Get should return existing entry") @@ -92,16 +92,16 @@ func testInsertGet(t *testing.T, revCache TestableRevCache) { inserted, err = revCache.Insert(ctx, rev) assert.False(t, inserted, "Insert should return false for already existing entry") assert.NoError(t, err, "Insert should not err") - revs, err = revCache.Get(ctx, revcache.SingleKey(ia110, ifId19)) + revs, err = revCache.Get(ctx, revcache.SingleKey(ia110, ifID19)) assert.NoError(t, err, "Get should not err") assert.Empty(t, revs, "Get should return empty result for not present value") } func testGetMultikey(t *testing.T, revCache TestableRevCache) { - rev1 := defaultRevInfo(ia110, ifId15) - rev2 := defaultRevInfo(ia110, ifId19) - rev3 := defaultRevInfo(ia120, ifId15) - rev4 := defaultRevInfo(ia120, common.IfIdType(10)) + rev1 := defaultRevInfo(ia110, ifID15) + rev2 := defaultRevInfo(ia110, ifID19) + rev3 := defaultRevInfo(ia120, ifID15) + rev4 := defaultRevInfo(ia120, common.IfIDType(10)) ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() @@ -119,16 +119,16 @@ func testGetMultikey(t *testing.T, revCache TestableRevCache) { _, err = revCache.Insert(ctx, rev4) require.NoError(t, err) - key1 := revcache.NewKey(ia110, ifId15) + key1 := revcache.NewKey(ia110, ifID15) revs, err = revCache.Get(ctx, revcache.KeySet{key1: {}}) assert.NoError(t, err, "Get should not err") assert.Equal(t, len(revs), 1, "Should contain one rev") assert.Equal(t, revcache.Revocations{key1: rev1}, revs, "Get should return revs for the given keys") - key2 := revcache.NewKey(ia110, ifId19) - key3 := revcache.NewKey(ia120, ifId15) - key4 := revcache.NewKey(ia120, ifId19) // not the key of sr4 + key2 := revcache.NewKey(ia110, ifID19) + key3 := revcache.NewKey(ia120, ifID15) + key4 := revcache.NewKey(ia120, ifID19) // not the key of sr4 searchKeys := revcache.KeySet{key1: {}, key2: {}, key3: {}, key4: {}} revs, err = revCache.Get(ctx, searchKeys) assert.NoError(t, err, "Get should not err") @@ -149,10 +149,10 @@ func testGetAll(t *testing.T, revCache TestableRevCache) { assert.False(t, more, "No more entries expected") // Insert some stuff and query again - rev1 := defaultRevInfo(ia110, ifId15) - rev2 := defaultRevInfo(ia110, ifId19) - rev3 := defaultRevInfo(ia120, ifId15) - rev4 := defaultRevInfo(ia120, common.IfIdType(20)) + rev1 := defaultRevInfo(ia110, ifID15) + rev2 := defaultRevInfo(ia110, ifID19) + rev3 := defaultRevInfo(ia120, ifID15) + rev4 := defaultRevInfo(ia120, common.IfIDType(20)) _, err = revCache.Insert(ctx, rev1) require.NoError(t, err) _, err = revCache.Insert(ctx, rev2) @@ -177,7 +177,7 @@ func testGetAll(t *testing.T, revCache TestableRevCache) { iInfo := revs[i] jInfo := revs[j] return iInfo.IA() < jInfo.IA() || - (iInfo.IA() == jInfo.IA() && iInfo.IfId < jInfo.IfId) + (iInfo.IA() == jInfo.IA() && iInfo.IfID < jInfo.IfID) }) assert.Equal(t, expectedRevs, revs, "All revocations should have been returned") } @@ -187,7 +187,7 @@ func testGetAllExpired(t *testing.T, revCache TestableRevCache) { defer cancelF() // insert expired rev revNew := &path_mgmt.RevInfo{ - IfId: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), @@ -204,7 +204,7 @@ func testGetAllExpired(t *testing.T, revCache TestableRevCache) { func testInsertExpired(t *testing.T, revCache TestableRevCache) { r := &path_mgmt.RevInfo{ - IfId: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-15 * time.Second)), @@ -218,13 +218,13 @@ func testInsertExpired(t *testing.T, revCache TestableRevCache) { } func testInsertNewer(t *testing.T, revCache TestableRevCache) { - rev := defaultRevInfo(ia110, ifId15) + rev := defaultRevInfo(ia110, ifID15) ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() _, err := revCache.Insert(ctx, rev) require.NoError(t, err) revNew := &path_mgmt.RevInfo{ - IfId: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(10 * time.Second)), @@ -234,7 +234,7 @@ func testInsertNewer(t *testing.T, revCache TestableRevCache) { inserted, err := revCache.Insert(ctx, revNew) assert.True(t, inserted, "Insert should return true for a new entry") assert.NoError(t, err, "Insert a new entry should not err") - key1 := revcache.NewKey(ia110, ifId15) + key1 := revcache.NewKey(ia110, ifID15) revs, err := revCache.Get(ctx, revcache.KeySet{key1: {}}) assert.NoError(t, err, "Get should not err for existing entry") assert.NotEmpty(t, revs, "Get should return non empty map for inserted value") @@ -245,14 +245,14 @@ func testGetExpired(t *testing.T, revCache TestableRevCache) { ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() revNew := &path_mgmt.RevInfo{ - IfId: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), RawTTL: 1, } revCache.InsertExpired(t, ctx, revNew) - revs, err := revCache.Get(ctx, revcache.SingleKey(ia110, ifId15)) + revs, err := revCache.Get(ctx, revcache.SingleKey(ia110, ifID15)) assert.Empty(t, revs, "Expired entry should not be returned") assert.NoError(t, err, "Should not error for expired entry") } @@ -261,19 +261,19 @@ func testGetMuliKeysExpired(t *testing.T, revCache TestableRevCache) { ctx, cancelF := context.WithTimeout(context.Background(), TimeOut) defer cancelF() revNew := &path_mgmt.RevInfo{ - IfId: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), RawTTL: 1, } revCache.InsertExpired(t, ctx, revNew) - rev110_19 := defaultRevInfo(ia110, ifId19) + rev110_19 := defaultRevInfo(ia110, ifID19) _, err := revCache.Insert(ctx, rev110_19) assert.NoError(t, err) - validKey := revcache.NewKey(ia110, ifId19) + validKey := revcache.NewKey(ia110, ifID19) srCache, err := revCache.Get(ctx, revcache.KeySet{ - revcache.NewKey(ia110, ifId15): {}, + revcache.NewKey(ia110, ifID15): {}, validKey: {}, }) assert.NoError(t, err, "Should not error for expired entry") @@ -287,14 +287,14 @@ func testDeleteExpired(t *testing.T, revCache TestableRevCache) { del, err := revCache.DeleteExpired(ctx) assert.NoError(t, err, "DeleteExpired on empty should not error") assert.EqualValues(t, 0, del, "DeleteExpired on empty should delete 0") - rev110_19 := defaultRevInfo(ia110, ifId19) + rev110_19 := defaultRevInfo(ia110, ifID19) _, err = revCache.Insert(ctx, rev110_19) assert.NoError(t, err) del, err = revCache.DeleteExpired(ctx) assert.NoError(t, err, "DeleteExpired should not error") assert.EqualValues(t, 0, del, "DeleteExpired should delete 0 if entry is not expired") revNew := &path_mgmt.RevInfo{ - IfId: ifId15, + IfID: ifID15, RawIsdas: ia110, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now().Add(-2 * time.Second)), @@ -309,9 +309,9 @@ func testDeleteExpired(t *testing.T, revCache TestableRevCache) { assert.EqualValues(t, 0, del, "DeleteExpired should delete 0 if entry is not expired") } -func defaultRevInfo(ia addr.IA, ifId common.IfIdType) *path_mgmt.RevInfo { +func defaultRevInfo(ia addr.IA, ifID common.IfIDType) *path_mgmt.RevInfo { return &path_mgmt.RevInfo{ - IfId: ifId, + IfID: ifID, RawIsdas: ia, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(time.Now()), diff --git a/private/revcache/util.go b/private/revcache/util.go index 801b41b489..db0e1894e1 100644 --- a/private/revcache/util.go +++ b/private/revcache/util.go @@ -46,10 +46,10 @@ func NoRevokedHopIntf(ctx context.Context, revCache RevCache, func addRevKeys(segs []*seg.PathSegment, keys KeySet, hopOnly bool) { addIntfs := func(ia addr.IA, ingress, egress uint16) { if ingress != 0 { - keys[Key{IA: ia, IfId: common.IfIdType(ingress)}] = struct{}{} + keys[Key{IA: ia, IfID: common.IfIDType(ingress)}] = struct{}{} } if egress != 0 { - keys[Key{IA: ia, IfId: common.IfIdType(egress)}] = struct{}{} + keys[Key{IA: ia, IfID: common.IfIDType(egress)}] = struct{}{} } } for _, s := range segs { diff --git a/private/revcache/util_test.go b/private/revcache/util_test.go index 2ffae1a640..b2ee074191 100644 --- a/private/revcache/util_test.go +++ b/private/revcache/util_test.go @@ -60,7 +60,7 @@ func TestNoRevokedHopIntf(t *testing.T) { revCache.EXPECT().Get(gomock.Eq(ctx), gomock.Any()).Return( revcache.Revocations{ revcache.Key{IA: addr.MustParseIA("2-ff00:0:211"), - IfId: common.IFIDType(graph.If_210_X_211_A)}: sRev, + IfID: common.IFIDType(graph.If_210_X_211_A)}: sRev, }, nil, ) noR, err := revcache.NoRevokedHopIntf(ctx, revCache, seg210_222_1) @@ -77,9 +77,9 @@ func TestNoRevokedHopIntf(t *testing.T) { }) } -func defaultRevInfo(ia addr.IA, ifId uint16, ts time.Time) *path_mgmt.RevInfo { +func defaultRevInfo(ia addr.IA, ifID uint16, ts time.Time) *path_mgmt.RevInfo { return &path_mgmt.RevInfo{ - IfId: common.IfIdType(ifId), + IfID: common.IfIDType(ifID), RawIsdas: ia, LinkType: proto.LinkType_core, RawTimestamp: util.TimeToSecs(ts), diff --git a/private/segment/segfetcher/pather.go b/private/segment/segfetcher/pather.go index d577bd27a4..4f045ac81a 100644 --- a/private/segment/segfetcher/pather.go +++ b/private/segment/segfetcher/pather.go @@ -196,7 +196,7 @@ func (p *Pather) translatePath(comb combinator.Path) (snet.Path, error) { nextHop := p.NextHopper.UnderlayNextHop(uint16(comb.Metadata.Interfaces[0].ID)) if nextHop == nil { return nil, serrors.New("Unable to find first-hop BR for path", - "ifId", comb.Metadata.Interfaces[0].ID) + "ifID", comb.Metadata.Interfaces[0].ID) } return path.Path{ Src: comb.Metadata.Interfaces[0].IA, diff --git a/private/segment/segfetcher/resolver_test.go b/private/segment/segfetcher/resolver_test.go index 7c4e289613..d452476fd9 100644 --- a/private/segment/segfetcher/resolver_test.go +++ b/private/segment/segfetcher/resolver_test.go @@ -411,11 +411,11 @@ func TestResolverWithRevocations(t *testing.T) { ExpectRevcache: func(t *testing.T, revCache *mock_revcache.MockRevCache) { key111_120 := revcache.Key{ IA: non_core_111, - IfId: common.IfIdType(graph.If_111_B_120_X), + IfID: common.IfIDType(graph.If_111_B_120_X), } key111_130 := revcache.Key{ IA: non_core_111, - IfId: common.IfIdType(graph.If_111_A_130_B), + IfID: common.IfIDType(graph.If_111_A_130_B), } revoke(t, revCache, key111_120) revoke(t, revCache, key111_130) @@ -446,7 +446,7 @@ func TestResolverWithRevocations(t *testing.T) { db.EXPECT().Get(gomock.Any(), gomock.Any()).Times(2) }, ExpectRevcache: func(t *testing.T, revCache *mock_revcache.MockRevCache) { - key110 := revcache.Key{IA: core_110, IfId: common.IfIdType(graph.If_110_X_130_A)} + key110 := revcache.Key{IA: core_110, IfID: common.IfIDType(graph.If_110_X_130_A)} ksMatcher := keySetContains{keys: []revcache.Key{key110}} rev := &path_mgmt.RevInfo{} revCache.EXPECT().Get(gomock.Any(), ksMatcher).Return(revcache.Revocations{ diff --git a/private/storage/beacon/sqlite/db.go b/private/storage/beacon/sqlite/db.go index 98c074d5db..1ede0786d4 100644 --- a/private/storage/beacon/sqlite/db.go +++ b/private/storage/beacon/sqlite/db.go @@ -140,15 +140,15 @@ func (e *executor) CandidateBeacons( beacons := make([]beacon.Beacon, 0, setSize) for rows.Next() { var rawBeacon sql.RawBytes - var inIfId common.IfIdType - if err = rows.Scan(&rawBeacon, &inIfId); err != nil { + var inIfID common.IfIDType + if err = rows.Scan(&rawBeacon, &inIfID); err != nil { return nil, db.NewReadError(beacon.ErrReadingRows, err) } s, err := beacon.UnpackBeacon(rawBeacon) if err != nil { return nil, db.NewDataError(beacon.ErrParse, err) } - beacons = append(beacons, beacon.Beacon{Segment: s, InIfId: uint16(inIfId)}) + beacons = append(beacons, beacon.Beacon{Segment: s, InIfID: uint16(inIfID)}) } if err := rows.Err(); err != nil { return nil, err @@ -217,8 +217,8 @@ func (e *executor) GetBeacons( var lastUpdated int64 var usage int var rawBeacon sql.RawBytes - var InIfId uint16 - err = rows.Scan(&RowID, &lastUpdated, &usage, &rawBeacon, &InIfId) + var InIfID uint16 + err = rows.Scan(&RowID, &lastUpdated, &usage, &rawBeacon, &InIfID) if err != nil { return nil, serrors.WrapStr("reading row", err) } @@ -229,7 +229,7 @@ func (e *executor) GetBeacons( res = append(res, storagebeacon.Beacon{ Beacon: beacon.Beacon{ Segment: seg, - InIfId: InIfId, + InIfID: InIfID, }, Usage: beacon.Usage(usage), LastUpdated: time.Unix(0, lastUpdated), @@ -360,7 +360,7 @@ func (e *executor) updateExistingBeacon( inst := `UPDATE Beacons SET FullID=?, InIntfID=?, HopsLength=?, InfoTime=?, ExpirationTime=?, LastUpdated=?, Usage=?, Beacon=? WHERE RowID=?` - _, err = e.db.ExecContext(ctx, inst, fullID, b.InIfId, len(b.Segment.ASEntries), infoTime, + _, err = e.db.ExecContext(ctx, inst, fullID, b.InIfID, len(b.Segment.ASEntries), infoTime, expTime, lastUpdated, usage, packedSeg, rowID) if err != nil { return db.NewWriteError("update segment", err) @@ -393,7 +393,7 @@ func insertNewBeacon( ExpirationTime, LastUpdated, Usage, Beacon) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ` - _, err = tx.ExecContext(ctx, inst, segID, fullID, start.ISD(), start.AS(), b.InIfId, + _, err = tx.ExecContext(ctx, inst, segID, fullID, start.ISD(), start.AS(), b.InIfID, len(b.Segment.ASEntries), infoTime, expTime, lastUpdated, usage, packed) if err != nil { return db.NewWriteError("insert beacon", err) diff --git a/private/storage/path/dbtest/dbtest.go b/private/storage/path/dbtest/dbtest.go index 06627ca3e6..d8e474eca6 100644 --- a/private/storage/path/dbtest/dbtest.go +++ b/private/storage/path/dbtest/dbtest.go @@ -94,7 +94,7 @@ func TestPathDB(t *testing.T, db TestablePathDB) { testWrapper(testGetAll)) t.Run("Get should return all path segments starting or ending at", testWrapper(testGetStartsAtEndsAt)) - t.Run("Get should return all path segment with given ifIds", + t.Run("Get should return all path segment with given ifIDs", testWrapper(testGetWithIntfs)) t.Run("Get should return all path segment with given HPGroupIDs", testWrapper(testGetWithHPGroupIDs)) @@ -134,7 +134,7 @@ func TestPathDB(t *testing.T, db TestablePathDB) { txTestWrapper(testGetAll)) t.Run("Get should return all path segments starting or ending at", txTestWrapper(testGetStartsAtEndsAt)) - t.Run("Get should return all path segment with given ifIds", + t.Run("Get should return all path segment with given ifIDs", txTestWrapper(testGetWithIntfs)) t.Run("Get should return all path segment with given HPGroupIDs", txTestWrapper(testGetWithHPGroupIDs)) @@ -384,8 +384,8 @@ func testGetWithIntfs(t *testing.T, pathDB pathdb.ReadWrite) { require.Equal(t, stat, pathdb.InsertStats{Inserted: 1}) params := &query.Params{ Intfs: []*query.IntfSpec{ - {IA: ia330, IfId: 5}, - {IA: ia332, IfId: 2}, + {IA: ia330, IfID: 5}, + {IA: ia332, IfID: 2}, }, } // Call @@ -596,21 +596,21 @@ func checkInterfacesPresent(t *testing.T, ctx context.Context, } } -func checkInterface(t *testing.T, ctx context.Context, ia addr.IA, ifId uint16, +func checkInterface(t *testing.T, ctx context.Context, ia addr.IA, ifID uint16, pathDB pathdb.ReadWrite, present bool) { r, err := pathDB.Get(ctx, &query.Params{ Intfs: []*query.IntfSpec{ { IA: ia, - IfId: common.IfIdType(ifId), + IfID: common.IfIDType(ifID), }, }, }) require.NoError(t, err) if present { - assert.Equal(t, 1, len(r), fmt.Sprintf("Interface should be present: %v#%d", ia, ifId)) + assert.Equal(t, 1, len(r), fmt.Sprintf("Interface should be present: %v#%d", ia, ifID)) } else { - assert.Zero(t, len(r), (fmt.Sprintf("Interface should not be present: %v#%d", ia, ifId))) + assert.Zero(t, len(r), (fmt.Sprintf("Interface should not be present: %v#%d", ia, ifID))) } } diff --git a/private/storage/path/sqlite/sqlite.go b/private/storage/path/sqlite/sqlite.go index a506626392..9c5094ed7e 100644 --- a/private/storage/path/sqlite/sqlite.go +++ b/private/storage/path/sqlite/sqlite.go @@ -483,7 +483,7 @@ func (e *executor) buildQuery(params *query.Params) (string, []interface{}) { subQ := []string{} for _, spec := range params.Intfs { subQ = append(subQ, "(i.IsdID=? AND i.AsID=? AND i.IntfID=?)") - args = append(args, spec.IA.ISD(), spec.IA.AS(), spec.IfId) + args = append(args, spec.IA.ISD(), spec.IA.AS(), spec.IfID) } where = append(where, fmt.Sprintf("(%s)", strings.Join(subQ, " OR "))) } diff --git a/private/topology/interface.go b/private/topology/interface.go index b8105d0508..7a02609eb3 100644 --- a/private/topology/interface.go +++ b/private/topology/interface.go @@ -39,7 +39,7 @@ type Topology interface { // Core returns whether the local AS is core. Core() bool // InterfaceIDs returns all interface IDS from the local AS. - InterfaceIDs() []common.IfIdType + InterfaceIDs() []common.IfIDType // PortRange returns the first and last ports of the port range (both included), // in which endhost listen for SCION/UDP application using the UDP/IP underlay. PortRange() (uint16, uint16) @@ -59,7 +59,7 @@ type Topology interface { UnderlayMulticast(svc addr.SVC) ([]*net.UDPAddr, error) // UnderlayNextHop returns the internal underlay address of the router // containing the interface ID. - UnderlayNextHop(ifId common.IfIdType) (*net.UDPAddr, bool) + UnderlayNextHop(ifID common.IfIDType) (*net.UDPAddr, bool) // MakeHostInfos returns the underlay addresses of all services for the specified service type. MakeHostInfos(st ServiceType) ([]*net.UDPAddr, error) @@ -144,10 +144,10 @@ func (t *topologyS) MTU() uint16 { return uint16(t.Topology.MTU) } -func (t *topologyS) InterfaceIDs() []common.IfIdType { - intfs := make([]common.IfIdType, 0, len(t.Topology.IFInfoMap)) - for ifId := range t.Topology.IFInfoMap { - intfs = append(intfs, ifId) +func (t *topologyS) InterfaceIDs() []common.IfIDType { + intfs := make([]common.IfIDType, 0, len(t.Topology.IFInfoMap)) + for ifID := range t.Topology.IFInfoMap { + intfs = append(intfs, ifID) } return intfs } @@ -156,8 +156,8 @@ func (t *topologyS) PortRange() (uint16, uint16) { return t.Topology.DispatchedPortStart, t.Topology.DispatchedPortEnd } -func (t *topologyS) UnderlayNextHop(ifId common.IfIdType) (*net.UDPAddr, bool) { - ifInfo, ok := t.Topology.IFInfoMap[ifId] +func (t *topologyS) UnderlayNextHop(ifID common.IfIDType) (*net.UDPAddr, bool) { + ifInfo, ok := t.Topology.IFInfoMap[ifID] if !ok { return nil, false } diff --git a/private/topology/json/json.go b/private/topology/json/json.go index a275ccc719..a15b1f90cd 100644 --- a/private/topology/json/json.go +++ b/private/topology/json/json.go @@ -94,7 +94,7 @@ type ServerInfo struct { // BRInfo contains Border Router specific information. type BRInfo struct { InternalAddr string `json:"internal_addr"` - Interfaces map[common.IfIdType]*BRInterface `json:"interfaces"` + Interfaces map[common.IfIDType]*BRInterface `json:"interfaces"` } // GatewayInfo contains SCION gateway information. @@ -113,7 +113,7 @@ type BRInterface struct { LinkTo string `json:"link_to"` MTU int `json:"mtu"` BFD *BFD `json:"bfd,omitempty"` - RemoteIFID common.IfIdType `json:"remote_interface_id,omitempty"` + RemoteIFID common.IfIDType `json:"remote_interface_id,omitempty"` } // Underlay is the underlay information for a BR interface. @@ -139,8 +139,8 @@ func (i ServerInfo) String() string { func (i BRInfo) String() string { var s []string s = append(s, fmt.Sprintf("Loc addrs:\n %s\nInterfaces:", i.InternalAddr)) - for ifId, intf := range i.Interfaces { - s = append(s, fmt.Sprintf("%d: %+v", ifId, intf)) + for ifID, intf := range i.Interfaces { + s = append(s, fmt.Sprintf("%d: %+v", ifID, intf)) } return strings.Join(s, "\n") } diff --git a/private/topology/json/json_test.go b/private/topology/json/json_test.go index 63768c8f05..25f590e771 100644 --- a/private/topology/json/json_test.go +++ b/private/topology/json/json_test.go @@ -46,7 +46,7 @@ func TestLoadRawFromFile(t *testing.T) { BorderRouters: map[string]*jsontopo.BRInfo{ "borderrouter6-f00:0:362-1": { InternalAddr: "10.1.0.1:0", - Interfaces: map[common.IfIdType]*jsontopo.BRInterface{ + Interfaces: map[common.IfIDType]*jsontopo.BRInterface{ 91: { Underlay: jsontopo.Underlay{ Local: "192.0.2.1:4997", @@ -65,7 +65,7 @@ func TestLoadRawFromFile(t *testing.T) { }, "borderrouter6-f00:0:362-9": { InternalAddr: "[2001:db8:a0b:12f0::2]:0", - Interfaces: map[common.IfIdType]*jsontopo.BRInterface{ + Interfaces: map[common.IfIDType]*jsontopo.BRInterface{ 32: { Underlay: jsontopo.Underlay{ Local: "[2001:db8:a0b:12f0::1]:4997", diff --git a/private/topology/mock_topology/mock.go b/private/topology/mock_topology/mock.go index d9b1e01f93..1e385ecccc 100644 --- a/private/topology/mock_topology/mock.go +++ b/private/topology/mock_topology/mock.go @@ -125,10 +125,10 @@ func (mr *MockTopologyMockRecorder) IFInfoMap() *gomock.Call { } // InterfaceIDs mocks base method. -func (m *MockTopology) InterfaceIDs() []common.IfIdType { +func (m *MockTopology) InterfaceIDs() []common.IfIDType { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InterfaceIDs") - ret0, _ := ret[0].([]common.IfIdType) + ret0, _ := ret[0].([]common.IfIDType) return ret0 } @@ -256,7 +256,7 @@ func (mr *MockTopologyMockRecorder) UnderlayMulticast(arg0 interface{}) *gomock. } // UnderlayNextHop mocks base method. -func (m *MockTopology) UnderlayNextHop(arg0 common.IfIdType) (*net.UDPAddr, bool) { +func (m *MockTopology) UnderlayNextHop(arg0 common.IfIDType) (*net.UDPAddr, bool) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UnderlayNextHop", arg0) ret0, _ := ret[0].(*net.UDPAddr) diff --git a/private/topology/reload.go b/private/topology/reload.go index a97e8db5dd..b8ea4e6ccf 100644 --- a/private/topology/reload.go +++ b/private/topology/reload.go @@ -129,11 +129,11 @@ func (l *Loader) Core() bool { return l.topo.Core() } -func (l *Loader) UnderlayNextHop(ifId uint16) *net.UDPAddr { +func (l *Loader) UnderlayNextHop(ifID uint16) *net.UDPAddr { l.mtx.Lock() defer l.mtx.Unlock() - addr, _ := l.topo.UnderlayNextHop(common.IfIdType(ifId)) + addr, _ := l.topo.UnderlayNextHop(common.IfIDType(ifID)) return addr } @@ -182,7 +182,7 @@ func (l *Loader) Gateways() ([]GatewayInfo, error) { return l.topo.Gateways() } -func (l *Loader) InterfaceInfoMap() map[common.IfIdType]IFInfo { +func (l *Loader) InterfaceInfoMap() map[common.IfIDType]IFInfo { l.mtx.Lock() defer l.mtx.Unlock() diff --git a/private/topology/topology.go b/private/topology/topology.go index 1b0399c9b4..20bb10c688 100644 --- a/private/topology/topology.go +++ b/private/topology/topology.go @@ -95,25 +95,25 @@ type ( // InternalAddr is the local data-plane address. InternalAddr netip.AddrPort // IFIDs is a sorted list of the interface IDs. - IFIDs []common.IfIdType + IFIDs []common.IfIDType // IFs is a map of interface IDs. - IFs map[common.IfIdType]*IFInfo + IFs map[common.IfIDType]*IFInfo } // IfInfoMap maps interface ids to the interface information. - IfInfoMap map[common.IfIdType]IFInfo + IfInfoMap map[common.IfIDType]IFInfo // IFInfo describes a border router link to another AS, including the internal data-plane // address applications should send traffic to and information about the link itself and the // remote side of it. IFInfo struct { // ID is the interface ID. It is unique per AS. - ID common.IfIdType + ID common.IfIDType BRName string InternalAddr netip.AddrPort Local netip.AddrPort Remote netip.AddrPort - RemoteIFID common.IfIdType + RemoteIFID common.IfIDType IA addr.IA LinkType LinkType MTU int @@ -267,17 +267,17 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { brInfo := BRInfo{ Name: name, InternalAddr: intAddr, - IFs: make(map[common.IfIdType]*IFInfo), + IFs: make(map[common.IfIDType]*IFInfo), } - for ifId, rawIntf := range rawBr.Interfaces { + for ifID, rawIntf := range rawBr.Interfaces { var err error - // Check that ifId is unique - if _, ok := t.IFInfoMap[ifId]; ok { - return serrors.New("IFID already exists", "ID", ifId) + // Check that ifID is unique + if _, ok := t.IFInfoMap[ifID]; ok { + return serrors.New("IFID already exists", "ID", ifID) } - brInfo.IFIDs = append(brInfo.IFIDs, ifId) + brInfo.IFIDs = append(brInfo.IFIDs, ifID) ifinfo := IFInfo{ - ID: ifId, + ID: ifID, BRName: name, InternalAddr: intAddr, MTU: rawIntf.MTU, @@ -305,8 +305,8 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { // These fields are only necessary for the border router. // Parsing should not fail if all fields are empty. if rawIntf.Underlay == (jsontopo.Underlay{}) { - brInfo.IFs[ifId] = &ifinfo - t.IFInfoMap[ifId] = ifinfo + brInfo.IFs[ifID] = &ifinfo + t.IFInfoMap[ifID] = ifinfo continue } if ifinfo.Local, err = rawBRIntfLocalAddr(&rawIntf.Underlay); err != nil { @@ -317,8 +317,8 @@ func (t *RWTopology) populateBR(raw *jsontopo.Topology) error { return serrors.WrapStr("unable to extract "+ "underlay external data-plane remote address", err) } - brInfo.IFs[ifId] = &ifinfo - t.IFInfoMap[ifId] = ifinfo + brInfo.IFs[ifID] = &ifinfo + t.IFInfoMap[ifID] = ifinfo } sort.Slice(brInfo.IFIDs, func(i, j int) bool { return brInfo.IFIDs[i] < brInfo.IFIDs[j] @@ -472,11 +472,11 @@ func (i *BRInfo) copy() *BRInfo { } } -func copyIFsMap(m map[common.IfIdType]*IFInfo) map[common.IfIdType]*IFInfo { +func copyIFsMap(m map[common.IfIDType]*IFInfo) map[common.IfIDType]*IFInfo { if m == nil { return nil } - newM := make(map[common.IfIdType]*IFInfo) + newM := make(map[common.IfIDType]*IFInfo) for k, v := range m { newM[k] = v.copy() } diff --git a/private/topology/topology_test.go b/private/topology/topology_test.go index ea41da8867..a0d634eff4 100644 --- a/private/topology/topology_test.go +++ b/private/topology/topology_test.go @@ -58,10 +58,10 @@ func TestBRs(t *testing.T) { brs := map[string]BRInfo{ "br1-ff00:0:311-1": { - IFIDs: []common.IfIdType{1, 3, 8}, + IFIDs: []common.IfIDType{1, 3, 8}, }, "br1-ff00:0:311-2": { - IFIDs: []common.IfIdType{11}, + IFIDs: []common.IfIDType{11}, }, } @@ -312,10 +312,10 @@ func TestBRsCoreAS(t *testing.T) { c := MustLoadTopo(t, "testdata/core.json") brCases := []struct { name string - interfaces []common.IfIdType + interfaces []common.IfIDType }{ - {name: "borderrouter6-ff00:0:362-1", interfaces: []common.IfIdType{91}}, - {name: "borderrouter6-ff00:0:362-9", interfaces: []common.IfIdType{32}}, + {name: "borderrouter6-ff00:0:362-1", interfaces: []common.IfIDType{91}}, + {name: "borderrouter6-ff00:0:362-9", interfaces: []common.IfIDType{32}}, } for _, test := range brCases { t.Run(test.name, func(t *testing.T) { diff --git a/router/connector.go b/router/connector.go index e6957f843d..0cafc81bf4 100644 --- a/router/connector.go +++ b/router/connector.go @@ -80,13 +80,13 @@ func (c *Connector) AddInternalInterface(ia addr.IA, local netip.AddrPort) error } // AddExternalInterface adds a link between the local and remote address. -func (c *Connector) AddExternalInterface(localIfId common.IfIdType, link control.LinkInfo, +func (c *Connector) AddExternalInterface(localIfID common.IfIDType, link control.LinkInfo, owned bool) error { c.mtx.Lock() defer c.mtx.Unlock() - intf := uint16(localIfId) - log.Debug("Adding external interface", "interface", localIfId, + intf := uint16(localIfID) + log.Debug("Adding external interface", "interface", localIfID, "local_isd_as", link.Local.IA, "local_addr", link.Local.Addr, "remote_isd_as", link.Remote.IA, "remote_addr", link.Remote.Addr, "owned", owned, @@ -98,10 +98,10 @@ func (c *Connector) AddExternalInterface(localIfId common.IfIdType, link control return serrors.WithCtx(errMultiIA, "current", c.ia, "new", link.Local.IA) } if err := c.DataPlane.AddLinkType(intf, link.LinkTo); err != nil { - return serrors.WrapStr("adding link type", err, "if_id", localIfId) + return serrors.WrapStr("adding link type", err, "if_id", localIfID) } if err := c.DataPlane.AddNeighborIA(intf, link.Remote.IA); err != nil { - return serrors.WrapStr("adding neighboring IA", err, "if_id", localIfId) + return serrors.WrapStr("adding neighboring IA", err, "if_id", localIfID) } link.BFD = c.applyBFDDefaults(link.BFD) diff --git a/router/control/conf.go b/router/control/conf.go index b68306f413..b911e5e92d 100644 --- a/router/control/conf.go +++ b/router/control/conf.go @@ -32,7 +32,7 @@ import ( type Dataplane interface { CreateIACtx(ia addr.IA) error AddInternalInterface(ia addr.IA, local netip.AddrPort) error - AddExternalInterface(localIfId common.IfIdType, info LinkInfo, owned bool) error + AddExternalInterface(localIfID common.IfIDType, info LinkInfo, owned bool) error AddSvc(ia addr.IA, svc addr.SVC, a netip.AddrPort) error DelSvc(ia addr.IA, svc addr.SVC, a netip.AddrPort) error SetKey(ia addr.IA, index int, key []byte) error @@ -57,7 +57,7 @@ type LinkInfo struct { type LinkEnd struct { IA addr.IA Addr netip.AddrPort - IFID common.IfIdType + IFID common.IfIDType } type ObservableDataplane interface { @@ -163,20 +163,20 @@ func DeriveHFMacKey(k []byte) []byte { } func confExternalInterfaces(dp Dataplane, cfg *Config) error { - // Sort out keys/ifIds to get deterministic order for unit testing + // Sort out keys/ifIDs to get deterministic order for unit testing infoMap := cfg.Topo.IFInfoMap() if len(infoMap) == 0 { // nothing to do return nil } - ifIds := []common.IfIdType{} + ifIDs := []common.IfIDType{} for k := range infoMap { - ifIds = append(ifIds, k) + ifIDs = append(ifIDs, k) } - sort.Slice(ifIds, func(i, j int) bool { return ifIds[i] < ifIds[j] }) + sort.Slice(ifIDs, func(i, j int) bool { return ifIDs[i] < ifIDs[j] }) // External interfaces - for _, ifId := range ifIds { - iface := infoMap[ifId] + for _, ifID := range ifIDs { + iface := infoMap[ifID] linkInfo := LinkInfo{ Local: LinkEnd{ IA: cfg.IA, @@ -194,7 +194,7 @@ func confExternalInterfaces(dp Dataplane, cfg *Config) error { MTU: iface.MTU, } - _, owned := cfg.BR.IFs[ifId] + _, owned := cfg.BR.IFs[ifID] if !owned { // XXX The current implementation effectively uses IP/UDP tunnels to create // the SCION network as an overlay, with forwarding to local hosts being a special case. @@ -207,7 +207,7 @@ func confExternalInterfaces(dp Dataplane, cfg *Config) error { linkInfo.BFD = BFD{} } - if err := dp.AddExternalInterface(ifId, linkInfo, owned); err != nil { + if err := dp.AddExternalInterface(ifID, linkInfo, owned); err != nil { return err } } diff --git a/router/control/internal/metrics/metrics.go b/router/control/internal/metrics/metrics.go index eb71231cf3..d33f57af83 100644 --- a/router/control/internal/metrics/metrics.go +++ b/router/control/internal/metrics/metrics.go @@ -65,9 +65,9 @@ func (l IntfLabels) Values() []string { return []string{l.Intf, l.NeighIA} } -func IntfToLabel(ifId common.IfIdType) string { - if ifId == 0 { +func IntfToLabel(ifID common.IfIDType) string { + if ifID == 0 { return "loc" } - return ifId.String() + return ifID.String() } diff --git a/router/dataplane.go b/router/dataplane.go index 68cf8eccda..1d08db5135 100644 --- a/router/dataplane.go +++ b/router/dataplane.go @@ -318,7 +318,7 @@ func (d *DataPlane) AddInternalInterface(conn BatchConn, ip netip.Addr) error { // AddExternalInterface adds the inter AS connection for the given interface ID. // If a connection for the given ID is already set this method will return an // error. This can only be called on a not yet running dataplane. -func (d *DataPlane) AddExternalInterface(ifId uint16, conn BatchConn, +func (d *DataPlane) AddExternalInterface(ifID uint16, conn BatchConn, src, dst control.LinkEnd, cfg control.BFD) error { d.mtx.Lock() @@ -330,9 +330,9 @@ func (d *DataPlane) AddExternalInterface(ifId uint16, conn BatchConn, if conn == nil || !src.Addr.IsValid() || !dst.Addr.IsValid() { return emptyValue } - err := d.addExternalInterfaceBFD(ifId, conn, src, dst, cfg) + err := d.addExternalInterfaceBFD(ifID, conn, src, dst, cfg) if err != nil { - return serrors.WrapStr("adding external BFD", err, "if_id", ifId) + return serrors.WrapStr("adding external BFD", err, "if_id", ifID) } if d.external == nil { d.external = make(map[uint16]BatchConn) @@ -340,18 +340,18 @@ func (d *DataPlane) AddExternalInterface(ifId uint16, conn BatchConn, if d.interfaces == nil { d.interfaces = make(map[uint16]BatchConn) } - if _, exists := d.external[ifId]; exists { - return serrors.WithCtx(alreadySet, "ifId", ifId) + if _, exists := d.external[ifID]; exists { + return serrors.WithCtx(alreadySet, "ifID", ifID) } - d.interfaces[ifId] = conn - d.external[ifId] = conn + d.interfaces[ifID] = conn + d.external[ifID] = conn return nil } // AddNeighborIA adds the neighboring IA for a given interface ID. If an IA for // the given ID is already set, this method will return an error. This can only // be called on a yet running dataplane. -func (d *DataPlane) AddNeighborIA(ifId uint16, remote addr.IA) error { +func (d *DataPlane) AddNeighborIA(ifID uint16, remote addr.IA) error { d.mtx.Lock() defer d.mtx.Unlock() if d.running { @@ -360,27 +360,27 @@ func (d *DataPlane) AddNeighborIA(ifId uint16, remote addr.IA) error { if remote.IsZero() { return emptyValue } - if _, exists := d.neighborIAs[ifId]; exists { - return serrors.WithCtx(alreadySet, "ifId", ifId) + if _, exists := d.neighborIAs[ifID]; exists { + return serrors.WithCtx(alreadySet, "ifID", ifID) } if d.neighborIAs == nil { d.neighborIAs = make(map[uint16]addr.IA) } - d.neighborIAs[ifId] = remote + d.neighborIAs[ifID] = remote return nil } // AddLinkType adds the link type for a given interface ID. If a link type for // the given ID is already set, this method will return an error. This can only // be called on a not yet running dataplane. -func (d *DataPlane) AddLinkType(ifId uint16, linkTo topology.LinkType) error { - if _, exists := d.linkTypes[ifId]; exists { - return serrors.WithCtx(alreadySet, "ifId", ifId) +func (d *DataPlane) AddLinkType(ifID uint16, linkTo topology.LinkType) error { + if _, exists := d.linkTypes[ifID]; exists { + return serrors.WithCtx(alreadySet, "ifID", ifID) } if d.linkTypes == nil { d.linkTypes = make(map[uint16]topology.LinkType) } - d.linkTypes[ifId] = linkTo + d.linkTypes[ifID] = linkTo return nil } @@ -403,7 +403,7 @@ func (d *DataPlane) AddRemotePeer(local, remote uint16) error { } // AddExternalInterfaceBFD adds the inter AS connection BFD session. -func (d *DataPlane) addExternalInterfaceBFD(ifId uint16, conn BatchConn, +func (d *DataPlane) addExternalInterfaceBFD(ifID uint16, conn BatchConn, src, dst control.LinkEnd, cfg control.BFD) error { if *cfg.Disable { @@ -412,7 +412,7 @@ func (d *DataPlane) addExternalInterfaceBFD(ifId uint16, conn BatchConn, var m bfd.Metrics if d.Metrics != nil { labels := prometheus.Labels{ - "interface": fmt.Sprint(ifId), + "interface": fmt.Sprint(ifID), "isd_as": d.localIA.String(), "neighbor_isd_as": dst.IA.String(), } @@ -423,11 +423,11 @@ func (d *DataPlane) addExternalInterfaceBFD(ifId uint16, conn BatchConn, PacketsReceived: d.Metrics.BFDPacketsReceived.With(labels), } } - s, err := newBFDSend(conn, src.IA, dst.IA, src.Addr, dst.Addr, ifId, d.macFactory()) + s, err := newBFDSend(conn, src.IA, dst.IA, src.Addr, dst.Addr, ifID, d.macFactory()) if err != nil { return err } - return d.addBFDController(ifId, s, cfg, m) + return d.addBFDController(ifID, s, cfg, m) } // getInterfaceState checks if there is a bfd session for the input interfaceID and @@ -441,7 +441,7 @@ func (d *DataPlane) getInterfaceState(interfaceID uint16) control.InterfaceState return control.InterfaceUp } -func (d *DataPlane) addBFDController(ifId uint16, s *bfdSend, cfg control.BFD, +func (d *DataPlane) addBFDController(ifID uint16, s *bfdSend, cfg control.BFD, metrics bfd.Metrics) error { if d.bfdSessions == nil { @@ -454,7 +454,7 @@ func (d *DataPlane) addBFDController(ifId uint16, s *bfdSend, cfg control.BFD, return err } disc := layers.BFDDiscriminator(uint32(discInt.Uint64()) + 1) - d.bfdSessions[ifId] = &bfd.Session{ + d.bfdSessions[ifID] = &bfd.Session{ Sender: s, DetectMult: layers.BFDDetectMultiplier(cfg.DetectMult), DesiredMinTxInterval: cfg.DesiredMinTxInterval, @@ -509,7 +509,7 @@ func (d *DataPlane) DelSvc(svc addr.SVC, a netip.AddrPort) error { // AddNextHop sets the next hop address for the given interface ID. If the // interface ID already has an address associated this operation fails. This can // only be called on a not yet running dataplane. -func (d *DataPlane) AddNextHop(ifId uint16, src, dst netip.AddrPort, cfg control.BFD, +func (d *DataPlane) AddNextHop(ifID uint16, src, dst netip.AddrPort, cfg control.BFD, sibling string) error { d.mtx.Lock() @@ -521,24 +521,24 @@ func (d *DataPlane) AddNextHop(ifId uint16, src, dst netip.AddrPort, cfg control if !dst.IsValid() || !src.IsValid() { return emptyValue } - err := d.addNextHopBFD(ifId, src, dst, cfg, sibling) + err := d.addNextHopBFD(ifID, src, dst, cfg, sibling) if err != nil { - return serrors.WrapStr("adding next hop BFD", err, "if_id", ifId) + return serrors.WrapStr("adding next hop BFD", err, "if_id", ifID) } if d.internalNextHops == nil { d.internalNextHops = make(map[uint16]netip.AddrPort) } - if _, exists := d.internalNextHops[ifId]; exists { - return serrors.WithCtx(alreadySet, "ifId", ifId) + if _, exists := d.internalNextHops[ifID]; exists { + return serrors.WithCtx(alreadySet, "ifID", ifID) } - d.internalNextHops[ifId] = dst + d.internalNextHops[ifID] = dst return nil } // AddNextHopBFD adds the BFD session for the next hop address. -// If the remote ifId belongs to an existing address, the existing +// If the remote ifID belongs to an existing address, the existing // BFD session will be re-used. -func (d *DataPlane) addNextHopBFD(ifId uint16, src, dst netip.AddrPort, cfg control.BFD, +func (d *DataPlane) addNextHopBFD(ifID uint16, src, dst netip.AddrPort, cfg control.BFD, sibling string) error { if *cfg.Disable { @@ -547,7 +547,7 @@ func (d *DataPlane) addNextHopBFD(ifId uint16, src, dst netip.AddrPort, cfg cont for k, v := range d.internalNextHops { if v.String() == dst.String() { if c, ok := d.bfdSessions[k]; ok { - d.bfdSessions[ifId] = c + d.bfdSessions[ifID] = c return nil } } @@ -567,7 +567,7 @@ func (d *DataPlane) addNextHopBFD(ifId uint16, src, dst netip.AddrPort, cfg cont if err != nil { return err } - return d.addBFDController(ifId, s, cfg, m) + return d.addBFDController(ifID, s, cfg, m) } func max(a int, b int) int { @@ -595,15 +595,15 @@ func (d *DataPlane) Run(ctx context.Context, cfg *RunConfig) error { d.initPacketPool(cfg, processorQueueSize) procQs, fwQs, slowQs := initQueues(cfg, d.interfaces, processorQueueSize) - for ifId, conn := range d.interfaces { - go func(ifId uint16, conn BatchConn) { + for ifID, conn := range d.interfaces { + go func(ifID uint16, conn BatchConn) { defer log.HandlePanic() - d.runReceiver(ifId, conn, cfg, procQs) - }(ifId, conn) - go func(ifId uint16, conn BatchConn) { + d.runReceiver(ifID, conn, cfg, procQs) + }(ifID, conn) + go func(ifID uint16, conn BatchConn) { defer log.HandlePanic() - d.runForwarder(ifId, conn, cfg, fwQs[ifId]) - }(ifId, conn) + d.runForwarder(ifID, conn, cfg, fwQs[ifID]) + }(ifID, conn) } for i := 0; i < cfg.NumProcessors; i++ { go func(i int) { @@ -619,10 +619,10 @@ func (d *DataPlane) Run(ctx context.Context, cfg *RunConfig) error { } for k, v := range d.bfdSessions { - go func(ifId uint16, c bfdSession) { + go func(ifID uint16, c bfdSession) { defer log.HandlePanic() if err := c.Run(ctx); err != nil && err != bfd.AlreadyRunning { - log.Error("BFD session failed to start", "ifId", ifId, "err", err) + log.Error("BFD session failed to start", "ifID", ifID, "err", err) } }(k, v) } @@ -661,16 +661,16 @@ func initQueues(cfg *RunConfig, interfaces map[uint16]BatchConn, slowQs[i] = make(chan *packet, processorQueueSize) } fwQs := make(map[uint16]chan *packet) - for ifId := range interfaces { - fwQs[ifId] = make(chan *packet, cfg.BatchSize) + for ifID := range interfaces { + fwQs[ifID] = make(chan *packet, cfg.BatchSize) } return procQs, fwQs, slowQs } -func (d *DataPlane) runReceiver(ifId uint16, conn BatchConn, cfg *RunConfig, +func (d *DataPlane) runReceiver(ifID uint16, conn BatchConn, cfg *RunConfig, procQs []chan *packet) { - log.Debug("Run receiver for", "interface", ifId) + log.Debug("Run receiver for", "interface", ifID) // Each receiver (therefore each input interface) has a unique random seed for the procID hash // function. @@ -692,7 +692,7 @@ func (d *DataPlane) runReceiver(ifId uint16, conn BatchConn, cfg *RunConfig, packets := make([]*packet, cfg.BatchSize) numReusable := 0 // unused buffers from previous loop - metrics := d.forwardingMetrics[ifId] // If receiver exists, fw metrics exist too. + metrics := d.forwardingMetrics[ifID] // If receiver exists, fw metrics exist too. enqueueForProcessing := func(size int, srcAddr *net.UDPAddr, pkt *packet) { sc := classOfSize(size) @@ -708,7 +708,7 @@ func (d *DataPlane) runReceiver(ifId uint16, conn BatchConn, cfg *RunConfig, } pkt.rawPacket = pkt.rawPacket[:size] // Update size; readBatch does not. - pkt.ingress = ifId + pkt.ingress = ifID pkt.srcAddr = srcAddr select { case procQs[procID] <- pkt: @@ -733,7 +733,7 @@ func (d *DataPlane) runReceiver(ifId uint16, conn BatchConn, cfg *RunConfig, numPkts, err := conn.ReadBatch(msgs) numReusable = len(msgs) - numPkts if err != nil { - log.Debug("Error while reading batch", "interfaceID", ifId, "err", err) + log.Debug("Error while reading batch", "interfaceID", ifID, "err", err) continue } for i, msg := range msgs[:numPkts] { @@ -956,7 +956,7 @@ func (p *slowPathPacketProcessor) processPacket(pkt *packet) error { layer = &slayers.SCMPDestinationUnreachable{} case slayers.SCMPTypeExternalInterfaceDown: layer = &slayers.SCMPExternalInterfaceDown{IA: p.d.localIA, - IfId: uint64(p.pkt.egress)} + IfID: uint64(p.pkt.egress)} case slayers.SCMPTypeInternalConnectivityDown: layer = &slayers.SCMPInternalConnectivityDown{IA: p.d.localIA, Ingress: uint64(p.pkt.ingress), Egress: uint64(p.pkt.egress)} @@ -995,9 +995,9 @@ func updateOutputMetrics(metrics interfaceMetrics, packets []*packet) { } } -func (d *DataPlane) runForwarder(ifId uint16, conn BatchConn, cfg *RunConfig, c <-chan *packet) { +func (d *DataPlane) runForwarder(ifID uint16, conn BatchConn, cfg *RunConfig, c <-chan *packet) { - log.Debug("Initialize forwarder for", "interface", ifId) + log.Debug("Initialize forwarder for", "interface", ifID) // We use this somewhat like a ring buffer. pkts := make([]*packet, cfg.BatchSize) @@ -1009,7 +1009,7 @@ func (d *DataPlane) runForwarder(ifId uint16, conn BatchConn, cfg *RunConfig, c msgs[i].Buffers = make([][]byte, 1) } - metrics := d.forwardingMetrics[ifId] + metrics := d.forwardingMetrics[ifID] toWrite := 0 for d.running { @@ -1188,16 +1188,16 @@ func (p *scionPacketProcessor) processIntraBFD(data []byte) disposition { return errorDiscard("error", err) } - ifId := uint16(0) + ifID := uint16(0) src := p.pkt.srcAddr.AddrPort() // POSSIBLY EXPENSIVE CONVERSION for k, v := range p.d.internalNextHops { if src == v { - ifId = k + ifID = k break } } - if v, ok := p.d.bfdSessions[ifId]; ok { + if v, ok := p.d.bfdSessions[ifID]; ok { v.ReceiveMessage(bfd) return pDiscard // All's fine. That packet's journey ends here. } @@ -1597,7 +1597,7 @@ func (p *scionPacketProcessor) validateEgressID() disposition { } func (p *scionPacketProcessor) updateNonConsDirIngressSegID() disposition { - // against construction dir the ingress router updates the SegID, ifId == 0 + // against construction dir the ingress router updates the SegID, ifID == 0 // means this comes from this AS itself, so nothing has to be done. // For packets destined to peer links this shouldn't be updated. if !p.infoField.ConsDir && p.pkt.ingress != 0 && !p.peering { @@ -2259,7 +2259,7 @@ type bfdSend struct { // newBFDSend creates and initializes a BFD Sender func newBFDSend(conn BatchConn, srcIA, dstIA addr.IA, srcAddr, dstAddr netip.AddrPort, - ifId uint16, mac hash.Hash) (*bfdSend, error) { + ifID uint16, mac hash.Hash) (*bfdSend, error) { scn := &slayers.SCION{ Version: 0, @@ -2287,7 +2287,7 @@ func newBFDSend(conn BatchConn, srcIA, dstIA addr.IA, srcAddr, dstAddr netip.Add } var ohp *onehop.Path - if ifId == 0 { + if ifID == 0 { scn.PathType = empty.PathType scn.Path = &empty.Path{} } else { @@ -2297,7 +2297,7 @@ func newBFDSend(conn BatchConn, srcIA, dstIA addr.IA, srcAddr, dstAddr netip.Add // Timestamp set in Send }, FirstHop: path.HopField{ - ConsEgress: ifId, + ConsEgress: ifID, ExpTime: hopFieldDefaultExpTime, }, } @@ -2648,11 +2648,11 @@ func nextHdr(layer gopacket.DecodingLayer) slayers.L4ProtocolType { func (d *DataPlane) initMetrics() { d.forwardingMetrics = make(map[uint16]interfaceMetrics) d.forwardingMetrics[0] = newInterfaceMetrics(d.Metrics, 0, d.localIA, d.neighborIAs) - for id := range d.external { - if _, notOwned := d.internalNextHops[id]; notOwned { + for ifID := range d.external { + if _, notOwned := d.internalNextHops[ifID]; notOwned { continue } - d.forwardingMetrics[id] = newInterfaceMetrics(d.Metrics, id, d.localIA, d.neighborIAs) + d.forwardingMetrics[ifID] = newInterfaceMetrics(d.Metrics, ifID, d.localIA, d.neighborIAs) } // Start our custom /proc/pid/stat collector to export iowait time and (in the future) other diff --git a/router/dataplane_test.go b/router/dataplane_test.go index 73a1787301..2ea5e06454 100644 --- a/router/dataplane_test.go +++ b/router/dataplane_test.go @@ -395,9 +395,9 @@ func TestDataPlaneRun(t *testing.T) { local := netip.MustParseAddrPort("10.0.200.100:0") _ = ret.SetKey([]byte("randomkeyformacs")) _ = ret.AddInternalInterface(mInternal, netip.Addr{}) - for remote, ifIds := range routers { - for _, ifId := range ifIds { - _ = ret.AddNextHop(ifId, local, remote, bfd(), "") + for remote, ifIDs := range routers { + for _, ifID := range ifIDs { + _ = ret.AddNextHop(ifID, local, remote, bfd(), "") } } return ret @@ -457,7 +457,7 @@ func TestDataPlaneRun(t *testing.T) { "bfd sender external": { prepareDP: func(ctrl *gomock.Controller, done chan<- struct{}) *router.DataPlane { ret := &router.DataPlane{Metrics: metrics} - ifId := uint16(1) + ifID := uint16(1) mInternal := mock_router.NewMockBatchConn(ctrl) mInternal.EXPECT().ReadBatch(gomock.Any()).Return(0, nil).AnyTimes() @@ -482,7 +482,7 @@ func TestDataPlaneRun(t *testing.T) { if !ok { return 1, nil } - if v.FirstHop.ConsEgress != ifId { + if v.FirstHop.ConsEgress != ifID { return 1, nil } } @@ -502,7 +502,7 @@ func TestDataPlaneRun(t *testing.T) { } _ = ret.SetKey([]byte("randomkeyformacs")) _ = ret.AddInternalInterface(mInternal, netip.Addr{}) - _ = ret.AddExternalInterface(ifId, mExternal, local, remote, bfd()) + _ = ret.AddExternalInterface(ifID, mExternal, local, remote, bfd()) return ret }, }, @@ -510,12 +510,12 @@ func TestDataPlaneRun(t *testing.T) { prepareDP: func(ctrl *gomock.Controller, done chan<- struct{}) *router.DataPlane { ret := &router.DataPlane{Metrics: metrics} - postExternalBFD := func(id layers.BFDDiscriminator, fromIfId uint16) []byte { + postExternalBFD := func(id layers.BFDDiscriminator, fromIfID uint16) []byte { scn := &slayers.SCION{ NextHdr: slayers.L4BFD, PathType: onehop.PathType, Path: &onehop.Path{ - FirstHop: path.HopField{ConsEgress: fromIfId}, + FirstHop: path.HopField{ConsEgress: fromIfID}, }, } bfdL := &layers.BFD{ diff --git a/scion/cmd/scion/common.go b/scion/cmd/scion/common.go index 7e92a9eb6e..edf290ed8d 100644 --- a/scion/cmd/scion/common.go +++ b/scion/cmd/scion/common.go @@ -43,7 +43,7 @@ type Path struct { // Hop represents an hop on the path. type Hop struct { - ID common.IfIdType `json:"interface" yaml:"interface"` + ID common.IfIDType `json:"interface" yaml:"interface"` IA addr.IA `json:"isd_as" yaml:"isd_as"` } diff --git a/scion/cmd/scion/showpaths.go b/scion/cmd/scion/showpaths.go index 79b7ee894b..55141ea5a1 100644 --- a/scion/cmd/scion/showpaths.go +++ b/scion/cmd/scion/showpaths.go @@ -54,8 +54,8 @@ func newShowpaths(pather CommandPather) *cobra.Command { Args: cobra.ExactArgs(1), Example: fmt.Sprintf(` %[1]s showpaths 1-ff00:0:110 --extended %[1]s showpaths 1-ff00:0:110 --local 127.0.0.55 --json - %[1]s showpaths 1-ff00:0:111 --sequence="0-0#2 0*" # outgoing IfId=2 - %[1]s showpaths 1-ff00:0:111 --sequence="0* 0-0#41" # incoming IfId=41 at dstIA + %[1]s showpaths 1-ff00:0:111 --sequence="0-0#2 0*" # outgoing IfID=2 + %[1]s showpaths 1-ff00:0:111 --sequence="0* 0-0#41" # incoming IfID=41 at dstIA %[1]s showpaths 1-ff00:0:111 --sequence="0* 1-ff00:0:112 0*" # 1-ff00:0:112 on the path %[1]s showpaths 1-ff00:0:110 --no-probe`, pather.CommandPath()), Long: fmt.Sprintf(`'showpaths' lists available paths between the local and the specified diff --git a/scion/cmd/scion/traceroute.go b/scion/cmd/scion/traceroute.go index 7a93c8f9aa..addbc9b231 100644 --- a/scion/cmd/scion/traceroute.go +++ b/scion/cmd/scion/traceroute.go @@ -261,7 +261,7 @@ func fmtRemote(remote snet.SCIONAddress, intf uint64) string { if remote == (snet.SCIONAddress{}) { return "??" } - return fmt.Sprintf("%s IfId=%d", remote, intf) + return fmt.Sprintf("%s IfID=%d", remote, intf) } func getHopInfo(u traceroute.Update, hop Hop) HopInfo { diff --git a/scion/showpaths/showpaths.go b/scion/showpaths/showpaths.go index 4d238043bb..621c4bc9af 100644 --- a/scion/showpaths/showpaths.go +++ b/scion/showpaths/showpaths.go @@ -58,7 +58,7 @@ type Path struct { // Hop represents an hop on the path. type Hop struct { - IfId common.IfIdType `json:"ifId"` + IfID common.IfIDType `json:"ifID"` IA addr.IA `json:"isd_as"` } @@ -388,7 +388,7 @@ func Run(ctx context.Context, dst addr.IA, cfg Config) (*Result, error) { Hops: []Hop{}, } for _, hop := range path.Metadata().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/tools/end2end/main.go b/tools/end2end/main.go index c40bf15f25..d16578140d 100644 --- a/tools/end2end/main.go +++ b/tools/end2end/main.go @@ -419,6 +419,6 @@ func readFrom(conn *snet.Conn, pld []byte) (int, net.Addr, error) { } return n, remoteAddr, serrors.WithCtx(err, "isd_as", opErr.RevInfo().IA(), - "interface", opErr.RevInfo().IfId, + "interface", opErr.RevInfo().IfID, ) }