示例#1
0
//Random Key updates
func keyUpdates(key string) {
	valArray, _, _ := ecc.Get("network", key)
	currVal := make([]byte, len(valArray))
	copy(currVal, valArray)
	valArray = []byte("value1")
	ecc.Put("network", key, valArray, currVal)
	time.Sleep(time.Second * 2)
	updArray := []byte("value2")
	ecc.Put("network", key, updArray, valArray)
	time.Sleep(time.Second * 2)
}
示例#2
0
func GetNetwork(id string) (*Network, error) {
	netByteArray, _, ok := ecc.Get(networkStore, id)
	if ok {
		network := &Network{}
		err := json.Unmarshal(netByteArray, network)
		if err != nil {
			return nil, err
		}
		return network, nil
	}
	return nil, errors.New("Network unavailable")
}
示例#3
0
func releaseVlan(vlan uint) {
	vlanArray, _, ok := ecc.Get(vlanStore, "vlan")
	currVal := make([]byte, vlanCount/8)
	copy(currVal, vlanArray)
	if !ok {
		vlanArray = make([]byte, vlanCount/8)
	}
	clearBit(vlanArray, vlan-1)
	eccerr := ecc.Put(vlanStore, "vlan", vlanArray, currVal)
	if eccerr == ecc.OUTDATED {
		releaseVlan(vlan)
	}
}
示例#4
0
func IPAMRelease(address net.IP, subnet net.IPNet) bool {
	addrArray, _, ok := ecc.Get(dataStore, subnet.String())
	currVal := make([]byte, len(addrArray))
	copy(currVal, addrArray)
	if !ok {
		return false
	}
	pos := getBitPosition(address, subnet)
	clearBit(addrArray, pos-1)
	eccerr := ecc.Put(dataStore, subnet.String(), addrArray, currVal)
	if eccerr == ecc.OUTDATED {
		return IPAMRelease(address, subnet)
	}
	return true
}
示例#5
0
func allocateVlan() (uint, error) {
	vlanArray, _, ok := ecc.Get(vlanStore, "vlan")
	currVal := make([]byte, vlanCount/8)
	copy(currVal, vlanArray)
	if !ok {
		vlanArray = make([]byte, vlanCount/8)
	}
	vlan := testAndSetBit(vlanArray)
	if vlan >= vlanCount {
		return vlanCount, errors.New("Vlan unavailable")
	}
	eccerr := ecc.Put(vlanStore, "vlan", vlanArray, currVal)
	if eccerr == ecc.OUTDATED {
		return allocateVlan()
	}
	return vlan, nil
}
示例#6
0
func IPAMRequest(subnet net.IPNet) net.IP {
	bits := bitCount(subnet)
	bc := int(bits / 8)
	partial := int(math.Mod(bits, float64(8)))

	if partial != 0 {
		bc += 1
	}
	addrArray, _, ok := ecc.Get(dataStore, subnet.String())
	currVal := make([]byte, len(addrArray))
	copy(currVal, addrArray)
	if !ok {
		addrArray = make([]byte, bc)
	}
	pos := testAndSetBit(addrArray)
	eccerr := ecc.Put(dataStore, subnet.String(), addrArray, currVal)
	if eccerr == ecc.OUTDATED {
		return IPAMRequest(subnet)
	}
	return getIP(subnet, pos)
}