Skip to content
Snippets Groups Projects
Commit b8805585 authored by Diogo's avatar Diogo
Browse files

Load balance member picking through switch statistics is now possible

parent b5be294d
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,20 @@
package net.floodlightcontroller.loadbalancer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import org.projectfloodlight.openflow.types.U64;
import org.sdnplatform.sync.internal.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import net.floodlightcontroller.loadbalancer.LoadBalancer.IPClient;
import net.floodlightcontroller.statistics.SwitchPortBandwidth;
/**
* Data structure for Load Balancer based on
......@@ -32,43 +41,76 @@ import net.floodlightcontroller.loadbalancer.LoadBalancer.IPClient;
@JsonSerialize(using=LBPoolSerializer.class)
public class LBPool {
protected String id;
protected String name;
protected String tenantId;
protected String netId;
protected short lbMethod;
protected byte protocol;
protected ArrayList<String> members;
protected ArrayList<String> monitors;
protected short adminState;
protected short status;
protected String vipId;
protected int previousMemberIndex;
public LBPool() {
id = String.valueOf((int) (Math.random()*10000));
name = null;
tenantId = null;
netId = null;
lbMethod = 0;
protocol = 0;
members = new ArrayList<String>();
monitors = new ArrayList<String>();
adminState = 0;
status = 0;
previousMemberIndex = -1;
}
public String pickMember(IPClient client) {
// simple round robin for now; add different lbmethod later
if (members.size() > 0) {
previousMemberIndex = (previousMemberIndex + 1) % members.size();
return members.get(previousMemberIndex);
} else {
return null;
}
}
protected static Logger log = LoggerFactory.getLogger(LBPool.class);
protected String id;
protected String name;
protected String tenantId;
protected String netId;
protected short lbMethod;
protected byte protocol;
protected ArrayList<String> members;
protected ArrayList<String> monitors;
protected short adminState;
protected short status;
protected final static short STATISTICS = 2;
protected final static short ROUND_ROBIN = 1;
protected String vipId;
protected int previousMemberIndex;
public LBPool() {
id = String.valueOf((int) (Math.random()*10000));
name = null;
tenantId = null;
netId = null;
lbMethod = 0;
protocol = 0;
members = new ArrayList<String>();
monitors = new ArrayList<String>();
adminState = 0;
status = 0;
previousMemberIndex = -1;
}
public String pickMember(IPClient client, HashMap<String,U64> membersbandwidth) {
// Get the members that belong to this pool and the statistics for them
if(members.size() > 0){
if (lbMethod == STATISTICS && membersbandwidth.values() !=null) {
ArrayList<String> memb = new ArrayList<String>();
for(String memberId: membersbandwidth.keySet()){
for(int i=0;i<members.size();i++){
if(members.get(i).equals(memberId)){
memb.add(memberId);
log.info("MEMBER OF THIS POOL: {}", memberId);
log.info("RecievedX: {}",membersbandwidth.get(memberId).getBigInteger());
}
}
}
// return the member which has the minimum bandwidth usage, out of this pool members
if(!memb.isEmpty()){
ArrayList<U64> vals = new ArrayList<U64>();
for(int j=0;j<memb.size();j++){
vals.add(membersbandwidth.get(memb.get(j)));
}
log.info("Members {}", memb);
log.info("VALS {}", vals);
log.info("MEMBER PICKED {}", memb.get(vals.indexOf(Collections.min(vals))));
return memb.get(vals.indexOf(Collections.min(vals)));
}
// simple round robin
} else if(lbMethod == ROUND_ROBIN || lbMethod == 0){
log.info("ROUND_ROBIN");
previousMemberIndex = (previousMemberIndex + 1) % members.size();
return members.get(previousMemberIndex);
}
}
return null;
}
}
......@@ -128,7 +128,12 @@ public class PoolsResource extends ServerResource {
continue;
}
if (n.equals("lb_method")) {
pool.lbMethod = Short.parseShort(jp.getText());
String method = jp.getText();
if(method.equalsIgnoreCase("RR")){
pool.lbMethod = (short) 1;
} else if(method.equalsIgnoreCase("STATISTICS")){
pool.lbMethod = (short) 2;
}
continue;
}
if (n.equals("protocol")) {
......
......@@ -63,7 +63,7 @@ net.floodlightcontroller.restserver.RestApiServer.useHttp=YES
net.floodlightcontroller.restserver.RestApiServer.httpsPort=8081
net.floodlightcontroller.restserver.RestApiServer.httpPort=8080
net.floodlightcontroller.restserver.RestApiServer.accessControlAllowAllOrigins=TRUE
net.floodlightcontroller.statistics.StatisticsCollector.enable=FALSE
net.floodlightcontroller.statistics.StatisticsCollector.enable=TRUE
net.floodlightcontroller.statistics.StatisticsCollector.collectionIntervalPortStatsSeconds=10
net.floodlightcontroller.topology.TopologyManager.pathMetric=latency
net.floodlightcontroller.topology.TopologyManager.maxPathsToCompute=3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment