use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class VplsIntentUtility method buildBrcIntents.
/**
* Builds broadcast Intents for a VPLS.
*
* @param vplsData the VPLS
* @param appId the application id for Intents
* @return broadcast Intents for the VPLS
*/
public static Set<Intent> buildBrcIntents(VplsData vplsData, ApplicationId appId) {
Set<Interface> interfaces = vplsData.interfaces();
// At least two or more network interfaces to build broadcast Intents
if (interfaces.size() < 2) {
return ImmutableSet.of();
}
Set<Intent> brcIntents = Sets.newHashSet();
ResourceGroup resourceGroup = ResourceGroup.of(vplsData.name());
// Generates broadcast Intents from any network interface to other
// network interface from the VPLS.
interfaces.forEach(src -> {
FilteredConnectPoint srcFcp = VplsIntentUtility.buildFilteredConnectedPoint(src);
Set<FilteredConnectPoint> dstFcps = interfaces.stream().filter(iface -> !iface.equals(src)).map(VplsIntentUtility::buildFilteredConnectedPoint).collect(Collectors.toSet());
Key key = VplsIntentUtility.buildKey(PREFIX_BROADCAST, srcFcp.connectPoint(), vplsData.name(), MacAddress.BROADCAST, appId);
Intent brcIntent = buildBrcIntent(key, appId, srcFcp, dstFcps, vplsData.encapsulationType(), resourceGroup);
brcIntents.add(brcIntent);
});
return brcIntents;
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class ObjectiveTrackerTest method testEventHostAvailableMatch.
/**
* Tests an event for a host becoming available that matches an intent.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testEventHostAvailableMatch() throws Exception {
final Device host = device("host1");
final DeviceEvent deviceEvent = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, host);
reasons.add(deviceEvent);
final Key key = Key.of(0x333L, APP_ID);
Collection<NetworkResource> resources = ImmutableSet.of(host.id());
tracker.addTrackedResources(key, resources);
deviceListener.event(deviceEvent);
assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
assertThat(delegate.intentIdsFromEvent, hasSize(1));
assertThat(delegate.compileAllFailedFromEvent, is(true));
assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class ObjectiveTrackerTest method testEventHostUnavailableMatch.
/**
* Tests an event for a host becoming unavailable that matches an intent.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testEventHostUnavailableMatch() throws Exception {
final Device host = device("host1");
final DeviceEvent deviceEvent = new DeviceEvent(DeviceEvent.Type.DEVICE_REMOVED, host);
reasons.add(deviceEvent);
final Key key = Key.of(0x333L, APP_ID);
Collection<NetworkResource> resources = ImmutableSet.of(host.id());
tracker.addTrackedResources(key, resources);
deviceListener.event(deviceEvent);
assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
assertThat(delegate.intentIdsFromEvent, hasSize(1));
assertThat(delegate.compileAllFailedFromEvent, is(false));
assertThat(delegate.intentIdsFromEvent.get(0).toString(), equalTo("0x333"));
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class IntentRemoveCommand method removeIntent.
/**
* Removes the intents passed as argument, assuming these
* belong to the application's ID provided (if any) and
* contain a key string.
*
* If an application ID is provided, it will be used to further
* filter the intents to be removed.
*
* @param intents list of intents to remove
* @param applicationIdString application ID to filter intents
* @param keyString string to filter intents
* @param purgeAfterRemove states whether the intents should be also purged
* @param sync states whether the cli should wait for the operation to finish
* before returning
*/
private void removeIntent(Iterable<Intent> intents, String applicationIdString, String keyString, boolean purgeAfterRemove, boolean sync) {
IntentService intentService = get(IntentService.class);
CoreService coreService = get(CoreService.class);
this.applicationIdString = applicationIdString;
this.keyString = keyString;
this.purgeAfterRemove = purgeAfterRemove;
this.sync = sync;
if (purgeAfterRemove || sync) {
print("Using \"sync\" to remove/purge intents - this may take a while...");
print("Check \"summary\" to see remove/purge progress.");
}
ApplicationId appId = appId();
if (!isNullOrEmpty(applicationIdString)) {
appId = coreService.getAppId(applicationIdString);
if (appId == null) {
print("Cannot find application Id %s", applicationIdString);
return;
}
}
if (isNullOrEmpty(keyString)) {
removeIntentsByAppId(intentService, intents, appId);
} else {
final Key key;
if (keyString.startsWith("0x")) {
// The intent uses a LongKey
keyString = keyString.replaceFirst("0x", "");
key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
} else {
// The intent uses a StringKey
key = Key.of(keyString, appId);
}
Intent intent = intentService.getIntent(key);
if (intent != null) {
removeIntent(intentService, intent);
}
}
}
use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.
the class IntentsDiagnosisCommand method getIntentsByLinkSet.
private Set<Map.Entry<LinkKey, Key>> getIntentsByLinkSet(ServiceRefs svcRefs) {
try {
ObjectiveTrackerService objTracker = svcRefs.getObjectiveTrackerService();
// Utilizing reflection instead of adding new interface for getting intentsByLink
Field f = objTracker.getClass().getDeclaredField(FIELD_INTENTS_BY_LINK);
f.setAccessible(true);
SetMultimap<LinkKey, Key> intentsByLink = (SetMultimap<LinkKey, Key>) f.get(objTracker);
return ImmutableSet.copyOf(intentsByLink.entries());
} catch (NoSuchFieldException | IllegalAccessException ex) {
error("error: " + ex);
return ImmutableSet.of();
}
}
Aggregations