alshabib

default single table pipeline supports filtering objectives

Change-Id: Idff7720b478e1c36e541d698768dbf8c4cc49d8c
...@@ -21,6 +21,7 @@ import org.onosproject.net.behaviour.Pipeliner; ...@@ -21,6 +21,7 @@ import org.onosproject.net.behaviour.Pipeliner;
21 import org.onosproject.net.behaviour.PipelinerContext; 21 import org.onosproject.net.behaviour.PipelinerContext;
22 import org.onosproject.net.driver.AbstractHandlerBehaviour; 22 import org.onosproject.net.driver.AbstractHandlerBehaviour;
23 import org.onosproject.net.flow.DefaultFlowRule; 23 import org.onosproject.net.flow.DefaultFlowRule;
24 +import org.onosproject.net.flow.DefaultTrafficSelector;
24 import org.onosproject.net.flow.DefaultTrafficTreatment; 25 import org.onosproject.net.flow.DefaultTrafficTreatment;
25 import org.onosproject.net.flow.FlowRule; 26 import org.onosproject.net.flow.FlowRule;
26 import org.onosproject.net.flow.FlowRuleOperations; 27 import org.onosproject.net.flow.FlowRuleOperations;
...@@ -32,6 +33,7 @@ import org.onosproject.net.flow.instructions.Instructions; ...@@ -32,6 +33,7 @@ import org.onosproject.net.flow.instructions.Instructions;
32 import org.onosproject.net.flowobjective.FilteringObjective; 33 import org.onosproject.net.flowobjective.FilteringObjective;
33 import org.onosproject.net.flowobjective.ForwardingObjective; 34 import org.onosproject.net.flowobjective.ForwardingObjective;
34 import org.onosproject.net.flowobjective.NextObjective; 35 import org.onosproject.net.flowobjective.NextObjective;
36 +import org.onosproject.net.flowobjective.Objective;
35 import org.onosproject.net.flowobjective.ObjectiveError; 37 import org.onosproject.net.flowobjective.ObjectiveError;
36 import org.slf4j.Logger; 38 import org.slf4j.Logger;
37 39
...@@ -57,12 +59,53 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme ...@@ -57,12 +59,53 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme
57 } 59 }
58 60
59 @Override 61 @Override
60 - public void filter(FilteringObjective filter) {} 62 + public void filter(FilteringObjective filter) {
63 +
64 + TrafficTreatment.Builder actions;
65 + switch (filter.type()) {
66 + case PERMIT:
67 + actions = (filter.meta() == null) ?
68 + DefaultTrafficTreatment.builder().punt() :
69 + DefaultTrafficTreatment.builder(filter.meta());
70 + break;
71 + case DENY:
72 + actions = (filter.meta() == null) ?
73 + DefaultTrafficTreatment.builder() :
74 + DefaultTrafficTreatment.builder(filter.meta());
75 + actions.drop();
76 + break;
77 + default:
78 + log.warn("Unknown filter type: {}", filter.type());
79 + actions = DefaultTrafficTreatment.builder().drop();
80 + }
81 +
82 + TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
83 +
84 + filter.conditions().stream().forEach(selector::add);
85 +
86 + if (filter.key() != null) {
87 + selector.add(filter.key());
88 + }
89 +
90 + FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
91 + .forDevice(deviceId)
92 + .withSelector(selector.build())
93 + .withTreatment(actions.build())
94 + .fromApp(filter.appId())
95 + .withPriority(filter.priority());
96 +
97 + if (filter.permanent()) {
98 + ruleBuilder.makePermanent();
99 + } else {
100 + ruleBuilder.makeTemporary(filter.timeout());
101 + }
102 +
103 + installObjective(ruleBuilder, filter);
104 +
105 + }
61 106
62 @Override 107 @Override
63 public void forward(ForwardingObjective fwd) { 108 public void forward(ForwardingObjective fwd) {
64 - FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
65 -
66 if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) { 109 if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) {
67 throw new UnsupportedOperationException( 110 throw new UnsupportedOperationException(
68 "Only VERSATILE is supported."); 111 "Only VERSATILE is supported.");
...@@ -92,8 +135,13 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme ...@@ -92,8 +135,13 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme
92 ruleBuilder.makeTemporary(fwd.timeout()); 135 ruleBuilder.makeTemporary(fwd.timeout());
93 } 136 }
94 137
138 + installObjective(ruleBuilder, fwd);
139 +
140 + }
95 141
96 - switch (fwd.op()) { 142 + private void installObjective(FlowRule.Builder ruleBuilder, Objective objective) {
143 + FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
144 + switch (objective.op()) {
97 145
98 case ADD: 146 case ADD:
99 flowBuilder.add(ruleBuilder.build()); 147 flowBuilder.add(ruleBuilder.build());
...@@ -102,28 +150,28 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme ...@@ -102,28 +150,28 @@ public class DefaultSingleTablePipeline extends AbstractHandlerBehaviour impleme
102 flowBuilder.remove(ruleBuilder.build()); 150 flowBuilder.remove(ruleBuilder.build());
103 break; 151 break;
104 default: 152 default:
105 - log.warn("Unknown operation {}", fwd.op()); 153 + log.warn("Unknown operation {}", objective.op());
106 } 154 }
107 155
108 flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() { 156 flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() {
109 @Override 157 @Override
110 public void onSuccess(FlowRuleOperations ops) { 158 public void onSuccess(FlowRuleOperations ops) {
111 - if (fwd.context().isPresent()) { 159 + if (objective.context().isPresent()) {
112 - fwd.context().get().onSuccess(fwd); 160 + objective.context().get().onSuccess(objective);
113 } 161 }
114 } 162 }
115 163
116 @Override 164 @Override
117 public void onError(FlowRuleOperations ops) { 165 public void onError(FlowRuleOperations ops) {
118 - if (fwd.context().isPresent()) { 166 + if (objective.context().isPresent()) {
119 - fwd.context().get().onError(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); 167 + objective.context().get().onError(objective, ObjectiveError.FLOWINSTALLATIONFAILED);
120 } 168 }
121 } 169 }
122 })); 170 }));
123 -
124 } 171 }
125 172
126 @Override 173 @Override
127 - public void next(NextObjective nextObjective) {} 174 + public void next(NextObjective nextObjective) {
175 + }
128 176
129 } 177 }
......