Committed by
Gerrit Code Review
Fix to avoid duplication of key and flow when host event occurs.
- modify key of the security group maps. - search for a subnet interface to the host. Change-Id: I502a35735b423fb6c27bab6b83b642a5f916e37c
Showing
3 changed files
with
31 additions
and
15 deletions
... | @@ -276,6 +276,12 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst | ... | @@ -276,6 +276,12 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst |
276 | .map(OpenstackSubnet::id) | 276 | .map(OpenstackSubnet::id) |
277 | .collect(Collectors.toSet()); | 277 | .collect(Collectors.toSet()); |
278 | 278 | ||
279 | + if (host.isPresent()) { | ||
280 | + if (!routableSubNetIds.contains(host.get().annotations().value(SUBNET_ID))) { | ||
281 | + // subnet of host is not connected to this router, do nothing. | ||
282 | + return; | ||
283 | + } | ||
284 | + } | ||
279 | 285 | ||
280 | Set<Host> hosts = host.isPresent() ? ImmutableSet.of(host.get()) : | 286 | Set<Host> hosts = host.isPresent() ? ImmutableSet.of(host.get()) : |
281 | Tools.stream(hostService.getHosts()) | 287 | Tools.stream(hostService.getHosts()) |
... | @@ -307,11 +313,12 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst | ... | @@ -307,11 +313,12 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst |
307 | r.id().equals(routerId)).iterator().next(); | 313 | r.id().equals(routerId)).iterator().next(); |
308 | } | 314 | } |
309 | 315 | ||
310 | - private Optional<OpenstackPort> routerIfacePort(String osNetId) { | 316 | + private Optional<OpenstackPort> routerIfacePort(String osNetId, String osSubNetId) { |
311 | // FIXME router interface is subnet specific, not network | 317 | // FIXME router interface is subnet specific, not network |
312 | return openstackService.ports().stream() | 318 | return openstackService.ports().stream() |
313 | .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE) && | 319 | .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE) && |
314 | - p.networkId().equals(osNetId)) | 320 | + p.networkId().equals(osNetId) && |
321 | + p.fixedIps().containsKey(osSubNetId)) | ||
315 | .findAny(); | 322 | .findAny(); |
316 | } | 323 | } |
317 | 324 | ||
... | @@ -538,7 +545,8 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst | ... | @@ -538,7 +545,8 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst |
538 | @Override | 545 | @Override |
539 | protected void hostDetected(Host host) { | 546 | protected void hostDetected(Host host) { |
540 | String osNetId = host.annotations().value(NETWORK_ID); | 547 | String osNetId = host.annotations().value(NETWORK_ID); |
541 | - Optional<OpenstackPort> routerIface = routerIfacePort(osNetId); | 548 | + String osSubNetId = host.annotations().value(SUBNET_ID); |
549 | + Optional<OpenstackPort> routerIface = routerIfacePort(osNetId, osSubNetId); | ||
542 | if (!routerIface.isPresent()) { | 550 | if (!routerIface.isPresent()) { |
543 | return; | 551 | return; |
544 | } | 552 | } |
... | @@ -550,7 +558,8 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst | ... | @@ -550,7 +558,8 @@ public class OpenstackRoutingManager extends AbstractVmHandler implements Openst |
550 | @Override | 558 | @Override |
551 | protected void hostRemoved(Host host) { | 559 | protected void hostRemoved(Host host) { |
552 | String osNetId = host.annotations().value(NETWORK_ID); | 560 | String osNetId = host.annotations().value(NETWORK_ID); |
553 | - Optional<OpenstackPort> routerIface = routerIfacePort(osNetId); | 561 | + String osSubNetId = host.annotations().value(SUBNET_ID); |
562 | + Optional<OpenstackPort> routerIface = routerIfacePort(osNetId, osSubNetId); | ||
554 | if (!routerIface.isPresent()) { | 563 | if (!routerIface.isPresent()) { |
555 | return; | 564 | return; |
556 | } | 565 | } | ... | ... |
... | @@ -33,6 +33,7 @@ import org.onlab.util.Tools; | ... | @@ -33,6 +33,7 @@ import org.onlab.util.Tools; |
33 | import org.onosproject.core.ApplicationId; | 33 | import org.onosproject.core.ApplicationId; |
34 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
35 | import org.onosproject.net.Host; | 35 | import org.onosproject.net.Host; |
36 | +import org.onosproject.net.HostId; | ||
36 | import org.onosproject.net.flow.DefaultTrafficSelector; | 37 | import org.onosproject.net.flow.DefaultTrafficSelector; |
37 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 38 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
38 | import org.onosproject.net.flow.TrafficSelector; | 39 | import org.onosproject.net.flow.TrafficSelector; |
... | @@ -78,7 +79,9 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler | ... | @@ -78,7 +79,9 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler |
78 | private static final String PROTO_UDP = "UDP"; | 79 | private static final String PROTO_UDP = "UDP"; |
79 | private static final String ETHTYPE_IPV4 = "IPV4"; | 80 | private static final String ETHTYPE_IPV4 = "IPV4"; |
80 | 81 | ||
81 | - private final Map<Host, Set<SecurityGroupRule>> securityGroupRuleMap = Maps.newConcurrentMap(); | 82 | + private final Map<HostId, Set<SecurityGroupRule>> securityGroupRuleMap = Maps.newConcurrentMap(); |
83 | + private final Map<HostId, Host> hostInfoMap = Maps.newHashMap(); | ||
84 | + | ||
82 | private ApplicationId appId; | 85 | private ApplicationId appId; |
83 | 86 | ||
84 | @Activate | 87 | @Activate |
... | @@ -118,9 +121,9 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler | ... | @@ -118,9 +121,9 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler |
118 | */ | 121 | */ |
119 | private void populateSecurityGroupRules(String tenantId, boolean install) { | 122 | private void populateSecurityGroupRules(String tenantId, boolean install) { |
120 | securityGroupRuleMap.entrySet().stream() | 123 | securityGroupRuleMap.entrySet().stream() |
121 | - .filter(entry -> getTenantId(entry.getKey()).equals(tenantId)) | 124 | + .filter(entry -> getTenantId(hostInfoMap.get(entry.getKey())).equals(tenantId)) |
122 | .forEach(entry -> { | 125 | .forEach(entry -> { |
123 | - Host local = entry.getKey(); | 126 | + Host local = hostInfoMap.get(entry.getKey()); |
124 | entry.getValue().forEach(sgRule -> { | 127 | entry.getValue().forEach(sgRule -> { |
125 | setSecurityGroupRule(local.location().deviceId(), | 128 | setSecurityGroupRule(local.location().deviceId(), |
126 | sgRule.rule(), | 129 | sgRule.rule(), |
... | @@ -259,7 +262,8 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler | ... | @@ -259,7 +262,8 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler |
259 | log.warn("Failed to get security group {}", sgId); | 262 | log.warn("Failed to get security group {}", sgId); |
260 | } | 263 | } |
261 | }); | 264 | }); |
262 | - securityGroupRuleMap.put(host, rules); | 265 | + hostInfoMap.put(host.id(), host); |
266 | + securityGroupRuleMap.put(host.id(), rules); | ||
263 | } | 267 | } |
264 | 268 | ||
265 | /** | 269 | /** |
... | @@ -293,11 +297,11 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler | ... | @@ -293,11 +297,11 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler |
293 | private Set<IpPrefix> getRemoteIps(String tenantId, String sgId) { | 297 | private Set<IpPrefix> getRemoteIps(String tenantId, String sgId) { |
294 | Set<IpPrefix> remoteIps = Sets.newHashSet(); | 298 | Set<IpPrefix> remoteIps = Sets.newHashSet(); |
295 | securityGroupRuleMap.entrySet().stream() | 299 | securityGroupRuleMap.entrySet().stream() |
296 | - .filter(entry -> Objects.equals(getTenantId(entry.getKey()), tenantId)) | 300 | + .filter(entry -> Objects.equals(getTenantId(hostInfoMap.get(entry.getKey())), tenantId)) |
297 | .forEach(entry -> { | 301 | .forEach(entry -> { |
298 | if (entry.getValue().stream() | 302 | if (entry.getValue().stream() |
299 | .anyMatch(rule -> rule.rule().secuityGroupId().equals(sgId))) { | 303 | .anyMatch(rule -> rule.rule().secuityGroupId().equals(sgId))) { |
300 | - remoteIps.add(IpPrefix.valueOf(getIp(entry.getKey()), 32)); | 304 | + remoteIps.add(IpPrefix.valueOf(getIp(hostInfoMap.get(entry.getKey())), 32)); |
301 | } | 305 | } |
302 | }); | 306 | }); |
303 | return remoteIps; | 307 | return remoteIps; |
... | @@ -310,7 +314,8 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler | ... | @@ -310,7 +314,8 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler |
310 | if (isHostAdded) { | 314 | if (isHostAdded) { |
311 | updateSecurityGroupRulesMap(host); | 315 | updateSecurityGroupRulesMap(host); |
312 | } else { | 316 | } else { |
313 | - securityGroupRuleMap.remove(host); | 317 | + securityGroupRuleMap.remove(host.id()); |
318 | + hostInfoMap.remove(host.id()); | ||
314 | } | 319 | } |
315 | 320 | ||
316 | Tools.stream(hostService.getHosts()) | 321 | Tools.stream(hostService.getHosts()) |
... | @@ -370,4 +375,4 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler | ... | @@ -370,4 +375,4 @@ public class OpenstackSecurityGroupManager extends AbstractVmHandler |
370 | return Objects.hash(rule, remoteIp); | 375 | return Objects.hash(rule, remoteIp); |
371 | } | 376 | } |
372 | } | 377 | } |
373 | -} | 378 | +} |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -161,8 +161,11 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider | ... | @@ -161,8 +161,11 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider |
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | 163 | ||
164 | + Map.Entry<String, Ip4Address> fixedIp = osPort.fixedIps().entrySet().stream().findFirst().get(); | ||
165 | + | ||
164 | OpenstackSubnet openstackSubnet = openstackService.subnets().stream() | 166 | OpenstackSubnet openstackSubnet = openstackService.subnets().stream() |
165 | - .filter(n -> n.networkId().equals(osPort.networkId())) | 167 | + .filter(n -> n.networkId().equals(osPort.networkId()) && |
168 | + n.id().equals(fixedIp.getKey())) | ||
166 | .findFirst().orElse(null); | 169 | .findFirst().orElse(null); |
167 | if (openstackSubnet == null) { | 170 | if (openstackSubnet == null) { |
168 | log.warn("Failed to find subnet for {}", osPort); | 171 | log.warn("Failed to find subnet for {}", osPort); |
... | @@ -171,8 +174,7 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider | ... | @@ -171,8 +174,7 @@ public final class OpenstackSwitchingHostManager extends AbstractProvider |
171 | 174 | ||
172 | registerDhcpInfo(osPort, openstackSubnet); | 175 | registerDhcpInfo(osPort, openstackSubnet); |
173 | ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number()); | 176 | ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number()); |
174 | - // TODO remove gateway IP from host annotation | 177 | + |
175 | - Map.Entry<String, Ip4Address> fixedIp = osPort.fixedIps().entrySet().stream().findFirst().get(); | ||
176 | 178 | ||
177 | // Added CREATE_TIME intentionally to trigger HOST_UPDATED event for the | 179 | // Added CREATE_TIME intentionally to trigger HOST_UPDATED event for the |
178 | // existing instances. | 180 | // existing instances. | ... | ... |
-
Please register or login to post a comment