Search in sources :

Example 96 with NodeId

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

the class DistributedVirtualFlowRuleStore method getTableStatistics.

@Override
public Iterable<TableStatisticsEntry> getTableStatistics(NetworkId networkId, DeviceId deviceId) {
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.debug("Failed to getTableStats: No master for {}", deviceId);
        return Collections.emptyList();
    }
    if (deviceTableStats.get(networkId) == null) {
        deviceTableStats.put(networkId, Maps.newConcurrentMap());
    }
    List<TableStatisticsEntry> tableStats = deviceTableStats.get(networkId).get(deviceId);
    if (tableStats == null) {
        return Collections.emptyList();
    }
    return ImmutableList.copyOf(tableStats);
}
Also used : NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 97 with NodeId

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

the class DistributedVirtualFlowRuleStore method removeFlowRule.

@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
    final DeviceId deviceId = rule.deviceId();
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (Objects.equals(local, master)) {
        // bypass and handle it locally
        return removeFlowRuleInternal(new VirtualFlowEntry(networkId, rule));
    }
    if (master == null) {
        log.warn("Failed to removeFlowRule: No master for {}", deviceId);
        // TODO: revisit if this should be null (="no-op") or Exception
        return null;
    }
    log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", master, deviceId);
    return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new VirtualFlowEntry(networkId, rule), REMOVE_FLOW_ENTRY, serializer::encode, serializer::decode, master));
}
Also used : VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) VirtualFlowEntry(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowEntry) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService)

Example 98 with NodeId

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

the class DistributedVirtualFlowRuleStore method getFlowEntry.

@Override
public FlowEntry getFlowEntry(NetworkId networkId, FlowRule rule) {
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(rule.deviceId());
    if (master == null) {
        log.debug("Failed to getFlowEntry: No master for {}, vnet {}", rule.deviceId(), networkId);
        return null;
    }
    if (Objects.equals(local, master)) {
        return flowTable.getFlowEntry(networkId, rule);
    }
    log.trace("Forwarding getFlowEntry to {}, which is the primary (master) " + "for device {}, vnet {}", master, rule.deviceId(), networkId);
    VirtualFlowRule vRule = new VirtualFlowRule(networkId, rule);
    return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(vRule, GET_FLOW_ENTRY, serializer::encode, serializer::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
}
Also used : NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) VirtualFlowRule(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRule)

Example 99 with NodeId

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

the class SimpleVirtualMastershipStore method getMastership.

@Override
public MastershipInfo getMastership(NetworkId networkId, DeviceId deviceId) {
    Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
    Map<DeviceId, AtomicInteger> termMap = getTermMap(networkId);
    Map<DeviceId, List<NodeId>> backups = getBackups(networkId);
    ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
    NodeId master = masterMap.get(deviceId);
    if (master != null) {
        roleBuilder.put(master, MastershipRole.MASTER);
    }
    backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
    clusterService.getNodes().stream().filter(node -> !masterMap.containsValue(node.id())).filter(node -> !backups.get(deviceId).contains(node.id())).forEach(node -> roleBuilder.put(node.id(), MastershipRole.NONE));
    return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
Also used : HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MastershipEvent(org.onosproject.mastership.MastershipEvent) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Node(org.onosproject.cluster.Node) VersionService(org.onosproject.core.VersionService) BACKUPS_CHANGED(org.onosproject.mastership.MastershipEvent.Type.BACKUPS_CHANGED) Map(java.util.Map) Version(org.onosproject.core.Version) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MASTER_CHANGED(org.onosproject.mastership.MastershipEvent.Type.MASTER_CHANGED) ImmutableMap(com.google.common.collect.ImmutableMap) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) VirtualNetworkMastershipStore(org.onosproject.incubator.net.virtual.VirtualNetworkMastershipStore) MastershipInfo(org.onosproject.mastership.MastershipInfo) Set(java.util.Set) Instant(java.time.Instant) MastershipTerm(org.onosproject.mastership.MastershipTerm) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RoleInfo(org.onosproject.cluster.RoleInfo) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) MastershipStoreDelegate(org.onosproject.mastership.MastershipStoreDelegate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) MastershipInfo(org.onosproject.mastership.MastershipInfo) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MastershipRole(org.onosproject.net.MastershipRole) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 100 with NodeId

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

the class SimpleVirtualMastershipStore method createFakeClusterService.

/**
 * Returns a fake cluster service for a test purpose only.
 *
 * @return a fake cluster service
 */
private ClusterService createFakeClusterService() {
    // just for ease of unit test
    final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
    ClusterService faceClusterService = 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 ControllerNode.State getState(NodeId nodeId) {
            if (instance.id().equals(nodeId)) {
                return ControllerNode.State.ACTIVE;
            } else {
                return ControllerNode.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) {
        }
    };
    return faceClusterService;
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) Instant(java.time.Instant) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) Node(org.onosproject.cluster.Node) 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)

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