Refactor CordVtn to use device projection feature instead of driver
Change-Id: I8220806f7933a4603c02a96212a4d8812a2bd284
diff --git a/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java b/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java
index 49f3c8f..5914b71 100644
--- a/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java
+++ b/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java
@@ -35,6 +35,7 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.core.GroupId;
+import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
import org.onosproject.net.Port;
@@ -42,11 +43,6 @@
import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.DefaultDriverData;
-import org.onosproject.net.driver.DefaultDriverHandler;
-import org.onosproject.net.driver.Driver;
-import org.onosproject.net.driver.DriverHandler;
-import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.DefaultFlowRule;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -127,7 +123,6 @@
private final ApplicationId appId;
private final FlowRuleService flowRuleService;
private final DeviceService deviceService;
- private final DriverService driverService;
private final GroupService groupService;
private final NetworkConfigRegistry configRegistry;
private final String tunnelType;
@@ -138,7 +133,6 @@
* @param appId application id
* @param flowRuleService flow rule service
* @param deviceService device service
- * @param driverService driver service
* @param groupService group service
* @param configRegistry config registry
* @param tunnelType tunnel type
@@ -146,14 +140,12 @@
public CordVtnRuleInstaller(ApplicationId appId,
FlowRuleService flowRuleService,
DeviceService deviceService,
- DriverService driverService,
GroupService groupService,
NetworkConfigRegistry configRegistry,
String tunnelType) {
this.appId = appId;
this.flowRuleService = flowRuleService;
this.deviceService = deviceService;
- this.driverService = driverService;
this.groupService = groupService;
this.configRegistry = configRegistry;
this.tunnelType = checkNotNull(tunnelType);
@@ -1504,16 +1496,20 @@
*/
private ExtensionTreatment getTunnelDst(DeviceId deviceId, Ip4Address remoteIp) {
try {
- Driver driver = driverService.getDriver(deviceId);
- DefaultDriverData driverData = new DefaultDriverData(driver, deviceId);
- DriverHandler handler = new DefaultDriverHandler(driverData);
- ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
+ Device device = deviceService.getDevice(deviceId);
- ExtensionTreatment treatment =
- resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
- treatment.setPropertyValue("tunnelDst", remoteIp);
+ if (device.is(ExtensionTreatmentResolver.class)) {
+ ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
+ ExtensionTreatment treatment =
+ resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
+ treatment.setPropertyValue("tunnelDst", remoteIp);
- return treatment;
+ return treatment;
+ } else {
+ log.warn("The extension treatment resolving behaviour is not supported in device {}",
+ device.id().toString());
+ return null;
+ }
} catch (ItemNotFoundException | UnsupportedOperationException |
ExtensionPropertyException e) {
log.error("Failed to get extension instruction {}", deviceId);