func computeInfo()

in cmd/ziffy/node/print.go [130:206]


func computeInfo(routes []PathInfo, cfThreshold ptp.Correction) map[keyPair]*SwitchPrintInfo {
	discovered := make(map[keyPair]*SwitchPrintInfo)

	for _, route := range routes {
		for swIndex, swh := range route.switches {
			corrField := ptp.Correction(0)
			last := false
			host := getHostNoPrefix(swh.ip)
			intf := getHostIfPrefix(swh.ip)

			if swh.ip == route.switches[len(route.switches)-1].ip {
				last = true
			} else {
				// If switches are not adjacent (hop count difference > 1) do not subtract CF
				// This may happen in two cases: switch does not send ICMP Hop Limit Exceeded
				// back to source or the packet may be lost in transit
				if route.switches[swIndex+1].hop != route.switches[swIndex].hop+1 {
					last = true
				} else {
					corrField = route.switches[swIndex+1].corrField - route.switches[swIndex].corrField
				}
			}

			if swh.hop == 1 && route.rackSwHostname != "" {
				host = route.rackSwHostname
			}

			pair := keyPair{
				host: host,
				hop:  int(swh.hop),
			}
			if discovered[pair] == nil {
				discovered[pair] = &SwitchPrintInfo{
					ip:        swh.ip,
					hostname:  host,
					interf:    intf,
					totalCF:   corrField,
					routes:    1,
					hop:       int(swh.hop),
					last:      last,
					maxCF:     corrField,
					minCF:     corrField,
					divRoutes: 1,
				}
			} else {
				discovered[pair].routes++
				if !last {
					discovered[pair].totalCF += corrField
					discovered[pair].divRoutes++
					if discovered[pair].maxCF < corrField {
						discovered[pair].maxCF = corrField
					}
					if discovered[pair].minCF > corrField {
						discovered[pair].minCF = corrField
					}
				}
			}
		}
	}
	for _, sw := range discovered {
		if sw.last {
			sw.avgCF = ptp.Correction(0)
			sw.tcEnable = tcNA
			continue
		}
		sw.avgCF = sw.totalCF / ptp.Correction(sw.divRoutes)

		avgCFNs := sw.avgCF.Nanoseconds()
		cfThresholdNs := cfThreshold.Nanoseconds()
		if math.Abs(avgCFNs) > cfThresholdNs {
			sw.tcEnable = tcTrue
		} else {
			sw.tcEnable = tcFalse
		}
	}
	return discovered
}