<netconf.version>0.2.2-SNAPSHOT</netconf.version>
<mdsal.version>1.0-SNAPSHOT</mdsal.version>
<containermanager.version>0.5.1-SNAPSHOT</containermanager.version>
- <switchmanager.api.version>0.5.1-SNAPSHOT</switchmanager.api.version>
+ <switchmanager.api.version>0.6.1-SNAPSHOT</switchmanager.api.version>
<connectionmanager.version>0.1.1-SNAPSHOT</connectionmanager.version>
<sal.version>0.6.0-SNAPSHOT</sal.version>
<sal.networkconfiguration.version>0.0.2-SNAPSHOT</sal.networkconfiguration.version>
<artifactId>usermanager.northbound</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>controllermanager.northbound</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </dependency>
<!-- Debug and logging -->
<dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
--- /dev/null
+<?xml version="1.0"?>
+<enunciate label="full" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
+
+ <services>
+ <rest defaultRestSubcontext="/controller/nb/v2/controllermanager"/>
+ </services>
+
+ <modules>
+ <docs docsDir="rest" title="Controller Manager REST API" includeExampleXml="true" includeExampleJson="true"/>
+ </modules>
+</enunciate>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.opendaylight</artifactId>
+ <version>1.4.1-SNAPSHOT</version>
+ <relativePath>../../commons/opendaylight</relativePath>
+ </parent>
+ <artifactId>controllermanager.northbound</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <scm>
+ <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+ <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+ <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+ <tag>HEAD</tag>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.enunciate</groupId>
+ <artifactId>maven-enunciate-plugin</artifactId>
+ <version>${enunciate.version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.5.1-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Import-Package>
+ org.opendaylight.controller.sal.core,
+ org.opendaylight.controller.sal.utils,
+ org.opendaylight.controller.containermanager,
+ org.opendaylight.controller.switchmanager,
+ org.opendaylight.controller.usermanager,
+ org.apache.commons.lang3.tuple,
+ org.apache.commons.logging,
+ com.sun.jersey.spi.container.servlet,
+ org.opendaylight.controller.northbound.commons,
+ org.opendaylight.controller.northbound.commons.exception,
+ org.opendaylight.controller.northbound.commons.utils,
+ org.opendaylight.controller.sal.authorization,
+ javax.ws.rs,
+ javax.ws.rs.core,
+ javax.xml.bind.annotation,
+ javax.xml.bind,
+ org.slf4j,
+ org.apache.catalina.filters,
+ org.codehaus.jackson.jaxrs,
+ org.codehaus.jackson.annotate,
+ !org.codehaus.enunciate.jaxrs
+ </Import-Package>
+ <Web-ContextPath>/controller/nb/v2/controllermanager</Web-ContextPath>
+ <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
+ </instructions>
+ <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller.thirdparty</groupId>
+ <artifactId>com.sun.jersey.jersey-servlet</artifactId>
+ <version>1.18-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>containermanager</artifactId>
+ <version>0.5.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.5.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.northbound</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.enunciate</groupId>
+ <artifactId>enunciate-core-annotations</artifactId>
+ <version>${enunciate.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller.thirdparty</groupId>
+ <artifactId>org.apache.catalina.filters.CorsFilter</artifactId>
+ <version>7.0.43-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.controllermanager.northbound;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
+import javax.ws.rs.core.UriInfo;
+
+import org.codehaus.enunciate.jaxrs.ResponseCode;
+import org.codehaus.enunciate.jaxrs.StatusCodes;
+import org.codehaus.enunciate.jaxrs.TypeHint;
+import org.opendaylight.controller.containermanager.IContainerManager;
+import org.opendaylight.controller.northbound.commons.RestMessages;
+import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
+import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
+import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
+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.Property;
+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.switchmanager.ISwitchManager;
+
+/**
+ * The class provides Northbound REST APIs to manager the controller. Currently
+ * it supports getting controller property(ies), setting a property, and
+ * removing a property
+ *
+ */
+
+@Path("/")
+public class ControllerManagerNorthbound {
+
+ private String username;
+
+ @Context
+ public void setSecurityContext(SecurityContext context) {
+ if (context != null && context.getUserPrincipal() != null) {
+ username = context.getUserPrincipal().getName();
+ }
+ }
+
+ protected String getUserName() {
+ return username;
+ }
+
+ private ISwitchManager getISwitchManagerService(String containerName) {
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+ this);
+
+ if (switchManager == null) {
+ throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+
+ return switchManager;
+ }
+
+ /**
+ * Retrieve a property or all properties for the controller in the network
+ *
+ * @param containerName
+ * Name of the Container (Eg. 'default')
+ * @param propertyName
+ * Name of the Property specified by
+ * {@link org.opendaylight.controller.sal.core.Property} and its
+ * extended classes
+ *
+ * Example:
+ *
+ * Request URL:
+ * http://localhost:8080/controller/nb/v2/controllermanager/default/properties/?propertyName=macAddress
+ *
+ * Response Body in XML:
+ * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+ * <controllerProperties>
+ * <properties>
+ * <macAddress>
+ * <value>3e:04:ef:11:13:80</value>
+ * </macAddress>
+ * </properties>
+ * </controllerProperties>
+ *
+ * Response Body in JSON:
+ * { "controllerProperties":
+ * {"properties":
+ * { "macAddress":
+ * { "value": "3e:04:ef:11:13:80" }
+ * }
+ * }
+ * }
+ *
+ */
+ @Path("/{containerName}/properties/")
+ @GET
+ @TypeHint(Property.class)
+ @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 or property is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public ControllerProperties getControllerProperties(@PathParam("containerName") String containerName,
+ @QueryParam("propertyName") String propertyName) {
+
+ 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);
+ }
+
+ ISwitchManager switchManager = getISwitchManagerService(containerName);
+
+ if (propertyName == null) {
+ Map<String, Property> propertyMap = switchManager.getControllerProperties();
+ Set<Property> properties = new HashSet<Property>(propertyMap.values());
+ return new ControllerProperties(properties);
+ }
+
+ Set<Property> properties = new HashSet<Property>();
+ Property property = switchManager.getControllerProperty(propertyName);
+ if (property == null) {
+ throw new ResourceNotFoundException("Unable to find property with name: " + propertyName);
+ }
+ properties.add(property);
+
+ return new ControllerProperties(properties);
+
+ }
+
+ /**
+ * Add a controller property to the controller. This method overrides
+ * previously set property values if the property already exist.
+ *
+ * @param containerName
+ * Name of the Container (Eg. 'default')
+ * @param propertyName
+ * Name of the Property specified by
+ * {@link org.opendaylight.controller.sal.core.Property} and its
+ * extended classes
+ * @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
+ *
+ * Example:
+ *
+ * Request URL:
+ * http://localhost:8080/controller/nb/v2/controllermanager/default/properties/description/defaultController
+ */
+ @Path("/{containerName}/properties/{propertyName}/{propertyValue}")
+ @PUT
+ @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @StatusCodes({ @ResponseCode(code = 201, condition = "Operation successful"),
+ @ResponseCode(code = 400, condition = "Invalid property parameters"),
+ @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+ @ResponseCode(code = 404, condition = "The containerName or property is not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+ public Response setControllerProperty(@Context UriInfo uriInfo, @PathParam("containerName") String containerName,
+ @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.READ, this)) {
+ throw new UnauthorizedException("User is not authorized to perform this operation on container "
+ + containerName);
+ }
+
+ ISwitchManager switchManager = getISwitchManagerService(containerName);
+
+ Property prop = switchManager.createProperty(propertyName, propertyValue);
+ if (prop == null) {
+ throw new BadRequestException("Property with name " + propertyName + " cannot be created.");
+ }
+
+ Status status = switchManager.setControllerProperty(prop);
+
+ if (status.isSuccess()) {
+ NorthboundUtils.auditlog("Controller Property", username, "updated", propertyName);
+ return Response.created(uriInfo.getRequestUri()).build();
+ }
+ return NorthboundUtils.getResponse(status);
+ }
+
+ /**
+ * Delete a property of the controller
+ *
+ * @param containerName
+ * Name of the Container (Eg. 'default')
+ * @param propertyName
+ * Name 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
+ *
+ * Example:
+ *
+ * Request URL:
+ * http://localhost:8080/controller/nb/v2/controllermanager/default/properties/description
+ */
+ @Path("/{containerName}/properties/{propertyName}")
+ @DELETE
+ @StatusCodes({ @ResponseCode(code = 204, condition = "Property removed successfully"),
+ @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 Response removeControllerProperty(@PathParam("containerName") String containerName,
+ @PathParam("propertyName") String propertyName) {
+
+ 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);
+ }
+
+ ISwitchManager switchManager = getISwitchManagerService(containerName);
+
+ Status status = switchManager.removeControllerProperty(propertyName);
+
+ if (status.isSuccess()) {
+ NorthboundUtils.auditlog("Controller Property", username, "removed", propertyName);
+
+ return Response.noContent().build();
+ }
+ return NorthboundUtils.getResponse(status);
+ }
+
+ private boolean isValidContainer(String containerName) {
+ if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ return true;
+ }
+ IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(
+ IContainerManager.class, this);
+ if (containerManager == null) {
+ throw new ServiceUnavailableException("Container Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
+ }
+ if (containerManager.getContainerNames().contains(containerName)) {
+ return true;
+ }
+ return false;
+ }
+
+}
--- /dev/null
+package org.opendaylight.controller.controllermanager.northbound;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.opendaylight.controller.sal.core.Property;
+
+/**
+ * The class describes set of properties attached to a controller
+ */
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class ControllerProperties {
+
+ @XmlElementRef
+ @XmlElementWrapper
+ @JsonIgnore
+ /**
+ * Set to store the controller properties
+ */
+ private Set<Property> properties;
+
+ // JAXB required constructor
+ private ControllerProperties() {
+ this.properties = null;
+ }
+
+ public ControllerProperties(Set<Property> properties) {
+ this.properties = properties;
+ }
+
+ @JsonProperty(value="properties")
+ public Map<String, Property> getMapProperties() {
+ Map<String, Property> map = new HashMap<String, Property>();
+ for (Property p : properties) {
+ map.put(p.getName(), p);
+ }
+ return map;
+ }
+
+ public void setMapProperties(Map<String, Property> propertiesMap) {
+ this.properties = new HashSet<Property>(propertiesMap.values());
+ }
+
+ public Set<Property> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Set<Property> properties) {
+ this.properties = properties;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>JAXRSSwitchManager</servlet-name>
+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAXRSSwitchManager</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+ <filter>
+ <filter-name>CorsFilter</filter-name>
+ <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
+ <init-param>
+ <param-name>cors.allowed.origins</param-name>
+ <param-value>*</param-value>
+ </init-param>
+ <init-param>
+ <param-name>cors.allowed.methods</param-name>
+ <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
+ </init-param>
+ <init-param>
+ <param-name>cors.allowed.headers</param-name>
+ <param-value>Content-Type,X-Requested-With,accept,authorization, origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
+ </init-param>
+ <init-param>
+ <param-name>cors.exposed.headers</param-name>
+ <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
+ </init-param>
+ <init-param>
+ <param-name>cors.support.credentials</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <init-param>
+ <param-name>cors.preflight.maxage</param-name>
+ <param-value>10</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>CorsFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>NB api</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
+ <http-method>PUT</http-method>
+ <http-method>PATCH</http-method>
+ <http-method>DELETE</http-method>
+ <http-method>HEAD</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>System-Admin</role-name>
+ <role-name>Network-Admin</role-name>
+ <role-name>Network-Operator</role-name>
+ <role-name>Container-User</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <security-role>
+ <role-name>System-Admin</role-name>
+ </security-role>
+ <security-role>
+ <role-name>Network-Admin</role-name>
+ </security-role>
+ <security-role>
+ <role-name>Network-Operator</role-name>
+ </security-role>
+ <security-role>
+ <role-name>Container-User</role-name>
+ </security-role>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>opendaylight</realm-name>
+ </login-config>
+</web-app>
\ No newline at end of file
--- /dev/null
+package org.opendaylight.controller.controllermanager.northbound;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.Property;
+
+public class ControllerManagerNorthboundTest extends TestCase {
+
+ @Test
+ public void testControllerProperties() {
+ ControllerProperties controllerProperties = new ControllerProperties(null);
+ Assert.assertTrue(controllerProperties.getProperties() == null);
+
+ Set<Property> properties = new HashSet<Property>();
+ controllerProperties.setProperties(properties);
+ Assert.assertTrue(controllerProperties.getProperties().equals(properties));
+ }
+
+}
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
</scm>
<artifactId>switchmanager</artifactId>
- <version>0.5.1-SNAPSHOT</version>
+ <version>0.6.1-SNAPSHOT</version>
<packaging>bundle</packaging>
<properties>
*/
@Deprecated
public String getNodeDescription(Node node);
+
+ /**
+ * Return all the properties of the controller
+ *
+ * @return map of {@link org.opendaylight.controller.sal.core.Property} such
+ * as {@link org.opendaylight.controller.sal.core.Description}
+ * and/or {@link org.opendaylight.controller.sal.core.Tier} etc.
+ */
+ public Map<String, Property> getControllerProperties();
+
+ /**
+ * Return a specific property of the controller given the property name
+ *
+ * @param propName
+ * the property name specified by
+ * {@link org.opendaylight.controller.sal.core.Property} and its
+ * extended classes
+ * @return {@link org.opendaylight.controller.sal.core.Property}
+ */
+ public Property getControllerProperty(String propertyName);
+
+ /**
+ * Set a specific property of the controller
+ *
+ * @param property
+ * {@link org.opendaylight.controller.sal.core.Property}
+ * @return
+ */
+ public Status setControllerProperty(Property property);
+
+ /**
+ * Remove a property of a node
+ *
+ * @param propertyName
+ * the property name specified by
+ * {@link org.opendaylight.controller.sal.core.Property} and its
+ * extended classes
+ * @return success or failed reason
+ */
+ public Status removeControllerProperty(String propertyName);
}
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
@Override
public Set<Node> getNodes() {
- return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet())
- : new HashSet<Node>();
+ return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet()) : new HashSet<Node>();
+ }
+
+ @Override
+ public Map<String, Property> getControllerProperties() {
+ return new HashMap<String, Property>(this.controllerProps);
+ }
+
+ @Override
+ public Property getControllerProperty(String propertyName) {
+ if (propertyName != null) {
+ HashMap<String, Property> propertyMap = new HashMap<String, Property>(this.controllerProps);
+ return propertyMap.get(propertyName);
+ }
+ return null;
+ }
+
+ @Override
+ public Status setControllerProperty(Property property) {
+ if (property != null) {
+ this.controllerProps.put(property.getName(), property);
+ return new Status(StatusCode.SUCCESS);
+ }
+ return new Status(StatusCode.BADREQUEST, "Invalid property provided when setting property");
+ }
+
+ @Override
+ public Status removeControllerProperty(String propertyName) {
+ if (propertyName != null) {
+ if (this.controllerProps.containsKey(propertyName)) {
+ this.controllerProps.remove(propertyName);
+ if (!this.controllerProps.containsKey(propertyName)) {
+ return new Status(StatusCode.SUCCESS);
+ }
+ }
+ String msg = "Unable to remove property " + propertyName + " from Controller";
+ return new Status(StatusCode.BADREQUEST, msg);
+ }
+ String msg = "Invalid property provided when removing property from Controller";
+ return new Status(StatusCode.BADREQUEST, msg);
}
/*
}
/**
- * Creates a Name/Tier/Bandwidth Property object based on given property
- * name and value. Other property types are not supported yet.
+ * Creates a Name/Tier/Bandwidth/MacAddress(controller property) Property
+ * object based on given property name and value. Other property types are
+ * not supported yet.
*
* @param propName
* Name of the Property
} else if (propName.equalsIgnoreCase(ForwardingMode.name)) {
int mode = Integer.parseInt(propValue);
return new ForwardingMode(mode);
- } else {
+ } else if (propName.equalsIgnoreCase(MacAddress.name)){
+ return new MacAddress(propValue);
+ }
+ else {
log.debug("Not able to create {} property", propName);
}
} catch (Exception e) {
return null;
}
+
@SuppressWarnings("deprecation")
@Override
public String getNodeDescription(Node node) {
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>switchmanager</artifactId>
+ <version>0.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<module>opendaylight/northbound/jolokia</module>
<module>opendaylight/northbound/connectionmanager</module>
<module>opendaylight/northbound/usermanager</module>
+ <module>opendaylight/northbound/controllermanager</module>
<!-- Northbound integration tests -->
<module>opendaylight/northbound/integrationtest</module>