2 * Copyright (c) 2016 Brocade Communications Systems, Inc. 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
8 package org.opendaylight.neutron.northbound.api;
10 import java.net.HttpURLConnection;
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.ws.rs.Consumes;
14 import javax.ws.rs.DELETE;
15 import javax.ws.rs.GET;
16 import javax.ws.rs.POST;
17 import javax.ws.rs.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.opendaylight.neutron.spi.INeutronSFCFlowClassifierCRUD;
27 import org.opendaylight.neutron.spi.NeutronSFCFlowClassifier;
30 * Neutron Northbound REST APIs for OpenStack SFC Flow Classifier.<br>
31 * This class provides REST APIs for managing OpenStack SFC Flow Classifier
35 * Authentication scheme : <b>HTTP Basic</b><br>
36 * Authentication realm : <b>opendaylight</b><br>
37 * Transport : <b>HTTP and HTTPS</b><br>
39 * HTTPS Authentication is disabled by default. Administrator can enable it in
40 * tomcat-server.xml after adding a proper keystore / SSL certificate from a
41 * trusted authority.<br>
43 * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
47 @Path("/sfc/flowclassifiers")
48 public final class NeutronSFCFlowClassifiersNorthbound extends AbstractNeutronNorthbound<NeutronSFCFlowClassifier,
49 NeutronSFCFlowClassifierRequest, INeutronSFCFlowClassifierCRUD> {
50 private static final String RESOURCE_NAME = "Sfc Flow Classifier";
53 protected String getResourceName() {
58 * Returns a list of all SFC Flow Classifiers.
62 @Produces({ MediaType.APPLICATION_JSON })
63 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
64 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
65 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
66 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
67 public Response listSFCFlowClassifiers(
69 @QueryParam("fields") List<String> fields,
70 // note: openstack isn't clear about filtering on lists, so we aren't handling them
71 @QueryParam("id") String queryID,
72 @QueryParam("name") String queryName,
73 @QueryParam("ethertype") String queryEthertype,
74 @QueryParam("protocol") String queryProtocol,
75 @QueryParam("source_port_range_min") Integer querySourcePortRangeMin,
76 @QueryParam("source_port_range_max") Integer querySourcePortRangeMax,
77 @QueryParam("tenant_id") String queryTenantID,
78 @QueryParam("destination_port_range_min") Integer queryDestinationPortRangeMin,
79 @QueryParam("destination_port_range_max") Integer queryDestinationPortRangeMax,
80 @QueryParam("source_ip_prefix") String querySourceIpPrefix,
81 @QueryParam("destination_ip_prefix") String queryDestinationIpPrefix,
82 @QueryParam("logical_source_port") String queryLogicalSourcePort,
83 @QueryParam("logical_destination_port") String queryLogicalDestinationPort) {
84 INeutronSFCFlowClassifierCRUD sfcFlowClassifierInterface = getNeutronCRUD();
85 List<NeutronSFCFlowClassifier> allSFCFlowClassifier = sfcFlowClassifierInterface.getAll();
86 List<NeutronSFCFlowClassifier> ans = new ArrayList<>();
87 for (NeutronSFCFlowClassifier classifier : allSFCFlowClassifier) {
88 if ((queryID == null || queryID.equals(classifier.getID()))
89 && (queryName == null || queryName.equals(classifier.getName()))
90 && (queryEthertype == null || queryEthertype.equals(classifier.getEthertype()))
91 && (queryProtocol == null || queryProtocol.equals(classifier.getProtocol()))
92 && (querySourcePortRangeMin == null
93 || querySourcePortRangeMin.equals(classifier.getSourcePortRangeMin()))
94 && (querySourcePortRangeMax == null
95 || querySourcePortRangeMax.equals(classifier.getSourcePortRangeMax()))
96 && (queryDestinationPortRangeMin == null
97 || queryDestinationPortRangeMin.equals(classifier.getDestinationPortRangeMin()))
98 && (queryDestinationPortRangeMax == null
99 || queryDestinationPortRangeMax.equals(classifier.getDestinationPortRangeMax()))
100 && (querySourceIpPrefix == null || querySourceIpPrefix.equals(classifier.getSourceIpPrefix()))
101 && (queryDestinationIpPrefix == null
102 || queryDestinationIpPrefix.equals(classifier.getDestinationIpPrefix()))
103 && (queryLogicalSourcePort == null
104 || queryLogicalSourcePort.equals(classifier.getLogicalSourcePortUUID()))
105 && (queryLogicalDestinationPort == null
106 || queryLogicalDestinationPort.equals(classifier.getLogicalDestinationPortUUID()))
107 && (queryTenantID == null || queryTenantID.equals(classifier.getTenantID()))) {
108 if (fields.size() > 0) {
109 ans.add(classifier.extractFields(fields));
116 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCFlowClassifierRequest(ans)).build();
121 * Returns a specific SFC Flow Classifier.
124 @Path("{flowClassifierUUID}")
126 @Produces({ MediaType.APPLICATION_JSON })
127 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
128 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
129 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
130 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
131 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
132 public Response showSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
134 @QueryParam("fields") List<String> fields) {
135 return show(sfcFlowClassifierUUID, fields);
139 * Creates new SFC Flow Classifier.
142 @Produces({ MediaType.APPLICATION_JSON })
143 @Consumes({ MediaType.APPLICATION_JSON })
144 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
145 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146 public Response createSFCFlowClassifier(final NeutronSFCFlowClassifierRequest input) {
147 return create(input);
151 protected void updateDelta(String uuid, NeutronSFCFlowClassifier delta, NeutronSFCFlowClassifier original) {
153 * note: what we get appears to not be a delta but
154 * rather an incomplete updated object. So we need to set
155 * the ID to complete the object and then send that down
160 delta.setTenantID(original.getTenantID());
164 * Updates an existing SFC Flow Classifier.
166 @Path("{flowClassifierUUID}")
168 @Produces({ MediaType.APPLICATION_JSON })
169 @Consumes({ MediaType.APPLICATION_JSON })
170 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
171 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
172 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
173 public Response updateSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
174 final NeutronSFCFlowClassifierRequest input) {
175 return update(sfcFlowClassifierUUID, input);
179 * Deletes the SFC Flow Classifier.
181 @Path("{flowClassifierUUID}")
183 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
184 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
185 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
186 public Response deleteSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID) {
187 return delete(sfcFlowClassifierUUID);