import org.opendaylight.controller.switchmanager.ISwitchManager;
/**
- * Flow Configuration Northbound API
+ * Flow Configuration Northbound API provides capabilities to program flows.
*
* <br>
* <br>
* Authentication realm : <b>opendaylight</b><br>
* Transport : <b>HTTP and HTTPS</b><br>
* <br>
- * HTTPS Authentication is disabled by default. Administrator can enable it in
- * tomcat-server.xml after adding a proper keystore / SSL certificate from a
- * trusted authority.<br>
- * More info :
- * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
+ * HTTPS Authentication is disabled by default.
*
*/
@Path("/")
@Context
public void setSecurityContext(SecurityContext context) {
- username = context.getUserPrincipal().getName();
+ if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
}
protected String getUserName() {
* Example:
*
* RequestURL:
- * http://localhost:8080/controller/nb/v2/flow/default
+ * http://localhost:8080/controller/nb/v2/flowprogrammer/default
*
* 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" type="OF"/>
+ *       <node>
+ *          <id>00:00:00:00:00:00:00:01</id>
+ *          <type>OF</type>
+ *       </node>
*       <ingressPort>1</ingressPort>
*       <priority>500</priority>
*       <etherType>0x800</etherType>
* </list>
*
* Response in JSON:
- * {"flowConfig":{"installInHw":"true","name":"flow1","node":{"@id":"00:00:00:00:00:00:00:01","@type":"OF"},
+ * {"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"}}
*
* </pre>
* Example:
*
* RequestURL:
- * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01
+ * http://localhost:8080/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:01
*
* 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" type="OF"/>
+ *       <node>
+ *          <id>00:00:00:00:00:00:00:01</id>
+ *          <type>OF</type>
+ *       </node>
*       <ingressPort>1</ingressPort>
*       <priority>500</priority>
*       <etherType>0x800</etherType>
* </list>
*
* Response in JSON:
- * {"flowConfig":{"installInHw":"true","name":"flow1","node":{"@id":"00:00:00:00:00:00:00:01","@type":"OF"},
+ * {"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"}}
*
* </pre>
* Example:
*
* RequestURL:
- * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1
+ * http://localhost:8080/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:01/staticFlow/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" type="OF"/>
+ *    <node>
+ *       <id>00:00:00:00:00:00:00:01</id>
+ *       <type>OF</type>
+ *    </node>
*    <ingressPort>1</ingressPort>
*    <priority>500</priority>
*    <etherType>0x800</etherType>
* </flowConfig>
*
* Response in JSON:
- * {"installInHw":"true","name":"flow1","node":{"@id":"00:00:00:00:00:00:00:01","@type":"OF"},
+ * {"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"}
*
* </pre>
*/
- @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}")
+ @Path("/{containerName}/node/{nodeType}/{nodeId}/staticFlow/{name}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(FlowConfig.class)
}
/**
- * Add a flow configuration
+ * Add a flow configuration. If a flow by the given name already
+ * exists, this method will respond with a non-successful status response.
*
* @param containerName
* Name of the Container (Eg. 'default')
* Example:
*
* RequestURL:
- * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1
+ * http://localhost:8080/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:01/staticFlow/flow1
*
* Request in XML:
* <flowConfig>
*    <installInHw>true</installInHw>
*    <name>flow1</name>
- *    <node id="00:00:00:00:00:00:00:01" type="OF"/>
+ *    <node>
+ *       <id>00:00:00:00:00:00:00:01</id>
+ *       <type>OF</type>
+ *    </node>
*    <ingressPort>1</ingressPort>
*    <priority>500</priority>
*    <etherType>0x800</etherType>
* </flowConfig>
*
* Request in JSON:
- * {"installInHw":"true","name":"flow1","node":{"@id":"00:00:00:00:00:00:00:01","@type":"OF"},
+ * {"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"}
*
* </pre>
*/
- @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}")
+ @Path("/{containerName}/node/{nodeType}/{nodeId}/staticFlow/{name}")
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
@PathParam(value = "name") String name,
@PathParam("nodeType") String nodeType,
@PathParam(value = "nodeId") String nodeId,
- @TypeHint(FlowConfig.class) JAXBElement<FlowConfig> flowConfig) {
+ @TypeHint(FlowConfig.class) FlowConfig flowConfig) {
if (!NorthboundUtils.isAuthorized(
getUserName(), containerName, Privilege.WRITE, this)) {
"User is not authorized to perform this operation on container "
+ containerName);
}
- handleResourceCongruence(name, flowConfig.getValue().getName());
- handleResourceCongruence(nodeId, flowConfig.getValue().getNode().getNodeIDString());
+
+ if (flowConfig.getNode() == null) {
+ return Response.status(Response.Status.BAD_REQUEST).entity("Invalid Configuration. Node is null or empty")
+ .build();
+ }
+ handleResourceCongruence(name, flowConfig.getName());
+ handleResourceCongruence(nodeId, flowConfig.getNode().getNodeIDString());
handleDefaultDisabled(containerName);
IForwardingRulesManager frm = getForwardingRulesManagerService(containerName);
+ RestMessages.RESOURCECONFLICT.toString());
}
- Status status = frm.addStaticFlow(flowConfig.getValue());
+ Status status = frm.addStaticFlow(flowConfig);
if (status.isSuccess()) {
NorthboundUtils.auditlog("Flow", username, "added", name, containerName);
* Example:
*
* RequestURL:
- * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1
+ * http://localhost:8080/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:01/staticFlow/flow1
*
* </pre>
*/
- @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}")
+ @Path("/{containerName}/node/{nodeType}/{nodeId}/staticFlow/{name}")
@DELETE
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
- @ResponseCode(code = 200, condition = "Flow Config deleted successfully"),
+ @ResponseCode(code = 204, 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 = "Failed to delete Flow config due to invalid operation. Failure details included in HTTP Error response"),
Status status = frm.removeStaticFlow(name, node);
if (status.isSuccess()) {
NorthboundUtils.auditlog("Flow", username, "removed", name, containerName);
+ return Response.noContent().build();
}
return NorthboundUtils.getResponse(status);
}
* Example:
*
* RequestURL:
- * http://localhost:8080/controller/nb/v2/flow/default/node/OF/00:00:00:00:00:00:00:01/static-flow/flow1
+ * http://localhost:8080/controller/nb/v2/flowprogrammer/default/node/OF/00:00:00:00:00:00:00:01/staticFlow/flow1
*
* </pre>
*/
- @Path("/{containerName}/node/{nodeType}/{nodeId}/static-flow/{name}")
+ @Path("/{containerName}/node/{nodeType}/{nodeId}/staticFlow/{name}")
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({