use of org.onosproject.net.intent.constraint.EncapsulationConstraint 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.EncapsulationConstraint 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.EncapsulationConstraint 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);
}
}
}
}
use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.
the class VirtualNetworkIntentManagerTest method testGetIntents.
/**
* Tests the getIntents, getIntent(), getIntentData(), getIntentCount(),
* isLocal() methods.
*/
@Test
public void testGetIntents() {
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 getIntents() method
assertEquals("The intents size did not match as expected.", 1, Iterators.size(vnetIntentService.getIntents().iterator()));
// Test the getIntent() method
assertNotNull("The intent should have been found.", vnetIntentService.getIntent(virtualIntent.key()));
// Test the getIntentData() method
assertEquals("The intent data size did not match as expected.", 1, Iterators.size(vnetIntentService.getIntentData().iterator()));
// Test the getIntentCount() method
assertEquals("The intent count did not match as expected.", 1, vnetIntentService.getIntentCount());
// Test the isLocal() method
assertTrue("The intent should be local.", vnetIntentService.isLocal(virtualIntent.key()));
}
use of org.onosproject.net.intent.constraint.EncapsulationConstraint in project onos by opennetworkinglab.
the class VplsIntentUtility method setEncap.
/**
* Sets one or more encapsulation constraints on the intent builder given.
*
* @param builder the intent builder
* @param constraints the existing intent constraints
* @param encap the encapsulation type to be set
*/
public 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(newConstraints::remove);
// 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