javax.xml.bind.annotation,
org.objectweb.asm,
org.opendaylight.controller.sal.utils,
+ org.opendaylight.controller.sal.core,
org.opendaylight.controller.sal.authorization,
org.opendaylight.controller.containermanager,
org.opendaylight.controller.usermanager,
+ org.opendaylight.controller.switchmanager,
org.opendaylight.controller.northbound.bundlescanner,
org.osgi.framework,
org.osgi.service.packageadmin,
</plugins>
</build>
<dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>switchmanager</artifactId>
+ <version>0.5.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal</artifactId>
import org.opendaylight.controller.containermanager.IContainerAuthorization;
import org.opendaylight.controller.sal.authorization.Privilege;
import org.opendaylight.controller.sal.authorization.UserLevel;
+import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.Name;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.usermanager.IUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public static void auditlog(String moduleName, String user, String action, String resource) {
auditlog(moduleName, user, action, resource, null);
}
+
+ public static String getNodeDesc(Node node, ISwitchManager switchManager) {
+ Description desc = (Description) switchManager.getNodeProp(node,
+ Description.propertyName);
+ String description = (desc == null) ? "" : desc.getValue();
+ return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node
+ .toString() : description;
+ }
+
+ public static String getNodeDesc(Node node, String containerName,
+ Object bundle) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper
+ .getInstance(ISwitchManager.class, containerName, bundle);
+ if (switchManager == null) {
+ return null;
+ }
+
+ return getNodeDesc(node, switchManager);
+ }
+
+ public static String getNodeDesc(Node node, Object bundle) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper
+ .getInstance(ISwitchManager.class,
+ GlobalConstants.DEFAULT.toString(), bundle);
+ if (switchManager == null) {
+ return null;
+ }
+
+ return getNodeDesc(node, switchManager);
+ }
+
+ public static String getPortName(NodeConnector nodeConnector,
+ String container, Object bundle) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper
+ .getInstance(ISwitchManager.class, container, bundle);
+ return getPortName(nodeConnector, switchManager);
+ }
+
+ public static String getPortName(NodeConnector nodeConnector, Object bundle) {
+ return getPortName(nodeConnector, GlobalConstants.DEFAULT.toString(), bundle);
+ }
+
+ public static String getPortName(NodeConnector nodeConnector,
+ ISwitchManager switchManager) {
+ Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector,
+ Name.NamePropName));
+ String nodeConnectorName = (ncName != null) ? ncName.getValue() : nodeConnector.getNodeConnectorIdAsString();
+ nodeConnectorName = nodeConnectorName + "@"
+ + getNodeDesc(nodeConnector.getNode(), switchManager);
+ return nodeConnectorName.substring(0, nodeConnectorName.length());
+ }
}
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
-import javax.xml.bind.JAXBElement;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
@Context
public void setSecurityContext(SecurityContext context) {
- if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
+ if (context != null && context.getUserPrincipal() != null) {
+ username = context.getUserPrincipal().getName();
+ }
}
protected String getUserName() {
return username;
}
- private IForwardingRulesManager getForwardingRulesManagerService(
- String containerName) {
- IContainerManager containerManager = (IContainerManager) ServiceHelper
- .getGlobalInstance(IContainerManager.class, this);
+ private IForwardingRulesManager getForwardingRulesManagerService(String containerName) {
+ IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(
+ IContainerManager.class, this);
if (containerManager == null) {
- throw new ServiceUnavailableException("Container "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Container " + RestMessages.SERVICEUNAVAILABLE.toString());
}
boolean found = false;
}
if (found == false) {
- throw new ResourceNotFoundException(containerName + " "
- + RestMessages.NOCONTAINER.toString());
+ throw new ResourceNotFoundException(containerName + " " + RestMessages.NOCONTAINER.toString());
}
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, containerName, this);
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
+ IForwardingRulesManager.class, containerName, this);
if (frm == null) {
- throw new ServiceUnavailableException("Flow Programmer "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString());
}
return frm;
}
- private List<FlowConfig> getStaticFlowsInternal(String containerName,
- Node node) {
+ private List<FlowConfig> getStaticFlowsInternal(String containerName, Node node) {
IForwardingRulesManager frm = getForwardingRulesManagerService(containerName);
if (frm == null) {
- throw new ServiceUnavailableException("Flow Programmer "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString());
}
List<FlowConfig> flows = new ArrayList<FlowConfig>();
flows.add(flow);
}
} else {
- ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
- ISwitchManager.class, containerName, this);
+ ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
if (sm == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
if (!sm.getNodes().contains(node)) {
- throw new ResourceNotFoundException(node.toString() + " : "
- + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(node.toString() + " : " + RestMessages.NONODE.toString());
}
for (FlowConfig flow : frm.getStaticFlows(node)) {
* Name of the Container (Eg. 'default')
* @return List of flows configured on a given container
*
- * <pre>
+ * <pre>
*
* Example:
*
@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 is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public FlowConfigs getStaticFlows(
- @PathParam("containerName") String containerName) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
- }
-
- List<FlowConfig> flowConfigs = getStaticFlowsInternal(containerName,
- null);
+ @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(@PathParam("containerName") String containerName) {
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
+ }
+
+ List<FlowConfig> flowConfigs = getStaticFlowsInternal(containerName, null);
return new FlowConfigs(flowConfigs);
}
* Node Identifier (Eg. '00:00:00:00:00:00:00:01')
* @return List of flows configured on a Node in a container
*
- * <pre>
+ * <pre>
*
* Example:
*
@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(
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ @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(@PathParam("containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId) {
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
Node node = Node.fromString(nodeType, nodeId);
if (node == null) {
- throw new ResourceNotFoundException(nodeId + " : "
- + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(nodeId + " : " + RestMessages.NONODE.toString());
}
List<FlowConfig> flows = getStaticFlowsInternal(containerName, node);
return new FlowConfigs(flows);
* Human-readable name for the configured flow (Eg. 'Flow1')
* @return Flow configuration matching the name and nodeId on a Container
*
- * <pre>
+ * <pre>
*
* Example:
*
@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(
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId, @PathParam("name") String name) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ @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(@PathParam("containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId, @PathParam("name") String name) {
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
IForwardingRulesManager frm = getForwardingRulesManagerService(containerName);
if (frm == null) {
- throw new ServiceUnavailableException("Flow Programmer "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Node node = handleNodeAvailability(containerName, nodeType, nodeId);
}
/**
- * Add a flow configuration. If a flow by the given name already
- * exists, this method will respond with a non-successful status response.
+ * 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')
* Flow Configuration in JSON or XML format
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
- @ResponseCode(code = 201, condition = "Flow Config processed successfully"),
- @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 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(
- @PathParam(value = "containerName") String containerName,
- @PathParam(value = "name") String name,
- @PathParam("nodeType") String nodeType,
- @PathParam(value = "nodeId") String nodeId,
- @TypeHint(FlowConfig.class) FlowConfig flowConfig) {
-
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ @ResponseCode(code = 201, condition = "Flow Config processed successfully"),
+ @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 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(@PathParam(value = "containerName") String containerName,
+ @PathParam(value = "name") String name, @PathParam("nodeType") String nodeType,
+ @PathParam(value = "nodeId") String nodeId, @TypeHint(FlowConfig.class) FlowConfig flowConfig) {
+
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
if (flowConfig.getNode() == null) {
IForwardingRulesManager frm = getForwardingRulesManagerService(containerName);
if (frm == null) {
- throw new ServiceUnavailableException("Flow Programmer "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Node node = handleNodeAvailability(containerName, nodeType, nodeId);
FlowConfig staticFlow = frm.getStaticFlow(name, node);
if (staticFlow != null) {
- throw new ResourceConflictException(name + " already exists."
- + RestMessages.RESOURCECONFLICT.toString());
+ throw new ResourceConflictException(name + " already exists." + RestMessages.RESOURCECONFLICT.toString());
}
Status status = frm.addStaticFlow(flowConfig);
if (status.isSuccess()) {
- NorthboundUtils.auditlog("Flow", username, "added", name, containerName);
+ NorthboundUtils.auditlog("Flow Entry", username, "added",
+ name + " on Node " + NorthboundUtils.getNodeDesc(node, containerName, this), containerName);
return Response.status(Response.Status.CREATED).entity("Success").build();
}
return NorthboundUtils.getResponse(status);
* Name of the Static Flow configuration (Eg. 'Flow1')
* @return Response as dictated by the HTTP Response code
*
- * <pre>
+ * <pre>
*
* Example:
*
@DELETE
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
- @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"),
- @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(
- @PathParam(value = "containerName") String containerName,
- @PathParam(value = "name") String name,
- @PathParam("nodeType") String nodeType,
+ @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"),
+ @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(@PathParam(value = "containerName") String containerName,
+ @PathParam(value = "name") String name, @PathParam("nodeType") String nodeType,
@PathParam(value = "nodeId") String nodeId) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
handleDefaultDisabled(containerName);
IForwardingRulesManager frm = getForwardingRulesManagerService(containerName);
if (frm == null) {
- throw new ServiceUnavailableException("Flow Programmer "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Node node = handleNodeAvailability(containerName, nodeType, nodeId);
FlowConfig staticFlow = frm.getStaticFlow(name, node);
if (staticFlow == null) {
- throw new ResourceNotFoundException(name + " : "
- + RestMessages.NOFLOW.toString());
+ throw new ResourceNotFoundException(name + " : " + RestMessages.NOFLOW.toString());
}
Status status = frm.removeStaticFlow(name, node);
if (status.isSuccess()) {
- NorthboundUtils.auditlog("Flow", username, "removed", name, containerName);
+ NorthboundUtils.auditlog("Flow Entry", username, "removed",
+ name + " from Node " + NorthboundUtils.getNodeDesc(node, containerName, this), containerName);
return Response.noContent().build();
}
return NorthboundUtils.getResponse(status);
* Name of the Static Flow configuration (Eg. 'Flow1')
* @return Response as dictated by the HTTP Response code
*
- * <pre>
+ * <pre>
*
* Example:
*
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
- @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 = "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(
- @PathParam(value = "containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam(value = "nodeId") String nodeId,
+ @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 = "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(@PathParam(value = "containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam(value = "nodeId") String nodeId,
@PathParam(value = "name") String name) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
handleDefaultDisabled(containerName);
IForwardingRulesManager frm = getForwardingRulesManagerService(containerName);
if (frm == null) {
- throw new ServiceUnavailableException("Flow Programmer "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Flow Programmer " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Node node = handleNodeAvailability(containerName, nodeType, nodeId);
FlowConfig staticFlow = frm.getStaticFlow(name, node);
if (staticFlow == null) {
- throw new ResourceNotFoundException(name + " : "
- + RestMessages.NOFLOW.toString());
+ throw new ResourceNotFoundException(name + " : " + RestMessages.NOFLOW.toString());
}
Status status = frm.toggleStaticFlowStatus(staticFlow);
if (status.isSuccess()) {
- NorthboundUtils.auditlog("Flow", username, "toggled", name, containerName);
+ NorthboundUtils.auditlog("Flow Entry", username, "toggled",
+ name + " on Node " + NorthboundUtils.getNodeDesc(node, containerName, this), containerName);
}
return NorthboundUtils.getResponse(status);
}
- private Node handleNodeAvailability(String containerName, String nodeType,
- String nodeId) {
+ private Node handleNodeAvailability(String containerName, String nodeType, String nodeId) {
Node node = Node.fromString(nodeType, nodeId);
if (node == null) {
- throw new ResourceNotFoundException(nodeId + " : "
- + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(nodeId + " : " + RestMessages.NONODE.toString());
}
- ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
- ISwitchManager.class, containerName, this);
+ ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
if (sm == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
if (!sm.getNodes().contains(node)) {
- throw new ResourceNotFoundException(node.toString() + " : "
- + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(node.toString() + " : " + RestMessages.NONODE.toString());
}
return node;
}
private void handleDefaultDisabled(String containerName) {
- IContainerManager containerManager = (IContainerManager) ServiceHelper
- .getGlobalInstance(IContainerManager.class, this);
+ IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(
+ IContainerManager.class, this);
if (containerManager == null) {
- throw new InternalServerErrorException(
- RestMessages.INTERNALERROR.toString());
+ throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString());
}
- if (containerName.equals(GlobalConstants.DEFAULT.toString())
- && containerManager.hasNonDefaultContainer()) {
- throw new NotAcceptableException(
- RestMessages.DEFAULTDISABLED.toString());
+ if (containerName.equals(GlobalConstants.DEFAULT.toString()) && containerManager.hasNonDefaultContainer()) {
+ throw new NotAcceptableException(RestMessages.DEFAULTDISABLED.toString());
}
}
*/
package org.opendaylight.controller.subnets.northbound;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
import org.opendaylight.controller.sal.authorization.Privilege;
+import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.switchmanager.ISwitchManager;
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The containerName passed was not found"),
- @ResponseCode(code = 503, condition = "Service unavailable") })
+ @ResponseCode(code = 404, condition = "The containerName passed was not found"),
+ @ResponseCode(code = 503, condition = "Service unavailable") })
@TypeHint(SubnetConfigs.class)
public SubnetConfigs listSubnets(@PathParam("containerName") String containerName) {
throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ containerName);
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
throw new ServiceUnavailableException("SwitchManager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The containerName or subnetName passed was not found"),
- @ResponseCode(code = 503, condition = "Service unavailable") })
+ @ResponseCode(code = 404, condition = "The containerName or subnetName passed was not found"),
+ @ResponseCode(code = 503, condition = "Service unavailable") })
@TypeHint(SubnetConfig.class)
public SubnetConfig listSubnet(@PathParam("containerName") String containerName,
@PathParam("subnetName") String subnetName) {
throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ containerName);
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
throw new ServiceUnavailableException("SwitchManager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
}
/**
- * Add a subnet into the specified container context, node connectors are optional
+ * Add a subnet into the specified container context, node connectors are
+ * optional
*
* @param containerName
- * name of the container context in which the subnet needs to be added
+ * name of the container context in which the subnet needs to be
+ * added
* @param subnetName
* name of new subnet to be added
* @param subnetConfigData
@Path("/{containerName}/subnet/{subnetName}")
@PUT
@StatusCodes({ @ResponseCode(code = 201, condition = "Subnet created successfully"),
- @ResponseCode(code = 400, condition = "Invalid data passed"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"),
- @ResponseCode(code = 404, condition = "Container name passed was not found or subnet config is null"),
- @ResponseCode(code = 500, condition = "Internal Server Error: Addition of subnet failed"),
- @ResponseCode(code = 503, condition = "Service unavailable") })
+ @ResponseCode(code = 400, condition = "Invalid data passed"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"),
+ @ResponseCode(code = 404, condition = "Container name passed was not found or subnet config is null"),
+ @ResponseCode(code = 500, condition = "Internal Server Error: Addition of subnet failed"),
+ @ResponseCode(code = 503, condition = "Service unavailable") })
public Response addSubnet(@PathParam("containerName") String containerName,
- @PathParam("subnetName") String subnetName,
- @TypeHint(SubnetConfig.class) SubnetConfig subnetConfigData) {
+ @PathParam("subnetName") String subnetName, @TypeHint(SubnetConfig.class) SubnetConfig subnetConfigData) {
handleContainerDoesNotExist(containerName);
SubnetConfig cfgObject = subnetConfigData;
handleNameMismatch(cfgObject.getName(), subnetName);
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
throw new ServiceUnavailableException("SwitchManager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Status status = switchManager.addSubnet(cfgObject);
if (status.isSuccess()) {
NorthboundUtils.auditlog("Subnet Gateway", username, "added", subnetName, containerName);
+ if (subnetConfigData.getNodeConnectors() != null) {
+ for (NodeConnector port : subnetConfigData.getNodeConnectors()) {
+ NorthboundUtils.auditlog("Port", getUserName(), "added",
+ NorthboundUtils.getPortName(port, switchManager) + " to Subnet Gateway " + subnetName,
+ containerName);
+ }
+ }
return Response.status(Response.Status.CREATED).build();
}
return NorthboundUtils.getResponse(status);
@Path("/{containerName}/subnet/{subnetName}")
@DELETE
@StatusCodes({ @ResponseCode(code = 204, condition = "No Content"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The containerName passed was not found"),
- @ResponseCode(code = 500, condition = "Internal Server Error : Removal of subnet failed"),
- @ResponseCode(code = 503, condition = "Service unavailable") })
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 404, condition = "The containerName passed was not found"),
+ @ResponseCode(code = 500, condition = "Internal Server Error : Removal of subnet failed"),
+ @ResponseCode(code = 503, condition = "Service unavailable") })
public Response removeSubnet(@PathParam("containerName") String containerName,
@PathParam("subnetName") String subnetName) {
+ containerName);
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
throw new ServiceUnavailableException("SwitchManager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({ @ResponseCode(code = 200, condition = "Configuration replaced successfully"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"),
- @ResponseCode(code = 404, condition = "The containerName or subnetName is not found"),
- @ResponseCode(code = 500, condition = "Internal server error: Modify subnet failed"),
- @ResponseCode(code = 503, condition = "Service unavailable") })
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 409, condition = "Subnet name in url conflicts with name in request body"),
+ @ResponseCode(code = 404, condition = "The containerName or subnetName is not found"),
+ @ResponseCode(code = 500, condition = "Internal server error: Modify subnet failed"),
+ @ResponseCode(code = 503, condition = "Service unavailable") })
public Response modifySubnet(@Context UriInfo uriInfo, @PathParam("containerName") String containerName,
@PathParam("subnetName") String subnetName, @TypeHint(SubnetConfig.class) SubnetConfig subnetConfigData) {
if (status.isSuccess()) {
if (existingConf == null) {
- NorthboundUtils.auditlog("Subnet Gateway", username, "created", subnetName, containerName);
+ NorthboundUtils.auditlog("Subnet Gateway", username, "added", subnetName, containerName);
+ if (subnetConfigData.getNodeConnectors() != null) {
+ for (NodeConnector port : subnetConfigData.getNodeConnectors()) {
+ NorthboundUtils.auditlog("Port", getUserName(), "added",
+ NorthboundUtils.getPortName(port, switchManager) + " to Subnet Gateway" + subnetName,
+ containerName);
+ }
+ }
return Response.created(uriInfo.getRequestUri()).build();
} else {
- NorthboundUtils.auditlog("Subnet Gateway", username, "modified", subnetName, containerName);
+ Set<NodeConnector> existingNCList = existingConf.getNodeConnectors();
+
+ if (existingNCList == null) {
+ existingNCList = new HashSet<NodeConnector>(0);
+ }
+ if (subnetConfigData.getNodeConnectors() != null) {
+ for (NodeConnector port : subnetConfigData.getNodeConnectors()) {
+ if (!existingNCList.contains(port)) {
+ NorthboundUtils.auditlog("Port", getUserName(), "added",
+ NorthboundUtils.getPortName(port, switchManager) + " to Subnet Gateway "
+ + subnetName, containerName);
+ }
+ }
+ }
+ for (NodeConnector port : existingNCList) {
+ if (!subnetConfigData.getNodeConnectors().contains(port)) {
+ NorthboundUtils
+ .auditlog("Port", getUserName(), "removed",
+ NorthboundUtils.getPortName(port, switchManager) + " from Subnet Gateway "
+ + subnetName, containerName);
+ }
+ }
}
}
return NorthboundUtils.getResponse(status);
}
private ISwitchManager getIfSwitchManagerService(String containerName) {
- IContainerManager containerManager = (IContainerManager) ServiceHelper
- .getGlobalInstance(IContainerManager.class, this);
+ IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(
+ IContainerManager.class, this);
if (containerManager == null) {
- throw new ServiceUnavailableException("Container "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Container " + RestMessages.SERVICEUNAVAILABLE.toString());
}
boolean found = false;
}
if (found == false) {
- throw new ResourceNotFoundException(containerName + " "
- + RestMessages.NOCONTAINER.toString());
+ throw new ResourceNotFoundException(containerName + " " + RestMessages.NOCONTAINER.toString());
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
return switchManager;
* {@link org.opendaylight.controller.sal.core.Property} attached to
* it.
*
- * <pre>
+ * <pre>
*
* Example:
*
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(Nodes.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") })
+ @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 Nodes getNodes(@PathParam("containerName") String containerName) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
List<NodeProperties> res = new ArrayList<NodeProperties>();
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(Response.class)
@StatusCodes({
- @ResponseCode(code = 201, condition = "Operation successful"),
- @ResponseCode(code = 400, condition = "The nodeId or configuration is invalid"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The Container Name or node or configuration name is not found"),
- @ResponseCode(code = 406, condition = "The property cannot be configured in non-default container"),
- @ResponseCode(code = 409, condition = "Unable to update configuration due to cluster conflict or conflicting description property"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addNodeProperty(
- @Context UriInfo uriInfo,
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId,
- @PathParam("propertyName") String propertyName,
- @PathParam("propertyValue") String propertyValue) {
+ @ResponseCode(code = 201, condition = "Operation successful"),
+ @ResponseCode(code = 400, condition = "The nodeId or configuration is invalid"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 404, condition = "The Container Name or node or configuration name is not found"),
+ @ResponseCode(code = 406, condition = "The property cannot be configured in non-default container"),
+ @ResponseCode(code = 409, condition = "Unable to update configuration due to cluster conflict or conflicting description property"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response addNodeProperty(@Context UriInfo uriInfo, @PathParam("containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
+ @PathParam("propertyName") String propertyName, @PathParam("propertyValue") String propertyValue) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
handleNodeAvailability(containerName, nodeType, nodeId);
SwitchConfig newSwitchConfig = new SwitchConfig(node.toString(), nodeProperties);
Status status = switchManager.updateNodeConfig(newSwitchConfig);
if (status.isSuccess()) {
+ NorthboundUtils.auditlog("Property " + propertyName, username, "updated",
+ "of Node " + NorthboundUtils.getNodeDesc(node, switchManager), containerName);
+
return Response.created(uriInfo.getRequestUri()).build();
}
return NorthboundUtils.getResponse(status);
* Type of the node being programmed (Eg. 'OF')
* @param nodeId
* Node Identifier as specified by
- * {@link org.opendaylight.controller.sal.core.Node}
- * (Eg. '00:00:00:00:00:03:01:02')
+ * {@link org.opendaylight.controller.sal.core.Node} (Eg.
+ * '00:00:00:00:00:03:01:02')
* @param propertyName
* Name of the Property. Properties that can be deleted are
* description, forwarding(only in default container) and tier.
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@Path("/{containerName}/node/{nodeType}/{nodeId}/property/{propertyName}")
@DELETE
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @StatusCodes({
- @ResponseCode(code = 204, condition = "Property removed successfully"),
- @ResponseCode(code = 400, condition = "The nodeId or configuration is invalid"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 409, condition = "Unable to delete property due to cluster conflict"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response deleteNodeProperty(
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId,
+ @StatusCodes({ @ResponseCode(code = 204, condition = "Property removed successfully"),
+ @ResponseCode(code = 400, condition = "The nodeId or configuration is invalid"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+ @ResponseCode(code = 409, condition = "Unable to delete property due to cluster conflict"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response deleteNodeProperty(@PathParam("containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
@PathParam("propertyName") String propertyName) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
handleNodeAvailability(containerName, nodeType, nodeId);
nodeProperties.remove(propertyName.toLowerCase());
SwitchConfig newSwitchConfig = new SwitchConfig(node.toString(), nodeProperties);
status = switchManager.updateNodeConfig(newSwitchConfig);
- if(status.isSuccess()){
- NorthboundUtils.auditlog("Node Property", username, "removed", propertyName + " from " + nodeId, containerName);
+ if (status.isSuccess()) {
+ NorthboundUtils.auditlog("Property " + propertyName, username, "removed", "of Node "
+ + NorthboundUtils.getNodeDesc(node, switchManager), containerName);
return Response.noContent().build();
}
}
* {@link org.opendaylight.controller.sal.core.Property} attached to
* it.
*
- * <pre>
+ * <pre>
*
* Example:
*
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(NodeConnectors.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 NodeConnectors getNodeConnectors(
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId) {
+ @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 NodeConnectors getNodeConnectors(@PathParam("containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
handleNodeAvailability(containerName, nodeType, nodeId);
}
for (NodeConnector nc : ncs) {
- Map<String, Property> propMap = switchManager
- .getNodeConnectorProps(nc);
+ Map<String, Property> propMap = switchManager.getNodeConnectorProps(nc);
if (propMap == null) {
continue;
}
Set<Property> props = new HashSet<Property>(propMap.values());
- NodeConnectorProperties ncProps = new NodeConnectorProperties(nc,
- props);
+ NodeConnectorProperties ncProps = new NodeConnectorProperties(nc, props);
res.add(ncProps);
}
* Type of the node being programmed (Eg. 'OF')
* @param nodeId
* Node Identifier as specified by
- * {@link org.opendaylight.controller.sal.core.Node}
- * (Eg. '00:00:00:00:00:00:00:03')
+ * {@link org.opendaylight.controller.sal.core.Node} (Eg.
+ * '00:00:00:00:00:00:00:03')
* @param nodeConnectorType
* Type of the node connector being programmed (Eg. 'OF')
* @param nodeConnectorId
* @param propertyName
* Name of the Property specified by
* {@link org.opendaylight.controller.sal.core.Property} and its
- * extended classes
- * Property that can be configured is bandwidth
+ * extended classes Property that can be configured is bandwidth
* @param propertyValue
* Value of the Property specified by
* {@link org.opendaylight.controller.sal.core.Property} and its
* extended classes
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@Path("/{containerName}/nodeconnector/{nodeType}/{nodeId}/{nodeConnectorType}/{nodeConnectorId}/property/{propertyName}/{propertyValue}")
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @StatusCodes({
- @ResponseCode(code = 201, condition = "Operation successful"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 409, condition = "Unable to add property due to cluster conflict"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addNodeConnectorProperty(
- @Context UriInfo uriInfo,
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId,
- @PathParam("nodeConnectorType") String nodeConnectorType,
- @PathParam("nodeConnectorId") String nodeConnectorId,
- @PathParam("propertyName") String propertyName,
+ @StatusCodes({ @ResponseCode(code = 201, condition = "Operation successful"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+ @ResponseCode(code = 409, condition = "Unable to add property due to cluster conflict"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response addNodeConnectorProperty(@Context UriInfo uriInfo,
+ @PathParam("containerName") String containerName, @PathParam("nodeType") String nodeType,
+ @PathParam("nodeId") String nodeId, @PathParam("nodeConnectorType") String nodeConnectorType,
+ @PathParam("nodeConnectorId") String nodeConnectorId, @PathParam("propertyName") String propertyName,
@PathParam("propertyValue") String propertyValue) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
handleNodeAvailability(containerName, nodeType, nodeId);
Node node = Node.fromString(nodeType, nodeId);
- handleNodeConnectorAvailability(containerName, node, nodeConnectorType,
- nodeConnectorId);
- NodeConnector nc = NodeConnector
- .fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
+ handleNodeConnectorAvailability(containerName, node, nodeConnectorType, nodeConnectorId);
+ NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
Property prop = switchManager.createProperty(propertyName, propertyValue);
if (prop == null) {
- throw new ResourceNotFoundException(
- RestMessages.INVALIDDATA.toString());
+ throw new ResourceNotFoundException(RestMessages.INVALIDDATA.toString());
}
Status ret = switchManager.addNodeConnectorProp(nc, prop);
if (ret.isSuccess()) {
+ NorthboundUtils.auditlog("Property " + propertyName, username, "updated", "of Node Connector "
+ + NorthboundUtils.getPortName(nc, switchManager), containerName);
return Response.created(uriInfo.getRequestUri()).build();
}
throw new InternalServerErrorException(ret.getDescription());
* Type of the node being programmed (Eg. 'OF')
* @param nodeId
* Node Identifier as specified by
- * {@link org.opendaylight.controller.sal.core.Node}
- * (Eg. '00:00:00:00:00:00:00:01')
+ * {@link org.opendaylight.controller.sal.core.Node} (Eg.
+ * '00:00:00:00:00:00:00:01')
* @param nodeConnectorType
* Type of the node connector being programmed (Eg. 'OF')
* @param nodeConnectorId
* extended classes. Property that can be deleted is bandwidth
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@Path("/{containerName}/nodeconnector/{nodeType}/{nodeId}/{nodeConnectorType}/{nodeConnectorId}/property/{propertyName}")
@DELETE
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @StatusCodes({
- @ResponseCode(code = 204, condition = "Property removed successfully"),
- @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
- @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response deleteNodeConnectorProperty(
- @PathParam("containerName") String containerName,
- @PathParam("nodeType") String nodeType,
- @PathParam("nodeId") String nodeId,
+ @StatusCodes({ @ResponseCode(code = 204, condition = "Property removed successfully"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 404, condition = "The Container Name or nodeId or configuration name is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response deleteNodeConnectorProperty(@PathParam("containerName") String containerName,
+ @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId,
@PathParam("nodeConnectorType") String nodeConnectorType,
- @PathParam("nodeConnectorId") String nodeConnectorId,
- @PathParam("propertyName") String propertyName) {
+ @PathParam("nodeConnectorId") String nodeConnectorId, @PathParam("propertyName") String propertyName) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
handleNodeAvailability(containerName, nodeType, nodeId);
Node node = Node.fromString(nodeType, nodeId);
- handleNodeConnectorAvailability(containerName, node, nodeConnectorType,
- nodeConnectorId);
- NodeConnector nc = NodeConnector
- .fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
+ handleNodeConnectorAvailability(containerName, node, nodeConnectorType, nodeConnectorId);
+ NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
Status ret = switchManager.removeNodeConnectorProp(nc, propertyName);
if (ret.isSuccess()) {
- NorthboundUtils.auditlog("Node Connector Property", username, "removed", nc + " from " + nodeConnectorId, containerName);
+ NorthboundUtils.auditlog("Property " + propertyName, username, "removed", "of Node Connector "
+ + NorthboundUtils.getPortName(nc, switchManager), containerName);
return Response.noContent().build();
}
throw new ResourceNotFoundException(ret.getDescription());
* Name of the Container (Eg. 'default')
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@POST
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@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 = 500, condition = "Failed to save switch configuration. Failure Reason included in HTTP Error response"),
- @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public Response saveSwitchConfig(
- @PathParam("containerName") String containerName) {
+ @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 = 500, condition = "Failed to save switch configuration. Failure Reason included in HTTP Error response"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public Response saveSwitchConfig(@PathParam("containerName") String containerName) {
if (!isValidContainer(containerName)) {
throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
}
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
ISwitchManager switchManager = getIfSwitchManagerService(containerName);
if (switchManager == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
Status ret = switchManager.saveSwitchConfig();
throw new InternalServerErrorException(ret.getDescription());
}
- private Node handleNodeAvailability(String containerName, String nodeType,
- String nodeId) {
+ private Node handleNodeAvailability(String containerName, String nodeType, String nodeId) {
Node node = Node.fromString(nodeType, nodeId);
if (node == null) {
- throw new ResourceNotFoundException(nodeId + " : "
- + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(nodeId + " : " + RestMessages.NONODE.toString());
}
- ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
- ISwitchManager.class, containerName, this);
+ ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
if (sm == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
if (!sm.getNodes().contains(node)) {
- throw new ResourceNotFoundException(node.toString() + " : "
- + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(node.toString() + " : " + RestMessages.NONODE.toString());
}
return node;
}
- private void handleNodeConnectorAvailability(String containerName,
- Node node, String nodeConnectorType, String nodeConnectorId) {
+ private void handleNodeConnectorAvailability(String containerName, Node node, String nodeConnectorType,
+ String nodeConnectorId) {
- NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType,
- nodeConnectorId, node);
+ NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType, nodeConnectorId, node);
if (nc == null) {
- throw new ResourceNotFoundException(nc + " : "
- + RestMessages.NORESOURCE.toString());
+ throw new ResourceNotFoundException(nc + " : " + RestMessages.NORESOURCE.toString());
}
- ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(
- ISwitchManager.class, containerName, this);
+ ISwitchManager sm = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName, this);
if (sm == null) {
- throw new ServiceUnavailableException("Switch Manager "
- + RestMessages.SERVICEUNAVAILABLE.toString());
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
}
if (!sm.getNodeConnectors(node).contains(nc)) {
- throw new ResourceNotFoundException(nc.toString() + " : "
- + RestMessages.NORESOURCE.toString());
+ throw new ResourceNotFoundException(nc.toString() + " : " + RestMessages.NORESOURCE.toString());
}
}
if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
return true;
}
- IContainerManager containerManager = (IContainerManager) ServiceHelper
- .getGlobalInstance(IContainerManager.class, this);
+ IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(
+ IContainerManager.class, this);
if (containerManager == null) {
- throw new InternalServerErrorException(
- RestMessages.INTERNALERROR.toString());
+ throw new InternalServerErrorException(RestMessages.INTERNALERROR.toString());
}
if (containerManager.getContainerNames().contains(containerName)) {
return true;
- }
+ }
return false;
}
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
-import javax.xml.bind.JAXBElement;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
import org.opendaylight.controller.sal.authorization.Privilege;
import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.core.Property;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
@Context
public void setSecurityContext(SecurityContext context) {
- if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
+ if (context != null && context.getUserPrincipal() != null) {
+ username = context.getUserPrincipal().getName();
+ }
}
protected String getUserName() {
@StatusCodes({ @ResponseCode(code = 404, condition = "The Container Name was not found") })
public Topology getTopology(@PathParam("containerName") String containerName) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper.getInstance(ITopologyManager.class,
+ containerName, this);
if (topologyManager == null) {
- throw new ResourceNotFoundException(
- RestMessages.NOCONTAINER.toString());
+ throw new ResourceNotFoundException(RestMessages.NOCONTAINER.toString());
}
Map<Edge, Set<Property>> topo = topologyManager.getEdges();
* Retrieve the user configured links
*
* @param containerName
- * The container for which we want to retrieve the user links (Eg. 'default')
+ * The container for which we want to retrieve the user links
+ * (Eg. 'default')
*
* @return A List of user configured links
*
- * <pre>
+ * <pre>
*
* Example:
*
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@TypeHint(TopologyUserLinks.class)
@StatusCodes({ @ResponseCode(code = 404, condition = "The Container Name was not found") })
- public TopologyUserLinks getUserLinks(
- @PathParam("containerName") String containerName) {
+ public TopologyUserLinks getUserLinks(@PathParam("containerName") String containerName) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.READ, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper.getInstance(ITopologyManager.class,
+ containerName, this);
if (topologyManager == null) {
- throw new ResourceNotFoundException(
- RestMessages.NOCONTAINER.toString());
+ throw new ResourceNotFoundException(RestMessages.NOCONTAINER.toString());
}
- ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topologyManager
- .getUserLinks();
+ ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topologyManager.getUserLinks();
if ((userLinks != null) && (userLinks.values() != null)) {
- List<TopologyUserLinkConfig> res = new ArrayList<TopologyUserLinkConfig>(
- userLinks.values());
+ List<TopologyUserLinkConfig> res = new ArrayList<TopologyUserLinkConfig>(userLinks.values());
return new TopologyUserLinks(res);
}
* in JSON or XML format
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
- @ResponseCode(code = 201, condition = "User Link added successfully"),
- @ResponseCode(code = 404, condition = "The Container Name was not found"),
- @ResponseCode(code = 409, condition = "Failed to add User Link due to Conflicting Name"),
- @ResponseCode(code = 500, condition = "Failed to add User Link. Failure Reason included in HTTP Error response"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addUserLink(
- @PathParam(value = "containerName") String containerName,
+ @ResponseCode(code = 201, condition = "User Link added successfully"),
+ @ResponseCode(code = 404, condition = "The Container Name was not found"),
+ @ResponseCode(code = 409, condition = "Failed to add User Link due to Conflicting Name"),
+ @ResponseCode(code = 500, condition = "Failed to add User Link. Failure Reason included in HTTP Error response"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response addUserLink(@PathParam(value = "containerName") String containerName,
@PathParam(value = "name") String name,
@TypeHint(TopologyUserLinkConfig.class) TopologyUserLinkConfig userLinkConfig) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper.getInstance(ITopologyManager.class,
+ containerName, this);
if (topologyManager == null) {
- throw new ResourceNotFoundException(
- RestMessages.NOCONTAINER.toString());
+ throw new ResourceNotFoundException(RestMessages.NOCONTAINER.toString());
}
Status status = topologyManager.addUserLink(userLinkConfig);
if (status.isSuccess()) {
- NorthboundUtils.auditlog("User Link", username, "added", userLinkConfig.getName(), containerName);
+ NorthboundUtils
+ .auditlog(
+ "User Link",username,"added", userLinkConfig.getName() + " from " + NorthboundUtils.getPortName(
+ NodeConnector.fromString(userLinkConfig.getSrcNodeConnector()),
+ containerName, this) + " to "
+ + NorthboundUtils.getPortName(NodeConnector.fromString
+ (userLinkConfig.getDstNodeConnector()),containerName, this), containerName);
return Response.status(Response.Status.CREATED).build();
}
throw new InternalServerErrorException(status.getDescription());
* Name of the Link Configuration (Eg. 'config1')
* @return Response as dictated by the HTTP Response Status code
*
- * <pre>
+ * <pre>
*
* Example:
*
@DELETE
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @StatusCodes({
- @ResponseCode(code = 204, condition = "User link removed successfully"),
- @ResponseCode(code = 404, condition = "The Container Name or Link Configuration Name was not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response deleteUserLink(
- @PathParam("containerName") String containerName,
- @PathParam("name") String name) {
+ @StatusCodes({ @ResponseCode(code = 204, condition = "User link removed successfully"),
+ @ResponseCode(code = 404, condition = "The Container Name or Link Configuration Name was not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response deleteUserLink(@PathParam("containerName") String containerName, @PathParam("name") String name) {
- if (!NorthboundUtils.isAuthorized(
- getUserName(), containerName, Privilege.WRITE, this)) {
- throw new UnauthorizedException(
- "User is not authorized to perform this operation on container "
- + containerName);
+ if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
}
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper.getInstance(ITopologyManager.class,
+ containerName, this);
if (topologyManager == null) {
- throw new ResourceNotFoundException(
- RestMessages.NOCONTAINER.toString());
+ throw new ResourceNotFoundException(RestMessages.NOCONTAINER.toString());
}
Status ret = topologyManager.deleteUserLink(name);
@RequestMapping(value = "/nodesLearnt", method = RequestMethod.GET)
@ResponseBody
- public DevicesJsonBean getNodesLearnt(HttpServletRequest request,
- @RequestParam(required = false) String container) {
+ public DevicesJsonBean getNodesLearnt(HttpServletRequest request, @RequestParam(required = false) String container) {
Gson gson = new Gson();
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
for (NodeConnector nodeConnector : nodeConnectorSet) {
String nodeConnectorNumberToStr = nodeConnector.getID().toString();
Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector, Name.NamePropName));
- Config portStatus = ((Config) switchManager
- .getNodeConnectorProp(nodeConnector,
- Config.ConfigPropName));
- State portState = ((State) switchManager
- .getNodeConnectorProp(nodeConnector,
- State.StatePropName));
- String nodeConnectorName = (ncName != null) ? ncName
- .getValue() : "";
+ Config portStatus = ((Config) switchManager.getNodeConnectorProp(nodeConnector,
+ Config.ConfigPropName));
+ State portState = ((State) switchManager.getNodeConnectorProp(nodeConnector,
+ State.StatePropName));
+ String nodeConnectorName = (ncName != null) ? ncName.getValue() : "";
nodeConnectorName += " (" + nodeConnector.getID() + ")";
if (portStatus != null) {
if (portStatus.getValue() == Config.ADMIN_UP) {
if (portState.getValue() == State.EDGE_UP) {
- nodeConnectorName = "<span class='admin-up'>"
- + nodeConnectorName + "</span>";
+ nodeConnectorName = "<span class='admin-up'>" + nodeConnectorName + "</span>";
} else if (portState.getValue() == State.EDGE_DOWN) {
- nodeConnectorName = "<span class='edge-down'>"
- + nodeConnectorName + "</span>";
+ nodeConnectorName = "<span class='edge-down'>" + nodeConnectorName + "</span>";
}
} else if (portStatus.getValue() == Config.ADMIN_DOWN) {
- nodeConnectorName = "<span class='admin-down'>"
- + nodeConnectorName + "</span>";
+ nodeConnectorName = "<span class='admin-down'>" + nodeConnectorName + "</span>";
}
}
Class<?> idClass = nodeConnector.getID().getClass();
if (idClass.equals(Short.class)) {
- portList.put(
- Short.parseShort(nodeConnectorNumberToStr),
- nodeConnectorName);
+ portList.put(Short.parseShort(nodeConnectorNumberToStr), nodeConnectorName);
} else {
intfList.add(nodeConnectorName);
}
}
if (portList.size() > 0) {
- Map<Short, String> sortedPortList = new TreeMap<Short, String>(
- portList);
+ Map<Short, String> sortedPortList = new TreeMap<Short, String>(portList);
for (Entry<Short, String> e : sortedPortList.entrySet()) {
sb1.append(e.getValue());
@RequestMapping(value = "/nodesLearnt/update", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean updateLearntNode(
- @RequestParam("nodeName") String nodeName,
- @RequestParam("nodeId") String nodeId,
- @RequestParam("tier") String tier,
- @RequestParam("operationMode") String operationMode,
- HttpServletRequest request,
+ public StatusJsonBean updateLearntNode(@RequestParam("nodeName") String nodeName,
+ @RequestParam("nodeId") String nodeId, @RequestParam("tier") String tier,
+ @RequestParam("operationMode") String operationMode, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return unauthorizedMessage();
}
StatusJsonBean resultBean = new StatusJsonBean();
try {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
Map<String, Property> nodeProperties = new HashMap<String, Property>();
Property desc = new Description(nodeName);
nodeProperties.put(desc.getName(), desc);
} else {
resultBean.setStatus(true);
resultBean.setMessage("Updated node information successfully");
- DaylightWebUtil.auditlog("Node", userName, "updated", nodeId + " to "+ nodeName, containerName);
+ DaylightWebUtil.auditlog("Property", userName, "updated",
+ "of Node " + DaylightWebUtil.getNodeDesc(Node.fromString(nodeId), switchManager));
}
} catch (Exception e) {
resultBean.setStatus(false);
- resultBean.setMessage("Error updating node information. "
- + e.getMessage());
+ resultBean.setMessage("Error updating node information. " + e.getMessage());
}
return resultBean;
}
@RequestMapping(value = "/staticRoutes", method = RequestMethod.GET)
@ResponseBody
- public DevicesJsonBean getStaticRoutes(HttpServletRequest request,
- @RequestParam(required = false) String container) {
+ public DevicesJsonBean getStaticRoutes(HttpServletRequest request, @RequestParam(required = false) String container) {
Gson gson = new Gson();
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
- IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
- .getInstance(IForwardingStaticRouting.class, containerName,
- this);
+ IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper.getInstance(
+ IForwardingStaticRouting.class, containerName, this);
if (staticRouting == null) {
return null;
}
List<Map<String, String>> staticRoutes = new ArrayList<Map<String, String>>();
- ConcurrentMap<String, StaticRouteConfig> routeConfigs = staticRouting
- .getStaticRouteConfigs();
+ ConcurrentMap<String, StaticRouteConfig> routeConfigs = staticRouting.getStaticRouteConfigs();
if (routeConfigs == null) {
return null;
}
@RequestMapping(value = "/staticRoute/add", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean addStaticRoute(
- @RequestParam("routeName") String routeName,
- @RequestParam("staticRoute") String staticRoute,
- @RequestParam("nextHop") String nextHop,
- HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public StatusJsonBean addStaticRoute(@RequestParam("routeName") String routeName,
+ @RequestParam("staticRoute") String staticRoute, @RequestParam("nextHop") String nextHop,
+ HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return unauthorizedMessage();
}
StatusJsonBean result = new StatusJsonBean();
try {
- IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
- .getInstance(IForwardingStaticRouting.class, containerName,
- this);
+ IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper.getInstance(
+ IForwardingStaticRouting.class, containerName, this);
StaticRouteConfig config = new StaticRouteConfig();
config.setName(routeName);
config.setStaticRoute(staticRoute);
@RequestMapping(value = "/staticRoute/delete", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean deleteStaticRoute(
- @RequestParam("routesToDelete") String routesToDelete,
- HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public StatusJsonBean deleteStaticRoute(@RequestParam("routesToDelete") String routesToDelete,
+ HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
- IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
- .getInstance(IForwardingStaticRouting.class, containerName,
- this);
+ IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper.getInstance(
+ IForwardingStaticRouting.class, containerName, this);
String[] routes = routesToDelete.split(",");
Status result;
resultBean.setStatus(true);
- resultBean
- .setMessage("Successfully deleted selected static routes");
+ resultBean.setMessage("Successfully deleted selected static routes");
for (String route : routes) {
result = staticRouting.removeStaticRoute(route);
if (!result.isSuccess()) {
}
} catch (Exception e) {
resultBean.setStatus(false);
- resultBean
- .setMessage("Error occurred while deleting static routes. "
- + e.getMessage());
+ resultBean.setMessage("Error occurred while deleting static routes. " + e.getMessage());
}
return resultBean;
}
subnet.put("subnet", conf.getSubnet());
List<SubnetGatewayPortBean> portsList = new ArrayList<SubnetGatewayPortBean>();
Iterator<NodeConnector> itor = conf.getNodeConnectors().iterator();
- while(itor.hasNext()) {
+ while (itor.hasNext()) {
SubnetGatewayPortBean bean = new SubnetGatewayPortBean();
NodeConnector nodeConnector = itor.next();
String nodeName = getNodeDesc(nodeConnector.getNode().toString(), containerName);
@RequestMapping(value = "/subnetGateway/add", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean addSubnetGateways(
- @RequestParam("gatewayName") String gatewayName,
- @RequestParam("gatewayIPAddress") String gatewayIPAddress,
- HttpServletRequest request,
+ public StatusJsonBean addSubnetGateways(@RequestParam("gatewayName") String gatewayName,
+ @RequestParam("gatewayIPAddress") String gatewayIPAddress, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
- SubnetConfig cfgObject = new SubnetConfig(gatewayName,
- gatewayIPAddress, new ArrayList<String>());
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
+ SubnetConfig cfgObject = new SubnetConfig(gatewayName, gatewayIPAddress, new ArrayList<String>());
Status result = switchManager.addSubnet(cfgObject);
if (result.isSuccess()) {
resultBean.setStatus(true);
@RequestMapping(value = "/subnetGateway/delete", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean deleteSubnetGateways(
- @RequestParam("gatewaysToDelete") String gatewaysToDelete,
- HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public StatusJsonBean deleteSubnetGateways(@RequestParam("gatewaysToDelete") String gatewaysToDelete,
+ HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
String[] subnets = gatewaysToDelete.split(",");
resultBean.setStatus(true);
resultBean.setMessage("Added gateway address successfully");
@RequestMapping(value = "/subnetGateway/ports/add", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean addSubnetGatewayPort(
- @RequestParam("portsName") String portsName,
- @RequestParam("ports") String ports,
- @RequestParam("nodeId") String nodeId, HttpServletRequest request,
+ public StatusJsonBean addSubnetGatewayPort(@RequestParam("portsName") String portsName,
+ @RequestParam("ports") String ports, @RequestParam("nodeId") String nodeId, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
List<String> toAdd = new ArrayList<String>();
for (String port : ports.split(",")) {
toAdd.add(port);
if (result.isSuccess()) {
resultBean.setStatus(true);
- resultBean
- .setMessage("Added ports to subnet gateway address successfully");
- DaylightWebUtil.auditlog("Ports to Subnet Gateway", userName, "added", ports, containerName);
+ resultBean.setMessage("Added ports to subnet gateway address successfully");
+ for (String port : toAdd) {
+ DaylightWebUtil.auditlog("Port", userName, "added",
+ DaylightWebUtil.getPortName(NodeConnector.fromString(port), switchManager)
+ + " to Subnet Gateway " + portsName, containerName);
+ }
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
@RequestMapping(value = "/subnetGateway/ports/delete", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean deleteSubnetGatewayPort(
- @RequestParam("gatewayName") String gatewayName,
- @RequestParam("nodePort") String nodePort,
- HttpServletRequest request,
+ public StatusJsonBean deleteSubnetGatewayPort(@RequestParam("gatewayName") String gatewayName,
+ @RequestParam("nodePort") String nodePort, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
List<String> toRemove = new ArrayList<String>();
for (String port : nodePort.split(",")) {
toRemove.add(port);
if (result.isSuccess()) {
resultBean.setStatus(true);
resultBean.setMessage("Deleted port from subnet gateway address successfully");
- DaylightWebUtil.auditlog("Ports from Subnet Gateway", userName, "removed", nodePort, containerName);
+ for (String port : toRemove) {
+ DaylightWebUtil.auditlog("Port", userName, "removed",
+ DaylightWebUtil.getPortName(NodeConnector.fromString(port), switchManager)
+ + " from Subnet Gateway " + gatewayName, containerName);
+ }
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
@RequestMapping(value = "/spanPorts", method = RequestMethod.GET)
@ResponseBody
- public DevicesJsonBean getSpanPorts(HttpServletRequest request,
- @RequestParam(required = false) String container) {
+ public DevicesJsonBean getSpanPorts(HttpServletRequest request, @RequestParam(required = false) String container) {
Gson gson = new Gson();
List<Map<String, String>> spanConfigs = new ArrayList<Map<String, String>>();
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
- Privilege privilege = DaylightWebUtil.getContainerPrivilege(
- userName, containerName, this);
+ Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
if (privilege != Privilege.NONE) {
List<String> spanConfigs_json = new ArrayList<String>();
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
if (switchManager != null) {
for (SpanConfig conf : switchManager.getSpanConfigList()) {
spanConfigs_json.add(gson.toJson(conf));
for (String config_json : spanConfigs_json) {
try {
@SuppressWarnings("unchecked")
- Map<String, String> config_data = mapper.readValue(config_json,
- HashMap.class);
+ Map<String, String> config_data = mapper.readValue(config_json, HashMap.class);
Map<String, String> config = new HashMap<String, String>();
for (String name : config_data.keySet()) {
config.put(name, config_data.get(name));
// Add switch portName value (non-configuration field)
- config.put("nodeName",
- getNodeDesc(config_data.get("nodeId"), containerName));
+ config.put("nodeName", getNodeDesc(config_data.get("nodeId"), containerName));
NodeConnector spanPortNodeConnector = NodeConnector.fromString(config_data.get("spanPort"));
Name ncName = ((Name) switchManager.getNodeConnectorProp(spanPortNodeConnector,
Name.NamePropName));
return null;
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
return null;
}
Set<NodeConnector> nodeConnectorSet = node.getNodeConnectors();
if (nodeConnectorSet != null) {
for (NodeConnector nodeConnector : nodeConnectorSet) {
- String nodeConnectorName = ((Name) switchManager
- .getNodeConnectorProp(nodeConnector, Name.NamePropName)).getValue();
- port.add(new PortJsonBean(nodeConnector.getID().toString(), nodeConnectorName, nodeConnector.toString()));
+ String nodeConnectorName = ((Name) switchManager.getNodeConnectorProp(nodeConnector,
+ Name.NamePropName)).getValue();
+ port.add(new PortJsonBean(nodeConnector.getID().toString(), nodeConnectorName, nodeConnector
+ .toString()));
}
}
nodeJsonBean.setNodeId(node.getNode().toString());
@RequestMapping(value = "/spanPorts/add", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean addSpanPort(
- @RequestParam("jsonData") String jsonData,
- HttpServletRequest request,
+ public StatusJsonBean addSpanPort(@RequestParam("jsonData") String jsonData, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
Gson gson = new Gson();
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
SpanConfig cfgObject = gson.fromJson(jsonData, SpanConfig.class);
Status result = switchManager.addSpanConfig(cfgObject);
if (result.isSuccess()) {
resultBean.setStatus(true);
resultBean.setMessage("SPAN Port added successfully");
- DaylightWebUtil.auditlog("SPAN Port", userName, "added", cfgObject.getNodeId(), containerName);
+ DaylightWebUtil.auditlog("SPAN Port", userName, "added",
+ DaylightWebUtil.getPortName(NodeConnector.fromString(cfgObject.getSpanPort()), switchManager),
+ containerName);
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
}
} catch (Exception e) {
resultBean.setStatus(false);
- resultBean.setMessage("Error occurred while adding span port. "
- + e.getMessage());
+ resultBean.setMessage("Error occurred while adding span port. " + e.getMessage());
}
return resultBean;
}
@RequestMapping(value = "/spanPorts/delete", method = RequestMethod.GET)
@ResponseBody
- public StatusJsonBean deleteSpanPorts(
- @RequestParam("spanPortsToDelete") String spanPortsToDelete,
- HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public StatusJsonBean deleteSpanPorts(@RequestParam("spanPortsToDelete") String spanPortsToDelete,
+ HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
StatusJsonBean resultBean = new StatusJsonBean();
try {
Gson gson = new Gson();
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
- Type collectionType = new TypeToken<List<SpanPortJsonBean>>() {}.getType();
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
+ Type collectionType = new TypeToken<List<SpanPortJsonBean>>() {
+ }.getType();
List<SpanPortJsonBean> jsonBeanList = gson.fromJson(spanPortsToDelete, collectionType);
for (SpanPortJsonBean jsonBean : jsonBeanList) {
- SpanConfig cfgObject = gson
- .fromJson(gson.toJson(jsonBean), SpanConfig.class);
+ SpanConfig cfgObject = gson.fromJson(gson.toJson(jsonBean), SpanConfig.class);
Status result = switchManager.removeSpanConfig(cfgObject);
if (!result.isSuccess()) {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
break;
}
- DaylightWebUtil.auditlog("SPAN Port", userName, "removed", cfgObject.getNodeId(), containerName);
+ DaylightWebUtil.auditlog("SPAN Port", userName, "removed",
+ DaylightWebUtil.getPortName(NodeConnector.fromString(cfgObject.getSpanPort()), switchManager),
+ containerName);
}
resultBean.setStatus(true);
resultBean.setMessage("SPAN Port(s) deleted successfully");
} catch (Exception e) {
resultBean.setStatus(false);
- resultBean.setMessage("Error occurred while deleting span port. "
- + e.getMessage());
+ resultBean.setMessage("Error occurred while deleting span port. " + e.getMessage());
}
return resultBean;
}
private String getNodeDesc(String nodeId, String containerName) {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
String description = "";
if (switchManager != null) {
- Description desc = (Description) switchManager.getNodeProp(Node.fromString(nodeId), Description.propertyName);
- if(desc != null) {
+ Description desc = (Description) switchManager.getNodeProp(Node.fromString(nodeId),
+ Description.propertyName);
+ if (desc != null) {
description = desc.getValue();
}
}
- return (description.isEmpty() || description.equalsIgnoreCase("none")) ? nodeId
- : description;
+ return (description.isEmpty() || description.equalsIgnoreCase("none")) ? nodeId : description;
}
private StatusJsonBean unauthorizedMessage() {
}
@RequestMapping(value = "login")
- public String login(final HttpServletRequest request,
- final HttpServletResponse response) {
+ public String login(final HttpServletRequest request, final HttpServletResponse response) {
// response.setHeader("X-Page-Location", "/login");
/*
* IUserManager userManager = (IUserManager) ServiceHelper
return "forward:" + "/";
}
-}
+}
\ No newline at end of file
@RequestMapping(value = "/main")
@ResponseBody
- public Map<String, Object> getFlows(HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public Map<String, Object> getFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
- Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName,
- containerName, this);
+ Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
if (privilege == Privilege.NONE) {
return null;
}
// fetch frm
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, containerName, this);
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
+ IForwardingRulesManager.class, containerName, this);
if (frm == null) {
return null;
}
// fetch sm
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
return null;
}
@RequestMapping(value = "/node-ports")
@ResponseBody
- public Map<String, Object> getNodePorts(HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public Map<String, Object> getNodePorts(HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
return null;
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
return null;
}
if (nodeConnectorSet != null) {
for (NodeConnector nodeConnector : nodeConnectorSet) {
- String nodeConnectorName = ((Name) switchManager
- .getNodeConnectorProp(nodeConnector,
- Name.NamePropName)).getValue();
- port.put((Short) nodeConnector.getID(), nodeConnectorName
- + "(" + nodeConnector.getNodeConnectorIDString()
- + ")");
+ String nodeConnectorName = ((Name) switchManager.getNodeConnectorProp(nodeConnector,
+ Name.NamePropName)).getValue();
+ port.put((Short) nodeConnector.getID(),
+ nodeConnectorName + "(" + nodeConnector.getNodeConnectorIDString() + ")");
}
}
@RequestMapping(value = "/node-flows")
@ResponseBody
- public Map<String, Object> getNodeFlows(HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public Map<String, Object> getNodeFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
return null;
}
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
if (switchManager == null) {
return null;
}
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, containerName, this);
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
+ IForwardingRulesManager.class, containerName, this);
if (frm == null) {
return null;
}
List<FlowConfig> flows = frm.getStaticFlows(node);
String nodeDesc = node.toString();
- SwitchConfig config = switchManager
- .getSwitchConfig(node.toString());
- if ((config != null)
- && (config.getProperty(Description.propertyName) != null)) {
- nodeDesc = ((Description) config
- .getProperty(Description.propertyName)).getValue();
+ SwitchConfig config = switchManager.getSwitchConfig(node.toString());
+ if ((config != null) && (config.getProperty(Description.propertyName) != null)) {
+ nodeDesc = ((Description) config.getProperty(Description.propertyName)).getValue();
}
nodes.put(nodeDesc, flows.size());
@RequestMapping(value = "/flow", method = RequestMethod.POST)
@ResponseBody
- public String actionFlow(@RequestParam(required = true) String action,
- @RequestParam(required = false) String body,
- @RequestParam(required = true) String nodeId,
- HttpServletRequest request,
+ public String actionFlow(@RequestParam(required = true) String action, @RequestParam(required = false) String body,
+ @RequestParam(required = true) String nodeId, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return "Operation not authorized";
}
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, containerName, this);
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
+ IForwardingRulesManager.class, containerName, this);
if (frm == null) {
return null;
}
Node node = Node.fromString(nodeId);
flow.setNode(node);
+
Status result = new Status(StatusCode.BADREQUEST, "Invalid request");
if (action.equals("add")) {
result = frm.addStaticFlow(flow);
- DaylightWebUtil.auditlog("Flow", userName, "added", flow.getName(),
- containerName);
+ if (result.isSuccess()) {
+ DaylightWebUtil.auditlog("Flow Entry", userName, "added", flow.getName() + " on Node "
+ + DaylightWebUtil.getNodeDesc(node, containerName, this), containerName);
+ }
}
- return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result
- .getDescription();
+ return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result.getDescription();
}
@RequestMapping(value = "/flow/{nodeId}/{name:.*}", method = RequestMethod.POST)
@ResponseBody
- public String removeFlow(@PathVariable("nodeId") String nodeId,
- @PathVariable("name") String name,
- @RequestParam(required = true) String action,
- HttpServletRequest request,
+ public String removeFlow(@PathVariable("nodeId") String nodeId, @PathVariable("name") String name,
+ @RequestParam(required = true) String action, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return "Operation not authorized";
}
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, containerName, this);
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
+ IForwardingRulesManager.class, containerName, this);
if (frm == null) {
return null;
}
if (action.equals("remove")) {
result = frm.removeStaticFlow(name, node);
if (result.isSuccess()) {
- DaylightWebUtil.auditlog("Flow", userName, "removed", name,
- containerName);
+ DaylightWebUtil.auditlog("Flow Entry", userName, "removed",
+ name + " on Node " + DaylightWebUtil.getNodeDesc(node, containerName, this), containerName);
}
} else if (action.equals("toggle")) {
result = frm.toggleStaticFlowStatus(name, node);
if (result.isSuccess()) {
- DaylightWebUtil.auditlog("Flow", userName, "toggled", name,
- containerName);
+ DaylightWebUtil.auditlog("Flow Entry", userName, "toggled",
+ name + " on Node " + DaylightWebUtil.getNodeDesc(node, containerName, this), containerName);
}
} else {
result = new Status(StatusCode.BADREQUEST, "Unknown action");
}
- return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result
- .getDescription();
+ return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result.getDescription();
}
@SuppressWarnings("unchecked")
@RequestMapping(value = "/flow/deleteFlows", method = RequestMethod.POST)
@ResponseBody
- public String removeSelectedFlows(
- @RequestParam(required = false) String body,
- HttpServletRequest request,
+ public String removeSelectedFlows(@RequestParam(required = false) String body, HttpServletRequest request,
@RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil
- .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return "Operation not authorized";
}
-
- IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
- .getInstance(IForwardingRulesManager.class, containerName, this);
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper.getInstance(
+ IForwardingRulesManager.class, containerName, this);
if (frm == null) {
return "Forwarding Rules Manager is not available";
}
Node node = Node.fromString(flowEntry.get("node"));
result = frm.removeStaticFlow(flowEntry.get("name"), node);
if (result.isSuccess()) {
- DaylightWebUtil.auditlog("Flow", userName, "removed",
- flowEntry.get("name"), containerName);
+ DaylightWebUtil.auditlog("Flow Entry", userName, "removed", flowEntry.get("name") + " on Node "
+ + DaylightWebUtil.getNodeDesc(node, containerName, this), containerName);
} else {
status = flowEntry.get("name") + ", " + status;
}
}
if (!status.equals("")) {
- return "Could not remove "
- + status.substring(0, status.length() - 2) + " Flow(s)";
+ return "Could not remove " + status.substring(0, status.length() - 2) + " Flow(s)";
} else {
return "Success";
}
}
private String getNodeDesc(Node node, ISwitchManager switchManager) {
- Description desc = (Description) switchManager.getNodeProp(node,
- Description.propertyName);
+ Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName);
String description = (desc == null) ? "" : desc.getValue();
- return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node
- .toString() : description;
+ return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node.toString() : description;
}
}
/**
* Returns list of clustered controllers. Highlights "this" controller and
* if controller is coordinator
+ *
* @return List<ClusterBean>
*/
@RequestMapping("/cluster")
for (InetAddress controller : controllers) {
ClusterNodeBean.Builder clusterBeanBuilder = new ClusterNodeBean.Builder(controller);
- //get number of connected nodes
+ // get number of connected nodes
Set<Node> connectedNodes = connectionManager.getNodes(controller);
int numNodes = connectedNodes == null ? 0 : connectedNodes.size();
clusterBeanBuilder.nodesConnected(numNodes);
- //determine if this is the executing controller
+ // determine if this is the executing controller
if (controller.equals(clusterServices.getMyAddress())) {
clusterBeanBuilder.highlightMe();
}
- //determine whether this is coordinator
+ // determine whether this is coordinator
if (clusterServices.getCoordinatorAddress().equals(controller)) {
clusterBeanBuilder.iAmCoordinator();
}
/**
* Return nodes connected to controller {controller}
+ *
* @param controller
* - byte[] of the address of the controller
* @return List<NodeBean>
Status result = (action.equals("add")) ? userManager.addLocalUser(config) : userManager.removeLocalUser(config);
if (result.isSuccess()) {
String userAction = (action.equals("add")) ? "added" : "removed";
- DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), userAction, config.getUser());
+ if (action.equals("add")) {
+ String userRoles = "";
+ for (String userRole : config.getRoles()) {
+ userRoles = userRoles + userRole + ",";
+ }
+ DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), userAction, config.getUser()
+ + " as " + userRoles.substring(0, userRoles.length() - 1));
+ } else {
+ DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), userAction, config.getUser());
+ }
return "Success";
}
return result.getDescription();
}
if (status.isSuccess()) {
- DaylightWebUtil.auditlog("User", requestingUser, "changed password for", username);
+ DaylightWebUtil.auditlog("User", request.getUserPrincipal().getName(), " changed password for User ",
+ username);
}
return status;
}
/**
* Is the operation permitted for the given level
+ *
* @param level
*/
private boolean authorize(IUserManager userManager, UserLevel level, HttpServletRequest request) {
import org.opendaylight.controller.containermanager.IContainerAuthorization;
import org.opendaylight.controller.sal.authorization.Privilege;
+import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.Name;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
import org.opendaylight.controller.sal.utils.GlobalConstants;
import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
import org.opendaylight.controller.usermanager.IUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public static void auditlog(String moduleName, String user, String action, String resource) {
auditlog(moduleName, user, action, resource, null);
}
+
+ public static String getNodeDesc(Node node, ISwitchManager switchManager) {
+ Description desc = (Description) switchManager.getNodeProp(node,
+ Description.propertyName);
+ String description = (desc == null) ? "" : desc.getValue();
+ return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node
+ .toString() : description;
+ }
+
+ public static String getNodeDesc(Node node, String containerName,
+ Object bundle) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper
+ .getInstance(ISwitchManager.class, containerName, bundle);
+ if (switchManager == null) {
+ return null;
+ }
+
+ return getNodeDesc(node, switchManager);
+ }
+
+ public static String getNodeDesc(Node node, Object bundle) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper
+ .getInstance(ISwitchManager.class,
+ GlobalConstants.DEFAULT.toString(), bundle);
+ if (switchManager == null) {
+ return null;
+ }
+
+ return getNodeDesc(node, switchManager);
+ }
+
+ public static String getPortName(NodeConnector nodeConnector,
+ String container, Object bundle) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper
+ .getInstance(ISwitchManager.class, container, bundle);
+ return getPortName(nodeConnector, switchManager);
+ }
+
+ public static String getPortName(NodeConnector nodeConnector, Object bundle) {
+ return getPortName(nodeConnector, GlobalConstants.DEFAULT.toString(), bundle);
+ }
+
+ public static String getPortName(NodeConnector nodeConnector,
+ ISwitchManager switchManager) {
+ Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector,
+ Name.NamePropName));
+ String nodeConnectorName = (ncName != null) ? ncName.getValue() : nodeConnector.getNodeConnectorIdAsString();
+ nodeConnectorName = nodeConnectorName + "@"
+ + getNodeDesc(nodeConnector.getNode(), switchManager);
+ return nodeConnectorName.substring(0, nodeConnectorName.length());
+ }
}
\ No newline at end of file