}\r
\r
public boolean isEnableDHCP() {\r
- if (enableDHCP == null)\r
+ if (enableDHCP == null) {\r
return true;\r
+ }\r
return enableDHCP;\r
}\r
\r
public Boolean getEnableDHCP() { return enableDHCP; }\r
\r
public void setEnableDHCP(Boolean newValue) {\r
- this.enableDHCP = newValue;\r
+ enableDHCP = newValue;\r
}\r
\r
public String getTenantID() {\r
Iterator<String> i = fields.iterator();\r
while (i.hasNext()) {\r
String s = i.next();\r
- if (s.equals("id"))\r
+ if (s.equals("id")) {\r
ans.setSubnetUUID(this.getSubnetUUID());\r
- if (s.equals("network_id"))\r
+ }\r
+ if (s.equals("network_id")) {\r
ans.setNetworkUUID(this.getNetworkUUID());\r
- if (s.equals("name"))\r
+ }\r
+ if (s.equals("name")) {\r
ans.setName(this.getName());\r
- if (s.equals("ip_version"))\r
+ }\r
+ if (s.equals("ip_version")) {\r
ans.setIpVersion(this.getIpVersion());\r
- if (s.equals("cidr"))\r
+ }\r
+ if (s.equals("cidr")) {\r
ans.setCidr(this.getCidr());\r
- if (s.equals("gateway_ip"))\r
+ }\r
+ if (s.equals("gateway_ip")) {\r
ans.setGatewayIP(this.getGatewayIP());\r
+ }\r
if (s.equals("dns_nameservers")) {\r
List<String> nsList = new ArrayList<String>();\r
nsList.addAll(this.getDnsNameservers());\r
hRoutes.addAll(this.getHostRoutes());\r
ans.setHostRoutes(hRoutes);\r
}\r
- if (s.equals("enable_dhcp"))\r
+ if (s.equals("enable_dhcp")) {\r
ans.setEnableDHCP(this.getEnableDHCP());\r
- if (s.equals("tenant_id"))\r
+ }\r
+ if (s.equals("tenant_id")) {\r
ans.setTenantID(this.getTenantID());\r
+ }\r
}\r
return ans;\r
}\r
try {\r
SubnetUtils util = new SubnetUtils(cidr);\r
SubnetInfo info = util.getInfo();\r
- if (!info.getNetworkAddress().equals(info.getAddress()))\r
+ if (!info.getNetworkAddress().equals(info.getAddress())) {\r
return false;\r
+ }\r
} catch (Exception e) {\r
return false;\r
}\r
Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
while (i.hasNext()) {\r
NeutronSubnet_IPAllocationPool pool = i.next();\r
- if (pool.contains(gatewayIP))\r
+ if (pool.contains(gatewayIP)) {\r
return true;\r
+ }\r
}\r
return false;\r
}\r
\r
- public void initDefaults() {\r
- if (enableDHCP == null)\r
+ public boolean initDefaults() {\r
+ if (enableDHCP == null) {\r
enableDHCP = true;\r
- if (ipVersion == null)\r
+ }\r
+ if (ipVersion == null) {\r
ipVersion = 4;\r
+ }\r
gatewayIPAssigned = false;\r
dnsNameservers = new ArrayList<String>();\r
allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>();\r
try {\r
SubnetUtils util = new SubnetUtils(cidr);\r
SubnetInfo info = util.getInfo();\r
- if (gatewayIP == null)\r
+ if (gatewayIP == null) {\r
gatewayIP = info.getLowAddress();\r
+ }\r
if (allocationPools.size() < 1) {\r
NeutronSubnet_IPAllocationPool source =\r
new NeutronSubnet_IPAllocationPool(info.getLowAddress(),\r
allocationPools = source.splitPool(gatewayIP);\r
}\r
} catch (Exception e) {\r
+ return false;\r
}\r
+ return true;\r
}\r
\r
public List<NeutronPort> getPortsInSubnet() {\r
* available allocation pools or not\r
*/\r
public boolean isIPInUse(String ipAddress) {\r
- if (ipAddress.equals(gatewayIP) && !gatewayIPAssigned )\r
+ if (ipAddress.equals(gatewayIP) && !gatewayIPAssigned ) {\r
return false;\r
+ }\r
Iterator<NeutronSubnet_IPAllocationPool> i = allocationPools.iterator();\r
while (i.hasNext()) {\r
NeutronSubnet_IPAllocationPool pool = i.next();\r
- if (pool.contains(ipAddress))\r
+ if (pool.contains(ipAddress)) {\r
return false;\r
+ }\r
}\r
return true;\r
}\r
}\r
else\r
if (NeutronSubnet_IPAllocationPool.convert(pool.getPoolStart()) <\r
- NeutronSubnet_IPAllocationPool.convert(ans))\r
+ NeutronSubnet_IPAllocationPool.convert(ans)) {\r
ans = pool.getPoolStart();\r
+ }\r
}\r
return ans;\r
}\r
if (pool.contains(ipAddress)) {\r
List<NeutronSubnet_IPAllocationPool> pools = pool.splitPool(ipAddress);\r
newList.addAll(pools);\r
- } else\r
+ } else {\r
newList.add(pool);\r
+ }\r
}\r
}\r
allocationPools = newList;\r
NeutronSubnet_IPAllocationPool pool = i.next();\r
long lIP = NeutronSubnet_IPAllocationPool.convert(pool.getPoolStart());\r
long hIP = NeutronSubnet_IPAllocationPool.convert(pool.getPoolEnd());\r
- if (sIP+1 == lIP)\r
+ if (sIP+1 == lIP) {\r
hPool = pool;\r
- if (sIP-1 == hIP)\r
+ }\r
+ if (sIP-1 == hIP) {\r
lPool = pool;\r
+ }\r
}\r
//if (lPool == NULL and hPool == NULL) create new pool where low = ip = high\r
- if (lPool == null && hPool == null)\r
+ if (lPool == null && hPool == null) {\r
allocationPools.add(new NeutronSubnet_IPAllocationPool(ipAddress,ipAddress));\r
+ }\r
//if (lPool == NULL and hPool != NULL) change low address of hPool to ipAddr\r
- if (lPool == null && hPool != null)\r
+ if (lPool == null && hPool != null) {\r
hPool.setPoolStart(ipAddress);\r
+ }\r
//if (lPool != NULL and hPool == NULL) change high address of lPool to ipAddr\r
- if (lPool != null && hPool == null)\r
+ if (lPool != null && hPool == null) {\r
lPool.setPoolEnd(ipAddress);\r
+ }\r
//if (lPool != NULL and hPool != NULL) remove lPool and hPool and create new pool\r
// where low address = lPool.low address and high address = hPool.high Address\r
if (lPool != null && hPool != null) {\r
import org.opendaylight.controller.networkconfig.neutron.NeutronCRUDInterfaces;\r
import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;\r
import org.opendaylight.controller.northbound.commons.RestMessages;\r
+import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;\r
import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;\r
import org.opendaylight.controller.sal.utils.ServiceHelper;\r
\r
(queryGatewayIP == null || queryGatewayIP.equals(oSS.getGatewayIP())) &&\r
(queryEnableDHCP == null || queryEnableDHCP.equals(oSS.getEnableDHCP())) &&\r
(queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {\r
- if (fields.size() > 0)\r
+ if (fields.size() > 0) {\r
ans.add(extractFields(oSS,fields));\r
- else\r
+ } else {\r
ans.add(oSS);\r
+ }\r
}\r
}\r
//TODO: apply pagination to results\r
throw new ServiceUnavailableException("Subnet CRUD Interface "\r
+ RestMessages.SERVICEUNAVAILABLE.toString());\r
}\r
- if (!subnetInterface.subnetExists(subnetUUID))\r
+ if (!subnetInterface.subnetExists(subnetUUID)) {\r
return Response.status(404).build();\r
+ }\r
if (fields.size() > 0) {\r
NeutronSubnet ans = subnetInterface.getSubnet(subnetUUID);\r
return Response.status(200).entity(\r
new NeutronSubnetRequest(extractFields(ans, fields))).build();\r
- } else\r
+ } else {\r
return Response.status(200).entity(\r
new NeutronSubnetRequest(subnetInterface.getSubnet(subnetUUID))).build();\r
+ }\r
}\r
\r
/**\r
* and that the gateway IP doesn't overlap with the allocation pools\r
* *then* add the subnet to the cache\r
*/\r
- if (subnetInterface.subnetExists(singleton.getID()))\r
+ if (subnetInterface.subnetExists(singleton.getID())) {\r
return Response.status(400).build();\r
- if (!networkInterface.networkExists(singleton.getNetworkUUID()))\r
+ }\r
+ if (!networkInterface.networkExists(singleton.getNetworkUUID())) {\r
return Response.status(404).build();\r
- if (!singleton.isValidCIDR())\r
+ }\r
+ if (!singleton.isValidCIDR()) {\r
return Response.status(400).build();\r
- singleton.initDefaults();\r
- if (singleton.gatewayIP_Pool_overlap())\r
+ }\r
+ if (!singleton.initDefaults()) {\r
+ throw new InternalServerErrorException("subnet object could not be initialized properly");\r
+ }\r
+ if (singleton.gatewayIP_Pool_overlap()) {\r
return Response.status(409).build();\r
+ }\r
Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null);\r
if (instances != null) {\r
for (Object instance : instances) {\r
INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
int status = service.canCreateSubnet(singleton);\r
- if (status < 200 || status > 299)\r
+ if (status < 200 || status > 299) {\r
return Response.status(status).build();\r
+ }\r
}\r
}\r
subnetInterface.addSubnet(singleton);\r
* and that the bulk request doesn't already contain a subnet with this id\r
*/\r
\r
- test.initDefaults();\r
- if (subnetInterface.subnetExists(test.getID()))\r
+ if (!test.initDefaults()) {\r
+ throw new InternalServerErrorException("subnet object could not be initialized properly");\r
+ }\r
+ if (subnetInterface.subnetExists(test.getID())) {\r
return Response.status(400).build();\r
- if (testMap.containsKey(test.getID()))\r
+ }\r
+ if (testMap.containsKey(test.getID())) {\r
return Response.status(400).build();\r
+ }\r
testMap.put(test.getID(), test);\r
- if (!networkInterface.networkExists(test.getNetworkUUID()))\r
+ if (!networkInterface.networkExists(test.getNetworkUUID())) {\r
return Response.status(404).build();\r
- if (!test.isValidCIDR())\r
+ }\r
+ if (!test.isValidCIDR()) {\r
return Response.status(400).build();\r
- if (test.gatewayIP_Pool_overlap())\r
+ }\r
+ if (test.gatewayIP_Pool_overlap()) {\r
return Response.status(409).build();\r
+ }\r
if (instances != null) {\r
for (Object instance : instances) {\r
INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
int status = service.canCreateSubnet(test);\r
- if (status < 200 || status > 299)\r
+ if (status < 200 || status > 299) {\r
return Response.status(status).build();\r
+ }\r
}\r
}\r
}\r
/*\r
* verify the subnet exists and there is only one delta provided\r
*/\r
- if (!subnetInterface.subnetExists(subnetUUID))\r
+ if (!subnetInterface.subnetExists(subnetUUID)) {\r
return Response.status(404).build();\r
- if (!input.isSingleton())\r
+ }\r
+ if (!input.isSingleton()) {\r
return Response.status(400).build();\r
+ }\r
NeutronSubnet delta = input.getSingleton();\r
NeutronSubnet original = subnetInterface.getSubnet(subnetUUID);\r
\r
*/\r
if (delta.getID() != null || delta.getTenantID() != null ||\r
delta.getIpVersion() != null || delta.getCidr() != null ||\r
- delta.getAllocationPools() != null)\r
+ delta.getAllocationPools() != null) {\r
return Response.status(400).build();\r
+ }\r
\r
Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null);\r
if (instances != null) {\r
for (Object instance : instances) {\r
INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
int status = service.canUpdateSubnet(delta, original);\r
- if (status < 200 || status > 299)\r
+ if (status < 200 || status > 299) {\r
return Response.status(status).build();\r
+ }\r
}\r
}\r
\r
/*\r
* verify the subnet exists and it isn't currently in use\r
*/\r
- if (!subnetInterface.subnetExists(subnetUUID))\r
+ if (!subnetInterface.subnetExists(subnetUUID)) {\r
return Response.status(404).build();\r
- if (subnetInterface.subnetInUse(subnetUUID))\r
+ }\r
+ if (subnetInterface.subnetInUse(subnetUUID)) {\r
return Response.status(409).build();\r
+ }\r
NeutronSubnet singleton = subnetInterface.getSubnet(subnetUUID);\r
Object[] instances = ServiceHelper.getGlobalInstances(INeutronSubnetAware.class, this, null);\r
if (instances != null) {\r
for (Object instance : instances) {\r
INeutronSubnetAware service = (INeutronSubnetAware) instance;\r
int status = service.canDeleteSubnet(singleton);\r
- if (status < 200 || status > 299)\r
+ if (status < 200 || status > 299) {\r
return Response.status(status).build();\r
+ }\r
}\r
}\r
\r