Committed by
Gerrit Code Review
CORD-223 Changed to use ovsdb driver to create tunnel interface and bridge
Change-Id: Ibd8ab0555bab3bcc9200958fd55e0bc67b0ea383
Showing
2 changed files
with
49 additions
and
21 deletions
... | @@ -23,17 +23,27 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -23,17 +23,27 @@ import org.apache.felix.scr.annotations.Deactivate; |
23 | import org.apache.felix.scr.annotations.Reference; | 23 | import org.apache.felix.scr.annotations.Reference; |
24 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
25 | import org.apache.felix.scr.annotations.Service; | 25 | import org.apache.felix.scr.annotations.Service; |
26 | +import org.onlab.util.ItemNotFoundException; | ||
26 | import org.onlab.util.KryoNamespace; | 27 | import org.onlab.util.KryoNamespace; |
27 | import org.onosproject.cluster.ClusterService; | 28 | import org.onosproject.cluster.ClusterService; |
28 | import org.onosproject.core.ApplicationId; | 29 | import org.onosproject.core.ApplicationId; |
29 | import org.onosproject.core.CoreService; | 30 | import org.onosproject.core.CoreService; |
31 | +import org.onosproject.net.DefaultAnnotations; | ||
30 | import org.onosproject.net.Device; | 32 | import org.onosproject.net.Device; |
31 | import org.onosproject.net.DeviceId; | 33 | import org.onosproject.net.DeviceId; |
32 | import org.onosproject.net.Host; | 34 | import org.onosproject.net.Host; |
35 | +import org.onosproject.net.behaviour.BridgeConfig; | ||
36 | +import org.onosproject.net.behaviour.BridgeName; | ||
33 | import org.onosproject.net.behaviour.ControllerInfo; | 37 | import org.onosproject.net.behaviour.ControllerInfo; |
38 | +import org.onosproject.net.behaviour.DefaultTunnelDescription; | ||
39 | +import org.onosproject.net.behaviour.TunnelConfig; | ||
40 | +import org.onosproject.net.behaviour.TunnelDescription; | ||
41 | +import org.onosproject.net.behaviour.TunnelName; | ||
34 | import org.onosproject.net.device.DeviceEvent; | 42 | import org.onosproject.net.device.DeviceEvent; |
35 | import org.onosproject.net.device.DeviceListener; | 43 | import org.onosproject.net.device.DeviceListener; |
36 | import org.onosproject.net.device.DeviceService; | 44 | import org.onosproject.net.device.DeviceService; |
45 | +import org.onosproject.net.driver.DriverHandler; | ||
46 | +import org.onosproject.net.driver.DriverService; | ||
37 | import org.onosproject.net.host.HostEvent; | 47 | import org.onosproject.net.host.HostEvent; |
38 | import org.onosproject.net.host.HostListener; | 48 | import org.onosproject.net.host.HostListener; |
39 | import org.onosproject.net.host.HostService; | 49 | import org.onosproject.net.host.HostService; |
... | @@ -58,6 +68,7 @@ import java.util.concurrent.Executors; | ... | @@ -58,6 +68,7 @@ import java.util.concurrent.Executors; |
58 | import static com.google.common.base.Preconditions.checkNotNull; | 68 | import static com.google.common.base.Preconditions.checkNotNull; |
59 | import static org.onlab.util.Tools.groupedThreads; | 69 | import static org.onlab.util.Tools.groupedThreads; |
60 | import static org.onosproject.net.Device.Type.SWITCH; | 70 | import static org.onosproject.net.Device.Type.SWITCH; |
71 | +import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN; | ||
61 | import static org.slf4j.LoggerFactory.getLogger; | 72 | import static org.slf4j.LoggerFactory.getLogger; |
62 | 73 | ||
63 | /** | 74 | /** |
... | @@ -79,7 +90,6 @@ public class CordVtn implements CordVtnService { | ... | @@ -79,7 +90,6 @@ public class CordVtn implements CordVtnService { |
79 | private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() { | 90 | private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() { |
80 | { | 91 | { |
81 | put("key", "flow"); | 92 | put("key", "flow"); |
82 | - put("local_ip", "flow"); | ||
83 | put("remote_ip", "flow"); | 93 | put("remote_ip", "flow"); |
84 | } | 94 | } |
85 | }; | 95 | }; |
... | @@ -99,6 +109,9 @@ public class CordVtn implements CordVtnService { | ... | @@ -99,6 +109,9 @@ public class CordVtn implements CordVtnService { |
99 | protected HostService hostService; | 109 | protected HostService hostService; |
100 | 110 | ||
101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 111 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
112 | + protected DriverService driverService; | ||
113 | + | ||
114 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
102 | protected OvsdbController controller; | 115 | protected OvsdbController controller; |
103 | 116 | ||
104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 117 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -213,8 +226,8 @@ public class CordVtn implements CordVtnService { | ... | @@ -213,8 +226,8 @@ public class CordVtn implements CordVtnService { |
213 | if (deviceService.getDevice(ovsdb.intBrId()) == null || | 226 | if (deviceService.getDevice(ovsdb.intBrId()) == null || |
214 | !deviceService.isAvailable(ovsdb.intBrId())) { | 227 | !deviceService.isAvailable(ovsdb.intBrId())) { |
215 | createIntegrationBridge(ovsdb); | 228 | createIntegrationBridge(ovsdb); |
216 | - } else if (!checkVxlanPort(ovsdb)) { | 229 | + } else if (!checkVxlanInterface(ovsdb)) { |
217 | - createVxlanPort(ovsdb); | 230 | + createVxlanInterface(ovsdb); |
218 | } | 231 | } |
219 | } | 232 | } |
220 | 233 | ||
... | @@ -272,26 +285,41 @@ public class CordVtn implements CordVtnService { | ... | @@ -272,26 +285,41 @@ public class CordVtn implements CordVtnService { |
272 | }); | 285 | }); |
273 | String dpid = ovsdb.intBrId().toString().substring(DPID_BEGIN); | 286 | String dpid = ovsdb.intBrId().toString().substring(DPID_BEGIN); |
274 | 287 | ||
275 | - // TODO change to use bridge config | 288 | + try { |
276 | - OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb); | 289 | + DriverHandler handler = driverService.createHandler(ovsdb.deviceId()); |
277 | - ovsdbClient.createBridge(DEFAULT_BRIDGE_NAME, dpid, controllers); | 290 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
291 | + bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), dpid, controllers); | ||
292 | + } catch (ItemNotFoundException e) { | ||
293 | + log.warn("Failed to create integration bridge on {}", ovsdb.deviceId()); | ||
294 | + } | ||
278 | } | 295 | } |
279 | 296 | ||
280 | - private void createVxlanPort(OvsdbNode ovsdb) { | 297 | + private void createVxlanInterface(OvsdbNode ovsdb) { |
281 | - // TODO change to use tunnel config and tunnel description | 298 | + DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder(); |
282 | - OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb); | 299 | + for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) { |
283 | - ovsdbClient.createTunnel(DEFAULT_BRIDGE_NAME, DEFAULT_TUNNEL, | 300 | + optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key)); |
284 | - DEFAULT_TUNNEL, DEFAULT_TUNNEL_OPTIONS); | 301 | + } |
302 | + TunnelDescription description = | ||
303 | + new DefaultTunnelDescription(null, null, VXLAN, | ||
304 | + TunnelName.tunnelName(DEFAULT_TUNNEL), | ||
305 | + optionBuilder.build()); | ||
306 | + try { | ||
307 | + DriverHandler handler = driverService.createHandler(ovsdb.deviceId()); | ||
308 | + TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); | ||
309 | + tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), description); | ||
310 | + } catch (ItemNotFoundException e) { | ||
311 | + log.warn("Failed to create VXLAN interface on {}", ovsdb.deviceId()); | ||
312 | + } | ||
285 | } | 313 | } |
286 | 314 | ||
287 | - private boolean checkVxlanPort(OvsdbNode ovsdb) { | 315 | + private boolean checkVxlanInterface(OvsdbNode ovsdb) { |
288 | - // TODO change to use tunnel config | ||
289 | - OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb); | ||
290 | try { | 316 | try { |
291 | - ovsdbClient.getPorts().stream() | 317 | + DriverHandler handler = driverService.createHandler(ovsdb.deviceId()); |
292 | - .filter(p -> p.portName().value().equals(DEFAULT_TUNNEL)) | 318 | + BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); |
293 | - .findFirst().get(); | 319 | + bridgeConfig.getPorts().stream() |
294 | - } catch (NoSuchElementException e) { | 320 | + .filter(p -> p.annotations().value("portName").equals(DEFAULT_TUNNEL)) |
321 | + .findAny().get(); | ||
322 | + } catch (ItemNotFoundException | NoSuchElementException e) { | ||
295 | return false; | 323 | return false; |
296 | } | 324 | } |
297 | return true; | 325 | return true; |
... | @@ -374,8 +402,8 @@ public class CordVtn implements CordVtnService { | ... | @@ -374,8 +402,8 @@ public class CordVtn implements CordVtnService { |
374 | return; | 402 | return; |
375 | } | 403 | } |
376 | 404 | ||
377 | - if (!checkVxlanPort(ovsdb)) { | 405 | + if (!checkVxlanInterface(ovsdb)) { |
378 | - createVxlanPort(ovsdb); | 406 | + createVxlanInterface(ovsdb); |
379 | } | 407 | } |
380 | } | 408 | } |
381 | 409 | ... | ... |
... | @@ -110,7 +110,7 @@ public class CordVtnConfigManager { | ... | @@ -110,7 +110,7 @@ public class CordVtnConfigManager { |
110 | break; | 110 | break; |
111 | case CONFIG_UPDATED: | 111 | case CONFIG_UPDATED: |
112 | log.info("Network configuration updated"); | 112 | log.info("Network configuration updated"); |
113 | - // TODO handle update event | 113 | + readConfiguration(); |
114 | break; | 114 | break; |
115 | default: | 115 | default: |
116 | break; | 116 | break; | ... | ... |
-
Please register or login to post a comment