Search in sources :

Example 51 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class WipeOutCommand method wipeOutIntents.

private void wipeOutIntents() {
    print("Wiping intents");
    IntentService intentService = get(IntentService.class);
    Set<Key> keysToWithdrawn = Sets.newConcurrentHashSet();
    Set<Intent> intentsToWithdrawn = Tools.stream(intentService.getIntents()).filter(intent -> intentService.getIntentState(intent.key()) != WITHDRAWN).collect(Collectors.toSet());
    intentsToWithdrawn.stream().map(Intent::key).forEach(keysToWithdrawn::add);
    CompletableFuture<Void> completableFuture = new CompletableFuture<>();
    IntentListener listener = e -> {
        if (e.type() == IntentEvent.Type.WITHDRAWN) {
            keysToWithdrawn.remove(e.subject().key());
        }
        if (keysToWithdrawn.isEmpty()) {
            completableFuture.complete(null);
        }
    };
    intentService.addListener(listener);
    intentsToWithdrawn.forEach(intentService::withdraw);
    try {
        if (!intentsToWithdrawn.isEmpty()) {
            // Wait 1.5 seconds for each Intent
            completableFuture.get(intentsToWithdrawn.size() * 1500L, TimeUnit.MILLISECONDS);
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        print("Encountered exception while withdrawing intents: " + e.toString());
    } finally {
        intentService.removeListener(listener);
    }
    intentsToWithdrawn.forEach(intentService::purge);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) LinkAdminService(org.onosproject.net.link.LinkAdminService) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) IntentEvent(org.onosproject.net.intent.IntentEvent) UiExtensionService(org.onosproject.ui.UiExtensionService) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Link(org.onosproject.net.Link) Command(org.apache.karaf.shell.api.action.Command) PacketRequest(org.onosproject.net.packet.PacketRequest) FlowRuleService(org.onosproject.net.flow.FlowRuleService) IntentService(org.onosproject.net.intent.IntentService) MeterService(org.onosproject.net.meter.MeterService) UiTopoLayoutService(org.onosproject.ui.UiTopoLayoutService) Intent(org.onosproject.net.intent.Intent) Device(org.onosproject.net.Device) GroupService(org.onosproject.net.group.GroupService) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) HostAdminService(org.onosproject.net.host.HostAdminService) PacketService(org.onosproject.net.packet.PacketService) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) Key(org.onosproject.net.intent.Key) WITHDRAWN(org.onosproject.net.intent.IntentState.WITHDRAWN) IntentListener(org.onosproject.net.intent.IntentListener) Service(org.apache.karaf.shell.api.action.lifecycle.Service) RegionAdminService(org.onosproject.net.region.RegionAdminService) IntentService(org.onosproject.net.intent.IntentService) Intent(org.onosproject.net.intent.Intent) CompletableFuture(java.util.concurrent.CompletableFuture) IntentListener(org.onosproject.net.intent.IntentListener) ExecutionException(java.util.concurrent.ExecutionException) Key(org.onosproject.net.intent.Key) TimeoutException(java.util.concurrent.TimeoutException)

Example 52 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class IntentsWebResource method deleteIntentById.

/**
 * Withdraws intent.
 * Withdraws the specified intent from the system.
 *
 * @param appId application identifier
 * @param key   intent key
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{appId}/{key}")
public Response deleteIntentById(@PathParam("appId") String appId, @PathParam("key") String key) {
    final ApplicationId app = get(CoreService.class).getAppId(appId);
    nullIsNotFound(app, APP_ID_NOT_FOUND);
    Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
    IntentService service = get(IntentService.class);
    if (intent == null) {
        intent = service.getIntent(Key.of(Long.decode(key), app));
    }
    if (intent == null) {
        // in this case.
        return Response.noContent().build();
    }
    Key k = intent.key();
    // set up latch and listener to track uninstall progress
    CountDownLatch latch = new CountDownLatch(1);
    IntentListener listener = new DeleteListener(k, latch);
    service.addListener(listener);
    try {
        // request the withdraw
        service.withdraw(intent);
        try {
            latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.info("REST Delete operation timed out waiting for intent {}", k);
            Thread.currentThread().interrupt();
        }
        // double check the state
        IntentState state = service.getIntentState(k);
        if (state == WITHDRAWN || state == FAILED) {
            service.purge(intent);
        }
    } finally {
        // clean up the listener
        service.removeListener(listener);
    }
    return Response.noContent().build();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentState(org.onosproject.net.intent.IntentState) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) CountDownLatch(java.util.concurrent.CountDownLatch) IntentListener(org.onosproject.net.intent.IntentListener) Key(org.onosproject.net.intent.Key) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 53 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class VplsIntentTest method generateVplsBrc.

/**
 * Generates a list of the expected sp2mp intents for a VPLS.
 *
 * @param fcPoints the filtered connect point
 * @param name the name of the VPLS
 * @param encap the encapsulation type
 * @return the list of expected sp2mp intents for the given VPLS
 */
