Skip to content
Snippets Groups Projects
Commit 3b9514b6 authored by Kuang-Ching Wang's avatar Kuang-Ching Wang
Browse files

Merge pull request #362 from kwanggithub/master

Replace REST calls in load balancer module to use internal static flow pusher calls
parents d29770de f650f9f2
No related branches found
No related tags found
No related merge requests found
...@@ -67,9 +67,6 @@ ...@@ -67,9 +67,6 @@
<include name="jython-2.5.2.jar"/> <include name="jython-2.5.2.jar"/>
<include name="libthrift-0.7.0.jar"/> <include name="libthrift-0.7.0.jar"/>
<include name="guava-13.0.1.jar" /> <include name="guava-13.0.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> </patternset>
<path id="classpath"> <path id="classpath">
......
File deleted
File deleted
File deleted
package net.floodlightcontroller.loadbalancer; package net.floodlightcontroller.loadbalancer;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
...@@ -14,15 +11,8 @@ import java.util.HashSet; ...@@ -14,15 +11,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.http.HttpResponse; import org.openflow.protocol.OFFlowMod;
import org.apache.http.client.ClientProtocolException; import org.openflow.protocol.OFMatch;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.json.simple.JSONObject;
import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFPacketIn; import org.openflow.protocol.OFPacketIn;
import org.openflow.protocol.OFPacketOut; import org.openflow.protocol.OFPacketOut;
...@@ -31,6 +21,7 @@ import org.openflow.protocol.OFType; ...@@ -31,6 +21,7 @@ import org.openflow.protocol.OFType;
import org.openflow.protocol.action.OFAction; import org.openflow.protocol.action.OFAction;
import org.openflow.protocol.action.OFActionOutput; import org.openflow.protocol.action.OFActionOutput;
import org.openflow.util.HexString; import org.openflow.util.HexString;
import org.openflow.util.U16;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -55,6 +46,8 @@ import net.floodlightcontroller.packet.UDP; ...@@ -55,6 +46,8 @@ import net.floodlightcontroller.packet.UDP;
import net.floodlightcontroller.restserver.IRestApiService; import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.routing.IRoutingService; import net.floodlightcontroller.routing.IRoutingService;
import net.floodlightcontroller.routing.Route; import net.floodlightcontroller.routing.Route;
import net.floodlightcontroller.staticflowentry.IStaticFlowEntryPusherService;
import net.floodlightcontroller.staticflowentry.StaticFlowEntries;
import net.floodlightcontroller.topology.ITopologyService; import net.floodlightcontroller.topology.ITopologyService;
import net.floodlightcontroller.topology.NodePortTuple; import net.floodlightcontroller.topology.NodePortTuple;
import net.floodlightcontroller.util.MACAddress; import net.floodlightcontroller.util.MACAddress;
...@@ -87,6 +80,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -87,6 +80,7 @@ public class LoadBalancer implements IFloodlightModule,
protected IDeviceService deviceManager; protected IDeviceService deviceManager;
protected IRoutingService routingEngine; protected IRoutingService routingEngine;
protected ITopologyService topology; protected ITopologyService topology;
protected IStaticFlowEntryPusherService sfp;
protected HashMap<String, LBVip> vips; protected HashMap<String, LBVip> vips;
protected HashMap<String, LBPool> pools; protected HashMap<String, LBPool> pools;
...@@ -99,6 +93,9 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -99,6 +93,9 @@ public class LoadBalancer implements IFloodlightModule,
//Copied from Forwarding with message damper routine for pushing proxy Arp //Copied from Forwarding with message damper routine for pushing proxy Arp
protected static int OFMESSAGE_DAMPER_CAPACITY = 10000; // ms. protected static int OFMESSAGE_DAMPER_CAPACITY = 10000; // ms.
protected static int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms protected static int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms
protected static String LB_ETHER_TYPE = "0x800";
protected static int LB_PRIORITY = 32768;
// Comparator for sorting by SwitchCluster // Comparator for sorting by SwitchCluster
public Comparator<SwitchPort> clusterIdComparator = public Comparator<SwitchPort> clusterIdComparator =
new Comparator<SwitchPort>() { new Comparator<SwitchPort>() {
...@@ -483,97 +480,84 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -483,97 +480,84 @@ public class LoadBalancer implements IFloodlightModule,
* @param LBMember member * @param LBMember member
* @param long pinSwitch * @param long pinSwitch
*/ */
@SuppressWarnings("unchecked")
public void pushStaticVipRoute(boolean inBound, Route route, IPClient client, LBMember member, long pinSwitch) { public void pushStaticVipRoute(boolean inBound, Route route, IPClient client, LBMember member, long pinSwitch) {
List<NodePortTuple> path = route.getPath(); List<NodePortTuple> path = route.getPath();
if (path.size()>0) { if (path.size()>0) {
for (int i = 0; i < path.size(); i+=2) { for (int i = 0; i < path.size(); i+=2) {
JSONObject json = new JSONObject();
long sw = path.get(i).getNodeId(); long sw = path.get(i).getNodeId();
String swString = HexString.toHexString(path.get(i).getNodeId());
json.put("switch", HexString.toHexString(sw)); String entryName;
String matchString = null;
String actionString = null;
OFFlowMod fm = (OFFlowMod) floodlightProvider.getOFMessageFactory()
.getMessage(OFType.FLOW_MOD);
fm.setIdleTimeout((short) 0); // infinite
fm.setHardTimeout((short) 0); // infinite
fm.setBufferId(OFPacketOut.BUFFER_ID_NONE);
fm.setCommand((short) 0);
fm.setFlags((short) 0);
fm.setOutPort(OFPort.OFPP_NONE.getValue());
fm.setCookie((long) 0);
fm.setPriority(Short.MAX_VALUE);
if (inBound) { if (inBound) {
json.put("name","inbound-vip-"+ member.vipId+"client-"+client.ipAddress+"-port-"+client.targetPort entryName = "inbound-vip-"+ member.vipId+"client-"+client.ipAddress+"-port-"+client.targetPort
+"srcswitch-"+path.get(0).getNodeId()+"sw-"+sw); +"srcswitch-"+path.get(0).getNodeId()+"sw-"+sw;
json.put("src-ip",IPv4.fromIPv4Address(client.ipAddress)); matchString = "nw_src="+IPv4.fromIPv4Address(client.ipAddress)+","
json.put("protocol",String.valueOf(client.nw_proto)); + "nw_proto="+String.valueOf(client.nw_proto)+","
json.put("src-port",String.valueOf(client.srcPort & 0xffff)); + "tp_src="+String.valueOf(client.srcPort & 0xffff)+","
json.put("ether-type","0x800"); + "dl_type="+LB_ETHER_TYPE+","
json.put("priority","32768"); + "in_port="+String.valueOf(path.get(i).getPortId());
json.put("ingress-port",String.valueOf(path.get(i).getPortId()));
json.put("active","true");
if (sw == pinSwitch) { if (sw == pinSwitch) {
json.put("actions","set-dst-ip="+IPv4.fromIPv4Address(member.address)+"," actionString = "set-dst-ip="+IPv4.fromIPv4Address(member.address)+","
+ "set-dst-mac="+member.macString+"," + "set-dst-mac="+member.macString+","
+ "output="+path.get(i+1).getPortId()); + "output="+path.get(i+1).getPortId();
} else { } else {
json.put("actions", actionString =
"output="+path.get(i+1).getPortId()); "output="+path.get(i+1).getPortId();
} }
} else { } else {
json.put("name","outbound-vip-"+ member.vipId+"client-"+client.ipAddress+"-port-"+client.targetPort entryName = "outbound-vip-"+ member.vipId+"client-"+client.ipAddress+"-port-"+client.targetPort
+"srcswitch-"+path.get(0).getNodeId()+"sw-"+sw); +"srcswitch-"+path.get(0).getNodeId()+"sw-"+sw;
json.put("dst-ip",IPv4.fromIPv4Address(client.ipAddress)); matchString = "nw_dst="+IPv4.fromIPv4Address(client.ipAddress)+","
json.put("protocol",String.valueOf(client.nw_proto)); + "nw_proto="+String.valueOf(client.nw_proto)+","
json.put("dst-port",String.valueOf(client.srcPort & 0xffff)); + "tp_dst="+String.valueOf(client.srcPort & 0xffff)+","
json.put("ether-type","0x800"); + "dl_type="+LB_ETHER_TYPE+","
json.put("priority","32768"); + "in_port="+String.valueOf(path.get(i).getPortId());
json.put("ingress-port",String.valueOf(path.get(i).getPortId()));
json.put("active","true");
if (sw == pinSwitch) { if (sw == pinSwitch) {
json.put("actions","set-src-ip="+IPv4.fromIPv4Address(vips.get(member.vipId).address)+"," actionString = "set-src-ip="+IPv4.fromIPv4Address(vips.get(member.vipId).address)+","
+ "set-src-mac="+vips.get(member.vipId).proxyMac.toString()+"," + "set-src-mac="+vips.get(member.vipId).proxyMac.toString()+","
+ "output="+path.get(i+1).getPortId()); + "output="+path.get(i+1).getPortId();
} else { } else {
json.put("actions", actionString = "output="+path.get(i+1).getPortId();
"output="+path.get(i+1).getPortId());
} }
} }
StaticFlowEntries.parseActionString(fm, actionString, log);
fm.setPriority(U16.t(LB_PRIORITY));
OFMatch ofMatch = new OFMatch();
try { try {
HttpClient httpclient = new DefaultHttpClient(); ofMatch.fromString(matchString);
HttpPost httpPost = new HttpPost("http://127.0.0.1:8080/wm/staticflowentrypusher/json"); } catch (IllegalArgumentException e) {
StringEntity se = new StringEntity(json.toString()); log.debug(
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); "ignoring flow entry {} on switch {} with illegal OFMatch() key: "
httpPost.setEntity(se); + matchString, entryName, swString);
}
HttpResponse response = null;
fm.setMatch(ofMatch);
try { sfp.addFlow(entryName, fm, swString);
response = httpclient.execute(httpPost);
} catch (ClientProtocolException cliente) {
cliente.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
BufferedReader rd = null;
try {
if (response !=null)
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
} catch (IllegalStateException statee) {
statee.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
String line = "";
try {
if (rd!= null) {
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} }
} }
return; return;
} }
...@@ -775,6 +759,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -775,6 +759,7 @@ public class LoadBalancer implements IFloodlightModule,
l.add(IDeviceService.class); l.add(IDeviceService.class);
l.add(ITopologyService.class); l.add(ITopologyService.class);
l.add(IRoutingService.class); l.add(IRoutingService.class);
l.add(IStaticFlowEntryPusherService.class);
return l; return l;
} }
...@@ -788,6 +773,7 @@ public class LoadBalancer implements IFloodlightModule, ...@@ -788,6 +773,7 @@ public class LoadBalancer implements IFloodlightModule,
deviceManager = context.getServiceImpl(IDeviceService.class); deviceManager = context.getServiceImpl(IDeviceService.class);
routingEngine = context.getServiceImpl(IRoutingService.class); routingEngine = context.getServiceImpl(IRoutingService.class);
topology = context.getServiceImpl(ITopologyService.class); topology = context.getServiceImpl(ITopologyService.class);
sfp = context.getServiceImpl(IStaticFlowEntryPusherService.class);
messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY, messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY,
EnumSet.of(OFType.FLOW_MOD), EnumSet.of(OFType.FLOW_MOD),
......
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