Skip to content
algo-segment.go 37.5 KiB
Newer Older
	maxThroughput := 0.0
	latency := 0.0
	jitter := 0.0
	packetLoss := 0.0
	// Get max throughput based on Node Type, as well as other netcharse
	if p, ok := node.(*ceModel.Process); ok {
		maxThroughput = float64(p.AppThroughput)
		latency = float64(p.AppLatency)
		jitter = float64(p.AppLatencyVariation)
		packetLoss = float64(p.AppPacketLoss)
	} else if pl, ok := node.(*ceModel.PhysicalLocation); ok {
		maxThroughput = float64(pl.LinkThroughput)
		latency = float64(pl.LinkLatency)
		jitter = float64(pl.LinkLatencyVariation)
		packetLoss = float64(pl.LinkPacketLoss)
	} else if nl, ok := node.(*ceModel.NetworkLocation); ok {
		maxThroughput = float64(nl.TerminalLinkThroughput)
		latency = float64(nl.TerminalLinkLatency)
		jitter = float64(nl.TerminalLinkLatencyVariation)
		packetLoss = float64(nl.TerminalLinkPacketLoss)
	} else if zone, ok := node.(*ceModel.Zone); ok {
		if zone.NetChar != nil {
			maxThroughput = float64(zone.NetChar.Throughput)
			latency = float64(zone.NetChar.Latency)
			jitter = float64(zone.NetChar.LatencyVariation)
			packetLoss = float64(zone.NetChar.PacketLoss)
		}
	} else if domain, ok := node.(*ceModel.Domain); ok {
		maxThroughput = float64(domain.InterZoneThroughput)
		latency = float64(domain.InterZoneLatency)
		jitter = float64(domain.InterZoneLatencyVariation)
		packetLoss = float64(domain.InterZonePacketLoss)
	} else if deployment, ok := node.(*ceModel.Deployment); ok {
		maxThroughput = float64(deployment.InterDomainThroughput)
		latency = float64(deployment.InterDomainLatency)
		jitter = float64(deployment.InterDomainLatencyVariation)
		packetLoss = float64(deployment.InterDomainPacketLoss)
	} else {
		log.Error("Error casting element: " + elemName)
	}

	// For compatiblity reasons, set to default value if 0
	if maxThroughput == 0 {
		maxThroughput = DEFAULT_THROUGHPUT_LINK
	}

	nc.Throughput = maxThroughput
	nc.Latency = latency
	nc.Jitter = jitter
	nc.PacketLoss = packetLoss

	return nc
}

// printFlowNamesFromList -
func printFlowNamesFromList(list []*SegAlgoFlow) string {
	str := ""
	for _, flow := range list {
		str += flow.Name + "."
	}
	return str
}

// printFlows -
func printFlows(segment *SegAlgoSegment) {
	log.Info("Flows on segment ", segment.Name)
	for _, flow := range segment.Flows {
		log.Info(printFlow(flow))
	}
}

// printFlow -
func printFlow(flow *SegAlgoFlow) string {
	s0 := fmt.Sprintf("%x", &flow)
	s1 := flow.Name + "(" + s0 + ")"
	s2t := fmt.Sprintf("%f", flow.ConfiguredNetChar.Throughput)
	s2l := fmt.Sprintf("%f", flow.ConfiguredNetChar.Latency)
	s2j := fmt.Sprintf("%f", flow.ConfiguredNetChar.Jitter)
	s2p := fmt.Sprintf("%f", flow.ConfiguredNetChar.PacketLoss)
	s3a := fmt.Sprintf("%f", flow.AllocatedThroughput)
	s4a := fmt.Sprintf("%f", flow.AllocatedThroughputLowerBound)
	s5a := fmt.Sprintf("%f", flow.AllocatedThroughputUpperBound)
	s3m := fmt.Sprintf("%f", flow.MaxPlannedThroughput)
	s4m := fmt.Sprintf("%f", flow.MaxPlannedLowerBound)
	s5m := fmt.Sprintf("%f", flow.MaxPlannedUpperBound)
	s3p := fmt.Sprintf("%f", flow.PlannedThroughput)
	s4p := fmt.Sprintf("%f", flow.PlannedLowerBound)
	s5p := fmt.Sprintf("%f", flow.PlannedUpperBound)
	s6 := fmt.Sprintf("%f", flow.CurrentThroughput)
	s7l := fmt.Sprintf("%f", flow.ComputedLatency)
	s7j := fmt.Sprintf("%f", flow.ComputedJitter)
	s7p := fmt.Sprintf("%f", flow.ComputedPacketLoss)
	s8l := fmt.Sprintf("%f", flow.AppliedNetChar.Latency)
	s8j := fmt.Sprintf("%f", flow.AppliedNetChar.Jitter)
	s8p := fmt.Sprintf("%f", flow.AppliedNetChar.PacketLoss)

	str := s1 + ": " + "Current: " + s6 + " - Configured: [" + s2t + "-" + s2l + "-" + s2j + "-" + s2p + "] Allocated: " + s3a + "[" + s4a + "-" + s5a + "]" + " - MaxPlanned: " + s3m + "[" + s4m + "-" + s5m + "]" + " - Planned: " + s3p + "[" + s4p + "-" + s5p + "] Computed Net Char: [" + s7l + "-" + s7j + "-" + s7p + "] Applied Net Char: [" + s8l + "-" + s8j + "-" + s8p + "]"
	str += printPath(flow.Path)
	return str
}

// printPath -
func printPath(path *SegAlgoPath) string {
	str := ""
	first := true
	if path != nil {
		str = "Path: "
		for _, segment := range path.Segments {
			if first {
				str += segment.Name
				first = false
			} else {
				str += "..." + segment.Name
			}
		}
	}
	return str
}
Simon Pastor's avatar
Simon Pastor committed

// // printElement -
// func printElement(elem *SegAlgoNetElem) string {
// 	str := elem.Name + "-" + elem.Type + "-" + elem.PhyLocName + "-" + elem.PoaName + "-" + elem.ZoneName + "-" + elem.DomainName
// 	return str
// }