Committed by
Gerrit Code Review
[ONOS-5134] VM cannot access to another VM with floating IP
Change-Id: I300d410994361de505558bfcdeb732a8a6c14b91
Showing
2 changed files
with
50 additions
and
7 deletions
| ... | @@ -62,7 +62,8 @@ public final class Constants { | ... | @@ -62,7 +62,8 @@ public final class Constants { |
| 62 | 62 | ||
| 63 | public static final int GATEWAY_ICMP_PRIORITY = 43000; | 63 | public static final int GATEWAY_ICMP_PRIORITY = 43000; |
| 64 | public static final int ROUTING_RULE_PRIORITY = 25000; | 64 | public static final int ROUTING_RULE_PRIORITY = 25000; |
| 65 | - public static final int FLOATING_RULE_PRIORITY = 42000; | 65 | + public static final int FLOATING_RULE_FOR_TRAFFIC_FROM_VM_PRIORITY = 42000; |
| 66 | + public static final int FLOATING_RULE_PRIORITY = 41000; | ||
| 66 | public static final int PNAT_RULE_PRIORITY = 26000; | 67 | public static final int PNAT_RULE_PRIORITY = 26000; |
| 67 | public static final int PNAT_TIMEOUT = 120; | 68 | public static final int PNAT_TIMEOUT = 120; |
| 68 | } | 69 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -30,6 +30,7 @@ import org.onosproject.core.ApplicationId; | ... | @@ -30,6 +30,7 @@ import org.onosproject.core.ApplicationId; |
| 30 | import org.onosproject.core.CoreService; | 30 | import org.onosproject.core.CoreService; |
| 31 | import org.onosproject.net.DeviceId; | 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Host; | 32 | import org.onosproject.net.Host; |
| 33 | +import org.onosproject.net.PortNumber; | ||
| 33 | import org.onosproject.net.device.DeviceService; | 34 | import org.onosproject.net.device.DeviceService; |
| 34 | import org.onosproject.net.flow.DefaultTrafficSelector; | 35 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| ... | @@ -231,6 +232,11 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope | ... | @@ -231,6 +232,11 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope |
| 231 | .matchIPDst(floatingIp.toIpPrefix()); | 232 | .matchIPDst(floatingIp.toIpPrefix()); |
| 232 | 233 | ||
| 233 | gatewayService.getGatewayDeviceIds().stream().forEach(deviceId -> { | 234 | gatewayService.getGatewayDeviceIds().stream().forEach(deviceId -> { |
| 235 | + TrafficSelector.Builder sForTrafficFromVmBuilder = DefaultTrafficSelector.builder() | ||
| 236 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
| 237 | + .matchIPDst(floatingIp.toIpPrefix()) | ||
| 238 | + .matchInPort(nodeService.tunnelPort(deviceId).get()); | ||
| 239 | + | ||
| 234 | RulePopulatorUtil.removeRule( | 240 | RulePopulatorUtil.removeRule( |
| 235 | flowObjectiveService, | 241 | flowObjectiveService, |
| 236 | appId, | 242 | appId, |
| ... | @@ -246,6 +252,14 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope | ... | @@ -246,6 +252,14 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope |
| 246 | sIncomingBuilder.build(), | 252 | sIncomingBuilder.build(), |
| 247 | ForwardingObjective.Flag.VERSATILE, | 253 | ForwardingObjective.Flag.VERSATILE, |
| 248 | FLOATING_RULE_PRIORITY); | 254 | FLOATING_RULE_PRIORITY); |
| 255 | + | ||
| 256 | + RulePopulatorUtil.removeRule( | ||
| 257 | + flowObjectiveService, | ||
| 258 | + appId, | ||
| 259 | + deviceId, | ||
| 260 | + sForTrafficFromVmBuilder.build(), | ||
| 261 | + ForwardingObjective.Flag.VERSATILE, | ||
| 262 | + FLOATING_RULE_FOR_TRAFFIC_FROM_VM_PRIORITY); | ||
| 249 | }); | 263 | }); |
| 250 | } | 264 | } |
| 251 | 265 | ||
| ... | @@ -259,13 +273,13 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope | ... | @@ -259,13 +273,13 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope |
| 259 | return; | 273 | return; |
| 260 | } | 274 | } |
| 261 | 275 | ||
| 262 | - TrafficSelector selector = DefaultTrafficSelector.builder() | 276 | + TrafficSelector selectorForTrafficFromExternal = DefaultTrafficSelector.builder() |
| 263 | .matchEthType(Ethernet.TYPE_IPV4) | 277 | .matchEthType(Ethernet.TYPE_IPV4) |
| 264 | .matchIPDst(floatingIp.toIpPrefix()) | 278 | .matchIPDst(floatingIp.toIpPrefix()) |
| 265 | .build(); | 279 | .build(); |
| 266 | 280 | ||
| 267 | gatewayService.getGatewayDeviceIds().stream().forEach(gnodeId -> { | 281 | gatewayService.getGatewayDeviceIds().stream().forEach(gnodeId -> { |
| 268 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | 282 | + TrafficTreatment treatmentForTrafficFromExternal = DefaultTrafficTreatment.builder() |
| 269 | .setEthSrc(Constants.DEFAULT_GATEWAY_MAC) | 283 | .setEthSrc(Constants.DEFAULT_GATEWAY_MAC) |
| 270 | .setEthDst(associatedVm.mac()) | 284 | .setEthDst(associatedVm.mac()) |
| 271 | .setIpDst(associatedVm.ipAddresses().stream().findFirst().get()) | 285 | .setIpDst(associatedVm.ipAddresses().stream().findFirst().get()) |
| ... | @@ -275,15 +289,43 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope | ... | @@ -275,15 +289,43 @@ public class OpenstackFloatingIpManager extends AbstractVmHandler implements Ope |
| 275 | .setOutput(nodeService.tunnelPort(gnodeId).get()) | 289 | .setOutput(nodeService.tunnelPort(gnodeId).get()) |
| 276 | .build(); | 290 | .build(); |
| 277 | 291 | ||
| 278 | - ForwardingObjective fo = DefaultForwardingObjective.builder() | 292 | + ForwardingObjective forwardingObjectiveForTrafficFromExternal = DefaultForwardingObjective.builder() |
| 279 | - .withSelector(selector) | 293 | + .withSelector(selectorForTrafficFromExternal) |
| 280 | - .withTreatment(treatment) | 294 | + .withTreatment(treatmentForTrafficFromExternal) |
| 281 | .withFlag(ForwardingObjective.Flag.VERSATILE) | 295 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 282 | .withPriority(FLOATING_RULE_PRIORITY) | 296 | .withPriority(FLOATING_RULE_PRIORITY) |
| 283 | .fromApp(appId) | 297 | .fromApp(appId) |
| 284 | .add(); | 298 | .add(); |
| 285 | 299 | ||
| 286 | - flowObjectiveService.forward(gnodeId, fo); | 300 | + flowObjectiveService.forward(gnodeId, forwardingObjectiveForTrafficFromExternal); |
| 301 | + | ||
| 302 | + | ||
| 303 | + TrafficSelector selectorForTrafficFromVm = DefaultTrafficSelector.builder() | ||
| 304 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
| 305 | + .matchIPDst(floatingIp.toIpPrefix()) | ||
| 306 | + .matchInPort(nodeService.tunnelPort(gnodeId).get()) | ||
| 307 | + .build(); | ||
| 308 | + | ||
| 309 | + TrafficTreatment treatmentForTrafficFromVm = DefaultTrafficTreatment.builder() | ||
| 310 | + .setEthSrc(Constants.DEFAULT_GATEWAY_MAC) | ||
| 311 | + .setEthDst(associatedVm.mac()) | ||
| 312 | + .setIpDst(associatedVm.ipAddresses().stream().findFirst().get()) | ||
| 313 | + .setTunnelId(Long.valueOf(associatedVm.annotations().value(VXLAN_ID))) | ||
| 314 | + .extension(buildExtension(deviceService, gnodeId, dataIp.get().getIp4Address()), | ||
| 315 | + gnodeId) | ||
| 316 | + .setOutput(PortNumber.IN_PORT) | ||
| 317 | + .build(); | ||
| 318 | + | ||
| 319 | + ForwardingObjective forwardingObjectiveForTrafficFromVm = DefaultForwardingObjective.builder() | ||
| 320 | + .withSelector(selectorForTrafficFromVm) | ||
| 321 | + .withTreatment(treatmentForTrafficFromVm) | ||
| 322 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
| 323 | + .withPriority(FLOATING_RULE_FOR_TRAFFIC_FROM_VM_PRIORITY) | ||
| 324 | + .fromApp(appId) | ||
| 325 | + .add(); | ||
| 326 | + | ||
| 327 | + flowObjectiveService.forward(gnodeId, forwardingObjectiveForTrafficFromVm); | ||
| 328 | + | ||
| 287 | }); | 329 | }); |
| 288 | } | 330 | } |
| 289 | 331 | ... | ... |
-
Please register or login to post a comment