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;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.codehaus.enunciate.jaxrs.TypeHint;
28 import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyCRUD;
29 import org.opendaylight.neutron.spi.NeutronVPNIPSECPolicy;
32 * Neutron Northbound REST APIs for VPN IPSEC Policy.<br>
33 * This class provides REST APIs for managing neutron VPN IPSEC Policies
37 * Authentication scheme : <b>HTTP Basic</b><br>
38 * Authentication realm : <b>opendaylight</b><br>
39 * Transport : <b>HTTP and HTTPS</b><br>
41 * HTTPS Authentication is disabled by default. Administrator can enable it in
42 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43 * trusted authority.<br>
45 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
49 @Path("/vpn/ipsecpolicies")
50 public final class NeutronVPNIPSECPoliciesNorthbound extends
51 AbstractNeutronNorthbound<NeutronVPNIPSECPolicy, NeutronVPNIPSECPolicyRequest, INeutronVPNIPSECPolicyCRUD> {
53 private static final String RESOURCE_NAME = "VPNIPSECPolicy";
56 protected String getResourceName() {
61 * Returns a list of all VPN IPSEC Policies */
64 @Produces({ MediaType.APPLICATION_JSON })
65 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
66 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
67 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
68 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
69 public Response listVPNIPSECPolicies(
71 @QueryParam("fields") List<String> fields,
73 @QueryParam("id") String queryID,
74 @QueryParam("tenant_id") String queryTenantID,
75 @QueryParam("name") String queryName,
76 @QueryParam("transform_protocol") String queryTransformProtocol,
77 @QueryParam("encapsulation_mode") String queryEncapsulationMode,
78 @QueryParam("auth_algorithm") String queryAuthAlgorithm,
79 @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
80 @QueryParam("pfs") String queryPFS
81 // pagination and sorting are TODO
83 INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronCRUD();
84 List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = policyInterface.getAll();
85 List<NeutronVPNIPSECPolicy> ans = new ArrayList<>();
86 for (NeutronVPNIPSECPolicy policy : allNeutronVPNIPSECPolicies) {
87 if ((queryID == null || queryID.equals(policy.getID()))
88 && (queryName == null || queryName.equals(policy.getName()))
89 && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
90 && (queryEncryptionAlgorithm == null
91 || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
92 && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
93 && (queryTransformProtocol == null || queryTransformProtocol.equals(policy.getTransformProtocol()))
94 && (queryEncapsulationMode == null || queryEncapsulationMode.equals(policy.getEncapsulationMode()))
95 && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
96 if (fields.size() > 0) {
97 ans.add(policy.extractFields(fields));
103 //TODO: apply pagination to results
104 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVPNIPSECPolicyRequest(ans)).build();
108 * Returns a specific VPN IPSEC Policy */
112 @Produces({ MediaType.APPLICATION_JSON })
113 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
114 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
115 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
116 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
117 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
118 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
119 public Response showVPNIPSECPolicy(@PathParam("policyID") String policyUUID,
121 @QueryParam("fields") List<String> fields) {
122 return show(policyUUID, fields);
126 * Creates new VPN IPSEC Policy */
128 @Produces({ MediaType.APPLICATION_JSON })
129 @Consumes({ MediaType.APPLICATION_JSON })
130 @TypeHint(NeutronVPNIPSECPolicy.class)
131 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
132 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
133 public Response createVPNIPSECPolicy(final NeutronVPNIPSECPolicyRequest input) {
134 return create(input);
138 * Updates a VPN IPSEC Policy */
141 @Produces({ MediaType.APPLICATION_JSON })
142 @Consumes({ MediaType.APPLICATION_JSON })
143 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
144 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
145 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146 public Response updateVPNIPSECPolicy(@PathParam("policyID") String policyUUID,
147 final NeutronVPNIPSECPolicyRequest input) {
148 return update(policyUUID, input);
152 * Deletes a VPN IPSEC Policy */
156 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
157 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
158 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
159 public Response deleteVPNIPSECPolicy(@PathParam("policyID") String policyUUID) {
160 return delete(policyUUID);