Search in sources :

Example 6 with DefaultControllerNode

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

the class SimpleMastershipStore method activate.

@Activate
public void activate() {
    if (clusterService == null) {
        // just for ease of unit test
        final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
        clusterService = new ClusterService() {

            private final Instant creationTime = Instant.now();

            @Override
            public ControllerNode getLocalNode() {
                return instance;
            }

            @Override
            public Set<ControllerNode> getNodes() {
                return ImmutableSet.of(instance);
            }

            @Override
            public Set<Node> getConsensusNodes() {
                return ImmutableSet.of();
            }

            @Override
            public ControllerNode getNode(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return instance;
                }
                return null;
            }

            @Override
            public State getState(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return State.ACTIVE;
                } else {
                    return State.INACTIVE;
                }
            }

            @Override
            public Version getVersion(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return versionService.version();
                }
                return null;
            }

            @Override
            public Instant getLastUpdatedInstant(NodeId nodeId) {
                return creationTime;
            }

            @Override
            public void addListener(ClusterEventListener listener) {
            }

            @Override
            public void removeListener(ClusterEventListener listener) {
            }
        };
    }
    log.info("Started");
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Version(org.onosproject.core.Version) State(org.onosproject.cluster.ControllerNode.State) Instant(java.time.Instant) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) Activate(org.osgi.service.component.annotations.Activate)

Example 7 with DefaultControllerNode

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

the class DefaultClusterMetadataProvider method activate.

@Activate
public void activate() {
    String localIp = getSiteLocalAddress();
    ControllerNode localNode = new DefaultControllerNode(new NodeId(localIp), IpAddress.valueOf(localIp), DEFAULT_ONOS_PORT);
    ClusterMetadata metadata = new ClusterMetadata(PROVIDER_ID, "default", localNode, ImmutableSet.of(), ImmutableSet.of(), UUID.randomUUID().toString());
    long version = System.currentTimeMillis();
    cachedMetadata.set(new Versioned<>(metadata, version));
    providerRegistry.register(this);
    log.info("Started");
}
Also used : ClusterMetadata(org.onosproject.cluster.ClusterMetadata) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Activate(org.osgi.service.component.annotations.Activate)

Example 8 with DefaultControllerNode

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

the class SimpleClusterStore method activate.

@Activate
public void activate() {
    instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST);
    listenerRegistry = new ListenerRegistry<>();
    eventDispatcher.addSink(WorkPartitionEvent.class, listenerRegistry);
    log.info("Started");
}
Also used : NodeId(org.onosproject.cluster.NodeId) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Activate(org.osgi.service.component.annotations.Activate)

Example 9 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project trellis-control by opennetworkinglab.

the class DefaultRoutingHandlerTest method testShouldHandleRoutingCase1.

// Node 1 is the leader of switch 1A, 1B, and 2
@Test
public void testShouldHandleRoutingCase1() {
    expect(mockWps.leadershipService.getLeadership(DEV1A_PARTITION_ID)).andReturn(new Leadership(DEV1A_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    expect(mockWps.leadershipService.getLeadership(DEV1B_PARTITION_ID)).andReturn(new Leadership(DEV1B_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    expect(mockWps.leadershipService.getLeadership(DEV2_PARTITION_ID)).andReturn(new Leadership(DEV2_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    replay(mockWps.leadershipService);
    expect(srManager.getPairDeviceId(DEV1A)).andReturn(Optional.of(DEV1B)).anyTimes();
    expect(srManager.getPairDeviceId(DEV1B)).andReturn(Optional.of(DEV1A)).anyTimes();
    expect(srManager.getPairDeviceId(DEV2)).andReturn(Optional.empty()).anyTimes();
    replay(srManager);
    // Node 1 should program every device
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE1, IP1)).anyTimes();
    replay(srManager.clusterService);
    // shouldProgram is initially empty
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertTrue(dfh.shouldProgram(DEV1A));
    assertTrue(dfh.shouldProgram(DEV1B));
    assertTrue(dfh.shouldProgram(DEV2));
    assertEquals(NODE1, dfh.shouldProgram.get(DEV1A));
    assertEquals(NODE1, dfh.shouldProgram.get(DEV1B));
    assertEquals(NODE1, dfh.shouldProgram.get(DEV2));
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 2 should program no device
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE2, IP2)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertFalse(dfh.shouldProgram(DEV1A));
    assertFalse(dfh.shouldProgram(DEV1B));
    assertFalse(dfh.shouldProgram(DEV2));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV1A));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV1B));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV2));
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 3 should program no device
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE3, IP3)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertFalse(dfh.shouldProgram(DEV1A));
    assertFalse(dfh.shouldProgram(DEV1B));
    assertFalse(dfh.shouldProgram(DEV2));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1A));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1B));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV2));
}
Also used : Leadership(org.onosproject.cluster.Leadership) Leader(org.onosproject.cluster.Leader) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Test(org.junit.Test)

Example 10 with DefaultControllerNode

use of org.onosproject.cluster.DefaultControllerNode in project trellis-control by opennetworkinglab.

the class DefaultRoutingHandlerTest method testShouldHandleRoutingCase4.

/*
     * Node 2 is the leader of switch 1A, 1B and Node 3 is the leader of 2.
     * Later on, node 1 becomes the leader of 1A, 1B
     */
