blob: 3da786af4472831284f0eca479b123520ebbc842 [file] [log] [blame]
alshabibaebe7752015-04-07 17:45:42 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.driver.pipeline;
17
18import org.onlab.osgi.ServiceDirectory;
19import org.onlab.packet.Ethernet;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
22import org.onosproject.core.ApplicationId;
23import org.onosproject.core.CoreService;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.behaviour.Pipeliner;
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070026import org.onosproject.net.behaviour.PipelinerContext;
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070027import org.onosproject.net.driver.AbstractBehaviour;
alshabibaebe7752015-04-07 17:45:42 -070028import org.onosproject.net.flow.DefaultFlowRule;
29import org.onosproject.net.flow.DefaultTrafficSelector;
30import org.onosproject.net.flow.DefaultTrafficTreatment;
31import org.onosproject.net.flow.FlowRule;
32import org.onosproject.net.flow.FlowRuleOperations;
33import org.onosproject.net.flow.FlowRuleOperationsContext;
34import org.onosproject.net.flow.FlowRuleService;
35import org.onosproject.net.flow.TrafficSelector;
36import org.onosproject.net.flow.TrafficTreatment;
37import org.onosproject.net.flowobjective.FilteringObjective;
38import org.onosproject.net.flowobjective.ForwardingObjective;
39import org.onosproject.net.flowobjective.NextObjective;
40import org.slf4j.Logger;
41
42import java.util.Collection;
43import java.util.concurrent.Future;
44
45import static org.slf4j.LoggerFactory.getLogger;
46
47/**
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070048 * Corsa pipeline handler.
alshabibaebe7752015-04-07 17:45:42 -070049 */
Thomas Vachuska5c2f8132015-04-08 23:09:08 -070050public class OVSCorsaPipeline extends AbstractBehaviour implements Pipeliner {
alshabibaebe7752015-04-07 17:45:42 -070051
52 private static final int CONTROLLER_PRIORITY = 255;
53 private static final int DROP_PRIORITY = 0;
54 private static final int HIGHEST_PRIORITY = 0xffff;
55
56 private final Logger log = getLogger(getClass());
57
58 private ServiceDirectory serviceDirectory;
59 private FlowRuleService flowRuleService;
60 private CoreService coreService;
61 private DeviceId deviceId;
62 private ApplicationId appId;
63
64 @Override
Thomas Vachuskaca88bb72015-04-08 19:38:02 -070065 public void init(DeviceId deviceId, PipelinerContext context) {
66 this.serviceDirectory = context.directory();
alshabibaebe7752015-04-07 17:45:42 -070067 this.deviceId = deviceId;
68
69
70 coreService = serviceDirectory.get(CoreService.class);
71 flowRuleService = serviceDirectory.get(FlowRuleService.class);
72
73 appId = coreService.registerApplication(
74 "org.onosproject.driver.OVSCorsaPipeline");
75
76 pushDefaultRules();
77
78 }
79
80 @Override
81 public Future<Boolean> filter(Collection<FilteringObjective> filteringObjectives) {
82 return null;
83 }
84
85 @Override
86 public Future<Boolean> forward(Collection<ForwardingObjective> forwardObjectives) {
87 return null;
88 }
89
90 @Override
91 public Future<Boolean> next(Collection<NextObjective> nextObjectives) {
92 return null;
93 }
94
alshabibaebe7752015-04-07 17:45:42 -070095 private void pushDefaultRules() {
96 boolean install = true;
97 processTableZero(install);
98 processTableOne(install);
99 processTableTwo(install);
100 processTableFour(install);
101 processTableFive(install);
102 processTableSix(install);
103 processTableNine(install);
104 }
105
106 private void processTableZero(boolean install) {
107 TrafficSelector.Builder selector;
108 TrafficTreatment.Builder treatment;
109
110 // Bcast rule
111 selector = DefaultTrafficSelector.builder();
112 treatment = DefaultTrafficTreatment.builder();
113
114 selector.matchEthDst(MacAddress.BROADCAST);
115 treatment.transition(FlowRule.Type.VLAN_MPLS);
116
117 FlowRule rule = new DefaultFlowRule(deviceId, selector.build(),
118 treatment.build(),
119 CONTROLLER_PRIORITY, appId, 0,
120 true, FlowRule.Type.FIRST);
121
122 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
123
124 ops = install ? ops.add(rule) : ops.remove(rule);
125
126
alshabibaebe7752015-04-07 17:45:42 -0700127 //Drop rule
128 selector = DefaultTrafficSelector.builder();
129 treatment = DefaultTrafficTreatment.builder();
130
131 treatment.drop();
132
133 rule = new DefaultFlowRule(deviceId, selector.build(),
134 treatment.build(), DROP_PRIORITY, appId,
135 0, true, FlowRule.Type.FIRST);
136
137 ops = install ? ops.add(rule) : ops.remove(rule);
138
139 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
140 @Override
141 public void onSuccess(FlowRuleOperations ops) {
142 log.info("Provisioned default table for bgp router");
143 }
144
145 @Override
146 public void onError(FlowRuleOperations ops) {
147 log.info("Failed to provision default table for bgp router");
148 }
149 }));
150
151 }
152
153 private void processTableOne(boolean install) {
154 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
155 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
156 .builder();
157 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
158 FlowRule rule;
159
160 selector.matchVlanId(VlanId.ANY);
161 treatment.transition(FlowRule.Type.VLAN);
162
163 rule = new DefaultFlowRule(deviceId, selector.build(),
164 treatment.build(), CONTROLLER_PRIORITY,
165 appId, 0, true, FlowRule.Type.VLAN_MPLS);
166
167 ops = install ? ops.add(rule) : ops.remove(rule);
168
169 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
170 @Override
171 public void onSuccess(FlowRuleOperations ops) {
172 log.info("Provisioned vlan/mpls table for bgp router");
173 }
174
175 @Override
176 public void onError(FlowRuleOperations ops) {
177 log.info(
178 "Failed to provision vlan/mpls table for bgp router");
179 }
180 }));
181
182 }
183
184 private void processTableTwo(boolean install) {
185 TrafficSelector.Builder selector;
186 TrafficTreatment.Builder treatment;
187 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
188 FlowRule rule;
189
190
alshabibaebe7752015-04-07 17:45:42 -0700191 //Drop rule
192 selector = DefaultTrafficSelector.builder();
193 treatment = DefaultTrafficTreatment.builder();
194
195 treatment.drop();
196
197 rule = new DefaultFlowRule(deviceId, selector.build(),
198 treatment.build(), DROP_PRIORITY, appId,
199 0, true, FlowRule.Type.VLAN);
200
201 ops = install ? ops.add(rule) : ops.remove(rule);
202
203 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
204 @Override
205 public void onSuccess(FlowRuleOperations ops) {
206 log.info("Provisioned vlan table for bgp router");
207 }
208
209 @Override
210 public void onError(FlowRuleOperations ops) {
211 log.info("Failed to provision vlan table for bgp router");
212 }
213 }));
214 }
215
216 private void processTableFour(boolean install) {
217 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
218 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
219 .builder();
220 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
221 FlowRule rule;
222
223 selector.matchEthType(Ethernet.TYPE_ARP);
224 treatment.punt();
225
226 rule = new DefaultFlowRule(deviceId, selector.build(),
227 treatment.build(), CONTROLLER_PRIORITY,
228 appId, 0, true, FlowRule.Type.ETHER);
229
230 ops = install ? ops.add(rule) : ops.remove(rule);
231
232 selector = DefaultTrafficSelector.builder();
233 treatment = DefaultTrafficTreatment.builder();
234
235 selector.matchEthType(Ethernet.TYPE_IPV4);
236 treatment.transition(FlowRule.Type.COS);
237
238 rule = new DefaultFlowRule(deviceId, selector.build(),
239 treatment.build(), CONTROLLER_PRIORITY,
240 appId, 0, true, FlowRule.Type.ETHER);
241
242 ops = install ? ops.add(rule) : ops.remove(rule);
243
244 //Drop rule
245 selector = DefaultTrafficSelector.builder();
246 treatment = DefaultTrafficTreatment.builder();
247
248 treatment.drop();
249
250 rule = new DefaultFlowRule(deviceId, selector.build(),
251 treatment.build(), DROP_PRIORITY, appId,
252 0, true, FlowRule.Type.ETHER);
253
254 ops = install ? ops.add(rule) : ops.remove(rule);
255
256 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
257 @Override
258 public void onSuccess(FlowRuleOperations ops) {
259 log.info("Provisioned ether table for bgp router");
260 }
261
262 @Override
263 public void onError(FlowRuleOperations ops) {
264 log.info("Failed to provision ether table for bgp router");
265 }
266 }));
267
268 }
269
270 private void processTableFive(boolean install) {
271 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
272 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
273 .builder();
274 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
275 FlowRule rule;
276
277 treatment.transition(FlowRule.Type.IP);
278
279 rule = new DefaultFlowRule(deviceId, selector.build(),
280 treatment.build(), DROP_PRIORITY, appId,
281 0, true, FlowRule.Type.COS);
282
283 ops = install ? ops.add(rule) : ops.remove(rule);
284
285 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
286 @Override
287 public void onSuccess(FlowRuleOperations ops) {
288 log.info("Provisioned cos table for bgp router");
289 }
290
291 @Override
292 public void onError(FlowRuleOperations ops) {
293 log.info("Failed to provision cos table for bgp router");
294 }
295 }));
296
297 }
298
299 private void processTableSix(boolean install) {
300 TrafficSelector.Builder selector;
301 TrafficTreatment.Builder treatment;
302 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
303 FlowRule rule;
304
305 //Drop rule
306 selector = DefaultTrafficSelector.builder();
307 treatment = DefaultTrafficTreatment.builder();
308
309 treatment.drop();
310
311 rule = new DefaultFlowRule(deviceId, selector.build(),
312 treatment.build(), DROP_PRIORITY, appId,
313 0, true, FlowRule.Type.IP);
314
315 ops = install ? ops.add(rule) : ops.remove(rule);
316
317 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
318 @Override
319 public void onSuccess(FlowRuleOperations ops) {
320 log.info("Provisioned FIB table for bgp router");
321 }
322
323 @Override
324 public void onError(FlowRuleOperations ops) {
325 log.info("Failed to provision FIB table for bgp router");
326 }
327 }));
328 }
329
330 private void processTableNine(boolean install) {
331 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
332 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
333 .builder();
334 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
335 FlowRule rule;
336
337 treatment.punt();
338
339 rule = new DefaultFlowRule(deviceId, selector.build(),
340 treatment.build(), CONTROLLER_PRIORITY,
341 appId, 0, true, FlowRule.Type.DEFAULT);
342
343 ops = install ? ops.add(rule) : ops.remove(rule);
344
345 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
346 @Override
347 public void onSuccess(FlowRuleOperations ops) {
348 log.info("Provisioned Local table for bgp router");
349 }
350
351 @Override
352 public void onError(FlowRuleOperations ops) {
353 log.info("Failed to provision Local table for bgp router");
354 }
355 }));
356 }
357
358}