Few core changes in preparation of P4Runtime subsystem refactoring
Refactoring aims at providing a more robust connection procedure of
P4Runtime-based devices.
Refactoring requires devices to be registered to the core with
available=false (i.e. offline), and marked online only when the P4
pipeline has been deployed to the device. Also, it leaves the duty of
handling pipeconf-specific drivers to the driver subsystem, instead of
having the GeneralDeviceProvider take care of it, which resulted to be
brittle.
Changes include:
- Choose not to mark device online when re-asserting mastership role by
declaring special device annotation.
- Lookup drivers in device projectable model unsing driver service
device-based method, which is consistent with the way other subsystems
look for device drivers.
- In DriverManager, when looking for device drivers, consider the case
of pipeconf-programmable devices, in which case a special "merged"
driver needs to instantiated at runtime.
- In PacketManager, push flow objectives only if device is available
(i.e. after pipeline has been deployed).
Change-Id: I80f78a4f40730a06cb82fa55fefab08a91a89268
diff --git a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
index 3697641..f4549c5 100644
--- a/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/flow/impl/FlowRuleManagerTest.java
@@ -39,6 +39,7 @@
import org.onosproject.net.Device.Type;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
+import org.onosproject.net.config.NetworkConfigServiceAdapter;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DefaultDriver;
@@ -51,7 +52,6 @@
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowEntry.FlowEntryState;
import org.onosproject.net.flow.FlowRule;
-import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation;
import org.onosproject.net.flow.FlowRuleEvent;
import org.onosproject.net.flow.FlowRuleListener;
import org.onosproject.net.flow.FlowRuleProgrammable;
@@ -66,6 +66,8 @@
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.flow.instructions.Instructions.MetadataInstruction;
+import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation;
+import org.onosproject.net.pi.PiPipeconfServiceAdapter;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.trivial.SimpleFlowRuleStore;
@@ -84,9 +86,16 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
-import static org.onosproject.net.flow.FlowRuleEvent.Type.*;
+import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADDED;
+import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
+import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
+import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
+import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_UPDATED;
/**
* Test codifying the flow rule service & flow rule provider service contracts.
@@ -712,6 +721,8 @@
TestDriverManager(DriverRegistry registry) {
this.registry = registry;
this.deviceService = mgr.deviceService;
+ this.pipeconfService = new PiPipeconfServiceAdapter();
+ this.networkConfigService = new NetworkConfigServiceAdapter();
activate();
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/group/impl/GroupManagerTest.java b/core/net/src/test/java/org/onosproject/net/group/impl/GroupManagerTest.java
index 7135c49..d1777ba 100644
--- a/core/net/src/test/java/org/onosproject/net/group/impl/GroupManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/group/impl/GroupManagerTest.java
@@ -37,6 +37,7 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.NetworkConfigServiceAdapter;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DefaultDriver;
@@ -64,6 +65,7 @@
import org.onosproject.net.group.GroupProviderService;
import org.onosproject.net.group.GroupService;
import org.onosproject.net.group.StoredGroupEntry;
+import org.onosproject.net.pi.PiPipeconfServiceAdapter;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.trivial.SimpleGroupStore;
@@ -74,7 +76,11 @@
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
/**
@@ -787,6 +793,8 @@
TestDriverManager(DriverRegistry registry) {
this.registry = registry;
this.deviceService = mgr.deviceService;
+ this.pipeconfService = new PiPipeconfServiceAdapter();
+ this.networkConfigService = new NetworkConfigServiceAdapter();
activate();
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java b/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java
index 3bd5e9b..ea21b9f 100644
--- a/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java
@@ -68,21 +68,26 @@
import org.onosproject.net.meter.MeterRequest;
import org.onosproject.net.meter.MeterService;
import org.onosproject.net.meter.MeterState;
+import org.onosproject.net.pi.PiPipeconfServiceAdapter;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.TestStorageService;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.onosproject.net.NetTestTools.APP_ID;
import static org.onosproject.net.NetTestTools.did;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
@@ -526,6 +531,7 @@
this.registry = registry;
this.deviceService = deviceService;
this.networkConfigService = networkConfigService;
+ this.pipeconfService = new PiPipeconfServiceAdapter();
activate();
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/packet/impl/PacketManagerTest.java b/core/net/src/test/java/org/onosproject/net/packet/impl/PacketManagerTest.java
index 6e4a7a5..81c2368 100644
--- a/core/net/src/test/java/org/onosproject/net/packet/impl/PacketManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/packet/impl/PacketManagerTest.java
@@ -30,6 +30,7 @@
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.NetworkConfigServiceAdapter;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.driver.DefaultDriver;
@@ -41,6 +42,7 @@
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketProgrammable;
import org.onosproject.net.packet.PacketProviderRegistry;
+import org.onosproject.net.pi.PiPipeconfServiceAdapter;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.provider.TestProvider;
import org.onosproject.store.trivial.SimplePacketStore;
@@ -147,6 +149,8 @@
TestDriverManager(DriverRegistry registry) {
this.registry = registry;
this.deviceService = mgr.deviceService;
+ this.pipeconfService = new PiPipeconfServiceAdapter();
+ this.networkConfigService = new NetworkConfigServiceAdapter();
activate();
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java b/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
index a418461..20ded6a 100644
--- a/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/pi/impl/PiPipeconfManagerTest.java
@@ -42,8 +42,6 @@
import org.onosproject.net.driver.DriverAdminService;
import org.onosproject.net.driver.DriverAdminServiceAdapter;
import org.onosproject.net.driver.DriverProvider;
-import org.onosproject.net.driver.DriverService;
-import org.onosproject.net.driver.DriverServiceAdapter;
import org.onosproject.net.pi.model.PiPipeconf;
import org.onosproject.net.pi.model.PiPipeconfId;
import org.onosproject.net.pi.service.PiPipeconfConfig;
@@ -72,7 +70,6 @@
//Mock util sets and classes
private final NetworkConfigRegistry cfgService = new MockNetworkConfigRegistry();
- private final DriverService driverService = new MockDriverService();
private final DriverAdminService driverAdminService = new MockDriverAdminService();
private Driver baseDriver = new MockDriver();
@@ -97,7 +94,6 @@
piPipeconfService = new PiPipeconfManager();
piPipeconf = BASIC_PIPECONF;
piPipeconfService.cfgService = cfgService;
- piPipeconfService.driverService = driverService;
piPipeconfService.driverAdminService = driverAdminService;
String key = "piPipeconf";
ObjectMapper mapper = new ObjectMapper();
@@ -112,7 +108,7 @@
@Test
public void activate() {
- assertEquals("Incorrect driver service", driverService, piPipeconfService.driverService);
+ assertEquals("Incorrect driver admin service", driverAdminService, piPipeconfService.driverAdminService);
assertEquals("Incorrect driverAdminService service", driverAdminService, piPipeconfService.driverAdminService);
assertEquals("Incorrect configuration service", cfgService, piPipeconfService.cfgService);
assertTrue("Incorrect config factory", cfgFactories.contains(piPipeconfService.configFactory));
@@ -121,7 +117,7 @@
@Test
public void deactivate() {
piPipeconfService.deactivate();
- assertEquals("Incorrect driver service", null, piPipeconfService.driverService);
+ assertEquals("Incorrect driver admin service", null, piPipeconfService.driverAdminService);
assertEquals("Incorrect driverAdminService service", null, piPipeconfService.driverAdminService);
assertEquals("Incorrect configuration service", null, piPipeconfService.cfgService);
assertFalse("Config factory should be unregistered", cfgFactories.contains(piPipeconfService.configFactory));
@@ -153,7 +149,10 @@
assertEquals("Returned PiPipeconf is not correct", piPipeconf,
piPipeconfService.getPipeconf(piPipeconf.id()).get());
- String mergedDriverName = piPipeconfService.mergeDriver(DEVICE_ID, piPipeconfId);
+ String mergedDriverName = piPipeconfService.getMergedDriver(DEVICE_ID, piPipeconfId);
+
+ String expectedName = BASE_DRIVER + ":" + piPipeconfId.id();
+ assertEquals(expectedName, mergedDriverName);
//we assume that the provider is 1 and that it contains 1 driver
//we also assume that everything after driverAdminService.registerProvider(provider); has been tested.
@@ -208,7 +207,8 @@
}
}
- private class MockDriverService extends DriverServiceAdapter {
+ private class MockDriverAdminService extends DriverAdminServiceAdapter {
+
@Override
public Driver getDriver(String driverName) {
if (driverName.equals(BASE_DRIVER)) {
@@ -216,9 +216,6 @@
}
throw new ItemNotFoundException("Driver not found");
}
- }
-
- private class MockDriverAdminService extends DriverAdminServiceAdapter {
@Override
public void registerProvider(DriverProvider provider) {