2 * Copyright (c) 2014-2015 NEC Corporation
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this
7 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.vtn.manager.northbound;
12 import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
13 import static java.net.HttpURLConnection.HTTP_CREATED;
14 import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
15 import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
16 import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
17 import static java.net.HttpURLConnection.HTTP_OK;
18 import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
19 import static java.net.HttpURLConnection.HTTP_UNAVAILABLE;
20 import static java.net.HttpURLConnection.HTTP_UNSUPPORTED_TYPE;
22 import javax.ws.rs.Consumes;
23 import javax.ws.rs.DELETE;
24 import javax.ws.rs.GET;
25 import javax.ws.rs.PUT;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.core.Context;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import javax.ws.rs.core.UriInfo;
34 import org.codehaus.enunciate.jaxrs.ResponseCode;
35 import org.codehaus.enunciate.jaxrs.ResponseHeader;
36 import org.codehaus.enunciate.jaxrs.ResponseHeaders;
37 import org.codehaus.enunciate.jaxrs.StatusCodes;
38 import org.codehaus.enunciate.jaxrs.TypeHint;
40 import org.opendaylight.vtn.manager.VTenantPath;
41 import org.opendaylight.vtn.manager.flow.filter.FlowFilter;
42 import org.opendaylight.vtn.manager.flow.filter.FlowFilterId;
45 * This class provides Northbound REST APIs to handle flow filter in the
49 * Each VTN has a list of flow filters. Flow filters in the VTN flow filter
50 * list are evaluated when an incoming packet is mapped to the VTN.
51 * Note that the VTN flow filter list is evaluated only once before other
52 * flow filter lists are evaluated.
57 @Path("/default/vtns/{tenantName}/flowfilters")
58 public class VTenantFlowFilterNorthbound extends VTNNorthBoundBase {
60 * Return information about flow filters configured in the specified VTN.
62 * @param tenantName The name of the VTN.
64 * <strong>flowfilters</strong> element contains information about the
65 * VTN flow filter list specified by the requested URI.
68 @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
69 @TypeHint(FlowFilterList.class)
71 @ResponseCode(code = HTTP_OK,
72 condition = "Operation completed successfully."),
73 @ResponseCode(code = HTTP_UNAUTHORIZED,
74 condition = "User is not authorized to perform this " +
76 @ResponseCode(code = HTTP_NOT_FOUND,
77 condition = "The specified VTN does not exist."),
78 @ResponseCode(code = HTTP_INTERNAL_ERROR,
79 condition = "Fatal internal error occurred in the " +
81 @ResponseCode(code = HTTP_UNAVAILABLE,
82 condition = "One or more of mandatory controller " +
83 "services, such as the VTN Manager, are unavailable.")})
84 public FlowFilterList getFlowFilters(
85 @PathParam("tenantName") String tenantName) {
86 return getFlowFilters(createFlowFilterId(tenantName));
90 * Delete all flow filters in the VTN flow filter list.
92 * @param tenantName The name of the VTN.
93 * @return Response as dictated by the HTTP Response Status code.
96 @TypeHint(TypeHint.NO_CONTENT.class)
98 @ResponseCode(code = HTTP_OK,
99 condition = "Flow filters were deleted successfully."),
100 @ResponseCode(code = HTTP_NO_CONTENT,
101 condition = "No flow filter was configured in the " +
103 @ResponseCode(code = HTTP_UNAUTHORIZED,
104 condition = "User is not authorized to perform this " +
106 @ResponseCode(code = HTTP_NOT_FOUND,
107 condition = "The specified VTN does not exist."),
108 @ResponseCode(code = HTTP_INTERNAL_ERROR,
109 condition = "Fatal internal error occurred in the " +
111 @ResponseCode(code = HTTP_UNAVAILABLE,
112 condition = "One or more of mandatory controller " +
113 "services, such as the VTN Manager, are unavailable.")})
114 public Response deleteFlowFilters(
115 @PathParam("tenantName") String tenantName) {
116 return deleteFlowFilters(createFlowFilterId(tenantName));
120 * Return information about the flow filter specified by the
121 * flow filter index in the VTN flow filter list.
123 * @param tenantName The name of the VTN.
125 * The index value which specifies the flow filter in the VTN flow filter
126 * list. A string representation of an integer value must be specified.
128 * <strong>flowfilter</strong> element contains information about the
129 * flow filter specified by the requested URI.
133 @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
134 @TypeHint(FlowFilter.class)
136 @ResponseCode(code = HTTP_OK,
137 condition = "Operation completed successfully."),
138 @ResponseCode(code = HTTP_NO_CONTENT,
139 condition = "The specified flow filter does not exist " +
140 "in the specified VTN."),
141 @ResponseCode(code = HTTP_UNAUTHORIZED,
142 condition = "User is not authorized to perform this " +
144 @ResponseCode(code = HTTP_NOT_FOUND,
146 "<li>The specified VTN does not exist.</li>" +
147 "<li>A string passed to <u>{index}</u> can not be " +
148 "converted into an integer.</li>" +
150 @ResponseCode(code = HTTP_INTERNAL_ERROR,
151 condition = "Fatal internal error occurred in the " +
153 @ResponseCode(code = HTTP_UNAVAILABLE,
154 condition = "One or more of mandatory controller " +
155 "services, such as the VTN Manager, are unavailable.")})
156 public FlowFilter getFlowFilter(
157 @PathParam("tenantName") String tenantName,
158 @PathParam("index") int index) {
159 return getFlowFilter(createFlowFilterId(tenantName), index);
163 * Create or modify the flow filter specified by the index number in the
164 * VTN flow filter list.
168 * If the flow filter specified by
169 * <span style="text-decoration: underline;">{index}</span> does not
170 * exist, a new flow filter will be associated with
171 * <span style="text-decoration: underline;">{index}</span> in the
172 * VTN flow filter list.
175 * If the flow filter specified by
176 * <span style="text-decoration: underline;">{index}</span> already
177 * exists, it will be modified as specified by
178 * <strong>flowfilter</strong> element.
182 * @param uriInfo Requested URI information.
183 * @param tenantName The name of the VTN.
185 * The index value which specifies the flow filter in the VTN flow filter
189 * A string representation of an integer value must be specified.
192 * The range of value that can be specified is from
193 * <strong>1</strong> to <strong>65535</strong>.
196 * This value is also used to determine the order of flow filter
197 * evaluation. Flow filters in the list are evaluated in ascending
198 * order of indices, and only the first matched flow filter is
199 * applied to the packet.
203 * <strong>flowfilter</strong> element specifies the configuration of the
207 * The <strong>index</strong> attribute in the
208 * <strong>flowfilter</strong> element is always ignored.
209 * The index number is determined by the
210 * <span style="text-decoration: underline;">{index}</span>
214 * Note that this API does not check whether the flow condition
215 * specified by the <strong>condition</strong> attribute in
216 * the <strong>flowfilter</strong> element actually exists or not.
217 * The flow filter will be invalidated if the specified
218 * flow condition does not exist.
221 * Note that this API does not check whether the destination
222 * virtual interface of the packet redirection, which is configured
223 * in the <strong>redirect</strong> element in the
224 * <strong>flowfilter</strong> element, actually exists or not.
225 * The packet will be discarded if the destination virtual interface
226 * is not found when the packet is going to be redirected by the
230 * @return Response as dictated by the HTTP Response Status code.
234 @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
235 @TypeHint(TypeHint.NO_CONTENT.class)
237 @ResponseHeader(name = "Location",
238 description = "URI corresponding to the newly " +
239 "created flow filter, which is the same URI " +
240 "specified in request. This header is set only if " +
241 "CREATED(201) is returned as response code.")})
243 @ResponseCode(code = HTTP_OK,
244 condition = "Existing flow filter was modified " +
246 @ResponseCode(code = HTTP_CREATED,
247 condition = "Flow filter was newly created " +
249 @ResponseCode(code = HTTP_NO_CONTENT,
250 condition = "Flow filter was not changed."),
251 @ResponseCode(code = HTTP_BAD_REQUEST,
253 "<li>Incorrect XML or JSON data is specified " +
254 "in Request body.</li>" +
255 "<li>Index number specified by <u>{index}</u> " +
256 "parameter is out of valid range.</li>" +
257 "<li>Incorrect value is configured in " +
258 "<strong>flowfilter</strong>.</li>" +
260 @ResponseCode(code = HTTP_UNAUTHORIZED,
261 condition = "User is not authorized to perform this " +
263 @ResponseCode(code = HTTP_NOT_FOUND,
265 "<li>The specified VTN does not exist.</li>" +
266 "<li>A string passed to <u>{index}</u> can not be " +
267 "converted into an integer.</li>" +
269 @ResponseCode(code = HTTP_UNSUPPORTED_TYPE,
270 condition = "Unsupported data type is specified in " +
271 "<strong>Content-Type</strong> header."),
272 @ResponseCode(code = HTTP_INTERNAL_ERROR,
273 condition = "Fatal internal error occurred in the " +
275 @ResponseCode(code = HTTP_UNAVAILABLE,
276 condition = "One or more of mandatory controller " +
277 "services, such as the VTN Manager, are unavailable.")})
278 public Response putFlowFilter(
279 @Context UriInfo uriInfo,
280 @PathParam("tenantName") String tenantName,
281 @PathParam("index") int index,
282 @TypeHint(FlowFilter.class) FlowFilter ff) {
283 return putFlowFilter(uriInfo, createFlowFilterId(tenantName), index,
288 * Delete the flow filter specified by the index number in the VTN
291 * @param tenantName The name of the VTN.
293 * The index value which specifies the flow filter in the VTN flow filter
294 * list. A string representation of an integer value must be specified.
295 * @return Response as dictated by the HTTP Response Status code.
299 @TypeHint(TypeHint.NO_CONTENT.class)
301 @ResponseCode(code = HTTP_OK,
302 condition = "Flow filter was deleted successfully."),
303 @ResponseCode(code = HTTP_NO_CONTENT,
304 condition = "The specified flow filter does not exist " +
305 "in the specified VTN."),
306 @ResponseCode(code = HTTP_UNAUTHORIZED,
307 condition = "User is not authorized to perform this " +
309 @ResponseCode(code = HTTP_NOT_FOUND,
311 "<li>The specified VTN does not exist.</li>" +
312 "<li>A string passed to <u>{index}</u> can not be " +
313 "converted into an integer.</li>" +
315 @ResponseCode(code = HTTP_INTERNAL_ERROR,
316 condition = "Fatal internal error occurred in the " +
318 @ResponseCode(code = HTTP_UNAVAILABLE,
319 condition = "One or more of mandatory controller " +
320 "services, such as the VTN Manager, are unavailable.")})
321 public Response deleteFlowFilter(
322 @PathParam("tenantName") String tenantName,
323 @PathParam("index") int index) {
324 return deleteFlowFilter(createFlowFilterId(tenantName), index);
328 * Create a flow filter identifier that specifies the flow filter list
331 * @param tenant The name of the tenant.
332 * @return A {@link FlowFilterId} instance.
334 private FlowFilterId createFlowFilterId(String tenant) {
335 VTenantPath path = new VTenantPath(tenant);
336 return new FlowFilterId(path);