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.inject.Inject;
14 import javax.inject.Singleton;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.DELETE;
17 import javax.ws.rs.GET;
18 import javax.ws.rs.POST;
19 import javax.ws.rs.PUT;
20 import javax.ws.rs.Path;
21 import javax.ws.rs.PathParam;
22 import javax.ws.rs.Produces;
23 import javax.ws.rs.QueryParam;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import org.codehaus.enunciate.jaxrs.ResponseCode;
27 import org.codehaus.enunciate.jaxrs.StatusCodes;
28 import org.opendaylight.neutron.spi.INeutronSFCFlowClassifierCRUD;
29 import org.opendaylight.neutron.spi.NeutronSFCFlowClassifier;
30 import org.ops4j.pax.cdi.api.OsgiService;
33 * Neutron Northbound REST APIs for OpenStack SFC Flow Classifier.
36 @Path("/sfc/flowclassifiers")
37 public final class NeutronSFCFlowClassifiersNorthbound extends AbstractNeutronNorthbound<NeutronSFCFlowClassifier,
38 NeutronSFCFlowClassifierRequest, INeutronSFCFlowClassifierCRUD> {
40 private static final String RESOURCE_NAME = "Sfc Flow Classifier";
43 public NeutronSFCFlowClassifiersNorthbound(@OsgiService INeutronSFCFlowClassifierCRUD neutronCRUD) {
48 protected String getResourceName() {
53 * Returns a list of all SFC Flow Classifiers.
56 @Produces({ MediaType.APPLICATION_JSON })
57 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
58 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
59 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
60 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
61 public Response listSFCFlowClassifiers(
63 @QueryParam("fields") List<String> fields,
64 // note: openstack isn't clear about filtering on lists, so we aren't handling them
65 @QueryParam("id") String queryID,
66 @QueryParam("name") String queryName,
67 @QueryParam("ethertype") String queryEthertype,
68 @QueryParam("protocol") String queryProtocol,
69 @QueryParam("source_port_range_min") Integer querySourcePortRangeMin,
70 @QueryParam("source_port_range_max") Integer querySourcePortRangeMax,
71 @QueryParam("tenant_id") String queryTenantID,
72 @QueryParam("destination_port_range_min") Integer queryDestinationPortRangeMin,
73 @QueryParam("destination_port_range_max") Integer queryDestinationPortRangeMax,
74 @QueryParam("source_ip_prefix") String querySourceIpPrefix,
75 @QueryParam("destination_ip_prefix") String queryDestinationIpPrefix,
76 @QueryParam("logical_source_port") String queryLogicalSourcePort,
77 @QueryParam("logical_destination_port") String queryLogicalDestinationPort) {
78 INeutronSFCFlowClassifierCRUD sfcFlowClassifierInterface = getNeutronCRUD();
79 List<NeutronSFCFlowClassifier> allSFCFlowClassifier = sfcFlowClassifierInterface.getAll();
80 List<NeutronSFCFlowClassifier> ans = new ArrayList<>();
81 for (NeutronSFCFlowClassifier classifier : allSFCFlowClassifier) {
82 if ((queryID == null || queryID.equals(classifier.getID()))
83 && (queryName == null || queryName.equals(classifier.getName()))
84 && (queryEthertype == null || queryEthertype.equals(classifier.getEthertype()))
85 && (queryProtocol == null || queryProtocol.equals(classifier.getProtocol()))
86 && (querySourcePortRangeMin == null
87 || querySourcePortRangeMin.equals(classifier.getSourcePortRangeMin()))
88 && (querySourcePortRangeMax == null
89 || querySourcePortRangeMax.equals(classifier.getSourcePortRangeMax()))
90 && (queryDestinationPortRangeMin == null
91 || queryDestinationPortRangeMin.equals(classifier.getDestinationPortRangeMin()))
92 && (queryDestinationPortRangeMax == null
93 || queryDestinationPortRangeMax.equals(classifier.getDestinationPortRangeMax()))
94 && (querySourceIpPrefix == null || querySourceIpPrefix.equals(classifier.getSourceIpPrefix()))
95 && (queryDestinationIpPrefix == null
96 || queryDestinationIpPrefix.equals(classifier.getDestinationIpPrefix()))
97 && (queryLogicalSourcePort == null
98 || queryLogicalSourcePort.equals(classifier.getLogicalSourcePortUUID()))
99 && (queryLogicalDestinationPort == null
100 || queryLogicalDestinationPort.equals(classifier.getLogicalDestinationPortUUID()))
101 && (queryTenantID == null || queryTenantID.equals(classifier.getTenantID()))) {
102 if (fields.size() > 0) {
103 ans.add(classifier.extractFields(fields));
110 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCFlowClassifierRequest(ans)).build();
115 * Returns a specific SFC Flow Classifier.
117 @Path("{flowClassifierUUID}")
119 @Produces({ MediaType.APPLICATION_JSON })
120 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
121 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
122 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
123 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
124 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
125 public Response showSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
127 @QueryParam("fields") List<String> fields) {
128 return show(sfcFlowClassifierUUID, fields);
132 * Creates new SFC Flow Classifier.
135 @Produces({ MediaType.APPLICATION_JSON })
136 @Consumes({ MediaType.APPLICATION_JSON })
137 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
138 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
139 public Response createSFCFlowClassifier(final NeutronSFCFlowClassifierRequest input) {
140 return create(input);
144 protected void updateDelta(String uuid, NeutronSFCFlowClassifier delta, NeutronSFCFlowClassifier original) {
146 * note: what we get appears to not be a delta but
147 * rather an incomplete updated object. So we need to set
148 * the ID to complete the object and then send that down
152 delta.setTenantID(original.getTenantID());
156 * Updates an existing SFC Flow Classifier.
158 @Path("{flowClassifierUUID}")
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 updateSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
166 final NeutronSFCFlowClassifierRequest input) {
167 return update(sfcFlowClassifierUUID, input);
171 * Deletes the SFC Flow Classifier.
173 @Path("{flowClassifierUUID}")
175 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
176 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
177 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
178 public Response deleteSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID) {
179 return delete(sfcFlowClassifierUUID);