Search in sources :

Example 1 with IntIntent

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

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;
}
Also used : IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) ConsistentMap(org.onosproject.store.service.ConsistentMap) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) ScheduledFuture(java.util.concurrent.ScheduledFuture) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) TimeoutException(java.util.concurrent.TimeoutException) SharedScheduledExecutors(org.onlab.util.SharedScheduledExecutors) ConnectPoint(org.onosproject.net.ConnectPoint) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) StorageService(org.onosproject.store.service.StorageService) SubjectFactories(org.onosproject.net.config.basics.SubjectFactories) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) Serializer(org.onosproject.store.service.Serializer) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) AtomicIdGenerator(org.onosproject.store.service.AtomicIdGenerator) Set(java.util.Set) Collectors(java.util.stream.Collectors) Versioned(org.onosproject.store.service.Versioned) ConfigFactory(org.onosproject.net.config.ConfigFactory) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) IntIntentCodec(org.onosproject.inbandtelemetry.rest.IntIntentCodec) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) AtomicValueEvent(org.onosproject.store.service.AtomicValueEvent) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) KryoNamespace(org.onlab.util.KryoNamespace) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) MapEventListener(org.onosproject.store.service.MapEventListener) ConcurrentMap(java.util.concurrent.ConcurrentMap) AtomicValue(org.onosproject.store.service.AtomicValue) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) IntService(org.onosproject.inbandtelemetry.api.IntService) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) DeviceListener(org.onosproject.net.device.DeviceListener) Striped(com.google.common.util.concurrent.Striped) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IntDeviceConfig(org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig) Maps(com.google.common.collect.Maps) CodecService(org.onosproject.codec.CodecService) AtomicValueEventListener(org.onosproject.store.service.AtomicValueEventListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Lock(java.util.concurrent.locks.Lock) IntObjective(org.onosproject.net.behaviour.inbandtelemetry.IntObjective) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) IntMetadataType(org.onosproject.net.behaviour.inbandtelemetry.IntMetadataType) Device(org.onosproject.net.Device) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntObjective(org.onosproject.net.behaviour.inbandtelemetry.IntObjective) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 3 with IntIntent

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));
    });
}
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 IntIntent

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();
}
Also used : IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntService(org.onosproject.inbandtelemetry.api.IntService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with IntIntent

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

Aggregations

IntIntent (org.onosproject.inbandtelemetry.api.IntIntent)7 IntIntentId (org.onosproject.inbandtelemetry.api.IntIntentId)5 IntService (org.onosproject.inbandtelemetry.api.IntService)4 Produces (javax.ws.rs.Produces)3 IntDeviceConfig (org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig)3 IntReportConfig (org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 GET (javax.ws.rs.GET)2 KryoNamespace (org.onlab.util.KryoNamespace)2 ApplicationId (org.onosproject.core.ApplicationId)2 IntIntentCodec (org.onosproject.inbandtelemetry.rest.IntIntentCodec)2 DeviceId (org.onosproject.net.DeviceId)2 NetworkConfigEvent (org.onosproject.net.config.NetworkConfigEvent)2 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Maps (com.google.common.collect.Maps)1 Striped (com.google.common.util.concurrent.Striped)1 IOException (java.io.IOException)1