Skip to content

Commit

Permalink
Add Carbon Intensity information to beacons and paths (#129)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
matzf authored and juagargi committed Mar 8, 2024
1 parent 50f0d4d commit 44aaebe
Show file tree
Hide file tree
Showing 17 changed files with 880 additions and 407 deletions.
82 changes: 70 additions & 12 deletions control/beaconing/staticinfo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type InterfaceBandwidths struct {
Intra map[common.IFIDType]uint64 `json:"Intra"`
}

type InterfaceCarbonIntensities struct {
Inter uint64 `json:"Inter"`
Intra map[common.IFIDType]uint64 `json:"Intra"`
}

type InterfaceGeodata struct {
Longitude float32 `json:"Longitude"`
Latitude float32 `json:"Latitude"`
Expand Down Expand Up @@ -79,12 +84,13 @@ func (l *LinkType) UnmarshalText(text []byte) error {

// StaticInfoCfg is used to parse data from config.json.
type StaticInfoCfg struct {
Latency map[common.IFIDType]InterfaceLatencies `json:"Latency"`
Bandwidth map[common.IFIDType]InterfaceBandwidths `json:"Bandwidth"`
LinkType map[common.IFIDType]LinkType `json:"LinkType"`
Geo map[common.IFIDType]InterfaceGeodata `json:"Geo"`
Hops map[common.IFIDType]InterfaceHops `json:"Hops"`
Note string `json:"Note"`
Latency map[common.IFIDType]InterfaceLatencies `json:"Latency"`
Bandwidth map[common.IFIDType]InterfaceBandwidths `json:"Bandwidth"`
CarbonIntensity map[common.IFIDType]InterfaceCarbonIntensities `json:"CarbonIntensity"`
LinkType map[common.IFIDType]LinkType `json:"LinkType"`
Geo map[common.IFIDType]InterfaceGeodata `json:"Geo"`
Hops map[common.IFIDType]InterfaceHops `json:"Hops"`
Note string `json:"Note"`
}

// ParseStaticInfoCfg parses data from a config file into a StaticInfoCfg struct.
Expand Down Expand Up @@ -120,6 +126,10 @@ func (cfg *StaticInfoCfg) clean() {
for _, s := range cfg.Bandwidth {
delete(s.Intra, 0)
}
delete(cfg.CarbonIntensity, 0)
for _, s := range cfg.CarbonIntensity {
delete(s.Intra, 0)
}
delete(cfg.LinkType, 0)
delete(cfg.Geo, 0)
delete(cfg.Hops, 0)
Expand All @@ -129,6 +139,7 @@ func (cfg *StaticInfoCfg) clean() {

symmetrizeLatency(cfg.Latency)
symmetrizeBandwidth(cfg.Bandwidth)
symmetrizeCarbonIntensity(cfg.CarbonIntensity)
symmetrizeHops(cfg.Hops)
}

Expand Down Expand Up @@ -178,6 +189,29 @@ func symmetrizeBandwidth(bandwidth map[common.IFIDType]InterfaceBandwidths) {
}
}

// symmetrizeCarbonIntensity makes the Intra carbon intensity values symmetric
func symmetrizeCarbonIntensity(carbonIntensity map[common.IFIDType]InterfaceCarbonIntensities) {
for i, sub := range carbonIntensity {
delete(sub.Intra, i) // Remove loopy entry
for j, v := range sub.Intra {
if _, ok := carbonIntensity[j]; !ok {
continue
}
if carbonIntensity[j].Intra == nil {
carbonIntensity[j] = InterfaceCarbonIntensities{
Inter: carbonIntensity[j].Inter,
Intra: make(map[common.IFIDType]uint64),
}
}
vTransposed, ok := carbonIntensity[j].Intra[i]
// Set if not specified or pick more conservative value if both are specified
if !ok || v < vTransposed {
carbonIntensity[j].Intra[i] = v
}
}
}
}

// symmetrizeHops makes the Intra hops values symmetric
func symmetrizeHops(hops map[common.IFIDType]InterfaceHops) {
for i, sub := range hops {
Expand Down Expand Up @@ -210,12 +244,13 @@ func (cfg StaticInfoCfg) generate(ifType map[common.IFIDType]topology.LinkType,
ingress, egress common.IFIDType) *staticinfo.Extension {

return &staticinfo.Extension{
Latency: cfg.generateLatency(ifType, ingress, egress),
Bandwidth: cfg.generateBandwidth(ifType, ingress, egress),
Geo: cfg.generateGeo(ifType, ingress, egress),
LinkType: cfg.generateLinkType(ifType, egress),
InternalHops: cfg.generateInternalHops(ifType, ingress, egress),
Note: cfg.Note,
Latency: cfg.generateLatency(ifType, ingress, egress),
Bandwidth: cfg.generateBandwidth(ifType, ingress, egress),
CarbonIntensity: cfg.generateCarbonIntensity(ifType, ingress, egress),
Geo: cfg.generateGeo(ifType, ingress, egress),
LinkType: cfg.generateLinkType(ifType, egress),
InternalHops: cfg.generateInternalHops(ifType, ingress, egress),
Note: cfg.Note,
}
}

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

// generateCarbonIntensity creates the BandwidthInfo by extracting the relevant values
// from the config.
func (cfg StaticInfoCfg) generateCarbonIntensity(ifType map[common.IFIDType]topology.LinkType,
ingress, egress common.IFIDType) staticinfo.CarbonIntensityInfo {

ci := staticinfo.CarbonIntensityInfo{
Intra: make(map[common.IFIDType]uint64),
Inter: make(map[common.IFIDType]uint64),
}
for ifid, v := range cfg.CarbonIntensity[egress].Intra {
if includeIntraInfo(ifType, ifid, ingress, egress) {
ci.Intra[ifid] = v
}
}
for ifid, v := range cfg.CarbonIntensity {
t := ifType[ifid]
if ifid == egress || t == topology.Peer {
ci.Inter[ifid] = v.Inter
}
}
return ci
}

// generateLinkType creates the LinkTypeInfo by extracting the relevant values from
// the config.
func (cfg StaticInfoCfg) generateLinkType(ifType map[common.IFIDType]topology.LinkType,
Expand Down
74 changes: 74 additions & 0 deletions control/beaconing/staticinfo_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const (
bandwidth_inter_3 uint64 = 80
bandwidth_inter_5 uint64 = 120

carbon_intensity_intra_1_2 uint64 = 300
carbon_intensity_inter_1 uint64 = 780
carbon_intensity_inter_2 uint64 = 400

link_type_1 staticinfo.LinkType = staticinfo.LinkTypeDirect
link_type_2 staticinfo.LinkType = staticinfo.LinkTypeOpennet
link_type_3 staticinfo.LinkType = staticinfo.LinkTypeMultihop
Expand Down Expand Up @@ -163,6 +167,20 @@ func getTestConfigData() *beaconing.StaticInfoCfg {
},
},
},
CarbonIntensity: map[common.IFIDType]beaconing.InterfaceCarbonIntensities{
1: {
Inter: carbon_intensity_inter_1,
Intra: map[common.IFIDType]uint64{
2: carbon_intensity_intra_1_2,
},
},
2: {
Inter: carbon_intensity_inter_2,
Intra: map[common.IFIDType]uint64{
1: carbon_intensity_intra_1_2,
},
},
},
LinkType: map[common.IFIDType]beaconing.LinkType{
1: beaconing.LinkType(link_type_1),
2: beaconing.LinkType(link_type_2),
Expand Down Expand Up @@ -270,6 +288,14 @@ func TestGenerateStaticInfo(t *testing.T) {
5: bandwidth_inter_5,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{
2: carbon_intensity_intra_1_2,
},
Inter: map[common.IFIDType]uint64{
1: carbon_intensity_inter_1,
},
},
Geo: staticinfo.GeoInfo{
1: geo_1,
3: geo_3,
Expand Down Expand Up @@ -313,6 +339,12 @@ func TestGenerateStaticInfo(t *testing.T) {
5: bandwidth_inter_5,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{
2: carbon_intensity_inter_2,
},
},
Geo: staticinfo.GeoInfo{
2: geo_2,
3: geo_3,
Expand Down Expand Up @@ -347,6 +379,10 @@ func TestGenerateStaticInfo(t *testing.T) {
5: bandwidth_inter_5,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{},
},
Geo: staticinfo.GeoInfo{
3: geo_3,
5: geo_5,
Expand Down Expand Up @@ -384,6 +420,14 @@ func TestGenerateStaticInfo(t *testing.T) {
5: bandwidth_inter_5,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{
2: carbon_intensity_intra_1_2,
},
Inter: map[common.IFIDType]uint64{
1: carbon_intensity_inter_1,
},
},
Geo: staticinfo.GeoInfo{
1: geo_1,
5: geo_5,
Expand Down Expand Up @@ -423,6 +467,12 @@ func TestGenerateStaticInfo(t *testing.T) {
5: bandwidth_inter_5,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{
2: carbon_intensity_inter_2,
},
},
Geo: staticinfo.GeoInfo{
2: geo_2,
5: geo_5,
Expand Down Expand Up @@ -463,6 +513,14 @@ func TestGenerateStaticInfo(t *testing.T) {
2: bandwidth_inter_2,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{
1: carbon_intensity_intra_1_2,
},
Inter: map[common.IFIDType]uint64{
2: carbon_intensity_inter_2,
},
},
Geo: staticinfo.GeoInfo{
2: geo_2,
},
Expand Down Expand Up @@ -495,6 +553,12 @@ func TestGenerateStaticInfo(t *testing.T) {
1: bandwidth_inter_1,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{
1: carbon_intensity_inter_1,
},
},
Geo: staticinfo.GeoInfo{
1: geo_1,
},
Expand Down Expand Up @@ -527,6 +591,12 @@ func TestGenerateStaticInfo(t *testing.T) {
1: bandwidth_inter_1,
},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{
1: carbon_intensity_inter_1,
},
},
Geo: staticinfo.GeoInfo{
1: geo_1,
3: geo_3,
Expand Down Expand Up @@ -554,6 +624,10 @@ func TestGenerateStaticInfo(t *testing.T) {
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{},
},
CarbonIntensity: staticinfo.CarbonIntensityInfo{
Intra: map[common.IFIDType]uint64{},
Inter: map[common.IFIDType]uint64{},
},
Geo: staticinfo.GeoInfo{
3: geo_3,
},
Expand Down
11 changes: 11 additions & 0 deletions control/beaconing/testdata/testconfigfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
"Inter": 120
}
},
"CarbonIntensity": {
"1": {
"Inter": 780,
"Intra": {
"2": 300
}
},
"2": {
"Inter": 400
}
},
"Linktype": {
"1":"direct",
"2":"opennet",
Expand Down
21 changes: 11 additions & 10 deletions daemon/internal/servers/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,17 @@ func pathToPB(path snet.Path) *sdpb.Path {
Interface: &sdpb.Interface{
Address: &sdpb.Underlay{Address: nextHopStr},
},
Interfaces: interfaces,
Mtu: uint32(meta.MTU),
Expiration: &timestamppb.Timestamp{Seconds: meta.Expiry.Unix()},
Latency: latency,
Bandwidth: meta.Bandwidth,
Geo: geo,
LinkType: linkType,
InternalHops: meta.InternalHops,
Notes: meta.Notes,
EpicAuths: epicAuths,
Interfaces: interfaces,
Mtu: uint32(meta.MTU),
Expiration: &timestamppb.Timestamp{Seconds: meta.Expiry.Unix()},
Latency: latency,
Bandwidth: meta.Bandwidth,
CarbonIntensity: meta.CarbonIntensity,
Geo: geo,
LinkType: linkType,
InternalHops: meta.InternalHops,
Notes: meta.Notes,
EpicAuths: epicAuths,
}

}
Expand Down
19 changes: 10 additions & 9 deletions pkg/daemon/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,16 @@ func convertPath(p *sdpb.Path, dst addr.IA) (path.Path, error) {
},
NextHop: underlayA,
Meta: snet.PathMetadata{
Interfaces: interfaces,
MTU: uint16(p.Mtu),
Expiry: expiry,
Latency: latency,
Bandwidth: p.Bandwidth,
Geo: geo,
LinkType: linkType,
InternalHops: p.InternalHops,
Notes: p.Notes,
Interfaces: interfaces,
MTU: uint16(p.Mtu),
Expiry: expiry,
Latency: latency,
Bandwidth: p.Bandwidth,
CarbonIntensity: p.CarbonIntensity,
Geo: geo,
LinkType: linkType,
InternalHops: p.InternalHops,
Notes: p.Notes,
},
}

Expand Down
Loading

0 comments on commit 44aaebe

Please sign in to comment.