Search in sources :

Example 41 with Key

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;
}
Also used : SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Interface(org.onosproject.net.intf.Interface) ResourceGroup(org.onosproject.net.ResourceGroup) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 42 with Key

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"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 43 with Key

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"));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) Key(org.onosproject.net.intent.Key) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 44 with Key

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);
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

Example 45 with Key

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();
    }
}
Also used : Field(java.lang.reflect.Field) SetMultimap(com.google.common.collect.SetMultimap) LinkKey(org.onosproject.net.LinkKey) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) LinkKey(org.onosproject.net.LinkKey) Key(org.onosproject.net.intent.Key)

Aggregations

Key (org.onosproject.net.intent.Key)65 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)25 Intent (org.onosproject.net.intent.Intent)22 ConnectPoint (org.onosproject.net.ConnectPoint)20 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 TrafficSelector (org.onosproject.net.flow.TrafficSelector)19 MultiPointToSinglePointIntent (org.onosproject.net.intent.MultiPointToSinglePointIntent)19 Test (org.junit.Test)15 Constraint (org.onosproject.net.intent.Constraint)15 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)14 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)12 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)12 SinglePointToMultiPointIntent (org.onosproject.net.intent.SinglePointToMultiPointIntent)12 ApplicationId (org.onosproject.core.ApplicationId)11 IntentService (org.onosproject.net.intent.IntentService)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 Interface (org.onosproject.net.intf.Interface)9 Set (java.util.Set)8 MacAddress (org.onlab.packet.MacAddress)8