summaryrefslogtreecommitdiffstats
path: root/src/vnet/mpls/mpls_tunnel.c
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-11-15 12:54:46 -0800
committerFlorin Coras <florin.coras@gmail.com>2017-11-18 01:34:22 +0000
commit70ed8aeff30c0eece0e19f0ad26c4cc8957278ae (patch)
treeb09bda6fef287b46dac123949f25972edc41e600 /src/vnet/mpls/mpls_tunnel.c
parent8ac4ce8547d84c2d581f572b4f51fd34dbf1b01f (diff)
unformat function for FIB paths
Change-Id: I32de25890ac0a643314f650591d2479879d9a2a6 Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/mpls/mpls_tunnel.c')
-rw-r--r--src/vnet/mpls/mpls_tunnel.c58
1 files changed, 7 insertions, 51 deletions
diff --git a/src/vnet/mpls/mpls_tunnel.c b/src/vnet/mpls/mpls_tunnel.c
index 2d5521f447a..a9f32d4e48f 100644
--- a/src/vnet/mpls/mpls_tunnel.c
+++ b/src/vnet/mpls/mpls_tunnel.c
@@ -778,11 +778,11 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
vnet_main_t * vnm = vnet_get_main();
u8 is_del = 0, l2_only = 0, is_multicast =0;
fib_route_path_t rpath, *rpaths = NULL;
- mpls_label_t out_label = MPLS_LABEL_INVALID;
- u32 sw_if_index = ~0;
+ u32 sw_if_index = ~0, payload_proto;
clib_error_t *error = NULL;
memset(&rpath, 0, sizeof(rpath));
+ payload_proto = DPO_PROTO_MPLS;
/* Get a line of input. */
if (! unformat_user (input, unformat_line_input, line_input))
@@ -800,56 +800,14 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
is_del = 0;
else if (unformat (line_input, "add"))
is_del = 0;
- else if (unformat (line_input, "out-labels"))
- {
- while (unformat (line_input, "%U",
- unformat_mpls_unicast_label,
- &out_label))
- {
- vec_add1 (rpath.frp_label_stack, out_label);
- }
- }
- else if (unformat (line_input, "via %U %U",
- unformat_ip4_address,
- &rpath.frp_addr.ip4,
- unformat_vnet_sw_interface, vnm,
- &rpath.frp_sw_if_index))
- {
- rpath.frp_weight = 1;
- rpath.frp_proto = DPO_PROTO_IP4;
- }
-
- else if (unformat (line_input, "via %U %U",
- unformat_ip6_address,
- &rpath.frp_addr.ip6,
- unformat_vnet_sw_interface, vnm,
- &rpath.frp_sw_if_index))
- {
- rpath.frp_weight = 1;
- rpath.frp_proto = DPO_PROTO_IP6;
- }
- else if (unformat (line_input, "via %U",
- unformat_ip6_address,
- &rpath.frp_addr.ip6))
- {
- rpath.frp_fib_index = 0;
- rpath.frp_weight = 1;
- rpath.frp_sw_if_index = ~0;
- rpath.frp_proto = DPO_PROTO_IP6;
- }
- else if (unformat (line_input, "via %U",
- unformat_ip4_address,
- &rpath.frp_addr.ip4))
- {
- rpath.frp_fib_index = 0;
- rpath.frp_weight = 1;
- rpath.frp_sw_if_index = ~0;
- rpath.frp_proto = DPO_PROTO_IP4;
- }
else if (unformat (line_input, "l2-only"))
l2_only = 1;
else if (unformat (line_input, "multicast"))
is_multicast = 1;
+ else if (unformat (line_input, "via %U",
+ unformat_fib_route_path,
+ &rpath, &payload_proto))
+ vec_add1(rpaths, rpath);
else
{
error = clib_error_return (0, "unknown input '%U'",
@@ -858,8 +816,6 @@ vnet_create_mpls_tunnel_command_fn (vlib_main_t * vm,
}
}
- vec_add1(rpaths, rpath);
-
if (is_del)
{
if (!vnet_mpls_tunnel_path_remove(sw_if_index, rpaths))
@@ -901,7 +857,7 @@ done:
VLIB_CLI_COMMAND (create_mpls_tunnel_command, static) = {
.path = "mpls tunnel",
.short_help =
- "mpls tunnel via [addr] [interface] [out-labels]",
+ "mpls tunnel [multicast] [l2-only] via [next-hop-address] [next-hop-interface] [next-hop-table <value>] [weight <value>] [preference <value>] [udp-encap-id <value>] [ip4-lookup-in-table <value>] [ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] [resolve-via-host] [resolve-via-connected] [rx-ip4 <interface>] [out-labels <value value value>]",
.function = vnet_create_mpls_tunnel_command_fn,
};
ht .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 *------------------------------------------------------------------
 * Copyright (c) 2020 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 _VNET_DEVICES_VIRTIO_VIRTIO_BUFFERING_H_
#define _VNET_DEVICES_VIRTIO_VIRTIO_BUFFERING_H_

#include <vnet/interface.h>

#define VIRTIO_BUFFERING_DEFAULT_SIZE 1024
#define VIRTIO_BUFFERING_TIMEOUT 1e-5

typedef struct
{
  f64 timeout_ts;
  u32 *buffers;
  u32 node_index;
  u16 size;
  u16 free_size;
  u16 front;
  u16 back;
  u8 is_enable;
} virtio_vring_buffering_t;

static_always_inline clib_error_t *
virtio_vring_buffering_init (virtio_vring_buffering_t ** buffering,
			     u32 node_index, u16 size)
{
  if (*buffering)
    return clib_error_return (0, "buffering: already initialized");

  if (!is_pow2 (size))
    return clib_error_return (0, "buffering: size must be power of 2");

  if (size > 32768)
    return clib_error_return (0, "buffering: size must be 32768 or lower");

  if (size == 0)
    size = VIRTIO_BUFFERING_DEFAULT_SIZE;

  virtio_vring_buffering_t *b_temp = 0;
  b_temp =
    (virtio_vring_buffering_t *)
    clib_mem_alloc (sizeof (virtio_vring_buffering_t));
  if (!b_temp)
    return clib_error_return (0, "buffering: memory allocation failed");

  clib_memset (b_temp, 0, sizeof (virtio_vring_buffering_t));

  b_temp->node_index = node_index;
  b_temp->free_size = size;
  b_temp->size = size;

  vec_validate_aligned (b_temp->buffers, size, CLIB_CACHE_LINE_BYTES);
  b_temp->is_enable = 1;

  *buffering = b_temp;
  return 0;
}

static_always_inline void
virtio_vring_buffering_buffers_free (vlib_main_t * vm,
				     virtio_vring_buffering_t * buffering)
{
  u16 n_buffers = buffering->size - buffering->free_size;
  if (n_buffers)
    {
      vlib_buffer_free_from_ring (vm, buffering->buffers, buffering->front,
				  buffering->size, n_buffers);
      buffering->free_size += n_buffers;
    }
}

static_always_inline void
virtio_vring_buffering_free (vlib_main_t * vm,
			     virtio_vring_buffering_t * buffering)
{
  if (buffering)
    {
      virtio_vring_buffering_buffers_free (vm, buffering);
      vec_free (buffering->buffers);
      clib_mem_free (buffering);
    }
}

static_always_inline u8
virtio_vring_buffering_is_enable (virtio_vring_buffering_t * buffering)
{
  if (buffering)
    return buffering->is_enable;

  return 0;
}

static_always_inline void
virtio_vring_buffering_set_is_enable (virtio_vring_buffering_t * buffering,
				      u8 is_enable)
{
  if (buffering)
    buffering->is_enable = is_enable;
}

static_always_inline void
virtio_vring_buffering_set_timeout (vlib_main_t * vm,
				    virtio_vring_buffering_t * buffering,
				    f64 timeout_expire)
{
  if (buffering)
    buffering->timeout_ts = vlib_time_now (vm) + timeout_expire;
}

static_always_inline u8
virtio_vring_buffering_is_timeout (vlib_main_t * vm,
				   virtio_vring_buffering_t * buffering)
{
  if (buffering && (buffering->timeout_ts < vlib_time_now (vm)))
    return 1;
  return 0;
}

static_always_inline u8
virtio_vring_buffering_is_empty (virtio_vring_buffering_t * buffering)
{
  if (buffering->size == buffering->free_size)
    return 1;
  return 0;
}

static_always_inline u8
virtio_vring_buffering_is_full (virtio_vring_buffering_t * buffering)
{
  if (buffering->free_size == 0)
    return 1;
  return 0;
}

static_always_inline u16
virtio_vring_n_buffers (virtio_vring_buffering_t * buffering)
{
  return (buffering->size - buffering->free_size);
}

static_always_inline u16
virtio_vring_buffering_store_packets (virtio_vring_buffering_t * buffering,
				      u32 * bi, u16 n_store)
{
  u16 mask, n_s = 0, i = 0;

  if (!virtio_vring_buffering_is_enable (buffering)
      || virtio_vring_buffering_is_full (buffering))
    return 0;

  mask = buffering->size - 1;
  n_s = clib_min (n_store, buffering->free_size);

  while (i < n_s)
    {
      buffering->buffers[buffering->back] = bi[i];
      buffering->back = (buffering->back + 1) & mask;
      buffering->free_size--;
      i++;
    }
  return n_s;
}

static_always_inline u32
virtio_vring_buffering_read_from_front (virtio_vring_buffering_t * buffering)
{
  u32 bi = ~0;
  u16 mask = buffering->size - 1;
  if (virtio_vring_buffering_is_empty (buffering))
    return bi;

  bi = buffering->buffers[buffering->front];
  buffering->buffers[buffering->front] = ~0;
  buffering->front = (buffering->front + 1) & mask;
  buffering->free_size++;
  return bi;
}

static_always_inline u32
virtio_vring_buffering_read_from_back (virtio_vring_buffering_t * buffering)
{
  u32 bi = ~0;
  u16 mask = buffering->size - 1;
  if (virtio_vring_buffering_is_empty (buffering))
    return bi;

  buffering->back = (buffering->back - 1) & mask;
  bi = buffering->buffers[buffering->back];
  buffering->buffers[buffering->back] = ~0;
  buffering->free_size++;
  return bi;
}

static_always_inline void
virtio_vring_buffering_schedule_node_on_dispatcher (
  vlib_main_t *vm, vnet_hw_if_tx_queue_t *txq,
  virtio_vring_buffering_t *buffering)
{
  if (buffering && virtio_vring_buffering_is_timeout (vm, buffering)
      && virtio_vring_n_buffers (buffering))
    {
      vlib_frame_t *f = vlib_get_frame_to_node (vm, buffering->node_index);
      vnet_hw_if_tx_frame_t *ft = vlib_frame_scalar_args (f);
      u32 *f_to = vlib_frame_vector_args (f);
      ft->shared_queue = txq->shared_queue;
      ft->queue_id = txq->queue_id;
      f_to[f->n_vectors] = virtio_vring_buffering_read_from_back (buffering);
      f->n_vectors++;
      vlib_put_frame_to_node (vm, buffering->node_index, f);
      virtio_vring_buffering_set_timeout (vm, buffering,
					  VIRTIO_BUFFERING_TIMEOUT);
    }
}

static_always_inline u8 *
virtio_vring_buffering_format (u8 * s, va_list * args)
{
  virtio_vring_buffering_t *buffering =
    va_arg (*args, virtio_vring_buffering_t *);
  u32 indent = format_get_indent (s);

  if (!buffering)
    return s;

  indent += 2;

  if (buffering->is_enable)
    s = format (s, "packet-buffering: enable\n");
  else
    s = format (s, "packet-buffering: disable\n");
  s =
    format (s,
	    "%Usize %u n_buffers %u front %u back %u",
	    format_white_space, indent, buffering->size,
	    virtio_vring_n_buffers (buffering), buffering->front,
	    buffering->back);

  return s;
}

#endif /* _VNET_DEVICES_VIRTIO_VIRTIO_BUFFERING_H_ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */