</scm>
<properties>
- <yangtools.version>0.6.2-SNAPSHOT</yangtools.version>
- <yangtools.generator.version>0.6.2-SNAPSHOT</yangtools.generator.version>
<yangtools.binding.version>0.6.2-SNAPSHOT</yangtools.binding.version>
</properties>
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>${yangtools.version}</version>
<executions>
<execution>
<goals>
<url>https://wiki.opendaylight.org/view/Openflow_Protocol_Library:Main</url>
<tag>HEAD</tag>
</scm>
+
+ <properties>
+ <yangtools.version>0.6.2-SNAPSHOT</yangtools.version>
+ <yangtools.generator.version>0.6.2-SNAPSHOT</yangtools.generator.version>
+ <yangtools.binding.version>0.6.2-SNAPSHOT</yangtools.binding.version>
+ </properties>
<build>
<plugins>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-Activator>
- org.opendaylight.openflowjava.protocol.impl.connection.Activator
- </Bundle-Activator>
- <Export-Package>org.opendaylight.openflowjava.protocol.impl.*</Export-Package>
- </instructions>
- </configuration>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.opendaylight.openflowjava.protocol.impl.*,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.*
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ </codeGeneratorClass>
+ <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+ <additionalConfiguration>
+ <namespaceToPackage1>
+ urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
+ </namespaceToPackage1>
+ </additionalConfiguration>
+ </generator>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
+ </codeGeneratorClass>
+ <outputBaseDir>${project.build.directory}/generated-sources/sal</outputBaseDir>
+ </generator>
+ <generator>
+ <codeGeneratorClass>org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl</codeGeneratorClass>
+ <outputBaseDir>${project.build.directory}/site/models</outputBaseDir>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-jmx-generator-plugin</artifactId>
+ <version>${config.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>maven-sal-api-gen-plugin</artifactId>
+ <version>${yangtools.generator.version}</version>
+ <type>jar</type>
+ </dependency>
+ </dependencies>
</plugin>
</plugins>
</build>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ <version>0.2.5-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
+++ /dev/null
-/*
- * Copyright (c) 2013 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.connection;
-
-import java.util.Hashtable;
-
-import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Activates library bundle, exposes provided implementations:
- * <ul>
- * <li>{@link SwitchConnectionProviderImpl}</li>
- * </ul>
- *
- * @author mirehak
- */
-public class Activator implements BundleActivator {
-
- private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
-
- @Override
- public void start(BundleContext context) throws Exception {
- LOG.debug("starting OF Library");
- Hashtable<String, String> props = new Hashtable<>();
- props.put("type", "default");
- context.registerService(
- SwitchConnectionProvider.class.getName(),
- new SwitchConnectionProviderImpl(), props);
- LOG.debug("started OF Library");
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- LOG.debug("stopping OF Library");
- //TODO:: add teardown activities (check, if servers are running, stop if necessary..)
- }
-}
package org.opendaylight.openflowjava.protocol.impl.connection;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
import java.util.concurrent.Future;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
private static final Logger LOGGER = LoggerFactory
.getLogger(SwitchConnectionProviderImpl.class);
private SwitchConnectionHandler switchConnectionHandler;
- private Set<ServerFacade> serverLot;
+ private ServerFacade serverFacade;
+ private ConnectionConfiguration connConfig;
@Override
- public void configure(Collection<ConnectionConfiguration> connConfigs) {
- LOGGER.debug("Configuring ..");
-
- //TODO - configure servers according to configuration
- serverLot = new HashSet<>();
- for (ConnectionConfiguration connConfig : connConfigs) {
- TcpHandler server = new TcpHandler(connConfig.getAddress(), connConfig.getPort());
- server.setSwitchConnectionHandler(switchConnectionHandler);
- server.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
- boolean tlsSupported = FEATURE_SUPPORT.REQUIRED.equals(connConfig.getTlsSupport());
- server.setEncryption(tlsSupported);
- serverLot.add(server);
- }
+ public void setConfiguration(ConnectionConfiguration connConfig) {
+ this.connConfig = connConfig;
}
@Override
}
@Override
- public Future<List<Boolean>> shutdown() {
+ public ListenableFuture<Boolean> shutdown() {
LOGGER.debug("Shutdown summoned");
- ListenableFuture<List<Boolean>> result = SettableFuture.create();
- try {
- List<ListenableFuture<Boolean>> shutdownChain = new ArrayList<>();
- for (ServerFacade server : serverLot) {
- ListenableFuture<Boolean> shutdownFuture = server.shutdown();
- shutdownChain.add(shutdownFuture);
- }
- if (!shutdownChain.isEmpty()) {
- result = Futures.allAsList(shutdownChain);
- } else {
- throw new IllegalStateException("No servers configured");
- }
- } catch (Exception e) {
- SettableFuture<List<Boolean>> exFuture = SettableFuture.create();
- exFuture.setException(e);
- result = exFuture;
- }
+ //TODO: provide exception in case of: not started, not configured (already stopped)
+ ListenableFuture<Boolean> result = serverFacade.shutdown();
return result;
}
@Override
- public Future<List<Boolean>> startup() {
- LOGGER.debug("startup summoned");
- ListenableFuture<List<Boolean>> result = SettableFuture.create();
+ public ListenableFuture<Boolean> startup() {
+ LOGGER.debug("Startup summoned");
+ serverFacade = createAndConfigureServer();
+
+ LOGGER.debug("Starting ..");
+ ListenableFuture<Boolean> result = null;
try {
- if (serverLot.isEmpty()) {
- throw new IllegalStateException("No servers configured");
+ if (serverFacade == null) {
+ throw new IllegalStateException("No server configured");
}
- for (ServerFacade server : serverLot) {
- if (server.getIsOnlineFuture().isDone()) {
- throw new IllegalStateException("Servers already running");
- }
+ if (serverFacade.getIsOnlineFuture().isDone()) {
+ throw new IllegalStateException("Server already running");
}
if (switchConnectionHandler == null) {
throw new IllegalStateException("switchConnectionHandler is not set");
}
- List<ListenableFuture<Boolean>> starterChain = new ArrayList<>();
- for (ServerFacade server : serverLot) {
- new Thread(server).start();
- ListenableFuture<Boolean> isOnlineFuture = server.getIsOnlineFuture();
- starterChain.add(isOnlineFuture);
- }
- if (!starterChain.isEmpty()) {
- result = Futures.allAsList(starterChain);
- } else {
- throw new IllegalStateException("No servers configured");
- }
+ new Thread(serverFacade).start();
+ result = serverFacade.getIsOnlineFuture();
} catch (Exception e) {
- SettableFuture<List<Boolean>> exFuture = SettableFuture.create();
- exFuture.setException(e);
- result = exFuture;
+ SettableFuture<Boolean> exResult = SettableFuture.create();
+ exResult.setException(e);
+ result = exResult;
}
return result;
}
+ /**
+ * @return
+ */
+ private TcpHandler createAndConfigureServer() {
+ LOGGER.debug("Configuring ..");
+ TcpHandler server = new TcpHandler(connConfig.getAddress(), connConfig.getPort());
+ server.setSwitchConnectionHandler(switchConnectionHandler);
+ server.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
+ boolean tlsSupported = FEATURE_SUPPORT.REQUIRED.equals(connConfig.getTlsSupport());
+ server.setEncryption(tlsSupported);
+
+ return server;
+ }
+
/**
* @return servers
*/
- public Set<ServerFacade> getServerLot() {
- return serverLot;
+ public ServerFacade getServerFacade() {
+ return serverFacade;
}
+ @Override
+ public void close() throws Exception {
+ shutdown();
+ }
}
--- /dev/null
+/**
+* Generated file
+
+* Generated from: yang module name: openflow-switch-connection-provider-impl yang module local name: openflow-switch-connection-provider-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Mar 28 17:50:58 PDT 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
+import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+*
+*/
+public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
+ {
+
+ private static Logger LOG = LoggerFactory
+ .getLogger(SwitchConnectionProviderModule.class);
+
+ /**
+ * @param identifier
+ * @param dependencyResolver
+ */
+ public SwitchConnectionProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ super(identifier, dependencyResolver);
+ }
+
+ /**
+ * @param identifier
+ * @param dependencyResolver
+ * @param oldModule
+ * @param oldInstance
+ */
+ public SwitchConnectionProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ SwitchConnectionProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
+ super(identifier, dependencyResolver, oldModule, oldInstance);
+ }
+
+ @Override
+ protected void customValidation(){
+ // Add custom validation for module attributes here.
+ }
+
+ @Override
+ public java.lang.AutoCloseable createInstance() {
+ LOG.info("SwitchConnectionProvider started.");
+ SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
+ try {
+ ConnectionConfiguration connConfiguration = createConnectionConfiguration();
+ switchConnectionProviderImpl.setConfiguration(connConfiguration);
+ } catch (UnknownHostException e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ return switchConnectionProviderImpl;
+ }
+
+ /**
+ * @return
+ * @throws UnknownHostException
+ */
+ private ConnectionConfiguration createConnectionConfiguration() throws UnknownHostException {
+ final InetAddress address = extractIpAddressBin(getAddress());
+ final Integer port = getPort();
+ final long switchIdleTimeout = getSwitchIdleTimeout();
+
+ return new ConnectionConfiguration() {
+ @Override
+ public InetAddress getAddress() {
+ return address;
+ }
+ @Override
+ public int getPort() {
+ return port;
+ }
+ @Override
+ public Object getTransferProtocol() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public FEATURE_SUPPORT getTlsSupport() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ @Override
+ public long getSwitchIdleTimeout() {
+ return switchIdleTimeout;
+ }
+ @Override
+ public Object getSslContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+
+ /**
+ * @param address
+ * @return
+ * @throws UnknownHostException
+ */
+ private static InetAddress extractIpAddressBin(IpAddress address) throws UnknownHostException {
+ byte[] addressBin = null;
+ if (address != null) {
+ if (address.getIpv4Address() != null) {
+ addressBin = address2bin(address.getIpv4Address().getValue());
+ } else if (address.getIpv6Address() != null) {
+ addressBin = address2bin(address.getIpv6Address().getValue());
+ }
+ }
+
+ if (addressBin == null) {
+ return null;
+ } else {
+ return InetAddress.getByAddress(addressBin);
+ }
+ }
+
+ /**
+ * @param value
+ * @return
+ */
+ private static byte[] address2bin(String value) {
+ //TODO: translate ipv4 or ipv6 into byte[]
+ return null;
+ }
+}
--- /dev/null
+/**
+* Generated file
+
+* Generated from: yang module name: openflow-switch-connection-provider-impl yang module local name: openflow-switch-connection-provider-impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Fri Mar 28 17:50:58 PDT 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
+
+/**
+*
+*/
+public class SwitchConnectionProviderModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModuleFactory
+{
+
+
+}
--- /dev/null
+module openflow-switch-connection-provider-impl {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:openflow:switch:connection:provider:impl";
+ prefix "openflow-switch-connection-provider-impl";
+
+ import config {prefix config; revision-date 2013-04-05; }
+ import openflow-switch-connection-provider {prefix openflow-switch-connection-provider; revision-date 2014-03-28; }
+ import ietf-inet-types {prefix ietf-inet; revision-date 2010-09-24; }
+
+ description
+ "openflow-switch-connection-provider";
+
+ revision "2014-03-28" {
+ description
+ "Initial revision";
+ }
+
+ identity openflow-switch-connection-provider-impl {
+ base "config:module-type";
+ config:provided-service openflow-switch-connection-provider:openflow-switch-connection-provider;
+ config:java-name-prefix SwitchConnectionProvider;
+ }
+
+
+ augment "/config:modules/config:module/config:configuration" {
+ case openflow-switch-connection-provider-impl {
+ when "/config:modules/config:module/config:type = 'openflow-switch-connection-provider-impl'";
+
+ leaf port {
+ description "local listening port";
+ type uint16;
+ mandatory true;
+ }
+ leaf address {
+ description "address of local listening interface";
+ type ietf-inet:ip-address;
+ }
+ leaf switch-idle-timeout {
+ description "idle timeout in [ms]";
+ type uint32;
+ mandatory true;
+ }
+ leaf tls-support {
+ description "tls support enabled (requires SSL-context / keystore)";
+ type boolean;
+ default false;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module openflow-switch-connection-provider {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:openflow:switch:connection:provider";
+ prefix "openflow-switch-connection-provider";
+
+ import config {prefix config; revision-date 2013-04-05; }
+
+ description
+ "openflow-switch-connection-provider service definitions";
+
+ revision "2014-03-28" {
+ description
+ "Initial revision";
+ }
+
+ identity openflow-switch-connection-provider {
+ base "config:service-type";
+ config:java-class "org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider";
+ }
+}
\ No newline at end of file
private InetAddress startupAddress;
private MockPlugin mockPlugin;
private SwitchConnectionProviderImpl scpimpl;
- private List<ConnectionConfiguration> configs;
+ private TestingConnConfigImpl configs;
/**
* @throws Exception
mockPlugin = new MockPlugin();
scpimpl = new SwitchConnectionProviderImpl();
scpimpl.setSwitchConnectionHandler(mockPlugin);
- configs = new ArrayList<>();
- configs.add(new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT));
- scpimpl.configure(configs);
+ configs = new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT);
+ scpimpl.setConfiguration(configs);
scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- TcpHandler server = (TcpHandler) scpimpl.getServerLot().iterator().next();
+ TcpHandler server = (TcpHandler) scpimpl.getServerFacade();
port = server.getPort();
}
package org.opendaylight.openflowjava.protocol.spi.connection;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Future;
-
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
+import com.google.common.util.concurrent.ListenableFuture;
+
/**
* @author mirehak
* @author michal.polkorab
*
*/
-public interface SwitchConnectionProvider {
+public interface SwitchConnectionProvider extends AutoCloseable {
/**
- * @param configurations list of [protocol, port, address and supported features]
+ * @param configuration [protocol, port, address and supported features]
*/
- public void configure(Collection<ConnectionConfiguration> configurations);
+ void setConfiguration(ConnectionConfiguration configuration);
/**
* start listening to switches, but please don't forget to do
* {@link #setSwitchConnectionHandler(SwitchConnectionHandler)} first
- * @return future, triggered to true, when all listening channels are up and running
+ * @return future, triggered to true, when listening channel is up and running
*/
- public Future<List<Boolean>> startup();
+ ListenableFuture<Boolean> startup();
/**
* stop listening to switches
* @return future, triggered to true, when all listening channels are down
*/
- public Future<List<Boolean>> shutdown();
+ ListenableFuture<Boolean> shutdown();
/**
* @param switchConHandler instance being informed when new switch connects
*/
- public void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler);
+ void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler);
}
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowjava.git</developerConnection>
<url>https://wiki.opendaylight.org/view/Openflow_Protocol_Library:Main</url>
<tag>HEAD</tag>
- </scm>
+ </scm>
<properties>
<sonar.host.url>https://sonar.opendaylight.org/</sonar.host.url>
<guava.version>14.0.1</guava.version>
<netty.version>4.0.17.Final</netty.version>
<releaseplugin.version>2.3.2</releaseplugin.version>
+ <yangtools.version>0.6.2-SNAPSHOT</yangtools.version>
+ <yangtools.generator.version>0.6.2-SNAPSHOT</yangtools.generator.version>
+ <config.version>0.2.5-SNAPSHOT</config.version>
</properties>
<pluginRepositories>
<artifactId>maven-release-plugin</artifactId>
<version>${releaseplugin.version}</version>
</plugin>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <version>${yangtools.version}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ </plugin>
</plugins>
</pluginManagement>
</build>