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.INeutronVPNIPSECPolicyCRUD;
35 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
36 import org.opendaylight.neutron.spi.NeutronVPNIPSECPolicy;
39 * Neutron Northbound REST APIs for VPN IPSEC Policy.<br>
40 * This class provides REST APIs for managing neutron VPN IPSEC Policies
44 * Authentication scheme : <b>HTTP Basic</b><br>
45 * Authentication realm : <b>opendaylight</b><br>
46 * Transport : <b>HTTP and HTTPS</b><br>
48 * HTTPS Authentication is disabled by default. Administrator can enable it in
49 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
50 * trusted authority.<br>
52 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
56 @Path("/vpn/ipsecpolicies")
57 public class NeutronVPNIPSECPoliciesNorthbound
58 extends AbstractNeutronNorthbound<NeutronVPNIPSECPolicy, NeutronVPNIPSECPolicyRequest, INeutronVPNIPSECPolicyCRUD> {
60 private static final String RESOURCE_NAME = "VPNIPSECPolicy";
63 protected String getResourceName() {
68 protected NeutronVPNIPSECPolicy extractFields(NeutronVPNIPSECPolicy o, List<String> fields) {
69 return o.extractFields(fields);
73 protected INeutronVPNIPSECPolicyCRUD getNeutronCRUD() {
74 NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronVPNIPSECPolicyCRUD(this);
75 if (answer.getVPNIPSECPolicyInterface() == null) {
76 throw new ServiceUnavailableException(serviceUnavailable());
78 return answer.getVPNIPSECPolicyInterface();
82 protected NeutronVPNIPSECPolicyRequest newNeutronRequest(NeutronVPNIPSECPolicy o) {
83 return new NeutronVPNIPSECPolicyRequest(o);
90 * Returns a list of all VPN IPSEC Policies */
93 @Produces({ MediaType.APPLICATION_JSON })
95 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
96 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
97 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
98 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
99 public Response listVPNIPSECPolicies(
101 @QueryParam("fields") List<String> fields,
103 @QueryParam("id") String queryID,
104 @QueryParam("tenant_id") String queryTenantID,
105 @QueryParam("name") String queryName,
106 @QueryParam("transform_protocol") String queryTransformProtocol,
107 @QueryParam("encapsulation_mode") String queryEncapsulationMode,
108 @QueryParam("auth_algorithm") String queryAuthAlgorithm,
109 @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
110 @QueryParam("pfs") String queryPFS
111 // pagination and sorting are TODO
113 INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronCRUD();
114 List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = policyInterface.getAll();
115 List<NeutronVPNIPSECPolicy> ans = new ArrayList<NeutronVPNIPSECPolicy>();
116 Iterator<NeutronVPNIPSECPolicy> i = allNeutronVPNIPSECPolicies.iterator();
117 while (i.hasNext()) {
118 NeutronVPNIPSECPolicy oSS = i.next();
119 if ((queryID == null || queryID.equals(oSS.getID())) &&
120 (queryName == null || queryName.equals(oSS.getName())) &&
121 (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(oSS.getAuthAlgorithm())) &&
122 (queryEncryptionAlgorithm == null || queryEncryptionAlgorithm.equals(oSS.getEncryptionAlgorithm())) &&
123 (queryPFS == null || queryPFS.equals(oSS.getPerfectForwardSecrecy())) &&
124 (queryTransformProtocol == null || queryTransformProtocol.equals(oSS.getTransformProtocol())) &&
125 (queryEncapsulationMode == null || queryEncapsulationMode.equals(oSS.getEncapsulationMode())) &&
126 (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {
127 if (fields.size() > 0) {
128 ans.add(extractFields(oSS,fields));
134 //TODO: apply pagination to results
135 return Response.status(HttpURLConnection.HTTP_OK).entity(
136 new NeutronVPNIPSECPolicyRequest(ans)).build();
140 * Returns a specific VPN IPSEC Policy */
144 @Produces({ MediaType.APPLICATION_JSON })
146 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
147 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
148 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
149 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
150 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
151 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
152 public Response showVPNIPSECPolicy(
153 @PathParam("policyID") String policyUUID,
155 @QueryParam("fields") List<String> fields
157 return show(policyUUID, fields);
161 * Creates new VPN IPSEC Policy */
163 @Produces({ MediaType.APPLICATION_JSON })
164 @Consumes({ MediaType.APPLICATION_JSON })
165 @TypeHint(NeutronVPNIPSECPolicy.class)
167 @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
168 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
169 public Response createVPNIPSECPolicy(final NeutronVPNIPSECPolicyRequest input) {
170 return create(input);
174 * Updates a VPN IPSEC Policy */
177 @Produces({ MediaType.APPLICATION_JSON })
178 @Consumes({ MediaType.APPLICATION_JSON })
180 @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
181 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
182 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
183 public Response updateVPNIPSECPolicy(
184 @PathParam("policyID") String policyUUID, final NeutronVPNIPSECPolicyRequest input
186 return update(policyUUID, input);
190 * Deletes a VPN IPSEC Policy */
195 @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
196 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
197 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
198 public Response deleteVPNIPSECPolicy(
199 @PathParam("policyID") String policyUUID) {
200 return delete(policyUUID);