Search in sources :

Example 1 with Intent

use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.

the class IntentSynchronizerTest method testIntentSync.

/**
 * Tests the synchronization behavior of intent synchronizer. We set up
 * a discrepancy between the intent service state and the intent
 * synchronizer's state and ensure that this is reconciled correctly.
 */
@Test
public void testIntentSync() {
    // Construct routes and intents.
    // This test simulates the following cases during the master change
    // time interval:
    // 1. intent1 did not change and the intent also did not change.
    // 2. intent2 was deleted, but the intent was not deleted.
    // 3. intent3 was newly added, and the intent was also submitted.
    // 4. intent4 was updated to RouteEntry4Update, and the intent was
    // also updated to a new one.
    // 5. intent5 did not change, but its intent id changed.
    // 6. intent6 was newly added, but the intent was not submitted.
    MultiPointToSinglePointIntent intent1 = intentBuilder(Ip4Prefix.valueOf("1.1.1.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    MultiPointToSinglePointIntent intent2 = intentBuilder(Ip4Prefix.valueOf("2.2.2.0/24"), "00:00:00:00:00:02", SW2_ETH1);
    MultiPointToSinglePointIntent intent3 = intentBuilder(Ip4Prefix.valueOf("3.3.3.0/24"), "00:00:00:00:00:03", SW3_ETH1);
    MultiPointToSinglePointIntent intent4 = intentBuilder(Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:03", SW3_ETH1);
    MultiPointToSinglePointIntent intent4Update = intentBuilder(Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:02", SW2_ETH1);
    MultiPointToSinglePointIntent intent5 = intentBuilder(Ip4Prefix.valueOf("5.5.5.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    MultiPointToSinglePointIntent intent7 = intentBuilder(Ip4Prefix.valueOf("7.7.7.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    MultiPointToSinglePointIntent intent6 = intentBuilder(Ip4Prefix.valueOf("6.6.6.0/24"), "00:00:00:00:00:01", SW1_ETH1);
    // Set up expectation
    Set<Intent> intents = new HashSet<>();
    intents.add(intent1);
    EasyMock.expect(intentService.getIntentState(intent1.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent2);
    EasyMock.expect(intentService.getIntentState(intent2.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent4);
    EasyMock.expect(intentService.getIntentState(intent4.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent5);
    EasyMock.expect(intentService.getIntentState(intent5.key())).andReturn(IntentState.INSTALLED).anyTimes();
    intents.add(intent7);
    EasyMock.expect(intentService.getIntentState(intent7.key())).andReturn(IntentState.WITHDRAWING).anyTimes();
    EasyMock.expect(intentService.getIntents()).andReturn(intents).anyTimes();
    // These are the operations that should be done to the intentService
    // during synchronization
    intentService.withdraw(intent2);
    intentService.submit(intent3);
    intentService.submit(intent4Update);
    intentService.submit(intent6);
    intentService.submit(intent7);
    EasyMock.replay(intentService);
    // Start the test
    // Simulate some input from the clients. The intent synchronizer has not
    // gained the global leadership yet, but it will remember this input for
    // when it does.
    intentSynchronizer.submit(intent1);
    intentSynchronizer.submit(intent2);
    intentSynchronizer.withdraw(intent2);
    intentSynchronizer.submit(intent3);
    intentSynchronizer.submit(intent4);
    intentSynchronizer.submit(intent4Update);
    intentSynchronizer.submit(intent5);
    intentSynchronizer.submit(intent6);
    intentSynchronizer.submit(intent7);
    // Give the leadership to the intent synchronizer. It will now attempt
    // to synchronize the intents in the store with the intents it has
    // recorded based on the earlier user input.
    intentSynchronizer.modifyPrimary(true);
    EasyMock.verify(intentService);
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 2 with Intent

use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.

the class IntentSynchronizerTest method testSubmit.

/**
 * Tests the behavior of the submit API, both when the synchronizer has
 * leadership and when it does not.
 */
@Test
public void testSubmit() {
    IpPrefix prefix = Ip4Prefix.valueOf("1.1.1.0/24");
    Intent intent = intentBuilder(prefix, "00:00:00:00:00:01", SW1_ETH1);
    // Set up expectations
    intentService.submit(intent);
    EasyMock.expect(intentService.getIntents()).andReturn(Collections.emptyList()).anyTimes();
    EasyMock.replay(intentService);
    // Give the intent synchronizer leadership so it will submit intents
    // to the intent service
    intentSynchronizer.modifyPrimary(true);
    // Test the submit
    intentSynchronizer.submit(intent);
    EasyMock.verify(intentService);
    // Now we'll remove leadership from the intent synchronizer and verify
    // that it does not submit any intents to the intent service when we
    // call the submit API
    EasyMock.reset(intentService);
    EasyMock.replay(intentService);
    intentSynchronizer.modifyPrimary(false);
    intentSynchronizer.submit(intent);
    EasyMock.verify(intentService);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 3 with Intent

use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.

the class OpticalPathProvisioner method createIntents.

/**
 * Scans the list of cross connection points and returns a list of optical connectivity intents.
 * During the process, save information about packet links to given set.
 *
 * @param crossConnectPoints list of (src, dst) pair between which optical path will be set up
 * @return list of optical connectivity intents
 */
private List<Intent> createIntents(List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints) {
    List<Intent> intents = new LinkedList<>();
    Iterator<Pair<ConnectPoint, ConnectPoint>> itr = crossConnectPoints.iterator();
    while (itr.hasNext()) {
        // checkArgument at start ensures we'll always have pairs of connect points
        Pair<ConnectPoint, ConnectPoint> next = itr.next();
        ConnectPoint src = next.getLeft();
        ConnectPoint dst = next.getRight();
        Port srcPort = deviceService.getPort(src.deviceId(), src.port());
        Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
        if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
            OduCltPort srcOCPort = (OduCltPort) srcPort;
            OduCltPort dstOCPort = (OduCltPort) dstPort;
            if (!srcOCPort.signalType().equals(dstOCPort.signalType())) {
                continue;
            }
            // Create OTN circuit
            OpticalCircuitIntent circuitIntent = OpticalCircuitIntent.builder().appId(appId).src(src).dst(dst).signalType(srcOCPort.signalType()).bidirectional(false).build();
            intents.add(circuitIntent);
        } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
            OchPort srcOchPort = (OchPort) srcPort;
            OchPort dstOchPort = (OchPort) dstPort;
            if (!srcOchPort.signalType().equals(dstOchPort.signalType())) {
                continue;
            }
            // Create lightpath
            OpticalConnectivityIntent opticalIntent = OpticalConnectivityIntent.builder().appId(appId).src(src).dst(dst).signalType(srcOchPort.signalType()).bidirectional(false).build();
            intents.add(opticalIntent);
        } else {
            log.warn("Unsupported cross connect point types {} {}", srcPort.type(), dstPort.type());
            return Collections.emptyList();
        }
    }
    return intents;
}
Also used : Port(org.onosproject.net.Port) OchPort(org.onosproject.net.optical.OchPort) OduCltPort(org.onosproject.net.optical.OduCltPort) OduCltPort(org.onosproject.net.optical.OduCltPort) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Intent(org.onosproject.net.intent.Intent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) LinkedList(java.util.LinkedList) OchPort(org.onosproject.net.optical.OchPort) Pair(org.apache.commons.lang3.tuple.Pair)

Example 4 with Intent

use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.

the class OpticalPathProvisioner method setupPath.

/*
     * Given a multi-layer path,
     * compute a set of segments which requires
     * OpticalConnectivity(~=OpticalConnectivityIntent or OpticalCircuitPath)
     * to provide packet-layer connectivity.
     */
@Override
public OpticalConnectivityId setupPath(Path path, Bandwidth bandwidth, Duration latency) {
    checkNotNull(path);
    log.debug("setupPath({}, {}, {})", path, bandwidth, latency);
    // map of cross connect points (optical port -> packet port)
    Map<ConnectPoint, ConnectPoint> crossConnectPointMap = new HashMap<>();
    // list of (src, dst) pair of optical ports between which optical path should be installed
    List<Pair<ConnectPoint, ConnectPoint>> crossConnectPoints = new ArrayList<>();
    // Scan path to find pairs of connect points between which optical intent is installed
    // opticalSrcPort works as a flag parameter to show scanning status
    ConnectPoint opticalSrcPort = null;
    for (Link link : path.links()) {
        if (!isCrossConnectLink(link)) {
            continue;
        }
        if (opticalSrcPort != null) {
            // opticalSrcPort!=null means src port was already found
            // in this case link.src() is optical layer, and link.dst() is packet layer
            // Check if types of src port and dst port matches
            Device srcDevice = checkNotNull(deviceService.getDevice(opticalSrcPort.deviceId()), "Unknown device ID");
            Device dstDevice = checkNotNull(deviceService.getDevice(link.src().deviceId()), "Unknown device ID");
            if (srcDevice.type() != dstDevice.type()) {
                log.error("Unsupported mix of cross connect points : {}, {}", srcDevice.type(), dstDevice.type());
                return null;
            }
            // Update cross connect points map
            crossConnectPointMap.put(link.src(), link.dst());
            // Add optical ports pair to list
            crossConnectPoints.add(Pair.of(opticalSrcPort, link.src()));
            // Reset flag parameter
            opticalSrcPort = null;
        } else {
            // opticalSrcPort==null means src port was not found yet
            // in this case link.src() is packet layer, and link.dst() is optical layer
            // Update cross connect points map
            crossConnectPointMap.put(link.dst(), link.src());
            // Set opticalSrcPort to src of link (optical port)
            opticalSrcPort = link.dst();
        }
    }
    // create intents from cross connect points
    List<Intent> intents = createIntents(crossConnectPoints);
    if (intents.isEmpty()) {
        log.error("No intents produced from {}", crossConnectPoints);
        return null;
    }
    // create set of PacketLinkRealizedByOptical
    Set<PacketLinkRealizedByOptical> packetLinks = createPacketLinkSet(crossConnectPoints, intents, crossConnectPointMap);
    // create OpticalConnectivity object and store information to distributed store
    OpticalConnectivity connectivity = createConnectivity(path, bandwidth, latency, packetLinks);
    // store cross connect port usage
    path.links().stream().filter(this::isCrossConnectLink).forEach(usedCrossConnectLinkSet::add);
    // Submit the intents
    for (Intent i : intents) {
        intentService.submit(i);
        log.debug("Submitted an intent: {}", i);
    }
    return connectivity.id();
}
Also used : HashMap(java.util.HashMap) Device(org.onosproject.net.Device) ArrayList(java.util.ArrayList) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Intent(org.onosproject.net.intent.Intent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with Intent

use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.

the class GnpyManager method obtainConnectivity.

@Override
public Pair<IntentId, Double> obtainConnectivity(ConnectPoint ingress, ConnectPoint egress, boolean bidirectional) {
    ByteArrayOutputStream connectivityRequest = createGnpyRequest(ingress, egress, bidirectional);
    String response = gnpyHttpUtil.post(null, "/gnpy-experimental", new ByteArrayInputStream(connectivityRequest.toByteArray()), MediaType.APPLICATION_JSON_TYPE, String.class);
    ObjectMapper om = new ObjectMapper();
    final ObjectReader reader = om.reader();
    JsonNode jsonNode;
    try {
        jsonNode = reader.readTree(response);
        if (jsonNode == null) {
            log.error("JsonNode is null for response {}", response);
            return null;
        }
        log.info("Response {}", response);
        String bestPath;
        try {
            bestPath = getBestOsnrPathKey(jsonNode);
        } catch (IllegalStateException e) {
            log.error("Exception while contacting GNPy", e);
            return null;
        }
        OchSignal ochSignal = createOchSignal(jsonNode);
        Map<DeviceId, Double> deviceAtoBPowerMap = new HashMap<>();
        Map<DeviceId, Double> deviceBtoAPowerMap = new HashMap<>();
        // TODO this list is currently only populated in the forward direction
        List<DeviceId> deviceIds = getDeviceAndPopulatePowerMap(jsonNode, deviceAtoBPowerMap, deviceBtoAPowerMap, bestPath);
        Path suggestedPath = createSuggestedPath(deviceIds);
        log.info("Suggested path {}", suggestedPath);
        Intent intent = createOpticalIntent(ingress, egress, deviceService, null, appId, bidirectional, ochSignal, suggestedPath);
        intentsPowerMap.put(intent.id(), new GnpyPowerInfo(deviceAtoBPowerMap, deviceBtoAPowerMap, getLaunchPower(jsonNode), suggestedPath.links(), ingress, egress, ochSignal));
        intentService.submit(intent);
        return Pair.of(intent.id(), getOsnr(jsonNode, bestPath));
    } catch (IOException e) {
        log.error("Exception while reading response {}", response, e);
        return null;
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) OchSignal(org.onosproject.net.OchSignal) JsonNode(com.fasterxml.jackson.databind.JsonNode) OpticalIntentUtility.createOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createOpticalIntent) Intent(org.onosproject.net.intent.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Intent (org.onosproject.net.intent.Intent)280 Test (org.junit.Test)176 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)133 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)110 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)108 FlowRule (org.onosproject.net.flow.FlowRule)90 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)87 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)84 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)77 List (java.util.List)75 Collectors (java.util.stream.Collectors)71 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)70 PathIntent (org.onosproject.net.intent.PathIntent)70 Collection (java.util.Collection)60 VlanId (org.onlab.packet.VlanId)60 TrafficSelector (org.onosproject.net.flow.TrafficSelector)60 CoreService (org.onosproject.core.CoreService)59 Collections (java.util.Collections)57 ImmutableSet (com.google.common.collect.ImmutableSet)54