Skip to content

Commit

Permalink
BS: Max MaxExpTime configurable (#2972)
Browse files Browse the repository at this point in the history
This PR makes the MaxExpTime for segments configurable through the
policy.

fixes #2968
  • Loading branch information
oncilla authored Aug 8, 2019
1 parent 87b7c1d commit 97efff4
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 78 deletions.
1 change: 1 addition & 0 deletions go/beacon_srv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go_library(
"//go/lib/snet:go_default_library",
"//go/lib/sock/reliable:go_default_library",
"//go/lib/sock/reliable/reconnect:go_default_library",
"//go/lib/spath:go_default_library",
"//go/lib/topology:go_default_library",
"//go/proto:go_default_library",
"@com_github_burntsushi_toml//:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/beacon/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go_library(
"//go/lib/infra/modules/db:go_default_library",
"//go/lib/log:go_default_library",
"//go/lib/prom:go_default_library",
"//go/lib/spath:go_default_library",
"//go/proto:go_default_library",
"@com_github_opentracing_opentracing_go//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
Expand Down
28 changes: 18 additions & 10 deletions go/beacon_srv/internal/beacon/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/spath"
)

// PolicyType is the policy type.
Expand All @@ -44,6 +45,8 @@ const (
DefaultCandidateSetSize = 100
// DefaultMaxHopsLength is the default MaxHopsLength value.
DefaultMaxHopsLength = 10
// DefaultMaxExpTime is the default MaxExpTime value.
DefaultMaxExpTime = spath.DefaultHopFExpiry
)

// Policies keeps track of all policies for a non-core beacon store.
Expand Down Expand Up @@ -178,6 +181,9 @@ type Policy struct {
// CandidateSetSize is the number of segments to consider for
// selection.
CandidateSetSize int `yaml:"CandidateSetSize"`
// MaxExpTime indicates the maximum value for the expiration time when
// extending the segment.
MaxExpTime *spath.ExpTimeType `yaml:"MaxExpTime"`
// Filter is the filter applied to segments.
Filter Filter `yaml:"Filter"`
// Type is the policy type.
Expand All @@ -192,14 +198,21 @@ func (p *Policy) InitDefaults() {
if p.CandidateSetSize == 0 {
p.CandidateSetSize = DefaultCandidateSetSize
}
if p.MaxExpTime == nil {
m := DefaultMaxExpTime
p.MaxExpTime = &m
}
p.Filter.InitDefaults()
}

func (p *Policy) initDefaults(t PolicyType) {
func (p *Policy) initDefaults(t PolicyType) error {
p.InitDefaults()
if p.Type == "" {
p.Type = t
if p.Type != "" && p.Type != t {
return common.NewBasicError("Specified policy type does not match", nil,
"expected", t, "actual", p.Type)
}
p.Type = t
return nil
}

// ParseYaml parses the policy in yaml format and initializes the default values.
Expand All @@ -208,13 +221,8 @@ func ParseYaml(b common.RawBytes, t PolicyType) (*Policy, error) {
if err := yaml.Unmarshal(b, p); err != nil {
return nil, common.NewBasicError("Unable to parse policy", err)
}
p.InitDefaults()
if p.Type == "" {
p.Type = t
}
if p.Type != t {
return nil, common.NewBasicError("Specified policy type does not match", nil,
"expected", t, "actual", p.Type)
if err := p.initDefaults(t); err != nil {
return nil, err
}
return p, nil
}
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/beacon/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestLoadFromYaml(t *testing.T) {
SoMsg("BestSetSize", p.BestSetSize, ShouldEqual, 6)
SoMsg("CandidateSetSize", p.CandidateSetSize, ShouldEqual, 20)
SoMsg("Type", p.Type, ShouldEqual, t)
SoMsg("MaxExpTime", *p.MaxExpTime, ShouldEqual, 42)
SoMsg("MaxHopsLength", p.Filter.MaxHopsLength, ShouldEqual, 8)
SoMsg("AsBlackList", p.Filter.AsBlackList, ShouldResemble, []addr.AS{ia110.A, ia111.A})
SoMsg("IsdBlackList", p.Filter.IsdBlackList, ShouldResemble, []addr.ISD{1, 2, 3})
Expand Down
31 changes: 28 additions & 3 deletions go/beacon_srv/internal/beacon/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/log"
"github.com/scionproto/scion/go/lib/spath"
"github.com/scionproto/scion/go/proto"
)

Expand Down Expand Up @@ -72,10 +73,10 @@ func (s *Store) BeaconsToPropagate(ctx context.Context) (<-chan BeaconOrErr, err
func (s *Store) SegmentsToRegister(ctx context.Context, segType proto.PathSegType) (
<-chan BeaconOrErr, error) {

switch {
case segType == proto.PathSegType_down:
switch segType {
case proto.PathSegType_down:
return s.getBeacons(ctx, &s.policies.DownReg)
case segType == proto.PathSegType_up:
case proto.PathSegType_up:
return s.getBeacons(ctx, &s.policies.UpReg)
default:
return nil, common.NewBasicError("Unsupported segment type", nil, "type", segType)
Expand All @@ -99,6 +100,19 @@ func (s *Store) getBeacons(ctx context.Context, policy *Policy) (<-chan BeaconOr
return results, nil
}

// MaxExpTime returns the segment maximum expiration time for the given policy.
func (s *Store) MaxExpTime(policyType PolicyType) spath.ExpTimeType {
switch policyType {
case UpRegPolicy:
return *s.policies.UpReg.MaxExpTime
case DownRegPolicy:
return *s.policies.DownReg.MaxExpTime
case PropPolicy:
return *s.policies.Prop.MaxExpTime
}
return DefaultMaxExpTime
}

// CoreStore provides abstracted access to the beacon database in a core AS. The
// store helps inserting beacons and revocations, and selects the best beacons
// for given purposes based on the configured policies. It should not be used in
Expand Down Expand Up @@ -184,6 +198,17 @@ func (s *CoreStore) getBeacons(ctx context.Context, policy *Policy) (<-chan Beac
return results, nil
}

// MaxExpTime returns the segment maximum expiration time for the given policy.
func (s *CoreStore) MaxExpTime(policyType PolicyType) spath.ExpTimeType {
switch policyType {
case CoreRegPolicy:
return *s.policies.CoreReg.MaxExpTime
case PropPolicy:
return *s.policies.Prop.MaxExpTime
}
return DefaultMaxExpTime
}

// baseStore is the basis for the beacon store.
type baseStore struct {
db DB
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/beacon/testdata/policy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
BestSetSize: 6
CandidateSetSize: 20
MaxExpTime: 42
Filter:
MaxHopsLength: 8
AsBlackList: ["ff00:0:110", "ff00:0:111"]
Expand Down
1 change: 1 addition & 0 deletions go/beacon_srv/internal/beacon/testdata/typedPolicy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
BestSetSize: 6
CandidateSetSize: 20
MaxExpTime: 42
Filter:
MaxHopsLength: 8
AsBlackList: ["ff00:0:110", "ff00:0:111"]
Expand Down
11 changes: 8 additions & 3 deletions go/beacon_srv/internal/beaconing/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ func (s *segExtender) createHopF(inIfid, egIfid common.IFIDType, prev common.Raw
return nil, common.NewBasicError("Chain does not cover minimum hop expiration time", nil,
"minimumExpiration", min, "chainExpiration", meta.ExpTime, "src", meta.Src)
}
if expiry > s.cfg.maxExpTime {
expiry = s.cfg.maxExpTime
}
expiry = min(expiry, s.cfg.GetMaxExpTime())
hop := &spath.HopField{
ConsIngress: inIfid,
ConsEgress: egIfid,
Expand All @@ -191,3 +189,10 @@ func (s *segExtender) IntfActive(ifid common.IFIDType) bool {
intf := s.cfg.Intfs.Get(ifid)
return intf != nil && intf.State() == ifstate.Active
}

func min(a, b spath.ExpTimeType) spath.ExpTimeType {
if a > b {
return b
}
return a
}
15 changes: 2 additions & 13 deletions go/beacon_srv/internal/beaconing/extender_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ type ExtenderConf struct {
MTU uint16
// IfidSize is the bit-size of the ifid in the hop-fields.
IfidSize uint8
// MaxExpTime is the maximum relative expiration time.
MaxExpTime *spath.ExpTimeType
// maxExpTime is a copy of MaxExpTime to avoid using the captured
// reference from the calling code.
maxExpTime spath.ExpTimeType
// GetMaxExpTime returns the maximum relative expiration time.
GetMaxExpTime func() spath.ExpTimeType
// task contains an identifier specific to the task that uses the extender.
task string
}
Expand All @@ -54,10 +51,6 @@ func (cfg *ExtenderConf) InitDefaults() {
if cfg.IfidSize == 0 {
cfg.IfidSize = DefaultIfidSize
}
if cfg.MaxExpTime == nil {
expiry := spath.DefaultHopFExpiry
cfg.MaxExpTime = &expiry
}
}

// Validate checks that the config contains a signer.
Expand All @@ -71,9 +64,5 @@ func (cfg *ExtenderConf) Validate() error {
if cfg.MTU == 0 {
return common.NewBasicError("MTU must be set", nil)
}
if cfg.MaxExpTime == nil {
return common.NewBasicError("MaxExpTime must be set", nil)
}
cfg.maxExpTime = *cfg.MaxExpTime
return nil
}
36 changes: 22 additions & 14 deletions go/beacon_srv/internal/beaconing/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/beacon_srv/internal/beacon"
"github.com/scionproto/scion/go/beacon_srv/internal/ifstate"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
Expand Down Expand Up @@ -116,10 +117,11 @@ func TestExtenderExtend(t *testing.T) {
intfs.Get(graph.If_111_A_112_X).Activate(graph.If_112_X_111_A)
intfs.Get(peer).Activate(graph.If_121_X_111_C)
ext, err := ExtenderConf{
MTU: 1337,
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: intfs,
MTU: 1337,
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: intfs,
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
}.new()
SoMsg("err", err, ShouldBeNil)
// Create path segment from description, if available.
Expand Down Expand Up @@ -185,13 +187,12 @@ func TestExtenderExtend(t *testing.T) {
intfs := ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{})
xtest.FailOnErr(t, err)
intfs.Get(graph.If_111_B_120_X).Activate(graph.If_120_X_111_B)
var maxExpTime = spath.ExpTimeType(1)
ext, err := ExtenderConf{
MTU: 1337,
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
MaxExpTime: &maxExpTime,
Intfs: intfs,
MTU: 1337,
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
GetMaxExpTime: maxExpTimeFactory(1),
Intfs: intfs,
}.new()
SoMsg("err", err, ShouldBeNil)
pseg := testBeacon(g, segDesc).Segment
Expand All @@ -209,10 +210,11 @@ func TestExtenderExtend(t *testing.T) {
intfs := ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{})
xtest.FailOnErr(t, err)
ext, err := ExtenderConf{
MTU: 1337,
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: intfs,
MTU: 1337,
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: intfs,
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
}.new()
SoMsg("err", err, ShouldBeNil)
pseg := testBeacon(g, segDesc).Segment
Expand Down Expand Up @@ -324,3 +326,9 @@ type failSigner struct {
func (f *failSigner) Sign(msg common.RawBytes) (*proto.SignS, error) {
return nil, errors.New("fail")
}

func maxExpTimeFactory(max spath.ExpTimeType) func() spath.ExpTimeType {
return func() spath.ExpTimeType {
return max
}
}
19 changes: 11 additions & 8 deletions go/beacon_srv/internal/beaconing/originator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/smartystreets/goconvey/convey"

"github.com/scionproto/scion/go/beacon_srv/internal/beacon"
"github.com/scionproto/scion/go/beacon_srv/internal/ifstate"
"github.com/scionproto/scion/go/beacon_srv/internal/onehop"
"github.com/scionproto/scion/go/lib/addr"
Expand Down Expand Up @@ -59,10 +60,11 @@ func TestOriginatorRun(t *testing.T) {
conn := mock_snet.NewMockPacketConn(mctrl)
o, err := OriginatorConf{
Config: ExtenderConf{
MTU: uint16(topoProvider.Get().MTU),
Signer: signer,
Intfs: intfs,
Mac: mac,
MTU: uint16(topoProvider.Get().MTU),
Signer: signer,
Intfs: intfs,
Mac: mac,
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Period: time.Hour,
BeaconSender: &onehop.BeaconSender{
Expand Down Expand Up @@ -112,10 +114,11 @@ func TestOriginatorRun(t *testing.T) {
conn := mock_snet.NewMockPacketConn(mctrl)
o, err := OriginatorConf{
Config: ExtenderConf{
MTU: uint16(topoProvider.Get().MTU),
Signer: signer,
Intfs: intfs,
Mac: mac,
MTU: uint16(topoProvider.Get().MTU),
Signer: signer,
Intfs: intfs,
Mac: mac,
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Period: 2 * time.Second,
BeaconSender: &onehop.BeaconSender{
Expand Down
12 changes: 8 additions & 4 deletions go/beacon_srv/internal/beaconing/propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ func TestPropagatorRun(t *testing.T) {
Config: ExtenderConf{
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: macProp,
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap,
ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Period: time.Hour,
BeaconProvider: provider,
Expand Down Expand Up @@ -218,8 +220,10 @@ func TestPropagatorRun(t *testing.T) {
Config: ExtenderConf{
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: macProp,
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap,
ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Period: 2 * time.Second,
BeaconProvider: provider,
Expand Down
18 changes: 12 additions & 6 deletions go/beacon_srv/internal/beaconing/registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ func TestRegistrarRun(t *testing.T) {
Config: ExtenderConf{
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap,
ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Period: time.Hour,
Msgr: msgr,
Expand Down Expand Up @@ -190,8 +192,10 @@ func TestRegistrarRun(t *testing.T) {
Config: ExtenderConf{
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap,
ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Msgr: msgr,
SegProvider: segProvider,
Expand Down Expand Up @@ -227,8 +231,10 @@ func TestRegistrarRun(t *testing.T) {
Config: ExtenderConf{
Signer: testSigner(t, priv, topoProvider.Get().ISD_AS),
Mac: mac,
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap, ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
Intfs: ifstate.NewInterfaces(topoProvider.Get().IFInfoMap,
ifstate.Config{}),
MTU: uint16(topoProvider.Get().MTU),
GetMaxExpTime: maxExpTimeFactory(beacon.DefaultMaxExpTime),
},
Msgr: msgr,
SegProvider: segProvider,
Expand Down
Loading

0 comments on commit 97efff4

Please sign in to comment.