Search in sources :

Example 1 with ClusterServiceAdapter

use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.

the class VirtualNetworkManagerTest method testServiceGetReturnsSavedInstance.

/**
 * Tests that the get() method returns saved service instances.
 */
@Test
public void testServiceGetReturnsSavedInstance() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), DeviceService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), LinkService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), TopologyService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), HostService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), PathService.class);
    // extra setup needed for FlowRuleService, PacketService, GroupService, and IntentService
    VirtualProviderManager virtualProviderManager = new VirtualProviderManager();
    virtualProviderManager.registerProvider(new DefaultVirtualFlowRuleProvider());
    virtualProviderManager.registerProvider(new DefaultVirtualPacketProvider());
    virtualProviderManager.registerProvider(new DefaultVirtualGroupProvider());
    testDirectory.add(CoreService.class, coreService).add(VirtualProviderRegistryService.class, virtualProviderManager).add(EventDeliveryService.class, new TestEventDispatcher()).add(ClusterService.class, new ClusterServiceAdapter()).add(VirtualNetworkFlowRuleStore.class, new SimpleVirtualFlowRuleStore()).add(VirtualNetworkPacketStore.class, new SimpleVirtualPacketStore()).add(VirtualNetworkGroupStore.class, new SimpleVirtualGroupStore()).add(VirtualNetworkIntentStore.class, new SimpleVirtualIntentStore()).add(VirtualNetworkFlowObjectiveStore.class, new SimpleVirtualFlowObjectiveStore());
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), FlowRuleService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), FlowObjectiveService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), PacketService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), GroupService.class);
    validateServiceGetReturnsSavedInstance(virtualNetwork.id(), IntentService.class);
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) SimpleVirtualFlowRuleStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowRuleStore) SimpleVirtualFlowObjectiveStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowObjectiveStore) VirtualNetworkIntentStore(org.onosproject.incubator.net.virtual.VirtualNetworkIntentStore) SimpleVirtualPacketStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualPacketStore) VirtualProviderRegistryService(org.onosproject.incubator.net.virtual.provider.VirtualProviderRegistryService) DefaultVirtualPacketProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualPacketProvider) DefaultVirtualGroupProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualGroupProvider) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) SimpleVirtualIntentStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualIntentStore) ClusterService(org.onosproject.cluster.ClusterService) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) SimpleVirtualGroupStore(org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualGroupStore) DefaultVirtualFlowRuleProvider(org.onosproject.incubator.net.virtual.impl.provider.DefaultVirtualFlowRuleProvider) VirtualProviderManager(org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager) VirtualNetworkPacketStore(org.onosproject.incubator.net.virtual.VirtualNetworkPacketStore) Test(org.junit.Test)

Example 2 with ClusterServiceAdapter

use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.

the class VplsOperationManagerTest method setup.

@Before
public void setup() {
    MockIdGenerator.cleanBind();
    vplsOperationManager = new VplsOperationManager();
    vplsOperationManager.coreService = new TestCoreService();
    vplsOperationManager.intentService = new TestIntentService();
    vplsOperationManager.leadershipService = new TestLeadershipService();
    vplsOperationManager.clusterService = new ClusterServiceAdapter();
    vplsOperationManager.hostService = new TestHostService();
    vplsOperationManager.vplsStore = new TestVplsStore();
    vplsOperationManager.isLeader = true;
    vplsOperationManager.activate();
}
Also used : ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) Before(org.junit.Before)

Example 3 with ClusterServiceAdapter

use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.

the class MastershipProxyManagerTest method testProxyManager.

