X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fflowprogrammer%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fflowprogrammer%2Fnorthbound%2FFlowProgrammerNorthbound.java;h=e863f99514adef7f8e339fd027c0f83d318b799f;hp=99452b4b21542b9a77a4dc73bbe83413e2fc1fc0;hb=c482b318eda18c6649b012c3b42e5004aace8db8;hpb=59cc8f34c24d81a8890a94c11dedd4b21caa0adf
diff --git a/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java b/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java
index 99452b4b21..e863f99514 100644
--- a/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java
+++ b/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java
@@ -33,6 +33,7 @@ import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
import org.opendaylight.controller.northbound.commons.RestMessages;
import org.opendaylight.controller.northbound.commons.exception.InternalServerErrorException;
+import org.opendaylight.controller.northbound.commons.exception.MethodNotAllowedException;
import org.opendaylight.controller.northbound.commons.exception.NotAcceptableException;
import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException;
import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
@@ -48,7 +49,7 @@ import org.opendaylight.controller.switchmanager.ISwitchManager;
/**
* Flow Configuration Northbound API
- *
+ *
*
*
* Authentication scheme : HTTP Basic
@@ -60,7 +61,7 @@ import org.opendaylight.controller.switchmanager.ISwitchManager;
* trusted authority.
* More info :
* http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
- *
+ *
*/
@Path("/")
public class FlowProgrammerNorthbound {
@@ -147,11 +148,41 @@ public class FlowProgrammerNorthbound {
/**
* Returns a list of Flows configured on the given container
- *
+ *
* @param containerName
- * Name of the Container. The Container name for the base
- * controller is "default".
- * @return List of configured flows configured on a given container
+ * Name of the Container (Eg. 'default')
+ * @return List of flows configured on a given container
+ *
+ *
+ * + * Example: + * + * RequestURL: + * http://localhost:8080/controller/nb/v2/flow/default + * + * Response in XML: + * <?xml version="1.0" encoding="UTF-8" standalone="yes"?> + * <list> + * <flowConfig> + * <installInHw>true</installInHw> + * <name>flow1</name> + * <node> + * <id>00:00:00:00:00:00:00:01</id> + * <type>OF</type> + * </node> + * <ingressPort>1</ingressPort> + * <priority>500</priority> + * <etherType>0x800</etherType> + * <nwSrc>9.9.1.1</nwSrc> + * <actions>OUTPUT=2</actions> + * </flowConfig> + * </list> + * + * Response in JSON: + * {"flowConfig":{"installInHw":"true","name":"flow1","node":{"id":"00:00:00:00:00:00:00:01","type":"OF"}, + * "ingressPort":"1","priority":"500","etherType":"0x800","nwSrc":"9.9.1.1","actions":"OUTPUT=2"}} + * + **/ @Path("/{containerName}") @GET @@ -159,6 +190,7 @@ public class FlowProgrammerNorthbound { @TypeHint(FlowConfigs.class) @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The containerName is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) public FlowConfigs getStaticFlows( @@ -177,22 +209,53 @@ public class FlowProgrammerNorthbound { /** * Returns a list of Flows configured on a Node in a given container - * + * * @param containerName - * Name of the Container. The Container name for the base - * controller is "default". + * Name of the Container (Eg. 'default') * @param nodeType - * Type of the node being programmed + * Type of the node being programmed (Eg. 'OF') * @param nodeId - * Node Identifier - * @return List of configured flows configured on a Node in a container + * Node Identifier (Eg. '00:00:00:00:00:00:00:01') + * @return List of flows configured on a Node in a container + * + *
+ * + * Example: + * + * RequestURL: + * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01 + * + * Response in XML: + * <?xml version="1.0" encoding="UTF-8" standalone="yes"?> + * <list> + * <flowConfig> + * <installInHw>true</installInHw> + * <name>flow1</name> + * <node> + * <id>00:00:00:00:00:00:00:01</id> + * <type>OF</type> + * </node> + * <ingressPort>1</ingressPort> + * <priority>500</priority> + * <etherType>0x800</etherType> + * <nwSrc>9.9.1.1</nwSrc> + * <actions>OUTPUT=2</actions> + * </flowConfig> + * </list> + * + * Response in JSON: + * {"flowConfig":{"installInHw":"true","name":"flow1","node":{"id":"00:00:00:00:00:00:00:01","type":"OF"}, + * "ingressPort":"1","priority":"500","etherType":"0x800","nwSrc":"9.9.1.1","actions":"OUTPUT=2"}} + * + **/ - @Path("/{containerName}/{nodeType}/{nodeId}") + @Path("/{containerName}/node/{nodeType}/{nodeId}") @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @TypeHint(FlowConfigs.class) @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The containerName or nodeId is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) public FlowConfigs getStaticFlows( @@ -217,24 +280,53 @@ public class FlowProgrammerNorthbound { /** * Returns the flow configuration matching a human-readable name and nodeId * on a given Container. - * + * * @param containerName - * Name of the Container. The Container name for the base - * controller is "default". + * Name of the Container (Eg. 'default') * @param nodeType - * Type of the node being programmed + * Type of the node being programmed (Eg. 'OF') * @param nodeId - * Node Identifier + * Node Identifier (Eg. '00:00:00:00:00:00:00:01') * @param name - * Human-readable name for the configured flow. + * Human-readable name for the configured flow (Eg. 'Flow1') * @return Flow configuration matching the name and nodeId on a Container + * + *
+ * + * Example: + * + * RequestURL: + * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1 + * + * Response in XML: + * <?xml version="1.0" encoding="UTF-8" standalone="yes"?> + * <flowConfig> + * <installInHw>true</installInHw> + * <name>flow1</name> + * <node> + * <id>00:00:00:00:00:00:00:01</id> + * <type>OF</type> + * </node> + * <ingressPort>1</ingressPort> + * <priority>500</priority> + * <etherType>0x800</etherType> + * <nwSrc>9.9.1.1</nwSrc> + * <actions>OUTPUT=2</actions> + * </flowConfig> + * + * Response in JSON: + * {"installInHw":"true","name":"flow1","node":{"id":"00:00:00:00:00:00:00:01","type":"OF"}, + * "ingressPort":"1","priority":"500","etherType":"0x800","nwSrc":"9.9.1.1","actions":"OUTPUT=2"} + * + **/ - @Path("/{containerName}/{nodeType}/{nodeId}/{name}") + @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}") @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @TypeHint(FlowConfig.class) @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The containerName or NodeId or Configuration name is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) public FlowConfig getStaticFlow( @@ -266,29 +358,58 @@ public class FlowProgrammerNorthbound { /** * Add a flow configuration - * + * * @param containerName - * Name of the Container. The Container name for the base - * controller is "default". + * Name of the Container (Eg. 'default') * @param nodeType - * Type of the node being programmed + * Type of the node being programmed (Eg. 'OF') * @param nodeId - * Node Identifier + * Node Identifier (Eg. '00:00:00:00:00:00:00:01') * @param name - * Name of the Static Flow configuration + * Name of the Static Flow configuration (Eg. 'Flow2') * @param FlowConfig * Flow Configuration in JSON or XML format * @return Response as dictated by the HTTP Response Status code + * + *
+ * + * Example: + * + * RequestURL: + * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1 + * + * Request in XML: + * <flowConfig> + * <installInHw>true</installInHw> + * <name>flow1</name> + * <node> + * <id>00:00:00:00:00:00:00:01</id> + * <type>OF</type> + * </node> + * <ingressPort>1</ingressPort> + * <priority>500</priority> + * <etherType>0x800</etherType> + * <nwSrc>9.9.1.1</nwSrc> + * <actions>OUTPUT=2</actions> + * </flowConfig> + * + * Request in JSON: + * {"installInHw":"true","name":"flow1","node":{"id":"00:00:00:00:00:00:00:01","type":"OF"}, + * "ingressPort":"1","priority":"500","etherType":"0x800","nwSrc":"9.9.1.1","actions":"OUTPUT=2"} + * + **/ - @Path("/{containerName}/{nodeType}/{nodeId}/{name}") - @POST + @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}") + @PUT @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ @ResponseCode(code = 201, condition = "Flow Config processed successfully"), - @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"), + @ResponseCode(code = 400, condition = "Failed to create Static Flow entry due to invalid flow configuration"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @ResponseCode(code = 404, condition = "The Container Name or nodeId is not found"), @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"), - @ResponseCode(code = 409, condition = "Failed to create Static Flow entry due to Conflicting Name"), + @ResponseCode(code = 409, condition = "Failed to create Static Flow entry due to Conflicting Name or configuration"), @ResponseCode(code = 500, condition = "Failed to create Static Flow entry. Failure Reason included in HTTP Error response"), @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") }) public Response addFlow( @@ -304,6 +425,8 @@ public class FlowProgrammerNorthbound { "User is not authorized to perform this operation on container " + containerName); } + handleResourceCongruence(name, flowConfig.getValue().getName()); + handleResourceCongruence(nodeId, flowConfig.getValue().getNode().getNodeIDString()); handleDefaultDisabled(containerName); IForwardingRulesManager frm = getForwardingRulesManagerService(containerName); @@ -321,37 +444,46 @@ public class FlowProgrammerNorthbound { + RestMessages.RESOURCECONFLICT.toString()); } - Status status = frm.addStaticFlow(flowConfig.getValue(), false); + Status status = frm.addStaticFlow(flowConfig.getValue()); + if (status.isSuccess()) { - return Response.status(Response.Status.CREATED).build(); + NorthboundUtils.auditlog("Flow", username, "added", name, containerName); + return Response.status(Response.Status.CREATED).entity("Success").build(); } - throw new InternalServerErrorException(status.getDescription()); + return NorthboundUtils.getResponse(status); } /** * Delete a Flow configuration - * - * DELETE /flows/{containerName}/{nodeType}/{nodeId}/{name} - * + * * @param containerName - * Name of the Container. The Container name for the base - * controller is "default". + * Name of the Container (Eg. 'default') * @param nodeType - * Type of the node being programmed + * Type of the node being programmed (Eg. 'OF') * @param nodeId - * Node Identifier + * Node Identifier (Eg. '00:00:00:00:00:00:00:01') * @param name - * Name of the Static Flow configuration + * Name of the Static Flow configuration (Eg. 'Flow1') * @return Response as dictated by the HTTP Response code + * + *
+ * + * Example: + * + * RequestURL: + * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1 + * + **/ - @Path("/{containerName}/{nodeType}/{nodeId}/{name}") + @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}") @DELETE @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ @ResponseCode(code = 200, condition = "Flow Config deleted successfully"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The Container Name or Node-id or Flow Name passed is not found"), - @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"), + @ResponseCode(code = 406, condition = "Failed to delete Flow config due to invalid operation. Failure details included in HTTP Error response"), @ResponseCode(code = 500, condition = "Failed to delete Flow config. Failure Reason included in HTTP Error response"), @ResponseCode(code = 503, condition = "One or more of Controller service is unavailable") }) public Response deleteFlow( @@ -385,33 +517,41 @@ public class FlowProgrammerNorthbound { Status status = frm.removeStaticFlow(name, node); if (status.isSuccess()) { - return Response.ok().build(); + NorthboundUtils.auditlog("Flow", username, "removed", name, containerName); } - throw new InternalServerErrorException(status.getDescription()); + return NorthboundUtils.getResponse(status); } /** * Toggle a Flow configuration - * + * * @param containerName - * Name of the Container. The Container name for the base - * controller is "default". + * Name of the Container (Eg. 'default') * @param nodeType - * Type of the node being programmed + * Type of the node being programmed (Eg. 'OF') * @param nodeId - * Node Identifier + * Node Identifier (Eg. '00:00:00:00:00:00:00:01') * @param name - * Name of the Static Flow configuration + * Name of the Static Flow configuration (Eg. 'Flow1') * @return Response as dictated by the HTTP Response code + * + *
+ * + * Example: + * + * RequestURL: + * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1 + * + **/ - - @Path("/{containerName}/{nodeType}/{nodeId}/{name}") - @PUT + @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}") + @POST @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes({ - @ResponseCode(code = 200, condition = "Flow Config deleted successfully"), + @ResponseCode(code = 200, condition = "Flow Config processed successfully"), + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The Container Name or Node-id or Flow Name passed is not found"), - @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"), + @ResponseCode(code = 406, condition = "Failed to delete Flow config due to invalid operation. Failure details included in HTTP Error response"), @ResponseCode(code = 500, condition = "Failed to delete Flow config. Failure Reason included in HTTP Error response"), @ResponseCode(code = 503, condition = "One or more of Controller service is unavailable") }) public Response toggleFlow( @@ -446,9 +586,9 @@ public class FlowProgrammerNorthbound { Status status = frm.toggleStaticFlowStatus(staticFlow); if (status.isSuccess()) { - return Response.ok().build(); + NorthboundUtils.auditlog("Flow", username, "toggled", name, containerName); } - throw new InternalServerErrorException(status.getDescription()); + return NorthboundUtils.getResponse(status); } private Node handleNodeAvailability(String containerName, String nodeType, @@ -489,4 +629,10 @@ public class FlowProgrammerNorthbound { } } + private void handleResourceCongruence(String resource, String configured) { + if (!resource.equals(configured)) { + throw new MethodNotAllowedException("Path's resource name conflicts with payload's resource name"); + } + } + }