Skip to content

Commit 8ddcc9b

Browse files
committed
Set unique gre key for every network.
Set interface id to nic uuid when creating the vif.
1 parent f3f93a9 commit 8ddcc9b

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public InterfaceDef plug(NicTO nic, String guestOsType) throws InternalErrorExce
8383
intf.defBridgeNet(_pifs.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType), networkRateKBps);
8484
intf.setVlanTag(Integer.parseInt(vlanId));
8585
}
86-
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch) {
86+
} else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch || nic.getBroadcastType() == Networks.BroadcastDomainType.OpenDaylight) {
8787
s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid);
8888
intf.setVirtualPortInterfaceId(nic.getUuid());
8989
String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private");

plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.HashMap;
2727
import java.util.Map;
2828
import java.util.Map.Entry;
29+
import java.util.Random;
2930
import java.util.UUID;
3031

3132
import javax.naming.ConfigurationException;
@@ -46,6 +47,7 @@
4647
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
4748
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork;
4849
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
50+
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
4951
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNode;
5052
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodeWrapper;
5153
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNodesList;
@@ -206,6 +208,27 @@ private Answer executeRequest(final MaintainCommand cmd) {
206208

207209
private Answer executeRequest(ConfigureNetworkCommand cmd) {
208210
NeutronNetworksNorthboundAction configureNetwork = new NeutronNetworksNorthboundAction(controllerUrl, controllerUsername, controllerPassword);
211+
212+
// Find free gre key
213+
int gre_key = -1;
214+
Random keyGenerator = new Random(System.currentTimeMillis());
215+
try {
216+
NeutronNetworksList<NeutronNetwork> networks = configureNetwork.listAllNetworks();
217+
while (true) {
218+
int i = keyGenerator.nextInt();
219+
for (NeutronNetwork network : networks.getNetworks()) {
220+
if (network.getSegmentationId() == i) {
221+
continue;
222+
}
223+
}
224+
gre_key = i;
225+
break;
226+
}
227+
} catch (NeutronRestApiException e) {
228+
s_logger.error("Failed to list existing networks on the ODL Controller", e);
229+
return new ConfigureNetworkAnswer(cmd, e);
230+
}
231+
209232
NeutronNetwork newNetwork = new NeutronNetwork();
210233

211234
// Configuration from the command
@@ -215,7 +238,7 @@ private Answer executeRequest(ConfigureNetworkCommand cmd) {
215238
// Static configuation
216239
newNetwork.setNetworkType("gre");
217240
newNetwork.setShared(false);
218-
newNetwork.setSegmentationId(100);
241+
newNetwork.setSegmentationId(gre_key);
219242
newNetwork.setId(UUID.randomUUID());
220243

221244
NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();

plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/resources/NeutronNetworksNorthboundAction.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@
2525
import java.text.MessageFormat;
2626
import java.util.Collections;
2727

28-
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
29-
import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum;
30-
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
31-
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
3228
import org.apache.commons.httpclient.methods.StringRequestEntity;
3329

3430
import com.google.gson.FieldNamingPolicy;
3531
import com.google.gson.Gson;
3632
import com.google.gson.GsonBuilder;
3733
import com.google.gson.reflect.TypeToken;
3834

35+
import org.apache.cloudstack.network.opendaylight.api.NeutronRestApiException;
36+
import org.apache.cloudstack.network.opendaylight.api.enums.NeutronNorthboundEnum;
37+
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetwork;
38+
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworkWrapper;
39+
import org.apache.cloudstack.network.opendaylight.api.model.NeutronNetworksList;
40+
3941
public class NeutronNetworksNorthboundAction extends Action {
4042

4143
private final Gson gsonNeutronNetwork;
@@ -50,7 +52,7 @@ public <T> T listAllNetworks() throws NeutronRestApiException {
5052
String uri = NeutronNorthboundEnum.NETWORKS_URI.getUri();
5153
String bodystring = executeGet(uri, Collections.<String, String> emptyMap());
5254

53-
Type returnType = new TypeToken<NeutronNetworksList<NeutronNetworkWrapper>>() {
55+
Type returnType = new TypeToken<NeutronNetworksList<NeutronNetwork>>() {
5456
}.getType();
5557

5658
T returnValue = (T) gsonNeutronNetwork.fromJson(bodystring, returnType);

0 commit comments

Comments
 (0)