Skip to content

Commit 5b89505

Browse files
matzfjuagargi
authored andcommitted
Add Carbon Intensity information to beacons and paths (scionproto#129)
* Add Carbon Intensity Information to beacons First crude version, just to allow adding _some_ numbers. Note: not merged code paths with bandwidth although this is currently processed identically, as changes to the representation of the carbon intensity information are to be expected. * Add Carbon Intensity to combinator, snet.Path and showpaths * Resolved conflict in daemon protobuf file by incrementing field number. Recreated protobuf generated file. * Resolved conflicts in other places due to diff not matching original, by adding the carbon intentity field in data structures/initializations again to the upstream ones.
1 parent a1ed624 commit 5b89505

File tree

17 files changed

+892
-419
lines changed

17 files changed

+892
-419
lines changed

control/beaconing/staticinfo_config.go

+70-12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ type InterfaceBandwidths struct {
3838
Intra map[common.IFIDType]uint64 `json:"Intra"`
3939
}
4040

41+
type InterfaceCarbonIntensities struct {
42+
Inter uint64 `json:"Inter"`
43+
Intra map[common.IFIDType]uint64 `json:"Intra"`
44+
}
45+
4146
type InterfaceGeodata struct {
4247
Longitude float32 `json:"Longitude"`
4348
Latitude float32 `json:"Latitude"`
@@ -79,12 +84,13 @@ func (l *LinkType) UnmarshalText(text []byte) error {
7984

8085
// StaticInfoCfg is used to parse data from config.json.
8186
type StaticInfoCfg struct {
82-
Latency map[common.IFIDType]InterfaceLatencies `json:"Latency"`
83-
Bandwidth map[common.IFIDType]InterfaceBandwidths `json:"Bandwidth"`
84-
LinkType map[common.IFIDType]LinkType `json:"LinkType"`
85-
Geo map[common.IFIDType]InterfaceGeodata `json:"Geo"`
86-
Hops map[common.IFIDType]InterfaceHops `json:"Hops"`
87-
Note string `json:"Note"`
87+
Latency map[common.IFIDType]InterfaceLatencies `json:"Latency"`
88+
Bandwidth map[common.IFIDType]InterfaceBandwidths `json:"Bandwidth"`
89+
CarbonIntensity map[common.IFIDType]InterfaceCarbonIntensities `json:"CarbonIntensity"`
90+
LinkType map[common.IFIDType]LinkType `json:"LinkType"`
91+
Geo map[common.IFIDType]InterfaceGeodata `json:"Geo"`
92+
Hops map[common.IFIDType]InterfaceHops `json:"Hops"`
93+
Note string `json:"Note"`
8894
}
8995

9096
// ParseStaticInfoCfg parses data from a config file into a StaticInfoCfg struct.
@@ -120,6 +126,10 @@ func (cfg *StaticInfoCfg) clean() {
120126
for _, s := range cfg.Bandwidth {
121127
delete(s.Intra, 0)
122128
}
129+
delete(cfg.CarbonIntensity, 0)
130+
for _, s := range cfg.CarbonIntensity {
131+
delete(s.Intra, 0)
132+
}
123133
delete(cfg.LinkType, 0)
124134
delete(cfg.Geo, 0)
125135
delete(cfg.Hops, 0)
@@ -129,6 +139,7 @@ func (cfg *StaticInfoCfg) clean() {
129139

130140
symmetrizeLatency(cfg.Latency)
131141
symmetrizeBandwidth(cfg.Bandwidth)
142+
symmetrizeCarbonIntensity(cfg.CarbonIntensity)
132143
symmetrizeHops(cfg.Hops)
133144
}
134145

@@ -178,6 +189,29 @@ func symmetrizeBandwidth(bandwidth map[common.IFIDType]InterfaceBandwidths) {
178189
}
179190
}
180191

192+
// symmetrizeCarbonIntensity makes the Intra carbon intensity values symmetric
193+
func symmetrizeCarbonIntensity(carbonIntensity map[common.IFIDType]InterfaceCarbonIntensities) {
194+
for i, sub := range carbonIntensity {
195+
delete(sub.Intra, i) // Remove loopy entry
196+
for j, v := range sub.Intra {
197+
if _, ok := carbonIntensity[j]; !ok {
198+
continue
199+
}
200+
if carbonIntensity[j].Intra == nil {
201+
carbonIntensity[j] = InterfaceCarbonIntensities{
202+
Inter: carbonIntensity[j].Inter,
203+
Intra: make(map[common.IFIDType]uint64),
204+
}
205+
}
206+
vTransposed, ok := carbonIntensity[j].Intra[i]
207+
// Set if not specified or pick more conservative value if both are specified
208+
if !ok || v < vTransposed {
209+
carbonIntensity[j].Intra[i] = v
210+
}
211+
}
212+
}
213+
}
214+
181215
// symmetrizeHops makes the Intra hops values symmetric
182216
func symmetrizeHops(hops map[common.IFIDType]InterfaceHops) {
183217
for i, sub := range hops {
@@ -210,12 +244,13 @@ func (cfg StaticInfoCfg) generate(ifType map[common.IFIDType]topology.LinkType,
210244
ingress, egress common.IFIDType) *staticinfo.Extension {
211245

212246
return &staticinfo.Extension{
213-
Latency: cfg.generateLatency(ifType, ingress, egress),
214-
Bandwidth: cfg.generateBandwidth(ifType, ingress, egress),
215-
Geo: cfg.generateGeo(ifType, ingress, egress),
216-
LinkType: cfg.generateLinkType(ifType, egress),
217-
InternalHops: cfg.generateInternalHops(ifType, ingress, egress),
218-
Note: cfg.Note,
247+
Latency: cfg.generateLatency(ifType, ingress, egress),
248+
Bandwidth: cfg.generateBandwidth(ifType, ingress, egress),
249+
CarbonIntensity: cfg.generateCarbonIntensity(ifType, ingress, egress),
250+
Geo: cfg.generateGeo(ifType, ingress, egress),
251+
LinkType: cfg.generateLinkType(ifType, egress),
252+
InternalHops: cfg.generateInternalHops(ifType, ingress, egress),
253+
Note: cfg.Note,
219254
}
220255
}
221256

@@ -265,6 +300,29 @@ func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IFIDType]topology.L
265300
return bw
266301
}
267302

303+
// generateCarbonIntensity creates the BandwidthInfo by extracting the relevant values
304+
// from the config.
305+
func (cfg StaticInfoCfg) generateCarbonIntensity(ifType map[common.IFIDType]topology.LinkType,
306+
ingress, egress common.IFIDType) staticinfo.CarbonIntensityInfo {
307+
308+
ci := staticinfo.CarbonIntensityInfo{
309+
Intra: make(map[common.IFIDType]uint64),
310+
Inter: make(map[common.IFIDType]uint64),
311+
}
312+
for ifid, v := range cfg.CarbonIntensity[egress].Intra {
313+
if includeIntraInfo(ifType, ifid, ingress, egress) {
314+
ci.Intra[ifid] = v
315+
}
316+
}
317+
for ifid, v := range cfg.CarbonIntensity {
318+
t := ifType[ifid]
319+
if ifid == egress || t == topology.Peer {
320+
ci.Inter[ifid] = v.Inter
321+
}
322+
}
323+
return ci
324+
}
325+
268326
// generateLinkType creates the LinkTypeInfo by extracting the relevant values from
269327
// the config.
270328
func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IFIDType]topology.LinkType,

control/beaconing/staticinfo_config_test.go

+74
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const (
5050
bandwidth_inter_3 uint64 = 80
5151
bandwidth_inter_5 uint64 = 120
5252

53+
carbon_intensity_intra_1_2 uint64 = 300
54+
carbon_intensity_inter_1 uint64 = 780
55+
carbon_intensity_inter_2 uint64 = 400
56+
5357
link_type_1 staticinfo.LinkType = staticinfo.LinkTypeDirect
5458
link_type_2 staticinfo.LinkType = staticinfo.LinkTypeOpennet
5559
link_type_3 staticinfo.LinkType = staticinfo.LinkTypeMultihop
@@ -163,6 +167,20 @@ func getTestConfigData() *beaconing.StaticInfoCfg {
163167
},
164168
},
165169
},
170+
CarbonIntensity: map[common.IFIDType]beaconing.InterfaceCarbonIntensities{
171+
1: {
172+
Inter: carbon_intensity_inter_1,
173+
Intra: map[common.IFIDType]uint64{
174+
2: carbon_intensity_intra_1_2,
175+
},
176+
},
177+
2: {
178+
Inter: carbon_intensity_inter_2,
179+
Intra: map[common.IFIDType]uint64{
180+
1: carbon_intensity_intra_1_2,
181+
},
182+
},
183+
},
166184
LinkType: map[common.IFIDType]beaconing.LinkType{
167185
1: beaconing.LinkType(link_type_1),
168186
2: beaconing.LinkType(link_type_2),
@@ -270,6 +288,14 @@ func TestGenerateStaticInfo(t *testing.T) {
270288
5: bandwidth_inter_5,
271289
},
272290
},
291+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
292+
Intra: map[common.IFIDType]uint64{
293+
2: carbon_intensity_intra_1_2,
294+
},
295+
Inter: map[common.IFIDType]uint64{
296+
1: carbon_intensity_inter_1,
297+
},
298+
},
273299
Geo: staticinfo.GeoInfo{
274300
1: geo_1,
275301
3: geo_3,
@@ -313,6 +339,12 @@ func TestGenerateStaticInfo(t *testing.T) {
313339
5: bandwidth_inter_5,
314340
},
315341
},
342+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
343+
Intra: map[common.IFIDType]uint64{},
344+
Inter: map[common.IFIDType]uint64{
345+
2: carbon_intensity_inter_2,
346+
},
347+
},
316348
Geo: staticinfo.GeoInfo{
317349
2: geo_2,
318350
3: geo_3,
@@ -347,6 +379,10 @@ func TestGenerateStaticInfo(t *testing.T) {
347379
5: bandwidth_inter_5,
348380
},
349381
},
382+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
383+
Intra: map[common.IFIDType]uint64{},
384+
Inter: map[common.IFIDType]uint64{},
385+
},
350386
Geo: staticinfo.GeoInfo{
351387
3: geo_3,
352388
5: geo_5,
@@ -384,6 +420,14 @@ func TestGenerateStaticInfo(t *testing.T) {
384420
5: bandwidth_inter_5,
385421
},
386422
},
423+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
424+
Intra: map[common.IFIDType]uint64{
425+
2: carbon_intensity_intra_1_2,
426+
},
427+
Inter: map[common.IFIDType]uint64{
428+
1: carbon_intensity_inter_1,
429+
},
430+
},
387431
Geo: staticinfo.GeoInfo{
388432
1: geo_1,
389433
5: geo_5,
@@ -423,6 +467,12 @@ func TestGenerateStaticInfo(t *testing.T) {
423467
5: bandwidth_inter_5,
424468
},
425469
},
470+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
471+
Intra: map[common.IFIDType]uint64{},
472+
Inter: map[common.IFIDType]uint64{
473+
2: carbon_intensity_inter_2,
474+
},
475+
},
426476
Geo: staticinfo.GeoInfo{
427477
2: geo_2,
428478
5: geo_5,
@@ -463,6 +513,14 @@ func TestGenerateStaticInfo(t *testing.T) {
463513
2: bandwidth_inter_2,
464514
},
465515
},
516+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
517+
Intra: map[common.IFIDType]uint64{
518+
1: carbon_intensity_intra_1_2,
519+
},
520+
Inter: map[common.IFIDType]uint64{
521+
2: carbon_intensity_inter_2,
522+
},
523+
},
466524
Geo: staticinfo.GeoInfo{
467525
2: geo_2,
468526
},
@@ -495,6 +553,12 @@ func TestGenerateStaticInfo(t *testing.T) {
495553
1: bandwidth_inter_1,
496554
},
497555
},
556+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
557+
Intra: map[common.IFIDType]uint64{},
558+
Inter: map[common.IFIDType]uint64{
559+
1: carbon_intensity_inter_1,
560+
},
561+
},
498562
Geo: staticinfo.GeoInfo{
499563
1: geo_1,
500564
},
@@ -527,6 +591,12 @@ func TestGenerateStaticInfo(t *testing.T) {
527591
1: bandwidth_inter_1,
528592
},
529593
},
594+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
595+
Intra: map[common.IFIDType]uint64{},
596+
Inter: map[common.IFIDType]uint64{
597+
1: carbon_intensity_inter_1,
598+
},
599+
},
530600
Geo: staticinfo.GeoInfo{
531601
1: geo_1,
532602
3: geo_3,
@@ -554,6 +624,10 @@ func TestGenerateStaticInfo(t *testing.T) {
554624
Intra: map[common.IFIDType]uint64{},
555625
Inter: map[common.IFIDType]uint64{},
556626
},
627+
CarbonIntensity: staticinfo.CarbonIntensityInfo{
628+
Intra: map[common.IFIDType]uint64{},
629+
Inter: map[common.IFIDType]uint64{},
630+
},
557631
Geo: staticinfo.GeoInfo{
558632
3: geo_3,
559633
},

control/beaconing/testdata/testconfigfile.json

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@
6060
"Inter": 120
6161
}
6262
},
63+
"CarbonIntensity": {
64+
"1": {
65+
"Inter": 780,
66+
"Intra": {
67+
"2": 300
68+
}
69+
},
70+
"2": {
71+
"Inter": 400
72+
}
73+
},
6374
"Linktype": {
6475
"1":"direct",
6576
"2":"opennet",

daemon/internal/servers/grpc.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,17 @@ func pathToPB(path snet.Path) *sdpb.Path {
176176
Interface: &sdpb.Interface{
177177
Address: &sdpb.Underlay{Address: nextHopStr},
178178
},
179-
Interfaces: interfaces,
180-
Mtu: uint32(meta.MTU),
181-
Expiration: &timestamppb.Timestamp{Seconds: meta.Expiry.Unix()},
182-
Latency: latency,
183-
Bandwidth: meta.Bandwidth,
184-
Geo: geo,
185-
LinkType: linkType,
186-
InternalHops: meta.InternalHops,
187-
Notes: meta.Notes,
188-
EpicAuths: epicAuths,
179+
Interfaces: interfaces,
180+
Mtu: uint32(meta.MTU),
181+
Expiration: &timestamppb.Timestamp{Seconds: meta.Expiry.Unix()},
182+
Latency: latency,
183+
Bandwidth: meta.Bandwidth,
184+
CarbonIntensity: meta.CarbonIntensity,
185+
Geo: geo,
186+
LinkType: linkType,
187+
InternalHops: meta.InternalHops,
188+
Notes: meta.Notes,
189+
EpicAuths: epicAuths,
189190
}
190191

191192
}

pkg/daemon/grpc.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,16 @@ func convertPath(p *sdpb.Path, dst addr.IA) (path.Path, error) {
289289
},
290290
NextHop: underlayA,
291291
Meta: snet.PathMetadata{
292-
Interfaces: interfaces,
293-
MTU: uint16(p.Mtu),
294-
Expiry: expiry,
295-
Latency: latency,
296-
Bandwidth: p.Bandwidth,
297-
Geo: geo,
298-
LinkType: linkType,
299-
InternalHops: p.InternalHops,
300-
Notes: p.Notes,
292+
Interfaces: interfaces,
293+
MTU: uint16(p.Mtu),
294+
Expiry: expiry,
295+
Latency: latency,
296+
Bandwidth: p.Bandwidth,
297+
CarbonIntensity: p.CarbonIntensity,
298+
Geo: geo,
299+
LinkType: linkType,
300+
InternalHops: p.InternalHops,
301+
Notes: p.Notes,
301302
},
302303
}
303304

0 commit comments

Comments
 (0)