Newer
Older
/*
* Copyright (c) 2019 InterDigital Communications, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use algo 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 netchar
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
Kevin Di Lallo
committed
dkm "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-key-mgr"
dataModel "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-data-model"
log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
mod "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-model"
redis "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-redis"
)
const MAX_THROUGHPUT = 9999999999
const THROUGHPUT_UNIT = 1000000 //convert from Mbps to bps
const DEFAULT_THROUGHPUT_LINK = 1000.0
const metricsDb = 0
Kevin Di Lallo
committed
const metricsKey string = "metrics:"
// SegAlgoConfig - Segment Algorithm Config
type SegAlgoConfig struct {
// Segment config
MaxBwPerInactiveFlow float64
MaxBwPerInactiveFlowFloor float64
MinActivityThreshold float64
IncrementalStep float64
InactivityIncrementalStep float64
TolerationThreshold float64
ActionUpperThreshold float64
// Debug Config
IsPercentage bool
LogVerbose bool
}
// SegAlgoSegment -
type SegAlgoSegment struct {
Name string
ConfiguredNetChar NetChar
MaxFairShareBwPerFlow float64
CurrentThroughput float64
MaxBwPerInactiveFlow float64
MinActivityThreshold float64
IncrementalStep float64
InactivityIncrementalStep float64
TolerationThreshold float64
ActionUpperThreshold float64
Flows []*SegAlgoFlow
}
// SegAlgoFlow -
type SegAlgoFlow struct {
Name string
SrcNetElem string
DstNetElem string
ConfiguredNetChar NetChar
AppliedNetChar NetChar
ComputedLatency float64
ComputedJitter float64
ComputedPacketLoss float64
AllocatedThroughput float64 //allocated
AllocatedThroughputLowerBound float64 //allocated
AllocatedThroughputUpperBound float64 //allocated
MaxPlannedThroughput float64
MaxPlannedLowerBound float64
MaxPlannedUpperBound float64
PlannedThroughput float64
PlannedLowerBound float64
PlannedUpperBound float64
CurrentThroughput float64 //measured
CurrentThroughputEgress float64 //measured
Path *SegAlgoPath
}
// SegAlgoPath -
type SegAlgoPath struct {
Name string
Segments []*SegAlgoSegment
}
// SegAlgoNetElem -
type SegAlgoNetElem struct {
Name string
Type string
PhyLocName string
PoaName string
ZoneName string
DomainName string
}
// SegmentAlgorithm -
type SegmentAlgorithm struct {
Kevin Di Lallo
committed
Namespace string
BaseKey string
FlowMap map[string]*SegAlgoFlow
SegmentMap map[string]*SegAlgoSegment
Config SegAlgoConfig
rc *redis.Connector
}
// NewSegmentAlgorithm - Create, Initialize and connect
Kevin Di Lallo
committed
func NewSegmentAlgorithm(name string, namespace string, redisAddr string) (*SegmentAlgorithm, error) {
// Create new instance & set default config
var err error
var algo SegmentAlgorithm
Kevin Di Lallo
committed
algo.Namespace = namespace
algo.BaseKey = dkm.GetKeyRoot(namespace) + metricsKey
algo.FlowMap = make(map[string]*SegAlgoFlow)
algo.SegmentMap = make(map[string]*SegAlgoSegment)
algo.Config.MaxBwPerInactiveFlow = 20.0
algo.Config.MaxBwPerInactiveFlowFloor = 6.0
algo.Config.MinActivityThreshold = 0.3
algo.Config.IncrementalStep = 3.0
algo.Config.InactivityIncrementalStep = 1.0
algo.Config.ActionUpperThreshold = 1.0
algo.Config.TolerationThreshold = 4.0
algo.Config.IsPercentage = true
// Create connection to Metrics Redis DB & flush entries
algo.rc, err = redis.NewConnector(redisAddr, metricsDb)
if err != nil {
log.Error("Failed connection to Metrics redis DB. Error: ", err)
return nil, err
}
Kevin Di Lallo
committed
_ = algo.rc.DBFlush(algo.BaseKey)
log.Info("Connected to Metrics redis DB")
return &algo, nil
}
// ProcessScenario -
func (algo *SegmentAlgorithm) ProcessScenario(model *mod.Model) error {
var netElemList []SegAlgoNetElem
// Process empty scenario
if model.GetScenarioName() == "" {
// Remove any existing metrics
algo.deleteMetricsEntries()
//reset the map
algo.FlowMap = make(map[string]*SegAlgoFlow)
}
// Clear segment & flow maps
algo.SegmentMap = make(map[string]*SegAlgoSegment)
// Process active scenario
procNames := model.GetNodeNames("CLOUD-APP", "EDGE-APP", "UE-APP")
// Create NetElem for each scenario process
for _, name := range procNames {
// Retrieve node & context from model
node := model.GetNode(name)
if node == nil {
err := errors.New("Error finding process: " + name)
return err
}
proc, ok := node.(*dataModel.Process)
if !ok {
err := errors.New("Error casting process: " + name)
return err
}
ctx := model.GetNodeContext(name)
if ctx == nil {
err := errors.New("Error getting context for process: " + name)
return err
}
Kevin Di Lallo
committed
nodeCtx, ok := ctx.(*mod.NodeContext)
if !ok {
err := errors.New("Error casting context for process: " + name)
return err
}
// Create & populate new element
element := new(SegAlgoNetElem)
element.Name = proc.Name
Kevin Di Lallo
committed
element.PhyLocName = nodeCtx.Parents[mod.PhyLoc]
element.DomainName = nodeCtx.Parents[mod.Domain]
// Type-specific values
element.Type = model.GetNodeType(element.PhyLocName)
if element.Type == "UE" || element.Type == "FOG" {
Kevin Di Lallo
committed
element.PoaName = nodeCtx.Parents[mod.NetLoc]
}
if element.Type != "DC" {
Kevin Di Lallo
committed
element.ZoneName = nodeCtx.Parents[mod.Zone]
}
deployment := model.GetNodeParent(element.DomainName).(*dataModel.Deployment)
// Set max App Net chars (use default if set to 0)
element.ConfiguredNetChar.Latency = float64(proc.NetChar.Latency)
element.ConfiguredNetChar.Jitter = float64(proc.NetChar.LatencyVariation)
element.ConfiguredNetChar.Distribution = deployment.NetChar.LatencyDistribution //set global value
element.ConfiguredNetChar.ThroughputDl = float64(proc.NetChar.ThroughputUl)
element.ConfiguredNetChar.ThroughputUl = float64(proc.NetChar.ThroughputUl)
element.ConfiguredNetChar.PacketLoss = float64(proc.NetChar.PacketLoss)
if element.ConfiguredNetChar.ThroughputUl == 0 {
element.ConfiguredNetChar.ThroughputUl = DEFAULT_THROUGHPUT_LINK
}
if element.ConfiguredNetChar.ThroughputDl == 0 {
element.ConfiguredNetChar.ThroughputDl = DEFAULT_THROUGHPUT_LINK
}
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// Add element to list
netElemList = append(netElemList, *element)
}
// Create all flows using Network Element list
for _, elemSrc := range netElemList {
for _, elemDest := range netElemList {
if elemSrc.Name != elemDest.Name {
// Create flow
algo.populateFlow(elemSrc.Name+":"+elemDest.Name, &elemSrc, &elemDest, 0, model)
// Create DB entry to begin collecting metrics for this flow
algo.createMetricsEntry(elemSrc.Name, elemDest.Name)
}
}
}
// Log segments & flows in Verbose mode
if algo.Config.LogVerbose {
log.Info("Segments map: ", algo.SegmentMap)
log.Info("Flows map: ", algo.FlowMap)
}
return nil
}
// CalculateNetChar - Run algorithm to recalculate network characteristics using latest scenario & metrics
func (algo *SegmentAlgorithm) CalculateNetChar() []FlowNetChar {
var updatedNetCharList []FlowNetChar
currentTime := time.Now()
algo.logTimeLapse(¤tTime, "time to print")
// Update flow with latest metrics
Kevin Di Lallo
committed
keyName := algo.BaseKey + "*:throughput"
err := algo.rc.ForEachEntry(keyName, algo.getMetricsThroughputEntryHandler, nil)
if err != nil {
log.Error("Failed to get entries: ", err)
return updatedNetCharList
}
algo.logTimeLapse(¤tTime, "time to update metrics")
// Recalculate segment BW allocation for each flow
algo.reCalculateNetChar()
algo.logTimeLapse(¤tTime, "time to recalculate throughput")
// Prepare list of updated flows
for _, flow := range algo.FlowMap {
updateNeeded := false
if flow.MaxPlannedThroughput != flow.AllocatedThroughput && flow.MaxPlannedThroughput != MAX_THROUGHPUT {
if algo.Config.LogVerbose {
log.Info("Update allocated bandwidth for ", flow.Name, " to ", flow.MaxPlannedThroughput, " from ", flow.AllocatedThroughput)
}
if flow.MaxPlannedThroughput >= 0 {
flow.AllocatedThroughput = flow.MaxPlannedThroughput
flow.AllocatedThroughputLowerBound = flow.MaxPlannedLowerBound
flow.AllocatedThroughputUpperBound = flow.MaxPlannedUpperBound
flow.AppliedNetChar.Throughput = flow.AllocatedThroughput
updateNeeded = true
if flow.MaxPlannedThroughput == 0 {
log.Error("Impossible 0 result: ", printFlow(flow))
}
} else {
log.Error("Impossible negative result: ", printFlow(flow))
}
}
if (flow.ComputedLatency != flow.AppliedNetChar.Latency) ||
(flow.ComputedJitter != flow.AppliedNetChar.Jitter) ||
(flow.ComputedPacketLoss != flow.AppliedNetChar.PacketLoss) ||
(flow.ConfiguredNetChar.Distribution != flow.AppliedNetChar.Distribution) {
log.Info("Update other netchars for ", flow.Name, " to ", flow.ComputedLatency, "-", flow.ComputedJitter, "-", flow.ComputedPacketLoss, " from ", flow.AppliedNetChar.Latency, "-", flow.AppliedNetChar.Jitter, "-", flow.AppliedNetChar.PacketLoss, "-", flow.AppliedNetChar.Distribution)
flow.AppliedNetChar.Latency = flow.ComputedLatency
flow.AppliedNetChar.Jitter = flow.ComputedJitter
flow.AppliedNetChar.PacketLoss = flow.ComputedPacketLoss
flow.AppliedNetChar.Distribution = flow.ConfiguredNetChar.Distribution
netchar := NetChar{flow.AppliedNetChar.Latency, flow.AppliedNetChar.Jitter, flow.AppliedNetChar.PacketLoss, flow.AppliedNetChar.Throughput, flow.ConfiguredNetChar.Distribution}
flowNetChar := FlowNetChar{flow.SrcNetElem, flow.DstNetElem, netchar}
updatedNetCharList = append(updatedNetCharList, flowNetChar)
}
}
return updatedNetCharList
}
// SetConfigAttribute
func (algo *SegmentAlgorithm) SetConfigAttribute(fieldName string, fieldValue string) {
switch fieldName {
case "maxBwPerInactiveFlow":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.MaxBwPerInactiveFlow = value
}
case "maxBwPerInactiveFlowFloor":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.MaxBwPerInactiveFlowFloor = value
}
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
case "minActivityThreshold":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.MinActivityThreshold = value
}
case "incrementalStep":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.IncrementalStep = value
}
case "inactivityIncrementalStep":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.InactivityIncrementalStep = value
}
case "tolerationThreshold":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.TolerationThreshold = value
}
case "actionUpperThreshold":
value, err := strconv.ParseFloat(fieldValue, 64)
if err == nil {
algo.Config.ActionUpperThreshold = value
}
case "isPercentage":
if "yes" == fieldValue {
algo.Config.IsPercentage = true
} else {
algo.Config.IsPercentage = false
}
case "logVerbose":
if "yes" == fieldValue {
algo.Config.LogVerbose = true
}
default:
}
}
// logTimeLapse -
func (algo *SegmentAlgorithm) logTimeLapse(currentTime *time.Time, message string) {
if algo.Config.LogVerbose {
elapsed := time.Since(*currentTime)
log.WithFields(log.Fields{
"meep.log.component": algo.Name,
"meep.time.location": message,
"meep.time.exec": elapsed,
}).Info("Measurements log")
*currentTime = time.Now()
}
}
// createMetricsEntry -
func (algo *SegmentAlgorithm) createMetricsEntry(srcElem string, dstElem string) {
var creationTime = make(map[string]interface{})
creationTime["creationTime"] = time.Now()
// Entries are created with no values, sidecar will only fill them, otherwise, won't be cleared
Kevin Di Lallo
committed
_ = algo.rc.SetEntry(algo.BaseKey+dstElem+":"+srcElem, creationTime)
_ = algo.rc.SetEntry(algo.BaseKey+dstElem+":throughput", creationTime)
}
// deleteMetricsEntries -
func (algo *SegmentAlgorithm) deleteMetricsEntries() {
for _, flow := range algo.FlowMap {
// Entries are created with no values, sidecar will only fill them, otherwise, won't be cleared
Kevin Di Lallo
committed
_ = algo.rc.DelEntry(algo.BaseKey + flow.DstNetElem + ":" + flow.SrcNetElem)
_ = algo.rc.DelEntry(algo.BaseKey + flow.DstNetElem + ":throughput")
}
}
// populateFlow - Create/Update flow
func (algo *SegmentAlgorithm) populateFlow(flowName string, srcElement *SegAlgoNetElem, destElement *SegAlgoNetElem, maxBw float64, model *mod.Model) {
// Use existing flow if present or Create new flow
flow := algo.FlowMap[flowName]
if flow == nil {
flow = new(SegAlgoFlow)
flow.Name = flowName
flow.SrcNetElem = srcElement.Name
flow.DstNetElem = destElement.Name
algo.FlowMap[flowName] = flow
} else if flow.Name != flowName || flow.SrcNetElem != srcElement.Name && flow.DstNetElem != destElement.Name {
log.Error("Flow already exists but not the same info, something is wrong!")
}
// Set maxBw to the minimum of the 2 ends if a max is not forced
if maxBw == 0 {
if srcElement.ConfiguredNetChar.ThroughputUl < destElement.ConfiguredNetChar.ThroughputDl {
maxBw = srcElement.ConfiguredNetChar.ThroughputUl
} else {
maxBw = destElement.ConfiguredNetChar.ThroughputDl
}
/* if srcElement.ConfiguredNetChar.ThroughputDl < destElement.ConfiguredNetChar.ThroughputUl {
maxBwDl = srcElement.ConfiguredNetChar.ThroughputDl
} else {
maxBwDl = destElement.ConfiguredNetChar.ThroughputUl
}
*/
}
flow.ConfiguredNetChar.Throughput = maxBw
//using distribution to pass it down, since it is global, they all have the same data at this point, so use any elements distribution
flow.ConfiguredNetChar.Distribution = srcElement.ConfiguredNetChar.Distribution
flow.ConfiguredNetChar.Latency = 0
flow.ConfiguredNetChar.Jitter = 0
flow.ConfiguredNetChar.PacketLoss = 0
// Create a new path for this flow
oldPath := flow.Path
flow.Path = algo.createPath(flowName, srcElement, destElement, model)
}
func (algo *SegmentAlgorithm) comparePath(oldPath *SegAlgoPath, newPath *SegAlgoPath) bool {
if oldPath == nil {
return true
}
return true
}
for index, newSegment := range newPath.Segments {
if newSegment.Name != oldPath.Segments[index].Name {
return true
}
}
// createPath -
func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNetElem, destElement *SegAlgoNetElem, model *mod.Model) *SegAlgoPath {
direction := ""
var segment *SegAlgoSegment
path := new(SegAlgoPath)
path.Name = flowName
//app segment ul, dl
direction = "uplink"
segment = algo.createSegment(srcElement.Name, direction, flowName, model)
path.Segments = append(path.Segments, segment)
direction = "downlink"
segment = algo.createSegment(destElement.Name, direction, flowName, model)
path.Segments = append(path.Segments, segment)
//node segment ul, dl
direction = "uplink"
segment = algo.createSegment(srcElement.PhyLocName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
direction = "downlink"
segment = algo.createSegment(destElement.PhyLocName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
//if on same node, return
if srcElement.PhyLocName == destElement.PhyLocName {
return path
}
//network location ul, dl
if srcElement.Type == "UE" {
direction = "uplink"
segment = algo.createSegment(srcElement.PoaName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
if destElement.Type == "UE" {
direction = "downlink"
segment = algo.createSegment(destElement.PoaName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
//if on same network location (poa), return
if srcElement.PoaName == destElement.PoaName {
return path
}
//zone ul, dl
segment = algo.createSegment(srcElement.ZoneName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
direction = "downlink"
segment = algo.createSegment(destElement.ZoneName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
//if in same zone, return
if srcElement.ZoneName == destElement.ZoneName {
return path
}
//domain ul, dl
segment = algo.createSegment(srcElement.DomainName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
direction = "downlink"
segment = algo.createSegment(destElement.DomainName, direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
//if in same domain, return
if srcElement.DomainName == destElement.DomainName {
return path
}
//cloud ul, dl
segment = algo.createSegment(model.GetScenarioName() + "-cloud-", direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
direction = "downlink"
segment = algo.createSegment(model.GetScenarioName() + "-cloud-", direction, flowName, model)
path.Segments = append(path.Segments, segment)
}
return path
}
/*
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
// createPath -
func (algo *SegmentAlgorithm) createPath(flowName string, srcElement *SegAlgoNetElem, destElement *SegAlgoNetElem, model *mod.Model) *SegAlgoPath {
//Tier 1 -- check if they are in the same poa
//Tier 2 -- check if they are in the same zone, but different poa
//Tier 3 -- check if they are in the same domain, but different zone
//Tier 4 -- check if they are in different domains
direction := ""
segmentName := ""
var segment *SegAlgoSegment
path := new(SegAlgoPath)
path.Name = flowName
//Tier 1
if srcElement.PoaName != "" {
//segments from element to POA
//2 possibilities
//UE->POA
//segments for srcElement(app) -> 1A. UE-Node uplink-> 2A. POA-TermLink uplink
//FOG-POA
//segments for srcElement(app) -> 1B. FogNode uplink
direction = "uplink"
//segment 1A or 1B
segmentName = srcElement.PhyLocName + "-" + direction
segment = algo.createSegment(segmentName, flowName, srcElement.PhyLocName, model)
path.Segments = append(path.Segments, segment)
if srcElement.Type == "UE" {
//segment 2A
segmentName = srcElement.PoaName + "-" + direction
segment = algo.createSegment(segmentName, flowName, srcElement.PoaName, model)
path.Segments = append(path.Segments, segment)
}
}
if destElement.PoaName != "" {
//segments from POA to element
//2 possibilities
//POA->FOG
//3A. Fog-Node downlink -> dstElement(app)
//POA-UE
//2B. POA-TermLink downlink -> 3B. UE-Node downlink -> dstElement(app)
direction = "downlink"
if destElement.Type == "UE" {
//segment 2B
segmentName = destElement.PoaName + "-" + direction
segment = algo.createSegment(segmentName, flowName, destElement.PoaName, model)
path.Segments = append(path.Segments, segment)
}
//segment 3A or 3B
segmentName = destElement.PhyLocName + "-" + direction
segment = algo.createSegment(segmentName, flowName, destElement.PhyLocName, model)
path.Segments = append(path.Segments, segment)
}
//Tier 2
//if same zone, different POA, OR no POA at all (Edge-Edge)
if (srcElement.PoaName != destElement.PoaName) || (srcElement.PoaName == "" && destElement.PoaName == "") {
//segments to intraZone backbone
//2 possibilities
//EDGE->IntraZoneBackbone
//srcElement(app) -> 1A. Edge-Node uplink -> 2A. IntraZone uplink
//POA->IntraZoneBackbone
//2B. IntraZone uplink
direction = "uplink"
if srcElement.Type == "EDGE" {
//segment 1A
segmentName = srcElement.PhyLocName + "-" + direction
segment = algo.createSegment(segmentName, flowName, srcElement.PhyLocName, model)
path.Segments = append(path.Segments, segment)
//segment 2A
segmentName = srcElement.ZoneName + "-" + srcElement.PhyLocName + "-" + direction
} else {
//segment 2B
segmentName = srcElement.ZoneName + "-" + srcElement.PoaName + "-" + direction
}
if srcElement.ZoneName != "" {
segment = algo.createSegment(segmentName, flowName, srcElement.ZoneName, model)
path.Segments = append(path.Segments, segment)
}
//segments from intraZone backbone
//2 possibilities
//IntraZoneBackbone->EDGE
//3A. IntraZone downlink -> 4A. Edge-Node downlink -> srcElement(app)
//IntraZoneBackbone->POA
//3B. IntraZone downlink
direction = "downlink"
if destElement.Type == "EDGE" {
//segment 4A
segmentName = destElement.PhyLocName + "-" + direction
segment = algo.createSegment(segmentName, flowName, destElement.PhyLocName, model)
path.Segments = append(path.Segments, segment)
//segment 3A
segmentName = destElement.ZoneName + "-" + destElement.PhyLocName + "-" + direction
} else {
//segment 3B
segmentName = destElement.ZoneName + "-" + destElement.PoaName + "-" + direction
}
if destElement.ZoneName != "" {
segment = algo.createSegment(segmentName, flowName, destElement.ZoneName, model)
path.Segments = append(path.Segments, segment)
}
}
//Tier 3
if srcElement.ZoneName != destElement.ZoneName {
//segments to interZone backbone
//1 possibility
//Zone->InterZoneBackbone
//1A. Zone uplink -> InterZone backbone (if zone exist)
direction = "uplink"
//segment 1A
if srcElement.ZoneName != "" {
segmentName = srcElement.ZoneName + "-" + direction
segment = algo.createSegment(segmentName, flowName, srcElement.DomainName, model)
path.Segments = append(path.Segments, segment)
}
//segments from interZone backbone
//1 possibility
//InterZoneBackbone->Zone
//2A. InterZone backbone -> Zone downlink (if zone exist)
direction = "downlink"
//segment 2A
if destElement.ZoneName != "" {
segmentName = destElement.ZoneName + "-" + direction
segment = algo.createSegment(segmentName, flowName, destElement.DomainName, model)
path.Segments = append(path.Segments, segment)
}
}
//Tier 4
if srcElement.DomainName != destElement.DomainName {
//segments to interDomain backbone
//1 possibility
//InterZoneBackbone->InterDomainBackbone
//1A. InterZone backbone -> Domain backbone
direction = "uplink"
//segment 1A
segmentName = srcElement.DomainName + "-" + direction
segment = algo.createSegment(segmentName, flowName, model.GetScenarioName(), model)
path.Segments = append(path.Segments, segment)
//segments from interDomain backbone
//1 possibility
//InterDomainBackbone->InterZoneBackbone
//2A. Domain backbone -> InterZone backbone
direction = "downlink"
//segment 2A
segmentName = destElement.DomainName + "-" + direction
segment = algo.createSegment(segmentName, flowName, model.GetScenarioName(), model)
path.Segments = append(path.Segments, segment)
//when going through interdomain, either from/to the cloud or another domain, if not cloud, already handled in other tiers sections
if destElement.Type == "CLOUD" {
segmentName = destElement.PhyLocName + "-" + direction
segment = algo.createSegment(segmentName, flowName, destElement.PhyLocName, model)
path.Segments = append(path.Segments, segment)
} else if srcElement.Type == "CLOUD" {
direction = "uplink"
segmentName = srcElement.PhyLocName + "-" + direction
segment = algo.createSegment(segmentName, flowName, srcElement.PhyLocName, model)
path.Segments = append(path.Segments, segment)
}
}
return path
}
// createSegment -
func (algo *SegmentAlgorithm) createSegment(elemName string, direction string, flowName string, model *mod.Model) *SegAlgoSegment {
// Create new segment if it does not exist
segmentName := elemName + direction
segment := algo.SegmentMap[segmentName]
if segment == nil {
segment = new(SegAlgoSegment)
segment.Name = segmentName
// Retrieve max throughput from model using model scenario element name
nc := getNetChars(elemName, model)
ncThroughput := 0.0
if direction == "uplink" {
ncThroughput = float64(nc.ThroughputUl)
} else {
ncThroughput = float64(nc.ThroughputDl)
}
segment.ConfiguredNetChar.Latency = float64(nc.Latency)
segment.ConfiguredNetChar.Jitter = float64(nc.LatencyVariation)
segment.ConfiguredNetChar.PacketLoss = float64(nc.PacketLoss)
segment.ConfiguredNetChar.Throughput = float64(ncThroughput)
// Initialize segment-specific BW attributes from Algo config
if algo.Config.IsPercentage {
segment.MaxBwPerInactiveFlow = algo.Config.MaxBwPerInactiveFlow * maxThroughput / 100
if segment.MaxBwPerInactiveFlow < algo.Config.MaxBwPerInactiveFlowFloor {
segment.MaxBwPerInactiveFlow = algo.Config.MaxBwPerInactiveFlowFloor
}
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
segment.MinActivityThreshold = algo.Config.MinActivityThreshold * maxThroughput / 100
segment.IncrementalStep = algo.Config.IncrementalStep * maxThroughput / 100
segment.InactivityIncrementalStep = algo.Config.InactivityIncrementalStep * maxThroughput / 100
segment.TolerationThreshold = algo.Config.TolerationThreshold * maxThroughput / 100
segment.ActionUpperThreshold = algo.Config.ActionUpperThreshold * maxThroughput / 100
} else {
segment.MaxBwPerInactiveFlow = algo.Config.MaxBwPerInactiveFlow
segment.MinActivityThreshold = algo.Config.MinActivityThreshold
segment.IncrementalStep = algo.Config.IncrementalStep
segment.InactivityIncrementalStep = algo.Config.InactivityIncrementalStep
segment.TolerationThreshold = algo.Config.TolerationThreshold
segment.ActionUpperThreshold = algo.Config.ActionUpperThreshold
}
// Add segment to map
algo.SegmentMap[segmentName] = segment
}
// Add flow to segment flow map
flow := algo.FlowMap[flowName]
if flow != nil {
segment.Flows = append(segment.Flows, flow)
} else {
log.Error("Missing flow: ", flowName)
}
return segment
}
// getMetricsThroughputEntryHandler -
func (algo *SegmentAlgorithm) getMetricsThroughputEntryHandler(key string, fields map[string]string, userData interface{}) error {
subKey := strings.Split(key, ":")
for trafficFrom, throughput := range fields {
Kevin Di Lallo
committed
flow := algo.FlowMap[trafficFrom+":"+subKey[len(subKey)-2]]
if flow != nil {
value, _ := strconv.ParseFloat(throughput, 64)
flow.CurrentThroughput = value
}
}
return nil
}
func (algo *SegmentAlgorithm) reCalculateNetChar() {
//reset every planned throughput values for every flow since they will start to populate those
for _, flow := range algo.FlowMap {
resetComputedNetChar(flow)
}
//all segments determined by the scenario
for _, segment := range algo.SegmentMap {
//throughput specific
updateMaxFairShareBwPerFlow(segment)
unusedBw, list := needToReevaluate(segment)
if list != nil {
if algo.Config.LogVerbose {
log.Info("Segment ", segment.Name, " reevaluation result - BW unused: ", unusedBw, "***Flows to evaluate***: ", printFlowNamesFromList(list))
}
recalculateSegmentBw(segment, list, unusedBw)
}
//latency, jitter, packet-loss computation for each flow in each segment
for _, flow := range segment.Flows {
flow.ComputedLatency += segment.ConfiguredNetChar.Latency
flow.ComputedJitter += segment.ConfiguredNetChar.Jitter
if flow.ComputedPacketLoss == 0 {
//first time it finds a value, it applies it directly
flow.ComputedPacketLoss = segment.ConfiguredNetChar.PacketLoss
} else {
if segment.ConfiguredNetChar.PacketLoss != 0 {
flow.ComputedPacketLoss += (flow.ComputedPacketLoss * (1 - segment.ConfiguredNetChar.PacketLoss))
}
}
}
if algo.Config.LogVerbose {
printFlows(segment)
}
}
}
// resetComputedNetChar -
func resetComputedNetChar(flow *SegAlgoFlow) {
flow.MaxPlannedThroughput = MAX_THROUGHPUT
flow.MaxPlannedLowerBound = MAX_THROUGHPUT
flow.MaxPlannedUpperBound = MAX_THROUGHPUT
flow.ComputedLatency = 0
flow.ComputedJitter = 0
flow.ComputedPacketLoss = 0
}
// recalculateSegmentBw -
func recalculateSegmentBw(segment *SegAlgoSegment, flowsToEvaluate []*SegAlgoFlow, unusedBw float64) {
nbEvaluatedflowsLeft := len(flowsToEvaluate)
if segment.CurrentThroughput > segment.ConfiguredNetChar.Throughput || nbEvaluatedflowsLeft >= 1 {
//category 1 Flows
for _, flow := range flowsToEvaluate {
if flow.CurrentThroughput+segment.IncrementalStep > segment.MaxFairShareBwPerFlow {
flow.PlannedThroughput = segment.MaxFairShareBwPerFlow //category 2 or 3
} else {
if flow.CurrentThroughput <= segment.MinActivityThreshold {
flow.PlannedThroughput = segment.MaxBwPerInactiveFlow
flow.PlannedUpperBound = segment.InactivityIncrementalStep
flow.PlannedLowerBound = 0
} else {
flow.PlannedThroughput = flow.CurrentThroughput + segment.IncrementalStep
if flow.PlannedThroughput > flow.ConfiguredNetChar.Throughput {
flow.PlannedThroughput = flow.ConfiguredNetChar.Throughput
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
}
flow.PlannedUpperBound = flow.PlannedThroughput - segment.ActionUpperThreshold
flow.PlannedLowerBound = flow.PlannedUpperBound - segment.TolerationThreshold
//lower bound cannot be less than min threshold
if flow.PlannedLowerBound < segment.MinActivityThreshold {
flow.PlannedLowerBound = segment.MinActivityThreshold
}
}
nbEvaluatedflowsLeft--
if flow.PlannedThroughput != segment.MaxBwPerInactiveFlow {
unusedBw -= flow.PlannedThroughput
}
}
}
var extra float64
if nbEvaluatedflowsLeft > 0 {
//category 2 Flows
for _, flow := range flowsToEvaluate {
if flow.PlannedThroughput == segment.MaxFairShareBwPerFlow {
if flow.CurrentThroughput < segment.MaxFairShareBwPerFlow {
nbEvaluatedflowsLeft--
if nbEvaluatedflowsLeft == 0 { //allocate everything of what is left
flow.PlannedThroughput = unusedBw
if flow.PlannedThroughput > flow.ConfiguredNetChar.Throughput {
flow.PlannedThroughput = flow.ConfiguredNetChar.Throughput
}
flow.PlannedUpperBound = flow.PlannedThroughput
flow.PlannedLowerBound = flow.PlannedThroughput - segment.TolerationThreshold
//lower bound cannot be less than min threshold
if flow.PlannedLowerBound < segment.MinActivityThreshold {
flow.PlannedLowerBound = segment.MinActivityThreshold
}
} else {
flow.PlannedThroughput = flow.CurrentThroughput + segment.IncrementalStep
if flow.PlannedThroughput > flow.ConfiguredNetChar.Throughput {
flow.PlannedThroughput = flow.ConfiguredNetChar.Throughput
}
flow.PlannedUpperBound = flow.PlannedThroughput - segment.ActionUpperThreshold
flow.PlannedLowerBound = flow.PlannedUpperBound - segment.TolerationThreshold
//lower bound cannot be less than min threshold
if flow.PlannedLowerBound < segment.MinActivityThreshold {
flow.PlannedLowerBound = segment.MinActivityThreshold
}
}
unusedBw -= flow.PlannedThroughput
}
}
}
if nbEvaluatedflowsLeft > 0 {
if nbEvaluatedflowsLeft >= 1 {
extra = (unusedBw - float64(nbEvaluatedflowsLeft)*segment.MaxFairShareBwPerFlow) / float64(nbEvaluatedflowsLeft)
} else {
extra = 0
}
//category 3
for _, flow := range flowsToEvaluate {
if flow.PlannedThroughput == segment.MaxFairShareBwPerFlow && flow.CurrentThroughput >= segment.MaxFairShareBwPerFlow {
flow.PlannedThroughput = segment.MaxFairShareBwPerFlow + extra
if flow.PlannedThroughput > flow.ConfiguredNetChar.Throughput {
flow.PlannedThroughput = flow.ConfiguredNetChar.Throughput
}
flow.PlannedUpperBound = flow.PlannedThroughput - segment.ActionUpperThreshold
flow.PlannedLowerBound = flow.PlannedUpperBound - segment.TolerationThreshold
unusedBw -= flow.PlannedThroughput
}
}
}
}
}
//we allocate all the bw to active users and very low values to inactive ones if there is any residual
//using a minimum value that is close but not exactly 0, since we use float operations and approximation may not lead to a perfect
if unusedBw >= 1 {
for _, flow := range flowsToEvaluate {
if flow.CurrentThroughput > segment.MinActivityThreshold {
flow.PlannedThroughput = segment.MaxFairShareBwPerFlow
if flow.PlannedThroughput > flow.ConfiguredNetChar.Throughput {
flow.PlannedThroughput = flow.ConfiguredNetChar.Throughput
}
flow.PlannedLowerBound = 0
flow.PlannedUpperBound = 0
}
}
}
//update or not the throughput
for _, flow := range flowsToEvaluate {
if flow.PlannedThroughput < flow.MaxPlannedThroughput {
if flow.PlannedThroughput <= 0 {
log.Error("Max : ", flow.PlannedThroughput, "---", flow.MaxPlannedThroughput)
}
flow.MaxPlannedThroughput = flow.PlannedThroughput
flow.MaxPlannedLowerBound = flow.PlannedLowerBound
flow.MaxPlannedUpperBound = flow.PlannedUpperBound
}
}
}
// needToReevaluate - determines which Flows must be recalculated for bandwidth sharing within the segment
func needToReevaluate(segment *SegAlgoSegment) (unusedBw float64, list []*SegAlgoFlow) {
unusedBw = segment.ConfiguredNetChar.Throughput
//how many active connections that needs to be taken into account
for _, flow := range segment.Flows {
if flow.CurrentThroughput < flow.AllocatedThroughputLowerBound || flow.CurrentThroughput > flow.AllocatedThroughputUpperBound || flow.CurrentThroughput >= segment.MaxFairShareBwPerFlow || flow.UpdateRequired {
list = append(list, flow)
} else {