1 package io.fd.honeycomb.v3po.translate.v3po.util;
3 import com.google.common.base.Preconditions;
4 import com.google.common.primitives.UnsignedBytes;
5 import javax.annotation.Nonnegative;
6 import javax.annotation.Nullable;
9 * Defines vlan tag rewrite config options for VPP
11 * TODO corresponding enum (defined in l2_vtr.h) should be defined in vpe.api
12 * (does vpp's IDL support enum type definition?)
13 * which would allow to generate this class in jvpp
15 public enum TagRewriteOperation {
26 private final static int MAX_INDEX = 3;
27 private final int code;
28 private final byte popTags;
30 TagRewriteOperation(final int popTags) {
31 this.code = this.ordinal();
32 this.popTags = UnsignedBytes.checkedCast(popTags);
35 private static TagRewriteOperation[][] translation = new TagRewriteOperation[][] {
36 {disabled, push_1, push_2},
37 {pop_1, translate_1_to_1, translate_1_to_2},
38 {pop_2, translate_2_to_1, translate_2_to_2}
42 * Returns VPP tag rewrite operation for given number of tags to pop and tags to push.
43 * @param toPop number of tags to pop (0..2)
44 * @param toPush number of tags to push (0..2)
45 * @return vpp tag rewrite operation for given input parameters
47 public static TagRewriteOperation get(@Nonnegative final int toPop, @Nonnegative final int toPush) {
48 Preconditions.checkElementIndex(toPop, MAX_INDEX, "Illegal number of tags to pop");
49 Preconditions.checkElementIndex(toPush, MAX_INDEX, "Illegal number of tags to push");
50 return translation[toPop][toPush];
54 * Returns VPP tag rewrite operation for given operation code.
55 * @param code VPP tag rewrite operation code
56 * @return vpp tag rewrite operation for given input parameter
59 public static TagRewriteOperation get(@Nonnegative final int code) {
60 for (TagRewriteOperation operation : TagRewriteOperation.values()) {
61 if (code == operation.code){
68 public byte getPopTags() {