blob: d103cdb4747955338941d0a1784ee4a999906c5c [file] [log] [blame]
wu5f6c5b82017-08-04 16:45:19 +08001/*
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 Casconeca94bcf2017-10-27 14:16:59 -070017package org.onosproject.pipelines.basic;
wu5f6c5b82017-08-04 16:45:19 +080018
19import com.google.common.collect.ImmutableBiMap;
Carmelo Cascone87892e22017-11-13 16:01:29 -080020import org.onosproject.net.pi.model.PiTableId;
wu5f6c5b82017-08-04 16:45:19 +080021
wu5f6c5b82017-08-04 16:45:19 +080022import java.util.Optional;
23
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070024import static org.onosproject.pipelines.basic.BasicConstants.TBL_TABLE0_ID;
25import static org.onosproject.pipelines.basic.EcmpConstants.TBL_ECMP_TABLE_ID;
wu5f6c5b82017-08-04 16:45:19 +080026
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070027/**
28 * Interpreter implementation for ecmp.p4.
29 */
30public class EcmpInterpreterImpl extends BasicInterpreterImpl {
wu5f6c5b82017-08-04 16:45:19 +080031
Carmelo Casconea62ac3d2017-08-30 03:19:00 +020032 private static final ImmutableBiMap<Integer, PiTableId> TABLE_MAP = new ImmutableBiMap.Builder<Integer, PiTableId>()
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070033 .put(0, TBL_TABLE0_ID)
34 .put(1, TBL_ECMP_TABLE_ID)
Carmelo Casconea62ac3d2017-08-30 03:19:00 +020035 .build();
wu5f6c5b82017-08-04 16:45:19 +080036
37 @Override
38 public Optional<Integer> mapPiTableId(PiTableId piTableId) {
39 return Optional.ofNullable(TABLE_MAP.inverse().get(piTableId));
40 }
41
42 @Override
wu5f6c5b82017-08-04 16:45:19 +080043 public Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId) {
44 return Optional.ofNullable(TABLE_MAP.get(flowRuleTableId));
45 }
Carmelo Casconeca94bcf2017-10-27 14:16:59 -070046}