sanghoshin
Committed by Gerrit Code Review

[Falcon] SONA : Supports routers

Adds the flow rules for router to the network node and compute nodes when a router is added.

Change-Id: I6e159b813a32f8e8b48f488d66731f882cf867ed
...@@ -31,6 +31,7 @@ import org.onosproject.core.CoreService; ...@@ -31,6 +31,7 @@ import org.onosproject.core.CoreService;
31 import org.onosproject.dhcp.DhcpService; 31 import org.onosproject.dhcp.DhcpService;
32 import org.onosproject.event.AbstractEvent; 32 import org.onosproject.event.AbstractEvent;
33 import org.onosproject.net.Device; 33 import org.onosproject.net.Device;
34 +import org.onosproject.net.DeviceId;
34 import org.onosproject.net.Host; 35 import org.onosproject.net.Host;
35 import org.onosproject.net.Port; 36 import org.onosproject.net.Port;
36 import org.onosproject.net.config.ConfigFactory; 37 import org.onosproject.net.config.ConfigFactory;
...@@ -98,6 +99,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -98,6 +99,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
98 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 99 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
99 protected DriverService driverService; 100 protected DriverService driverService;
100 101
102 + public static final String PORTNAME_PREFIX_VM = "tap";
103 + public static final String PORTNAME_PREFIX_ROUTER = "qr";
104 + public static final String PORTNAME_PREFIX_TUNNEL = "vxlan";
105 + public static final String PORTNAME = "portName";
106 +
101 private ApplicationId appId; 107 private ApplicationId appId;
102 private boolean doNotPushFlows; 108 private boolean doNotPushFlows;
103 private Ip4Address neutronServer; 109 private Ip4Address neutronServer;
...@@ -195,7 +201,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -195,7 +201,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
195 @Override 201 @Override
196 public OpenstackPort port(Port port) { 202 public OpenstackPort port(Port port) {
197 Collection<OpenstackPort> ports = restHandler.getPorts(); 203 Collection<OpenstackPort> ports = restHandler.getPorts();
198 - String uuid = port.annotations().value("portName").substring(3); 204 + String uuid = port.annotations().value(PORTNAME).substring(3);
199 return ports.stream() 205 return ports.stream()
200 .filter(p -> p.id().startsWith(uuid)) 206 .filter(p -> p.id().startsWith(uuid))
201 .findFirst().orElse(null); 207 .findFirst().orElse(null);
...@@ -253,37 +259,23 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -253,37 +259,23 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
253 } 259 }
254 260
255 private void processPortUpdated(Device device, Port port) { 261 private void processPortUpdated(Device device, Port port) {
256 - if (!port.annotations().value("portName").equals("vxlan") && !doNotPushFlows) { 262 + if (!port.annotations().value(PORTNAME).equals(PORTNAME_PREFIX_TUNNEL) && !doNotPushFlows) {
257 - if (port.isEnabled()) { 263 + if (port.isEnabled() || port.annotations().value(PORTNAME).startsWith(PORTNAME_PREFIX_ROUTER)) {
258 OpenstackSwitchingRulePopulator rulePopulator = 264 OpenstackSwitchingRulePopulator rulePopulator =
259 new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, 265 new OpenstackSwitchingRulePopulator(appId, flowObjectiveService,
260 deviceService, restHandler, driverService); 266 deviceService, restHandler, driverService);
261 rulePopulator.populateSwitchingRules(device, port); 267 rulePopulator.populateSwitchingRules(device, port);
262 - 268 + updatePortMap(device.id(), port, restHandler.getNetworks(), rulePopulator.openstackPort(port));
263 - OpenstackPort openstackPort = port(port);
264 -
265 - long vni = Long.parseLong(restHandler.getNetworks().stream()
266 - .filter(n -> n.id().equals(openstackPort.networkId()))
267 - .findAny().orElse(null).segmentId());
268 -
269 - OpenstackPortInfo.Builder portBuilder = OpenstackPortInfo.builder()
270 - .setDeviceId(device.id())
271 - .setHostIp((Ip4Address) openstackPort.fixedIps().values().stream().findFirst().orElse(null))
272 - .setVNI(vni);
273 -
274 - openstackPortInfoMap.putIfAbsent(port.annotations().value("portName"),
275 - portBuilder.build());
276 - }
277 269
278 //In case portupdate event is driven by vm shutoff from openstack 270 //In case portupdate event is driven by vm shutoff from openstack
279 - if (!port.isEnabled() && openstackPortInfoMap.containsKey(port.annotations().value("portName"))) { 271 + } else if (!port.isEnabled() && openstackPortInfoMap.containsKey(port.annotations().value(PORTNAME))) {
280 log.debug("Flowrules according to the port {} were removed", port.number().toString()); 272 log.debug("Flowrules according to the port {} were removed", port.number().toString());
281 OpenstackSwitchingRulePopulator rulePopulator = 273 OpenstackSwitchingRulePopulator rulePopulator =
282 new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, 274 new OpenstackSwitchingRulePopulator(appId, flowObjectiveService,
283 deviceService, restHandler, driverService); 275 deviceService, restHandler, driverService);
284 - openstackPortInfoMap.get(port.annotations().value("portName")); 276 + openstackPortInfoMap.get(port.annotations().value(PORTNAME));
285 rulePopulator.removeSwitchingRules(port, openstackPortInfoMap); 277 rulePopulator.removeSwitchingRules(port, openstackPortInfoMap);
286 - openstackPortInfoMap.remove(port.annotations().value("portName")); 278 + openstackPortInfoMap.remove(port.annotations().value(PORTNAME));
287 } 279 }
288 } 280 }
289 } 281 }
...@@ -297,16 +289,20 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -297,16 +289,20 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
297 new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, 289 new OpenstackSwitchingRulePopulator(appId, flowObjectiveService,
298 deviceService, restHandler, driverService); 290 deviceService, restHandler, driverService);
299 291
292 + Collection<OpenstackNetwork> networks = restHandler.getNetworks();
293 +
300 deviceService.getDevices().forEach(device -> { 294 deviceService.getDevices().forEach(device -> {
301 log.debug("device {} num of ports {} ", device.id(), 295 log.debug("device {} num of ports {} ", device.id(),
302 deviceService.getPorts(device.id()).size()); 296 deviceService.getPorts(device.id()).size());
303 deviceService.getPorts(device.id()).stream() 297 deviceService.getPorts(device.id()).stream()
304 - .filter(port -> port.annotations().value("portName").startsWith("tap")) 298 + .filter(port -> port.annotations().value(PORTNAME).startsWith(PORTNAME_PREFIX_VM) ||
299 + port.annotations().value(PORTNAME).startsWith(PORTNAME_PREFIX_ROUTER))
305 .forEach(vmPort -> { 300 .forEach(vmPort -> {
306 OpenstackPort osPort = rulePopulator.openstackPort(vmPort); 301 OpenstackPort osPort = rulePopulator.openstackPort(vmPort);
307 if (osPort != null) { 302 if (osPort != null) {
308 if (!doNotPushFlows) { 303 if (!doNotPushFlows) {
309 rulePopulator.populateSwitchingRules(device, vmPort); 304 rulePopulator.populateSwitchingRules(device, vmPort);
305 + updatePortMap(device.id(), vmPort, networks, osPort);
310 } 306 }
311 registerDhcpInfo(osPort); 307 registerDhcpInfo(osPort);
312 } else { 308 } else {
...@@ -318,6 +314,21 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -318,6 +314,21 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
318 ); 314 );
319 } 315 }
320 316
317 + private void updatePortMap(DeviceId deviceId, Port port, Collection<OpenstackNetwork> networks,
318 + OpenstackPort openstackPort) {
319 + long vni = Long.parseLong(networks.stream()
320 + .filter(n -> n.id().equals(openstackPort.networkId()))
321 + .findAny().orElse(null).segmentId());
322 +
323 + OpenstackPortInfo.Builder portBuilder = OpenstackPortInfo.builder()
324 + .setDeviceId(deviceId)
325 + .setHostIp((Ip4Address) openstackPort.fixedIps().values().stream().findFirst().orElse(null))
326 + .setVNI(vni);
327 +
328 + openstackPortInfoMap.putIfAbsent(port.annotations().value(PORTNAME),
329 + portBuilder.build());
330 + }
331 +
321 private void processHostRemoved(Host host) { 332 private void processHostRemoved(Host host) {
322 log.debug("host {} was removed", host.toString()); 333 log.debug("host {} was removed", host.toString());
323 } 334 }
...@@ -325,8 +336,8 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -325,8 +336,8 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
325 private void registerDhcpInfo(OpenstackPort openstackPort) { 336 private void registerDhcpInfo(OpenstackPort openstackPort) {
326 Ip4Address ip4Address; 337 Ip4Address ip4Address;
327 Ip4Address subnetMask; 338 Ip4Address subnetMask;
328 - Ip4Address dhcpServer;
329 Ip4Address gatewayIPAddress; 339 Ip4Address gatewayIPAddress;
340 + Ip4Address dhcpServer;
330 Ip4Address domainServer; 341 Ip4Address domainServer;
331 OpenstackSubnet openstackSubnet; 342 OpenstackSubnet openstackSubnet;
332 343
...@@ -480,6 +491,5 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -480,6 +491,5 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
480 networkEventExcutorService.execute(this::configureNetwork); 491 networkEventExcutorService.execute(this::configureNetwork);
481 } 492 }
482 } 493 }
483 -
484 } 494 }
485 } 495 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -208,7 +208,9 @@ public class OpenstackSwitchingRulePopulator { ...@@ -208,7 +208,9 @@ public class OpenstackSwitchingRulePopulator {
208 String cidx = d.annotations().value("channelId"); 208 String cidx = d.annotations().value("channelId");
209 Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]); 209 Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]);
210 Ip4Address fixedIpx = getFixedIpAddressForPort(pName); 210 Ip4Address fixedIpx = getFixedIpAddressForPort(pName);
211 - if (port.isEnabled()) { 211 + if (port.isEnabled() ||
212 + port.annotations().value("portName").startsWith(
213 + OpenstackSwitchingManager.PORTNAME_PREFIX_ROUTER)) {
212 setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx); 214 setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx);
213 setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp); 215 setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp);
214 } 216 }
...@@ -475,7 +477,8 @@ public class OpenstackSwitchingRulePopulator { ...@@ -475,7 +477,8 @@ public class OpenstackSwitchingRulePopulator {
475 477
476 private PortNumber getTunnelPort(DeviceId deviceId) { 478 private PortNumber getTunnelPort(DeviceId deviceId) {
477 Port port = deviceService.getPorts(deviceId).stream() 479 Port port = deviceService.getPorts(deviceId).stream()
478 - .filter(p -> p.annotations().value("portName").equals("vxlan")) 480 + .filter(p -> p.annotations().value("portName").equals(
481 + OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL))
479 .findAny().orElse(null); 482 .findAny().orElse(null);
480 483
481 if (port == null) { 484 if (port == null) {
......