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.
32 @Path("/sfc/flowclassifiers")
33 public final class NeutronSFCFlowClassifiersNorthbound extends AbstractNeutronNorthbound<NeutronSFCFlowClassifier,
34 NeutronSFCFlowClassifierRequest, INeutronSFCFlowClassifierCRUD> {
36 private static final String RESOURCE_NAME = "Sfc Flow Classifier";
39 protected String getResourceName() {
44 * Returns a list of all SFC Flow Classifiers.
47 @Produces({ MediaType.APPLICATION_JSON })
48 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
49 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
50 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
51 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
52 public Response listSFCFlowClassifiers(
54 @QueryParam("fields") List<String> fields,
55 // note: openstack isn't clear about filtering on lists, so we aren't handling them
56 @QueryParam("id") String queryID,
57 @QueryParam("name") String queryName,
58 @QueryParam("ethertype") String queryEthertype,
59 @QueryParam("protocol") String queryProtocol,
60 @QueryParam("source_port_range_min") Integer querySourcePortRangeMin,
61 @QueryParam("source_port_range_max") Integer querySourcePortRangeMax,
62 @QueryParam("tenant_id") String queryTenantID,
63 @QueryParam("destination_port_range_min") Integer queryDestinationPortRangeMin,
64 @QueryParam("destination_port_range_max") Integer queryDestinationPortRangeMax,
65 @QueryParam("source_ip_prefix") String querySourceIpPrefix,
66 @QueryParam("destination_ip_prefix") String queryDestinationIpPrefix,
67 @QueryParam("logical_source_port") String queryLogicalSourcePort,
68 @QueryParam("logical_destination_port") String queryLogicalDestinationPort) {
69 INeutronSFCFlowClassifierCRUD sfcFlowClassifierInterface = getNeutronCRUD();
70 List<NeutronSFCFlowClassifier> allSFCFlowClassifier = sfcFlowClassifierInterface.getAll();
71 List<NeutronSFCFlowClassifier> ans = new ArrayList<>();
72 for (NeutronSFCFlowClassifier classifier : allSFCFlowClassifier) {
73 if ((queryID == null || queryID.equals(classifier.getID()))
74 && (queryName == null || queryName.equals(classifier.getName()))
75 && (queryEthertype == null || queryEthertype.equals(classifier.getEthertype()))
76 && (queryProtocol == null || queryProtocol.equals(classifier.getProtocol()))
77 && (querySourcePortRangeMin == null
78 || querySourcePortRangeMin.equals(classifier.getSourcePortRangeMin()))
79 && (querySourcePortRangeMax == null
80 || querySourcePortRangeMax.equals(classifier.getSourcePortRangeMax()))
81 && (queryDestinationPortRangeMin == null
82 || queryDestinationPortRangeMin.equals(classifier.getDestinationPortRangeMin()))
83 && (queryDestinationPortRangeMax == null
84 || queryDestinationPortRangeMax.equals(classifier.getDestinationPortRangeMax()))
85 && (querySourceIpPrefix == null || querySourceIpPrefix.equals(classifier.getSourceIpPrefix()))
86 && (queryDestinationIpPrefix == null
87 || queryDestinationIpPrefix.equals(classifier.getDestinationIpPrefix()))
88 && (queryLogicalSourcePort == null
89 || queryLogicalSourcePort.equals(classifier.getLogicalSourcePortUUID()))
90 && (queryLogicalDestinationPort == null
91 || queryLogicalDestinationPort.equals(classifier.getLogicalDestinationPortUUID()))
92 && (queryTenantID == null || queryTenantID.equals(classifier.getTenantID()))) {
93 if (fields.size() > 0) {
94 ans.add(classifier.extractFields(fields));
101 return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCFlowClassifierRequest(ans)).build();
106 * Returns a specific SFC Flow Classifier.
108 @Path("{flowClassifierUUID}")
110 @Produces({ MediaType.APPLICATION_JSON })
111 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
112 @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
113 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
114 @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
115 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
116 public Response showSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
118 @QueryParam("fields") List<String> fields) {
119 return show(sfcFlowClassifierUUID, fields);
123 * Creates new SFC Flow Classifier.
126 @Produces({ MediaType.APPLICATION_JSON })
127 @Consumes({ MediaType.APPLICATION_JSON })
128 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
129 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
130 public Response createSFCFlowClassifier(final NeutronSFCFlowClassifierRequest input) {
131 return create(input);
135 protected void updateDelta(String uuid, NeutronSFCFlowClassifier delta, NeutronSFCFlowClassifier original) {
137 * note: what we get appears to not be a delta but
138 * rather an incomplete updated object. So we need to set
139 * the ID to complete the object and then send that down
143 delta.setTenantID(original.getTenantID());
147 * Updates an existing SFC Flow Classifier.
149 @Path("{flowClassifierUUID}")
151 @Produces({ MediaType.APPLICATION_JSON })
152 @Consumes({ MediaType.APPLICATION_JSON })
153 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
154 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
155 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
156 public Response updateSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID,
157 final NeutronSFCFlowClassifierRequest input) {
158 return update(sfcFlowClassifierUUID, input);
162 * Deletes the SFC Flow Classifier.
164 @Path("{flowClassifierUUID}")
166 @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
167 @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
168 @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
169 public Response deleteSFCFlowClassifier(@PathParam("flowClassifierUUID") String sfcFlowClassifierUUID) {
170 return delete(sfcFlowClassifierUUID);