[AETHER-38] Extract pipeline-dependent code from current T3 implementation
- Executes also a refactoring of several components of the app;
- Uses the new abstractions introduced in the ONOS core and
deprecates the old ones
- Deprecates unused APIs of the TroubleshootService
- Generator and other utils has been moved to the ONOS core
- Updates and fixes unit tests to make the build happy
Change-Id: Iac9ba644e1e199a58e8da53d0db78e36db56647c
diff --git a/app/src/main/java/org/onosproject/t3/api/FlowNib.java b/app/src/main/java/org/onosproject/t3/api/FlowNib.java
index b9f2226..1b70551 100644
--- a/app/src/main/java/org/onosproject/t3/api/FlowNib.java
+++ b/app/src/main/java/org/onosproject/t3/api/FlowNib.java
@@ -67,7 +67,7 @@
.filter(flow -> flow.state() == flowState
&& flow.deviceId().equals(deviceId))
.collect(Collectors.toSet());
- return flowsFiltered != null ? ImmutableSet.copyOf(flowsFiltered) : ImmutableSet.of();
+ return ImmutableSet.copyOf(flowsFiltered);
}
/**
diff --git a/app/src/main/java/org/onosproject/t3/api/GroupNib.java b/app/src/main/java/org/onosproject/t3/api/GroupNib.java
index b1fb563..14f55a7 100644
--- a/app/src/main/java/org/onosproject/t3/api/GroupNib.java
+++ b/app/src/main/java/org/onosproject/t3/api/GroupNib.java
@@ -56,6 +56,21 @@
}
/**
+ * Returns all groups associated with the given device and filtered by the group state.
+ *
+ * @param deviceId device ID to get groups for
+ * @param groupState the group state
+ * @return iterable of device's groups
+ */
+ public Iterable<Group> getGroupsByState(DeviceId deviceId, Group.GroupState groupState) {
+ Set<Group> groupsFiltered = groups.stream()
+ .filter(group -> group.state() == groupState
+ && group.deviceId().equals(deviceId))
+ .collect(Collectors.toSet());
+ return ImmutableSet.copyOf(groupsFiltered);
+ }
+
+ /**
* Returns all groups associated with the given device.
*
* @param deviceId device ID to get groups for
@@ -63,9 +78,9 @@
*/
public Iterable<Group> getGroups(DeviceId deviceId) {
Set<Group> groupsFiltered = groups.stream()
- .filter(g -> g.deviceId().equals(deviceId))
+ .filter(group -> group.deviceId().equals(deviceId))
.collect(Collectors.toSet());
- return groupsFiltered != null ? ImmutableSet.copyOf(groupsFiltered) : ImmutableSet.of();
+ return ImmutableSet.copyOf(groupsFiltered);
}
/**
diff --git a/app/src/main/java/org/onosproject/t3/api/GroupsInDevice.java b/app/src/main/java/org/onosproject/t3/api/GroupsInDevice.java
index 74203af..b17cfbb 100644
--- a/app/src/main/java/org/onosproject/t3/api/GroupsInDevice.java
+++ b/app/src/main/java/org/onosproject/t3/api/GroupsInDevice.java
@@ -25,8 +25,9 @@
/**
* Class to represent the groups in a device for a given output and packet.
+ * @deprecated in t3-4.0
*/
-//FIXME consider name change.
+@Deprecated
public class GroupsInDevice {
private ConnectPoint output;
diff --git a/app/src/main/java/org/onosproject/t3/api/StaticPacketTrace.java b/app/src/main/java/org/onosproject/t3/api/StaticPacketTrace.java
index 22db007..57e1dce 100644
--- a/app/src/main/java/org/onosproject/t3/api/StaticPacketTrace.java
+++ b/app/src/main/java/org/onosproject/t3/api/StaticPacketTrace.java
@@ -21,6 +21,7 @@
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
+import org.onosproject.net.PipelineTraceableHitChain;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.TrafficSelector;
@@ -36,10 +37,11 @@
*/
public class StaticPacketTrace {
- private final TrafficSelector inPacket;
- private final ConnectPoint in;
+ private final TrafficSelector ingressPacket;
+ private final ConnectPoint ingressPoint;
List<List<ConnectPoint>> completePaths;
private Map<DeviceId, List<GroupsInDevice>> outputsForDevice;
+ private Map<DeviceId, List<PipelineTraceableHitChain>> hitChainsForDevice;
private Map<DeviceId, List<FlowEntry>> flowsForDevice;
private StringBuilder resultMessage;
private Pair<Host, Host> hosts;
@@ -48,15 +50,16 @@
/**
* Builds the trace with a given packet and a connect point.
*
- * @param packet the packet to trace
- * @param in the initial connect point
+ * @param inPacket the packet to trace
+ * @param inPoint the initial connect point
*/
- public StaticPacketTrace(TrafficSelector packet, ConnectPoint in) {
- this.inPacket = packet;
- this.in = in;
+ public StaticPacketTrace(TrafficSelector inPacket, ConnectPoint inPoint) {
+ this.ingressPacket = inPacket;
+ this.ingressPoint = inPoint;
completePaths = new ArrayList<>();
outputsForDevice = new HashMap<>();
flowsForDevice = new HashMap<>();
+ hitChainsForDevice = new HashMap<>();
resultMessage = new StringBuilder();
hosts = null;
}
@@ -64,16 +67,17 @@
/**
* Builds the trace with a given packet and a connect point.
*
- * @param packet the packet to trace
- * @param in the initial connect point
- * @param hosts pair of source and destination hosts
+ * @param inPacket the packet to trace
+ * @param inPoint the initial connect point
+ * @param hosts pair of source and destination hosts
*/
- public StaticPacketTrace(TrafficSelector packet, ConnectPoint in, Pair<Host, Host> hosts) {
- this.inPacket = packet;
- this.in = in;
+ public StaticPacketTrace(TrafficSelector inPacket, ConnectPoint inPoint, Pair<Host, Host> hosts) {
+ this.ingressPacket = inPacket;
+ this.ingressPoint = inPoint;
completePaths = new ArrayList<>();
outputsForDevice = new HashMap<>();
flowsForDevice = new HashMap<>();
+ hitChainsForDevice = new HashMap<>();
resultMessage = new StringBuilder();
this.hosts = hosts;
}
@@ -84,7 +88,7 @@
* @return the initial packet in the form of a selector.
*/
public TrafficSelector getInitialPacket() {
- return inPacket;
+ return ingressPacket;
}
/**
@@ -93,7 +97,7 @@
* @return the connect point
*/
public ConnectPoint getInitialConnectPoint() {
- return in;
+ return ingressPoint;
}
/**
@@ -122,7 +126,9 @@
*
* @param deviceId the device
* @param outputPath the groups in device objects
+ * @deprecated in t3-4.0
*/
+ @Deprecated
public void addGroupOutputPath(DeviceId deviceId, GroupsInDevice outputPath) {
if (!outputsForDevice.containsKey(deviceId)) {
outputsForDevice.put(deviceId, new ArrayList<>());
@@ -131,16 +137,48 @@
}
/**
+ * Adds the pipeline hit chain for a given device.
+ *
+ * @param deviceId the device
+ * @param hitChain the hit chain
+ */
+ public void addHitChain(DeviceId deviceId, PipelineTraceableHitChain hitChain) {
+ hitChainsForDevice.compute(deviceId, (k, v) -> {
+ if (v == null) {
+ v = new ArrayList<>();
+ }
+ if (!v.contains(hitChain)) {
+ v.add(hitChain);
+ }
+ return v;
+ });
+ }
+
+ /**
* Returns all the possible group-based outputs for a given device.
*
* @param deviceId the device
* @return the list of Groups for this device.
+ * @deprecated in t3-4.0
*/
+ @Deprecated
public List<GroupsInDevice> getGroupOuputs(DeviceId deviceId) {
return outputsForDevice.get(deviceId) == null ? null : ImmutableList.copyOf(outputsForDevice.get(deviceId));
}
/**
+ * Returns all the possible pipeline hit chains for a given device.
+ *
+ * @param deviceId the device
+ * @return the list of hit chains
+ */
+ public List<PipelineTraceableHitChain> getHitChains(DeviceId deviceId) {
+ List<PipelineTraceableHitChain> hitChains = hitChainsForDevice.get(deviceId);
+ return hitChains == null ? null : ImmutableList.copyOf(hitChains);
+
+ }
+
+ /**
* Adds a complete possible path.
*
* @param completePath the path
@@ -163,7 +201,9 @@
*
* @param deviceId the device considered
* @param flows the flows
+ * @deprecated in t3-4.0
*/
+ @Deprecated
public void addFlowsForDevice(DeviceId deviceId, List<FlowEntry> flows) {
flowsForDevice.put(deviceId, flows);
}
@@ -173,7 +213,9 @@
*
* @param deviceId the device
* @return the flows matched
+ * @deprecated in t3-4.0
*/
+ @Deprecated
public List<FlowEntry> getFlowsForDevice(DeviceId deviceId) {
return flowsForDevice.getOrDefault(deviceId, ImmutableList.of());
}
@@ -214,15 +256,15 @@
this.success.add(success);
}
-
@Override
public String toString() {
return "StaticPacketTrace{" +
- "inPacket=" + inPacket +
- ", in=" + in +
+ "ingressPacket=" + ingressPacket +
+ ", ingressPoint=" + ingressPoint +
", completePaths=" + completePaths +
", outputsForDevice=" + outputsForDevice +
", flowsForDevice=" + flowsForDevice +
+ ", hitChains=" + hitChainsForDevice +
", resultMessage=" + resultMessage +
'}';
}
diff --git a/app/src/main/java/org/onosproject/t3/api/TroubleshootService.java b/app/src/main/java/org/onosproject/t3/api/TroubleshootService.java
index 3ab6052..d9c2f59 100644
--- a/app/src/main/java/org/onosproject/t3/api/TroubleshootService.java
+++ b/app/src/main/java/org/onosproject/t3/api/TroubleshootService.java
@@ -18,10 +18,10 @@
import org.onlab.packet.EthType;
import org.onlab.packet.VlanId;
+import org.onlab.util.Generator;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.HostId;
import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.t3.impl.Generator;
import java.util.List;
import java.util.Set;
@@ -37,7 +37,9 @@
*
* @param type the etherType of the traffic we want to trace.
* @return trace result
+ * @deprecated in t3-4.0
*/
+ @Deprecated
List<StaticPacketTrace> pingAll(EthType.EtherType type);
/**
@@ -81,7 +83,9 @@
*
* @param vlanId the vlan id configured for multicast
* @return list of trace result
+ * @deprecated in t3-4.0
*/
+ @Deprecated
List<Set<StaticPacketTrace>> getMulitcastTrace(VlanId vlanId);
/**