blob: 2ac846c518eb4a88686889c44a8f7794ff1de1ae [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;
alshabibaebe7752015-04-07 17:45:42 -070027import org.onosproject.net.driver.DriverData;
28import 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/**
48 * Created by ash on 07/04/15.
49 */
50public class OVSCorsaPipeline implements Pipeliner {
51
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
95 @Override
96 public void setData(DriverData data) {
97
98 }
99
100
101 private void pushDefaultRules() {
102 boolean install = true;
103 processTableZero(install);
104 processTableOne(install);
105 processTableTwo(install);
106 processTableFour(install);
107 processTableFive(install);
108 processTableSix(install);
109 processTableNine(install);
110 }
111
112 private void processTableZero(boolean install) {
113 TrafficSelector.Builder selector;
114 TrafficTreatment.Builder treatment;
115
116 // Bcast rule
117 selector = DefaultTrafficSelector.builder();
118 treatment = DefaultTrafficTreatment.builder();
119
120 selector.matchEthDst(MacAddress.BROADCAST);
121 treatment.transition(FlowRule.Type.VLAN_MPLS);
122
123 FlowRule rule = new DefaultFlowRule(deviceId, selector.build(),
124 treatment.build(),
125 CONTROLLER_PRIORITY, appId, 0,
126 true, FlowRule.Type.FIRST);
127
128 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
129
130 ops = install ? ops.add(rule) : ops.remove(rule);
131
132
133
134 //Drop rule
135 selector = DefaultTrafficSelector.builder();
136 treatment = DefaultTrafficTreatment.builder();
137
138 treatment.drop();
139
140 rule = new DefaultFlowRule(deviceId, selector.build(),
141 treatment.build(), DROP_PRIORITY, appId,
142 0, true, FlowRule.Type.FIRST);
143
144 ops = install ? ops.add(rule) : ops.remove(rule);
145
146 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
147 @Override
148 public void onSuccess(FlowRuleOperations ops) {
149 log.info("Provisioned default table for bgp router");
150 }
151
152 @Override
153 public void onError(FlowRuleOperations ops) {
154 log.info("Failed to provision default table for bgp router");
155 }
156 }));
157
158 }
159
160 private void processTableOne(boolean install) {
161 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
162 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
163 .builder();
164 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
165 FlowRule rule;
166
167 selector.matchVlanId(VlanId.ANY);
168 treatment.transition(FlowRule.Type.VLAN);
169
170 rule = new DefaultFlowRule(deviceId, selector.build(),
171 treatment.build(), CONTROLLER_PRIORITY,
172 appId, 0, true, FlowRule.Type.VLAN_MPLS);
173
174 ops = install ? ops.add(rule) : ops.remove(rule);
175
176 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
177 @Override
178 public void onSuccess(FlowRuleOperations ops) {
179 log.info("Provisioned vlan/mpls table for bgp router");
180 }
181
182 @Override
183 public void onError(FlowRuleOperations ops) {
184 log.info(
185 "Failed to provision vlan/mpls table for bgp router");
186 }
187 }));
188
189 }
190
191 private void processTableTwo(boolean install) {
192 TrafficSelector.Builder selector;
193 TrafficTreatment.Builder treatment;
194 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
195 FlowRule rule;
196
197
198
199 //Drop rule
200 selector = DefaultTrafficSelector.builder();
201 treatment = DefaultTrafficTreatment.builder();
202
203 treatment.drop();
204
205 rule = new DefaultFlowRule(deviceId, selector.build(),
206 treatment.build(), DROP_PRIORITY, appId,
207 0, true, FlowRule.Type.VLAN);
208
209 ops = install ? ops.add(rule) : ops.remove(rule);
210
211 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
212 @Override
213 public void onSuccess(FlowRuleOperations ops) {
214 log.info("Provisioned vlan table for bgp router");
215 }
216
217 @Override
218 public void onError(FlowRuleOperations ops) {
219 log.info("Failed to provision vlan table for bgp router");
220 }
221 }));
222 }
223
224 private void processTableFour(boolean install) {
225 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
226 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
227 .builder();
228 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
229 FlowRule rule;
230
231 selector.matchEthType(Ethernet.TYPE_ARP);
232 treatment.punt();
233
234 rule = new DefaultFlowRule(deviceId, selector.build(),
235 treatment.build(), CONTROLLER_PRIORITY,
236 appId, 0, true, FlowRule.Type.ETHER);
237
238 ops = install ? ops.add(rule) : ops.remove(rule);
239
240 selector = DefaultTrafficSelector.builder();
241 treatment = DefaultTrafficTreatment.builder();
242
243 selector.matchEthType(Ethernet.TYPE_IPV4);
244 treatment.transition(FlowRule.Type.COS);
245
246 rule = new DefaultFlowRule(deviceId, selector.build(),
247 treatment.build(), CONTROLLER_PRIORITY,
248 appId, 0, true, FlowRule.Type.ETHER);
249
250 ops = install ? ops.add(rule) : ops.remove(rule);
251
252 //Drop rule
253 selector = DefaultTrafficSelector.builder();
254 treatment = DefaultTrafficTreatment.builder();
255
256 treatment.drop();
257
258 rule = new DefaultFlowRule(deviceId, selector.build(),
259 treatment.build(), DROP_PRIORITY, appId,
260 0, true, FlowRule.Type.ETHER);
261
262 ops = install ? ops.add(rule) : ops.remove(rule);
263
264 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
265 @Override
266 public void onSuccess(FlowRuleOperations ops) {
267 log.info("Provisioned ether table for bgp router");
268 }
269
270 @Override
271 public void onError(FlowRuleOperations ops) {
272 log.info("Failed to provision ether table for bgp router");
273 }
274 }));
275
276 }
277
278 private void processTableFive(boolean install) {
279 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
280 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
281 .builder();
282 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
283 FlowRule rule;
284
285 treatment.transition(FlowRule.Type.IP);
286
287 rule = new DefaultFlowRule(deviceId, selector.build(),
288 treatment.build(), DROP_PRIORITY, appId,
289 0, true, FlowRule.Type.COS);
290
291 ops = install ? ops.add(rule) : ops.remove(rule);
292
293 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
294 @Override
295 public void onSuccess(FlowRuleOperations ops) {
296 log.info("Provisioned cos table for bgp router");
297 }
298
299 @Override
300 public void onError(FlowRuleOperations ops) {
301 log.info("Failed to provision cos table for bgp router");
302 }
303 }));
304
305 }
306
307 private void processTableSix(boolean install) {
308 TrafficSelector.Builder selector;
309 TrafficTreatment.Builder treatment;
310 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
311 FlowRule rule;
312
313 //Drop rule
314 selector = DefaultTrafficSelector.builder();
315 treatment = DefaultTrafficTreatment.builder();
316
317 treatment.drop();
318
319 rule = new DefaultFlowRule(deviceId, selector.build(),
320 treatment.build(), DROP_PRIORITY, appId,
321 0, true, FlowRule.Type.IP);
322
323 ops = install ? ops.add(rule) : ops.remove(rule);
324
325 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
326 @Override
327 public void onSuccess(FlowRuleOperations ops) {
328 log.info("Provisioned FIB table for bgp router");
329 }
330
331 @Override
332 public void onError(FlowRuleOperations ops) {
333 log.info("Failed to provision FIB table for bgp router");
334 }
335 }));
336 }
337
338 private void processTableNine(boolean install) {
339 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
340 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
341 .builder();
342 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
343 FlowRule rule;
344
345 treatment.punt();
346
347 rule = new DefaultFlowRule(deviceId, selector.build(),
348 treatment.build(), CONTROLLER_PRIORITY,
349 appId, 0, true, FlowRule.Type.DEFAULT);
350
351 ops = install ? ops.add(rule) : ops.remove(rule);
352
353 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
354 @Override
355 public void onSuccess(FlowRuleOperations ops) {
356 log.info("Provisioned Local table for bgp router");
357 }
358
359 @Override
360 public void onError(FlowRuleOperations ops) {
361 log.info("Failed to provision Local table for bgp router");
362 }
363 }));
364 }
365
366}