wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 17 | package org.onosproject.pipelines.basic; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 18 | |
| 19 | import com.google.common.collect.ImmutableBiMap; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame^] | 20 | import org.onosproject.net.pi.model.PiTableId; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 21 | |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 22 | import java.util.Optional; |
| 23 | |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 24 | import static org.onosproject.pipelines.basic.BasicConstants.TBL_TABLE0_ID; |
| 25 | import static org.onosproject.pipelines.basic.EcmpConstants.TBL_ECMP_TABLE_ID; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 26 | |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Interpreter implementation for ecmp.p4. |
| 29 | */ |
| 30 | public class EcmpInterpreterImpl extends BasicInterpreterImpl { |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 31 | |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 32 | private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP = new ImmutableBiMap.Builder<Integer, PiTableId>() |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 33 | .put(0, TBL_TABLE0_ID) |
| 34 | .put(1, TBL_ECMP_TABLE_ID) |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 35 | .build(); |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 36 | |
| 37 | @Override |
| 38 | public Optional<Integer> mapPiTableId(PiTableId piTableId) { |
| 39 | return Optional.ofNullable(TABLE_MAP.inverse().get(piTableId)); |
| 40 | } |
| 41 | |
| 42 | @Override |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 43 | public Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId) { |
| 44 | return Optional.ofNullable(TABLE_MAP.get(flowRuleTableId)); |
| 45 | } |
Carmelo Cascone | ca94bcf | 2017-10-27 14:16:59 -0700 | [diff] [blame] | 46 | } |