Jonathan Hart

Intent treatments need to be passed down to the flows

Change-Id: I4569536cb62188f711ce005af1c3501dc31f7e74
...@@ -44,6 +44,16 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -44,6 +44,16 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
44 return new Builder(); 44 return new Builder();
45 } 45 }
46 46
47 + /**
48 + * Returns a new traffic treatment builder primed to produce entities
49 + * patterned after the supplied treatment.
50 + *
51 + * @return traffic treatment builder
52 + */
53 + public static TrafficTreatment.Builder builder(TrafficTreatment treatment) {
54 + return new Builder(treatment);
55 + }
56 +
47 //FIXME: Order of instructions may affect hashcode 57 //FIXME: Order of instructions may affect hashcode
48 @Override 58 @Override
49 public int hashCode() { 59 public int hashCode() {
...@@ -90,6 +100,13 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { ...@@ -90,6 +100,13 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
90 private Builder() { 100 private Builder() {
91 } 101 }
92 102
103 + // Creates a new builder based off an existing treatment
104 + private Builder(TrafficTreatment treatment) {
105 + for (Instruction instruction : treatment.instructions()) {
106 + add(instruction);
107 + }
108 + }
109 +
93 @Override 110 @Override
94 public Builder add(Instruction instruction) { 111 public Builder add(Instruction instruction) {
95 if (drop) { 112 if (drop) {
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 -import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
4 import static org.slf4j.LoggerFactory.getLogger; 3 import static org.slf4j.LoggerFactory.getLogger;
5 4
6 import java.util.List; 5 import java.util.List;
...@@ -17,6 +16,7 @@ import org.onlab.onos.net.Link; ...@@ -17,6 +16,7 @@ import org.onlab.onos.net.Link;
17 import org.onlab.onos.net.PortNumber; 16 import org.onlab.onos.net.PortNumber;
18 import org.onlab.onos.net.flow.DefaultFlowRule; 17 import org.onlab.onos.net.flow.DefaultFlowRule;
19 import org.onlab.onos.net.flow.DefaultTrafficSelector; 18 import org.onlab.onos.net.flow.DefaultTrafficSelector;
19 +import org.onlab.onos.net.flow.DefaultTrafficTreatment;
20 import org.onlab.onos.net.flow.FlowRule; 20 import org.onlab.onos.net.flow.FlowRule;
21 import org.onlab.onos.net.flow.FlowRuleBatchEntry; 21 import org.onlab.onos.net.flow.FlowRuleBatchEntry;
22 import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation; 22 import org.onlab.onos.net.flow.FlowRuleBatchEntry.FlowRuleOperation;
...@@ -61,18 +61,16 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec ...@@ -61,18 +61,16 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
61 61
62 @Override 62 @Override
63 public List<FlowRuleBatchOperation> install(LinkCollectionIntent intent) { 63 public List<FlowRuleBatchOperation> install(LinkCollectionIntent intent) {
64 - TrafficSelector.Builder builder =
65 - DefaultTrafficSelector.builder(intent.selector());
66 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 64 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
67 for (Link link : intent.links()) { 65 for (Link link : intent.links()) {
68 rules.add(createBatchEntry(FlowRuleOperation.ADD, 66 rules.add(createBatchEntry(FlowRuleOperation.ADD,
69 - builder.build(), 67 + intent,
70 link.src().deviceId(), 68 link.src().deviceId(),
71 link.src().port())); 69 link.src().port()));
72 } 70 }
73 71
74 rules.add(createBatchEntry(FlowRuleOperation.ADD, 72 rules.add(createBatchEntry(FlowRuleOperation.ADD,
75 - builder.build(), 73 + intent,
76 intent.egressPoint().deviceId(), 74 intent.egressPoint().deviceId(),
77 intent.egressPoint().port())); 75 intent.egressPoint().port()));
78 76
...@@ -81,19 +79,17 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec ...@@ -81,19 +79,17 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
81 79
82 @Override 80 @Override
83 public List<FlowRuleBatchOperation> uninstall(LinkCollectionIntent intent) { 81 public List<FlowRuleBatchOperation> uninstall(LinkCollectionIntent intent) {
84 - TrafficSelector.Builder builder =
85 - DefaultTrafficSelector.builder(intent.selector());
86 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 82 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
87 83
88 for (Link link : intent.links()) { 84 for (Link link : intent.links()) {
89 rules.add(createBatchEntry(FlowRuleOperation.REMOVE, 85 rules.add(createBatchEntry(FlowRuleOperation.REMOVE,
90 - builder.build(), 86 + intent,
91 link.src().deviceId(), 87 link.src().deviceId(),
92 link.src().port())); 88 link.src().port()));
93 } 89 }
94 90
95 rules.add(createBatchEntry(FlowRuleOperation.REMOVE, 91 rules.add(createBatchEntry(FlowRuleOperation.REMOVE,
96 - builder.build(), 92 + intent,
97 intent.egressPoint().deviceId(), 93 intent.egressPoint().deviceId(),
98 intent.egressPoint().port())); 94 intent.egressPoint().port()));
99 95
...@@ -104,17 +100,23 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec ...@@ -104,17 +100,23 @@ public class LinkCollectionIntentInstaller implements IntentInstaller<LinkCollec
104 * Creates a FlowRuleBatchEntry based on the provided parameters. 100 * Creates a FlowRuleBatchEntry based on the provided parameters.
105 * 101 *
106 * @param operation the FlowRuleOperation to use 102 * @param operation the FlowRuleOperation to use
107 - * @param selector the traffic selector 103 + * @param intent the link collection intent
108 * @param deviceId the device ID for the flow rule 104 * @param deviceId the device ID for the flow rule
109 * @param outPort the output port of the flow rule 105 * @param outPort the output port of the flow rule
110 * @return the new flow rule batch entry 106 * @return the new flow rule batch entry
111 */ 107 */
112 private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation, 108 private FlowRuleBatchEntry createBatchEntry(FlowRuleOperation operation,
113 - TrafficSelector selector, 109 + LinkCollectionIntent intent,
114 DeviceId deviceId, 110 DeviceId deviceId,
115 PortNumber outPort) { 111 PortNumber outPort) {
116 112
117 - TrafficTreatment treatment = builder().setOutput(outPort).build(); 113 + TrafficTreatment.Builder treatmentBuilder =
114 + DefaultTrafficTreatment.builder(intent.treatment());
115 +
116 + TrafficTreatment treatment = treatmentBuilder.setOutput(outPort).build();
117 +
118 + TrafficSelector selector = DefaultTrafficSelector.builder(intent.selector())
119 + .build();
118 120
119 FlowRule rule = new DefaultFlowRule(deviceId, 121 FlowRule rule = new DefaultFlowRule(deviceId,
120 selector, treatment, 123, appId, 0, true); 122 selector, treatment, 123, appId, 0, true);
......