use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class GossipIntentStore method getRandomNode.
private List<NodeId> getRandomNode() {
NodeId me = clusterService.getLocalNode().id();
List<NodeId> nodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(node -> !Objects.equals(node, me)).collect(Collectors.toList());
if (nodes.isEmpty()) {
return ImmutableList.of();
}
return ImmutableList.of(nodes.get(RandomUtils.nextInt(nodes.size())));
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class ECLinkStore method createOrUpdateLink.
@Override
public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) {
final DeviceId dstDeviceId = linkDescription.dst().deviceId();
final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId);
// otherwise signal the actual master.
if (clusterService.getLocalNode().id().equals(dstNodeId)) {
LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst());
Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId);
if (internalLinkKey == null) {
return null;
}
linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription));
return refreshLinkCache(linkKey);
} else {
// Forwarding was added as a workaround for ONOS-490
if (!"cfg".equals(providerId.scheme()) && !"null".equals(providerId.scheme())) {
return null;
}
// Proper fix is to implement forwarding to master on ConfigProvider
if (dstNodeId == null) {
return null;
}
return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId));
}
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class DistributedPacketStore method emit.
@Override
public void emit(OutboundPacket packet) {
NodeId myId = clusterService.getLocalNode().id();
NodeId master = mastershipService.getMasterFor(packet.sendThrough());
if (master == null) {
return;
}
if (myId.equals(master)) {
notifyDelegate(new PacketEvent(Type.EMIT, packet));
return;
}
communicationService.unicast(packet, PACKET_OUT_SUBJECT, SERIALIZER::encode, master).whenComplete((r, error) -> {
if (error != null) {
log.warn("Failed to send packet-out to {}", master, error);
}
});
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class ControlPlaneMonitorTest method setup.
/**
* Sets up the services required by control plane monitor.
*/
@Before
public void setup() {
monitor = new ControlPlaneMonitor();
mockCommunicationService = new ClusterCommunicationServiceAdapter();
monitor.communicationService = mockCommunicationService;
nodeId = new NodeId("1");
mockControllerNode = new MockControllerNode(nodeId);
mockClusterService = createMock(ClusterService.class);
monitor.clusterService = mockClusterService;
expect(mockClusterService.getNode(anyObject())).andReturn(mockControllerNode).anyTimes();
expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
replay(mockClusterService);
monitor.activate();
}
use of org.onosproject.cluster.NodeId in project onos by opennetworkinglab.
the class ControlPlaneMonitorTest method testNetworkMetric.
/**
* Tests network metric update and load function.
*/
@Test
public void testNetworkMetric() {
MetricValue mv = new MetricValue.Builder().load(10).add();
Set<String> set = ImmutableSet.of("eth0", "eth1");
set.forEach(network -> NETWORK_METRICS.forEach(cmt -> testUpdateMetricWithResource(cmt, mv, network)));
set.forEach(network -> NETWORK_METRICS.forEach(cmt -> testLoadMetricWithResource(nodeId, cmt, mv, network)));
}
Aggregations