Refactor CordVtn to use device projection feature instead of driver
Change-Id: I8220806f7933a4603c02a96212a4d8812a2bd284
diff --git a/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtn.java b/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtn.java
index 24f650d..61f37b5 100644
--- a/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtn.java
+++ b/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtn.java
@@ -51,7 +51,6 @@
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.config.basics.SubjectFactories;
import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.group.GroupService;
import org.onosproject.net.host.DefaultHostDescription;
@@ -67,7 +66,6 @@
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
-
import org.openstack4j.api.OSClient;
import org.openstack4j.api.exceptions.AuthenticationException;
import org.openstack4j.model.identity.Access;
@@ -118,9 +116,6 @@
protected HostService hostService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DriverService driverService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleService flowRuleService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -181,7 +176,6 @@
appId = coreService.registerApplication("org.onosproject.cordvtn");
ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
deviceService,
- driverService,
groupService,
configRegistry,
DEFAULT_TUNNEL);
diff --git a/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnNodeManager.java b/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnNodeManager.java
index bec23da..0aece81 100644
--- a/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnNodeManager.java
+++ b/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnNodeManager.java
@@ -59,8 +59,6 @@
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.DriverHandler;
-import org.onosproject.net.driver.DriverService;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.group.GroupService;
import org.onosproject.net.host.HostService;
@@ -148,9 +146,6 @@
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DriverService driverService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -241,7 +236,6 @@
ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
deviceService,
- driverService,
groupService,
configRegistry,
DEFAULT_TUNNEL);
@@ -583,9 +577,13 @@
String dpid = node.intBrId().toString().substring(DPID_BEGIN);
try {
- DriverHandler handler = driverService.createHandler(node.ovsdbId());
- BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
- bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers);
+ Device device = deviceService.getDevice(node.ovsdbId());
+ if (device.is(BridgeConfig.class)) {
+ BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
+ bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers);
+ } else {
+ log.warn("The bridging behaviour is not supported in device {}", device.id().toString());
+ }
} catch (ItemNotFoundException e) {
log.warn("Failed to create integration bridge on {}", node.hostname());
}
@@ -611,9 +609,13 @@
optionBuilder.build());
try {
- DriverHandler handler = driverService.createHandler(node.ovsdbId());
- TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class);
- tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE), description);
+ Device device = deviceService.getDevice(node.ovsdbId());
+ if (device.is(TunnelConfig.class)) {
+ TunnelConfig tunnelConfig = device.as(TunnelConfig.class);
+ tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE), description);
+ } else {
+ log.warn("The tunneling behaviour is not supported in device {}", device.id().toString());
+ }
} catch (ItemNotFoundException e) {
log.warn("Failed to create tunnel interface on {}", node.hostname());
}
@@ -630,9 +632,13 @@
}
try {
- DriverHandler handler = driverService.createHandler(node.ovsdbId());
- BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
- bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.dpIntf());
+ Device device = deviceService.getDevice(node.ovsdbId());
+ if (device.is(BridgeConfig.class)) {
+ BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
+ bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.dpIntf());
+ } else {
+ log.warn("The bridging behaviour is not supported in device {}", device.id().toString());
+ }
} catch (ItemNotFoundException e) {
log.warn("Failed to add {} on {}", node.dpIntf(), node.hostname());
}
diff --git a/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java b/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java
index 49f3c8f..5914b71 100644
--- a/apps/cordvtn/src/main/java/org/onosproject/cordvtn/impl/CordVtnRuleInstaller.java
+++ b/apps/cordvtn/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);