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

hp: add topology support #3940

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 6 additions & 8 deletions go/lib/topology/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Topology interface {
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
MakeHostInfos(st ServiceType) ([]net.UDPAddr, error)

// Gateways returns an array of all gateways.
Gateways() ([]GatewayInfo, error)
Expand Down Expand Up @@ -190,20 +190,18 @@ func (t *topologyS) UnderlayNextHop2(ifid common.IFIDType) (*net.UDPAddr, bool)
return copyUDPAddr(ifInfo.InternalAddr), true
}

func (t *topologyS) MakeHostInfos(st ServiceType) []net.UDPAddr {
func (t *topologyS) MakeHostInfos(st ServiceType) ([]net.UDPAddr, error) {
var hostInfos []net.UDPAddr
addresses, err := t.Topology.GetAllTopoAddrs(st)
addresses, err := t.Topology.getAllTopoAddrs(st)
if err != nil {
// FIXME(lukedirtwalker): inform client about this:
// see https://github.com/scionproto/scion/issues/1673
return hostInfos
return nil, err
}
for _, a := range addresses {
if tmp := a.SCIONAddress; tmp != nil {
hostInfos = append(hostInfos, *tmp)
}
}
return hostInfos
return hostInfos, nil
}

func (t *topologyS) Core() bool {
Expand Down Expand Up @@ -339,7 +337,7 @@ func (t *topologyS) UnderlayMulticast(svc addr.HostSVC) ([]*net.UDPAddr, error)
if err != nil {
return nil, err
}
topoAddrs, err := t.Topology.GetAllTopoAddrs(st)
topoAddrs, err := t.Topology.getAllTopoAddrs(st)
if err != nil {
return nil, serrors.Wrap(addr.ErrUnsupportedSVCAddress, err, "svc", svc)
}
Expand Down
12 changes: 7 additions & 5 deletions go/lib/topology/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ type Topology struct {
MTU int `json:"mtu"`
// Attributes are the primary AS attributes as described in
// https://github.com/scionproto/scion/blob/master/doc/ControlPlanePKI.md#primary-ases
Attributes []Attribute `json:"attributes"`
BorderRouters map[string]*BRInfo `json:"border_routers,omitempty"`
ControlService map[string]*ServerInfo `json:"control_service,omitempty"`
DiscoveryService map[string]*ServerInfo `json:"discovery_service,omitempty"`
SIG map[string]*GatewayInfo `json:"sigs,omitempty"`
Attributes []Attribute `json:"attributes"`
BorderRouters map[string]*BRInfo `json:"border_routers,omitempty"`
ControlService map[string]*ServerInfo `json:"control_service,omitempty"`
DiscoveryService map[string]*ServerInfo `json:"discovery_service,omitempty"`
HiddenSegmentLookup map[string]*ServerInfo `json:"hidden_segment_lookup_service,omitempty"`
HiddenSegmentReg map[string]*ServerInfo `json:"hidden_segment_registration_service,omitempty"`
SIG map[string]*GatewayInfo `json:"sigs,omitempty"`
}

// ServerInfo contains the information for a SCION application running in the local AS.
Expand Down
5 changes: 3 additions & 2 deletions go/lib/topology/mock_topology/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions go/lib/topology/servicetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
Control
Discovery
Gateway
HiddenSegmentLookup
HiddenSegmentRegistration
)

func (t ServiceType) String() string {
Expand All @@ -38,6 +40,10 @@ func (t ServiceType) String() string {
return "discovery"
case Gateway:
return "gateway"
case HiddenSegmentLookup:
return "hiddensegmentlookup"
case HiddenSegmentRegistration:
return "hiddensegmentregistration"
default:
return "unknown"
}
Expand All @@ -54,6 +60,10 @@ func ServiceTypeFromString(s string) ServiceType {
return Discovery
case "gateway":
return Gateway
case "hiddensegmentlookup":
return HiddenSegmentLookup
case "hiddensegmentregistration":
return HiddenSegmentRegistration
default:
return Unknown
}
Expand Down
2 changes: 2 additions & 0 deletions go/lib/topology/servicetype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestServiceTypeStringAndParse(t *testing.T) {
topology.Control,
topology.Discovery,
topology.Gateway,
topology.HiddenSegmentLookup,
topology.HiddenSegmentRegistration,
}
for _, st := range serviceTypes {
t.Run(st.String(), func(t *testing.T) {
Expand Down
50 changes: 35 additions & 15 deletions go/lib/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import (
// EndhostPort is the underlay port that the dispatcher binds to on non-routers.
const EndhostPort = underlay.EndhostPort

// ErrAddressNotFound indicates the address was not found.
var ErrAddressNotFound = serrors.New("address not found")

type (
// RWTopology is the topology type for applications and libraries that need write
// access to AS topology information (e.g., discovery, topology reloaders).
Expand Down Expand Up @@ -64,9 +67,11 @@ type (
BRNames []string
IFInfoMap IfInfoMap

CS IDAddrMap
DS IDAddrMap
SIG map[string]GatewayInfo
CS IDAddrMap
DS IDAddrMap
HiddenSegmentLookup IDAddrMap
HiddenSegmentRegistration IDAddrMap
SIG map[string]GatewayInfo
}

// GatewayInfo describes a scion gateway.
Expand Down Expand Up @@ -137,11 +142,13 @@ type (
// NewRWTopology creates new empty Topo object, including all possible service maps etc.
func NewRWTopology() *RWTopology {
return &RWTopology{
BR: make(map[string]BRInfo),
CS: make(IDAddrMap),
DS: make(IDAddrMap),
SIG: make(map[string]GatewayInfo),
IFInfoMap: make(IfInfoMap),
BR: make(map[string]BRInfo),
CS: make(IDAddrMap),
DS: make(IDAddrMap),
HiddenSegmentLookup: make(IDAddrMap),
HiddenSegmentRegistration: make(IDAddrMap),
SIG: make(map[string]GatewayInfo),
IFInfoMap: make(IfInfoMap),
}
}

Expand Down Expand Up @@ -306,7 +313,14 @@ func (t *RWTopology) populateServices(raw *jsontopo.Topology) error {
if err != nil {
return serrors.WrapStr("unable to extract DS address", err)
}

t.HiddenSegmentLookup, err = svcMapFromRaw(raw.HiddenSegmentLookup)
if err != nil {
return serrors.WrapStr("unable to extract hidden segment lookup address", err)
}
t.HiddenSegmentRegistration, err = svcMapFromRaw(raw.HiddenSegmentReg)
if err != nil {
return serrors.WrapStr("unable to extract hidden segment registration address", err)
}
return nil
}

Expand All @@ -330,15 +344,15 @@ func (t *RWTopology) GetTopoAddr(id string, svc ServiceType) (*TopoAddr, error)
return topoAddr, nil
}

// GetAllTopoAddrs returns the address information of all processes of the requested type.
func (t *RWTopology) GetAllTopoAddrs(svc ServiceType) ([]TopoAddr, error) {
// getAllTopoAddrs returns the address information of all processes of the requested type.
func (t *RWTopology) getAllTopoAddrs(svc ServiceType) ([]TopoAddr, error) {
svcInfo, err := t.getSvcInfo(svc)
if err != nil {
return nil, err
}
topoAddrs := svcInfo.getAllTopoAddrs()
if topoAddrs == nil {
return nil, serrors.New("Address not found")
return nil, ErrAddressNotFound
}
return topoAddrs, nil
}
Expand All @@ -351,6 +365,10 @@ func (t *RWTopology) getSvcInfo(svc ServiceType) (*svcInfo, error) {
return &svcInfo{idTopoAddrMap: t.DS}, nil
case Control:
return &svcInfo{idTopoAddrMap: t.CS}, nil
case HiddenSegmentLookup:
return &svcInfo{idTopoAddrMap: t.HiddenSegmentLookup}, nil
case HiddenSegmentRegistration:
return &svcInfo{idTopoAddrMap: t.HiddenSegmentRegistration}, nil
case Gateway:
m := make(IDAddrMap)
for k, v := range t.SIG {
Expand All @@ -377,9 +395,11 @@ func (t *RWTopology) Copy() *RWTopology {
BRNames: append(t.BRNames[:0:0], t.BRNames...),
IFInfoMap: t.IFInfoMap.copy(),

CS: t.CS.copy(),
DS: t.DS.copy(),
SIG: copySIGMap(t.SIG),
CS: t.CS.copy(),
DS: t.DS.copy(),
SIG: copySIGMap(t.SIG),
HiddenSegmentLookup: t.HiddenSegmentLookup.copy(),
HiddenSegmentRegistration: t.HiddenSegmentRegistration.copy(),
}
}

Expand Down
1 change: 1 addition & 0 deletions go/pkg/discovery/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ go_test(
"//go/lib/topology:go_default_library",
"//go/pkg/proto/discovery:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
],
)
2 changes: 1 addition & 1 deletion go/pkg/discovery/testdata/topology.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"isd_as": "1-ff00:0:311",
"sigs": {
"sig1-ff00:0:311-1": {
Expand Down
30 changes: 27 additions & 3 deletions go/pkg/discovery/toposervice.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package discovery

import (
"context"
"errors"
"net"

"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -86,9 +87,32 @@ func (t Topology) HiddenSegmentServices(ctx context.Context,
labels := requestLabels{ReqType: "hidden_segment_services"}
logger := log.FromCtx(ctx)

logger.Debug("Hidden segment services currently not supported")
t.updateTelemetry(span, labels.WithResult("err_unimplemented"), nil)
return nil, status.Error(codes.Unimplemented, "not supported")
topo := t.Provider.Get()
lookups, err := topo.MakeHostInfos(topology.HiddenSegmentLookup)
if err != nil && !errors.Is(err, topology.ErrAddressNotFound) {
return nil, err
}
registration, err := topo.MakeHostInfos(topology.HiddenSegmentRegistration)
if err != nil && !errors.Is(err, topology.ErrAddressNotFound) {
return nil, err
}

response := &dpb.HiddenSegmentServicesResponse{}
for _, l := range lookups {
response.Lookup = append(response.Lookup, &dpb.HiddenSegmentLookupServer{
Address: l.String(),
})
}
for _, r := range registration {
response.Registration = append(response.Registration, &dpb.HiddenSegmentRegistrationServer{
Address: r.String(),
})
}

logger.Debug("Replied with hidden segment services",
"lookups", len(lookups), "registration", len(registration))
t.updateTelemetry(span, labels.WithResult(prom.Success), nil)
return response, nil
}

// RequestsLabels exposes the labels required by the Requests metric.
Expand Down
Loading