Search in sources :

Example 96 with DeviceId

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));
}
Also used : DeviceId(org.onosproject.net.DeviceId) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode)

Example 97 with DeviceId

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;
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) DeviceId(org.onosproject.net.DeviceId) LabelResourcePool(org.onosproject.incubator.net.resource.label.LabelResourcePool) DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) HashSet(java.util.HashSet)

Example 98 with DeviceId

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;
}
Also used : DefaultLabelResource(org.onosproject.incubator.net.resource.label.DefaultLabelResource) LabelResource(org.onosproject.incubator.net.resource.label.LabelResource) DeviceId(org.onosproject.net.DeviceId) LabelResourceRequest(org.onosproject.incubator.net.resource.label.LabelResourceRequest) Device(org.onosproject.net.Device) NodeId(org.onosproject.cluster.NodeId) Collection(java.util.Collection)

Example 99 with DeviceId

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);
        }
    }
}
Also used : Device(org.onosproject.net.Device) DeviceId(org.onosproject.net.DeviceId)

Example 100 with DeviceId

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);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId)

Aggregations

DeviceId (org.onosproject.net.DeviceId)782 List (java.util.List)178 PortNumber (org.onosproject.net.PortNumber)170 Collectors (java.util.stream.Collectors)152 ConnectPoint (org.onosproject.net.ConnectPoint)152 Set (java.util.Set)138 DeviceService (org.onosproject.net.device.DeviceService)122 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)118 ArrayList (java.util.ArrayList)115 VlanId (org.onlab.packet.VlanId)115 Logger (org.slf4j.Logger)114 Collections (java.util.Collections)109 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)109 Device (org.onosproject.net.Device)107 Collection (java.util.Collection)106 Test (org.junit.Test)104 CoreService (org.onosproject.core.CoreService)103 FlowRule (org.onosproject.net.flow.FlowRule)101 ImmutableSet (com.google.common.collect.ImmutableSet)99 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)96