use of org.onosproject.inbandtelemetry.api.IntIntent 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.IntIntent in project onos by opennetworkinglab.
the class SimpleIntManager method configDevice.
protected boolean configDevice(DeviceId deviceId) {
// Returns true if config was successful, false if not and a clean up is
// needed.
final Device device = deviceService.getDevice(deviceId);
if (device == null || !device.is(IntProgrammable.class)) {
return true;
}
if (isNotIntConfigured()) {
log.warn("Missing INT config, aborting programming of INT device {}", deviceId);
return true;
}
final boolean isEdge = !hostService.getConnectedHosts(deviceId).isEmpty();
final IntDeviceRole intDeviceRole = isEdge ? IntDeviceRole.SOURCE_SINK : IntDeviceRole.TRANSIT;
log.info("Started programming of INT device {} with role {}...", deviceId, intDeviceRole);
final IntProgrammable intProg = device.as(IntProgrammable.class);
if (!isIntStarted()) {
// Leave device with no INT configuration.
return true;
}
if (!intProg.init()) {
log.warn("Unable to init INT pipeline on {}", deviceId);
return false;
}
boolean supportSource = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SOURCE);
boolean supportSink = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SINK);
boolean supportPostcard = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.POSTCARD);
if (intDeviceRole != IntDeviceRole.SOURCE_SINK && !supportPostcard) {
// Stop here, no more configuration needed for transit devices unless it support postcard.
return true;
}
if (supportSink || supportPostcard) {
if (!intProg.setupIntConfig(intConfig.get())) {
log.warn("Unable to apply INT report config on {}", deviceId);
return false;
}
}
// Port configuration.
final Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream().map(port -> new ConnectPoint(deviceId, port.number())).filter(cp -> !hostService.getConnectedHosts(cp).isEmpty()).map(ConnectPoint::port).collect(Collectors.toSet());
for (PortNumber port : hostPorts) {
if (supportSource) {
log.info("Setting port {}/{} as INT source port...", deviceId, port);
if (!intProg.setSourcePort(port)) {
log.warn("Unable to set INT source port {} on {}", port, deviceId);
return false;
}
}
if (supportSink) {
log.info("Setting port {}/{} as INT sink port...", deviceId, port);
if (!intProg.setSinkPort(port)) {
log.warn("Unable to set INT sink port {} on {}", port, deviceId);
return false;
}
}
}
if (!supportSource && !supportPostcard) {
// it supports postcard mode.
return true;
}
// Apply intents.
// This is a trivial implementation where we simply get the
// corresponding INT objective from an intent and we apply to all
// device which support reporting.
int appliedCount = 0;
for (Versioned<IntIntent> versionedIntent : intentMap.values()) {
IntIntent intent = versionedIntent.value();
IntObjective intObjective = getIntObjective(intent);
if (intent.telemetryMode() == IntIntent.TelemetryMode.INBAND_TELEMETRY && supportSource) {
intProg.addIntObjective(intObjective);
appliedCount++;
} else if (intent.telemetryMode() == IntIntent.TelemetryMode.POSTCARD && supportPostcard) {
intProg.addIntObjective(intObjective);
appliedCount++;
} else {
log.warn("Device {} does not support intent {}.", deviceId, intent);
}
}
log.info("Completed programming of {}, applied {} INT objectives of {} total", deviceId, appliedCount, intentMap.size());
return true;
}
use of org.onosproject.inbandtelemetry.api.IntIntent 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.IntIntent in project onos by opennetworkinglab.
the class IntWebResource method getIntent.
/**
* Get an IntIntent. Returns an IntIntent in the system.
* @param id IntIntentId
* @return 200 OK with a IntIntent
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response getIntent(@PathParam("id") String id) {
ArrayNode intsNode = root.putArray(INT);
IntService service = get(IntService.class);
final IntIntent intIntent = nullIsNotFound(service.getIntIntent(IntIntentId.valueOf(Long.parseLong(id))), INT_NOT_FOUND + id);
intsNode.add(codec(IntIntent.class).encode(intIntent, this));
return ok(root).build();
}
use of org.onosproject.inbandtelemetry.api.IntIntent 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());
}
}
Aggregations