Developing lightweight computation at the DSG edge

Commit c0c01710 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[monitor-assign] Set current assignation policy as #1


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent edccffaa
......@@ -416,52 +416,62 @@ func reassignDevs() {
assgnchanges := false // Track changes in the assignation list
// If less than maximum devices are assigned and more can be assigned,
// pick some at random, at a maximum rate so that the maximum is reached
// in 1 hour, until the maximum is reached
if (len(localAssign) < maxDevs) && (len(localAssign) < len(cnmlDevices)) {
// Assign new nodes
toassign := int(math.Min(float64(int(math.Min(math.Min(float64(len(cnmlDevices)), float64(maxDevs))*float64(devsCheckInterval)/float64(fillingTime)+1, float64(len(cnmlDevices)-len(localAssign))))), float64(maxDevs-len(localAssign))))
fmt.Println("Assigning", toassign, "new devices")
//Create a list with all the unassigned devices
var unassignedDevices []cnml.DeviceIpv4sGraphserver
for _, v := range cnmlDevices {
if (!isDeviceInAssignationSlice(v.ID, globalAssign) || len(globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID) < minMons) && !isDeviceInAssignationSlice(v.ID, localAssign) {
unassignedDevices = append(unassignedDevices, v)
switch policy {
case 1:
// Policy #1: The monitoring server self-assigns those network devices that
// have less monitoring devices assigned than the minimum number specified
// by the minMons parameter. Devices are picked randomly until the server
// reaches its maximum number of monitored devices, specified by the maxDevs
// parameter.
// Check if more nodes can be assigned, and if there are any devices not
// being monitored by this server that could be assigned
if (len(localAssign) < maxDevs) && (len(localAssign) < len(cnmlDevices)) {
// Calculate how many new devices can be assigned
toassign := int(math.Min(float64(int(math.Min(math.Min(float64(len(cnmlDevices)), float64(maxDevs))*float64(devsCheckInterval)/float64(fillingTime)+1, float64(len(cnmlDevices)-len(localAssign))))), float64(maxDevs-len(localAssign))))
fmt.Println("Assigning", toassign, "new devices")
// Create a list with all the unassigned devices
var unassignedDevices []cnml.DeviceIpv4sGraphserver
for _, v := range cnmlDevices {
if (!isDeviceInAssignationSlice(v.ID, globalAssign) || len(globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID) < minMons) && !isDeviceInAssignationSlice(v.ID, localAssign) {
unassignedDevices = append(unassignedDevices, v)
}
}
}
fmt.Println(len(unassignedDevices), "devices unassigned") //, of which", len(assignGraphserver), "are assigned via web")
fmt.Println("Picking", toassign, "nodes randomly")
for i := 0; i < toassign; i++ {
if len(unassignedDevices) > 0 {
//Pick a random device from the unassigned list
randsource := rand.New(rand.NewSource(time.Now().UnixNano()))
j := randsource.Intn(len(unassignedDevices))
//Save it to the assigned devices list
var newAssignDev cnml.DeviceMonitorAssignation
newAssignDev.Device.ID = unassignedDevices[j].ID
newAssignDev.Device.Addresses = unassignedDevices[j].Addresses
newAssignDev.MonitorID = append(newAssignDev.MonitorID, ID)
localAssign = append(localAssign, newAssignDev)
assgnchanges = true
//Remove it from the unassigned devices list
unassignedDevices = rmDeviceFromSlice(unassignedDevices[j], unassignedDevices)
} else {
fmt.Println(toassign-i, "more devices were to be assigned, but no unassigned devices remain")
break
fmt.Println(len(unassignedDevices), "devices unassigned")
fmt.Println("Picking", toassign, "nodes randomly")
// Select some devices to self-assign, up to the previously calculated
// value in the "toassign" variable
for i := 0; i < toassign; i++ {
// Check if unassigned devices remain
if len(unassignedDevices) > 0 {
// Pick a random device from the unassigned list
randsource := rand.New(rand.NewSource(time.Now().UnixNano()))
j := randsource.Intn(len(unassignedDevices))
// Save it to the new assigned devices list
var newAssignDev cnml.DeviceMonitorAssignation
newAssignDev.Device.ID = unassignedDevices[j].ID
newAssignDev.Device.Addresses = unassignedDevices[j].Addresses
newAssignDev.MonitorID = append(newAssignDev.MonitorID, ID)
localAssign = append(localAssign, newAssignDev)
assgnchanges = true
// Remove it from the unassigned devices list
unassignedDevices = rmDeviceFromSlice(unassignedDevices[j], unassignedDevices)
} else {
fmt.Println(toassign-i, "more devices were to be assigned, but no unassigned devices remain")
break
}
}
fmt.Println(len(localAssign), "devices currently assigned to this monitor")
} else {
fmt.Println("Not assigning any new device.")
}
fmt.Println(len(localAssign), "devices currently assigned to this monitor")
} else {
//TODO: unassign devices if len(localAssign) > maxDevs
fmt.Println("Not assigning any new device")
}
// Update the new assigned devices to the global shared list
if assgnchanges {
fmt.Println("Exporting the new assigned devices list")
for _, v := range localAssign {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment