Set unique gre key for every network.

Set interface id to nic uuid when creating the vif.
This commit is contained in:
Hugo Trippaers 2014-01-03 10:49:03 +01:00
parent f3f93a96f5
commit 8ddcc9ba80
3 changed files with 32 additions and 7 deletions

View File

@ -83,7 +83,7 @@ public class OvsVifDriver extends VifDriverBase {
intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType), networkRateKBps); intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType), networkRateKBps);
intf.setVlanTag(Integer.parseInt(vlanId)); intf.setVlanTag(Integer.parseInt(vlanId));
} }
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) { } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch || nic.getBroadcastType() == Networks.BroadcastDomainType.OpenDaylight) {
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid); s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
intf.setVirtualPortInterfaceId(nic.getUuid()); intf.setVirtualPortInterfaceId(nic.getUuid());
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");

View File

@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
@ -46,6 +47,7 @@ import org.apache.cloudstack.network.opendaylight.agent.responses.DestroyPortAns
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException; import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork; import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper; import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNode; import org.apache.cloudstack.network.opendaylight.api.model.NeutronNode;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper; import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodesList; import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodesList;
@ -206,6 +208,27 @@ public class OpenDaylightControllerResource implements ServerResource {
private Answer executeRequest(ConfigureNetworkCommand cmd) { private Answer executeRequest(ConfigureNetworkCommand cmd) {
NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword); NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
// Find free gre key
int gre_key = -1;
Random keyGenerator = new Random(System.currentTimeMillis());
try {
NeutronNetworksList<NeutronNetwork> networks = configureNetwork.listAllNetworks();
while (true) {
int i = keyGenerator.nextInt();
for (NeutronNetwork network : networks.getNetworks()) {
if (network.getSegmentationId() == i) {
continue;
}
}
gre_key = i;
break;
}
} catch (NeutronRestApiException e) {
s_logger.error("Failed to list existing networks on the ODL Controller", e);
return new ConfigureNetworkAnswer(cmd, e);
}
NeutronNetwork newNetwork = new NeutronNetwork(); NeutronNetwork newNetwork = new NeutronNetwork();
// Configuration from the command // Configuration from the command
@ -215,7 +238,7 @@ public class OpenDaylightControllerResource implements ServerResource {
// Static configuation // Static configuation
newNetwork.setNetworkType("gre"); newNetwork.setNetworkType("gre");
newNetwork.setShared(false); newNetwork.setShared(false);
newNetwork.setSegmentationId(100); newNetwork.setSegmentationId(gre_key);
newNetwork.setId(UUID.randomUUID()); newNetwork.setId(UUID.randomUUID());
NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper(); NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();

View File

@ -25,10 +25,6 @@ import java.net.URL;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Collections; import java.util.Collections;
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.httpclient.methods.StringRequestEntity;
import com.google.gson.FieldNamingPolicy; import com.google.gson.FieldNamingPolicy;
@ -36,6 +32,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
public class NeutronNetworksNorthboundAction extends Action { public class NeutronNetworksNorthboundAction extends Action {
private final Gson gsonNeutronNetwork; private final Gson gsonNeutronNetwork;
@ -50,7 +52,7 @@ public class NeutronNetworksNorthboundAction extends Action {
String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri(); String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri();
String bodystring = executeGet(uri, Collections.<String, String> emptyMap()); String bodystring = executeGet(uri, Collections.<String, String> emptyMap());
Type returnType = new TypeToken<NeutronNetworksList<NeutronNetworkWrapper>>() { Type returnType = new TypeToken<NeutronNetworksList<NeutronNetwork>>() {
}.getType(); }.getType();
T returnValue = (T) gsonNeutronNetwork.fromJson(bodystring, returnType); T returnValue = (T) gsonNeutronNetwork.fromJson(bodystring, returnType);