private List<SinglePointToMultiPointIntent> generateVplsBrc(Set<FilteredConnectPoint> fcPoints, String name, EncapsulationType encap) {
    List<SinglePointToMultiPointIntent> intents = Lists.newArrayList();
    fcPoints.forEach(point -> {
        Set<FilteredConnectPoint> otherPoints = fcPoints.stream().filter(fcp -> !fcp.equals(point)).collect(Collectors.toSet());
        Key brckey = buildKey(VplsIntentUtility.PREFIX_BROADCAST, point.connectPoint(), name, MacAddress.BROADCAST);
        intents.add(buildBrcIntent(brckey, point, otherPoints, encap));
    });
    return intents;
}
Also used : IntentServiceAdapter(org.onosproject.net.intent.IntentServiceAdapter) MockIdGenerator(org.onosproject.net.intent.MockIdGenerator) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) NONE(org.onosproject.net.EncapsulationType.NONE) VplsData(org.onosproject.vpls.api.VplsData) InterfaceService(org.onosproject.net.intf.InterfaceService) IntentUtils(org.onosproject.net.intent.IntentUtils) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceListener(org.onosproject.net.intf.InterfaceListener) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) After(org.junit.After) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Before(org.junit.Before) EasyMock.anyObject(org.easymock.EasyMock.anyObject) ImmutableSet(com.google.common.collect.ImmutableSet) VLAN(org.onosproject.net.EncapsulationType.VLAN) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) VplsIntentUtility(org.onosproject.vpls.intent.VplsIntentUtility) EasyMock.expect(org.easymock.EasyMock.expect) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) Key(org.onosproject.net.intent.Key) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) MacAddress(org.onlab.packet.MacAddress) Assert.assertEquals(org.junit.Assert.assertEquals) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) Key(org.onosproject.net.intent.Key) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 54 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class PacketLinkRealizedByOpticalTest method testCreate.

/**
 * Checks the construction of PacketLinkRealizedByOptical object with all parameters specified.
 */
@Test
public void testCreate() {
    ConnectPoint cp1 = new ConnectPoint(DeviceId.deviceId("of:0000000000000001"), PortNumber.portNumber(1L));
    ConnectPoint cp2 = new ConnectPoint(DeviceId.deviceId("of:0000000000000002"), PortNumber.portNumber(2L));
    Key key = Key.of(10L, appId);
    Bandwidth bandwidth = Bandwidth.bps(100L);
    PacketLinkRealizedByOptical plink = new PacketLinkRealizedByOptical(cp1, cp2, key, bandwidth);
    assertNotNull(plink);
    assertEquals(plink.src(), cp1);
    assertEquals(plink.dst(), cp2);
    assertEquals((long) plink.bandwidth().bps(), 100L);
}
Also used : Bandwidth(org.onlab.util.Bandwidth) ConnectPoint(org.onosproject.net.ConnectPoint) Key(org.onosproject.net.intent.Key) Test(org.junit.Test)

Example 55 with Key

use of org.onosproject.net.intent.Key in project onos by opennetworkinglab.

the class ServiceApplicationComponent method processTapiEvent.

/**
 * Process TAPI Event from NBI.
 *
 * @param config TAPI Connectivity config for the event
 */
public void processTapiEvent(TapiConnectivityConfig config) {
    checkNotNull(config, "Config can't be null");
    Key key = Key.of(config.uuid(), appId);
    // Setup the Intent
    if (config.isSetup()) {
        log.debug("TAPI config: {} to setup intent", config);
        Intent intent = createOpticalIntent(config.leftCp(), config.rightCp(), key, appId);
        intentService.submit(intent);
    } else {
        // Release the intent
        Intent intent = intentService.getIntent(key);
        if (intent == null) {
            log.error("Intent for uuid {} does not exist", config.uuid());
            return;
        }
        log.debug("TAPI config: {} to purge intent {}", config, intent);
        CountDownLatch latch = new CountDownLatch(1);
        IntentListener listener = new DeleteListener(key, latch);
        intentService.addListener(listener);
        try {
            /*
                 * RCAS: Note, withdraw is asynchronous. We cannot call purge
                 * directly, because at this point it remains in the "INSTALLED"
                 * state.
                 */
            intentService.withdraw(intent);
            /*
                 * org.onosproject.onos-core-net - 2.1.0.SNAPSHOT |
                 * Purge for intent 0x0 is rejected because intent state is INSTALLED
                 * intentService.purge(intent);
                 */
            try {
                latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            // double check the state
            IntentState state = intentService.getIntentState(key);
            if (state == WITHDRAWN || state == FAILED) {
                intentService.purge(intent);
            }
        } finally {
            intentService.removeListener(listener);
        }
    }
}
Also used : IntentState(org.onosproject.net.intent.IntentState) Intent(org.onosproject.net.intent.Intent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) CountDownLatch(java.util.concurrent.CountDownLatch) IntentListener(org.onosproject.net.intent.IntentListener) 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