Search in sources :

Example 1 with IntReportConfig

use of org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig in project onos by opennetworkinglab.

the class TestCodecService method getIntReportConfig.

private IntReportConfig getIntReportConfig(String fileName) throws IOException {
    IntReportConfig config = new IntReportConfig();
    InputStream jsonStream = getClass().getResourceAsStream(fileName);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonStream);
    config.init(APP_ID, INT_REPORT_CONFIG_KEY, jsonNode, mapper, c -> {
    });
    return config;
}
Also used : InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with IntReportConfig

use of org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig 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 3 with IntReportConfig

use of org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig 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)

Example 4 with IntReportConfig

use of org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig in project onos by opennetworkinglab.

the class TestCodecService method setup.

@Before
public void setup() throws IOException {
    storageService = new TestStorageService();
    mastershipService = createNiceMock(MastershipService.class);
    coreService = createNiceMock(CoreService.class);
    hostService = createNiceMock(HostService.class);
    deviceService = createNiceMock(DeviceService.class);
    expect(deviceService.getDevices()).andReturn(ImmutableList.of()).anyTimes();
    networkConfigRegistry = createNiceMock(NetworkConfigRegistry.class);
    networkConfigService = createNiceMock(NetworkConfigService.class);
    manager = new SimpleIntManager();
    manager.coreService = coreService;
    manager.deviceService = deviceService;
    manager.storageService = storageService;
    manager.mastershipService = mastershipService;
    manager.hostService = hostService;
    manager.netcfgService = networkConfigService;
    manager.netcfgRegistry = networkConfigRegistry;
    manager.eventExecutor = MoreExecutors.newDirectExecutorService();
    manager.codecService = codecService;
    expect(coreService.registerApplication(APP_NAME)).andReturn(APP_ID).anyTimes();
    networkConfigRegistry.registerConfigFactory(anyObject());
    expectLastCall().once();
    Capture<NetworkConfigListener> capture = newCapture();
    networkConfigService.addListener(EasyMock.capture(capture));
    expectLastCall().once();
    IntReportConfig config = getIntReportConfig("/report-config.json");
    expect(networkConfigService.getConfig(APP_ID, IntReportConfig.class)).andReturn(config).anyTimes();
    replay(mastershipService, deviceService, coreService, hostService, networkConfigRegistry, networkConfigService);
    manager.activate();
    networkConfigListener = capture.getValue();
}
Also used : HostService(org.onosproject.net.host.HostService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) TestStorageService(org.onosproject.store.service.TestStorageService) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) MastershipService(org.onosproject.mastership.MastershipService) IntReportConfig(org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Before(org.junit.Before)

Aggregations

IntReportConfig (org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig)4 IntIntent (org.onosproject.inbandtelemetry.api.IntIntent)2 IntIntentId (org.onosproject.inbandtelemetry.api.IntIntentId)2 IntDeviceConfig (org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 Test (org.junit.Test)1 KryoNamespace (org.onlab.util.KryoNamespace)1 ApplicationId (org.onosproject.core.ApplicationId)1 CoreService (org.onosproject.core.CoreService)1 IntIntentCodec (org.onosproject.inbandtelemetry.rest.IntIntentCodec)1 MastershipService (org.onosproject.mastership.MastershipService)1 DeviceId (org.onosproject.net.DeviceId)1 NetworkConfigEvent (org.onosproject.net.config.NetworkConfigEvent)1 NetworkConfigListener (org.onosproject.net.config.NetworkConfigListener)1 NetworkConfigRegistry (org.onosproject.net.config.NetworkConfigRegistry)1 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)1 DeviceService (org.onosproject.net.device.DeviceService)1