Search in sources :

Example 1 with Device

use of org.onosproject.net.Device 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 2 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class TestCodecService method getMockDevice.

private Device getMockDevice(boolean supportInt, DeviceId deviceId) {
    Device device = createNiceMock(Device.class);
    expect(device.is(IntProgrammable.class)).andReturn(supportInt).anyTimes();
    expect(device.id()).andReturn(deviceId).anyTimes();
    return device;
}
Also used : DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable)

Example 3 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class TestCodecService method testConfigTransitDevice.

@Test
public void testConfigTransitDevice() {
    reset(deviceService, hostService);
    Device device = getMockDevice(true, DEVICE_ID);
    IntProgrammable intProg = getMockIntProgrammable(false, true, false, false);
    setUpDeviceTest(device, intProg, false, false);
    replay(deviceService, hostService, device, intProg);
    installTestIntents();
    assertTrue(manager.configDevice(DEVICE_ID));
    verify(intProg);
}
Also used : DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable) Test(org.junit.Test)

Example 4 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class TestCodecService method testConfigSourceDevice.

@Test
public void testConfigSourceDevice() {
    reset(deviceService, hostService);
    Device device = getMockDevice(true, DEVICE_ID);
    IntProgrammable intProg = getMockIntProgrammable(true, false, false, false);
    setUpDeviceTest(device, intProg, true, false);
    IntObjective intObj = IntObjective.builder().withSelector(FLOW_SELECTOR2).build();
    expect(intProg.addIntObjective(eq(intObj))).andReturn(true).once();
    expect(intProg.setSourcePort(PortNumber.portNumber(1))).andReturn(true).once();
    expect(intProg.setSourcePort(PortNumber.portNumber(2))).andReturn(true).once();
    replay(deviceService, hostService, device, intProg);
    installTestIntents();
    assertTrue(manager.configDevice(DEVICE_ID));
    verify(intProg);
}
Also used : DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) IntObjective(org.onosproject.net.behaviour.inbandtelemetry.IntObjective) IntProgrammable(org.onosproject.net.behaviour.inbandtelemetry.IntProgrammable) Test(org.junit.Test)

Example 5 with Device

use of org.onosproject.net.Device in project onos by opennetworkinglab.

the class K8sRoutingSnatHandler method setExtIntfArpRule.

private void setExtIntfArpRule(K8sNode k8sNode, boolean install) {
    k8sNodeService.completeNodes().forEach(n -> {
        Device device = deviceService.getDevice(n.extBridge());
        TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).build();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setArpOp(ARP.OP_REPLY).extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setEthSrc(k8sNode.extBridgeMac()).setArpSha(k8sNode.extBridgeMac()).setArpSpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).setOutput(PortNumber.IN_PORT).build();
        k8sFlowRuleService.setRule(appId, n.extBridge(), selector, treatment, PRIORITY_STATEFUL_SNAT_RULE, EXT_ENTRY_TABLE, install);
    });
}
Also used : Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

Device (org.onosproject.net.Device)312 DeviceService (org.onosproject.net.device.DeviceService)102 DeviceId (org.onosproject.net.DeviceId)85 DefaultDevice (org.onosproject.net.DefaultDevice)50 Port (org.onosproject.net.Port)49 ConnectPoint (org.onosproject.net.ConnectPoint)45 Test (org.junit.Test)42 List (java.util.List)37 PortNumber (org.onosproject.net.PortNumber)33 DeviceEvent (org.onosproject.net.device.DeviceEvent)32 TrafficSelector (org.onosproject.net.flow.TrafficSelector)30 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)26 DefaultPort (org.onosproject.net.DefaultPort)25 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)25 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)24 ArrayList (java.util.ArrayList)24 Set (java.util.Set)24