Beispiel #1
0
func (self matchHash) Key(target matchHash) uint32 {
	hasher := fnv.New32()
	for k, s := range self {
		var value, mask []byte
		if bKey, ok := k.(OxmKeyBasic); !ok || oxm.Header(bKey).Class() != ofp4.OFPXMC_OPENFLOW_BASIC {
			continue
		} else {
			length, _ := ofp4.OxmOfDefs(uint32(bKey))
			value = make([]byte, length)
			mask = make([]byte, length)
		}
		if t, ok := target[k]; ok {
			a := s.(OxmValueMask)
			b := t.(OxmValueMask)
			for i, _ := range mask {
				mask[i] = 0xFF
			}
			if a.Mask != nil {
				for i, _ := range mask {
					mask[i] &= a.Mask[i]
				}
			}
			if b.Mask != nil {
				for i, _ := range mask {
					mask[i] &= b.Mask[i]
				}
			}
			for i, _ := range value {
				value[i] = b.Value[i] & mask[i]
			}
		}
		hasher.Write(value)
	}
	return hasher.Sum32()
}
Beispiel #2
0
func (self oxmBasic) OxmId(id uint32) uint32 {
	length, mask := ofp4.OxmOfDefs(id)
	hdr := oxm.Header(id)
	hdr.SetMask(mask)
	if mask {
		hdr.SetLength(length * 2)
	} else {
		hdr.SetLength(length)
	}
	return uint32(hdr)
}
Beispiel #3
0
// creates a common match union parameter.
func (self matchHash) Merge(from matchHash) {
	var removal []OxmKey
	for k, s := range self {
		var a, b OxmValueMask
		var length int
		if bKey, ok := k.(OxmKeyBasic); !ok || oxm.Header(bKey).Class() != ofp4.OFPXMC_OPENFLOW_BASIC {
			continue
		} else if f, ok := from[k]; !ok {
			removal = append(removal, k)
			continue
		} else {
			a = s.(OxmValueMask)
			b = f.(OxmValueMask)
			length, _ = ofp4.OxmOfDefs(uint32(bKey))
		}
		fullMask := true
		mask := make([]byte, length)
		for i, _ := range mask {
			mask[i] = 0xFF
		}
		if a.Mask != nil {
			for i, _ := range mask {
				mask[i] &= a.Mask[i]
			}
		}
		if b.Mask != nil {
			for i, _ := range mask {
				mask[i] &= b.Mask[i]
			}
		}
		for i, m := range mask {
			mask[i] &^= (a.Value[i] & m) ^ (b.Value[i] & m)
			if mask[i] != 0 {
				fullMask = false
			}
		}
		if fullMask {
			removal = append(removal, k)
			continue
		}
		payload := OxmValueMask{
			Value: make([]byte, length),
			Mask:  mask,
		}
		for i, m := range mask {
			payload.Value[i] = a.Value[i] & m
		}
		self[k] = payload
	}
	for _, rem := range removal {
		delete(self, rem)
	}
}
Beispiel #4
0
func makeOxmBasic(oxmType uint32) []byte {
	length, mask := ofp4.OxmOfDefs(oxmType)
	if mask {
		length = length * 2
	}
	hdr := oxm.Header(oxmType)
	hdr.SetMask(mask)
	hdr.SetLength(length)
	buf := make([]byte, 4+length)
	binary.BigEndian.PutUint32(buf, oxmType)
	return buf
}