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);
}
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));
}
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);
}
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());
}
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;
}
Aggregations