blob: d662231b764dace8c444172854f56abdd550fbe5 [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
17package org.onosproject.pi.demo.app.ecmp;
18
19import com.google.common.collect.ImmutableBiMap;
Carmelo Casconea62ac3d2017-08-30 03:19:00 +020020import org.onosproject.drivers.p4runtime.DefaultP4Interpreter;
wu5f6c5b82017-08-04 16:45:19 +080021import org.onosproject.net.pi.runtime.PiTableId;
22
wu5f6c5b82017-08-04 16:45:19 +080023import java.util.Optional;
24
wu5f6c5b82017-08-04 16:45:19 +080025/**
26 * Implementation of a PiPipeline interpreter for the ecmp.json configuration.
27 */
Carmelo Casconea62ac3d2017-08-30 03:19:00 +020028public class EcmpInterpreter extends DefaultP4Interpreter {
wu5f6c5b82017-08-04 16:45:19 +080029
Carmelo Cascone3929cc82017-09-06 13:34:25 +020030 protected static final String ECMP_METADATA_HEADER_NAME = "ecmp_metadata";
wu5f6c5b82017-08-04 16:45:19 +080031 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";
wu5f6c5b82017-08-04 16:45:19 +080034 protected static final String ECMP_GROUP_TABLE = "ecmp_group_table";
wu5f6c5b82017-08-04 16:45:19 +080035
Carmelo Casconea62ac3d2017-08-30 03:19:00 +020036 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();
wu5f6c5b82017-08-04 16:45:19 +080040
41 @Override
42 public Optional<Integer> mapPiTableId(PiTableId piTableId) {
43 return Optional.ofNullable(TABLE_MAP.inverse().get(piTableId));
44 }
45
46 @Override
wu5f6c5b82017-08-04 16:45:19 +080047 public Optional<PiTableId> mapFlowRuleTableId(int flowRuleTableId) {
48 return Optional.ofNullable(TABLE_MAP.get(flowRuleTableId));
49 }
wu5f6c5b82017-08-04 16:45:19 +080050}