blob: 84dd5db7497e377c40765ad8c6c63d083e390745 [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;
26import org.onosproject.net.driver.DriverData;
27import org.onosproject.net.flow.DefaultFlowRule;
28import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.DefaultTrafficTreatment;
30import org.onosproject.net.flow.FlowRule;
31import org.onosproject.net.flow.FlowRuleOperations;
32import org.onosproject.net.flow.FlowRuleOperationsContext;
33import org.onosproject.net.flow.FlowRuleService;
34import org.onosproject.net.flow.TrafficSelector;
35import org.onosproject.net.flow.TrafficTreatment;
36import org.onosproject.net.flowobjective.FilteringObjective;
37import org.onosproject.net.flowobjective.ForwardingObjective;
38import org.onosproject.net.flowobjective.NextObjective;
39import org.slf4j.Logger;
40
41import java.util.Collection;
42import java.util.concurrent.Future;
43
44import static org.slf4j.LoggerFactory.getLogger;
45
46/**
47 * Created by ash on 07/04/15.
48 */
49public class OVSCorsaPipeline implements Pipeliner {
50
51 private static final int CONTROLLER_PRIORITY = 255;
52 private static final int DROP_PRIORITY = 0;
53 private static final int HIGHEST_PRIORITY = 0xffff;
54
55 private final Logger log = getLogger(getClass());
56
57 private ServiceDirectory serviceDirectory;
58 private FlowRuleService flowRuleService;
59 private CoreService coreService;
60 private DeviceId deviceId;
61 private ApplicationId appId;
62
63 @Override
64 public void init(DeviceId deviceId, ServiceDirectory serviceDirectory) {
65 this.serviceDirectory = serviceDirectory;
66 this.deviceId = deviceId;
67
68
69 coreService = serviceDirectory.get(CoreService.class);
70 flowRuleService = serviceDirectory.get(FlowRuleService.class);
71
72 appId = coreService.registerApplication(
73 "org.onosproject.driver.OVSCorsaPipeline");
74
75 pushDefaultRules();
76
77 }
78
79 @Override
80 public Future<Boolean> filter(Collection<FilteringObjective> filteringObjectives) {
81 return null;
82 }
83
84 @Override
85 public Future<Boolean> forward(Collection<ForwardingObjective> forwardObjectives) {
86 return null;
87 }
88
89 @Override
90 public Future<Boolean> next(Collection<NextObjective> nextObjectives) {
91 return null;
92 }
93
94 @Override
95 public void setData(DriverData data) {
96
97 }
98
99
100 private void pushDefaultRules() {
101 boolean install = true;
102 processTableZero(install);
103 processTableOne(install);
104 processTableTwo(install);
105 processTableFour(install);
106 processTableFive(install);
107 processTableSix(install);
108 processTableNine(install);
109 }
110
111 private void processTableZero(boolean install) {
112 TrafficSelector.Builder selector;
113 TrafficTreatment.Builder treatment;
114
115 // Bcast rule
116 selector = DefaultTrafficSelector.builder();
117 treatment = DefaultTrafficTreatment.builder();
118
119 selector.matchEthDst(MacAddress.BROADCAST);
120 treatment.transition(FlowRule.Type.VLAN_MPLS);
121
122 FlowRule rule = new DefaultFlowRule(deviceId, selector.build(),
123 treatment.build(),
124 CONTROLLER_PRIORITY, appId, 0,
125 true, FlowRule.Type.FIRST);
126
127 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
128
129 ops = install ? ops.add(rule) : ops.remove(rule);
130
131
132
133 //Drop rule
134 selector = DefaultTrafficSelector.builder();
135 treatment = DefaultTrafficTreatment.builder();
136
137 treatment.drop();
138
139 rule = new DefaultFlowRule(deviceId, selector.build(),
140 treatment.build(), DROP_PRIORITY, appId,
141 0, true, FlowRule.Type.FIRST);
142
143 ops = install ? ops.add(rule) : ops.remove(rule);
144
145 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
146 @Override
147 public void onSuccess(FlowRuleOperations ops) {
148 log.info("Provisioned default table for bgp router");
149 }
150
151 @Override
152 public void onError(FlowRuleOperations ops) {
153 log.info("Failed to provision default table for bgp router");
154 }
155 }));
156
157 }
158
159 private void processTableOne(boolean install) {
160 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
161 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
162 .builder();
163 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
164 FlowRule rule;
165
166 selector.matchVlanId(VlanId.ANY);
167 treatment.transition(FlowRule.Type.VLAN);
168
169 rule = new DefaultFlowRule(deviceId, selector.build(),
170 treatment.build(), CONTROLLER_PRIORITY,
171 appId, 0, true, FlowRule.Type.VLAN_MPLS);
172
173 ops = install ? ops.add(rule) : ops.remove(rule);
174
175 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
176 @Override
177 public void onSuccess(FlowRuleOperations ops) {
178 log.info("Provisioned vlan/mpls table for bgp router");
179 }
180
181 @Override
182 public void onError(FlowRuleOperations ops) {
183 log.info(
184 "Failed to provision vlan/mpls table for bgp router");
185 }
186 }));
187
188 }
189
190 private void processTableTwo(boolean install) {
191 TrafficSelector.Builder selector;
192 TrafficTreatment.Builder treatment;
193 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
194 FlowRule rule;
195
196
197
198 //Drop rule
199 selector = DefaultTrafficSelector.builder();
200 treatment = DefaultTrafficTreatment.builder();
201
202 treatment.drop();
203
204 rule = new DefaultFlowRule(deviceId, selector.build(),
205 treatment.build(), DROP_PRIORITY, appId,
206 0, true, FlowRule.Type.VLAN);
207
208 ops = install ? ops.add(rule) : ops.remove(rule);
209
210 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
211 @Override
212 public void onSuccess(FlowRuleOperations ops) {
213 log.info("Provisioned vlan table for bgp router");
214 }
215
216 @Override
217 public void onError(FlowRuleOperations ops) {
218 log.info("Failed to provision vlan table for bgp router");
219 }
220 }));
221 }
222
223 private void processTableFour(boolean install) {
224 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
225 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
226 .builder();
227 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
228 FlowRule rule;
229
230 selector.matchEthType(Ethernet.TYPE_ARP);
231 treatment.punt();
232
233 rule = new DefaultFlowRule(deviceId, selector.build(),
234 treatment.build(), CONTROLLER_PRIORITY,
235 appId, 0, true, FlowRule.Type.ETHER);
236
237 ops = install ? ops.add(rule) : ops.remove(rule);
238
239 selector = DefaultTrafficSelector.builder();
240 treatment = DefaultTrafficTreatment.builder();
241
242 selector.matchEthType(Ethernet.TYPE_IPV4);
243 treatment.transition(FlowRule.Type.COS);
244
245 rule = new DefaultFlowRule(deviceId, selector.build(),
246 treatment.build(), CONTROLLER_PRIORITY,
247 appId, 0, true, FlowRule.Type.ETHER);
248
249 ops = install ? ops.add(rule) : ops.remove(rule);
250
251 //Drop rule
252 selector = DefaultTrafficSelector.builder();
253 treatment = DefaultTrafficTreatment.builder();
254
255 treatment.drop();
256
257 rule = new DefaultFlowRule(deviceId, selector.build(),
258 treatment.build(), DROP_PRIORITY, appId,
259 0, true, FlowRule.Type.ETHER);
260
261 ops = install ? ops.add(rule) : ops.remove(rule);
262
263 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
264 @Override
265 public void onSuccess(FlowRuleOperations ops) {
266 log.info("Provisioned ether table for bgp router");
267 }
268
269 @Override
270 public void onError(FlowRuleOperations ops) {
271 log.info("Failed to provision ether table for bgp router");
272 }
273 }));
274
275 }
276
277 private void processTableFive(boolean install) {
278 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
279 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
280 .builder();
281 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
282 FlowRule rule;
283
284 treatment.transition(FlowRule.Type.IP);
285
286 rule = new DefaultFlowRule(deviceId, selector.build(),
287 treatment.build(), DROP_PRIORITY, appId,
288 0, true, FlowRule.Type.COS);
289
290 ops = install ? ops.add(rule) : ops.remove(rule);
291
292 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
293 @Override
294 public void onSuccess(FlowRuleOperations ops) {
295 log.info("Provisioned cos table for bgp router");
296 }
297
298 @Override
299 public void onError(FlowRuleOperations ops) {
300 log.info("Failed to provision cos table for bgp router");
301 }
302 }));
303
304 }
305
306 private void processTableSix(boolean install) {
307 TrafficSelector.Builder selector;
308 TrafficTreatment.Builder treatment;
309 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
310 FlowRule rule;
311
312 //Drop rule
313 selector = DefaultTrafficSelector.builder();
314 treatment = DefaultTrafficTreatment.builder();
315
316 treatment.drop();
317
318 rule = new DefaultFlowRule(deviceId, selector.build(),
319 treatment.build(), DROP_PRIORITY, appId,
320 0, true, FlowRule.Type.IP);
321
322 ops = install ? ops.add(rule) : ops.remove(rule);
323
324 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
325 @Override
326 public void onSuccess(FlowRuleOperations ops) {
327 log.info("Provisioned FIB table for bgp router");
328 }
329
330 @Override
331 public void onError(FlowRuleOperations ops) {
332 log.info("Failed to provision FIB table for bgp router");
333 }
334 }));
335 }
336
337 private void processTableNine(boolean install) {
338 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
339 TrafficTreatment.Builder treatment = DefaultTrafficTreatment
340 .builder();
341 FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
342 FlowRule rule;
343
344 treatment.punt();
345
346 rule = new DefaultFlowRule(deviceId, selector.build(),
347 treatment.build(), CONTROLLER_PRIORITY,
348 appId, 0, true, FlowRule.Type.DEFAULT);
349
350 ops = install ? ops.add(rule) : ops.remove(rule);
351
352 flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {
353 @Override
354 public void onSuccess(FlowRuleOperations ops) {
355 log.info("Provisioned Local table for bgp router");
356 }
357
358 @Override
359 public void onError(FlowRuleOperations ops) {
360 log.info("Failed to provision Local table for bgp router");
361 }
362 }));
363 }
364
365}