@Test
public void testShouldHandleRoutingCase4() {
    expect(mockWps.leadershipService.getLeadership(DEV1A_PARTITION_ID)).andReturn(new Leadership(DEV1A_PARTITION_ID, new Leader(NODE2, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    expect(mockWps.leadershipService.getLeadership(DEV1B_PARTITION_ID)).andReturn(new Leadership(DEV1B_PARTITION_ID, new Leader(NODE2, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    expect(mockWps.leadershipService.getLeadership(DEV2_PARTITION_ID)).andReturn(new Leadership(DEV2_PARTITION_ID, new Leader(NODE3, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    replay(mockWps.leadershipService);
    expect(srManager.getPairDeviceId(DEV1A)).andReturn(Optional.of(DEV1B)).anyTimes();
    expect(srManager.getPairDeviceId(DEV1B)).andReturn(Optional.of(DEV1A)).anyTimes();
    expect(srManager.getPairDeviceId(DEV2)).andReturn(Optional.empty()).anyTimes();
    replay(srManager);
    // Node 1 should program no device
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE1, IP1)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertFalse(dfh.shouldProgram(DEV1A));
    assertFalse(dfh.shouldProgram(DEV1B));
    assertFalse(dfh.shouldProgram(DEV2));
    assertNotEquals(NODE1, dfh.shouldProgram.get(DEV1A));
    assertNotEquals(NODE1, dfh.shouldProgram.get(DEV1B));
    assertNotEquals(NODE1, dfh.shouldProgram.get(DEV2));
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 2 should program 1A and 1B
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE2, IP2)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertTrue(dfh.shouldProgram(DEV1A));
    assertTrue(dfh.shouldProgram(DEV1B));
    assertFalse(dfh.shouldProgram(DEV2));
    assertEquals(NODE2, dfh.shouldProgram.get(DEV1A));
    assertEquals(NODE2, dfh.shouldProgram.get(DEV1B));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV2));
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 3 should program 2
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE3, IP3)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertFalse(dfh.shouldProgram(DEV1A));
    assertFalse(dfh.shouldProgram(DEV1B));
    assertTrue(dfh.shouldProgram(DEV2));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1A));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1B));
    assertEquals(NODE3, dfh.shouldProgram.get(DEV2));
    // Partition of switch 1A moves to Node 1. This can happen for a cluster event
    reset(mockWps.leadershipService);
    expect(mockWps.leadershipService.getLeadership(DEV1A_PARTITION_ID)).andReturn(new Leadership(DEV1A_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    expect(mockWps.leadershipService.getLeadership(DEV1B_PARTITION_ID)).andReturn(new Leadership(DEV1B_PARTITION_ID, new Leader(NODE1, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    expect(mockWps.leadershipService.getLeadership(DEV2_PARTITION_ID)).andReturn(new Leadership(DEV2_PARTITION_ID, new Leader(NODE3, 0, 0), List.of(NODE2, NODE3))).anyTimes();
    replay(mockWps.leadershipService);
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 1 should program 1A, 1B
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE1, IP1)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertTrue(dfh.shouldProgram(DEV1A));
    assertTrue(dfh.shouldProgram(DEV1B));
    assertFalse(dfh.shouldProgram(DEV2));
    assertEquals(NODE1, dfh.shouldProgram.get(DEV1A));
    assertEquals(NODE1, dfh.shouldProgram.get(DEV1B));
    assertNotEquals(NODE1, dfh.shouldProgram.get(DEV2));
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 2 should program no device
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE2, IP2)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertFalse(dfh.shouldProgram(DEV1A));
    assertFalse(dfh.shouldProgram(DEV1B));
    assertFalse(dfh.shouldProgram(DEV2));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV1A));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV1B));
    assertNotEquals(NODE2, dfh.shouldProgram.get(DEV2));
    reset(srManager.clusterService);
    clearShouldProgram();
    // Node 3 should program 2
    expect(srManager.clusterService.getLocalNode()).andReturn(new DefaultControllerNode(NODE3, IP3)).anyTimes();
    replay(srManager.clusterService);
    assertNull(dfh.shouldProgram.get(DEV1A));
    assertNull(dfh.shouldProgram.get(DEV1B));
    assertNull(dfh.shouldProgram.get(DEV2));
    assertFalse(dfh.shouldProgram(DEV1A));
    assertFalse(dfh.shouldProgram(DEV1B));
    assertTrue(dfh.shouldProgram(DEV2));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1A));
    assertNotEquals(NODE3, dfh.shouldProgram.get(DEV1B));
    assertEquals(NODE3, dfh.shouldProgram.get(DEV2));
}
Also used : Leadership(org.onosproject.cluster.Leadership) Leader(org.onosproject.cluster.Leader) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Test(org.junit.Test)

Aggregations

DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)16 NodeId (org.onosproject.cluster.NodeId)9 Test (org.junit.Test)7 ControllerNode (org.onosproject.cluster.ControllerNode)7 Leader (org.onosproject.cluster.Leader)5 Leadership (org.onosproject.cluster.Leadership)5 Activate (org.osgi.service.component.annotations.Activate)5 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)3 ClusterMetadata (org.onosproject.cluster.ClusterMetadata)3 Sets (com.google.common.collect.Sets)2 InetAddress (java.net.InetAddress)2 URL (java.net.URL)2 ClusterMetadataProvider (org.onosproject.cluster.ClusterMetadataProvider)2 ClusterMetadataProviderRegistry (org.onosproject.cluster.ClusterMetadataProviderRegistry)2 ClusterMetadataProviderService (org.onosproject.cluster.ClusterMetadataProviderService)2 ClusterService (org.onosproject.cluster.ClusterService)2 ClusterServiceAdapter (org.onosproject.cluster.ClusterServiceAdapter)2 Node (org.onosproject.cluster.Node)2 PartitionId (org.onosproject.cluster.PartitionId)2