Skip to content

Commit

Permalink
Merge branch 'master' into wipInIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
jiceatscion authored Jul 24, 2024
2 parents 21a9374 + 42e7811 commit f0c8e2e
Show file tree
Hide file tree
Showing 85 changed files with 839 additions and 779 deletions.
10 changes: 10 additions & 0 deletions .golangcilint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
disable-all: true
enable:
# Default linters.
- forbidigo
- errcheck
- gosimple
- govet
Expand All @@ -19,6 +20,15 @@ linters:
- misspell
- goheader
linters-settings:
# ...
forbidigo:
forbid:
- p: "([iI][fF][iI]d)|([iI]F[iI][dD])|([iI][fF]i[dD])"
msg: "spell interface ID as ifID / IfID"
- p: "(?i)interfaceID" # case insensitive
msg: "spell interface ID as ifID / IfID"
- p: "Trc"
msg: "spell trust root certificate as trc / TRC"
lll:
line-length: 100
tab-width: 4
Expand Down
12 changes: 6 additions & 6 deletions control/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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) {
Expand Down
16 changes: 8 additions & 8 deletions control/beacon/beacondbtest/beacondbtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {

Expand Down Expand Up @@ -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()
}
6 changes: 3 additions & 3 deletions control/beacon/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions control/beaconing/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions control/beaconing/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions control/beaconing/grpc/beacon_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion control/beaconing/grpc/creation_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions control/beaconing/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions control/beaconing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}()

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions control/beaconing/originator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand All @@ -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()
Expand Down Expand Up @@ -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()
}

Expand Down
8 changes: 4 additions & 4 deletions control/beaconing/originator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand All @@ -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
},
Expand Down
Loading

0 comments on commit f0c8e2e

Please sign in to comment.