Search in sources :

Example 6 with Intent

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

the class PeerConnectivityManagerTest method testConnectionSetup.

/**
 * Tests whether peer connectivity manager can set up correct BGP and
 * ICMP intents according to specific configuration.
 * <p/>
 * Two tricky cases included in the configuration are: 2 peers on a same
 * switch port, peer on the same switch with BGPd.
 */
@Test
public void testConnectionSetup() {
    reset(intentSynchronizer);
    // Setup the expected intents
    for (Intent intent : intentList) {
        intentSynchronizer.submit(eqExceptId(intent));
    }
    replay(intentSynchronizer);
    // Running the interface to be tested.
    peerConnectivityManager.start();
    verify(intentSynchronizer);
}
Also used : Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 7 with Intent

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

the class SimpleFabricRouting method dump.

// Dump Cli Handler
private void dump(String subject, PrintStream out) {
    if ("intents".equals(subject)) {
        out.println("Routing Route Intents:\n");
        for (Intent entry : intentService.getIntents()) {
            if (appId.equals(entry.appId())) {
                MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
                out.println("    " + intent.key().toString() + " to " + intent.egressPoint().toString() + " set " + intent.treatment().immediate().toString() + " from " + intent.ingressPoints().toString());
            }
        }
        out.println("");
        out.println("Routing Intercept Flow Rules:\n");
        List<FlowRule> rules = new ArrayList(interceptFlowRules);
        Collections.sort(rules, new Comparator<FlowRule>() {

            @Override
            public int compare(FlowRule a, FlowRule b) {
                int r = a.deviceId().toString().compareTo(b.deviceId().toString());
                // descending on priority
                return (r != 0) ? r : Integer.compare(b.priority(), a.priority());
            }
        });
        for (FlowRule rule : rules) {
            out.println("    device=" + rule.deviceId().toString() + " priority=" + rule.priority() + " selector=" + rule.selector().criteria().toString());
        }
        out.println("");
        out.println("Routing Intents to Be Purged:\n");
        for (Key key : toBePurgedIntentKeys) {
            out.println("    " + key.toString());
        }
        out.println("");
    } else if ("reactive-intents".equals(subject)) {
        for (Intent entry : intentService.getIntents()) {
            if (appId.equals(entry.appId())) {
                MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
                out.println(intent.key().toString() + " to " + intent.egressPoint().toString() + " set " + intent.treatment().immediate().toString() + " from " + intent.ingressPoints().toString());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Key(org.onosproject.net.intent.Key)

Example 8 with Intent

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

the class SimpleFabricRouting method withdrawAllReactiveIntents.

public void withdrawAllReactiveIntents() {
    // check all intents of this app
    // NOTE: cli calls are handling within the cli called node only; so should not user inents.isLocal()
    Set<Intent> myIntents = new HashSet<>();
    for (Intent intent : intentService.getIntents()) {
        if (appId.equals(intent.appId())) {
            myIntents.add(intent);
        }
    }
    // withdraw all my intents
    for (Intent intent : myIntents) {
        switch(intentService.getIntentState(intent.key())) {
            case FAILED:
                intentService.purge(intent);
                toBePurgedIntentKeys.add(intent.key());
                break;
            case WITHDRAWN:
                intentService.purge(intent);
                toBePurgedIntentKeys.add(intent.key());
                break;
            case INSTALL_REQ:
            case INSTALLED:
            case INSTALLING:
            case RECOMPILING:
            case COMPILING:
                intentService.withdraw(intent);
                toBePurgedIntentKeys.add(intent.key());
                break;
            case WITHDRAW_REQ:
            case WITHDRAWING:
                toBePurgedIntentKeys.add(intent.key());
                break;
            case PURGE_REQ:
            case CORRUPT:
            default:
                // no action
                break;
        }
    }
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) HashSet(java.util.HashSet)

Example 9 with Intent

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

the class SimpleFabricRouting method refreshRouteIntents.

/**
 * Refresh routes by examining network resource status.
 */
private void refreshRouteIntents() {
    for (Intent entry : intentService.getIntents()) {
        if (!appId.equals(entry.appId())) {
            continue;
        }
        MultiPointToSinglePointIntent intent = (MultiPointToSinglePointIntent) entry;
        if (!intentService.isLocal(intent.key())) {
            if (toBePurgedIntentKeys.contains(intent.key())) {
                // clear non local intent
                toBePurgedIntentKeys.remove(intent.key());
            }
            continue;
        }
        try {
            switch(intentService.getIntentState(intent.key())) {
                // case FAILED:   // failed intent is not auto removed
                case WITHDRAWN:
                    log.warn("intent found failed or withdrawn; " + "remove and try to purge intent: key={}", intent.key());
                    // purge intents here without withdraw
                    intentService.purge(intentService.getIntent(intent.key()));
                    toBePurgedIntentKeys.add(intent.key());
                    continue;
                default:
                    // no action
                    break;
            }
        } catch (Exception e) {
            log.warn("intent status lookup failed: error={}", e);
            // this intent seems invalid; no action
            continue;
        }
        // dummy loop to break on remove cases
        if (!deviceService.isAvailable(intent.egressPoint().deviceId())) {
            log.info("refresh route intents; remove intent for no device: key={}", intent.key());
            intentService.withdraw(intentService.getIntent(intent.key()));
            toBePurgedIntentKeys.add(intent.key());
            continue;
        }
        if (!(simpleFabric.fabricNetwork(intent.egressPoint(), VlanId.NONE) != null || (REACTIVE_ALLOW_LINK_CP && !linkService.getEgressLinks(intent.egressPoint()).isEmpty()))) {
            log.info("refresh route intents; remove intent for egress point not available: key={}", intent.key());
            intentService.withdraw(intentService.getIntent(intent.key()));
            toBePurgedIntentKeys.add(intent.key());
            continue;
        }
        // MAY NEED TO CHECK: intent.egressPoint and intent.treatment's dstMac is valid against hosts
        if (REACTIVE_SINGLE_TO_SINGLE && !REACTIVE_ALLOW_LINK_CP) {
            // single path intent only; no need to check ingress points
            continue;
        }
        Set<FilteredConnectPoint> newIngressPoints = new HashSet<>();
        boolean ingressPointChanged = false;
        for (FilteredConnectPoint cp : intent.filteredIngressPoints()) {
            if (deviceService.isAvailable(cp.connectPoint().deviceId()) && (simpleFabric.fabricNetwork(cp.connectPoint(), VlanId.NONE) != null || (REACTIVE_ALLOW_LINK_CP && !linkService.getIngressLinks(cp.connectPoint()).isEmpty()))) {
                newIngressPoints.add(cp);
            } else {
                log.info("refresh route ingress cp of " + "not in 2Networks nor links: {}", cp);
                ingressPointChanged = true;
            }
        }
        if (newIngressPoints.isEmpty()) {
            log.info("refresh route intents; " + "remove intent for no ingress nor egress point available: key={}", intent.key());
            intentService.withdraw(intentService.getIntent(intent.key()));
            toBePurgedIntentKeys.add(intent.key());
            continue;
        }
        // update ingress points
        if (ingressPointChanged) {
            MultiPointToSinglePointIntent updatedIntent = MultiPointToSinglePointIntent.builder().appId(appId).key(intent.key()).selector(intent.selector()).treatment(intent.treatment()).filteredIngressPoints(newIngressPoints).filteredEgressPoint(intent.filteredEgressPoint()).priority(intent.priority()).constraints(intent.constraints()).build();
            log.info("refresh route update intent: key={} updatedIntent={}", intent.key(), updatedIntent);
            // may remove from old purged entry
            toBePurgedIntentKeys.remove(intent.key());
            intentService.submit(updatedIntent);
        }
    }
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HashSet(java.util.HashSet)

Example 10 with Intent

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

the class SimpleFabricRouting method checkIntentsPurge.

private void checkIntentsPurge() {
    // check intents to be purge
    if (!toBePurgedIntentKeys.isEmpty()) {
        Set<Key> removeKeys = new HashSet<>();
        for (Key key : toBePurgedIntentKeys) {
            if (!intentService.isLocal(key)) {
                removeKeys.add(key);
                continue;
            }
            Intent intentToPurge = intentService.getIntent(key);
            if (intentToPurge == null) {
                log.info("purged intent: key={}", key);
                removeKeys.add(key);
            } else {
                switch(intentService.getIntentState(key)) {
                    // case FAILED:  // not auto removed
                    case WITHDRAWN:
                        log.info("try to purge intent: key={}", key);
                        intentService.purge(intentToPurge);
                        break;
                    case INSTALL_REQ:
                    case INSTALLED:
                    case INSTALLING:
                    case RECOMPILING:
                    case COMPILING:
                        log.warn("not to purge for active intent: key={}", key);
                        removeKeys.add(key);
                        break;
                    case WITHDRAW_REQ:
                    case WITHDRAWING:
                    case PURGE_REQ:
                    case CORRUPT:
                    default:
                        // no action
                        break;
                }
            }
        }
        toBePurgedIntentKeys.removeAll(removeKeys);
    }
}
Also used : MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) Key(org.onosproject.net.intent.Key) HashSet(java.util.HashSet)

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