Flavio Castro
Committed by Gerrit Code Review

Added workaround to install default rules on the IP table

Change-Id: I4944cab643f5d1826294c0605b35a78f7b094aa8
...@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
27 27
28 import org.onlab.packet.Ethernet; 28 import org.onlab.packet.Ethernet;
29 import org.onlab.packet.MacAddress; 29 import org.onlab.packet.MacAddress;
30 +import org.onlab.packet.IpPrefix;
30 import org.onlab.packet.VlanId; 31 import org.onlab.packet.VlanId;
31 import org.onosproject.core.ApplicationId; 32 import org.onosproject.core.ApplicationId;
32 import org.onosproject.net.Port; 33 import org.onosproject.net.Port;
...@@ -372,13 +373,27 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { ...@@ -372,13 +373,27 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline {
372 fail(fwd, ObjectiveError.UNSUPPORTED); 373 fail(fwd, ObjectiveError.UNSUPPORTED);
373 return Collections.emptySet(); 374 return Collections.emptySet();
374 } 375 }
375 - 376 + boolean defaultRule = false;
376 int forTableId = -1; 377 int forTableId = -1;
377 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); 378 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
379 + TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
380 +
381 + /*
382 + * NOTE: The switch does not support matching 0.0.0.0/0.
383 + * Split it into 0.0.0.0/1 and 128.0.0.0/1
384 + */
378 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { 385 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
386 + IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
387 + if (ipv4Dst.prefixLength() > 0) {
379 filteredSelector.matchEthType(Ethernet.TYPE_IPV4) 388 filteredSelector.matchEthType(Ethernet.TYPE_IPV4)
380 - .matchIPDst(((IPCriterion) 389 + .matchIPDst(ipv4Dst);
381 - selector.getCriterion(Criterion.Type.IPV4_DST)).ip()); 390 + } else {
391 + filteredSelector.matchEthType(Ethernet.TYPE_IPV4)
392 + .matchIPDst(IpPrefix.valueOf("0.0.0.0/1"));
393 + complementarySelector.matchEthType(Ethernet.TYPE_IPV4)
394 + .matchIPDst(IpPrefix.valueOf("128.0.0.0/1"));
395 + defaultRule = true;
396 + }
382 forTableId = UNICAST_ROUTING_TABLE; 397 forTableId = UNICAST_ROUTING_TABLE;
383 log.debug("processing IPv4 specific forwarding objective {} -> next:{}" 398 log.debug("processing IPv4 specific forwarding objective {} -> next:{}"
384 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); 399 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
...@@ -436,8 +451,26 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { ...@@ -436,8 +451,26 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline {
436 } else { 451 } else {
437 ruleBuilder.makeTemporary(fwd.timeout()); 452 ruleBuilder.makeTemporary(fwd.timeout());
438 } 453 }
454 + Collection<FlowRule> flowRuleCollection = new ArrayList<>();
455 + flowRuleCollection.add(ruleBuilder.build());
456 + if (defaultRule) {
457 + FlowRule.Builder rule = DefaultFlowRule.builder()
458 + .fromApp(fwd.appId())
459 + .withPriority(fwd.priority())
460 + .forDevice(deviceId)
461 + .withSelector(complementarySelector.build())
462 + .withTreatment(tb.build())
463 + .forTable(forTableId);
464 + if (fwd.permanent()) {
465 + rule.makePermanent();
466 + } else {
467 + rule.makeTemporary(fwd.timeout());
468 + }
469 + flowRuleCollection.add(rule.build());
470 + log.debug("Default rule 0.0.0.0/0 is being installed two rules");
471 + }
439 472
440 - return Collections.singletonList(ruleBuilder.build()); 473 + return flowRuleCollection;
441 } 474 }
442 475
443 @Override 476 @Override
......
...@@ -764,17 +764,29 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline ...@@ -764,17 +764,29 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
764 TrafficSelector selector = fwd.selector(); 764 TrafficSelector selector = fwd.selector();
765 EthTypeCriterion ethType = 765 EthTypeCriterion ethType =
766 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE); 766 (EthTypeCriterion) selector.getCriterion(Criterion.Type.ETH_TYPE);
767 - 767 + boolean defaultRule = false;
768 + boolean popMpls = false;
768 int forTableId; 769 int forTableId;
769 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder(); 770 TrafficSelector.Builder filteredSelector = DefaultTrafficSelector.builder();
770 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder(); 771 TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
771 - boolean popMpls = false; 772 + TrafficSelector.Builder complementarySelector = DefaultTrafficSelector.builder();
772 773
774 + /*
775 + * NOTE: The switch does not support matching 0.0.0.0/0.
776 + * Split it into 0.0.0.0/1 and 128.0.0.0/1
777 + */
773 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) { 778 if (ethType.ethType().toShort() == Ethernet.TYPE_IPV4) {
774 - IpPrefix ipPrefix = ((IPCriterion) 779 + IpPrefix ipv4Dst = ((IPCriterion) selector.getCriterion(Criterion.Type.IPV4_DST)).ip();
775 - selector.getCriterion(Criterion.Type.IPV4_DST)).ip(); 780 + if (ipv4Dst.prefixLength() > 0) {
776 filteredSelector.matchEthType(Ethernet.TYPE_IPV4) 781 filteredSelector.matchEthType(Ethernet.TYPE_IPV4)
777 - .matchIPDst(ipPrefix); 782 + .matchIPDst(ipv4Dst);
783 + } else {
784 + filteredSelector.matchEthType(Ethernet.TYPE_IPV4)
785 + .matchIPDst(IpPrefix.valueOf("0.0.0.0/1"));
786 + complementarySelector.matchEthType(Ethernet.TYPE_IPV4)
787 + .matchIPDst(IpPrefix.valueOf("128.0.0.0/1"));
788 + defaultRule = true;
789 + }
778 forTableId = UNICAST_ROUTING_TABLE; 790 forTableId = UNICAST_ROUTING_TABLE;
779 log.debug("processing IPv4 specific forwarding objective {} -> next:{}" 791 log.debug("processing IPv4 specific forwarding objective {} -> next:{}"
780 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId); 792 + " in dev:{}", fwd.id(), fwd.nextId(), deviceId);
...@@ -863,8 +875,26 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline ...@@ -863,8 +875,26 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline
863 } else { 875 } else {
864 ruleBuilder.makeTemporary(fwd.timeout()); 876 ruleBuilder.makeTemporary(fwd.timeout());
865 } 877 }
878 + Collection<FlowRule> flowRuleCollection = new ArrayList<>();
879 + flowRuleCollection.add(ruleBuilder.build());
880 + if (defaultRule) {
881 + FlowRule.Builder rule = DefaultFlowRule.builder()
882 + .fromApp(fwd.appId())
883 + .withPriority(fwd.priority())
884 + .forDevice(deviceId)
885 + .withSelector(complementarySelector.build())
886 + .withTreatment(tb.build())
887 + .forTable(forTableId);
888 + if (fwd.permanent()) {
889 + rule.makePermanent();
890 + } else {
891 + rule.makeTemporary(fwd.timeout());
892 + }
893 + flowRuleCollection.add(rule.build());
894 + log.debug("Default rule 0.0.0.0/0 is being installed two rules");
895 + }
866 896
867 - return Collections.singletonList(ruleBuilder.build()); 897 + return flowRuleCollection;
868 } 898 }
869 899
870 /** 900 /**
......