2 * Copyright (c) 2013, 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.INeutronVpnIpSecSiteConnectionsCRUD;
29 import org.opendaylight.neutron.spi.NeutronVpnIpSecSiteConnection;
32 * Neutron Northbound REST APIs for VPN IPSEC SiteConnection.<br>
33 * This class provides REST APIs for managing neutron VPN IPSEC SiteConnections
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/ipsecsiteconnections")
50 public final class NeutronVpnIpSecSiteConnectionsNorthbound
51 extends AbstractNeutronNorthbound<NeutronVpnIpSecSiteConnection,
52 NeutronVpnIpSecSiteConnectionRequest, INeutronVpnIpSecSiteConnectionsCRUD> {
54 private static final String RESOURCE_NAME = "VPNIPSECSiteConnections";
57 protected String getResourceName() {
62 * Returns a list of all VPN IPSEC SiteConnections.
66 @Produces({ MediaType.APPLICATION_JSON })
67 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
68 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
69 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
70 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
71 public Response listVpnIPSecSiteConnections(
73 @QueryParam("fields") List<String> fields,
75 @QueryParam("id") String queryID,
76 @QueryParam("tenant_id") String queryTenantID,
77 @QueryParam("name") String queryName,
78 @QueryParam("peer_address") String queryPeerAddress,
79 @QueryParam("peer_id") String queryPeerID,
80 @QueryParam("route_mode") String queryRouteMode,
81 @QueryParam("mtu") Integer queryMtu,
82 @QueryParam("auth_mode") String queryAuthMode,
83 @QueryParam("psk") String queryPsk,
84 @QueryParam("initiator") String queryInitiator,
85 @QueryParam("admin_state_up") Boolean queryAdminStateUp,
86 @QueryParam("status") String queryStatus,
87 @QueryParam("ikepolicy_id") String queryIkePolicyID,
88 @QueryParam("ipsecpolicy_id") String queryIpSecPolicyID,
89 @QueryParam("vpnservice_id") String queryVpnServiceID
90 // pagination and sorting are TODO
92 INeutronVpnIpSecSiteConnectionsCRUD labelInterface = getNeutronCRUD();
93 List<NeutronVpnIpSecSiteConnection> allNeutronVpnIPSecSiteConnection = labelInterface.getAll();
94 List<NeutronVpnIpSecSiteConnection> ans = new ArrayList<>();
95 for (NeutronVpnIpSecSiteConnection siteConnection : allNeutronVpnIPSecSiteConnection) {
96 if ((queryID == null || queryID.equals(siteConnection.getID()))
97 && (queryTenantID == null || queryTenantID.equals(siteConnection.getTenantID()))
98 && (queryName == null || queryName.equals(siteConnection.getName()))
99 && (queryPeerAddress == null || queryPeerAddress.equals(siteConnection.getPeerAddress()))
100 && (queryPeerID == null || queryPeerID.equals(siteConnection.getPeerID()))
101 && (queryRouteMode == null || queryRouteMode.equals(siteConnection.getRouteMode()))
102 && (queryMtu == null || queryMtu.equals(siteConnection.getMtu()))
103 && (queryAuthMode == null || queryAuthMode.equals(siteConnection.getAuthMode()))
104 && (queryPsk == null || queryPsk.equals(siteConnection.getPreSharedKey()))
105 && (queryInitiator == null || queryInitiator.equals(siteConnection.getInitiator()))
106 && (queryAdminStateUp == null || queryAdminStateUp.equals(siteConnection.getAdminStateUp()))
107 && (queryStatus == null || queryStatus.equals(siteConnection.getStatus()))
108 && (queryIkePolicyID == null || queryIkePolicyID.equals(siteConnection.getIkePolicyID()))
109 && (queryIpSecPolicyID == null || queryIpSecPolicyID.equals(siteConnection.getIpsecPolicyID()))
110 && (queryVpnServiceID == null || queryVpnServiceID.equals(siteConnection.getVpnServiceID()))) {
111 if (fields.size() > 0) {
112 ans.add(siteConnection.extractFields(fields));
114 ans.add(siteConnection);
119 // TODO: apply pagination to results
120 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIpSecSiteConnectionRequest(ans)).build();
124 * Returns a specific VPN IPSEC SiteConnection.
127 @Path("{connectionID}")
129 @Produces({ MediaType.APPLICATION_JSON })
130 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
131 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
132 @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
133 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
134 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
135 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
136 public Response showVpnIPSecSiteConnection(@PathParam("connectionID") String connectionID,
138 @QueryParam("fields") List<String> fields) {
139 return show(connectionID, fields);
143 * Creates new VPN IPSEC SiteConnection.
146 @Produces({ MediaType.APPLICATION_JSON })
147 @Consumes({ MediaType.APPLICATION_JSON })
148 @TypeHint(NeutronVpnIpSecSiteConnection.class)
149 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
150 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
151 public Response createVpnIPSecSiteConnection(final NeutronVpnIpSecSiteConnectionRequest input) {
152 return create(input);
156 * Updates a VPN IPSEC SiteConnection.
158 @Path("{connectionID}")
160 @Produces({ MediaType.APPLICATION_JSON })
161 @Consumes({ MediaType.APPLICATION_JSON })
162 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
163 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
164 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
165 public Response updateVpnIPSecSiteConnection(@PathParam("connectionID") String connectionID,
166 final NeutronVpnIpSecSiteConnectionRequest input) {
167 return update(connectionID, input);
171 * Deletes a VPN IPSEC SiteConnection.
174 @Path("{connectionID}")
176 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
177 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
178 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
179 public Response deleteVpnIPSecSiteConnection(@PathParam("connectionID") String connectionID) {
180 return delete(connectionID);