2 * Copyright (c) 2015 IBM Corporation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.neutron.northbound.api;
11 import java.net.HttpURLConnection;
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.DELETE;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.POST;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.PathParam;
24 import javax.ws.rs.Produces;
25 import javax.ws.rs.QueryParam;
26 import javax.ws.rs.core.Context;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import javax.ws.rs.core.UriInfo;
31 import org.codehaus.enunciate.jaxrs.ResponseCode;
32 import org.codehaus.enunciate.jaxrs.StatusCodes;
33 import org.codehaus.enunciate.jaxrs.TypeHint;
34 import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyAware;
35 import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyCRUD;
36 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
37 import org.opendaylight.neutron.spi.NeutronVPNIPSECPolicy;
40 * Neutron Northbound REST APIs for VPN IPSEC Policy.<br>
41 * This class provides REST APIs for managing neutron VPN IPSEC Policies
45 * Authentication scheme : <b>HTTP Basic</b><br>
46 * Authentication realm : <b>opendaylight</b><br>
47 * Transport : <b>HTTP and HTTPS</b><br>
49 * HTTPS Authentication is disabled by default. Administrator can enable it in
50 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
51 * trusted authority.<br>
53 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
57 @Path("/vpn/ipsecpolicies")
58 public class NeutronVPNIPSECPoliciesNorthbound
59 extends AbstractNeutronNorthbound<NeutronVPNIPSECPolicy, NeutronVPNIPSECPolicyRequest, INeutronVPNIPSECPolicyCRUD, INeutronVPNIPSECPolicyAware> {
61 private static final String RESOURCE_NAME = "VPNIPSECPolicy";
64 protected String getResourceName() {
69 protected NeutronVPNIPSECPolicy extractFields(NeutronVPNIPSECPolicy o, List<String> fields) {
70 return o.extractFields(fields);
74 protected INeutronVPNIPSECPolicyCRUD getNeutronCRUD() {
75 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronVPNIPSECPolicyCRUD(this);
76 if (answer.getVPNIPSECPolicyInterface() == null) {
77 throw new ServiceUnavailableException(serviceUnavailable());
79 return answer.getVPNIPSECPolicyInterface();
83 protected NeutronVPNIPSECPolicyRequest newNeutronRequest(NeutronVPNIPSECPolicy o) {
84 return new NeutronVPNIPSECPolicyRequest(o);
88 protected Object[] getInstances() {
89 return NeutronUtil.getInstances(INeutronVPNIPSECPolicyAware.class, this);
93 protected int canCreate(Object instance, NeutronVPNIPSECPolicy singleton) {
94 INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
95 return service.canCreateNeutronVPNIPSECPolicy(singleton);
99 protected void created(Object instance, NeutronVPNIPSECPolicy singleton) {
100 INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
101 service.neutronVPNIPSECPolicyCreated(singleton);
105 protected int canUpdate(Object instance, NeutronVPNIPSECPolicy delta, NeutronVPNIPSECPolicy original) {
106 INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
107 return service.canUpdateNeutronVPNIPSECPolicy(delta, original);
111 protected void updated(Object instance, NeutronVPNIPSECPolicy updated) {
112 INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
113 service.neutronVPNIPSECPolicyUpdated(updated);
117 protected int canDelete(Object instance, NeutronVPNIPSECPolicy singleton) {
118 INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
119 return service.canDeleteNeutronVPNIPSECPolicy(singleton);
123 protected void deleted(Object instance, NeutronVPNIPSECPolicy singleton) {
124 INeutronVPNIPSECPolicyAware service = (INeutronVPNIPSECPolicyAware) instance;
125 service.neutronVPNIPSECPolicyDeleted(singleton);
132 * Returns a list of all VPN IPSEC Policies */
135 @Produces({ MediaType.APPLICATION_JSON })
137 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
139 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
140 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
141 public Response listVPNIPSECPolicies(
143 @QueryParam("fields") List<String> fields,
145 @QueryParam("id") String queryID,
146 @QueryParam("tenant_id") String queryTenantID,
147 @QueryParam("name") String queryName,
148 @QueryParam("description") String queryDescription,
149 @QueryParam("transform_protocol") String queryTransformProtocol,
150 @QueryParam("encapsulation_mode") String queryEncapsulationMode,
151 @QueryParam("auth_algorithm") String queryAuthAlgorithm,
152 @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
153 @QueryParam("pfs") String queryPFS
154 // pagination and sorting are TODO
156 INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronCRUD();
157 List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = policyInterface.getAllNeutronVPNIPSECPolicies();
158 List<NeutronVPNIPSECPolicy> ans = new ArrayList<NeutronVPNIPSECPolicy>();
159 Iterator<NeutronVPNIPSECPolicy> i = allNeutronVPNIPSECPolicies.iterator();
160 while (i.hasNext()) {
161 NeutronVPNIPSECPolicy oSS = i.next();
162 if ((queryID == null || queryID.equals(oSS.getID())) &&
163 (queryName == null || queryName.equals(oSS.getName())) &&
164 (queryDescription == null || queryDescription.equals(oSS.getDescription())) &&
165 (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(oSS.getAuthAlgorithm())) &&
166 (queryEncryptionAlgorithm == null || queryEncryptionAlgorithm.equals(oSS.getEncryptionAlgorithm())) &&
167 (queryPFS == null || queryPFS.equals(oSS.getPerfectForwardSecrecy())) &&
168 (queryTransformProtocol == null || queryTransformProtocol.equals(oSS.getTransformProtocol())) &&
169 (queryEncapsulationMode == null || queryEncapsulationMode.equals(oSS.getEncapsulationMode())) &&
170 (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {
171 if (fields.size() > 0) {
172 ans.add(extractFields(oSS,fields));
178 //TODO: apply pagination to results
179 return Response.status(HttpURLConnection.HTTP_OK).entity(
180 new NeutronVPNIPSECPolicyRequest(ans)).build();
184 * Returns a specific VPN IPSEC Policy */
188 @Produces({ MediaType.APPLICATION_JSON })
190 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
191 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
192 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
193 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
194 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
195 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
196 public Response showVPNIPSECPolicy(
197 @PathParam("policyID") String policyUUID,
199 @QueryParam("fields") List<String> fields
201 return show(policyUUID, fields);
205 * Creates new VPN IPSEC Policy */
207 @Produces({ MediaType.APPLICATION_JSON })
208 @Consumes({ MediaType.APPLICATION_JSON })
209 @TypeHint(NeutronVPNIPSECPolicy.class)
211 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
212 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
213 public Response createVPNIPSECPolicy(final NeutronVPNIPSECPolicyRequest input) {
214 return create(input);
218 * Updates a VPN IPSEC Policy */
221 @Produces({ MediaType.APPLICATION_JSON })
222 @Consumes({ MediaType.APPLICATION_JSON })
224 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
225 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
226 public Response updateVPNIPSECPolicy(
227 @PathParam("policyID") String policyUUID, final NeutronVPNIPSECPolicyRequest input
229 return update(policyUUID, input);
233 * Deletes a VPN IPSEC Policy */
238 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
239 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
240 public Response deleteVPNIPSECPolicy(
241 @PathParam("policyID") String policyUUID) {
242 return delete(policyUUID);