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.
65 @Produces({ MediaType.APPLICATION_JSON })
66 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
67 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
68 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
69 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
70 public Response listVpnIPSecPolicies(
72 @QueryParam("fields") List<String> fields,
74 @QueryParam("id") String queryID,
75 @QueryParam("tenant_id") String queryTenantID,
76 @QueryParam("name") String queryName,
77 @QueryParam("transform_protocol") String queryTransformProtocol,
78 @QueryParam("encapsulation_mode") String queryEncapsulationMode,
79 @QueryParam("auth_algorithm") String queryAuthAlgorithm,
80 @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
81 @QueryParam("pfs") String queryPFS
82 // pagination and sorting are TODO
84 INeutronVpnIpSecPolicyCRUD policyInterface = getNeutronCRUD();
85 List<NeutronVpnIpSecPolicy> allNeutronVpnIPSecPolicies = policyInterface.getAll();
86 List<NeutronVpnIpSecPolicy> ans = new ArrayList<>();
87 for (NeutronVpnIpSecPolicy policy : allNeutronVpnIPSecPolicies) {
88 if ((queryID == null || queryID.equals(policy.getID()))
89 && (queryName == null || queryName.equals(policy.getName()))
90 && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
91 && (queryEncryptionAlgorithm == null
92 || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
93 && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
94 && (queryTransformProtocol == null || queryTransformProtocol.equals(policy.getTransformProtocol()))
95 && (queryEncapsulationMode == null || queryEncapsulationMode.equals(policy.getEncapsulationMode()))
96 && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
97 if (fields.size() > 0) {
98 ans.add(policy.extractFields(fields));
104 //TODO: apply pagination to results
105 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIpSecPolicyRequest(ans)).build();
109 * Returns a specific VPN IPSEC Policy.
114 @Produces({ MediaType.APPLICATION_JSON })
115 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
116 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
117 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
118 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
119 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
120 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121 public Response showVpnIPSecPolicy(@PathParam("policyID") String policyUUID,
123 @QueryParam("fields") List<String> fields) {
124 return show(policyUUID, fields);
128 * Creates new VPN IPSEC Policy.
131 @Produces({ MediaType.APPLICATION_JSON })
132 @Consumes({ MediaType.APPLICATION_JSON })
133 @TypeHint(NeutronVpnIpSecPolicy.class)
134 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
135 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
136 public Response createVpnIPSecPolicy(final NeutronVpnIpSecPolicyRequest input) {
137 return create(input);
141 * Updates a VPN IPSEC Policy.
145 @Produces({ MediaType.APPLICATION_JSON })
146 @Consumes({ MediaType.APPLICATION_JSON })
147 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
148 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
149 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
150 public Response updateVpnIPSecPolicy(@PathParam("policyID") String policyUUID,
151 final NeutronVpnIpSecPolicyRequest input) {
152 return update(policyUUID, input);
156 * Deletes a VPN IPSEC Policy.
161 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
162 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
163 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
164 public Response deleteVpnIPSecPolicy(@PathParam("policyID") String policyUUID) {
165 return delete(policyUUID);