use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class HostToHostIntentCompilerTest method testBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly.
*/
@Test
public void testBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
final double bpsToReserve = 100.0;
ContinuousResource resourceSw1P1 = Resources.continuous(DID_S1, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw1P2 = Resources.continuous(DID_S1, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P1 = Resources.continuous(DID_S2, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw2P2 = Resources.continuous(DID_S2, PORT_2, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P1 = Resources.continuous(DID_S3, PORT_1, Bandwidth.class).resource(bpsToReserve);
ContinuousResource resourceSw3P2 = Resources.continuous(DID_S3, PORT_2, Bandwidth.class).resource(bpsToReserve);
String[] hops = { HOST_ONE, S1, S2, S3, HOST_TWO };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve)));
final HostToHostIntent intent = makeIntent(HOST_ONE, HOST_TWO, constraints);
HostToHostIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceAllocation rAOne = new ResourceAllocation(resourceSw1P1, intentKey);
ResourceAllocation rATwo = new ResourceAllocation(resourceSw1P2, intentKey);
ResourceAllocation rAThree = new ResourceAllocation(resourceSw2P1, intentKey);
ResourceAllocation rAFour = new ResourceAllocation(resourceSw2P2, intentKey);
ResourceAllocation rAFive = new ResourceAllocation(resourceSw3P1, intentKey);
ResourceAllocation rASix = new ResourceAllocation(resourceSw3P2, intentKey);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class AddMultiPointToSinglePointIntentCommand method doExecute.
@Override
protected void doExecute() {
IntentService service = get(IntentService.class);
if (deviceStrings.length < 2) {
return;
}
String egressDeviceString = deviceStrings[deviceStrings.length - 1];
FilteredConnectPoint egress = new FilteredConnectPoint(ConnectPoint.deviceConnectPoint(egressDeviceString));
Set<FilteredConnectPoint> ingressPoints = new HashSet<>();
for (int index = 0; index < deviceStrings.length - 1; index++) {
String ingressDeviceString = deviceStrings[index];
ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
ingressPoints.add(new FilteredConnectPoint(ingress));
}
TrafficSelector selector = buildTrafficSelector();
TrafficTreatment treatment = buildTrafficTreatment();
List<Constraint> constraints = buildConstraints();
Intent intent = MultiPointToSinglePointIntent.builder().appId(appId()).key(key()).selector(selector).treatment(treatment).filteredIngressPoints(ingressPoints).filteredEgressPoint(egress).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
service.submit(intent);
print("Multipoint to single point intent submitted:\n%s", intent.toString());
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class SimpleFabricForwarding method buildConstraints.
private List<Constraint> buildConstraints(List<Constraint> constraints, EncapsulationType encapsulation) {
if (!encapsulation.equals(EncapsulationType.NONE)) {
List<Constraint> newConstraints = new ArrayList<>(constraints);
constraints.stream().filter(c -> c instanceof EncapsulationConstraint).forEach(newConstraints::remove);
newConstraints.add(new EncapsulationConstraint(encapsulation));
return ImmutableList.copyOf(newConstraints);
}
return constraints;
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class SimpleFabricRouting method buildConstraints.
// constraints generator
private List<Constraint> buildConstraints(List<Constraint> constraints, EncapsulationType encap) {
if (!encap.equals(EncapsulationType.NONE)) {
List<Constraint> newConstraints = new ArrayList<>(constraints);
constraints.stream().filter(c -> c instanceof EncapsulationConstraint).forEach(newConstraints::remove);
newConstraints.add(new EncapsulationConstraint(encap));
return ImmutableList.copyOf(newConstraints);
}
return constraints;
}
use of org.onosproject.net.intent.Constraint in project onos by opennetworkinglab.
the class SdnIpFib method encapUpdate.
/*
* Triggered when the network configuration configuration is modified.
* It checks if the encapsulation type has changed from last time, and in
* case modifies all intents.
*/
private void encapUpdate() {
synchronized (this) {
// Get the encapsulation type just set from the configuration
EncapsulationType encap = encap();
for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) {
// Get each intent currently registered by SDN-IP
MultiPointToSinglePointIntent intent = entry.getValue();
// Make sure the same constraint is not already part of the
// intent constraints
List<Constraint> constraints = intent.constraints();
if (!constraints.stream().filter(c -> c instanceof EncapsulationConstraint && new EncapsulationConstraint(encap).equals(c)).findAny().isPresent()) {
MultiPointToSinglePointIntent.Builder intentBuilder = MultiPointToSinglePointIntent.builder(intent);
// Set the new encapsulation constraint
setEncap(intentBuilder, constraints, encap);
// Build and submit the new intent
MultiPointToSinglePointIntent newIntent = intentBuilder.build();
routeIntents.put(entry.getKey(), newIntent);
intentSynchronizer.submit(newIntent);
}
}
}
}
Aggregations