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; ...@@ -51,7 +51,6 @@ import org.onosproject.net.config.NetworkConfigRegistry;
51 import org.onosproject.net.config.NetworkConfigService; 51 import org.onosproject.net.config.NetworkConfigService;
52 import org.onosproject.net.config.basics.SubjectFactories; 52 import org.onosproject.net.config.basics.SubjectFactories;
53 import org.onosproject.net.device.DeviceService; 53 import org.onosproject.net.device.DeviceService;
54 -import org.onosproject.net.driver.DriverService;
55 import org.onosproject.net.flow.FlowRuleService; 54 import org.onosproject.net.flow.FlowRuleService;
56 import org.onosproject.net.group.GroupService; 55 import org.onosproject.net.group.GroupService;
57 import org.onosproject.net.host.DefaultHostDescription; 56 import org.onosproject.net.host.DefaultHostDescription;
...@@ -67,7 +66,6 @@ import org.onosproject.net.packet.PacketProcessor; ...@@ -67,7 +66,6 @@ import org.onosproject.net.packet.PacketProcessor;
67 import org.onosproject.net.packet.PacketService; 66 import org.onosproject.net.packet.PacketService;
68 import org.onosproject.net.provider.AbstractProvider; 67 import org.onosproject.net.provider.AbstractProvider;
69 import org.onosproject.net.provider.ProviderId; 68 import org.onosproject.net.provider.ProviderId;
70 -
71 import org.openstack4j.api.OSClient; 69 import org.openstack4j.api.OSClient;
72 import org.openstack4j.api.exceptions.AuthenticationException; 70 import org.openstack4j.api.exceptions.AuthenticationException;
73 import org.openstack4j.model.identity.Access; 71 import org.openstack4j.model.identity.Access;
...@@ -118,9 +116,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -118,9 +116,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
118 protected HostService hostService; 116 protected HostService hostService;
119 117
120 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 118 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
121 - protected DriverService driverService;
122 -
123 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
124 protected FlowRuleService flowRuleService; 119 protected FlowRuleService flowRuleService;
125 120
126 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 121 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -181,7 +176,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro ...@@ -181,7 +176,6 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro
181 appId = coreService.registerApplication("org.onosproject.cordvtn"); 176 appId = coreService.registerApplication("org.onosproject.cordvtn");
182 ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService, 177 ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
183 deviceService, 178 deviceService,
184 - driverService,
185 groupService, 179 groupService,
186 configRegistry, 180 configRegistry,
187 DEFAULT_TUNNEL); 181 DEFAULT_TUNNEL);
......
...@@ -59,8 +59,6 @@ import org.onosproject.net.device.DeviceAdminService; ...@@ -59,8 +59,6 @@ import org.onosproject.net.device.DeviceAdminService;
59 import org.onosproject.net.device.DeviceEvent; 59 import org.onosproject.net.device.DeviceEvent;
60 import org.onosproject.net.device.DeviceListener; 60 import org.onosproject.net.device.DeviceListener;
61 import org.onosproject.net.device.DeviceService; 61 import org.onosproject.net.device.DeviceService;
62 -import org.onosproject.net.driver.DriverHandler;
63 -import org.onosproject.net.driver.DriverService;
64 import org.onosproject.net.flow.FlowRuleService; 62 import org.onosproject.net.flow.FlowRuleService;
65 import org.onosproject.net.group.GroupService; 63 import org.onosproject.net.group.GroupService;
66 import org.onosproject.net.host.HostService; 64 import org.onosproject.net.host.HostService;
...@@ -148,9 +146,6 @@ public class CordVtnNodeManager { ...@@ -148,9 +146,6 @@ public class CordVtnNodeManager {
148 protected ClusterService clusterService; 146 protected ClusterService clusterService;
149 147
150 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 148 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
151 - protected DriverService driverService;
152 -
153 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
154 protected DeviceService deviceService; 149 protected DeviceService deviceService;
155 150
156 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 151 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -241,7 +236,6 @@ public class CordVtnNodeManager { ...@@ -241,7 +236,6 @@ public class CordVtnNodeManager {
241 236
242 ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService, 237 ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService,
243 deviceService, 238 deviceService,
244 - driverService,
245 groupService, 239 groupService,
246 configRegistry, 240 configRegistry,
247 DEFAULT_TUNNEL); 241 DEFAULT_TUNNEL);
...@@ -583,9 +577,13 @@ public class CordVtnNodeManager { ...@@ -583,9 +577,13 @@ public class CordVtnNodeManager {
583 String dpid = node.intBrId().toString().substring(DPID_BEGIN); 577 String dpid = node.intBrId().toString().substring(DPID_BEGIN);
584 578
585 try { 579 try {
586 - DriverHandler handler = driverService.createHandler(node.ovsdbId()); 580 + Device device = deviceService.getDevice(node.ovsdbId());
587 - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); 581 + if (device.is(BridgeConfig.class)) {
588 - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers); 582 + BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
583 + bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers);
584 + } else {
585 + log.warn("The bridging behaviour is not supported in device {}", device.id().toString());
586 + }
589 } catch (ItemNotFoundException e) { 587 } catch (ItemNotFoundException e) {
590 log.warn("Failed to create integration bridge on {}", node.hostname()); 588 log.warn("Failed to create integration bridge on {}", node.hostname());
591 } 589 }
...@@ -611,9 +609,13 @@ public class CordVtnNodeManager { ...@@ -611,9 +609,13 @@ public class CordVtnNodeManager {
611 optionBuilder.build()); 609 optionBuilder.build());
612 610
613 try { 611 try {
614 - DriverHandler handler = driverService.createHandler(node.ovsdbId()); 612 + Device device = deviceService.getDevice(node.ovsdbId());
615 - TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); 613 + if (device.is(TunnelConfig.class)) {
616 - tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE), description); 614 + TunnelConfig tunnelConfig = device.as(TunnelConfig.class);
615 + tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE), description);
616 + } else {
617 + log.warn("The tunneling behaviour is not supported in device {}", device.id().toString());
618 + }
617 } catch (ItemNotFoundException e) { 619 } catch (ItemNotFoundException e) {
618 log.warn("Failed to create tunnel interface on {}", node.hostname()); 620 log.warn("Failed to create tunnel interface on {}", node.hostname());
619 } 621 }
...@@ -630,9 +632,13 @@ public class CordVtnNodeManager { ...@@ -630,9 +632,13 @@ public class CordVtnNodeManager {
630 } 632 }
631 633
632 try { 634 try {
633 - DriverHandler handler = driverService.createHandler(node.ovsdbId()); 635 + Device device = deviceService.getDevice(node.ovsdbId());
634 - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); 636 + if (device.is(BridgeConfig.class)) {
635 - bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.dpIntf()); 637 + BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
638 + bridgeConfig.addPort(BridgeName.bridgeName(DEFAULT_BRIDGE), node.dpIntf());
639 + } else {
640 + log.warn("The bridging behaviour is not supported in device {}", device.id().toString());
641 + }
636 } catch (ItemNotFoundException e) { 642 } catch (ItemNotFoundException e) {
637 log.warn("Failed to add {} on {}", node.dpIntf(), node.hostname()); 643 log.warn("Failed to add {} on {}", node.dpIntf(), node.hostname());
638 } 644 }
......
...@@ -35,6 +35,7 @@ import org.onosproject.cordvtn.api.CordVtnNode; ...@@ -35,6 +35,7 @@ import org.onosproject.cordvtn.api.CordVtnNode;
35 import org.onosproject.core.ApplicationId; 35 import org.onosproject.core.ApplicationId;
36 import org.onosproject.core.DefaultGroupId; 36 import org.onosproject.core.DefaultGroupId;
37 import org.onosproject.core.GroupId; 37 import org.onosproject.core.GroupId;
38 +import org.onosproject.net.Device;
38 import org.onosproject.net.DeviceId; 39 import org.onosproject.net.DeviceId;
39 import org.onosproject.net.Host; 40 import org.onosproject.net.Host;
40 import org.onosproject.net.Port; 41 import org.onosproject.net.Port;
...@@ -42,11 +43,6 @@ import org.onosproject.net.PortNumber; ...@@ -42,11 +43,6 @@ import org.onosproject.net.PortNumber;
42 import org.onosproject.net.behaviour.ExtensionTreatmentResolver; 43 import org.onosproject.net.behaviour.ExtensionTreatmentResolver;
43 import org.onosproject.net.config.NetworkConfigRegistry; 44 import org.onosproject.net.config.NetworkConfigRegistry;
44 import org.onosproject.net.device.DeviceService; 45 import org.onosproject.net.device.DeviceService;
45 -import org.onosproject.net.driver.DefaultDriverData;
46 -import org.onosproject.net.driver.DefaultDriverHandler;
47 -import org.onosproject.net.driver.Driver;
48 -import org.onosproject.net.driver.DriverHandler;
49 -import org.onosproject.net.driver.DriverService;
50 import org.onosproject.net.flow.DefaultFlowRule; 46 import org.onosproject.net.flow.DefaultFlowRule;
51 import org.onosproject.net.flow.DefaultTrafficSelector; 47 import org.onosproject.net.flow.DefaultTrafficSelector;
52 import org.onosproject.net.flow.DefaultTrafficTreatment; 48 import org.onosproject.net.flow.DefaultTrafficTreatment;
...@@ -127,7 +123,6 @@ public class CordVtnRuleInstaller { ...@@ -127,7 +123,6 @@ public class CordVtnRuleInstaller {
127 private final ApplicationId appId; 123 private final ApplicationId appId;
128 private final FlowRuleService flowRuleService; 124 private final FlowRuleService flowRuleService;
129 private final DeviceService deviceService; 125 private final DeviceService deviceService;
130 - private final DriverService driverService;
131 private final GroupService groupService; 126 private final GroupService groupService;
132 private final NetworkConfigRegistry configRegistry; 127 private final NetworkConfigRegistry configRegistry;
133 private final String tunnelType; 128 private final String tunnelType;
...@@ -138,7 +133,6 @@ public class CordVtnRuleInstaller { ...@@ -138,7 +133,6 @@ public class CordVtnRuleInstaller {
138 * @param appId application id 133 * @param appId application id
139 * @param flowRuleService flow rule service 134 * @param flowRuleService flow rule service
140 * @param deviceService device service 135 * @param deviceService device service
141 - * @param driverService driver service
142 * @param groupService group service 136 * @param groupService group service
143 * @param configRegistry config registry 137 * @param configRegistry config registry
144 * @param tunnelType tunnel type 138 * @param tunnelType tunnel type
...@@ -146,14 +140,12 @@ public class CordVtnRuleInstaller { ...@@ -146,14 +140,12 @@ public class CordVtnRuleInstaller {
146 public CordVtnRuleInstaller(ApplicationId appId, 140 public CordVtnRuleInstaller(ApplicationId appId,
147 FlowRuleService flowRuleService, 141 FlowRuleService flowRuleService,
148 DeviceService deviceService, 142 DeviceService deviceService,
149 - DriverService driverService,
150 GroupService groupService, 143 GroupService groupService,
151 NetworkConfigRegistry configRegistry, 144 NetworkConfigRegistry configRegistry,
152 String tunnelType) { 145 String tunnelType) {
153 this.appId = appId; 146 this.appId = appId;
154 this.flowRuleService = flowRuleService; 147 this.flowRuleService = flowRuleService;
155 this.deviceService = deviceService; 148 this.deviceService = deviceService;
156 - this.driverService = driverService;
157 this.groupService = groupService; 149 this.groupService = groupService;
158 this.configRegistry = configRegistry; 150 this.configRegistry = configRegistry;
159 this.tunnelType = checkNotNull(tunnelType); 151 this.tunnelType = checkNotNull(tunnelType);
...@@ -1504,16 +1496,20 @@ public class CordVtnRuleInstaller { ...@@ -1504,16 +1496,20 @@ public class CordVtnRuleInstaller {
1504 */ 1496 */
1505 private ExtensionTreatment getTunnelDst(DeviceId deviceId, Ip4Address remoteIp) { 1497 private ExtensionTreatment getTunnelDst(DeviceId deviceId, Ip4Address remoteIp) {
1506 try { 1498 try {
1507 - Driver driver = driverService.getDriver(deviceId); 1499 + Device device = deviceService.getDevice(deviceId);
1508 - DefaultDriverData driverData = new DefaultDriverData(driver, deviceId);
1509 - DriverHandler handler = new DefaultDriverHandler(driverData);
1510 - ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
1511 1500
1512 - ExtensionTreatment treatment = 1501 + if (device.is(ExtensionTreatmentResolver.class)) {
1513 - resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type()); 1502 + ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
1514 - treatment.setPropertyValue("tunnelDst", remoteIp); 1503 + ExtensionTreatment treatment =
1504 + resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type());
1505 + treatment.setPropertyValue("tunnelDst", remoteIp);
1515 1506
1516 - return treatment; 1507 + return treatment;
1508 + } else {
1509 + log.warn("The extension treatment resolving behaviour is not supported in device {}",
1510 + device.id().toString());
1511 + return null;
1512 + }
1517 } catch (ItemNotFoundException | UnsupportedOperationException | 1513 } catch (ItemNotFoundException | UnsupportedOperationException |
1518 ExtensionPropertyException e) { 1514 ExtensionPropertyException e) {
1519 log.error("Failed to get extension instruction {}", deviceId); 1515 log.error("Failed to get extension instruction {}", deviceId);
......