use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class HostToHostIntentCompiler method createLinkCollectionIntent.
private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
// Try to allocate bandwidth
List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
allocateBandwidth(intent, pathCPs);
Link ingressLink = path.links().get(0);
Link egressLink = path.links().get(path.links().size() - 1);
FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
/*
* The path contains also the edge links, these are not necessary
* for the LinkCollectionIntent.
*/
Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class CompilerRegistry method compile.
/**
* Compiles an intent recursively.
*
* @param intent intent
* @param previousInstallables previous intent installables
* @return result of compilation
*/
List<Intent> compile(Intent intent, List<Intent> previousInstallables) {
if (intent.isInstallable()) {
return ImmutableList.of(intent);
}
// FIXME: get previous resources
List<Intent> installables = new ArrayList<>();
Queue<Intent> compileQueue = new LinkedList<>();
compileQueue.add(intent);
Intent compiling;
while ((compiling = compileQueue.poll()) != null) {
registerSubclassCompilerIfNeeded(compiling);
List<Intent> compiled = getCompiler(compiling).compile(compiling, previousInstallables);
compiled.forEach(i -> {
if (i.isInstallable()) {
installables.add(i);
} else {
compileQueue.add(i);
}
});
}
return installables;
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class ConnectivityIntentCodec method encode.
@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
checkNotNull(intent, "Connectivity intent cannot be null");
final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
final ObjectNode result = intentCodec.encode(intent, context);
if (intent.selector() != null) {
final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
}
if (intent.treatment() != null) {
final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
}
result.put(IntentCodec.PRIORITY, intent.priority());
if (intent.constraints() != null) {
final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
if (intent.constraints() != null) {
final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
for (final Constraint constraint : intent.constraints()) {
final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
jsonConstraints.add(constraintNode);
}
}
}
return result;
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class IntentMonitorAndRerouteManager method startMonitorIntent.
@Override
public synchronized boolean startMonitorIntent(Key intentKey) {
checkNotNull(intentKey, "Intent Key must not be null");
log.debug("Start Monitor Intent: {}", intentKey.toString());
toBeMonitoredIntents.add(intentKey);
// Check if the requested intent is already present in the intent manager
Intent installedIntent = intentService.getIntent(intentKey);
if (!allowedIntent(installedIntent)) {
return false;
}
// Check if the intent that is present in the intent subsystem is already installed
if (intentService.getIntentState(intentKey) == IntentState.INSTALLED) {
storeMonitoredIntent((ConnectivityIntent) installedIntent);
}
return true;
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class IntentSynchronizerTest method testIntentSync.
/**
* Tests the synchronization behavior of intent synchronizer. We set up
* a discrepancy between the intent service state and the intent
* synchronizer's state and ensure that this is reconciled correctly.
*/
@Test
public void testIntentSync() {
// Construct routes and intents.
// This test simulates the following cases during the master change
// time interval:
// 1. intent1 did not change and the intent also did not change.
// 2. intent2 was deleted, but the intent was not deleted.
// 3. intent3 was newly added, and the intent was also submitted.
// 4. intent4 was updated to RouteEntry4Update, and the intent was
// also updated to a new one.
// 5. intent5 did not change, but its intent id changed.
// 6. intent6 was newly added, but the intent was not submitted.
MultiPointToSinglePointIntent intent1 = intentBuilder(Ip4Prefix.valueOf("1.1.1.0/24"), "00:00:00:00:00:01", SW1_ETH1);
MultiPointToSinglePointIntent intent2 = intentBuilder(Ip4Prefix.valueOf("2.2.2.0/24"), "00:00:00:00:00:02", SW2_ETH1);
MultiPointToSinglePointIntent intent3 = intentBuilder(Ip4Prefix.valueOf("3.3.3.0/24"), "00:00:00:00:00:03", SW3_ETH1);
MultiPointToSinglePointIntent intent4 = intentBuilder(Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:03", SW3_ETH1);
MultiPointToSinglePointIntent intent4Update = intentBuilder(Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:02", SW2_ETH1);
MultiPointToSinglePointIntent intent5 = intentBuilder(Ip4Prefix.valueOf("5.5.5.0/24"), "00:00:00:00:00:01", SW1_ETH1);
MultiPointToSinglePointIntent intent7 = intentBuilder(Ip4Prefix.valueOf("7.7.7.0/24"), "00:00:00:00:00:01", SW1_ETH1);
MultiPointToSinglePointIntent intent6 = intentBuilder(Ip4Prefix.valueOf("6.6.6.0/24"), "00:00:00:00:00:01", SW1_ETH1);
// Set up expectation
Set<Intent> intents = new HashSet<>();
intents.add(intent1);
EasyMock.expect(intentService.getIntentState(intent1.key())).andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent2);
EasyMock.expect(intentService.getIntentState(intent2.key())).andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent4);
EasyMock.expect(intentService.getIntentState(intent4.key())).andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent5);
EasyMock.expect(intentService.getIntentState(intent5.key())).andReturn(IntentState.INSTALLED).anyTimes();
intents.add(intent7);
EasyMock.expect(intentService.getIntentState(intent7.key())).andReturn(IntentState.WITHDRAWING).anyTimes();
EasyMock.expect(intentService.getIntents()).andReturn(intents).anyTimes();
// These are the operations that should be done to the intentService
// during synchronization
intentService.withdraw(intent2);
intentService.submit(intent3);
intentService.submit(intent4Update);
intentService.submit(intent6);
intentService.submit(intent7);
EasyMock.replay(intentService);
// Start the test
// Simulate some input from the clients. The intent synchronizer has not
// gained the global leadership yet, but it will remember this input for
// when it does.
intentSynchronizer.submit(intent1);
intentSynchronizer.submit(intent2);
intentSynchronizer.withdraw(intent2);
intentSynchronizer.submit(intent3);
intentSynchronizer.submit(intent4);
intentSynchronizer.submit(intent4Update);
intentSynchronizer.submit(intent5);
intentSynchronizer.submit(intent6);
intentSynchronizer.submit(intent7);
// Give the leadership to the intent synchronizer. It will now attempt
// to synchronize the intents in the store with the intents it has
// recorded based on the earlier user input.
intentSynchronizer.modifyPrimary(true);
EasyMock.verify(intentService);
}
Aggregations