Search in sources :

Example 66 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class McastConfigTest method setUp.

/**
 * Initialize test related variables.
 *
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    InputStream jsonStream = McastConfigTest.class.getResourceAsStream("/mcast-config.json");
    InputStream invalidJsonStream = McastConfigTest.class.getResourceAsStream("/mcast-config-invalid.json");
    InputStream jsonStreamForInnerVlan = McastConfigTest.class.getResourceAsStream("/mcast-config-inner.json");
    InputStream invalidJsonStreamForInnerVlan = McastConfigTest.class.getResourceAsStream("/mcast-config-invalid-inner.json");
    ApplicationId subject = APP_ID;
    String key = CoreService.CORE_APP_NAME;
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonStream);
    JsonNode invalidJsonNode = mapper.readTree(invalidJsonStream);
    JsonNode jsonNodeForInnerVlan = mapper.readTree(jsonStreamForInnerVlan);
    JsonNode invalidJsonNodeForInnerVlan = mapper.readTree(invalidJsonStreamForInnerVlan);
    ConfigApplyDelegate delegate = new MockDelegate();
    config = new McastConfig();
    config.init(subject, key, jsonNode, mapper, delegate);
    invalidConfig = new McastConfig();
    invalidConfig.init(subject, key, invalidJsonNode, mapper, delegate);
    configForInnerVlan = new McastConfig();
    configForInnerVlan.init(subject, key, jsonNodeForInnerVlan, mapper, delegate);
    invalidConfigForInnerVlan = new McastConfig();
    invalidConfigForInnerVlan.init(subject, key, invalidJsonNodeForInnerVlan, mapper, delegate);
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) TestApplicationId(org.onosproject.TestApplicationId) ApplicationId(org.onosproject.core.ApplicationId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Before(org.junit.Before)

Example 67 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class SubjectFactoriesTest method testAppIdFactory.

@Test
public void testAppIdFactory() {
    SubjectFactory<ApplicationId> appIdFactory = SubjectFactories.APP_SUBJECT_FACTORY;
    assertThat(appIdFactory, notNullValue());
    ApplicationId id = NetTestTools.APP_ID;
    ApplicationId createdAppId = appIdFactory.createSubject(id.name());
    assertThat(createdAppId.id(), equalTo(id.id()));
    assertThat(appIdFactory.subjectKey(id), is(id.name()));
}
Also used : TestApplicationId(org.onosproject.TestApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Test(org.junit.Test)

Example 68 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class BandwidthProfileTest method testMeterConversion.

@Test
public void testMeterConversion() {
    DeviceId deviceId = DeviceId.deviceId("netconf:10.0.0.1:22");
    ApplicationId appId = TestApplicationId.create("org.onosproject.foo.app");
    Meter.Builder meterBuilder = new DefaultMeter.Builder().withId(MeterId.meterId(ONE)).withUnit(Meter.Unit.KB_PER_SEC).forDevice(deviceId).burst();
    // Create Meter with single band
    Band band1 = DefaultBand.builder().ofType(Band.Type.DROP).withRate(TEN_M).burstSize(TWO_K).build();
    Meter meter = meterBuilder.fromApp(appId).withBands(Arrays.asList(band1)).build();
    BandwidthProfile bandwidthProfile = BandwidthProfile.fromMeter(meter);
    assertEquals("wrong bw profile name", bandwidthProfile.name(), meter.id().toString());
    assertEquals("wrong bw profile type", bandwidthProfile.type(), BandwidthProfile.Type.sr2CM);
    assertEquals("wrong bw profile CIR", bandwidthProfile.cir().bps(), band1.rate() * EIGHT_K, 0);
    assertEquals("wrong bw profile CBS", (long) bandwidthProfile.cbs(), (long) band1.burst());
    assertNull(bandwidthProfile.pir());
    assertNull(bandwidthProfile.pbs());
    assertNull(bandwidthProfile.ebs());
    assertEquals("wrong green action", bandwidthProfile.greenAction(), getBuilder(Action.PASS).build());
    assertNull(bandwidthProfile.yellowAction());
    assertEquals("wrong red action", bandwidthProfile.redAction(), getBuilder(Action.DISCARD).build());
    assertEquals("wrong color-aware mode", bandwidthProfile.colorAware(), false);
    // Create Meter with two bands
    Band band2 = DefaultBand.builder().burstSize(ONE_K).ofType(Band.Type.REMARK).dropPrecedence((short) 0b001010).withRate(ONE_M).build();
    meter = meterBuilder.fromApp(appId).withBands(Arrays.asList(band1, band2)).build();
    bandwidthProfile = BandwidthProfile.fromMeter(meter);
    assertEquals("wrong bw profile name", bandwidthProfile.name(), meter.id().toString());
    assertEquals("wrong bw profile type", bandwidthProfile.type(), BandwidthProfile.Type.trTCM);
    assertEquals("wrong bw profile CIR", bandwidthProfile.cir().bps(), band2.rate() * EIGHT_K, 0);
    assertEquals("wrong bw profile CBS", (long) bandwidthProfile.cbs(), (long) band2.burst());
    assertEquals("wrong bw profile PIR", bandwidthProfile.pir().bps(), band1.rate() * EIGHT_K, 0);
    assertEquals("wrong bw profile PBS", (long) bandwidthProfile.pbs(), (long) band1.burst());
    assertNull(bandwidthProfile.ebs());
    assertEquals("wrong green action", bandwidthProfile.greenAction(), getBuilder(Action.PASS).build());
    assertEquals("wrong yellow action", bandwidthProfile.yellowAction(), getBuilder(Action.REMARK).dscpClass(DscpClass.AF11).build());
    assertEquals("wrong red action", bandwidthProfile.redAction(), getBuilder(Action.DISCARD).build());
    assertEquals("wrong color-aware mode", bandwidthProfile.colorAware(), false);
}
Also used : DefaultMeter(org.onosproject.net.meter.DefaultMeter) Meter(org.onosproject.net.meter.Meter) DeviceId(org.onosproject.net.DeviceId) DefaultBand(org.onosproject.net.meter.DefaultBand) Band(org.onosproject.net.meter.Band) TestApplicationId(org.onosproject.TestApplicationId) ApplicationId(org.onosproject.core.ApplicationId) Test(org.junit.Test)

Example 69 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class DistributedSecurityModeStoreTest method setUp.

@Before
public void setUp() throws Exception {
    appId = new DefaultApplicationId(1, "test");
    testPermissions = new HashSet<Permission>();
    testPermission = new Permission("testClass", "testName");
    testPermissions.add(testPermission);
    testFeatures = new ArrayList<String>();
    testFeatures.add("testFeature");
    testRequiredApps = new ArrayList<String>();
    testRequiredApps.add("testRequiredApp");
    app = DefaultApplication.builder().withAppId(appId).withVersion(Version.version(1, 1, "patch", "build")).withTitle("testTitle").withDescription("testDes").withOrigin("testOri").withCategory("testCT").withUrl("testurl").withReadme("test").withIcon(null).withRole(ApplicationRole.ADMIN).withPermissions(testPermissions).withFeaturesRepo(Optional.ofNullable(null)).withFeatures(testFeatures).withRequiredApps(testRequiredApps).build();
    testLocations = new HashSet<String>();
    testLocations.add("locationA");
    testLocations.add("locationB");
    Set<ApplicationId> appIdSet = new HashSet<ApplicationId>();
    appIdSet.add(appId);
    localBundleAppDirectory = new ConcurrentHashMap<>();
    localBundleAppDirectory.put("testLocation", appIdSet);
    localAppBundleDirectory = new ConcurrentHashMap<>();
    localAppBundleDirectory.put(appId, testLocations);
    violations = new ConcurrentHashMap<ApplicationId, Set<Permission>>();
    violations.put(appId, testPermissions);
    testSecInfo = new SecurityInfo(testPermissions, SECURED);
    states = new ConcurrentHashMap<ApplicationId, SecurityInfo>();
    states.put(appId, testSecInfo);
}
Also used : HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Permission(org.onosproject.security.Permission) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 70 with ApplicationId

use of org.onosproject.core.ApplicationId in project onos by opennetworkinglab.

the class DistributedApplicationStore method activate.

@Activate
public void activate() {
    messageHandlingExecutor = newSingleThreadExecutor(groupedThreads("onos/store/app", "message-handler", log));
    clusterCommunicator.addSubscriber(APP_BITS_REQUEST, bytes -> new String(bytes, Charsets.UTF_8), name -> {
        try {
            log.info("Sending bits for application {}", name);
            return toByteArray(getApplicationInputStream(name));
        } catch (ApplicationException e) {
            log.warn("Bits for application {} are not available on this node yet", name);
            return null;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }, Function.identity(), messageHandlingExecutor);
    apps = storageService.<ApplicationId, InternalApplicationHolder>consistentMapBuilder().withName("onos-apps").withRelaxedReadConsistency().withSerializer(Serializer.using(KryoNamespaces.API, InternalApplicationHolder.class, InternalState.class)).withVersion(versionService.version()).withRevisionType(RevisionType.PROPAGATE).withCompatibilityFunction(this::convertApplication).build();
    /* To update the version in application store if it does not matche with the local system.
           This will happen only when upgrading onos using issu or during rollback if upgrade does not work.
         */
    apps.asJavaMap().forEach((appId, holder) -> apps.asJavaMap().put(appId, convertApplication(holder, versionService.version())));
    appActivationTopic = storageService.<Application>topicBuilder().withName("onos-apps-activation-topic").withSerializer(Serializer.using(KryoNamespaces.API)).withVersion(versionService.version()).withRevisionType(RevisionType.PROPAGATE).withCompatibilityFunction(this::convertApplication).build();
    activationExecutor = newSingleThreadExecutor(groupedThreads("onos/store/app", "app-activation", log));
    appActivationTopic.subscribe(appActivator, activationExecutor);
    executor = newSingleThreadScheduledExecutor(groupedThreads("onos/app", "store", log));
    statusChangeListener = status -> {
        if (status == Status.ACTIVE) {
            executor.execute(this::bootstrapExistingApplications);
        }
    };
    apps.addListener(appsListener, activationExecutor);
    apps.addStatusChangeListener(statusChangeListener);
    coreAppId = getId(CoreService.CORE_APP_NAME);
    downloadMissingApplications();
    activateExistingApplications();
    log.info("Started");
}
Also used : ApplicationException(org.onosproject.app.ApplicationException) IOException(java.io.IOException) ApplicationId(org.onosproject.core.ApplicationId) StorageException(org.onosproject.store.service.StorageException) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

ApplicationId (org.onosproject.core.ApplicationId)138 CoreService (org.onosproject.core.CoreService)36 Activate (org.osgi.service.component.annotations.Activate)36 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)25 Path (javax.ws.rs.Path)21 Produces (javax.ws.rs.Produces)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)15 GET (javax.ws.rs.GET)14 Test (org.junit.Test)13 ApplicationAdminService (org.onosproject.app.ApplicationAdminService)11 FlowRuleService (org.onosproject.net.flow.FlowRuleService)11 TrafficSelector (org.onosproject.net.flow.TrafficSelector)11 Intent (org.onosproject.net.intent.Intent)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 InputStream (java.io.InputStream)9 DeviceId (org.onosproject.net.DeviceId)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 IntentService (org.onosproject.net.intent.IntentService)9 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8