blob: e96fb63879b5c82b2c9516350485243fcefb100f [file] [log] [blame]
Pier Luigif90c6502017-03-16 10:06:21 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Pier Luigif90c6502017-03-16 10:06:21 +01003 *
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 */
16
17package org.onosproject.drivers.corsa;
18
19import org.onosproject.driver.pipeline.DefaultSingleTablePipeline;
20import org.onosproject.net.behaviour.Pipeliner;
21import org.onosproject.net.flow.DefaultTrafficTreatment;
22import org.onosproject.net.flow.TrafficTreatment;
23import org.onosproject.net.flowobjective.DefaultForwardingObjective;
24import org.onosproject.net.flowobjective.ForwardingObjective;
25import org.slf4j.Logger;
26
27import static org.onosproject.net.flowobjective.ForwardingObjective.Flag.VERSATILE;
28import static org.slf4j.LoggerFactory.getLogger;
29
30/**
31 * Abstraction of the Corsa L2 Overlay pipeline.
32 * This pipeline is single table with groups support.
33 */
34public class CorsaL2OverlayPipeline extends DefaultSingleTablePipeline implements Pipeliner {
35
36 private final Logger log = getLogger(getClass());
37
38 @Override
39 public void forward(ForwardingObjective fwd) {
40 // The Corsa devices don't support the clear deferred actions
41 // so for now we have to filter this instruction for the fwd
42 // objectives sent by the Packet Manager before to create the
43 // flow rule
44 if (fwd.flag() == VERSATILE && fwd.treatment().clearedDeferred()) {
45 // First we create a new treatment without the unsupported action
46 TrafficTreatment.Builder noClearTreatment = DefaultTrafficTreatment.builder();
47 fwd.treatment().allInstructions().forEach(noClearTreatment::add);
48 // Then we create a new forwarding objective without the unsupported action
49 ForwardingObjective.Builder noClearFwd = DefaultForwardingObjective.builder(fwd);
50 noClearFwd.withTreatment(noClearTreatment.build());
51 // According to the operation we substitute fwd with the correct objective
52 switch (fwd.op()) {
53 case ADD:
54 fwd = noClearFwd.add(fwd.context().orElse(null));
55 break;
56 case REMOVE:
57 fwd = noClearFwd.remove(fwd.context().orElse(null));
58 break;
59 default:
60 log.warn("Unknown operation {}", fwd.op());
61 return;
62 }
63 }
64 // Finally we send to the DefaultSingleTablePipeline for the real processing
65 super.forward(fwd);
66 }
67
68}