use of org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig in project onos by opennetworkinglab.
the class TestCodecService method setUpDeviceTest.
private void setUpDeviceTest(Device device, IntProgrammable intProg, boolean hostConnected, boolean setupIntConfig) {
expect(device.as(IntProgrammable.class)).andReturn(intProg).anyTimes();
expect(deviceService.getDevice(eq(DEVICE_ID))).andReturn(device).anyTimes();
expect(deviceService.getDevices()).andReturn(ImmutableList.of(device)).anyTimes();
if (setupIntConfig) {
IntDeviceConfig expectedConfig = createIntDeviceConfig();
expect(intProg.setupIntConfig(eq(expectedConfig))).andReturn(true).atLeastOnce();
}
expect(deviceService.getPorts(DEVICE_ID)).andReturn(DEVICE_PORTS).anyTimes();
if (hostConnected) {
HOSTS.forEach((cp, host) -> {
expect(hostService.getConnectedHosts(eq(cp))).andReturn(ImmutableSet.of(host)).anyTimes();
});
expect(hostService.getConnectedHosts(eq(DEVICE_ID))).andReturn(Sets.newHashSet(HOSTS.values()));
} else {
expect(hostService.getConnectedHosts(eq(DEVICE_ID))).andReturn(ImmutableSet.of()).anyTimes();
}
}
use of org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig 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.net.behaviour.inbandtelemetry.IntDeviceConfig 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