コード例 #1
0
ファイル: control.go プロジェクト: hkwi/gopenflow
func (self *ofmMpMeterConfig) Map() Reducable {
	mpreq := ofp4.MeterMultipartRequest(ofp4.MultipartRequest(self.req).Body())
	meterId := mpreq.MeterId()
	for meterId, meter := range self.pipe.getMeters(meterId) {
		var bands []byte
		for _, b := range meter.bands {
			if bin, err := b.MarshalBinary(); err != nil {
				panic(err)
			} else {
				bands = append(bands, bin...)
			}
		}
		var flags uint16
		if meter.flagPkts {
			flags |= ofp4.OFPMF_PKTPS
		} else {
			flags |= ofp4.OFPMF_KBPS
		}
		if meter.flagBurst {
			flags |= ofp4.OFPMF_BURST
		}
		if meter.flagStats {
			flags |= ofp4.OFPMF_STATS
		}
		chunk := ofp4.MakeMeterConfig(flags, meterId, bands)
		self.chunks = append(self.chunks, chunk)
	}
	return self
}
コード例 #2
0
ファイル: control.go プロジェクト: hkwi/gopenflow
func (self *ofmMpMeter) Map() Reducable {
	pipe := self.pipe

	meterId := ofp4.MeterMultipartRequest(ofp4.MultipartRequest(self.req).Body()).MeterId()
	for meterId, meter := range pipe.getMeters(meterId) {
		duration := time.Now().Sub(meter.created)
		var bands []byte
		for _, b := range meter.bands {
			bands = append(bands, ofp4.MakeMeterBandStats(b.getPacketCount(), b.getByteCount())...)
		}
		flowCount := len(pipe.filterFlows(flowFilter{
			tableId:  ofp4.OFPTT_ALL,
			outPort:  ofp4.OFPP_ANY,
			outGroup: ofp4.OFPG_ANY,
			meterId:  meterId,
		}))
		chunk := ofp4.MakeMeterStats(
			meterId,
			uint32(flowCount),
			meter.packetCount,
			meter.byteCount,
			uint32(duration.Seconds()),
			uint32(duration.Nanoseconds()%int64(time.Second)),
			bands)
		self.chunks = append(self.chunks, chunk)
	}
	return self
}