Bob zhou
Committed by Jonathan Hart

[ONOS-4426] [ONOS-4511] [ONOS-4502] Upgrade Vtn Module when access same network segment.

Change-Id: I3afe6b36a44f0eedd642eeadfc23fc3233e7621e
...@@ -23,9 +23,12 @@ import java.util.Objects; ...@@ -23,9 +23,12 @@ import java.util.Objects;
23 23
24 import org.onlab.osgi.ServiceDirectory; 24 import org.onlab.osgi.ServiceDirectory;
25 import org.onlab.packet.EthType.EtherType; 25 import org.onlab.packet.EthType.EtherType;
26 +import org.onlab.packet.IpAddress;
27 +import org.onlab.packet.IpPrefix;
26 import org.onosproject.core.ApplicationId; 28 import org.onosproject.core.ApplicationId;
27 import org.onosproject.core.CoreService; 29 import org.onosproject.core.CoreService;
28 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
31 +import org.onosproject.net.PortNumber;
29 import org.onosproject.net.behaviour.Pipeliner; 32 import org.onosproject.net.behaviour.Pipeliner;
30 import org.onosproject.net.behaviour.PipelinerContext; 33 import org.onosproject.net.behaviour.PipelinerContext;
31 import org.onosproject.net.device.DeviceService; 34 import org.onosproject.net.device.DeviceService;
...@@ -40,6 +43,8 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -40,6 +43,8 @@ import org.onosproject.net.flow.TrafficSelector;
40 import org.onosproject.net.flow.TrafficTreatment; 43 import org.onosproject.net.flow.TrafficTreatment;
41 import org.onosproject.net.flow.criteria.Criteria; 44 import org.onosproject.net.flow.criteria.Criteria;
42 import org.onosproject.net.flow.criteria.Criterion.Type; 45 import org.onosproject.net.flow.criteria.Criterion.Type;
46 +import org.onosproject.net.flow.criteria.IPCriterion;
47 +import org.onosproject.net.flow.instructions.Instructions;
43 import org.onosproject.net.flowobjective.FilteringObjective; 48 import org.onosproject.net.flowobjective.FilteringObjective;
44 import org.onosproject.net.flowobjective.FlowObjectiveStore; 49 import org.onosproject.net.flowobjective.FlowObjectiveStore;
45 import org.onosproject.net.flowobjective.ForwardingObjective; 50 import org.onosproject.net.flowobjective.ForwardingObjective;
...@@ -71,6 +76,7 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -71,6 +76,7 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
71 private static final int SNAT_TABLE = 40; 76 private static final int SNAT_TABLE = 40;
72 private static final int MAC_TABLE = 50; 77 private static final int MAC_TABLE = 50;
73 private static final int TABLE_MISS_PRIORITY = 0; 78 private static final int TABLE_MISS_PRIORITY = 0;
79 + private static final String USERDATA_IP = "169.254.169.254";
74 80
75 @Override 81 @Override
76 public void init(DeviceId deviceId, PipelinerContext context) { 82 public void init(DeviceId deviceId, PipelinerContext context) {
...@@ -213,7 +219,7 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -213,7 +219,7 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
213 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); 219 TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
214 220
215 treatment.transition(MAC_TABLE); 221 treatment.transition(MAC_TABLE);
216 - 222 + treatment.add(Instructions.createOutput(PortNumber.CONTROLLER));
217 FlowRule rule; 223 FlowRule rule;
218 rule = DefaultFlowRule.builder().forDevice(deviceId) 224 rule = DefaultFlowRule.builder().forDevice(deviceId)
219 .withSelector(selector.build()) 225 .withSelector(selector.build())
...@@ -290,8 +296,9 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -290,8 +296,9 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
290 Integer transition = null; 296 Integer transition = null;
291 Integer forTable = null; 297 Integer forTable = null;
292 // MAC table flow rules 298 // MAC table flow rules
293 - if (selector.getCriterion(Type.TUNNEL_ID) != null && selector 299 + if (selector.getCriterion(Type.TUNNEL_ID) != null
294 - .getCriterion(Type.ETH_DST) != null) { 300 + && (selector.getCriterion(Type.ETH_DST) != null
301 + || selector.getCriterion(Type.ETH_SRC) != null)) {
295 forTable = MAC_TABLE; 302 forTable = MAC_TABLE;
296 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable); 303 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
297 } 304 }
...@@ -306,6 +313,10 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -306,6 +313,10 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
306 transition = MAC_TABLE; 313 transition = MAC_TABLE;
307 } else if (selector.getCriterion(Type.IPV4_DST) != null) { 314 } else if (selector.getCriterion(Type.IPV4_DST) != null) {
308 transition = DNAT_TABLE; 315 transition = DNAT_TABLE;
316 + } else if (selector.getCriterion(Type.ETH_TYPE) != null
317 + && selector.getCriterion(Type.ETH_TYPE).equals(Criteria
318 + .matchEthType(EtherType.ARP.ethType().toShort()))) {
319 + transition = ARP_TABLE;
309 } 320 }
310 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable); 321 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
311 } 322 }
...@@ -315,6 +326,10 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -315,6 +326,10 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
315 .matchEthType(EtherType.ARP.ethType().toShort()))) { 326 .matchEthType(EtherType.ARP.ethType().toShort()))) {
316 // CLASSIFIER table arp flow rules 327 // CLASSIFIER table arp flow rules
317 if (selector.getCriterion(Type.TUNNEL_ID) == null) { 328 if (selector.getCriterion(Type.TUNNEL_ID) == null) {
329 + if (selector.getCriterion(Type.ARP_OP) != null) {
330 + forTable = CLASSIFIER_TABLE;
331 + return reassemblyFlowRule(ruleBuilder, tb, null, forTable);
332 + }
318 transition = ARP_TABLE; 333 transition = ARP_TABLE;
319 forTable = CLASSIFIER_TABLE; 334 forTable = CLASSIFIER_TABLE;
320 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable); 335 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
...@@ -322,6 +337,13 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -322,6 +337,13 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
322 forTable = ARP_TABLE; 337 forTable = ARP_TABLE;
323 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable); 338 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
324 } 339 }
340 + // SNAT table flow rules
341 + if (selector.getCriterion(Type.TUNNEL_ID) != null
342 + && selector.getCriterion(Type.IPV4_SRC) != null) {
343 + transition = MAC_TABLE;
344 + forTable = SNAT_TABLE;
345 + return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
346 + }
325 // L3FWD table flow rules 347 // L3FWD table flow rules
326 if (selector.getCriterion(Type.TUNNEL_ID) != null 348 if (selector.getCriterion(Type.TUNNEL_ID) != null
327 && selector.getCriterion(Type.IPV4_DST) != null) { 349 && selector.getCriterion(Type.IPV4_DST) != null) {
...@@ -331,15 +353,16 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline ...@@ -331,15 +353,16 @@ public class OpenVSwitchPipeline extends DefaultSingleTablePipeline
331 } 353 }
332 // DNAT table flow rules 354 // DNAT table flow rules
333 if (selector.getCriterion(Type.IPV4_DST) != null) { 355 if (selector.getCriterion(Type.IPV4_DST) != null) {
334 - transition = L3FWD_TABLE; 356 + IPCriterion ipCriterion = (IPCriterion) selector.getCriterion(Type.IPV4_DST);
335 - forTable = DNAT_TABLE; 357 + IpPrefix ipPrefix = ipCriterion.ip();
358 + // specific CLASSIFIER table flow rules for userdata
359 + if (ipPrefix.address().equals(IpAddress.valueOf(USERDATA_IP))) {
360 + forTable = CLASSIFIER_TABLE;
361 + transition = MAC_TABLE;
336 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable); 362 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
337 } 363 }
338 - // SNAT table flow rules 364 + transition = L3FWD_TABLE;
339 - if (selector.getCriterion(Type.TUNNEL_ID) != null 365 + forTable = DNAT_TABLE;
340 - && selector.getCriterion(Type.IPV4_SRC) != null) {
341 - transition = MAC_TABLE;
342 - forTable = SNAT_TABLE;
343 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable); 366 return reassemblyFlowRule(ruleBuilder, tb, transition, forTable);
344 } 367 }
345 return Collections.singletonList(ruleBuilder.build()); 368 return Collections.singletonList(ruleBuilder.build());
......
...@@ -461,6 +461,10 @@ public class DefaultOvsdbClient ...@@ -461,6 +461,10 @@ public class DefaultOvsdbClient
461 return; 461 return;
462 } 462 }
463 463
464 + Map<String, String> options = new HashMap<>();
465 + options.put("disable-in-band", "true");
466 + bridge.setOtherConfig(options);
467 +
464 String bridgeUuid = getBridgeUuid(bridgeName); 468 String bridgeUuid = getBridgeUuid(bridgeName);
465 if (bridgeUuid == null) { 469 if (bridgeUuid == null) {
466 log.debug("Create a new bridge"); 470 log.debug("Create a new bridge");
...@@ -525,16 +529,18 @@ public class DefaultOvsdbClient ...@@ -525,16 +529,18 @@ public class DefaultOvsdbClient
525 return; 529 return;
526 } 530 }
527 531
532 + Map<String, String> options = new HashMap<>();
533 + options.put("disable-in-band", "true");
534 + if (dpid != null) {
535 + options.put("datapath-id", dpid);
536 + }
537 + bridge.setOtherConfig(options);
538 +
528 String bridgeUuid = getBridgeUuid(bridgeName); 539 String bridgeUuid = getBridgeUuid(bridgeName);
529 if (bridgeUuid == null) { 540 if (bridgeUuid == null) {
530 log.debug("Create a new bridge"); 541 log.debug("Create a new bridge");
531 542
532 bridge.setName(bridgeName); 543 bridge.setName(bridgeName);
533 - if (dpid != null) {
534 - Map<String, String> options = new HashMap<>();
535 - options.put("datapath-id", dpid);
536 - bridge.setOtherConfig(options);
537 - }
538 bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", 544 bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid",
539 OvsdbConstant.DATABASENAME, "bridges", 545 OvsdbConstant.DATABASENAME, "bridges",
540 ovsUuid, bridge.getRow()); 546 ovsUuid, bridge.getRow());
...@@ -586,7 +592,10 @@ public class DefaultOvsdbClient ...@@ -586,7 +592,10 @@ public class DefaultOvsdbClient
586 bridge.setProtocols(protocols); 592 bridge.setProtocols(protocols);
587 593
588 Map<String, String> options = new HashMap<>(); 594 Map<String, String> options = new HashMap<>();
595 + options.put("disable-in-band", "true");
596 + if (dpid != null) {
589 options.put("datapath-id", dpid); 597 options.put("datapath-id", dpid);
598 + }
590 bridge.setOtherConfig(options); 599 bridge.setOtherConfig(options);
591 600
592 String bridgeUuid = getBridgeUuid(bridgeName); 601 String bridgeUuid = getBridgeUuid(bridgeName);
......