ONOS-1736 - Modified PacketManager to register packet request flows using the core app id, instead of the requesting app id. This is to prevent packet request flows from vanishing when app removes all its flows. This is a provisional fix until packet requests allow removal via reference counting or a similar tracking strategy.
Change-Id: Ib0e53ae8c6b5ae030a9c17a34407a5897027127b
diff --git a/core/api/src/main/java/org/onosproject/core/CoreService.java b/core/api/src/main/java/org/onosproject/core/CoreService.java
index 705b25b..42db086 100644
--- a/core/api/src/main/java/org/onosproject/core/CoreService.java
+++ b/core/api/src/main/java/org/onosproject/core/CoreService.java
@@ -24,8 +24,15 @@
*/
public interface CoreService {
- public static final ProviderId CORE_PROVIDER_ID =
- new ProviderId("core", "org.onosproject.core");
+ /**
+ * Name of the core "application".
+ */
+ public static final String CORE_APP_NAME = "org.onosproject.core";
+
+ /**
+ * Identifier of the core "provider".
+ */
+ public static final ProviderId CORE_PROVIDER_ID = new ProviderId("core", CORE_APP_NAME);
/**
* Returns the product version.
diff --git a/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java b/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
index d09f024..8e0de97 100644
--- a/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
+++ b/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
@@ -70,6 +70,7 @@
@Activate
public void activate() {
+ registerApplication(CORE_APP_NAME);
cfgService.registerProperties(getClass());
List<String> versionLines = Tools.slurp(VERSION_FILE);
if (versionLines != null && !versionLines.isEmpty()) {
diff --git a/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java b/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
index 19f5bb9..9dd0634 100644
--- a/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
+++ b/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
@@ -22,6 +22,7 @@
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
import org.onosproject.net.Device;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
@@ -61,14 +62,17 @@
@Component(immediate = true)
@Service
public class PacketManager
-extends AbstractProviderRegistry<PacketProvider, PacketProviderService>
-implements PacketService, PacketProviderRegistry {
+ extends AbstractProviderRegistry<PacketProvider, PacketProviderService>
+ implements PacketService, PacketProviderRegistry {
private final Logger log = getLogger(getClass());
private final PacketStoreDelegate delegate = new InternalStoreDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ private CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -81,8 +85,11 @@
private final Map<Integer, PacketProcessor> processors = new ConcurrentHashMap<>();
+ private ApplicationId appId;
+
@Activate
public void activate() {
+ appId = coreService.getAppId(CoreService.CORE_APP_NAME);
store.setDelegate(delegate);
deviceService.addListener(deviceListener);
log.info("Started");
@@ -153,7 +160,7 @@
* Pushes flow rules to the device to request packets be sent to the
* controller.
*
- * @param device the device to push the rules to
+ * @param device the device to push the rules to
* @param request the packet request
*/
private void pushRule(Device device, PacketRequest request) {
@@ -162,16 +169,10 @@
return;
}
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .punt()
- .build();
-
- FlowRule flow = new DefaultFlowRule(device.id(),
- request.selector(),
- treatment,
- request.priority().priorityValue(),
- request.appId(),
- 0, true, request.tableType());
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
+ FlowRule flow = new DefaultFlowRule(device.id(), request.selector(), treatment,
+ request.priority().priorityValue(),
+ appId, 0, true, request.tableType());
flowService.applyFlowRules(flow);
}
@@ -204,8 +205,8 @@
// Personalized link provider service issued to the supplied provider.
private class InternalPacketProviderService
- extends AbstractProviderService<PacketProvider>
- implements PacketProviderService {
+ extends AbstractProviderService<PacketProvider>
+ implements PacketProviderService {
protected InternalPacketProviderService(PacketProvider provider) {
super(provider);
@@ -225,7 +226,7 @@
* Internal callback from the packet store.
*/
private class InternalStoreDelegate
- implements PacketStoreDelegate {
+ implements PacketStoreDelegate {
@Override
public void notify(PacketEvent event) {
localEmit(event.subject());