2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package io.fd.honeycomb.v3po.translate.v3po.util;
18 import com.google.common.base.Preconditions;
19 import com.google.common.primitives.UnsignedBytes;
20 import javax.annotation.Nonnegative;
21 import javax.annotation.Nullable;
24 * Defines vlan tag rewrite config options for VPP
26 * TODO corresponding enum (defined in l2_vtr.h) should be defined in vpe.api
27 * (does vpp's IDL support enum type definition?)
28 * which would allow to generate this class in jvpp
30 public enum TagRewriteOperation {
41 private final static int MAX_INDEX = 3;
42 private final int code;
43 private final byte popTags;
45 TagRewriteOperation(final int popTags) {
46 this.code = this.ordinal();
47 this.popTags = UnsignedBytes.checkedCast(popTags);
50 private static TagRewriteOperation[][] translation = new TagRewriteOperation[][] {
51 {disabled, push_1, push_2},
52 {pop_1, translate_1_to_1, translate_1_to_2},
53 {pop_2, translate_2_to_1, translate_2_to_2}
57 * Returns VPP tag rewrite operation for given number of tags to pop and tags to push.
58 * @param toPop number of tags to pop (0..2)
59 * @param toPush number of tags to push (0..2)
60 * @return vpp tag rewrite operation for given input parameters
62 public static TagRewriteOperation get(@Nonnegative final int toPop, @Nonnegative final int toPush) {
63 Preconditions.checkElementIndex(toPop, MAX_INDEX, "Illegal number of tags to pop");
64 Preconditions.checkElementIndex(toPush, MAX_INDEX, "Illegal number of tags to push");
65 return translation[toPop][toPush];
69 * Returns VPP tag rewrite operation for given operation code.
70 * @param code VPP tag rewrite operation code
71 * @return vpp tag rewrite operation for given input parameter
74 public static TagRewriteOperation get(@Nonnegative final int code) {
75 for (TagRewriteOperation operation : TagRewriteOperation.values()) {
76 if (code == operation.code){
83 public byte getPopTags() {