use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.
the class OpticalPathProvisionerTest method testSetupPath.
/**
* Checks setupPath method works.
*/
@Test
public void testSetupPath() {
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
Path path = new DefaultPath(PROVIDER_ID, links, new ScalarWeight(0));
OpticalConnectivityId cid = target.setupPath(path, bandwidth, latency);
assertNotNull(cid);
// 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 testRemoveConnectivity.
/**
* Checks removeConnectivity method works.
*/
@Test
public void testRemoveConnectivity() {
Bandwidth bandwidth = Bandwidth.bps(100);
Duration latency = Duration.ofMillis(10);
OpticalConnectivityId cid = target.setupConnectivity(CP12, CP71, bandwidth, latency);
// Checks intents are withdrawn
assertTrue(target.removeConnectivity(cid));
assertEquals(1, intentService.withdrawn.size());
assertEquals(OpticalConnectivityIntent.class, intentService.withdrawn.get(0).getClass());
OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.withdrawn.get(0);
assertEquals(CP31, connIntent.getSrc());
assertEquals(CP52, connIntent.getDst());
}
use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.
the class ConnectivityIntentCommand method buildConstraints.
/**
* Builds the constraint list for this command based on the command line
* parameters.
*
* @return List of constraint objects describing the constraints requested
*/
protected List<Constraint> buildConstraints() {
final List<Constraint> constraints = new LinkedList<>();
// Check for a bandwidth specification
if (!isNullOrEmpty(bandwidthString)) {
Bandwidth bandwidth;
try {
bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
// when the string can't be parsed as long, then try to parse as double
} catch (NumberFormatException e) {
bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
}
constraints.add(new BandwidthConstraint(bandwidth));
}
// Check for partial failure specification
if (partial) {
constraints.add(new PartialFailureConstraint());
}
// Check for encapsulation specification
if (!isNullOrEmpty(encapsulationString)) {
final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
constraints.add(new EncapsulationConstraint(encapType));
}
// Check for hashed path selection
if (hashedPathSelection) {
constraints.add(new HashedPathSelectionConstraint());
}
// Check for domain processing
if (domains) {
constraints.add(DomainConstraint.domain());
}
// Check for a latency specification
if (!isNullOrEmpty(latConstraint)) {
try {
long lat = Long.parseLong(latConstraint);
constraints.add(new LatencyConstraint(Duration.of(lat, ChronoUnit.NANOS)));
} catch (NumberFormatException e) {
double lat = Double.parseDouble(latConstraint);
constraints.add(new LatencyConstraint(Duration.of((long) lat, ChronoUnit.NANOS)));
}
}
return constraints;
}
use of org.onlab.util.Bandwidth in project onos by opennetworkinglab.
the class ResourceDeviceListener method registerPortResource.
private void registerPortResource(Device device, Port port) {
Resource portPath = Resources.discrete(device.id(), port.number()).resource();
if (!adminService.register(portPath)) {
log.error("Failed to register Port: {}", portPath.id());
}
queryBandwidth(device.id(), port.number()).map(bw -> portPath.child(Bandwidth.class, bw.bps())).map(adminService::register).ifPresent(success -> {
if (!success) {
log.error("Failed to register Bandwidth for {}", portPath.id());
}
});
// for VLAN IDs
Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
if (!vlans.isEmpty()) {
boolean success = adminService.register(vlans.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register VLAN IDs for {}", portPath.id());
}
}
// for MPLS labels
Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
if (!mplsLabels.isEmpty()) {
boolean success = adminService.register(mplsLabels.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register MPLS Labels for {}", portPath.id());
}
}
// for Lambdas
Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
if (!lambdas.isEmpty()) {
boolean success = adminService.register(lambdas.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register lambdas for {}", portPath.id());
}
}
// for Tributary slots
Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
if (!tSlots.isEmpty()) {
boolean success = adminService.register(tSlots.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register tributary slots for {}", portPath.id());
}
}
}
Aggregations