Search in sources :

Example 1 with IntIntentId

use of org.onosproject.inbandtelemetry.api.IntIntentId in project onos by opennetworkinglab.

the class IntWebResource method getIntents.

/**
 * Gets all IntIntents. Returns array of all IntIntents in the system.
 * @return 200 OK with a collection of IntIntents
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntents() {
    ArrayNode intsNode = root.putArray(INTS);
    IntService service = get(IntService.class);
    Map<IntIntentId, IntIntent> intIntents = service.getIntIntents();
    if (!intIntents.isEmpty()) {
        intIntents.entrySet().forEach(intIntentEntry -> {
            intsNode.add(codec(IntIntent.class).encode(intIntentEntry.getValue(), this).put(ID, intIntentEntry.getKey().id()));
        });
    }
    return ok(root).build();
}
Also used : IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntService(org.onosproject.inbandtelemetry.api.IntService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with IntIntentId

use of org.onosproject.inbandtelemetry.api.IntIntentId in project onos by opennetworkinglab.

the class SimpleIntManager method installIntIntent.

@Override
public IntIntentId installIntIntent(IntIntent intent) {
    checkNotNull(intent);
    final Integer intentId = (int) intentIds.nextId();
    final IntIntentId intIntentId = IntIntentId.valueOf(intentId);
    // Intent map event will trigger device configure.
    intentMap.put(intIntentId, intent);
    return intIntentId;
}
Also used : IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId)

Example 3 with IntIntentId

use of org.onosproject.inbandtelemetry.api.IntIntentId in project onos by opennetworkinglab.

the class TestCodecService method testPushIntAppConfig.

@Test
public void testPushIntAppConfig() throws IOException {
    IntReportConfig config = getIntReportConfig("/report-config.json");
    NetworkConfigEvent event = new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, APP_ID, config, null, IntReportConfig.class);
    networkConfigListener.event(event);
    // We expected that the manager will store the device config which
    // converted from the app config.
    IntDeviceConfig expectedConfig = createIntDeviceConfig();
    IntDeviceConfig actualConfig = manager.getConfig();
    assertEquals(expectedConfig, actualConfig);
    // Install watch subnets via netcfg
    // In the report-config.json, there are 3 subnets we want to watch
    // For subnet 0.0.0.0/0, the IntManager will create only one IntIntent with an empty selector.
    Set<IntIntent> expectedIntIntents = Sets.newHashSet();
    ConsistentMap<IntIntentId, IntIntent> intentMap = TestUtils.getField(manager, "intentMap");
    IntIntent.Builder baseIntentBuilder = IntIntent.builder().withReportType(IntIntent.IntReportType.TRACKED_FLOW).withReportType(IntIntent.IntReportType.DROPPED_PACKET).withReportType(IntIntent.IntReportType.CONGESTED_QUEUE).withTelemetryMode(IntIntent.TelemetryMode.POSTCARD);
    // Watch IP Src == subnet 1
    TrafficSelector expectedSelector = DefaultTrafficSelector.builder().matchIPSrc(IpPrefix.valueOf(WATCHED_SUBNET_1)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Watch IP Dst == subnet 1
    expectedSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf(WATCHED_SUBNET_1)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Watch IP Src == subnet 2
    expectedSelector = DefaultTrafficSelector.builder().matchIPSrc(IpPrefix.valueOf(WATCHED_SUBNET_2)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Watch IP Dst == subnet 2
    expectedSelector = DefaultTrafficSelector.builder().matchIPDst(IpPrefix.valueOf(WATCHED_SUBNET_2)).build();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // Any packets
    expectedSelector = DefaultTrafficSelector.emptySelector();
    expectedIntIntents.add(baseIntentBuilder.withSelector(expectedSelector).build());
    // The INT intent installation order can be random, so we need to collect
    // all expected INT intents and check if actual intent exists.
    assertAfter(50, 100, () -> assertEquals(5, intentMap.size()));
    intentMap.entrySet().forEach(entry -> {
        IntIntent actualIntIntent = entry.getValue().value();
        assertTrue(expectedIntIntents.contains(actualIntIntent));
    });
}
Also used : NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) IntDeviceConfig(org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) Test(org.junit.Test)

Example 4 with IntIntentId

use of org.onosproject.inbandtelemetry.api.IntIntentId in project onos by opennetworkinglab.

the class IntWebResource method createIntent.

/**
 * Creates new IntIntent. Creates and installs a new IntIntent.
 *
 * @param stream IntIntent JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel Int
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createIntent(InputStream stream) {
    IntService service = get(IntService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        IntIntent intIntent = codec(IntIntent.class).decode(jsonTree, this);
        IntIntentId intIntentId = service.installIntIntent(intIntent);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(INT).path(Long.toString(intIntentId.id()));
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntService(org.onosproject.inbandtelemetry.api.IntService) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with IntIntentId

use of org.onosproject.inbandtelemetry.api.IntIntentId in project onos by opennetworkinglab.

the class SimpleIntManager method activate.

@Activate
public void activate() {
    final ApplicationId appId = coreService.registerApplication(APP_NAME);
    KryoNamespace.Builder serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(IntIntent.class).register(IntIntentId.class).register(IntDeviceRole.class).register(IntIntent.IntHeaderType.class).register(IntMetadataType.class).register(IntIntent.IntReportType.class).register(IntIntent.TelemetryMode.class).register(IntDeviceConfig.class).register(IntDeviceConfig.TelemetrySpec.class);
    codecService.registerCodec(IntIntent.class, new IntIntentCodec());
    devicesToConfigure = storageService.<DeviceId, Long>consistentMapBuilder().withSerializer(Serializer.using(serializer.build())).withName("onos-int-devices-to-configure").withApplicationId(appId).withPurgeOnUninstall().build();
    devicesToConfigure.addListener(devicesToConfigureListener);
    intentMap = storageService.<IntIntentId, IntIntent>consistentMapBuilder().withSerializer(Serializer.using(serializer.build())).withName("onos-int-intents").withApplicationId(appId).withPurgeOnUninstall().build();
    intentMap.addListener(intentMapListener);
    intStarted = storageService.<Boolean>atomicValueBuilder().withSerializer(Serializer.using(serializer.build())).withName("onos-int-started").withApplicationId(appId).build().asAtomicValue();
    intStarted.addListener(intStartedListener);
    intConfig = storageService.<IntDeviceConfig>atomicValueBuilder().withSerializer(Serializer.using(serializer.build())).withName("onos-int-config").withApplicationId(appId).build().asAtomicValue();
    intConfig.addListener(intConfigListener);
    intentIds = storageService.getAtomicIdGenerator("int-intent-id-generator");
    // Bootstrap config for already existing devices.
    triggerAllDeviceConfigure();
    // Bootstrap core event executor before adding listener
    eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/int", "events-%d", log));
    hostService.addListener(hostListener);
    deviceService.addListener(deviceListener);
    netcfgRegistry.registerConfigFactory(intAppConfigFactory);
    netcfgService.addListener(appConfigListener);
    // Initialize the INT report
    IntReportConfig reportConfig = netcfgService.getConfig(appId, IntReportConfig.class);
    if (reportConfig != null) {
        IntDeviceConfig intDeviceConfig = IntDeviceConfig.builder().withMinFlowHopLatencyChangeNs(reportConfig.minFlowHopLatencyChangeNs()).withCollectorPort(reportConfig.collectorPort()).withCollectorIp(reportConfig.collectorIp()).enabled(true).build();
        setConfig(intDeviceConfig);
    }
    startInt();
    log.info("Started");
}
Also used : IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntDeviceConfig(org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig) DeviceId(org.onosproject.net.DeviceId) IntIntentCodec(org.onosproject.inbandtelemetry.rest.IntIntentCodec) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) KryoNamespace(org.onlab.util.KryoNamespace) ApplicationId(org.onosproject.core.ApplicationId) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

IntIntentId (org.onosproject.inbandtelemetry.api.IntIntentId)5 IntIntent (org.onosproject.inbandtelemetry.api.IntIntent)4 Produces (javax.ws.rs.Produces)2 IntService (org.onosproject.inbandtelemetry.api.IntService)2 IntDeviceConfig (org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig)2 IntReportConfig (org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Test (org.junit.Test)1 KryoNamespace (org.onlab.util.KryoNamespace)1 ApplicationId (org.onosproject.core.ApplicationId)1 IntIntentCodec (org.onosproject.inbandtelemetry.rest.IntIntentCodec)1 DeviceId (org.onosproject.net.DeviceId)1 NetworkConfigEvent (org.onosproject.net.config.NetworkConfigEvent)1 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)1