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();
}
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;
}
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));
});
}
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());
}
}
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");
}
Aggregations