Search in sources :

Example 31 with NodeId

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

the class ECFlowRuleStore method getTableStatistics.

@Override
public Iterable<TableStatisticsEntry> getTableStatistics(DeviceId deviceId) {
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null && deviceService.isAvailable(deviceId)) {
        log.warn("Failed to getTableStats: No master for {}", deviceId);
        return Collections.emptyList();
    }
    List<TableStatisticsEntry> tableStats = deviceTableStats.get(deviceId);
    if (tableStats == null) {
        return Collections.emptyList();
    }
    return ImmutableList.copyOf(tableStats);
}
Also used : NodeId(org.onosproject.cluster.NodeId) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 32 with NodeId

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

the class ECFlowRuleStore method getFlowRuleCount.

@Override
public int getFlowRuleCount(DeviceId deviceId, FlowEntryState state) {
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null && deviceService.isAvailable(deviceId)) {
        log.warn("Failed to getFlowRuleCount: No master for {}", deviceId);
        return 0;
    }
    if (Objects.equals(local, master) || master == null) {
        return flowTable.getFlowRuleCount(deviceId, state);
    }
    log.trace("Forwarding getFlowRuleCount to master {} for device {}", master, deviceId);
    return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(Pair.of(deviceId, state), GET_DEVICE_FLOW_COUNT, serializer::encode, serializer::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, 0);
}
Also used : NodeId(org.onosproject.cluster.NodeId)

Example 33 with NodeId

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

the class ECFlowRuleStore method getFlowEntry.

@Override
public FlowEntry getFlowEntry(FlowRule rule) {
    NodeId master = mastershipService.getMasterFor(rule.deviceId());
    if (master == null && deviceService.isAvailable(rule.deviceId())) {
        log.warn("Failed to getFlowEntry: No master for {}", rule.deviceId());
        return null;
    }
    if (Objects.equals(local, master) || master == null) {
        return flowTable.getFlowEntry(rule);
    }
    log.trace("Forwarding getFlowEntry to {}, which is the primary (master) for device {}", master, rule.deviceId());
    return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(rule, ECFlowRuleStoreMessageSubjects.GET_FLOW_ENTRY, serializer::encode, serializer::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
}
Also used : NodeId(org.onosproject.cluster.NodeId)

Example 34 with NodeId

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

the class GossipDeviceStore method removeDevice.

@Override
public synchronized DeviceEvent removeDevice(DeviceId deviceId) {
    final NodeId myId = clusterService.getLocalNode().id();
    NodeId master = mastershipService.getMasterFor(deviceId);
    // if there exist a master, forward
    // if there is no master, try to become one and process
    boolean relinquishAtEnd = false;
    if (master == null) {
        final MastershipRole myRole = mastershipService.getLocalRole(deviceId);
        if (myRole != MastershipRole.NONE) {
            relinquishAtEnd = true;
        }
        log.debug("Temporarily requesting role for {} to remove", deviceId);
        if (mastershipService.requestRoleFor(deviceId).join() == MastershipRole.MASTER) {
            master = myId;
        }
    }
    boolean isMaster = myId.equals(master);
    // If this node is not the master, forward the request.
    if (!isMaster) {
        log.debug("{} has control of {}, forwarding remove request", master, deviceId);
        // TODO check unicast return value
        clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master);
    /* error log:
             log.error("Failed to forward {} remove request to {}", deviceId, master, e);
             */
    }
    // If this node is the master, get a timestamp. Otherwise, default to the current device timestamp.
    Timestamp timestamp = isMaster ? deviceClockService.getTimestamp(deviceId) : null;
    DeviceEvent event = removeDeviceInternal(deviceId, timestamp);
    // If this node is the master, update peers.
    if (isMaster && event != null) {
        log.debug("Notifying peers of a device removed topology event for deviceId: {}", deviceId);
        notifyPeers(new InternalDeviceRemovedEvent(deviceId, timestamp));
    }
    notifyDelegateIfNotNull(event);
    // Relinquish mastership if acquired to remove the device.
    if (relinquishAtEnd) {
        log.debug("Relinquishing temporary role acquired for {}", deviceId);
        mastershipService.relinquishMastership(deviceId);
    }
    return event;
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) ControllerNodeToNodeId.toNodeId(org.onosproject.cluster.ControllerNodeToNodeId.toNodeId) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp)

Example 35 with NodeId

use of org.onosproject.cluster.NodeId 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

NodeId (org.onosproject.cluster.NodeId)145 ClusterService (org.onosproject.cluster.ClusterService)36 DeviceId (org.onosproject.net.DeviceId)36 Set (java.util.Set)26 MastershipRole (org.onosproject.net.MastershipRole)23 ControllerNode (org.onosproject.cluster.ControllerNode)22 Test (org.junit.Test)18 Activate (org.osgi.service.component.annotations.Activate)18 List (java.util.List)16 MastershipService (org.onosproject.mastership.MastershipService)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 Map (java.util.Map)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)10 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)10 Component (org.osgi.service.component.annotations.Component)9 Deactivate (org.osgi.service.component.annotations.Deactivate)9