Search in sources :

Example 6 with TrafficLinkMap

use of org.onosproject.ui.impl.topo.util.TrafficLinkMap in project onos by opennetworkinglab.

the class ProtectedIntentMonitor method protectedIntentHighlights.

// =======================================================================
// === Generate messages in JSON object node format
private Highlights protectedIntentHighlights() {
    Highlights highlights = new Highlights();
    TrafficLinkMap linkMap = new TrafficLinkMap();
    IntentService intentService = services.intent();
    if (selectedIntent != null) {
        List<Intent> installables = intentService.getInstallableIntents(selectedIntent.key());
        if (installables != null) {
            ProtectionEndpointIntent ep1 = installables.stream().filter(ProtectionEndpointIntent.class::isInstance).map(ProtectionEndpointIntent.class::cast).findFirst().orElse(null);
            ProtectionEndpointIntent ep2 = installables.stream().filter(ii -> !ii.equals(ep1)).filter(ProtectionEndpointIntent.class::isInstance).map(ProtectionEndpointIntent.class::cast).findFirst().orElse(null);
            if (ep1 == null || ep2 == null) {
                log.warn("Selected Intent {} didn't have 2 protection endpoints", selectedIntent.key());
                stopMonitoring();
                return highlights;
            }
            Set<Link> primary = new LinkedHashSet<>();
            Set<Link> backup = new LinkedHashSet<>();
            Map<Boolean, List<FlowRuleIntent>> transits = installables.stream().filter(FlowRuleIntent.class::isInstance).map(FlowRuleIntent.class::cast).collect(Collectors.groupingBy(this::isPrimary));
            // walk primary
            ConnectPoint primHead = ep1.description().paths().get(0).output().connectPoint();
            ConnectPoint primTail = ep2.description().paths().get(0).output().connectPoint();
            List<FlowRuleIntent> primTransit = transits.getOrDefault(true, ImmutableList.of());
            populateLinks(primary, primHead, primTail, primTransit);
            // walk backup
            ConnectPoint backHead = ep1.description().paths().get(1).output().connectPoint();
            ConnectPoint backTail = ep2.description().paths().get(1).output().connectPoint();
            List<FlowRuleIntent> backTransit = transits.getOrDefault(false, ImmutableList.of());
            populateLinks(backup, backHead, backTail, backTransit);
            // Add packet to optical links
            if (!usingBackup(primary)) {
                primary.addAll(protectedIntentMultiLayer(primHead, primTail));
            }
            backup.addAll(protectedIntentMultiLayer(backHead, backTail));
            boolean isOptical = selectedIntent instanceof OpticalConnectivityIntent;
            // Flavor is swapped so green is primary path.
            if (usingBackup(primary)) {
                // the backup becomes in use so we have a dotted line
                processLinks(linkMap, backup, Flavor.PRIMARY_HIGHLIGHT, isOptical, true, PROTECTED_MOD_BACKUP_SET);
            } else {
                processLinks(linkMap, primary, Flavor.PRIMARY_HIGHLIGHT, isOptical, true, PROTECTED_MOD_PRIMARY_SET);
                processLinks(linkMap, backup, Flavor.SECONDARY_HIGHLIGHT, isOptical, false, PROTECTED_MOD_BACKUP_SET);
            }
            updateHighlights(highlights, primary);
            updateHighlights(highlights, backup);
            colorLinks(highlights, linkMap);
            highlights.subdueAllElse(Highlights.Amount.MINIMALLY);
        } else {
            log.debug("Selected Intent has no installable intents");
        }
    } else {
        log.debug("Selected Intent is null");
    }
    return highlights;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntentService(org.onosproject.net.intent.IntentService) Highlights(org.onosproject.ui.topo.Highlights) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) TrafficLinkMap(org.onosproject.ui.impl.topo.util.TrafficLinkMap) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) List(java.util.List) Link(org.onosproject.net.Link) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Aggregations

TrafficLinkMap (org.onosproject.ui.impl.topo.util.TrafficLinkMap)5 Link (org.onosproject.net.Link)3 TrafficLink (org.onosproject.ui.impl.topo.util.TrafficLink)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Device (org.onosproject.net.Device)2 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)2 Intent (org.onosproject.net.intent.Intent)2 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)2 Highlights (org.onosproject.ui.topo.Highlights)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1