diff --git a/control/beacon/beacon.go b/control/beacon/beacon.go index 6378247870..30d71d4a2e 100644 --- a/control/beacon/beacon.go +++ b/control/beacon/beacon.go @@ -60,5 +60,5 @@ func (b Beacon) String() string { } func link(entry seg.ASEntry) (addr.IA, uint16) { - return entry.Local, entry.HopEntry.HopField.ConsIngress + return entry.Local, entry.HopEntry.HopField.ConsEgress } diff --git a/control/beacon/beacon_test.go b/control/beacon/beacon_test.go index 194cff6c15..d82388ec5b 100644 --- a/control/beacon/beacon_test.go +++ b/control/beacon/beacon_test.go @@ -20,14 +20,19 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/scionproto/scion/control/beacon" + "github.com/scionproto/scion/pkg/addr" "github.com/scionproto/scion/pkg/private/xtest/graph" + "github.com/scionproto/scion/pkg/segment" ) // TestBeaconDiversity tests that diversity is calculated correctly. func TestBeaconDiversity(t *testing.T) { var tests = []struct { - name string - beacon []uint16 + name string + beacon []uint16 + // mBeacon allows to manually specify the other beacon. + mBeacon beacon.Beacon diversity int }{ { @@ -51,6 +56,36 @@ func TestBeaconDiversity(t *testing.T) { }, diversity: 2, }, + { + name: "Last link distinct", + mBeacon: beacon.Beacon{ + Segment: &segment.PathSegment{ + ASEntries: []segment.ASEntry{ + { + Local: addr.MustParseIA("1-ff00:0:130"), + Next: addr.MustParseIA("1-ff00:0:110"), + HopEntry: segment.HopEntry{ + HopField: segment.HopField{ + ConsEgress: graph.If_130_A_110_X, + }, + }, + }, + { + Local: addr.MustParseIA("1-ff00:0:110"), + Next: addr.MustParseIA("2-ff00:0:210"), + HopEntry: segment.HopEntry{ + HopField: segment.HopField{ + ConsIngress: graph.If_110_X_130_A, + ConsEgress: 2321, + }, + }, + }, + }, + }, + InIfID: 2123, + }, + diversity: 1, + }, } mctrl := gomock.NewController(t) @@ -58,7 +93,10 @@ func TestBeaconDiversity(t *testing.T) { bseg := testBeacon(g, tests[0].beacon...) for _, test := range tests { t.Run(test.name, func(t *testing.T) { - other := testBeacon(g, test.beacon...) + other := test.mBeacon + if len(test.beacon) > 0 { + other = testBeacon(g, test.beacon...) + } diversity := bseg.Diversity(other) assert.Equal(t, test.diversity, diversity) }) diff --git a/control/beacon/store_test.go b/control/beacon/store_test.go index db1fcdd2de..5fc2dcdcab 100644 --- a/control/beacon/store_test.go +++ b/control/beacon/store_test.go @@ -274,10 +274,9 @@ func testCoreStoreSelection(t *testing.T, } func testBeacon(g *graph.Graph, desc ...uint16) beacon.Beacon { - pseg := testSegment(g, desc) - asEntry := pseg.ASEntries[pseg.MaxIdx()] + pseg := testSegment(g, desc[:len(desc)-1]) return beacon.Beacon{ - InIfID: asEntry.HopEntry.HopField.ConsIngress, + InIfID: desc[len(desc)-1], Segment: pseg, } }