package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
}
}
+ public void _controllerShowConnConfig(CommandInterpreter ci) {
+ String str = System.getProperty("secureChannelEnabled");
+ if ((str != null) && (str.trim().equalsIgnoreCase("true"))) {
+ ci.print("The Controller and Switch should communicate through TLS connetion.\n");
+
+ String keyStoreFile = System.getProperty("controllerKeyStore");
+ String trustStoreFile = System.getProperty("controllerTrustStore");
+ if ((keyStoreFile == null) || keyStoreFile.trim().isEmpty()) {
+ ci.print("controllerKeyStore not specified in ./configuration/config.ini\n");
+ } else {
+ ci.print("controllerKeyStore=" + keyStoreFile + "\n");
+ }
+ if ((trustStoreFile == null) || trustStoreFile.trim().isEmpty()) {
+ ci.print("controllerTrustStore not specified in ./configuration/config.ini\n");
+ } else {
+ ci.print("controllerTrustStore=" + trustStoreFile + "\n");
+ }
+ } else {
+ ci.print("The Controller and Switch should communicate through TCP connetion.\n");
+ }
+ }
+
private void registerWithOSGIConsole() {
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
.getBundleContext();
help.append("--Open Flow Controller --\n");
help.append("\tcontrollerShowSwitches\n");
help.append("\tcontrollerReset\n");
+ help.append("\tcontrollerShowConnConfig\n");
return help.toString();
}
}
newBuffer.put(outBuffer);
outBuffer = newBuffer;
}
+ }
+ synchronized (outBuffer) {
msg.writeTo(outBuffer);
if (!socket.isOpen()) {
package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousCloseException;
* @throws Exception
*/
private void createSecureChannel(SocketChannel socket) throws Exception {
- String keyStoreFile = System.getProperty("controllerKeyStore").trim();
- String keyStorePassword = System.getProperty("controllerKeyStorePassword").trim();
- String trustStoreFile = System.getProperty("controllerTrustStore").trim();
- String trustStorePassword = System.getProperty("controllerTrustStorePassword").trim();
-
+ String keyStoreFile = System.getProperty("controllerKeyStore");
+ String keyStorePassword = System.getProperty("controllerKeyStorePassword");
+ String trustStoreFile = System.getProperty("controllerTrustStore");
+ String trustStorePassword = System.getProperty("controllerTrustStorePassword");
+
+ if (keyStoreFile != null) {
+ keyStoreFile = keyStoreFile.trim();
+ }
+ if ((keyStoreFile == null) || keyStoreFile.isEmpty()) {
+ throw new FileNotFoundException("controllerKeyStore not specified in ./configuration/config.ini");
+ }
+ if (keyStorePassword != null) {
+ keyStorePassword = keyStorePassword.trim();
+ }
+ if ((keyStorePassword == null) || keyStorePassword.isEmpty()) {
+ throw new FileNotFoundException("controllerKeyStorePassword not specified in ./configuration/config.ini");
+ }
+ if (trustStoreFile != null) {
+ trustStoreFile = trustStoreFile.trim();
+ }
+ if ((trustStoreFile == null) || trustStoreFile.isEmpty()) {
+ throw new FileNotFoundException("controllerTrustStore not specified in ./configuration/config.ini");
+ }
+ if (trustStorePassword != null) {
+ trustStorePassword = trustStorePassword.trim();
+ }
+ if ((trustStorePassword == null) || trustStorePassword.isEmpty()) {
+ throw new FileNotFoundException("controllerTrustStorePassword not specified in ./configuration/config.ini");
+ }
+
KeyStore ks = KeyStore.getInstance("JKS");
KeyStore ts = KeyStore.getInstance("JKS");
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
newBuffer.put(myAppData);
myAppData = newBuffer;
}
+ }
+ synchronized (myAppData) {
msg.writeTo(myAppData);
myAppData.flip();
sslEngineResult = sslEngine.wrap(myAppData, myNetData);
package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
-import java.io.IOException;
+import java.net.SocketException;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
@Override
public Integer asyncSend(OFMessage msg, int xid) {
msg.setXid(xid);
- transmitQ.add(new PriorityMessage(msg, 0));
+ if (transmitQ != null) {
+ transmitQ.add(new PriorityMessage(msg, 0));
+ }
return xid;
}
@Override
public Integer asyncFastSend(OFMessage msg, int xid) {
msg.setXid(xid);
- transmitQ.add(new PriorityMessage(msg, 1));
+ if (transmitQ != null) {
+ transmitQ.add(new PriorityMessage(msg, 1));
+ }
return xid;
}
public void resumeSend() {
try {
- msgReadWriteService.resumeSend();
+ if (msgReadWriteService != null) {
+ msgReadWriteService.resumeSend();
+ }
} catch (Exception e) {
reportError(e);
}
}
private void reportError(Exception e) {
- if (e instanceof AsynchronousCloseException) {
+ if (e instanceof AsynchronousCloseException ||
+ e instanceof InterruptedException ||
+ e instanceof SocketException) {
logger.debug("Caught exception {}", e.getMessage());
} else {
logger.warn("Caught exception {}", e.getMessage());
logger.trace("Message sent: {}", pmsg.toString());
}
Thread.sleep(10);
+ } catch (InterruptedException ie) {
+ reportError(new InterruptedException("PriorityMessageTransmit thread interrupted"));
} catch (Exception e) {
reportError(e);
}
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-to-sources</artifactId>
+ <artifactId>maven-yang</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-to-sources</artifactId>
+ <artifactId>maven-yang</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-to-sources</artifactId>
+ <artifactId>maven-yang</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-to-sources</artifactId>
+ <artifactId>maven-yang</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-to-sources</artifactId>
+ <artifactId>maven-yang</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-to-sources</artifactId>
+ <artifactId>maven-yang</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
<artifactId>maven-yang-plugin</artifactId>
<packaging>maven-plugin</packaging>
+ <description>
+ This plugin is a wrapper for "yang to source code" generation.
+ It can be configured by a set of third-party code generators and resource providers.
+ For further info see available goals.
+ Sample usage:
+
+ TODO: add sample usage when finished
+ </description>
<dependencies>
<dependency>
</dependency>
</dependencies>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.2</version>
+ </plugin>
+ </plugins>
+ </reporting>
+
<build>
<plugins>
<plugin>
import com.google.common.base.Preconditions;
/**
- * Complex configuration arguments
+ * Base complex configuration arguments
*/
public abstract class ConfigArg {
public abstract void check();
+ /**
+ * Configuration argument for resource generator class and output directory.
+ */
public static final class ResourceProviderArg extends ConfigArg {
private String resourceProviderClass;
}
/**
- * Transfer object for code generator class and output directory.
+ * Configuration argument for code generator class and output directory.
*/
public static final class CodeGeneratorArg extends ConfigArg {
private String codeGeneratorClass;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
+/**
+ * Generate resources from yang files using user provided set of
+ * {@link ResourceGenerator}s. Can be used to copy yang files that served as
+ * blueprint for code generation into resources directory. Steps of this
+ * process:
+ * <ol>
+ * <li>List yang files from {@link #yangFilesRootDir} (If this goal is in the
+ * same execution as generate-sources, the same cached list will be used and the
+ * root folder will not be searched for yang files twice)</li>
+ * <li>For each {@link ResourceGenerator} from {@link #resourceProviders}:</li>
+ * <ol>
+ * <li>Instantiate using default constructor</li>
+ * <li>Call {@link ResourceGenerator#generateResourceFiles(Collection, File)}</li>
+ * </ol>
+ * </ol>
+ */
@Mojo(name = "generate-resources", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
public final class YangToResourcesMojo extends AbstractMojo {
private static final String LOG_PREFIX = "yang-to-resources:";
+ /**
+ * Classes implementing {@link ResourceGenerator} interface. An instance
+ * will be created out of every class using default constructor. Method
+ * {@link ResourceGenerator#generateResourceFiles(Collection, File)} will be
+ * called on every instance.
+ */
@Parameter(required = true)
private ResourceProviderArg[] resourceProviders;
+ /**
+ * Source directory that will be recursively searched for yang files (ending
+ * with .yang suffix).
+ */
@Parameter(required = true)
private String yangFilesRootDir;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
+/**
+ * Generate sources from yang files using user provided set of
+ * {@link CodeGenerator}s. Steps of this process:
+ * <ol>
+ * <li>List yang files from {@link #yangFilesRootDir}</li>
+ * <li>Process yang files using {@link YangModelParserImpl}</li>
+ * <li>For each {@link CodeGenerator} from {@link #codeGenerators}:</li>
+ * <ol>
+ * <li>Instantiate using default constructor</li>
+ * <li>Call {@link CodeGenerator#generateSources(SchemaContext, File)}</li>
+ * </ol>
+ * </ol>
+ */
@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public final class YangToSourcesMojo extends AbstractMojo {
private static final String LOG_PREFIX = "yang-to-sources:";
+ /**
+ * Classes implementing {@link CodeGenerator} interface. An instance will be
+ * created out of every class using default constructor. Method
+ * {@link CodeGenerator#generateSources(SchemaContext, File)} will be called
+ * on every instance.
+ */
@Parameter(required = true)
private CodeGeneratorArg[] codeGenerators;
+ /**
+ * Source directory that will be recursively searched for yang files (ending
+ * with .yang suffix).
+ */
@Parameter(required = true)
private String yangFilesRootDir;
import org.opendaylight.controller.yang.model.api.SchemaContext;
+/**
+ * Classes implementing this interface can be submitted to maven-yang-plugin's
+ * generate-sources goal.
+ */
public interface CodeGenerator {
+ /**
+ * Generate sources from provided {@link SchemaContext}
+ *
+ * @param context
+ * parsed from yang files
+ * @param outputBaseDir
+ * expected output directory for generated sources configured by
+ * user
+ * @return collection of files that were generated from schema context
+ */
Collection<File> generateSources(SchemaContext context, File outputBaseDir);
}
import java.io.File;
import java.util.Collection;
+/**
+ * Classes implementing this interface can be submitted to maven-yang-plugin's
+ * generate-resources goal.
+ */
public interface ResourceGenerator {
+ /**
+ * Generate resources (e.g. copy files into resources folder) from provided
+ * list of yang files
+ *
+ * @param resources
+ * list of parsed yang files
+ * @param outputBaseDir
+ * expected output directory for resources configured by user
+ */
void generateResourceFiles(Collection<File> resources, File outputBaseDir);
}