summaryrefslogtreecommitdiffstats
path: root/v3po/vpp-translate-utils/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/vpp-translate-utils/src/main/java/io')
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/SubInterfaceUtils.java28
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TagRewriteOperation.java71
-rw-r--r--v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java2
3 files changed, 99 insertions, 2 deletions
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/SubInterfaceUtils.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/SubInterfaceUtils.java
new file mode 100644
index 000000000..1df82af73
--- /dev/null
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/SubInterfaceUtils.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.v3po.util;
+
+public final class SubInterfaceUtils {
+
+ private SubInterfaceUtils() {
+ throw new UnsupportedOperationException("Utility class cannot be instantiated.");
+ }
+
+ public static String getSubInterfaceName(final String superIfName, final int subIfaceId) {
+ return String.format("%s.%d", superIfName, subIfaceId);
+ }
+}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TagRewriteOperation.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TagRewriteOperation.java
new file mode 100644
index 000000000..8609207b6
--- /dev/null
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TagRewriteOperation.java
@@ -0,0 +1,71 @@
+package io.fd.honeycomb.v3po.translate.v3po.util;
+
+import com.google.common.base.Preconditions;
+import com.google.common.primitives.UnsignedBytes;
+import javax.annotation.Nonnegative;
+import javax.annotation.Nullable;
+
+/**
+ * Defines vlan tag rewrite config options for VPP
+ *
+ * TODO corresponding enum (defined in l2_vtr.h) should be defined in vpe.api
+ * (does vpp's IDL support enum type definition?)
+ * which would allow to generate this class in jvpp
+ */
+public enum TagRewriteOperation {
+ disabled(0),
+ push_1(0),
+ push_2(0),
+ pop_1(1),
+ pop_2(2),
+ translate_1_to_1(1),
+ translate_1_to_2(1),
+ translate_2_to_1(2),
+ translate_2_to_2(2);
+
+ private final static int MAX_INDEX = 3;
+ private final int code;
+ private final byte popTags;
+
+ TagRewriteOperation(final int popTags) {
+ this.code = this.ordinal();
+ this.popTags = UnsignedBytes.checkedCast(popTags);
+ }
+
+ private static TagRewriteOperation[][] translation = new TagRewriteOperation[][] {
+ {disabled, push_1, push_2},
+ {pop_1, translate_1_to_1, translate_1_to_2},
+ {pop_2, translate_2_to_1, translate_2_to_2}
+ };
+
+ /**
+ * Returns VPP tag rewrite operation for given number of tags to pop and tags to push.
+ * @param toPop number of tags to pop (0..2)
+ * @param toPush number of tags to push (0..2)
+ * @return vpp tag rewrite operation for given input parameters
+ */
+ public static TagRewriteOperation get(@Nonnegative final int toPop, @Nonnegative final int toPush) {
+ Preconditions.checkElementIndex(toPop, MAX_INDEX, "Illegal number of tags to pop");
+ Preconditions.checkElementIndex(toPush, MAX_INDEX, "Illegal number of tags to push");
+ return translation[toPop][toPush];
+ }
+
+ /**
+ * Returns VPP tag rewrite operation for given operation code.
+ * @param code VPP tag rewrite operation code
+ * @return vpp tag rewrite operation for given input parameter
+ */
+ @Nullable
+ public static TagRewriteOperation get(@Nonnegative final int code) {
+ for (TagRewriteOperation operation : TagRewriteOperation.values()) {
+ if (code == operation.code){
+ return operation;
+ }
+ }
+ return null;
+ }
+
+ public byte getPopTags() {
+ return popTags;
+ }
+}
diff --git a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
index b13dbb4fe..3c1ef7f28 100644
--- a/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
+++ b/v3po/vpp-translate-utils/src/main/java/io/fd/honeycomb/v3po/translate/v3po/util/TranslateUtils.java
@@ -34,8 +34,6 @@ import org.openvpp.jvpp.dto.JVppReply;
public final class TranslateUtils {
- // TODO move to vpp-translate-utils
-
public static final Splitter COLON_SPLITTER = Splitter.on(':');
private TranslateUtils() {}