</dependency>
<dependency>
<groupId>org.opendaylight.mdsal.model</groupId>
- <artifactId>odl-mdsal-model-draft-clemm-netmod-yang-network-topo-01</artifactId>
+ <artifactId>odl-mdsal-model-draft-clemm-netmod-yang-network-topo-01-minimal</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
+++ /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.netconf</groupId>
- <artifactId>netconf-subsystem</artifactId>
- <version>1.5.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>netconf-it</artifactId>
- <name>${project.artifactId}</name>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-netty-util</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>mockito-configuration</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>xmlunit</groupId>
- <artifactId>xmlunit</artifactId>
- </dependency>
- <!-- compile dependencies -->
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>sal-netconf-connector</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-client</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-client</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-impl</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-mapping-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-monitoring</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-netty-util</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-ssh</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-testtool</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-ssh</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>netconf-util</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>netty-config-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>yang-test</artifactId>
- <scope>test</scope>
- </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.netconf.it;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import com.google.common.base.Throwables;
-import com.google.common.io.ByteStreams;
-import com.google.common.util.concurrent.CheckedFuture;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.local.LocalAddress;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.concurrent.GlobalEventExecutor;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Before;
-import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory;
-import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver;
-import org.opendaylight.controller.config.facade.xml.osgi.YangStoreService;
-import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
-import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
-import org.opendaylight.controller.config.spi.ModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.IdentityTestModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory;
-import org.opendaylight.netconf.api.NetconfMessage;
-import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
-import org.opendaylight.netconf.client.NetconfClientDispatcherImpl;
-import org.opendaylight.netconf.client.SimpleNetconfClientSessionListener;
-import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
-import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder;
-import org.opendaylight.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl;
-import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
-import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
-import org.opendaylight.netconf.impl.SessionIdProvider;
-import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
-import org.opendaylight.netconf.impl.osgi.NetconfMonitoringServiceImpl;
-import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
-import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringActivator;
-import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringOperationService;
-import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.protocol.framework.NeverReconnectStrategy;
-import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.yangtools.yang.binding.BindingMapping;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-
-public abstract class AbstractNetconfConfigTest extends AbstractConfigTest {
-
- public static final String LOOPBACK_ADDRESS = "127.0.0.1";
- public static final int SERVER_CONNECTION_TIMEOUT_MILLIS = 5000;
- private static final int RESOURCE_TIMEOUT_MINUTES = 2;
-
- static ModuleFactory[] FACTORIES =
- {new TestImplModuleFactory(), new DepTestImplModuleFactory(), new NetconfTestImplModuleFactory(),
- new IdentityTestModuleFactory(), new MultipleDependenciesModuleFactory()};
-
- protected ConfigSubsystemFacadeFactory configSubsystemFacadeFactory;
- private EventLoopGroup nettyThreadgroup;
- private HashedWheelTimer hashedWheelTimer;
-
- private NetconfClientDispatcherImpl clientDispatcher;
- private Channel serverTcpChannel;
-
- private NetconfMessage getConfig;
- private NetconfMessage get;
-
- /**
- * @Before in subclasses is called after this method.
- */
- @Before
- public void setUpAbstractNetconfConfigTest() throws Exception {
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, FACTORIES));
-
- nettyThreadgroup = new NioEventLoopGroup();
- hashedWheelTimer = new HashedWheelTimer();
-
- loadMessages();
-
- setUpTestInitial();
-
- final AggregatedNetconfOperationServiceFactory factoriesListener =
- new AggregatedNetconfOperationServiceFactory();
- final NetconfMonitoringService netconfMonitoringService = getNetconfMonitoringService(factoriesListener);
- configSubsystemFacadeFactory =
- new ConfigSubsystemFacadeFactory(configRegistryClient, configRegistryClient, getYangStore());
- factoriesListener.onAddNetconfOperationServiceFactory(
- new NetconfOperationServiceFactoryImpl(configSubsystemFacadeFactory));
- factoriesListener.onAddNetconfOperationServiceFactory(
- new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
- new NetconfMonitoringOperationService(netconfMonitoringService)));
-
- for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories(
- factoriesListener)) {
- factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
- }
-
- serverTcpChannel = startNetconfTcpServer(factoriesListener, netconfMonitoringService);
- clientDispatcher =
- new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
- }
-
- /**
- * Called before setUp method is executed, so test classes can set up resources before
- * setUpAbstractNetconfConfigTest method is called.
- */
- protected void setUpTestInitial() throws Exception {}
-
- private void loadMessages() throws Exception {
- this.getConfig = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
- this.get = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/get.xml");
- }
-
- public NetconfMessage getGetConfig() {
- return getConfig;
- }
-
- public NetconfMessage getGet() {
- return get;
- }
-
- private Channel startNetconfTcpServer(final AggregatedNetconfOperationServiceFactory listener,
- final NetconfMonitoringService monitoring) throws Exception {
- final NetconfServerDispatcherImpl dispatch = createDispatcher(listener, monitoring);
-
- final ChannelFuture s;
- if (getTcpServerAddress() instanceof LocalAddress) {
- s = dispatch.createLocalServer(((LocalAddress) getTcpServerAddress()));
- } else {
- s = dispatch.createServer(((InetSocketAddress) getTcpServerAddress()));
- }
- s.await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES);
- return s.channel();
- }
-
- protected Iterable<NetconfOperationServiceFactory> getAdditionalServiceFactories(
- final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception {
- return Collections.emptySet();
- }
-
- protected NetconfMonitoringService getNetconfMonitoringService(
- final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception {
- return new NetconfMonitoringServiceImpl(factoriesListener);
- }
-
- protected abstract SocketAddress getTcpServerAddress();
-
- public NetconfClientDispatcherImpl getClientDispatcher() {
- return clientDispatcher;
- }
-
- private HardcodedYangStoreService getYangStore() throws IOException {
- final Collection<InputStream> yangDependencies = getBasicYangs();
- return new HardcodedYangStoreService(yangDependencies, getBindingRuntimeContext());
- }
-
- static Collection<InputStream> getBasicYangs() throws IOException {
-
- final List<String> paths = Arrays.asList("/META-INF/yang/config@2013-04-05.yang",
- "/META-INF/yang/rpc-context@2013-06-17.yang",
- "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang",
- "/META-INF/yang/test-types.yang", "/META-INF/yang/test-groups.yang",
- "/META-INF/yang/ietf-inet-types@2013-07-15.yang");
-
- final Collection<InputStream> yangDependencies = new ArrayList<>();
- final List<String> failedToFind = new ArrayList<>();
- for (final String path : paths) {
- final InputStream resourceAsStream = NetconfITTest.class.getResourceAsStream(path);
- if (resourceAsStream == null) {
- failedToFind.add(path);
- } else {
- yangDependencies.add(resourceAsStream);
- }
- }
- assertEquals("Some yang files were not found", Collections.<String>emptyList(), failedToFind);
- return yangDependencies;
- }
-
- protected NetconfServerDispatcherImpl createDispatcher(
- final AggregatedNetconfOperationServiceFactory factoriesListener,
- final NetconfMonitoringService sessionMonitoringService) {
- final SessionIdProvider idProvider = new SessionIdProvider();
-
- final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory =
- new NetconfServerSessionNegotiatorFactory(hashedWheelTimer, factoriesListener, idProvider,
- SERVER_CONNECTION_TIMEOUT_MILLIS, sessionMonitoringService);
-
- final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer =
- new NetconfServerDispatcherImpl.ServerChannelInitializer(serverNegotiatorFactory);
- return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
- }
-
- protected HashedWheelTimer getHashedWheelTimer() {
- return hashedWheelTimer;
- }
-
- protected EventLoopGroup getNettyThreadgroup() {
- return nettyThreadgroup;
- }
-
- /**
- * @After in subclasses is be called before this.
- */
- @After
- public void cleanUpNetconf() throws Exception {
- serverTcpChannel.close().await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES);
- hashedWheelTimer.stop();
- nettyThreadgroup.shutdownGracefully().await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES);
- }
-
- public NetconfClientConfiguration getClientConfiguration(final InetSocketAddress tcpAddress, final int timeout) {
- final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
- b.withAddress(tcpAddress);
- b.withSessionListener(new SimpleNetconfClientSessionListener());
- b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, timeout));
- b.withConnectionTimeoutMillis(timeout);
- return b.build();
- }
-
- public static final class HardcodedYangStoreService extends YangStoreService {
- public HardcodedYangStoreService(final Collection<? extends InputStream> inputStreams,
- final BindingRuntimeContext bindingRuntimeContext) throws IOException {
- super(new SchemaContextProvider() {
- @Override
- public SchemaContext getSchemaContext() {
- return getSchema(inputStreams);
- }
- }, new SchemaSourceProvider<YangTextSchemaSource>() {
- @Override
- public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
- SourceIdentifier sourceIdentifier) {
-
- return null;
- }
- });
-
- refresh(bindingRuntimeContext);
- }
-
- private static SchemaContext getSchema(final Collection<? extends InputStream> inputStreams) {
- final ArrayList<InputStream> byteArrayInputStreams = new ArrayList<>();
- for (final InputStream inputStream : inputStreams) {
- assertNotNull(inputStream);
- final byte[] content;
- try {
- content = ByteStreams.toByteArray(inputStream);
- } catch (IOException e) {
- throw new IllegalStateException("Cannot read " + inputStream, e);
- }
- final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content);
- byteArrayInputStreams.add(byteArrayInputStream);
- }
-
- for (final InputStream inputStream : byteArrayInputStreams) {
- try {
- inputStream.reset();
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- try {
- return YangInferencePipeline.RFC6020_REACTOR.newBuild().buildEffective(byteArrayInputStreams);
- } catch (SourceException | ReactorException e) {
- throw Throwables.propagate(e);
- }
- }
-
- @Override
- public EnumResolver getEnumResolver() {
- return new EnumResolver() {
- @Override
- public String fromYang(final String enumType, final String enumYangValue) {
- return BindingMapping.getClassName(enumYangValue);
- }
-
- @Override
- public String toYang(final String enumType, final String enumJavaValue) {
- return enumJavaValue.toLowerCase();
- }
- };
- }
- }
-}
+++ /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.netconf.it;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.opendaylight.controller.config.util.xml.XmlUtil.readXmlToDocument;
-import static org.opendaylight.netconf.util.test.XmlUnitUtil.assertContainsElementWithName;
-import static org.opendaylight.netconf.util.test.XmlUnitUtil.assertElementsCount;
-
-import com.google.common.collect.HashBiMap;
-import com.google.common.collect.Lists;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.List;
-import javax.management.InstanceNotFoundException;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.config.api.jmx.notifications.CommitJMXNotification;
-import org.opendaylight.controller.config.api.jmx.notifications.ConfigJMXNotification;
-import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
-import org.opendaylight.controller.config.persist.api.Persister;
-import org.opendaylight.controller.config.persist.impl.ConfigPersisterNotificationHandler;
-import org.opendaylight.netconf.api.NetconfMessage;
-import org.opendaylight.netconf.client.TestingNetconfClient;
-import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2;
-import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest {
-
- public static final int PORT = 12026;
- private static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT);
-
- @Override
- protected SocketAddress getTcpServerAddress() {
- return TCP_ADDRESS;
- }
-
- @Test
- public void testNetconfCommitNotifications() throws Exception {
- final VerifyingNotificationListener notificationVerifier = createCommitNotificationListener();
- final VerifyingPersister mockedAggregator = mockAggregator();
-
- try (TestingNetconfClient persisterClient = new TestingNetconfClient("persister", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) {
- try (ConfigPersisterNotificationHandler configPersisterNotificationHandler = new ConfigPersisterNotificationHandler(
- platformMBeanServer, mockedAggregator, configSubsystemFacadeFactory)) {
-
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) {
- NetconfMessage response = netconfClient.sendMessage(loadEditConfigMessage());
- assertContainsElementWithName(response.getDocument(), "ok");
- response = netconfClient.sendMessage(loadCommitMessage());
- assertContainsElementWithName(response.getDocument(), "ok");
-
- response = netconfClient.sendMessage(loadGetConfigMessage());
- assertContainsElementWithName(response.getDocument(), "modules");
- assertContainsElementWithName(response.getDocument(), "services");
- }
- }
- }
-
- notificationVerifier.assertNotificationCount(1);
-
- mockedAggregator.assertSnapshotCount(1);
- // Capabilities are stripped for persister
- mockedAggregator.assertSnapshotContent(0, 4, 3, 3);
- }
-
- @Override
- protected BindingRuntimeContext getBindingRuntimeContext() {
- final BindingRuntimeContext ret = super.getBindingRuntimeContext();
- doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME);
- doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME);
- final HashBiMap<String, String> toBeReturned = HashBiMap.create();
- toBeReturned.put("two", "Two");
- toBeReturned.put("one", "One");
- toBeReturned.put("version1", "Version1");
- doReturn(toBeReturned).when(ret).getEnumMapping(anyString());
- return ret;
- }
-
- private VerifyingPersister mockAggregator() throws IOException {
- return new VerifyingPersister();
- }
-
- private VerifyingNotificationListener createCommitNotificationListener() throws InstanceNotFoundException {
- final VerifyingNotificationListener listener = new VerifyingNotificationListener();
- platformMBeanServer.addNotificationListener(ConfigJMXNotification.OBJECT_NAME, listener, null, null);
- return listener;
- }
-
- private NetconfMessage loadGetConfigMessage() throws Exception {
- return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
- }
-
- private NetconfMessage loadEditConfigMessage() throws Exception {
- return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig.xml");
- }
-
- private NetconfMessage loadCommitMessage() throws Exception {
- return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml");
- }
-
- private static class VerifyingNotificationListener implements NotificationListener {
- public List<Notification> notifications = Lists.newArrayList();
-
- @Override
- public void handleNotification(final Notification notification, final Object handback) {
- this.notifications.add(notification);
- }
-
- void assertNotificationCount(final Object size) {
- assertEquals(size, notifications.size());
- }
-
- void assertNotificationContent(final int notificationIndex) {
- final Notification notification = notifications.get(notificationIndex);
- assertEquals(CommitJMXNotification.class, notification.getClass());
- }
- }
-
- private static class VerifyingPersister implements Persister {
-
- public List<ConfigSnapshotHolder> snapshots = Lists.newArrayList();
- private Persister mockedPersister;
-
- public VerifyingPersister() throws IOException {
- final Persister mockedAggregator = mock(Persister.class);
-
- doAnswer(new Answer<Object>() {
- @Override
- public Object answer(final InvocationOnMock invocation) throws Throwable {
- final ConfigSnapshotHolder configSnapshot = (ConfigSnapshotHolder) invocation.getArguments()[0];
- snapshots.add(configSnapshot);
- return null;
- }
- }).when(mockedAggregator).persistConfig(any(ConfigSnapshotHolder.class));
-
- this.mockedPersister = mockedAggregator;
- }
-
- void assertSnapshotCount(final Object size) {
- assertEquals(size, snapshots.size());
- }
-
- void assertSnapshotContent(final int notificationIndex, final int expectedModulesSize, final int expectedServicesSize, final int expectedCapsSize)
- throws SAXException, IOException {
- final ConfigSnapshotHolder snapshot = snapshots.get(notificationIndex);
- final int capsSize = snapshot.getCapabilities().size();
- assertEquals("Expected capabilities count should be " + expectedCapsSize + " but was " + snapshot.getCapabilities(), expectedCapsSize, capsSize);
- final Document configSnapshot = readXmlToDocument(snapshot.getConfigSnapshot());
- assertElementsCount(configSnapshot, "module", expectedModulesSize);
- assertElementsCount(configSnapshot, "instance", expectedServicesSize);
- }
-
- @Override
- public void persistConfig(final ConfigSnapshotHolder configSnapshotHolder) throws IOException {
- mockedPersister.persistConfig(configSnapshotHolder);
- }
-
- @Override
- public List<ConfigSnapshotHolder> loadLastConfigs() throws IOException {
- return mockedPersister.loadLastConfigs();
- }
-
- @Override
- public void close() {
- mockedPersister.close();
- }
- }
-}
+++ /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.netconf.it;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.opendaylight.netconf.util.test.XmlUnitUtil.assertContainsElementWithText;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import org.junit.Test;
-import org.opendaylight.controller.config.util.capability.Capability;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.netconf.api.NetconfMessage;
-import org.opendaylight.netconf.api.monitoring.CapabilityListener;
-import org.opendaylight.netconf.client.TestingNetconfClient;
-import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
-import org.opendaylight.netconf.mapping.api.NetconfOperationService;
-import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.w3c.dom.Document;
-
-public class NetconfITMonitoringTest extends AbstractNetconfConfigTest {
-
- public static final int PORT = 12025;
- public static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT);
- public static final TestingCapability TESTING_CAPABILITY = new TestingCapability();
-
- @Override
- protected InetSocketAddress getTcpServerAddress() {
- return TCP_ADDRESS;
- }
-
- @Test
- public void testGetResponseFromMonitoring() throws Exception {
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("client-monitoring", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 10000))) {
- try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("client-monitoring2", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 10000))) {
- Thread.sleep(500);
- final NetconfMessage response = netconfClient2.sendMessage(getGet());
- assertSessionElementsInResponse(response.getDocument(), 2);
- }
- Thread.sleep(500);
- final NetconfMessage response = netconfClient.sendMessage(getGet());
- assertSessionElementsInResponse(response.getDocument(), 1);
- }
- }
-
- @Test(timeout = 13 * 10000)
- public void testClientHelloWithAuth() throws Exception {
- String fileName = "netconfMessages/client_hello_with_auth.xml";
- final String hello = XmlFileLoader.fileToString(fileName);
-
- fileName = "netconfMessages/get.xml";
- final String get = XmlFileLoader.fileToString(fileName);
-
- final Socket sock = new Socket(TCP_ADDRESS.getHostName(), TCP_ADDRESS.getPort());
- sock.getOutputStream().write(hello.getBytes(StandardCharsets.UTF_8));
- final String separator = "]]>]]>";
-
- sock.getOutputStream().write(separator.getBytes(StandardCharsets.UTF_8));
- sock.getOutputStream().write(get.getBytes(StandardCharsets.UTF_8));
- sock.getOutputStream().write(separator.getBytes(StandardCharsets.UTF_8));
-
- final StringBuilder responseBuilder = new StringBuilder();
-
- try (InputStream inputStream = sock.getInputStream();
- InputStreamReader reader = new InputStreamReader(inputStream);
- BufferedReader buff = new BufferedReader(reader)) {
- String line;
- while ((line = buff.readLine()) != null) {
-
- responseBuilder.append(line);
- responseBuilder.append(System.lineSeparator());
-
- if(line.contains("</rpc-reply>"))
- break;
- }
- }
-
- sock.close();
-
- final String helloMsg = responseBuilder.substring(0, responseBuilder.indexOf(separator));
- Document doc = XmlUtil.readXmlToDocument(helloMsg);
- assertContainsElementWithText(doc, "urn:ietf:params:netconf:capability:candidate:1.0");
-
- final String replyMsg = responseBuilder.substring(responseBuilder.indexOf(separator) + separator.length());
- doc = XmlUtil.readXmlToDocument(replyMsg);
- assertContainsElementWithText(doc, "tomas");
- }
-
- private void assertSessionElementsInResponse(final Document document, final int i) {
- final int elementSize = document.getElementsByTagName("session-id").getLength();
- assertEquals("Incorrect number of session-id tags in " + XmlUtil.toString(document), i, elementSize);
- }
-
- public static AggregatedNetconfOperationServiceFactory getNetconfOperationProvider() throws Exception {
- final AggregatedNetconfOperationServiceFactory factoriesListener = mock(AggregatedNetconfOperationServiceFactory.class);
- final NetconfOperationService snap = mock(NetconfOperationService.class);
- try {
- doNothing().when(snap).close();
- } catch (final Exception e) {
- // not happening
- throw new IllegalStateException(e);
- }
- final Set<Capability> caps = Sets.newHashSet();
- caps.add(TESTING_CAPABILITY);
-
- doReturn(caps).when(factoriesListener).getCapabilities();
- doReturn(snap).when(factoriesListener).createService(anyString());
-
- AutoCloseable mock = mock(AutoCloseable.class);
- doNothing().when(mock).close();
- doReturn(mock).when(factoriesListener).registerCapabilityListener(any(CapabilityListener.class));
-
- return factoriesListener;
- }
-
- private static class TestingCapability implements Capability {
- @Override
- public String getCapabilityUri() {
- return "namespaceModuleRevision";
- }
-
- @Override
- public Optional<String> getModuleNamespace() {
- return Optional.of("namespace");
- }
-
- @Override
- public Optional<String> getModuleName() {
- return Optional.of("name");
- }
-
- @Override
- public Optional<String> getRevision() {
- return Optional.of("revision");
- }
-
- @Override
- public Optional<String> getCapabilitySchema() {
- return Optional.of("content");
- }
-
- @Override
- public List<String> getLocation() {
- return Collections.emptyList();
- }
- }
-}
+++ /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.netconf.it;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.local.LocalAddress;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.concurrent.GlobalEventExecutor;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.file.Files;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.netconf.api.NetconfMessage;
-import org.opendaylight.netconf.auth.AuthProvider;
-import org.opendaylight.netconf.client.NetconfClientDispatcher;
-import org.opendaylight.netconf.client.NetconfClientDispatcherImpl;
-import org.opendaylight.netconf.client.NetconfClientSessionListener;
-import org.opendaylight.netconf.client.SimpleNetconfClientSessionListener;
-import org.opendaylight.netconf.client.TestingNetconfClient;
-import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
-import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder;
-import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
-import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPassword;
-import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
-import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
-import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.netconf.ssh.SshProxyServer;
-import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
-import org.opendaylight.netconf.util.messages.NetconfMessageUtil;
-import org.opendaylight.netconf.util.osgi.NetconfConfigUtil;
-import org.opendaylight.protocol.framework.NeverReconnectStrategy;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.xml.sax.SAXException;
-
-public class NetconfITSecureTest extends AbstractNetconfConfigTest {
-
- public static final int PORT = 12024;
- private static final InetSocketAddress TLS_ADDRESS = new InetSocketAddress("127.0.0.1", PORT);
-
- public static final String USERNAME = "user";
- public static final String PASSWORD = "pwd";
-
- private SshProxyServer sshProxyServer;
-
- private ExecutorService nioExec;
- private EventLoopGroup clientGroup;
- private ScheduledExecutorService minaTimerEx;
-
- @Before
- public void setUp() throws Exception {
- nioExec = Executors.newFixedThreadPool(1);
- clientGroup = new NioEventLoopGroup();
- minaTimerEx = Executors.newScheduledThreadPool(1);
- sshProxyServer = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
- sshProxyServer.bind(
- new SshProxyServerConfigurationBuilder()
- .setBindingAddress(TLS_ADDRESS)
- .setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress())
- .setAuthenticator(new AuthProvider() {
- @Override
- public boolean authenticated(String username, String password) {
- return true;
- }
- }
- )
- .setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()))
- .setIdleTimeout(Integer.MAX_VALUE)
- .createSshProxyServerConfiguration());
- }
-
- @After
- public void tearDown() throws Exception {
- sshProxyServer.close();
- clientGroup.shutdownGracefully();
- minaTimerEx.shutdownNow();
- nioExec.shutdownNow();
- }
-
- @Test(timeout = 2*60*1000)
- public void testSecure() throws Exception {
- final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(new SimpleNetconfClientSessionListener(), TLS_ADDRESS))) {
- NetconfMessage response = netconfClient.sendMessage(getGetConfig());
- assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()),
- NetconfMessageUtil.isErrorMessage(response));
-
- final NetconfMessage gs = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc message-id=\"2\"\n" +
- " xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
- " <get-schema xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" +
- " <identifier>config</identifier>\n" +
- " </get-schema>\n" +
- "</rpc>\n"));
-
- response = netconfClient.sendMessage(gs);
- assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()),
- NetconfMessageUtil.isErrorMessage(response));
- }
- }
-
- /**
- * Test all requests are handled properly and no mismatch occurs in listener
- */
- @Test(timeout = 6*60*1000)
- public void testSecureStress() throws Exception {
- final int requests = 4000;
-
- final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer());
- final NetconfDeviceCommunicator sessionListener = getSessionListener();
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(sessionListener, TLS_ADDRESS))) {
-
- final AtomicInteger responseCounter = new AtomicInteger(0);
- final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = Lists.newArrayList();
-
- for (int i = 0; i < requests; i++) {
- NetconfMessage getConfig = getGetConfig();
- getConfig = changeMessageId(getConfig, i);
- final ListenableFuture<RpcResult<NetconfMessage>> netconfMessageFuture = sessionListener.sendRequest(getConfig, QName.create("namespace", "2012-12-12", "get"));
- futures.add(netconfMessageFuture);
- Futures.addCallback(netconfMessageFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
- @Override
- public void onSuccess(final RpcResult<NetconfMessage> result) {
- responseCounter.incrementAndGet();
- }
-
- @Override
- public void onFailure(final Throwable t) {
- throw new RuntimeException(t);
- }
- });
- }
-
- // Wait for every future
- for (final ListenableFuture<RpcResult<NetconfMessage>> future : futures) {
- try {
- future.get(3, TimeUnit.MINUTES);
- } catch (final TimeoutException e) {
- fail("Request " + futures.indexOf(future) + " is not responding");
- }
- }
-
- // Give future listeners some time to finish counter incrementation
- Thread.sleep(5000);
-
- assertEquals(requests, responseCounter.get());
- }
- }
-
- public static NetconfMessage changeMessageId(final NetconfMessage getConfig, final int i) throws IOException, SAXException {
- String s = XmlUtil.toString(getConfig.getDocument(), false);
- s = s.replace("101", Integer.toString(i));
- return new NetconfMessage(XmlUtil.readXmlToDocument(s));
- }
-
- static NetconfClientConfiguration getClientConfiguration(final NetconfClientSessionListener sessionListener,final InetSocketAddress tlsAddress) throws IOException {
- final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
- b.withAddress(tlsAddress);
- // Using session listener from sal-netconf-connector since stress test cannot be performed with simple listener
- b.withSessionListener(sessionListener);
- b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
- b.withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH);
- b.withConnectionTimeoutMillis(5000);
- b.withAuthHandler(getAuthHandler());
- return b.build();
- }
-
- static NetconfDeviceCommunicator getSessionListener() {
- RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> mockedRemoteDevice = mock(RemoteDevice.class);
- doNothing().when(mockedRemoteDevice).onRemoteSessionUp(any(NetconfSessionPreferences.class), any(NetconfDeviceCommunicator.class));
- doNothing().when(mockedRemoteDevice).onRemoteSessionDown();
- return new NetconfDeviceCommunicator(new RemoteDeviceId("secure-test", InetSocketAddress.createUnresolved("localhost", 22)), mockedRemoteDevice);
- }
-
- public AuthProvider getAuthProvider() throws Exception {
- final AuthProvider mockAuth = mock(AuthProvider.class);
- doReturn("mockedAuth").when(mockAuth).toString();
- doReturn(true).when(mockAuth).authenticated(anyString(), anyString());
- return mockAuth;
- }
-
- public static AuthenticationHandler getAuthHandler() throws IOException {
- return new LoginPassword(USERNAME, PASSWORD);
- }
-
- @Override
- protected LocalAddress getTcpServerAddress() {
- return NetconfConfigUtil.getNetconfLocalAddress();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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.netconf.it;
-
-import static java.lang.Thread.sleep;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.opendaylight.netconf.it.NetconfITSecureTest.getSessionListener;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.HashedWheelTimer;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.netconf.api.NetconfMessage;
-import org.opendaylight.netconf.client.NetconfClientDispatcher;
-import org.opendaylight.netconf.client.NetconfClientDispatcherImpl;
-import org.opendaylight.netconf.client.TestingNetconfClient;
-import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
-import org.opendaylight.netconf.test.tool.Main.Params;
-import org.opendaylight.netconf.test.tool.NetconfDeviceSimulator;
-import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-
-public class NetconfITSecureTestTool
-{
-
- //set up port both for testool device and test
- public static final int PORT = 17833;
- private static final InetSocketAddress TLS_ADDRESS = new InetSocketAddress("127.0.0.1", PORT);
-
- private String xmlFile = "netconfMessages/editConfig.xml";
-
- private ExecutorService msgExec = Executors.newFixedThreadPool(8);
-
- Collection<Future<?>> tasks = new LinkedList<Future<?>>();
-
- final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator();
-
- @Before
- public void setUp() throws Exception {
-
- //Set up parameters for testtool device
- Params params = new Params();
- params.debug = true;
- params.deviceCount = 1;
- params.startingPort = PORT;
- params.ssh = true;
- params.exi = true;
-
- final List<Integer> openDevices = netconfDeviceSimulator.start(params);
- }
-
- @After
- public void tearDown() throws Exception {
-
- }
-
- /**
- * Test all requests are handled properly and no mismatch occurs in listener
- */
- @Test(timeout = 6*60*1000)
- public void testSecureStress() throws Exception {
-
- final int requests = 4000;
-
- List<Future<?>> tasks = new ArrayList<>();
-
- final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), new HashedWheelTimer());
-
- final NetconfDeviceCommunicator sessionListener = getSessionListener();
-
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, NetconfITSecureTest.getClientConfiguration(sessionListener, TLS_ADDRESS));)
- {
-
- final AtomicInteger responseCounter = new AtomicInteger(0);
- final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = Lists.newArrayList();
-
- for (int i = 0; i < requests; i++) {
-
- NetconfMessage getConfig = XmlFileLoader.xmlFileToNetconfMessage(xmlFile);
-
- getConfig = NetconfITSecureTest.changeMessageId(getConfig,i);
-
- Runnable worker = new NetconfITSecureTestToolRunnable(getConfig,i, sessionListener, futures, responseCounter);
-
- tasks.add(msgExec.submit(worker));
-
- }
-
- msgExec.shutdown();
-
- // Wait for every future
- for (final Future<?> task : tasks){
- try
- {
-
- task.get(3, TimeUnit.MINUTES);
- } catch (final TimeoutException e) {
- fail(String.format("Request %d is not responding", tasks.indexOf(task)));
- }
- }
-
- for (final ListenableFuture<RpcResult<NetconfMessage>> future : futures) {
- try {
-
- future.get(3, TimeUnit.MINUTES);
- } catch (final TimeoutException e) {
- fail(String.format("Reply %d is not responding", futures.indexOf(future)));
- }
- }
-
- sleep(5000);
-
- assertEquals(requests, responseCounter.get());
-
- }
- }
-
- class NetconfITSecureTestToolRunnable implements Runnable {
-
- private NetconfMessage getConfig;
- private int it;
- private NetconfDeviceCommunicator sessionListener;
- private List<ListenableFuture<RpcResult<NetconfMessage>>> futures;
- private AtomicInteger responseCounter;
-
- public NetconfITSecureTestToolRunnable(NetconfMessage getConfig, int it, NetconfDeviceCommunicator sessionListener, List<ListenableFuture<RpcResult<NetconfMessage>>> futures, AtomicInteger responseCounter){
- this.getConfig = getConfig;
- this.it = it;
- this.sessionListener = sessionListener;
- this.futures = futures;
- this.responseCounter = responseCounter;
- }
-
- @Override
- public void run(){
-
- ListenableFuture<RpcResult<NetconfMessage>> netconfMessageFuture;
-
- netconfMessageFuture = sessionListener.sendRequest(getConfig, QName.create("namespace", "2012-12-12", "get"));
-
- futures.add(netconfMessageFuture);
- Futures.addCallback(netconfMessageFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
-
- @Override
- public void onSuccess(final RpcResult<NetconfMessage> result) {
-
- if(result.isSuccessful()&result.getErrors().isEmpty()) {
- responseCounter.incrementAndGet();
- } else {
-
- fail(String.format("Message result not ok %s", result.getErrors().toString()));
-
- }
- }
-
- @Override
- public void onFailure(final Throwable t) {
-
- fail(String.format("Message failed %s", Throwables.getStackTraceAsString(t)));
-
- }
- }
- );
- }
- }
-
-}
+++ /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.netconf.it;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.doReturn;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeoutException;
-import javax.management.ObjectName;
-import javax.xml.parsers.ParserConfigurationException;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.XmlElement;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleMXBean;
-import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory;
-import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean;
-import org.opendaylight.netconf.api.NetconfMessage;
-import org.opendaylight.netconf.client.NetconfClientDispatcher;
-import org.opendaylight.netconf.client.TestingNetconfClient;
-import org.opendaylight.netconf.util.test.XmlFileLoader;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2;
-import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-public class NetconfITTest extends AbstractNetconfConfigTest {
-
- public static final int PORT = 12023;
- public static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT);
-
- private NetconfMessage getConfigCandidate, editConfig, closeSession;
- private NetconfClientDispatcher clientDispatcher;
-
- @Before
- public void setUp() throws Exception {
- loadMessages();
- clientDispatcher = getClientDispatcher();
- }
-
- @Override
- protected InetSocketAddress getTcpServerAddress() {
- return TCP_ADDRESS;
- }
-
- private void loadMessages() throws IOException, SAXException, ParserConfigurationException {
- this.editConfig = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/edit_config.xml");
- this.getConfigCandidate = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig_candidate.xml");
- this.closeSession = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/closeSession.xml");
- }
-
- @Test
- public void testNetconfClientDemonstration() throws Exception {
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", clientDispatcher, getClientConfiguration(TCP_ADDRESS, 4000))) {
-
- final Set<String> capabilitiesFromNetconfServer = netconfClient.getCapabilities();
- final long sessionId = netconfClient.getSessionId();
-
- // NetconfMessage can be created :
- // new NetconfMessage(XmlUtil.readXmlToDocument("<xml/>"));
-
- final NetconfMessage response = netconfClient.sendMessage(getGetConfig());
- response.getDocument();
- }
- }
-
- @Test
- public void testTwoSessions() throws Exception {
- try (TestingNetconfClient netconfClient = new TestingNetconfClient("1", clientDispatcher, getClientConfiguration(TCP_ADDRESS, 10000))) {
- try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("2", clientDispatcher, getClientConfiguration(TCP_ADDRESS, 10000))) {
- assertNotNull(netconfClient2.getCapabilities());
- }
- }
- }
-
- @Test
- public void rpcReplyContainsAllAttributesTest() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- final String rpc = "<rpc message-id=\"5\" a=\"a\" b=\"44\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><get/>" + "</rpc>";
- final Document doc = XmlUtil.readXmlToDocument(rpc);
- final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc));
- assertNotNull(message);
- final NamedNodeMap expectedAttributes = doc.getDocumentElement().getAttributes();
- final NamedNodeMap returnedAttributes = message.getDocument().getDocumentElement().getAttributes();
-
- assertSameAttributes(expectedAttributes, returnedAttributes);
- }
- }
-
- private void assertSameAttributes(final NamedNodeMap expectedAttributes, final NamedNodeMap returnedAttributes) {
- assertNotNull("Expecting 4 attributes", returnedAttributes);
- assertEquals(expectedAttributes.getLength(), returnedAttributes.getLength());
-
- for (int i = 0; i < expectedAttributes.getLength(); i++) {
- final Node expAttr = expectedAttributes.item(i);
- final Node attr = returnedAttributes.item(i);
- assertEquals(expAttr.getNodeName(), attr.getNodeName());
- assertEquals(expAttr.getNamespaceURI(), attr.getNamespaceURI());
- assertEquals(expAttr.getTextContent(), attr.getTextContent());
- }
- }
-
- @Test
- public void rpcReplyErrorContainsAllAttributesTest() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- final String rpc = "<rpc message-id=\"1\" a=\"adada\" b=\"4\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><commit/>" + "</rpc>";
- final Document doc = XmlUtil.readXmlToDocument(rpc);
- final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc));
- final NamedNodeMap expectedAttributes = doc.getDocumentElement().getAttributes();
- final NamedNodeMap returnedAttributes = message.getDocument().getDocumentElement().getAttributes();
-
- assertSameAttributes(expectedAttributes, returnedAttributes);
- }
- }
-
- @Test
- public void rpcOutputContainsCorrectNamespace() throws Exception {
- final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
- final ObjectName dep = transaction.createModule(DepTestImplModuleFactory.NAME, "instanceD");
- final ObjectName impl = transaction.createModule(NetconfTestImplModuleFactory.NAME, "instance");
- final NetconfTestImplModuleMXBean proxy = configRegistryClient
- .newMXBeanProxy(impl, NetconfTestImplModuleMXBean.class);
- proxy.setTestingDep(dep);
- proxy.setSimpleShort((short) 0);
-
- transaction.commit();
-
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- final String expectedNamespace = "urn:opendaylight:params:xml:ns:yang:controller:test:impl";
-
- final String rpc = "<rpc message-id=\"5\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + "<no-arg xmlns=\""
- + expectedNamespace
- + "\"> "
- + "<context-instance>/modules/module[type='impl-netconf'][name='instance']</context-instance>"
- + "<arg1>argument1</arg1>" + "</no-arg>" + "</rpc>";
- final Document doc = XmlUtil.readXmlToDocument(rpc);
- final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc));
-
- final Element rpcReply = message.getDocument().getDocumentElement();
- final XmlElement resultElement = XmlElement.fromDomElement(rpcReply).getOnlyChildElement();
- assertEquals("result", resultElement.getName());
-
- final String namespace = resultElement.getNamespaceAttribute();
- assertEquals(expectedNamespace, namespace);
- }
- }
-
- @Test
- public void testCloseSession() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
-
- // edit config
- Document rpcReply = netconfClient.sendMessage(this.editConfig)
- .getDocument();
- assertIsOK(rpcReply);
-
- rpcReply = netconfClient.sendMessage(this.closeSession)
- .getDocument();
-
- assertIsOK(rpcReply);
- }
- }
-
- @Test
- public void testEditConfig() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- // send edit_config.xml
- final Document rpcReply = netconfClient.sendMessage(this.editConfig).getDocument();
- assertIsOK(rpcReply);
- }
- }
-
- @Test
- public void testValidate() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- // begin transaction
- Document rpcReply = netconfClient.sendMessage(getConfigCandidate).getDocument();
- assertEquals("data", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName());
-
- // operations empty
- rpcReply = netconfClient.sendMessage(XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/validate.xml"))
- .getDocument();
- assertIsOK(rpcReply);
- }
- }
-
- private void assertIsOK(final Document rpcReply) throws DocumentedException {
- assertEquals("rpc-reply", rpcReply.getDocumentElement().getLocalName());
- assertEquals("ok", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName());
- }
-
- private Document assertGetConfigWorks(final TestingNetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException, DocumentedException {
- return assertGetConfigWorks(netconfClient, getGetConfig());
- }
-
- private Document assertGetConfigWorks(final TestingNetconfClient netconfClient, final NetconfMessage getConfigMessage)
- throws InterruptedException, ExecutionException, TimeoutException, DocumentedException {
- final NetconfMessage rpcReply = netconfClient.sendMessage(getConfigMessage);
- assertNotNull(rpcReply);
- assertEquals("data", XmlElement.fromDomDocument(rpcReply.getDocument()).getOnlyChildElement().getName());
- return rpcReply.getDocument();
- }
-
- @Test
- public void testGetConfig() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- assertGetConfigWorks(netconfClient);
- }
- }
-
- @Test
- public void createYangTestBasedOnYuma() throws Exception {
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- Document rpcReply = netconfClient.sendMessage(
- XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_yang-test.xml"))
- .getDocument();
- assertEquals("rpc-reply", rpcReply.getDocumentElement().getTagName());
- assertIsOK(rpcReply);
- assertGetConfigWorks(netconfClient, this.getConfigCandidate);
- rpcReply = netconfClient.sendMessage(XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml"))
- .getDocument();
- assertIsOK(rpcReply);
-
- final ObjectName on = new ObjectName(
- "org.opendaylight.controller:instanceName=impl-dep-instance,type=Module,moduleFactoryName=impl-dep");
- final Set<ObjectName> cfgBeans = configRegistryClient.lookupConfigBeans();
- assertEquals(cfgBeans, Sets.newHashSet(on));
- }
- }
-
- private TestingNetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception {
- final TestingNetconfClient netconfClient = new TestingNetconfClient("test " + address.toString(), clientDispatcher, getClientConfiguration(address, 5000));
- assertEquals(expected, Long.toString(netconfClient.getSessionId()));
- return netconfClient;
- }
-
- @Test
- public void testIdRef() throws Exception {
- final NetconfMessage editId = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_identities.xml");
- final NetconfMessage commit = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml");
-
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- assertIsOK(netconfClient.sendMessage(editId).getDocument());
- assertIsOK(netconfClient.sendMessage(commit).getDocument());
-
- final NetconfMessage response = netconfClient.sendMessage(getGetConfig());
-
- assertThat(XmlUtil.toString(response.getDocument()), containsString("<afi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity1</afi>"));
- assertThat(XmlUtil.toString(response.getDocument()), containsString("<afi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity2</afi>"));
- assertThat(XmlUtil.toString(response.getDocument()), containsString("<safi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity2</safi>"));
- assertThat(XmlUtil.toString(response.getDocument()), containsString("<safi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity1</safi>"));
-
- } catch (final Exception e) {
- fail(Throwables.getStackTraceAsString(e));
- }
- }
-
- @Override
- protected BindingRuntimeContext getBindingRuntimeContext() {
- final BindingRuntimeContext ret = super.getBindingRuntimeContext();
- doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME);
- doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME);
- return ret;
- }
-
- @Test
- public void testMultipleDependencies() throws Exception {
- // push first xml, should add parent and d1,d2 dependencies
- try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) {
- final Document rpcReply = netconfClient.sendMessage(
- XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_multiple-deps1.xml"))
- .getDocument();
- assertIsOK(rpcReply);
- commit(netconfClient);
- }
- // verify that parent.getTestingDeps == d1,d2
- final MultipleDependenciesModuleMXBean parentProxy = configRegistryClient.newMXBeanProxy(
- configRegistryClient.lookupConfigBean(MultipleDependenciesModuleFactory.NAME, "parent"),
- MultipleDependenciesModuleMXBean.class);
- {
- final List<ObjectName> testingDeps = parentProxy.getTestingDeps();
- assertEquals(2, testingDeps.size());
- final Set<String> actualRefs = getServiceReferences(testingDeps);
- assertEquals(Sets.newHashSet("ref_d1", "ref_d2"), actualRefs);
- }
-
- // push second xml, should add d3 to parent's dependencies
- mergeD3(parentProxy);
- // push second xml again, to test that d3 is not added again
- mergeD3(parentProxy);
- }
-
- public void mergeD3(final MultipleDependenciesModuleMXBean parentProxy) throws Exception {
- try (TestingNetconfClient netconfClient = new TestingNetconfClient(
- "test " + TCP_ADDRESS.toString(), clientDispatcher, getClientConfiguration(TCP_ADDRESS, 5000))) {
-
- final Document rpcReply = netconfClient.sendMessage(
- XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_multiple-deps2.xml"))
- .getDocument();
- assertIsOK(rpcReply);
- commit(netconfClient);
- }
- {
- final List<ObjectName> testingDeps = parentProxy.getTestingDeps();
- assertEquals(3, testingDeps.size());
- final Set<String> actualRefs = getServiceReferences(testingDeps);
- assertEquals(Sets.newHashSet("ref_d1", "ref_d2", "ref_d3"), actualRefs);
- }
- }
-
- public Set<String> getServiceReferences(final List<ObjectName> testingDeps) {
- return new HashSet<>(Lists.transform(testingDeps, ObjectNameUtil::getReferenceName));
- }
-
- public void commit(final TestingNetconfClient netconfClient) throws Exception {
- final Document rpcReply;
- rpcReply = netconfClient.sendMessage(XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml"))
- .getDocument();
- assertIsOK(rpcReply);
- }
-}
+++ /dev/null
-<configuration scan="true">
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>%date{"yyyy-MM-dd HH:mm:ss.SSS z"} [%thread] %-5level %logger{36} - %msg%n</pattern>
- </encoder>
- </appender>
-
- <logger name="org.opendaylight.controller.netconf" level="INFO"/>
- <logger name="org.opendaylight.controller.sal.connect.netconf" level="DEBUG"/>
-
- <root level="error">
- <appender-ref ref="STDOUT" />
- </root>
-
-</configuration>
+++ /dev/null
-<rpc message-id="a" a="64" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
-<edit-config>
- <target>
- <candidate/>
- </target>
- <test-option>
- set
- </test-option>
- <default-operation>merge</default-operation>
- <config>
- <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <module>
- <type xmlns:test-impl="urn:opendaylight:params:xml:ns:yang:controller:test:impl">
- test-impl:impl-identity-test
- </type>
- <name>id-test</name>
- <identities>
- <afi xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:test:types">prefix:test-identity1</afi>
- <safi xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:test:types">prefix:test-identity2</safi>
- </identities>
- <identities>
- <afi xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:test:types">prefix:test-identity2</afi>
- <safi xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:test:types">prefix:test-identity1</safi>
- </identities>
- <identities-container>
- <afi xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:test:types">prefix:test-identity2</afi>
- </identities-container>
- <afi xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:test:types">prefix:test-identity1</afi>
- </module>
- </modules>
-
- <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
-
- </services>
- </config>
-</edit-config>
-</rpc>
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.mdsal.dom.api.DOMMountPointListener;
import org.opendaylight.mdsal.eos.dom.simple.SimpleDOMEntityOwnershipService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
* 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.netconf.topology.singleton.impl;
import static org.awaitility.Awaitility.await;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
public class NetconfTopologyManagerTest {
private static final int ACTOR_RESPONSE_WAIT_TIME = 10;
import java.net.URL;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.netconf.sal.restconf.broker.SalRemoteServiceBroker;
import org.opendaylight.yangtools.restconf.client.RestconfClientFactory;
import org.opendaylight.yangtools.restconf.client.api.RestconfClientContext;
import org.opendaylight.yangtools.restconf.client.api.UnsupportedProtocolException;
import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextHolder;
import org.slf4j.Logger;