Skip to content
Snippets Groups Projects
Commit 34bc8929 authored by kwanggithub's avatar kwanggithub
Browse files

Merge branch 'backport' of ../../bsckwang/bigswitchcontroller into LB

parents 34710a43 44dad720
No related branches found
No related tags found
No related merge requests found
Showing
with 1751 additions and 414 deletions
......@@ -9,3 +9,4 @@ target
thrift
*.swp
*.pyc
findbugs-results
......@@ -46,6 +46,8 @@
<property name="thrift.package" value="net/floodlightcontroller/packetstreamer/thrift"/>
<property name="ant.build.javac.source" value="1.6"/>
<property name="ant.build.javac.target" value="1.6"/>
<property name="findbugs.home" value="../build/findbugs-2.0.2"/>
<property name="findbugs.results" value="findbugs-results" />
<property name="lib" location="lib"/>
<patternset id="lib">
......@@ -65,6 +67,10 @@
<include name="jython-2.5.2.jar"/>
<include name="libthrift-0.7.0.jar"/>
<include name="guava-13.0.1.jar" />
<include name="commons-logging-1.1.1.jar" />
<include name="httpclient-4.2.2.jar" />
<include name="httpcore-4.2.2.jar" />
<include name="json-simple-1.1.1.jar" />
</patternset>
<path id="classpath">
......@@ -276,4 +282,34 @@
</exec>
</target>
<target name="findbugs-xml" depends="init,compile">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${findbugs.home}/lib/findbugs-ant.jar"/>
<mkdir dir="${findbugs.results}"/>
<findbugs home="${findbugs.home}"
output="xml"
outputFile="${findbugs.results}/results.xml" >
<sourcePath path="${source}" />
<sourcePath path="${thrift.out.dir}" />
<class location="${build}" />
<auxClasspath>
<path refid="classpath" />
</auxClasspath>
</findbugs>
</target>
<target name="findbugs" depends="init,compile">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${findbugs.home}/lib/findbugs-ant.jar"/>
<mkdir dir="${findbugs.results}"/>
<findbugs home="${findbugs.home}"
output="html"
outputFile="${findbugs.results}/results.html" >
<sourcePath path="${source}" />
<sourcePath path="${thrift.out.dir}" />
<class location="${build}" />
<auxClasspath>
<path refid="classpath" />
</auxClasspath>
</findbugs>
</target>
</project>
File added
File added
File added
File added
......@@ -458,11 +458,14 @@ entity.getLastSeenTimestamp().getTime());
} else if (oldAPFlag) {
// retain oldAP as is. Put the newAP in oldAPs for flagging
// possible duplicates.
oldAPList = new ArrayList<AttachmentPoint>();
if (oldAPs != null) oldAPList.addAll(oldAPs);
// Add ot oldAPList only if it was picked up from the oldAPList
oldAPList.add(newAP);
this.oldAPs = oldAPList;
oldAPList = new ArrayList<AttachmentPoint>();
if (oldAPs != null) oldAPList.addAll(oldAPs);
// Add to oldAPList only if it was picked up from the oldAPList
oldAPList.add(newAP);
this.oldAPs = oldAPList;
if (!topology.isInSameBroadcastDomain(oldAP.getSw(), oldAP.getPort(),
newAP.getSw(), newAP.getPort()))
return true; // attachment point changed.
}
return false;
}
......
......@@ -75,6 +75,7 @@ DeviceManagerImpl.DeviceUpdate.Change.*;
import org.openflow.protocol.OFMatchWithSwDpid;
import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFPacketIn;
import org.openflow.protocol.OFPort;
import org.openflow.protocol.OFType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -253,8 +254,8 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
@Override
public int compare(AttachmentPoint oldAP, AttachmentPoint newAP) {
//First compare based on L2 domain ID;
long oldSw = oldAP.getSw();
short oldPort = oldAP.getPort();
long oldDomain = topology.getL2DomainId(oldSw);
......@@ -268,6 +269,16 @@ IFlowReconcileListener, IInfoProvider, IHAListener {
if (oldDomain < newDomain) return -1;
else if (oldDomain > newDomain) return 1;
// Give preference to OFPP_LOCAL always
if (oldPort != OFPort.OFPP_LOCAL.getValue() &&
newPort == OFPort.OFPP_LOCAL.getValue()) {
return -1;
} else if (oldPort == OFPort.OFPP_LOCAL.getValue() &&
newPort != OFPort.OFPP_LOCAL.getValue()) {
return 1;
}
// We expect that the last seen of the new AP is higher than
// old AP, if it is not, just reverse and send the negative
// of the result.
......
package net.floodlightcontroller.loadbalancer;
import java.util.Collection;
import net.floodlightcontroller.core.module.IFloodlightService;
public interface ILoadBalancerService extends IFloodlightService {
/**
* List all current Vips.
*/
public Collection<LBVip> listVips();
/**
* List selected Vip by its ID.
* @param vipId Id of requested Vip
*/
public Collection<LBVip> listVip(String vipId);
/**
* Create and return a new Vip.
* @param LBVip vip: data structure with caller provided Vip attributes
* @return LBVip: Created Vip
*/
public LBVip createVip(LBVip vip);
/**
* Update and return an existing Vip.
* @param LBVip vip: data structure with caller provided Vip attributes
* @return LBVip: Updated Vip
*/
public LBVip updateVip(LBVip vip);
/**
* Remove an existing Vip.
* @param String vipId
* @return int: removal status
*/
public int removeVip(String vipId);
/**
* List all current pools.
*/
public Collection<LBPool> listPools();
/**
* List selected pool by its ID.
* @param poolId Id of requested pool
*/
public Collection<LBPool> listPool(String poolId);
/**
* Create and return a new pool.
* @param LBPool pool: data structure with caller provided pool attributes
* @return LBPool: Created pool
*/
public LBPool createPool(LBPool pool);
/**
* Update and return an existing pool.
* @param LBPool pool: data structure with caller provided pool attributes
* @return LBPool: Updated pool
*/
public LBPool updatePool(LBPool pool);
/**
* Remove an existing pool.
* @param String poolId
* @return int: removal status
*/
public int removePool(String poolId);
/**
* List all current members.
*/
public Collection<LBMember> listMembers();
/**
* List selected member by its ID.
* @param memberId Id of requested member
*/
public Collection<LBMember> listMember(String memberId);
/**
* List all members in a specified pool.
*/
public Collection<LBMember> listMembersByPool(String poolId);
/**
* Create and return a new member.
* @param LBMember member: data structure with caller provided member attributes
* @return LBMember: Created member
*/
public LBMember createMember(LBMember member);
/**
* Update and return an existing member.
* @param LBMember member: data structure with caller provided member attributes
* @return LBMember: Updated member
*/
public LBMember updateMember(LBMember member);
/**
* Remove an existing member.
* @param String memberId
* @return int: removal status
*/
public int removeMember(String memberId);
/**
* List all current monitors.
*/
public Collection<LBMonitor> listMonitors();
/**
* List selected monitor by its ID.
* @param monitorId Id of requested monitor
*/
public Collection<LBMonitor> listMonitor(String monitorId);
/**
* Create and return a new monitor.
* @param LBMonitor monitor: data structure with caller provided monitor attributes
* @return LBMonitor: Created monitor
*/
public LBMonitor createMonitor(LBMonitor monitor);
/**
* Update and return an existing monitor.
* @param LBMonitor monitor: data structure with caller provided pool attributes
* @return LBMonitor: Updated monitor
*/
public LBMonitor updateMonitor(LBMonitor monitor);
/**
* Remove an existing monitor.
* @param String monitorId
* @return int: removal status
*/
public int removeMonitor(String monitorId);
}
package net.floodlightcontroller.loadbalancer;
import org.codehaus.jackson.map.annotate.JsonSerialize;
/**
* Data structure for Load Balancer based on
* Quantum proposal http://wiki.openstack.org/LBaaS/CoreResourceModel/proposal
*
* @author KC Wang
*/
@JsonSerialize(using=LBMemberSerializer.class)
public class LBMember {
protected String id;
protected int address;
protected short port;
protected String macString;
protected int connectionLimit;
protected short adminState;
protected short status;
protected String poolId;
protected String vipId;
public LBMember() {
id = String.valueOf((int) (Math.random()*10000));
address = 0;
macString = null;
port = 0;
connectionLimit = 0;
adminState = 0;
status = 0;
poolId = null;
vipId = null;
}
}
package net.floodlightcontroller.loadbalancer;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
public class LBMemberSerializer extends JsonSerializer<LBMember>{
@Override
public void serialize(LBMember member, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("id", member.id);
jGen.writeStringField("address", String.valueOf(member.address));
jGen.writeStringField("port", Short.toString(member.port));
jGen.writeStringField("poolId", member.poolId);
jGen.writeStringField("vipId", member.vipId);
jGen.writeEndObject();
}
}
package net.floodlightcontroller.loadbalancer;
/**
* Data structure for Load Balancer based on
* Quantum proposal http://wiki.openstack.org/LBaaS/CoreResourceModel/proposal
*
* @author KC Wang
*/
public class LBMonitor {
protected String id;
protected String name;
protected short type;
protected short delay;
protected short timeout;
protected short attemptsBeforeDeactivation;
protected String netId;
protected int address;
protected byte protocol;
protected short port;
//protected path??
protected short adminState;
protected short status;
public LBMonitor() {
id = null;
name = null;
type = 0;
delay = 0;
timeout = 0;
attemptsBeforeDeactivation = 0;
netId = null;
address = 0;
protocol = 0;
port = 0;
adminState = 0;
status = 0;
}
}
package net.floodlightcontroller.loadbalancer;
import java.util.ArrayList;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import net.floodlightcontroller.loadbalancer.LoadBalancer.IPClient;
/**
* Data structure for Load Balancer based on
* Quantum proposal http://wiki.openstack.org/LBaaS/CoreResourceModel/proposal
*
* @author KC Wang
*/
@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;
}
}
}
package net.floodlightcontroller.loadbalancer;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
public class LBPoolSerializer extends JsonSerializer<LBPool>{
@Override
public void serialize(LBPool pool, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("name", pool.name);
jGen.writeStringField("id", pool.id);
jGen.writeStringField("vipId", pool.vipId);
for (int i=0; i<pool.members.size(); i++)
jGen.writeStringField("pool", pool.members.get(i));
jGen.writeEndObject();
}
}
package net.floodlightcontroller.loadbalancer;
/**
* Data structure for Load Balancer based on
* Quantum proposal http://wiki.openstack.org/LBaaS/CoreResourceModel/proposal
*
* @author KC Wang
*/
public class LBStats {
protected int bytesIn;
protected int bytesOut;
protected int activeConnections;
protected int totalConnections;
public LBStats() {
bytesIn = 0;
bytesOut = 0;
activeConnections = 0;
totalConnections = 0;
}
}
package net.floodlightcontroller.loadbalancer;
import java.util.ArrayList;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import net.floodlightcontroller.loadbalancer.LoadBalancer.IPClient;
import net.floodlightcontroller.util.MACAddress;
/**
* Data structure for Load Balancer based on
* Quantum proposal http://wiki.openstack.org/LBaaS/CoreResourceModel/proposal
*
* @author KC Wang
*/
@JsonSerialize(using=LBVipSerializer.class)
public class LBVip {
protected String id;
protected String name;
protected String tenantId;
protected String netId;
protected int address;
protected byte protocol;
protected short lbMethod;
protected short port;
protected ArrayList<String> pools;
protected boolean sessionPersistence;
protected int connectionLimit;
protected short adminState;
protected short status;
protected MACAddress proxyMac;
public LBVip() {
this.id = String.valueOf((int) (Math.random()*10000));
this.name = null;
this.tenantId = null;
this.netId = null;
this.address = 0;
this.protocol = 0;
this.lbMethod = 0;
this.port = 0;
this.pools = new ArrayList<String>();
this.sessionPersistence = false;
this.connectionLimit = 0;
this.address = 0;
this.status = 0;
this.proxyMac = MACAddress.valueOf("12:34:56:78:90:12");
}
public String pickPool(IPClient client) {
// for now, return the first pool; consider different pool choice policy later
if (pools.size() > 0)
return pools.get(0);
else
return null;
}
}
package net.floodlightcontroller.loadbalancer;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
public class LBVipSerializer extends JsonSerializer<LBVip>{
@Override
public void serialize(LBVip vip, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("name", vip.name);
jGen.writeStringField("id", vip.id);
jGen.writeStringField("address", String.valueOf(vip.address));
jGen.writeStringField("protocol", Byte.toString(vip.protocol));
jGen.writeStringField("port", Short.toString(vip.port));
jGen.writeEndObject();
}
}
This diff is collapsed.
package net.floodlightcontroller.loadbalancer;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.routing.Router;
import net.floodlightcontroller.restserver.RestletRoutable;
import net.floodlightcontroller.virtualnetwork.NoOp;
public class LoadBalancerWebRoutable implements RestletRoutable {
@Override
public Restlet getRestlet(Context context) {
Router router = new Router(context);
router.attach("/vips/", VipsResource.class); // GET, POST
router.attach("/vips/{vip}", VipsResource.class); // GET, PUT, DELETE
router.attach("/pools/", PoolsResource.class); // GET, POST
router.attach("/pools/{pool}", PoolsResource.class); // GET, PUT, DELETE
router.attach("/members/", MembersResource.class); // GET, POST
router.attach("/members/{member}", MembersResource.class); // GET, PUT, DELETE
router.attach("/pools/{pool}/members", PoolMemberResource.class); //GET
router.attach("/health_monitors/", MonitorsResource.class); //GET, POST
router.attach("/health_monitors/{monitor}", MonitorsResource.class); //GET, PUT, DELETE
router.attachDefault(NoOp.class);
return router;
}
@Override
public String basePath() {
return "/quantum/v1.0";
}
}
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