Developing lightweight computation at the DSG edge

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

[monitor-assign] Add policy #2


Signed-off-by: Roger Pueyo Centelles's avatarRoger Pueyo Centelles <rpueyo@ac.upc.edu>
parent c0c01710
......@@ -213,7 +213,7 @@ func initializeFlags() {
}
//Policy
if *policyPtr >= 1 && *policyPtr <= 1 {
if *policyPtr >= 1 && *policyPtr <= 2 {
policy = *policyPtr
}
......@@ -443,6 +443,71 @@ func reassignDevs() {
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.")
}
case 2:
// Policy #2: The monitoring server self-assigns those network devices that
// have the least monitoring devices already assigned. Devices are picked
// randomly, from those with less monitors, 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")
// Calculate which is the number of least monitors a device has
leastMons := 0
for _, v := range globalAssign {
leastMons = int(math.Max(float64(leastMons), float64(len(v.MonitorID))))
}
for _, v := range cnmlDevices {
if !isDeviceInAssignationSlice(v.ID, globalAssign) {
leastMons = 0
} else {
leastMons = int(math.Min(float64(leastMons), float64(len(globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID))))
}
}
fmt.Println(leastMons)
var unassignedDevices []cnml.DeviceIpv4sGraphserver
for _, v := range cnmlDevices {
if (!isDeviceInAssignationSlice(v.ID, globalAssign) || len(globalAssign[posDeviceInAssignationSlice(v.ID, globalAssign)].MonitorID) <= leastMons) && !isDeviceInAssignationSlice(v.ID, localAssign) {
unassignedDevices = append(unassignedDevices, v)
}
}
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++ {
......
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