Committed by
Gerrit Code Review
SONA: OpenstackSwitching - init flow rules
- Populates flow rules when the app is initialized for existing VMs - Add the IP mappings for the existing VMs to DHCP service. Change-Id: Ie73c2532c83b0c0df21261616d7af81744c0aa32
Showing
2 changed files
with
37 additions
and
0 deletions
... | @@ -214,6 +214,30 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -214,6 +214,30 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
214 | log.debug("port {} is removed", port.toString()); | 214 | log.debug("port {} is removed", port.toString()); |
215 | } | 215 | } |
216 | 216 | ||
217 | + private void initializeFlowRules() { | ||
218 | + OpenstackSwitchingRulePopulator rulePopulator = | ||
219 | + new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, | ||
220 | + deviceService, restHandler, driverService); | ||
221 | + | ||
222 | + deviceService.getDevices().forEach(device -> { | ||
223 | + log.debug("device {} num of ports {} ", device.id(), | ||
224 | + deviceService.getPorts(device.id()).size()); | ||
225 | + deviceService.getPorts(device.id()).stream() | ||
226 | + .filter(port -> port.annotations().value("portName").startsWith("tap")) | ||
227 | + .forEach(vmPort -> { | ||
228 | + OpenstackPort osPort = rulePopulator.openstackPort(vmPort); | ||
229 | + if (osPort != null) { | ||
230 | + rulePopulator.populateSwitchingRules(device, vmPort); | ||
231 | + registerDhcpInfo(osPort); | ||
232 | + } else { | ||
233 | + log.warn("No openstackPort information for port {}", vmPort); | ||
234 | + } | ||
235 | + } | ||
236 | + ); | ||
237 | + } | ||
238 | + ); | ||
239 | + } | ||
240 | + | ||
217 | private void registerDhcpInfo(OpenstackPort openstackPort) { | 241 | private void registerDhcpInfo(OpenstackPort openstackPort) { |
218 | Ip4Address ip4Address; | 242 | Ip4Address ip4Address; |
219 | Ip4Address subnetMask; | 243 | Ip4Address subnetMask; |
... | @@ -343,6 +367,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -343,6 +367,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
343 | doNotPushFlows = cfg.doNotPushFlows(); | 367 | doNotPushFlows = cfg.doNotPushFlows(); |
344 | restHandler = new OpenstackRestHandler(cfg); | 368 | restHandler = new OpenstackRestHandler(cfg); |
345 | arpHandler = new OpenstackArpHandler(restHandler, packetService); | 369 | arpHandler = new OpenstackArpHandler(restHandler, packetService); |
370 | + initializeFlowRules(); | ||
346 | } | 371 | } |
347 | 372 | ||
348 | @Override | 373 | @Override | ... | ... |
... | @@ -99,6 +99,18 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -99,6 +99,18 @@ public class OpenstackSwitchingRulePopulator { |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
102 | + * Returns OpenstackPort object for the Port reference given. | ||
103 | + * | ||
104 | + * @param port Port object | ||
105 | + * @return OpenstackPort reference, or null when not found | ||
106 | + */ | ||
107 | + public OpenstackPort openstackPort(Port port) { | ||
108 | + String uuid = port.annotations().value("portName").substring(3); | ||
109 | + return openstackPortList.stream().filter(p -> p.id().startsWith(uuid)) | ||
110 | + .findAny().orElse(null); | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
102 | * Populates the flow rules for traffic to VMs in the same Cnode as the sender. | 114 | * Populates the flow rules for traffic to VMs in the same Cnode as the sender. |
103 | * | 115 | * |
104 | * @param device device to put the rules | 116 | * @param device device to put the rules | ... | ... |
-
Please register or login to post a comment