Pier Luigi | f90c650 | 2017-03-16 10:06:21 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Pier Luigi | f90c650 | 2017-03-16 10:06:21 +0100 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.corsa; |
| 18 | |
| 19 | import org.onosproject.driver.pipeline.DefaultSingleTablePipeline; |
| 20 | import org.onosproject.net.behaviour.Pipeliner; |
| 21 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 24 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import static org.onosproject.net.flowobjective.ForwardingObjective.Flag.VERSATILE; |
| 28 | import 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 | */ |
| 34 | public 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 | } |