@Test
public void testProxyManager() throws Exception {
    TestClusterCommunicationServiceFactory clusterCommunicatorFactory = new TestClusterCommunicationServiceFactory();
    NodeId a = NodeId.nodeId("a");
    NodeId b = NodeId.nodeId("b");
    DeviceId deviceId = DeviceId.deviceId("a");
    Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
    ProxyInterfaceImpl proxyInterface1 = new ProxyInterfaceImpl();
    MastershipProxyManager proxyManager1 = new MastershipProxyManager();
    proxyManager1.clusterService = new ClusterServiceAdapter() {

        @Override
        public ControllerNode getLocalNode() {
            return new DefaultControllerNode(a, IpAddress.valueOf(0));
        }
    };
    proxyManager1.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(a);
    proxyManager1.mastershipService = new MastershipServiceAdapter() {

        @Override
        public NodeId getMasterFor(DeviceId deviceId) {
            return b;
        }
    };
    proxyManager1.activate();
    proxyManager1.registerProxyService(ProxyInterface.class, proxyInterface1, serializer);
    ProxyInterfaceImpl proxyInterface2 = new ProxyInterfaceImpl();
    MastershipProxyManager proxyManager2 = new MastershipProxyManager();
    proxyManager2.clusterService = new ClusterServiceAdapter() {

        @Override
        public ControllerNode getLocalNode() {
            return new DefaultControllerNode(b, IpAddress.valueOf(0));
        }
    };
    proxyManager2.clusterCommunicator = clusterCommunicatorFactory.newCommunicationService(b);
    proxyManager2.mastershipService = new MastershipServiceAdapter() {

        @Override
        public NodeId getMasterFor(DeviceId deviceId) {
            return b;
        }
    };
    proxyManager2.activate();
    proxyManager2.registerProxyService(ProxyInterface.class, proxyInterface2, serializer);
    MastershipProxyFactory<ProxyInterface> proxyFactory1 = proxyManager1.getProxyFactory(ProxyInterface.class, serializer);
    assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).sync("Hello world!"));
    assertEquals(1, proxyInterface2.syncCalls.get());
    assertEquals("Hello world!", proxyFactory1.getProxyFor(deviceId).async("Hello world!").join());
    assertEquals(1, proxyInterface2.asyncCalls.get());
    MastershipProxyFactory<ProxyInterface> proxyFactory2 = proxyManager2.getProxyFactory(ProxyInterface.class, serializer);
    assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).sync("Hello world!"));
    assertEquals(2, proxyInterface2.syncCalls.get());
    assertEquals("Hello world!", proxyFactory2.getProxyFor(deviceId).async("Hello world!").join());
    assertEquals(2, proxyInterface2.asyncCalls.get());
    proxyManager1.deactivate();
    proxyManager2.deactivate();
}
Also used : DeviceId(org.onosproject.net.DeviceId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) Test(org.junit.Test)

Example 4 with ClusterServiceAdapter

use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.

the class PacketManagerTest method setUp.

