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