Committed by
Gerrit Code Review
SONA: OpenstackSwitching - RulePopulator Modified
- Populates flow rules to make suitable for SONA Pipeline Change-Id: I8e84cd74d843a64771d43db16a9f7c5b2323c965
Showing
1 changed file
with
83 additions
and
9 deletions
| ... | @@ -53,7 +53,9 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -53,7 +53,9 @@ public class OpenstackSwitchingRulePopulator { |
| 53 | 53 | ||
| 54 | private static Logger log = LoggerFactory | 54 | private static Logger log = LoggerFactory |
| 55 | .getLogger(OpenstackSwitchingRulePopulator.class); | 55 | .getLogger(OpenstackSwitchingRulePopulator.class); |
| 56 | - private static final int SWITCHING_RULE_PRIORITY = 50000; | 56 | + private static final int SWITCHING_RULE_PRIORITY = 30000; |
| 57 | + private static final int EAST_WEST_ROUTING_RULE_PRIORITY = 29000; | ||
| 58 | + private static final int TUNNELTAG_RULE_PRIORITY = 30000; | ||
| 57 | 59 | ||
| 58 | private FlowObjectiveService flowObjectiveService; | 60 | private FlowObjectiveService flowObjectiveService; |
| 59 | private DriverService driverService; | 61 | private DriverService driverService; |
| ... | @@ -87,6 +89,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -87,6 +89,7 @@ public class OpenstackSwitchingRulePopulator { |
| 87 | openstackPortList = restHandler.getPorts(); | 89 | openstackPortList = restHandler.getPorts(); |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 92 | + | ||
| 90 | /** | 93 | /** |
| 91 | * Populates flow rules for the VM created. | 94 | * Populates flow rules for the VM created. |
| 92 | * | 95 | * |
| ... | @@ -94,11 +97,28 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -94,11 +97,28 @@ public class OpenstackSwitchingRulePopulator { |
| 94 | * @param port port for the VM created | 97 | * @param port port for the VM created |
| 95 | */ | 98 | */ |
| 96 | public void populateSwitchingRules(Device device, Port port) { | 99 | public void populateSwitchingRules(Device device, Port port) { |
| 100 | + populateFlowRulesForVMSetTunnelTag(device, port); | ||
| 97 | populateFlowRulesForTrafficToSameCnode(device, port); | 101 | populateFlowRulesForTrafficToSameCnode(device, port); |
| 98 | populateFlowRulesForTrafficToDifferentCnode(device, port); | 102 | populateFlowRulesForTrafficToDifferentCnode(device, port); |
| 99 | } | 103 | } |
| 100 | 104 | ||
| 101 | /** | 105 | /** |
| 106 | + * Populate the flow rules for tagging tunnelId according to which inport is came from. | ||
| 107 | + * | ||
| 108 | + * @param device device to put the rules | ||
| 109 | + * @param port port info of the VM | ||
| 110 | + */ | ||
| 111 | + private void populateFlowRulesForVMSetTunnelTag(Device device, Port port) { | ||
| 112 | + Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName")); | ||
| 113 | + String portName = port.annotations().value("portName"); | ||
| 114 | + String vni = getVniForPort(portName); | ||
| 115 | + | ||
| 116 | + if (vmIp != null) { | ||
| 117 | + setFlowRuleForVMSetTunnelTag(device.id(), port, vni); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 102 | * Returns OpenstackPort object for the Port reference given. | 122 | * Returns OpenstackPort object for the Port reference given. |
| 103 | * | 123 | * |
| 104 | * @param port Port object | 124 | * @param port Port object |
| ... | @@ -118,8 +138,12 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -118,8 +138,12 @@ public class OpenstackSwitchingRulePopulator { |
| 118 | */ | 138 | */ |
| 119 | private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) { | 139 | private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) { |
| 120 | Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName")); | 140 | Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName")); |
| 141 | + String portName = port.annotations().value("portName"); | ||
| 142 | + String vni = getVniForPort(portName); | ||
| 143 | + MacAddress vmMacAddress = getVmMacAddressForPort(portName); | ||
| 144 | + | ||
| 121 | if (vmIp != null) { | 145 | if (vmIp != null) { |
| 122 | - setFlowRuleForVMsInSameCnode(vmIp, device.id(), port); | 146 | + setFlowRuleForVMsInSameCnode(vmIp, device.id(), port, vni, vmMacAddress); |
| 123 | } | 147 | } |
| 124 | } | 148 | } |
| 125 | 149 | ||
| ... | @@ -167,7 +191,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -167,7 +191,7 @@ public class OpenstackSwitchingRulePopulator { |
| 167 | .filter(p -> p.id().startsWith(uuid)) | 191 | .filter(p -> p.id().startsWith(uuid)) |
| 168 | .findAny().orElse(null); | 192 | .findAny().orElse(null); |
| 169 | if (port == null) { | 193 | if (port == null) { |
| 170 | - log.warn("No port information for port {}", portName); | 194 | + log.debug("No port information for port {}", portName); |
| 171 | return null; | 195 | return null; |
| 172 | } | 196 | } |
| 173 | 197 | ||
| ... | @@ -229,33 +253,82 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -229,33 +253,82 @@ public class OpenstackSwitchingRulePopulator { |
| 229 | return port.macAddress(); | 253 | return port.macAddress(); |
| 230 | } | 254 | } |
| 231 | 255 | ||
| 256 | + private void setFlowRuleForVMSetTunnelTag(DeviceId deviceId, Port port, String vni) { | ||
| 257 | + | ||
| 258 | + TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | ||
| 259 | + TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | ||
| 260 | + | ||
| 261 | + sBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
| 262 | + .matchInPort(port.number()); | ||
| 263 | + | ||
| 264 | + tBuilder.setTunnelId(Long.parseLong(vni)); | ||
| 265 | + | ||
| 266 | + ForwardingObjective fo = DefaultForwardingObjective.builder() | ||
| 267 | + .withSelector(sBuilder.build()) | ||
| 268 | + .withTreatment(tBuilder.build()) | ||
| 269 | + .withPriority(TUNNELTAG_RULE_PRIORITY) | ||
| 270 | + .withFlag(ForwardingObjective.Flag.SPECIFIC) | ||
| 271 | + .fromApp(appId) | ||
| 272 | + .add(); | ||
| 273 | + | ||
| 274 | + flowObjectiveService.forward(deviceId, fo); | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + | ||
| 232 | /** | 278 | /** |
| 233 | * Sets the flow rules for traffic between VMs in the same Cnode. | 279 | * Sets the flow rules for traffic between VMs in the same Cnode. |
| 234 | * | 280 | * |
| 235 | * @param ip4Address VM IP address | 281 | * @param ip4Address VM IP address |
| 236 | * @param id device ID to put rules | 282 | * @param id device ID to put rules |
| 237 | * @param port VM port | 283 | * @param port VM port |
| 284 | + * @param vni VM VNI | ||
| 285 | + * @param vmMacAddress VM MAC address | ||
| 238 | */ | 286 | */ |
| 239 | private void setFlowRuleForVMsInSameCnode(Ip4Address ip4Address, DeviceId id, | 287 | private void setFlowRuleForVMsInSameCnode(Ip4Address ip4Address, DeviceId id, |
| 240 | - Port port) { | 288 | + Port port, String vni, MacAddress vmMacAddress) { |
| 289 | + | ||
| 290 | + //For L2 Switching Case | ||
| 241 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); | 291 | TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); |
| 242 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | 292 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 243 | 293 | ||
| 244 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 294 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 245 | - .matchIPDst(ip4Address.toIpPrefix()); | 295 | + .matchIPDst(ip4Address.toIpPrefix()) |
| 296 | + .matchTunnelId(Long.parseLong(vni)); | ||
| 297 | + | ||
| 246 | tBuilder.setOutput(port.number()); | 298 | tBuilder.setOutput(port.number()); |
| 247 | 299 | ||
| 248 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 300 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 249 | .withSelector(sBuilder.build()) | 301 | .withSelector(sBuilder.build()) |
| 250 | .withTreatment(tBuilder.build()) | 302 | .withTreatment(tBuilder.build()) |
| 251 | .withPriority(SWITCHING_RULE_PRIORITY) | 303 | .withPriority(SWITCHING_RULE_PRIORITY) |
| 252 | - .withFlag(ForwardingObjective.Flag.VERSATILE) | 304 | + .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 305 | + .fromApp(appId) | ||
| 306 | + .add(); | ||
| 307 | + | ||
| 308 | + flowObjectiveService.forward(id, fo); | ||
| 309 | + | ||
| 310 | + //For L3 Ease-West Routing Case | ||
| 311 | + sBuilder = DefaultTrafficSelector.builder(); | ||
| 312 | + tBuilder = DefaultTrafficTreatment.builder(); | ||
| 313 | + | ||
| 314 | + sBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
| 315 | + .matchIPDst(ip4Address.toIpPrefix()); | ||
| 316 | + | ||
| 317 | + tBuilder.setEthDst(vmMacAddress) | ||
| 318 | + .setOutput(port.number()); | ||
| 319 | + | ||
| 320 | + fo = DefaultForwardingObjective.builder() | ||
| 321 | + .withSelector(sBuilder.build()) | ||
| 322 | + .withTreatment(tBuilder.build()) | ||
| 323 | + .withPriority(EAST_WEST_ROUTING_RULE_PRIORITY) | ||
| 324 | + .withFlag(ForwardingObjective.Flag.SPECIFIC) | ||
| 253 | .fromApp(appId) | 325 | .fromApp(appId) |
| 254 | .add(); | 326 | .add(); |
| 255 | 327 | ||
| 256 | flowObjectiveService.forward(id, fo); | 328 | flowObjectiveService.forward(id, fo); |
| 257 | } | 329 | } |
| 258 | 330 | ||
| 331 | + | ||
| 259 | /** | 332 | /** |
| 260 | * Sets the flow rules between traffic from VMs in different Cnode. | 333 | * Sets the flow rules between traffic from VMs in different Cnode. |
| 261 | * | 334 | * |
| ... | @@ -271,16 +344,17 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -271,16 +344,17 @@ public class OpenstackSwitchingRulePopulator { |
| 271 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | 344 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 272 | 345 | ||
| 273 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 346 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
| 347 | + .matchTunnelId(Long.parseLong(vni)) | ||
| 274 | .matchIPDst(vmIp.toIpPrefix()); | 348 | .matchIPDst(vmIp.toIpPrefix()); |
| 275 | - tBuilder.setTunnelId(Long.parseLong(vni)) | 349 | + |
| 276 | - .extension(buildNiciraExtenstion(id, hostIp), id) | 350 | + tBuilder.extension(buildNiciraExtenstion(id, hostIp), id) |
| 277 | .setOutput(getTunnelPort(id)); | 351 | .setOutput(getTunnelPort(id)); |
| 278 | 352 | ||
| 279 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 353 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
| 280 | .withSelector(sBuilder.build()) | 354 | .withSelector(sBuilder.build()) |
| 281 | .withTreatment(tBuilder.build()) | 355 | .withTreatment(tBuilder.build()) |
| 282 | .withPriority(SWITCHING_RULE_PRIORITY) | 356 | .withPriority(SWITCHING_RULE_PRIORITY) |
| 283 | - .withFlag(ForwardingObjective.Flag.VERSATILE) | 357 | + .withFlag(ForwardingObjective.Flag.SPECIFIC) |
| 284 | .fromApp(appId) | 358 | .fromApp(appId) |
| 285 | .add(); | 359 | .add(); |
| 286 | 360 | ... | ... |
-
Please register or login to post a comment