@Before
public void setUp() {
    mgr = new PacketManager();
    injectEventDispatcher(mgr, new TestEventDispatcher());
    mgr.store = new SimplePacketStore();
    mgr.clusterService = new ClusterServiceAdapter();
    mgr.deviceService = new TestDeviceService();
    mgr.deviceService = new TestDeviceService();
    mgr.coreService = new TestCoreService();
    providerRegistry = mgr;
    mgr.activate();
    DriverRegistryManager driverRegistry = new DriverRegistryManager();
    driverService = new TestDriverManager(driverRegistry);
    driverRegistry.addDriver(new DefaultDriver("foo", ImmutableList.of(), "", "", "", ImmutableMap.of(PacketProgrammable.class, TestPacketProgrammable.class), ImmutableMap.of()));
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DriverRegistryManager(org.onosproject.net.driver.impl.DriverRegistryManager) SimplePacketStore(org.onosproject.store.trivial.SimplePacketStore) Before(org.junit.Before)

Example 5 with ClusterServiceAdapter

use of org.onosproject.cluster.ClusterServiceAdapter in project onos by opennetworkinglab.

the class UpgradeManagerTest method createUpgradeManager.

/**
 * Creates a new upgrade manager to test.
 *
 * @param version the local node version
 * @param state the initial upgrade state
 * @param versions a list of controller node versions
 * @return the activated upgrade manager
 */
@SuppressWarnings("unchecked")
private UpgradeManager createUpgradeManager(Version version, Upgrade state, List<Version> versions) {
    UpgradeManager upgradeManager = new UpgradeManager();
    injectEventDispatcher(upgradeManager, new TestEventDispatcher());
    upgradeManager.membershipService = new MembershipServiceAdapter() {

        @Override
        public MembershipGroup getLocalGroup() {
            return getGroups().stream().filter(group -> group.version().equals(version)).findFirst().get();
        }

        @Override
        public Collection<MembershipGroup> getGroups() {
            AtomicInteger nodeCounter = new AtomicInteger();
            Map<Version, Set<Member>> groups = Maps.newHashMap();
            versions.stream().forEach(version -> {
                groups.computeIfAbsent(version, k -> Sets.newHashSet()).add(new Member(NodeId.nodeId(String.valueOf(nodeCounter.getAndIncrement())), version));
            });
            return Maps.transformEntries(groups, MembershipGroup::new).values();
        }
    };
    upgradeManager.clusterService = new ClusterServiceAdapter() {

        @Override
        public Set<ControllerNode> getNodes() {
            AtomicInteger nodeCounter = new AtomicInteger();
            return versions.stream().map(v -> {
                int nodeId = nodeCounter.getAndIncrement();
                return new DefaultControllerNode(NodeId.nodeId(String.valueOf(nodeId)), IpAddress.valueOf("127.0.0.1"), nodeId);
            }).collect(Collectors.toSet());
        }

        @Override
        public ControllerNode getNode(NodeId nodeId) {
            return getNodes().stream().filter(node -> node.id().equals(nodeId)).findFirst().orElse(null);
        }

        @Override
        public Version getVersion(NodeId nodeId) {
            return versions.get(Integer.parseInt(nodeId.id()));
        }
    };
    upgradeManager.versionService = new VersionServiceAdapter() {

        @Override
        public Version version() {
            return version;
        }
    };
    upgradeManager.coordinationService = new CoordinationServiceAdapter() {

        @Override
        public <V> AtomicValueBuilder<V> atomicValueBuilder() {
            return new AtomicValueBuilder<V>() {

                @Override
                public AsyncAtomicValue<V> build() {
                    return new AsyncAtomicValueAdapter() {

                        @Override
                        public AtomicValue asAtomicValue() {
                            return new AtomicValueAdapter() {

                                private Object value = state;

                                @Override
                                public void set(Object value) {
                                    this.value = value;
                                }

                                @Override
                                public Object get() {
                                    return value;
                                }

                                @Override
                                public boolean compareAndSet(Object expect, Object update) {
                                    if ((value == null && expect == null) || (value != null && value.equals(expect))) {
                                        value = update;
                                        return true;
                                    }
                                    return false;
                                }
                            };
                        }
                    };
                }
            };
        }
    };
    upgradeManager.activate();
    return upgradeManager;
}
Also used : Arrays(java.util.Arrays) NetTestTools.injectEventDispatcher(org.onosproject.net.NetTestTools.injectEventDispatcher) Member(org.onosproject.cluster.Member) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MembershipGroup(org.onosproject.cluster.MembershipGroup) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) AtomicValue(org.onosproject.store.service.AtomicValue) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) Upgrade(org.onosproject.upgrade.Upgrade) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Version(org.onosproject.core.Version) Assert.fail(org.junit.Assert.fail) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) VersionServiceAdapter(org.onosproject.core.VersionServiceAdapter) AtomicValueAdapter(org.onosproject.store.service.AtomicValueAdapter) ClusterEvent(org.onosproject.cluster.ClusterEvent) CoordinationServiceAdapter(org.onosproject.store.service.CoordinationServiceAdapter) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) Sets(com.google.common.collect.Sets) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) MembershipServiceAdapter(org.onosproject.cluster.MembershipServiceAdapter) Set(java.util.Set) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) AtomicValue(org.onosproject.store.service.AtomicValue) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) CoordinationServiceAdapter(org.onosproject.store.service.CoordinationServiceAdapter) Version(org.onosproject.core.Version) Member(org.onosproject.cluster.Member) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) MembershipServiceAdapter(org.onosproject.cluster.MembershipServiceAdapter) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) AtomicValueAdapter(org.onosproject.store.service.AtomicValueAdapter) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) MembershipGroup(org.onosproject.cluster.MembershipGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Collection(java.util.Collection) VersionServiceAdapter(org.onosproject.core.VersionServiceAdapter) Map(java.util.Map)

Aggregations

ClusterServiceAdapter (org.onosproject.cluster.ClusterServiceAdapter)9 Before (org.junit.Before)6 TestEventDispatcher (org.onosproject.common.event.impl.TestEventDispatcher)4 Test (org.junit.Test)3 ControllerNode (org.onosproject.cluster.ControllerNode)2 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)2 NodeId (org.onosproject.cluster.NodeId)2 VirtualNetworkPacketStore (org.onosproject.incubator.net.virtual.VirtualNetworkPacketStore)2 VirtualProviderManager (org.onosproject.incubator.net.virtual.impl.provider.VirtualProviderManager)2 SimpleVirtualFlowObjectiveStore (org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowObjectiveStore)2 SimpleVirtualFlowRuleStore (org.onosproject.incubator.net.virtual.store.impl.SimpleVirtualFlowRuleStore)2 TestStorageService (org.onosproject.store.service.TestStorageService)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1