Search in sources :

Example 6 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class ServerQueueConfig method getQueues.

@Override
public Collection<QueueDescription> getQueues() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Get the device
    RestSBDevice device = super.getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides queue administration
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_NIC_QUEUE_ADMIN, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // Load the JSON into object
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (objNode == null) {
        log.error("Failed to get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    Collection<QueueDescription> queueDescs = Sets.newHashSet();
    // Fetch NICs' array
    JsonNode nicsNode = objNode.path(PARAM_NICS);
    for (JsonNode nn : nicsNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        int nicId = nicObjNode.path(PARAM_ID).asInt();
        JsonNode queuesNode = nicObjNode.path(PARAM_QUEUES);
        // Each NIC has a set of queues
        for (JsonNode qn : queuesNode) {
            ObjectNode queueObjNode = (ObjectNode) qn;
            // Get the attributes of a queue
            int queueIdInt = queueObjNode.path(PARAM_ID).asInt();
            String queueTypeStr = get(qn, PARAM_TYPE);
            long queueRateInt = queueObjNode.path(PARAM_NIC_MAX_RATE).asLong();
            QueueId queueId = QueueId.queueId("nic" + nicId + ":" + queueIdInt);
            EnumSet<Type> queueTypes = getQueueTypesFromString(queueTypeStr);
            Bandwidth queueRate = Bandwidth.mbps(queueRateInt);
            queueDescs.add(DefaultQueueDescription.builder().queueId(queueId).type(queueTypes).maxRate(queueRate).build());
        }
    }
    log.info("[Device {}] NIC queues: {}", deviceId, queueDescs);
    return ImmutableList.copyOf(queueDescs);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) QueueId(org.onosproject.net.behaviour.QueueId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultQueueDescription(org.onosproject.net.behaviour.DefaultQueueDescription) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Type(org.onosproject.net.behaviour.QueueDescription.Type) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Bandwidth(org.onlab.util.Bandwidth) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 7 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalPathProvisioner method setupConnectivity.

/*
     * Request packet-layer connectivity between specified ports,
     * over packet-optical multi-layer infrastructure.
     *
     * Functionality-wise this is effectively submitting Packet-Optical
     * multi-layer P2P Intent.
     *
     * It computes multi-layer path meeting specified constraint,
     * and calls setupPath.
     */
@Override
public OpticalConnectivityId setupConnectivity(ConnectPoint ingress, ConnectPoint egress, Bandwidth bandwidth, Duration latency) {
    checkNotNull(ingress);
    checkNotNull(egress);
    log.info("setupConnectivity({}, {}, {}, {})", ingress, egress, bandwidth, latency);
    Bandwidth bw = (bandwidth == null) ? NO_BW_REQUIREMENT : bandwidth;
    Stream<Path> paths = topologyService.getKShortestPaths(topologyService.currentTopology(), ingress.deviceId(), egress.deviceId(), new BandwidthLinkWeight(bandwidth));
    // Path service calculates from node to node, we're only interested in port to port
    Optional<OpticalConnectivityId> id = paths.filter(p -> p.src().equals(ingress) && p.dst().equals(egress)).limit(maxPaths).map(p -> setupPath(p, bw, latency)).filter(Objects::nonNull).findFirst();
    if (id.isPresent()) {
        log.info("Assigned OpticalConnectivityId: {}", id);
    } else {
        log.error("setupConnectivity({}, {}, {}, {}) failed.", ingress, egress, bandwidth, latency);
    }
    return id.orElse(null);
}
Also used : Path(org.onosproject.net.Path) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth)

Example 8 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalPathProvisionerTest method testSetupConnectivity.

/**
 * Checks setupConnectivity method works.
 */
@Test
public void testSetupConnectivity() {
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
    assertNotNull(cid);
    // Checks path computation is called as expected
    assertEquals(1, topologyService.edges.size());
    assertEquals(CP12.deviceId(), topologyService.edges.get(0).getKey());
    assertEquals(CP71.deviceId(), topologyService.edges.get(0).getValue());
    // Checks intents are installed as expected
    assertEquals(1, intentService.submitted.size());
    assertEquals(OpticalConnectivityIntent.class, intentService.submitted.get(0).getClass());
    OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.submitted.get(0);
    assertEquals(CP31, connIntent.getSrc());
    assertEquals(CP52, connIntent.getDst());
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Duration(java.time.Duration) Test(org.junit.Test)

Example 9 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalPathProvisionerTest method testInstalledEventRemote.

/**
 * Checks if PATH_INSTALLED event comes up after intent whose master is remote node is installed.
 */
@Test
public void testInstalledEventRemote() {
    // set the master for ingress device of intent to remote node
    mastershipService.setMastership(DEVICE2.id(), MastershipRole.NONE);
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
    // notify all intents are installed
    intentService.notifyInstalled();
    // remote nodes must not receive event before distributed map is updated
    assertEquals(0, listener.events.size());
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Duration(java.time.Duration) Test(org.junit.Test)

Example 10 with Bandwidth

use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.

the class OpticalPathProvisionerTest method testGetPath.

/**
 * Checks getPath method works.
 */
@Test
public void testGetPath() {
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
    OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
    Optional<List<Link>> path = target.getPath(cid);
    // Checks returned path is as expected
    assertTrue(path.isPresent());
    assertEquals(links, path.get());
}
Also used : OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) Duration(java.time.Duration) ArrayList(java.util.ArrayList) List(java.util.List) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link) Test(org.junit.Test)

Aggregations

Bandwidth (org.onlab.util.Bandwidth)24 Test (org.junit.Test)15 OpticalConnectivityId (org.onosproject.newoptical.api.OpticalConnectivityId)14 Duration (java.time.Duration)12 ConnectPoint (org.onosproject.net.ConnectPoint)10 Link (org.onosproject.net.Link)6 DefaultLink (org.onosproject.net.DefaultLink)5 Key (org.onosproject.net.intent.Key)5 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)5 ContinuousResource (org.onosproject.net.resource.ContinuousResource)5 Path (org.onosproject.net.Path)4 Constraint (org.onosproject.net.intent.Constraint)4 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)4 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)4 ResourceService (org.onosproject.net.resource.ResourceService)4 List (java.util.List)3 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)3 MockResourceService (org.onosproject.net.resource.MockResourceService)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2