@@ -38,6 +38,11 @@ type InterfaceBandwidths struct {
38
38
Intra map [common.IFIDType ]uint64 `json:"Intra"`
39
39
}
40
40
41
+ type InterfaceCarbonIntensities struct {
42
+ Inter uint64 `json:"Inter"`
43
+ Intra map [common.IFIDType ]uint64 `json:"Intra"`
44
+ }
45
+
41
46
type InterfaceGeodata struct {
42
47
Longitude float32 `json:"Longitude"`
43
48
Latitude float32 `json:"Latitude"`
@@ -79,12 +84,13 @@ func (l *LinkType) UnmarshalText(text []byte) error {
79
84
80
85
// StaticInfoCfg is used to parse data from config.json.
81
86
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"`
88
94
}
89
95
90
96
// ParseStaticInfoCfg parses data from a config file into a StaticInfoCfg struct.
@@ -120,6 +126,10 @@ func (cfg *StaticInfoCfg) clean() {
120
126
for _ , s := range cfg .Bandwidth {
121
127
delete (s .Intra , 0 )
122
128
}
129
+ delete (cfg .CarbonIntensity , 0 )
130
+ for _ , s := range cfg .CarbonIntensity {
131
+ delete (s .Intra , 0 )
132
+ }
123
133
delete (cfg .LinkType , 0 )
124
134
delete (cfg .Geo , 0 )
125
135
delete (cfg .Hops , 0 )
@@ -129,6 +139,7 @@ func (cfg *StaticInfoCfg) clean() {
129
139
130
140
symmetrizeLatency (cfg .Latency )
131
141
symmetrizeBandwidth (cfg .Bandwidth )
142
+ symmetrizeCarbonIntensity (cfg .CarbonIntensity )
132
143
symmetrizeHops (cfg .Hops )
133
144
}
134
145
@@ -178,6 +189,29 @@ func symmetrizeBandwidth(bandwidth map[common.IFIDType]InterfaceBandwidths) {
178
189
}
179
190
}
180
191
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
+
181
215
// symmetrizeHops makes the Intra hops values symmetric
182
216
func symmetrizeHops (hops map [common.IFIDType ]InterfaceHops ) {
183
217
for i , sub := range hops {
@@ -210,12 +244,13 @@ func (cfg StaticInfoCfg) generate(ifType map[common.IFIDType]topology.LinkType,
210
244
ingress , egress common.IFIDType ) * staticinfo.Extension {
211
245
212
246
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 ,
219
254
}
220
255
}
221
256
@@ -265,6 +300,29 @@ func (cfg StaticInfoCfg) generateBandwidth(ifType map[common.IFIDType]topology.L
265
300
return bw
266
301
}
267
302
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
+
268
326
// generateLinkType creates the LinkTypeInfo by extracting the relevant values from
269
327
// the config.
270
328
func (cfg StaticInfoCfg ) generateLinkType (ifType map [common.IFIDType ]topology.LinkType ,
0 commit comments