private Answer executeRequest(final MaintainCommand cmd) {
return new MaintainAnswer(cmd);
}
private Answer executeRequest(ConfigureNetworkCommand cmd) {
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();
// Configuration from the command
newNetwork.setName(cmd.getName());
newNetwork.setTenantId(cmd.getTenantId());
// Static configuation
newNetwork.setNetworkType("gre");
newNetwork.setShared(false);
newNetwork.setSegmentationId(gre_key);
newNetwork.setId(UUID.randomUUID());
NeutronNetworkWrapper wrapper = new NeutronNetworkWrapper();
wrapper.setNetwork(newNetwork);
try {
wrapper = configureNetwork.createNeutronNetwork(wrapper);
} catch (NeutronRestApiException e) {
s_logger.error("createNeutronNetwork failed", e);
return new ConfigureNetworkAnswer(cmd, e);
}