ONOS-2145 Added ability to withdraw packet intercepts via PacketService::cancelPackets.
Change-Id: Ie41271fa02740560bd67b0faf49f633ee749773c
diff --git a/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java b/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java
index 5bb2bdc..c6db17f 100644
--- a/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java
+++ b/core/api/src/main/java/org/onosproject/net/flowobjective/ObjectiveContext.java
@@ -20,14 +20,27 @@
/**
* The context of a objective that will become the subject of
* the notification.
- *
+ * <p>
* Implementations of this class must be serializable.
+ * </p>
*/
@Beta
public interface ObjectiveContext {
- default void onSuccess(Objective objective) {}
+ /**
+ * Invoked on successful execution of the flow objective.
+ *
+ * @param objective objective to execute
+ */
+ default void onSuccess(Objective objective) {
+ }
- default void onError(Objective objective, ObjectiveError error) {}
+ /**
+ * Invoked when error is encountered while executing the flow objective.
+ *
+ * @param objective objective to execute
+ */
+ default void onError(Objective objective, ObjectiveError error) {
+ }
}
diff --git a/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java b/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java
index 0efcc7f..ce2eb11 100644
--- a/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/packet/DefaultPacketRequest.java
@@ -17,9 +17,10 @@
import com.google.common.base.MoreObjects;
import org.onosproject.core.ApplicationId;
-import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
+import java.util.Objects;
+
/**
* Default implementation of a packet request.
*/
@@ -27,14 +28,19 @@
private final TrafficSelector selector;
private final PacketPriority priority;
private final ApplicationId appId;
- private final FlowRule.Type tableType;
+ /**
+ * Creates a new packet request.
+ *
+ * @param selector traffic selector
+ * @param priority intercept priority
+ * @param appId application id
+ */
public DefaultPacketRequest(TrafficSelector selector, PacketPriority priority,
- ApplicationId appId, FlowRule.Type tableType) {
+ ApplicationId appId) {
this.selector = selector;
this.priority = priority;
this.appId = appId;
- this.tableType = tableType;
}
public TrafficSelector selector() {
@@ -49,39 +55,23 @@
return appId;
}
- public FlowRule.Type tableType() {
- return tableType;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- DefaultPacketRequest that = (DefaultPacketRequest) o;
-
- if (priority != that.priority) {
- return false;
- }
- if (!selector.equals(that.selector)) {
- return false;
- }
- if (!tableType.equals(that.tableType)) {
- return false;
- }
-
- return true;
- }
-
@Override
public int hashCode() {
- int result = selector.hashCode();
- result = 31 * result + priority.hashCode();
- return result;
+ return Objects.hash(selector, priority, appId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final DefaultPacketRequest other = (DefaultPacketRequest) obj;
+ return Objects.equals(this.selector, other.selector)
+ && Objects.equals(this.priority, other.priority)
+ && Objects.equals(this.appId, other.appId);
}
@Override
@@ -89,7 +79,6 @@
return MoreObjects.toStringHelper(this.getClass())
.add("selector", selector)
.add("priority", priority)
- .add("appId", appId)
- .add("table-type", tableType).toString();
+ .add("appId", appId).toString();
}
}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/net/packet/PacketRequest.java b/core/api/src/main/java/org/onosproject/net/packet/PacketRequest.java
index a4e45ac..dc09219 100644
--- a/core/api/src/main/java/org/onosproject/net/packet/PacketRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/packet/PacketRequest.java
@@ -16,7 +16,6 @@
package org.onosproject.net.packet;
import org.onosproject.core.ApplicationId;
-import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
/**
@@ -26,26 +25,23 @@
/**
* Obtain the traffic selector.
+ *
* @return a traffic selector
*/
TrafficSelector selector();
/**
* Obtain the priority.
+ *
* @return a PacketPriority
*/
PacketPriority priority();
/**
* Obtain the application id.
+ *
* @return an application id
*/
ApplicationId appId();
- /**
- * Obtain the table type.
- * @return a table type
- */
- FlowRule.Type tableType();
-
}
diff --git a/core/api/src/main/java/org/onosproject/net/packet/PacketService.java b/core/api/src/main/java/org/onosproject/net/packet/PacketService.java
index be5a505..06c416e 100644
--- a/core/api/src/main/java/org/onosproject/net/packet/PacketService.java
+++ b/core/api/src/main/java/org/onosproject/net/packet/PacketService.java
@@ -16,7 +16,6 @@
package org.onosproject.net.packet;
import org.onosproject.core.ApplicationId;
-import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.TrafficSelector;
/**
@@ -54,28 +53,21 @@
*
* @param selector the traffic selector used to match packets
* @param priority the priority of the rule
- * @param appId the application ID of the requester
+ * @param appId the application ID of the requester
*/
void requestPackets(TrafficSelector selector, PacketPriority priority,
ApplicationId appId);
/**
- * Requests that packets matching the given selector are punted from the
- * dataplane to the controller. Clients of the PacketService should use
- * this call to hint at the tableType in the dataplane valid for the selector.
+ * Cancels previous packet requests for packets matching the given
+ * selector to be punted from the dataplane to the controller.
*
* @param selector the traffic selector used to match packets
* @param priority the priority of the rule
- * @param appId the application ID of the requester
- * @param tableType the abstract table Type in the dataplane where flowrules
- * should be inserted to punt the selector packets to the
- * control plane
+ * @param appId the application ID of the requester
*/
- void requestPackets(TrafficSelector selector, PacketPriority priority,
- ApplicationId appId, FlowRule.Type tableType);
-
-
- // TODO add API to allow applications to revoke requests when they deactivate
+ void cancelPackets(TrafficSelector selector, PacketPriority priority,
+ ApplicationId appId);
/**
* Emits the specified outbound packet onto the network.
diff --git a/core/api/src/main/java/org/onosproject/net/packet/PacketStore.java b/core/api/src/main/java/org/onosproject/net/packet/PacketStore.java
index 450c23b..ff45cc0 100644
--- a/core/api/src/main/java/org/onosproject/net/packet/PacketStore.java
+++ b/core/api/src/main/java/org/onosproject/net/packet/PacketStore.java
@@ -34,16 +34,22 @@
void emit(OutboundPacket packet);
/**
- * Register a request for packets. If the registration
- * is successful the manager can proceed, otherwise it should
- * consider these packet already available in the system.
+ * Requests intercept of packets that match the given selector.
*
* @param request a packet request
- * @return a boolean indicating registration state.
+ * @return true if the first time the given selector was requested
*/
boolean requestPackets(PacketRequest request);
/**
+ * Cancels intercept of packets that match the given selector.
+ *
+ * @param request a packet request
+ * @return true if there is no other application requesting the given selector
+ */
+ boolean cancelPackets(PacketRequest request);
+
+ /**
* Obtains all existing requests in the system.
*
* @return a set of packet requests
diff --git a/core/api/src/test/java/org/onosproject/net/packet/PacketServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/packet/PacketServiceAdapter.java
new file mode 100644
index 0000000..afe936b
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/packet/PacketServiceAdapter.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.packet;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.flow.TrafficSelector;
+
+/**
+ * Test adapter for packet service.
+ */
+public class PacketServiceAdapter implements PacketService {
+ @Override
+ public void addProcessor(PacketProcessor processor, int priority) {
+ }
+
+ @Override
+ public void removeProcessor(PacketProcessor processor) {
+ }
+
+ @Override
+ public void requestPackets(TrafficSelector selector, PacketPriority priority, ApplicationId appId) {
+ }
+
+ @Override
+ public void cancelPackets(TrafficSelector selector, PacketPriority priority, ApplicationId appId) {
+ }
+
+ @Override
+ public void emit(OutboundPacket packet) {
+ }
+}