summaryrefslogtreecommitdiffstats
path: root/src/vnet/tunnel
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2019-12-29 23:55:18 +0000
committerDamjan Marion <dmarion@me.com>2020-01-27 20:40:30 +0000
commit59ff918ea5b86112ffc89054aa38107703354585 (patch)
tree0e6dc887ead19b7be828954a08b1e15da81ddb58 /src/vnet/tunnel
parent3b37125bdb0251181f90a429a4532b339711cf89 (diff)
tunnel: Common types for IP tunnels
Type: refactor Signed-off-by: Neale Ranns <nranns@cisco.com> Change-Id: I18dcdb7af3e327f6cacdbcb1e52b89f13d6ba6e2
Diffstat (limited to 'src/vnet/tunnel')
-rw-r--r--src/vnet/tunnel/tunnel.c58
-rw-r--r--src/vnet/tunnel/tunnel.h66
-rw-r--r--src/vnet/tunnel/tunnel_types.api50
-rw-r--r--src/vnet/tunnel/tunnel_types_api.c87
-rw-r--r--src/vnet/tunnel/tunnel_types_api.h47
5 files changed, 308 insertions, 0 deletions
diff --git a/src/vnet/tunnel/tunnel.c b/src/vnet/tunnel/tunnel.c
new file mode 100644
index 00000000000..83b1046b526
--- /dev/null
+++ b/src/vnet/tunnel/tunnel.c
@@ -0,0 +1,58 @@
+/*
+ * tunnel.h: shared definitions for tunnels.
+ *
+ * Copyright (c) 2019 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.
+ */
+
+#include <vnet/tunnel/tunnel.h>
+
+u8 *
+format_tunnel_mode (u8 * s, va_list * args)
+{
+ tunnel_mode_t mode = va_arg (*args, int);
+
+ switch (mode)
+ {
+#define _(n, v) case TUNNEL_MODE_##n: \
+ s = format (s, "%s", v); \
+ break;
+ foreach_tunnel_mode
+#undef _
+ }
+
+ return (s);
+}
+
+u8 *
+format_tunnel_encap_decap_flags (u8 * s, va_list * args)
+{
+ tunnel_encap_decap_flags_t f = va_arg (*args, int);
+
+ if (f == TUNNEL_ENCAP_DECAP_FLAG_NONE)
+ return (format (s, "none"));
+
+#define _(a,b,c) if (f & TUNNEL_ENCAP_DECAP_FLAG_##a) s = format(s, "%s ", b);
+ forech_tunnel_encap_decap_flag
+#undef _
+ return (s);
+}
+
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/tunnel/tunnel.h b/src/vnet/tunnel/tunnel.h
new file mode 100644
index 00000000000..e3390f5a165
--- /dev/null
+++ b/src/vnet/tunnel/tunnel.h
@@ -0,0 +1,66 @@
+/*
+ * tunnel.h: shared definitions for tunnels.
+ *
+ * Copyright (c) 2019 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.
+ */
+
+#ifndef __TUNNEL_H__
+#define __TUNNEL_H__
+
+#include <vlib/vlib.h>
+
+#define foreach_tunnel_mode \
+ _(P2P, "point-to-point") \
+ _(MP, "multi-point") \
+
+typedef enum tunnel_mode_t_
+{
+#define _(n, s) TUNNEL_MODE_##n,
+ foreach_tunnel_mode
+#undef _
+} __clib_packed tunnel_mode_t;
+
+extern u8 *format_tunnel_mode (u8 * s, va_list * args);
+
+/**
+ * Keep these idenitical to those in ipip.api
+ */
+#define forech_tunnel_encap_decap_flag \
+ _(NONE, "none", 0x0) \
+ _(ENCAP_COPY_DF, "encap-copy-df", 0x1) \
+ _(ENCAP_SET_DF, "encap-set-df", 0x2) \
+ _(ENCAP_COPY_DSCP, "encap-copy-dscp", 0x4) \
+ _(ENCAP_COPY_ECN, "encap-copy-ecn", 0x8) \
+ _(DECAP_COPY_ECN, "decap-copy-ecn", 0x10)
+
+typedef enum tunnel_encap_decap_flags_t_
+{
+#define _(a,b,c) TUNNEL_ENCAP_DECAP_FLAG_##a = c,
+ forech_tunnel_encap_decap_flag
+#undef _
+} __clib_packed tunnel_encap_decap_flags_t;
+
+#define TUNNEL_FLAG_MASK (0x1f)
+
+extern u8 *format_tunnel_encap_decap_flags (u8 * s, va_list * args);
+
+#endif
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/tunnel/tunnel_types.api b/src/vnet/tunnel/tunnel_types.api
new file mode 100644
index 00000000000..103948d08c7
--- /dev/null
+++ b/src/vnet/tunnel/tunnel_types.api
@@ -0,0 +1,50 @@
+/* Hey Emacs use -*- mode: C -*- */
+/*
+ * Copyright (c) 2019 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.
+ */
+
+/**
+ * Flags controlling tunnel behaviour
+ */
+enum tunnel_encap_decap_flags : u8
+{
+ TUNNEL_API_ENCAP_DECAP_FLAG_NONE = 0,
+ /** at encap, copy the DF bit of the payload into the tunnel header */
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DF = 0x1,
+ /** at encap, set the DF bit in the tunnel header */
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_SET_DF = 0x2,
+ /** at encap, copy the DSCP bits of the payload into the tunnel header */
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP = 0x4,
+ /** at encap, copy the ECN bit of the payload into the tunnel header */
+ TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN = 0x8,
+ /** at decap, copy the ECN bit of the tunnel header into the payload */
+ TUNNEL_API_ENCAP_DECAP_FLAG_DECAP_COPY_ECN = 0x10,
+};
+
+/**
+ * tunnel mode
+ */
+enum tunnel_mode : u8
+{
+ /** point-to-point */
+ TUNNEL_API_MODE_P2P,
+ /** multi-point */
+ TUNNEL_API_MODE_MP,
+};
+
+/*
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/tunnel/tunnel_types_api.c b/src/vnet/tunnel/tunnel_types_api.c
new file mode 100644
index 00000000000..1d48178e9df
--- /dev/null
+++ b/src/vnet/tunnel/tunnel_types_api.c
@@ -0,0 +1,87 @@
+/*
+ * tunnel_api.c - tunnel api
+ *
+ * Copyright (c) 2018 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.
+ */
+
+#include <vnet/api_errno.h>
+#include <vnet/tunnel/tunnel_types_api.h>
+
+#include <vnet/tunnel/tunnel_types.api_enum.h>
+#include <vnet/tunnel/tunnel_types.api_types.h>
+
+
+STATIC_ASSERT (sizeof (vl_api_tunnel_encap_decap_flags_t) ==
+ sizeof (tunnel_encap_decap_flags_t),
+ "tunnel API and internal flags enum size differ");
+
+int
+tunnel_encap_decap_flags_decode (vl_api_tunnel_encap_decap_flags_t f,
+ tunnel_encap_decap_flags_t * o)
+{
+ if (f & ~TUNNEL_FLAG_MASK)
+ /* unknown flags set */
+ return (VNET_API_ERROR_INVALID_VALUE_2);
+
+ *o = (tunnel_encap_decap_flags_t) f;
+ return (0);
+}
+
+vl_api_tunnel_encap_decap_flags_t
+tunnel_encap_decap_flags_encode (tunnel_encap_decap_flags_t f)
+{
+ return ((vl_api_tunnel_encap_decap_flags_t) f);
+}
+
+int
+tunnel_mode_decode (vl_api_tunnel_mode_t in, tunnel_mode_t * out)
+{
+ switch (in)
+ {
+#define _(n, v) \
+ case TUNNEL_API_MODE_##n: \
+ *out = TUNNEL_MODE_##n; \
+ return (0);
+ foreach_tunnel_mode
+#undef _
+ }
+
+ return (VNET_API_ERROR_INVALID_VALUE_2);
+}
+
+vl_api_tunnel_mode_t
+tunnel_mode_encode (tunnel_mode_t in)
+{
+ vl_api_tunnel_mode_t out = TUNNEL_API_MODE_P2P;
+
+ switch (in)
+ {
+#define _(n, v) \
+ case TUNNEL_MODE_##n: \
+ out = TUNNEL_API_MODE_##n; \
+ break;
+ foreach_tunnel_mode
+#undef _
+ }
+
+ return (out);
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vnet/tunnel/tunnel_types_api.h b/src/vnet/tunnel/tunnel_types_api.h
new file mode 100644
index 00000000000..06439dc87c1
--- /dev/null
+++ b/src/vnet/tunnel/tunnel_types_api.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018 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.
+ */
+
+#ifndef __TUNNEL_TYPES_API_H__
+#define __TUNNEL_TYPES_API_H__
+
+/**
+ * Conversion functions to/from (decode/encode) API types to VPP internal types
+ */
+
+#include <vnet/tunnel/tunnel.h>
+#include <vnet/tunnel/tunnel_types.api_types.h>
+
+/**
+ * These enum decode/encodes use 'int' as the type for the enum because
+ * one cannot forward declare an enum
+ */
+extern int tunnel_encap_decap_flags_decode (vl_api_tunnel_encap_decap_flags_t
+ _f,
+ tunnel_encap_decap_flags_t * out);
+extern vl_api_tunnel_encap_decap_flags_t
+tunnel_encap_decap_flags_encode (tunnel_encap_decap_flags_t f);
+
+extern int tunnel_mode_decode (vl_api_tunnel_mode_t in, tunnel_mode_t * out);
+extern vl_api_tunnel_mode_t tunnel_mode_encode (tunnel_mode_t in);
+
+#endif
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */