Jian Li

Refactor CordVtn to use device projection feature instead of driver

Change-Id: I8220806f7933a4603c02a96212a4d8812a2bd284
......@@ -51,7 +51,6 @@ import org.onosproject.net.config.NetworkConfigRegistry;
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.PacketProcessor;
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 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
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 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
appId = coreService.registerApplication("org.onosproject.cordvtn");
ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
deviceService,
driverService,
groupService,
configRegistry,
DEFAULT_TUNNEL);
......
......@@ -59,8 +59,6 @@ import org.onosproject.net.device.DeviceAdminService;
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 @@ public class CordVtnNodeManager {
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 @@ public class CordVtnNodeManager {
ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
deviceService,
driverService,
groupService,
configRegistry,
DEFAULT_TUNNEL);
......@@ -583,9 +577,13 @@ public class CordVtnNodeManager {
String dpid = node.intBrId().toString().substring(DPID_BEGIN);
try {
DriverHandler handler = driverService.createHandler(node.ovsdbId());
BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
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 @@ public class CordVtnNodeManager {
optionBuilder.build());
try {
DriverHandler handler = driverService.createHandler(node.ovsdbId());
TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class);
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 @@ public class CordVtnNodeManager {
}
try {
DriverHandler handler = driverService.createHandler(node.ovsdbId());
BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
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());
}
......
......@@ -35,6 +35,7 @@ import org.onosproject.cordvtn.api.CordVtnNode;
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.PortNumber;
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 @@ public class CordVtnRuleInstaller {
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 @@ public class CordVtnRuleInstaller {
* @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 class CordVtnRuleInstaller {
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 @@ public class CordVtnRuleInstaller {
*/
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);
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;
} 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);
......