use of org.onosproject.net.resource.ContinuousResource in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenLargeResourceIsRequested.
@Test
public void testHasEnoughResourceWhenLargeResourceIsRequested() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(600).bps());
assertThat(sut.hasEnoughResource(request), is(false));
}
use of org.onosproject.net.resource.ContinuousResource in project onos by opennetworkinglab.
the class LinkPropsTopovMessageHandler method getBandwidth.
/**
* Gets the links connected to the highlighted device.
* Creates a ContinuousResource object for each link
* and gets the bandwidth of the link from the query
* and sets the label of the link as the bandwidth value.
*/
private Highlights getBandwidth(Set<Link> links, DeviceId devId) {
LpLinkMap linkMap = new LpLinkMap();
Highlights highlights = new Highlights();
if (links != null) {
log.debug("Processing {} links", links.size());
links.forEach(linkMap::add);
PortNumber portnum = PortNumber.portNumber((int) links.iterator().next().src().port().toLong());
for (LpLink dlink : linkMap.biLinks()) {
DiscreteResourceId parent = Resources.discrete(devId, portnum).id();
ContinuousResource continuousResource = (ContinuousResource) resourceQueryService.getAvailableResources(parent, Bandwidth.class).iterator().next();
double availBandwidth = continuousResource.value();
dlink.makeImportant().setLabel(Double.toString(availBandwidth) + " bytes/s");
highlights.add(dlink.highlight(null));
}
} else {
log.debug("No egress links found for device {}", devId);
}
return highlights;
}
use of org.onosproject.net.resource.ContinuousResource in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenSmallResourceIsRequested.
@Test
public void testHasEnoughResourceWhenSmallResourceIsRequested() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(200).bps());
assertThat(sut.hasEnoughResource(request), is(true));
}
use of org.onosproject.net.resource.ContinuousResource in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testAllocateSameValue.
@Test
public void testAllocateSameValue() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).bps());
ResourceConsumer consumer = IntentId.valueOf(1);
ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).bps());
ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
assertThat(newValue.allocations().size(), is(2));
assertThat(newValue.allocations().stream().allMatch(x -> x.equals(new ResourceAllocation(allocated, consumer))), is(true));
}
use of org.onosproject.net.resource.ContinuousResource in project onos by opennetworkinglab.
the class ContinuousResourceAllocationTest method testNoAllocationHasEnoughResource.
@Test
public void testNoAllocationHasEnoughResource() {
ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
ContinuousResourceAllocation sut = ContinuousResourceAllocation.empty(original);
ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(100).bps());
assertThat(sut.hasEnoughResource(request), is(true));
}
Aggregations