use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileSingleHopDirectVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and single-hop-direct-link scenario. Ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileSingleHopDirectVlan() {
sut.activate();
List<Intent> compiled = sut.compile(singleHopDirectIntentVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p4.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d2p4.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port()).matchVlanId(ingressVlan).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p5.port()).build()));
Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
sut.deactivate();
}
use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.
the class VirtualNetworkIntentManagerTest method testCreateAndRemoveIntent.
/**
* Tests the submit(), withdraw(), and purge() methods.
*/
@Test
public void testCreateAndRemoveIntent() {
VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
Key intentKey = Key.of("test", APP_ID);
List<Constraint> constraints = new ArrayList<>();
constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(intentKey).appId(APP_ID).ingressPoint(cp1).egressPoint(cp5).constraints(constraints).build();
// Test the submit() method.
vnetIntentService.submit(virtualIntent);
// Wait for the both intents to go into an INSTALLED state.
try {
if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for intent to get installed.");
}
} catch (InterruptedException e) {
fail("Semaphore exception during intent installation." + e.getMessage());
}
// Test the getIntentState() method
assertEquals("The intent state did not match as expected.", IntentState.INSTALLED, vnetIntentService.getIntentState(virtualIntent.key()));
// Test the withdraw() method.
vnetIntentService.withdraw(virtualIntent);
// Wait for the both intents to go into a WITHDRAWN state.
try {
if (!withdrawn.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for intent to get withdrawn.");
}
} catch (InterruptedException e) {
fail("Semaphore exception during intent withdrawal." + e.getMessage());
}
// Test the getIntentState() method
assertEquals("The intent state did not match as expected.", IntentState.WITHDRAWN, vnetIntentService.getIntentState(virtualIntent.key()));
// Test the purge() method.
vnetIntentService.purge(virtualIntent);
// Wait for the both intents to be removed/purged.
try {
if (!purged.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
fail("Failed to wait for intent to get purged.");
}
} catch (InterruptedException e) {
fail("Semaphore exception during intent purging." + e.getMessage());
}
}
use of org.onosproject.net.intent.constraint.EncapsulationConstraint 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.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.
the class SdnIpFib method setEncap.
/**
* Sets an encapsulation constraint to the intent builder given.
*
* @param builder the intent builder
* @param constraints the existing intent constraints
* @param encap the encapsulation type to be set
*/
private static void setEncap(ConnectivityIntent.Builder builder, List<Constraint> constraints, EncapsulationType encap) {
// Constraints might be an immutable list, so a new modifiable list
// is created
List<Constraint> newConstraints = new ArrayList<>(constraints);
// Remove any encapsulation constraint if already in the list
constraints.stream().filter(c -> c instanceof EncapsulationConstraint).forEach(c -> newConstraints.remove(c));
// constraint should be added to the list
if (!encap.equals(NONE)) {
newConstraints.add(new EncapsulationConstraint(encap));
}
// Submit new constraint list as immutable list
builder.constraints(ImmutableList.copyOf(newConstraints));
}
Aggregations