Fixed HostToHost intent highlighting on topology view.
Also removed obsolete code from TVMHB.
Change-Id: I67e0c9bda5719ad2ae7217a163e24642747c7541
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
index 95c0cf4..0ad0585 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
@@ -44,14 +44,10 @@
import org.onosproject.net.HostId;
import org.onosproject.net.HostLocation;
import org.onosproject.net.Link;
-import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowRuleService;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.instructions.Instruction;
-import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.IntentService;
@@ -69,13 +65,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -83,7 +75,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;
-import static org.onosproject.net.DefaultEdgeLink.createEdgeLink;
import static org.onosproject.net.PortNumber.portNumber;
import static org.onosproject.ui.topo.TopoConstants.CoreButtons;
import static org.onosproject.ui.topo.TopoConstants.Properties;
@@ -483,47 +474,6 @@
return count;
}
- // Counts all flow entries that egress on the links of the given device.
- private Map<Link, Integer> getLinkFlowCounts(DeviceId deviceId) {
- // get the flows for the device
- List<FlowEntry> entries = new ArrayList<>();
- for (FlowEntry flowEntry : flowService.getFlowEntries(deviceId)) {
- entries.add(flowEntry);
- }
-
- // get egress links from device, and include edge links
- Set<Link> links = new HashSet<>(linkService.getDeviceEgressLinks(deviceId));
- Set<Host> hosts = hostService.getConnectedHosts(deviceId);
- if (hosts != null) {
- for (Host host : hosts) {
- links.add(createEdgeLink(host, false));
- }
- }
-
- // compile flow counts per link
- Map<Link, Integer> counts = new HashMap<>();
- for (Link link : links) {
- counts.put(link, getEgressFlows(link, entries));
- }
- return counts;
- }
-
- // Counts all entries that egress on the link source port.
- private int getEgressFlows(Link link, List<FlowEntry> entries) {
- int count = 0;
- PortNumber out = link.src().port();
- for (FlowEntry entry : entries) {
- TrafficTreatment treatment = entry.treatment();
- for (Instruction instruction : treatment.allInstructions()) {
- if (instruction.type() == Instruction.Type.OUTPUT &&
- ((OutputInstruction) instruction).port().equals(out)) {
- count++;
- }
- }
- }
- return count;
- }
-
// Returns host details response.
protected PropertyPanel hostDetails(HostId hostId) {
Host host = hostService.getHost(hostId);
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java
index 2849fd9..b2ba156 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TrafficMonitor.java
@@ -31,6 +31,7 @@
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
import org.onosproject.net.intent.FlowObjectiveIntent;
import org.onosproject.net.intent.FlowRuleIntent;
+import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.LinkCollectionIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
@@ -109,9 +110,9 @@
/**
* Constructs a traffic monitor.
*
- * @param trafficPeriod traffic task period in ms
- * @param servicesBundle bundle of services
- * @param msgHandler our message handler
+ * @param trafficPeriod traffic task period in ms
+ * @param servicesBundle bundle of services
+ * @param msgHandler our message handler
*/
public TrafficMonitor(long trafficPeriod, ServicesBundle servicesBundle,
TopologyViewMessageHandler msgHandler) {
@@ -133,9 +134,9 @@
* <p>
* The monitoring mode is expected to be one of:
* <ul>
- * <li>ALL_FLOW_TRAFFIC</li>
- * <li>ALL_PORT_TRAFFIC</li>
- * <li>SELECTED_INTENT</li>
+ * <li>ALL_FLOW_TRAFFIC</li>
+ * <li>ALL_PORT_TRAFFIC</li>
+ * <li>SELECTED_INTENT</li>
* </ul>
*
* @param mode monitoring mode
@@ -179,11 +180,11 @@
* <p>
* The monitoring mode is expected to be one of:
* <ul>
- * <li>DEV_LINK_FLOWS</li>
- * <li>RELATED_INTENTS</li>
+ * <li>DEV_LINK_FLOWS</li>
+ * <li>RELATED_INTENTS</li>
* </ul>
*
- * @param mode monitoring mode
+ * @param mode monitoring mode
* @param nodeSelection how to select a node
*/
public synchronized void monitor(Mode mode, NodeSelection nodeSelection) {
@@ -223,6 +224,7 @@
}
// TODO: move this out to the "h2h/multi-intent app"
+
/**
* Monitor for traffic data to be sent back to the web client, for the
* given intent.
@@ -308,7 +310,7 @@
selectedIntents = null;
}
- private synchronized void scheduleTask() {
+ private synchronized void scheduleTask() {
if (trafficTask == null) {
log.debug("Starting up background traffic task...");
trafficTask = new TrafficUpdateTask();
@@ -431,7 +433,7 @@
allBut.remove(current);
secondary = allBut;
log.debug("Highlight intent: {} ([{}] of {})",
- current.id(), selectedIntents.index(), count);
+ current.id(), selectedIntents.index(), count);
}
highlightIntentLinks(highlights, primary, secondary);
@@ -447,7 +449,7 @@
Set<Intent> primary = new HashSet<>();
primary.add(current);
log.debug("Highlight traffic for intent: {} ([{}] of {})",
- current.id(), selectedIntents.index(), selectedIntents.size());
+ current.id(), selectedIntents.index(), selectedIntents.size());
highlightIntentLinksWithTraffic(highlights, primary);
highlights.subdueAllElse(Amount.MINIMALLY);
@@ -505,14 +507,13 @@
private Map<Link, Integer> getLinkFlowCounts(DeviceId deviceId) {
// get the flows for the device
List<FlowEntry> entries = new ArrayList<>();
- for (FlowEntry flowEntry : servicesBundle.flowService()
- .getFlowEntries(deviceId)) {
+ for (FlowEntry flowEntry : servicesBundle.flowService().getFlowEntries(deviceId)) {
entries.add(flowEntry);
}
// get egress links from device, and include edge links
Set<Link> links = new HashSet<>(servicesBundle.linkService()
- .getDeviceEgressLinks(deviceId));
+ .getDeviceEgressLinks(deviceId));
Set<Host> hosts = servicesBundle.hostService().getConnectedHosts(deviceId);
if (hosts != null) {
for (Host host : hosts) {
@@ -574,9 +575,9 @@
if (installable instanceof PathIntent) {
links = ((PathIntent) installable).path().links();
} else if (installable instanceof FlowRuleIntent) {
- links = linkResources(installable);
+ links = addEdgeLinksIfNeeded(intent, linkResources(installable));
} else if (installable instanceof FlowObjectiveIntent) {
- links = linkResources(installable);
+ links = addEdgeLinksIfNeeded(intent, linkResources(installable));
} else if (installable instanceof LinkCollectionIntent) {
links = ((LinkCollectionIntent) installable).links();
} else if (installable instanceof OpticalPathIntent) {
@@ -591,6 +592,19 @@
}
}
+ private Iterable<Link> addEdgeLinksIfNeeded(Intent parentIntent,
+ Collection<Link> links) {
+ if (parentIntent instanceof HostToHostIntent) {
+ links = new HashSet<>(links);
+ HostToHostIntent h2h = (HostToHostIntent) parentIntent;
+ Host h1 = servicesBundle.hostService().getHost(h2h.one());
+ Host h2 = servicesBundle.hostService().getHost(h2h.two());
+ links.add(createEdgeLink(h1, true));
+ links.add(createEdgeLink(h2, true));
+ }
+ return links;
+ }
+
private void updateHighlights(Highlights highlights, Iterable<Link> links) {
for (Link link : links) {
ensureNodePresent(highlights, link.src().elementId());