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 | |
| 17 | package org.onosproject.pi.demo.app.ecmp; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableBiMap; |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 20 | import org.onosproject.drivers.p4runtime.DefaultP4Interpreter; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 21 | import org.onosproject.net.pi.runtime.PiTableId; |
| 22 | |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 23 | import java.util.Optional; |
| 24 | |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 25 | /** |
| 26 | * Implementation of a PiPipeline interpreter for the ecmp.json configuration. |
| 27 | */ |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 28 | public class EcmpInterpreter extends DefaultP4Interpreter { |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 29 | |
Carmelo Cascone | 3929cc8 | 2017-09-06 13:34:25 +0200 | [diff] [blame] | 30 | protected static final String ECMP_METADATA_HEADER_NAME = "ecmp_metadata"; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 31 | protected static final String ECMP_GROUP_ACTION_NAME = "ecmp_group"; |
| 32 | protected static final String GROUP_ID = "group_id"; |
| 33 | protected static final String SELECTOR = "selector"; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 34 | protected static final String ECMP_GROUP_TABLE = "ecmp_group_table"; |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 35 | |
Carmelo Cascone | a62ac3d | 2017-08-30 03:19:00 +0200 | [diff] [blame] | 36 | private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP = new ImmutableBiMap.Builder<Integer, PiTableId>() |
| 37 | .put(0, PiTableId.of(TABLE0)) |
| 38 | .put(1, PiTableId.of(ECMP_GROUP_TABLE)) |
| 39 | .build(); |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 40 | |
| 41 | @Override |
| 42 | public Optional<Integer> mapPiTableId(PiTableId piTableId) { |
| 43 | return Optional.ofNullable(TABLE_MAP.inverse().get(piTableId)); |
| 44 | } |
| 45 | |
| 46 | @Override |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 47 | public Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId) { |
| 48 | return Optional.ofNullable(TABLE_MAP.get(flowRuleTableId)); |
| 49 | } |
wu | 5f6c5b8 | 2017-08-04 16:45:19 +0800 | [diff] [blame] | 50 | } |