Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/private/common: move IfIDType out of private/common and to its own package #4604

Merged
merged 8 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion control/beacon/beacondbtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ go_library(
deps = [
"//control/beacon:go_default_library",
"//pkg/addr:go_default_library",
"//pkg/private/common:go_default_library",
"//pkg/private/xtest/graph:go_default_library",
"//pkg/segment:go_default_library",
"//pkg/segment/iface:go_default_library",
"//pkg/slayers/path:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
Expand Down
8 changes: 4 additions & 4 deletions control/beacon/beacondbtest/beacondbtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

"github.com/scionproto/scion/control/beacon"
"github.com/scionproto/scion/pkg/addr"
"github.com/scionproto/scion/pkg/private/common"
"github.com/scionproto/scion/pkg/private/xtest/graph"
seg "github.com/scionproto/scion/pkg/segment"
"github.com/scionproto/scion/pkg/segment/iface"
"github.com/scionproto/scion/pkg/slayers/path"
)

Expand Down Expand Up @@ -334,14 +334,14 @@ func InsertBeacon(t *testing.T, db beacon.DB, ases []IfInfo,

type PeerEntry struct {
IA addr.IA
Ingress common.IfIDType
Ingress iface.ID
}

type IfInfo struct {
IA addr.IA
Next addr.IA
Ingress common.IfIDType
Egress common.IfIDType
Ingress iface.ID
Egress iface.ID
Peers []PeerEntry
}

Expand Down
4 changes: 2 additions & 2 deletions control/beaconing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_library(
"//pkg/addr:go_default_library",
"//pkg/log:go_default_library",
"//pkg/metrics:go_default_library",
"//pkg/private/common:go_default_library",
"//pkg/private/prom:go_default_library",
"//pkg/private/serrors:go_default_library",
"//pkg/private/util:go_default_library",
Expand All @@ -31,6 +30,7 @@ go_library(
"//pkg/segment/extensions/digest:go_default_library",
"//pkg/segment/extensions/epic:go_default_library",
"//pkg/segment/extensions/staticinfo:go_default_library",
"//pkg/segment/iface:go_default_library",
"//pkg/slayers/path:go_default_library",
"//pkg/snet:go_default_library",
"//private/periodic:go_default_library",
Expand Down Expand Up @@ -62,7 +62,6 @@ go_test(
"//control/beaconing/mock_beaconing:go_default_library",
"//control/ifstate:go_default_library",
"//pkg/addr:go_default_library",
"//pkg/private/common:go_default_library",
"//pkg/private/serrors:go_default_library",
"//pkg/private/util:go_default_library",
"//pkg/private/xtest/graph:go_default_library",
Expand All @@ -72,6 +71,7 @@ go_test(
"//pkg/scrypto/signed:go_default_library",
"//pkg/segment:go_default_library",
"//pkg/segment/extensions/staticinfo:go_default_library",
"//pkg/segment/iface:go_default_library",
"//pkg/slayers/path:go_default_library",
"//pkg/slayers/path/scion:go_default_library",
"//pkg/snet:go_default_library",
Expand Down
6 changes: 3 additions & 3 deletions control/beaconing/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
package beaconing

import (
"github.com/scionproto/scion/pkg/private/common"
"github.com/scionproto/scion/pkg/segment/extensions/staticinfo"
"github.com/scionproto/scion/pkg/segment/iface"
"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[iface.ID]topology.LinkType,
ingress, egress iface.ID) *staticinfo.Extension {
return cfg.generate(ifType, ingress, egress)
}
80 changes: 40 additions & 40 deletions control/beaconing/staticinfo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ import (
"time"

"github.com/scionproto/scion/control/ifstate"
"github.com/scionproto/scion/pkg/private/common"
"github.com/scionproto/scion/pkg/private/serrors"
"github.com/scionproto/scion/pkg/private/util"
"github.com/scionproto/scion/pkg/segment/extensions/staticinfo"
"github.com/scionproto/scion/pkg/segment/iface"
"github.com/scionproto/scion/private/topology"
)

type InterfaceLatencies struct {
Inter util.DurWrap `json:"Inter"`
Intra map[common.IfIDType]util.DurWrap `json:"Intra"`
Inter util.DurWrap `json:"Inter"`
Intra map[iface.ID]util.DurWrap `json:"Intra"`
}

type InterfaceBandwidths struct {
Inter uint64 `json:"Inter"`
Intra map[common.IfIDType]uint64 `json:"Intra"`
Inter uint64 `json:"Inter"`
Intra map[iface.ID]uint64 `json:"Intra"`
}

type InterfaceGeodata struct {
Expand All @@ -45,7 +45,7 @@ type InterfaceGeodata struct {
}

type InterfaceHops struct {
Intra map[common.IfIDType]uint32 `json:"Intra"`
Intra map[iface.ID]uint32 `json:"Intra"`
}

type LinkType staticinfo.LinkType
Expand Down Expand Up @@ -79,12 +79,12 @@ 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"`
Note string `json:"Note"`
Latency map[iface.ID]InterfaceLatencies `json:"Latency"`
Bandwidth map[iface.ID]InterfaceBandwidths `json:"Bandwidth"`
LinkType map[iface.ID]LinkType `json:"LinkType"`
Geo map[iface.ID]InterfaceGeodata `json:"Geo"`
Hops map[iface.ID]InterfaceHops `json:"Hops"`
Note string `json:"Note"`
}

// ParseStaticInfoCfg parses data from a config file into a StaticInfoCfg struct.
Expand Down Expand Up @@ -135,7 +135,7 @@ func (cfg *StaticInfoCfg) clean() {
}

// symmetrizeLatency makes the Intra latency values symmetric
func symmetrizeLatency(latency map[common.IfIDType]InterfaceLatencies) {
func symmetrizeLatency(latency map[iface.ID]InterfaceLatencies) {
for i, sub := range latency {
delete(sub.Intra, i) // Remove loopy entry
for j, v := range sub.Intra {
Expand All @@ -145,7 +145,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[iface.ID]util.DurWrap),
}
}
vTransposed, ok := latency[j].Intra[i]
Expand All @@ -158,7 +158,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[iface.ID]InterfaceBandwidths) {
for i, sub := range bandwidth {
delete(sub.Intra, i) // Remove loopy entry
for j, v := range sub.Intra {
Expand All @@ -168,7 +168,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[iface.ID]uint64),
}
}
vTransposed, ok := bandwidth[j].Intra[i]
Expand All @@ -181,13 +181,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[iface.ID]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[iface.ID]uint32),
}
}
vTransposed, ok := hops[j].Intra[i]
Expand All @@ -205,11 +205,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, iface.ID(ingress), iface.ID(egress))
}

func (cfg StaticInfoCfg) generate(ifType map[common.IfIDType]topology.LinkType,
ingress, egress common.IfIDType) *staticinfo.Extension {
func (cfg StaticInfoCfg) generate(ifType map[iface.ID]topology.LinkType,
ingress, egress iface.ID) *staticinfo.Extension {

return &staticinfo.Extension{
Latency: cfg.generateLatency(ifType, ingress, egress),
Expand All @@ -223,12 +223,12 @@ 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[iface.ID]topology.LinkType,
ingress, egress iface.ID) staticinfo.LatencyInfo {

l := staticinfo.LatencyInfo{
Intra: make(map[common.IfIDType]time.Duration),
Inter: make(map[common.IfIDType]time.Duration),
Intra: make(map[iface.ID]time.Duration),
Inter: make(map[iface.ID]time.Duration),
}
for ifID, v := range cfg.Latency[egress].Intra {
if includeIntraInfo(ifType, ifID, ingress, egress) {
Expand All @@ -246,12 +246,12 @@ 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[iface.ID]topology.LinkType,
ingress, egress iface.ID) staticinfo.BandwidthInfo {

bw := staticinfo.BandwidthInfo{
Intra: make(map[common.IfIDType]uint64),
Inter: make(map[common.IfIDType]uint64),
Intra: make(map[iface.ID]uint64),
Inter: make(map[iface.ID]uint64),
}
for ifID, v := range cfg.Bandwidth[egress].Intra {
if includeIntraInfo(ifType, ifID, ingress, egress) {
Expand All @@ -269,8 +269,8 @@ 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[iface.ID]topology.LinkType,
egress iface.ID) staticinfo.LinkTypeInfo {

lt := make(staticinfo.LinkTypeInfo)
for ifID, intfLT := range cfg.LinkType {
Expand All @@ -284,8 +284,8 @@ 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[iface.ID]topology.LinkType,
ingress, egress iface.ID) staticinfo.InternalHopsInfo {

ihi := make(staticinfo.InternalHopsInfo)
for ifID, v := range cfg.Hops[egress].Intra {
Expand All @@ -298,8 +298,8 @@ 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[iface.ID]topology.LinkType,
ingress, egress iface.ID) staticinfo.GeoInfo {

gi := staticinfo.GeoInfo{}
for ifID, loc := range cfg.Geo {
Expand Down Expand Up @@ -331,8 +331,8 @@ func (cfg StaticInfoCfg) generateGeo(ifType map[common.IfIDType]topology.LinkTyp
// 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[iface.ID]topology.LinkType,
ifID, ingress, egress iface.ID) bool {

isCoreIngress := (ifType[ingress] == topology.Core || ingress == 0)
isCoreEgress := (ifType[egress] == topology.Core || egress == 0)
Expand All @@ -347,11 +347,11 @@ func includeIntraInfo(ifType map[common.IfIDType]topology.LinkType,
t == topology.Peer
}

func interfaceTypeTable(intfs *ifstate.Interfaces) map[common.IfIDType]topology.LinkType {
func interfaceTypeTable(intfs *ifstate.Interfaces) map[iface.ID]topology.LinkType {
ifMap := intfs.All()
ifTypes := make(map[common.IfIDType]topology.LinkType, len(ifMap))
ifTypes := make(map[iface.ID]topology.LinkType, len(ifMap))
for ifID, ifInfo := range ifMap {
ifTypes[common.IfIDType(ifID)] = ifInfo.TopoInfo().LinkType
ifTypes[iface.ID(ifID)] = ifInfo.TopoInfo().LinkType
}
return ifTypes
}
Loading
Loading