use of org.onosproject.net.DeviceId in project onos by opennetworkinglab.
the class OpenstackNodeManager method updateNode.
@Override
public void updateNode(OpenstackNode osNode) {
checkNotNull(osNode, ERR_NULL_NODE);
OpenstackNode updatedNode;
OpenstackNode existingNode = osNodeStore.node(osNode.hostname());
checkNotNull(existingNode, ERR_NULL_NODE);
DeviceId existDeviceId = osNodeStore.node(osNode.hostname()).intgBridge();
if (vlanIntfChanged(existingNode, osNode) || physicalIntfChanged(existingNode, osNode) || dpdkIntfChanged(existingNode, osNode)) {
removeNode(osNode.hostname());
// we wait 1 second for ovsdb client completely to do removal job
try {
TimeUnit.MILLISECONDS.sleep(1000);
} catch (InterruptedException e) {
log.error("Exception occurred because of {}", e);
}
if (!intfsRemovedFromExistNode(existingNode)) {
log.error("Updated node failed because intfs of existingNode {} " + "are not removed properly", existingNode.toString());
return;
}
createNode(osNode);
return;
}
if (osNode.intgBridge() == null && osNode.type() != CONTROLLER) {
updatedNode = osNode.updateIntbridge(existDeviceId);
checkArgument(!hasIntgBridge(updatedNode.intgBridge(), updatedNode.hostname()), NOT_DUPLICATED_MSG, updatedNode.intgBridge());
} else {
updatedNode = osNode;
checkArgument(!hasIntgBridge(updatedNode.intgBridge(), updatedNode.hostname()), NOT_DUPLICATED_MSG, updatedNode.intgBridge());
}
osNodeStore.updateNode(updatedNode);
log.info(String.format(MSG_NODE, osNode.hostname(), MSG_UPDATED));
}
use of org.onosproject.net.DeviceId in project onos by opennetworkinglab.
the class DistributedLabelResourceStore method internalApply.
private Collection<LabelResource> internalApply(LabelResourceRequest request) {
DeviceId deviceId = request.deviceId();
long applyNum = request.applyNum();
Versioned<LabelResourcePool> poolOld = resourcePool.get(deviceId);
if (poolOld == null) {
log.info("label resource pool not allocated for deviceId {}.", deviceId);
return Collections.emptyList();
}
LabelResourcePool pool = poolOld.value();
Collection<LabelResource> result = new HashSet<>();
long freeNum = this.getFreeNumOfDevicePool(deviceId);
if (applyNum > freeNum) {
log.info("the free number of the label resource pool of deviceId {} is not enough.");
return Collections.emptyList();
}
Set<LabelResource> releaseLabels = new HashSet<>(pool.releaseLabelId());
long tmp = releaseLabels.size() > applyNum ? applyNum : releaseLabels.size();
LabelResource resource = null;
for (int i = 0; i < tmp; i++) {
Iterator<LabelResource> it = releaseLabels.iterator();
if (it.hasNext()) {
resource = it.next();
releaseLabels.remove(resource);
}
result.add(resource);
}
for (long j = pool.currentUsedMaxLabelId().labelId(); j < pool.currentUsedMaxLabelId().labelId() + applyNum - tmp; j++) {
resource = new DefaultLabelResource(deviceId, LabelResourceId.labelResourceId(j));
result.add(resource);
}
long beginLabel = pool.beginLabel().labelId();
long endLabel = pool.endLabel().labelId();
long totalNum = pool.totalNum();
long current = pool.currentUsedMaxLabelId().labelId() + applyNum - tmp;
long usedNum = pool.usedNum() + applyNum;
ImmutableSet<LabelResource> freeLabel = ImmutableSet.copyOf(releaseLabels);
LabelResourcePool newPool = new LabelResourcePool(deviceId.toString(), beginLabel, endLabel, totalNum, usedNum, current, freeLabel);
resourcePool.put(deviceId, newPool);
log.info("success to apply label resource");
return result;
}
use of org.onosproject.net.DeviceId in project onos by opennetworkinglab.
the class DistributedLabelResourceStore method releaseToDevicePool.
@Override
public boolean releaseToDevicePool(Multimap<DeviceId, LabelResource> release) {
Map<DeviceId, Collection<LabelResource>> maps = release.asMap();
Set<DeviceId> deviceIdSet = maps.keySet();
LabelResourceRequest request = null;
for (Iterator<DeviceId> it = deviceIdSet.iterator(); it.hasNext(); ) {
DeviceId deviceId = it.next();
Device device = deviceService.getDevice(deviceId);
if (device == null) {
continue;
}
ImmutableSet<LabelResource> collection = ImmutableSet.copyOf(maps.get(deviceId));
request = new LabelResourceRequest(deviceId, LabelResourceRequest.Type.RELEASE, 0, collection);
NodeId master = mastershipService.getMasterFor(deviceId);
if (master == null) {
log.warn("Failed to releaseToDevicePool: No master for {}", deviceId);
return false;
}
if (master.equals(clusterService.getLocalNode().id())) {
return internalRelease(request);
}
log.trace("Forwarding request to {}, which is the primary (master) for device {}", master, deviceId);
return complete(clusterCommunicator.sendAndReceive(request, LabelResourceMessageSubjects.LABEL_POOL_RELEASE, SERIALIZER::encode, SERIALIZER::decode, master));
}
return false;
}
use of org.onosproject.net.DeviceId in project onos by opennetworkinglab.
the class ScaleTestManager method adjustFlows.
private void adjustFlows() {
int deviceCount = deviceService.getAvailableDeviceCount();
if (deviceCount == 0) {
return;
}
int flowsPerDevice = flowCount / deviceCount;
for (Device device : deviceService.getAvailableDevices()) {
DeviceId id = device.id();
if (deviceService.getRole(id) != MastershipRole.MASTER || flowsPerDevice == 0) {
continue;
}
int currentFlowCount = flowRuleService.getFlowRuleCount(id);
if (flowsPerDevice > currentFlowCount) {
addMoreFlows(flowsPerDevice, device, id, currentFlowCount);
} else if (flowsPerDevice < currentFlowCount) {
removeExcessFlows(flowsPerDevice, id, currentFlowCount);
}
}
}
use of org.onosproject.net.DeviceId in project onos by opennetworkinglab.
the class ProxyTestCommand method doExecute.
@Override
protected void doExecute() {
ProxyTest proxyTest = get(ProxyTest.class);
TestProxy proxy;
if ("node".equals(type)) {
NodeId nodeId = NodeId.nodeId(arg1);
proxy = proxyTest.getProxyFor(nodeId);
} else if ("master".equals(type)) {
DeviceId deviceId = DeviceId.deviceId(arg1);
proxy = proxyTest.getProxyFor(deviceId);
} else {
throw new IllegalArgumentException("Unknown operation type " + type);
}
if ("sync".equals(operation)) {
print("%s", proxy.testSync(arg2));
} else if ("async".equals(operation)) {
try {
print("%s", proxy.testAsync(arg2).get(10, TimeUnit.SECONDS));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new IllegalStateException(e);
}
} else {
throw new IllegalArgumentException("Unknown operation " + operation);
}
}
Aggregations