コード例 #1
0
ファイル: set.go プロジェクト: nplanel/skydive
func (fs *FlowSet) AvgBandwidth() (fsbw FlowSetBandwidth) {
	if len(fs.Flows) == 0 {
		return
	}

	fsbw.Duration = fs.End - fs.Start
	for _, f := range fs.Flows {
		fstart := f.Metric.Start
		fend := f.Metric.Last

		fduration := fend - fstart
		if fduration == 0 {
			fduration = 1
		}

		fdurationWindow := common.MinInt64(fend, fs.End) - common.MaxInt64(fstart, fs.Start)
		if fdurationWindow == 0 {
			fdurationWindow = 1
		}

		m := f.Metric
		fsbw.ABpackets += m.ABPackets * fdurationWindow / fduration
		fsbw.ABbytes += m.ABBytes * fdurationWindow / fduration
		fsbw.BApackets += m.BAPackets * fdurationWindow / fduration
		fsbw.BAbytes += m.BABytes * fdurationWindow / fduration
		fsbw.NBFlow++
	}
	return
}
コード例 #2
0
ファイル: set.go プロジェクト: skydive-project/skydive
// Merge merges two FlowSet. If Sorted both of the FlowSet have to be sorted
// first. If Dedup both of the FlowSet have to be dedup first too.
func (fs *FlowSet) Merge(ofs *FlowSet, context MergeContext) error {
	fs.Start = common.MinInt64(fs.Start, ofs.Start)
	if fs.Start == 0 {
		fs.Start = ofs.Start
	}
	fs.End = common.MaxInt64(fs.End, ofs.End)

	var err error
	if context.Sorted {
		if fs.Flows, err = fs.mergeSortedFlows(fs.Flows, ofs.Flows, context); err != nil {
			return err
		}
	} else if context.Dedup {
		return fs.mergeDedup(ofs, context.DedupBy)
	} else {
		fs.Flows = append(fs.Flows, ofs.Flows...)
	}

	return nil
}
コード例 #3
0
ファイル: set.go プロジェクト: nplanel/skydive
func (fs *FlowSet) Merge(ofs *FlowSet, context MergeContext) {
	fs.Start = common.MinInt64(fs.Start, ofs.Start)
	if fs.Start == 0 {
		fs.Start = ofs.Start
	}
	fs.End = common.MaxInt64(fs.End, ofs.End)

	if context.Sorted {
		fs.Flows = fs.mergeFlows(fs.Flows, ofs.Flows, context)
	} else if context.Dedup {
		uuids := make(map[string]bool)
		for _, flow := range fs.Flows {
			uuids[flow.TrackingID] = true
		}

		for _, flow := range ofs.Flows {
			if !uuids[flow.TrackingID] {
				fs.Flows = append(fs.Flows, flow)
			}
		}
	} else {
		fs.Flows = append(fs.Flows, ofs.Flows...)
	}
}