Trigger pipeconf deploy right after registration
Without waiting for the next pipeconf watchdog periodic probe.
To support this, this patch extends the PiPipeconfService to advertise
pipeconf registration events.
Change-Id: Ib44f1813bd37083c666a5e7980de320ce469c2d2
diff --git a/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfEvent.java b/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfEvent.java
new file mode 100644
index 0000000..339912d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfEvent.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * 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.pi.service;
+
+import org.onosproject.event.AbstractEvent;
+import org.onosproject.net.pi.model.PiPipeconf;
+import org.onosproject.net.pi.model.PiPipeconfId;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Event related to the PiPipeconfService.
+ */
+public class PiPipeconfEvent extends AbstractEvent<PiPipeconfEvent.Type, PiPipeconfId> {
+
+ private final PiPipeconf pipeconf;
+
+ /**
+ * Type of pipeconf event.
+ */
+ public enum Type {
+ REGISTERED,
+ UNREGISTERED
+ }
+
+ /**
+ * Creates anew pipeconf event for the given type and pipeconf.
+ *
+ * @param type type of event
+ * @param pipeconf pipeconf
+ */
+ public PiPipeconfEvent(Type type, PiPipeconf pipeconf) {
+ super(type, checkNotNull(pipeconf).id());
+ this.pipeconf = pipeconf;
+ }
+
+
+ /**
+ * Creates anew pipeconf event for the given type and pipeconf ID.
+ *
+ * @param type type of event
+ * @param pipeconfId pipeconf ID
+ */
+ public PiPipeconfEvent(Type type, PiPipeconfId pipeconfId) {
+ super(type, pipeconfId);
+ pipeconf = null;
+ }
+
+ /**
+ * Returns the pipeconf instance associated to this event, or null if one
+ * was not provided. For example, {@link Type#UNREGISTERED} events are not
+ * expected to carry the pipeconf instance that was unregistered, but just
+ * the ID (via {@link #subject()}).
+ *
+ * @return pipeconf instance or null
+ */
+ public PiPipeconf pipeconf() {
+ return pipeconf;
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfListener.java b/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfListener.java
new file mode 100644
index 0000000..11209e1
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfListener.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * 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.pi.service;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener of pipeconf events.
+ */
+public interface PiPipeconfListener extends EventListener<PiPipeconfEvent> {
+}
diff --git a/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfService.java b/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfService.java
index 9943352..d24348d 100644
--- a/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfService.java
+++ b/core/api/src/main/java/org/onosproject/net/pi/service/PiPipeconfService.java
@@ -17,6 +17,7 @@
package org.onosproject.net.pi.service;
import com.google.common.annotations.Beta;
+import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipeconfId;
@@ -27,12 +28,12 @@
* A service to manage the configurations of protocol-independent pipelines.
*/
@Beta
-public interface PiPipeconfService {
+public interface PiPipeconfService extends ListenerService<PiPipeconfEvent, PiPipeconfListener> {
// TODO: we might want to extend ListenerService to support the broadcasting of PipeconfEvent.
/**
- * Registers the given pipeconf.
+ * Registers the given pipeconf making it available to other subsystems.
*
* @param pipeconf a pipeconf
* @throws IllegalStateException if the same pipeconf identifier is already
@@ -41,17 +42,14 @@
void register(PiPipeconf pipeconf) throws IllegalStateException;
/**
- * Unregisters the Pipeconf identified by the given PiPipeconfId.
- * Unregistering a Pipeconf removes it from the ONOS controller, thus making
- * it un-capable of controlling (e.g installing flow rules) the devices that
- * have the pipeconf's P4 program deployed. For now this method DOES NOT
- * remove the P4 program from the devices.
+ * Unregisters the given pipeconf. Once unregistered, other subsystems will
+ * not be able to access the pipeconf content.
*
* @param pipeconfId a pipeconfId
* @throws IllegalStateException if the same pipeconf identifier is already
* registered.
*/
- void remove(PiPipeconfId pipeconfId) throws IllegalStateException;
+ void unregister(PiPipeconfId pipeconfId) throws IllegalStateException;
/**
* Returns all pipeconfs registered.
diff --git a/core/api/src/test/java/org/onosproject/net/pi/PiPipeconfServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/pi/PiPipeconfServiceAdapter.java
index 66f9315..f77afe0 100644
--- a/core/api/src/test/java/org/onosproject/net/pi/PiPipeconfServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/pi/PiPipeconfServiceAdapter.java
@@ -19,6 +19,7 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipeconfId;
+import org.onosproject.net.pi.service.PiPipeconfListener;
import org.onosproject.net.pi.service.PiPipeconfService;
import java.util.Collections;
@@ -34,7 +35,7 @@
}
@Override
- public void remove(PiPipeconfId pipeconfId) throws IllegalStateException {
+ public void unregister(PiPipeconfId pipeconfId) throws IllegalStateException {
}
@@ -67,4 +68,14 @@
public Optional<PiPipeconfId> ofDevice(DeviceId deviceId) {
return Optional.empty();
}
+
+ @Override
+ public void addListener(PiPipeconfListener listener) {
+
+ }
+
+ @Override
+ public void removeListener(PiPipeconfListener listener) {
+
+ }
}