-
Notifications
You must be signed in to change notification settings - Fork 160
/
ifstate.go
99 lines (92 loc) · 3.28 KB
/
ifstate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2018 ETH Zurich, Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package rctrl
import (
"time"
"github.com/scionproto/scion/go/border/internal/metrics"
"github.com/scionproto/scion/go/border/rctx"
"github.com/scionproto/scion/go/lib/addr"
"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/ctrl"
"github.com/scionproto/scion/go/lib/ctrl/path_mgmt"
"github.com/scionproto/scion/go/lib/infra"
"github.com/scionproto/scion/go/lib/snet"
)
const (
// ifStateFreq is how often the router will request an Interface State update
// from the beacon service.
ifStateFreq = 30 * time.Second
)
// IFStateUpdate handles generating periodic Interface State Request (IFStateReq)
// packets that are sent to the local Beacon Service (BS), as well as
// processing the Interface State updates. IFStateReqs are mostly needed on
// startup, to make sure the border router is aware of the status of the local
// interfaces. The BS normally updates the border routers everytime an
// interface state changes, so this is only needed as a fail-safe after
// startup.
func ifStateUpdate() {
if err := genIFStateReq(); err != nil {
logger.Error(err.Error(), nil)
}
for range time.Tick(ifStateFreq) {
if err := genIFStateReq(); err != nil {
logger.Error(err.Error(), nil)
}
}
}
// genIFStateReq generates an Interface State request packet to the local beacon service.
func genIFStateReq() error {
cl := metrics.ControlLabels{
Type: metrics.IFStateReq,
Result: metrics.ErrProcess,
}
cpld, err := ctrl.NewPathMgmtPld(&path_mgmt.IFStateReq{}, nil, nil)
if err != nil {
metrics.Control.Pkts(cl).Inc()
return common.NewBasicError("Generating IFStateReq Ctrl payload", err)
}
scpld, err := cpld.SignedPld(infra.NullSigner)
if err != nil {
metrics.Control.Pkts(cl).Inc()
return common.NewBasicError("Generating IFStateReq signed Ctrl payload", err)
}
pld, err := scpld.PackPld()
if err != nil {
metrics.Control.Pkts(cl).Inc()
return common.NewBasicError("Writing IFStateReq signed Ctrl payload", err)
}
dst := &snet.Addr{
IA: ia,
Host: &addr.AppAddr{L3: addr.SvcBS.Multicast(), L4: addr.NewL4UDPInfo(0)},
}
bsAddrs, err := rctx.Get().ResolveSVCMulti(addr.SvcBS)
if err != nil {
metrics.Control.Pkts(cl).Inc()
return common.NewBasicError("Resolving SVC BS multicast", err)
}
var errors common.MultiError
for _, addr := range bsAddrs {
dst.NextHop = addr
if _, err := snetConn.WriteToSCION(pld, dst); err != nil {
cl.Result = metrics.ErrWrite
metrics.Control.Pkts(cl).Inc()
errors = append(errors, common.NewBasicError("Writing IFStateReq", err, "dst", dst))
continue
}
logger.Debug("Sent IFStateReq", "dst", dst, "overlayDst", addr)
cl.Result = metrics.Success
metrics.Control.Pkts(cl).Inc()
}
return errors.ToError()
}