/*
 * Copyright (c) 2015 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.
 */
/*
 * interface_format.c: interface formatting
 *
 * Copyright (c) 2008 Eliot Dresselhaus
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <vnet/vnet.h>
#include <vppinfra/bitmap.h>
#include <vnet/l2/l2_input.h>
#include <vnet/l2/l2_output.h>
#include <vnet/l2/l2_vtr.h>
#include <vnet/interface/rx_queue_funcs.h>
#include <vnet/interface/tx_queue_funcs.h>

u8 *
format_vtr (u8 * s, va_list * args)
{
  u32 vtr_op = va_arg (*args, u32);
  u32 dot1q = va_arg (*args, u32);
  u32 tag1 = va_arg (*args, u32);
  u32 tag2 = va_arg (*args, u32);
  switch (vtr_op)
    {
    case L2_VTR_DISABLED:
      return format (s, "none");
    case L2_VTR_PUSH_1:
      return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
    case L2_VTR_PUSH_2:
      return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1,
		     tag2);
    case L2_VTR_POP_1:
      return format (s, "pop-1");
    case L2_VTR_POP_2:
      return format (s, "pop-2");
    case L2_VTR_TRANSLATE_1_1:
      return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
    case L2_VTR_TRANSLATE_1_2:
      return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
		     tag1, tag2);
    case L2_VTR_TRANSLATE_2_1:
      return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
    case L2_VTR_TRANSLATE_2_2:
      return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
		     tag1, tag2);
    default:
      return format (s, "none");
    }
}

u8 *
format_vnet_sw_interface_flags (u8 * s, va_list * args)
{
  u32 flags = va_arg (*args, u32);

  if (flags & VNET_SW_INTERFACE_FLAG_ERROR)
    s = format (s, "error");
  else
    {
      s = format (s, "%s",
		  (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "down");
      if (flags & VNET_SW_INTERFACE_FLAG_PUNT)
	s = format (s, "/punt");
    }

  return s;
}

u8 *
format_vnet_hw_if_rx_mode (u8 * s, va_list * args)
{
  vnet_hw_if_rx_mode mode = va_arg (*args, vnet_hw_if_rx_mode);

  if (mode == VNET_HW_IF_RX_MODE_POLLING)
    return format (s, "polling");

  if (mode == VNET_HW_IF_RX_MODE_INTERRUPT)
    return format (s, "interrupt");

  if (mode == VNET_HW_IF_RX_MODE_ADAPTIVE)
    return format (s, "adaptive");

  return format (s, "unknown");
}

u8 *
format_vnet_hw_interface_link_speed (u8 * s, va_list * args)
{
  u32 link_speed = va_arg (*args, u32);

  if (link_speed == 0 || link_speed == UINT32_MAX)
    return format (s, "unknown");

  if (link_speed >= 1000000)
    return format (s, "%f Gbps", (f64) link_speed / 1000000);

  if (link_speed >= 1000)
    return format (s, "%f Mbps", (f64) link_speed / 1000);

  return format (s, "%u Kbps", link_speed);
}

u8 *
format_vnet_hw_interface_rss_queues (u8 * s, va_list * args)
{
  clib_bitmap_t *bitmap = va_arg (*args, clib_bitmap_t *);
  int i;

  if (bitmap == NULL)
    return s;

  if (bitmap)
    {
    /* *INDENT-OFF* */
    clib_bitmap_foreach (i, bitmap)  {
      s = format (s, "%u ", i);
    }
    /* *INDENT-ON* */
    }

  return s;
}

u8 *
format_vnet_hw_interface (u8 * s, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  vnet_hw_interface_t *hi = va_arg (*args, vnet_hw_interface_t *);
  vnet_hw_interface_class_t *hw_class;
  vnet_device_class_t *dev_class;
  int verbose = va_arg (*args, int);
  u32 indent;

  if (!hi)
    return format (s, "%=32s%=6s%=8s%s", "Name", "Idx", "Link", "Hardware");

  indent = format_get_indent (s);

  s = format (s, "%-32v%=6d", hi->name, hi->hw_if_index);

  if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
    s = format (s, "%=8s", "slave");
  else
    s = format (s, "%=8s",
		hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP ? "up" : "down");

  hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index);
  dev_class = vnet_get_device_class (vnm, hi->dev_class_index);

  if (hi->bond_info && (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
    {
      int hw_idx;
      s = format (s, "Slave-Idx:");
      clib_bitmap_foreach (hw_idx, hi->bond_info)
	s = format (s, " %d", hw_idx);
    }
  else if (dev_class->format_device_name)
    s = format (s, "%U", dev_class->format_device_name, hi->dev_instance);
  else
    s = format (s, "%s%d", dev_class->name, hi->dev_instance);

  s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2,
	      format_vnet_hw_interface_link_speed, hi->link_speed);

  if (vec_len (hi->rx_queue_indices))
    {
      s = format (s, "\n%URX Queues:", format_white_space, indent + 2);
      s = format (s, "\n%U%-6s%-15s%-10s", format_white_space, indent + 4,
		  "queue", "thread", "mode");
      for (int i = 0; i < vec_len (hi->rx_queue_indices); i++)
	{
	  vnet_hw_if_rx_queue_t *rxq;
	  rxq = vnet_hw_if_get_rx_queue (vnm, hi->rx_queue_indices[i]);
	  s = format (s, "\n%U%-6u%-15U%-10U", format_white_space, indent + 4,
		      rxq->queue_id, format_vlib_thread_name_and_index,
		      rxq->thread_index, format_vnet_hw_if_rx_mode, rxq->mode);
	}
    }

  if (vec_len (hi->tx_queue_indices))
    {
      s = format (s, "\n%UTX Queues:", format_white_space, indent + 2);
      s = format (
	s, "\n%UTX Hash: %U", format_white_space, indent + 4, format_vnet_hash,
	vnet_hash_function_from_func (hi->hf, hw_class->tx_hash_fn_type));
      s = format (s, "\n%U%-6s%-7s%-15s", format_white_space, indent + 4,
		  "queue", "shared", "thread(s)");
      for (int i = 0; i < vec_len (hi->tx_queue_indices); i++)
	{
	  vnet_hw_if_tx_queue_t *txq;
	  txq = vnet_hw_if_get_tx_queue (vnm, hi->tx_queue_indices[i]);
	  s = format (
	    s, "\n%U%-6u%-7s%U", format_white_space, indent + 4, txq->queue_id,
	    clib_bitmap_count_set_bits (txq->threads) > 1 ? "yes" : "no",
	    format_bitmap_list, txq->threads);
	}
    }

  if (hi->rss_queues)
    {
      s = format (s, "\n%URSS queues: %U", format_white_space, indent + 2,
		  format_vnet_hw_interface_rss_queues, hi->rss_queues);
    }

  if (verbose)
    {
      if (hw_class->format_device)
	s = format (s, "\n%U%U",
		    format_white_space, indent + 2,
		    hw_class->format_device, hi->hw_if_index, verbose);
      else
	{
	  s = format (s, "\n%U%s",
		      format_white_space, indent + 2, hw_class->name);
	  if (hw_class->format_address && vec_len (hi->hw_address) > 0)
	    s =
	      format (s, " address %U", hw_class->format_address,
		      hi->hw_address);
	}

      if (dev_class->format_device)
	s = format (s, "\n%U%U",
		    format_white_space, indent + 2,
		    dev_class->format_device, hi->dev_instance, verbose);
    }

  return s;
}

u8 *
format_vnet_sw_interface_name (u8 * s, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
  vnet_sw_interface_t *si_sup =
    vnet_get_sup_sw_interface (vnm, si->sw_if_index);
  vnet_hw_interface_t *hi_sup;

  ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
  hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);

  s = format (s, "%v", hi_sup->name);

  if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
    s = format (s, ".%d", si->sub.id);

  return s;
}

u8 *
format_vnet_sw_if_index_name (u8 * s, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  u32 sw_if_index = va_arg (*args, u32);
  vnet_sw_interface_t *si;

  si = vnet_get_sw_interface_or_null (vnm, sw_if_index);

  if (NULL == si)
    {
      return format (s, "DELETED");
    }
  return format (s, "%U", format_vnet_sw_interface_name, vnm, si);
}

u8 *
format_vnet_hw_if_index_name (u8 * s, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  u32 hw_if_index = va_arg (*args, u32);
  vnet_hw_interface_t *hi;

  hi = vnet_get_hw_interface (vnm, hw_if_index);

  if (hi == 0)
    return format (s, "DELETED");

  return format (s, "%v", hi->name);
}

u8 *
format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
				vnet_sw_interface_t * si, int json)
{
  u32 indent, n_printed;
  int j, n_counters;
  char *x = "";
  int json_need_comma_nl = 0;
  u8 *n = 0;

  /*
   * to output a json snippet, stick quotes in lots of places
   * definitely deserves a one-character variable name.
   */
  if (json)
    x = "\"";

  indent = format_get_indent (s);
  n_printed = 0;

  n_counters = vec_len (im->combined_sw_if_counters);

  /* rx, tx counters... */
  for (j = 0; j < n_counters; j++)
    {
      vlib_combined_counter_main_t *cm;
      vlib_counter_t v, vtotal;
      vtotal.packets = 0;
      vtotal.bytes = 0;

      cm = im->combined_sw_if_counters + j;
      vlib_get_combined_counter (cm, si->sw_if_index, &v);
      vtotal.packets += v.packets;
      vtotal.bytes += v.bytes;

      /* Only display non-zero counters. */
      if (vtotal.packets == 0)
	continue;

      if (json)
	{
	  if (json_need_comma_nl)
	    {
	      vec_add1 (s, ',');
	      vec_add1 (s, '\n');
	    }
	  s = format (s, "%s%s_packets%s: %s%Ld%s,\n", x, cm->name, x, x,
		      vtotal.packets, x);
	  s = format (s, "%s%s_bytes%s: %s%Ld%s", x, cm->name, x, x,
		      vtotal.bytes, x);
	  json_need_comma_nl = 1;
	  continue;
	}

      if (n_printed > 0)
	s = format (s, "\n%U", format_white_space, indent);
      n_printed += 2;

      if (n)
	vec_set_len (n, 0);
      n = format (n, "%s packets", cm->name);
      s = format (s, "%-16v%16Ld", n, vtotal.packets);

      vec_set_len (n, 0);
      n = format (n, "%s bytes", cm->name);
      s = format (s, "\n%U%-16v%16Ld",
		  format_white_space, indent, n, vtotal.bytes);
    }
  vec_free (n);

  {
    vlib_simple_counter_main_t *cm;
    u64 v, vtotal;

    n_counters = vec_len (im->sw_if_counters);

    for (j = 0; j < n_counters; j++)
      {
	vtotal = 0;

	cm = im->sw_if_counters + j;

	v = vlib_get_simple_counter (cm, si->sw_if_index);
	vtotal += v;

	/* Only display non-zero counters. */
	if (vtotal == 0)
	  continue;

	if (json)
	  {
	    if (json_need_comma_nl)
	      {
		vec_add1 (s, ',');
		vec_add1 (s, '\n');
	      }
	    s = format (s, "%s%s%s: %s%Ld%s", x, cm->name, x, x, vtotal, x);
	    json_need_comma_nl = 1;
	    continue;
	  }


	if (n_printed > 0)
	  s = format (s, "\n%U", format_white_space, indent);
	n_printed += 1;

	s = format (s, "%-16s%16Ld", cm->name, vtotal);
      }
  }

  return s;
}

static u8 *
format_vnet_sw_interface_mtu (u8 * s, va_list * args)
{
  vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);

  return format (s, "%d/%d/%d/%d", si->mtu[VNET_MTU_L3],
		 si->mtu[VNET_MTU_IP4],
		 si->mtu[VNET_MTU_IP6], si->mtu[VNET_MTU_MPLS]);
}

u8 *
format_vnet_sw_interface (u8 * s, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
  vnet_interface_main_t *im = &vnm->interface_main;

  if (!si)
    return format (s, "%=32s%=5s%=10s%=21s%=16s%=16s",
		   "Name", "Idx", "State", "MTU (L3/IP4/IP6/MPLS)", "Counter",
		   "Count");

  s = format (s, "%-32U%=5d%=10U%=21U",
	      format_vnet_sw_interface_name, vnm, si, si->sw_if_index,
	      format_vnet_sw_interface_flags, si->flags,
	      format_vnet_sw_interface_mtu, si);

  s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );

  return s;
}

u8 *
format_vnet_sw_interface_name_override (u8 * s, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
  /* caller supplied display name for this interface */
  u8 *name = va_arg (*args, u8 *);
  vnet_interface_main_t *im = &vnm->interface_main;


  if (!si)
    return format (s, "%=32s%=5s%=16s%=16s%=16s",
		   "Name", "Idx", "State", "Counter", "Count");

  s = format (s, "%-32v%=5d%=16U",
	      name, si->sw_if_index,
	      format_vnet_sw_interface_flags, si->flags);

  s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );

  return s;
}

u8 *
format_vnet_buffer_flags (u8 * s, va_list * args)
{
  vlib_buffer_t *buf = va_arg (*args, vlib_buffer_t *);

#define _(a,b,c,v) if (buf->flags & VNET_BUFFER_F_##b) s = format (s, "%s ", c);
  foreach_vnet_buffer_flag;
#undef _
  return s;
}

u8 *
format_vnet_buffer_opaque (u8 * s, va_list * args)
{
  vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
  vnet_buffer_opaque_t *o = (vnet_buffer_opaque_t *) b->opaque;
  vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
  vnet_buffer_opquae_formatter_t helper_fp;
  int i;

  s = format (s, "raw: ");

  for (i = 0; i < ARRAY_LEN (b->opaque); i++)
    s = format (s, "%08x ", b->opaque[i]);

  vec_add1 (s, '\n');

  s = format (s,
	      "sw_if_index[VLIB_RX]: %d, sw_if_index[VLIB_TX]: %d",
	      o->sw_if_index[0], o->sw_if_index[1]);
  vec_add1 (s, '\n');

  s = format (s,
	      "L2 offset %d, L3 offset %d, L4 offset %d, feature arc index %d",
	      (u32) (o->l2_hdr_offset),
	      (u32) (o->l3_hdr_offset),
	      (u32) (o->l4_hdr_offset), (u32) (o->feature_arc_index));
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.adj_index[VLIB_RX]: %d, ip.adj_index[VLIB_TX]: %d",
	      (u32) (o->ip.adj_index[0]), (u32) (o->ip.adj_index[1]));
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.flow_hash: 0x%x, ip.save_protocol: 0x%x, ip.fib_index: %d",
	      o->ip.flow_hash, o->ip.save_protocol, o->ip.fib_index);
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.save_rewrite_length: %d, ip.rpf_id: %d",
	      o->ip.save_rewrite_length, o->ip.rpf_id);
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.icmp.type: %d ip.icmp.code: %d, ip.icmp.data: 0x%x",
	      (u32) (o->ip.icmp.type),
	      (u32) (o->ip.icmp.code), o->ip.icmp.data);
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.reass.next_index: %d, ip.reass.estimated_mtu: %d",
	      o->ip.reass.next_index, (u32) (o->ip.reass.estimated_mtu));
  vec_add1 (s, '\n');
  s = format (s,
	      "ip.reass.error_next_index: %d, ip.reass.owner_thread_index: %d",
	      o->ip.reass.error_next_index,
	      (u32) (o->ip.reass.owner_thread_index));
  vec_add1 (s, '\n');
  s = format (s,
	      "ip.reass.ip_proto: %d, ip.reass.l4_src_port: %d",
	      o->ip.reass.ip_proto, (u32) (o->ip.reass.l4_src_port));
  vec_add1 (s, '\n');
  s = format (s, "ip.reass.l4_dst_port: %d", o->ip.reass.l4_dst_port);
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.reass.fragment_first: %d ip.reass.fragment_last: %d",
	      (u32) (o->ip.reass.fragment_first),
	      (u32) (o->ip.reass.fragment_last));
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.reass.range_first: %d ip.reass.range_last: %d",
	      (u32) (o->ip.reass.range_first),
	      (u32) (o->ip.reass.range_last));
  vec_add1 (s, '\n');

  s = format (s,
	      "ip.reass.next_range_bi: 0x%x, ip.reass.ip6_frag_hdr_offset: %d",
	      o->ip.reass.next_range_bi,
	      (u32) (o->ip.reass.ip6_frag_hdr_offset));
  vec_add1 (s, '\n');

  s = format (s,
	      "mpls.ttl: %d, mpls.exp: %d, mpls.first: %d, "
	      "mpls.save_rewrite_length: %d, mpls.bier.n_bytes: %d",
	      (u32) (o->mpls.ttl), (u32) (o->mpls.exp), (u32) (o->mpls.first),
	      o->mpls.save_rewrite_length, (u32) (o->mpls.bier.n_bytes));
  vec_add1 (s, '\n');
  s = format (s, "mpls.mpls_hdr_length: %d", (u32) (o->mpls.mpls_hdr_length));
  vec_add1 (s, '\n');

  s = format (s,
	      "l2.feature_bitmap: %08x, l2.bd_index: %d, l2.l2fib_sn %d, "
	      "l2.l2_len: %d, l2.shg: %d, l2.bd_age: %d",
	      (u32) (o->l2.feature_bitmap), (u32) (o->l2.bd_index),
	      (u32) (o->l2.l2fib_sn),
	      (u32) (o->l2.l2_len), (u32) (o->l2.shg), (u32) (o->l2.bd_age));
  vec_add1 (s, '\n');

  s = format (s,
	      "l2.feature_bitmap_input: %U, L2.feature_bitmap_output: %U",
	      format_l2_input_feature_bitmap, o->l2.feature_bitmap, 0,
	      format_l2_output_features, o->l2.feature_bitmap, 0);
  vec_add1 (s, '\n');

  s = format (s,
	      "l2t.next_index: %d, l2t.session_index: %d",
	      (u32) (o->l2t.next_index), o->l2t.session_index);
  vec_add1 (s, '\n');

  s = format (s,
	      "l2_classify.table_index: %d, l2_classify.opaque_index: %d, "
	      "l2_classify.hash: 0x%lx",
	      o->l2_classify.table_index, o->l2_classify.opaque_index,
	      o->l2_classify.hash);
  vec_add1 (s, '\n');

  s = format (s, "policer.index: %d", o->policer.index);
  vec_add1 (s, '\n');

  s = format (s, "ipsec.sad_index: %d, ipsec.protect_index",
	      o->ipsec.sad_index, o->ipsec.protect_index);
  vec_add1 (s, '\n');

  s = format (s, "map.mtu: %d", (u32) (o->map.mtu));
  vec_add1 (s, '\n');

  s = format (s,
	      "map_t.map_domain_index: %d, map_t.v6.saddr: 0x%x, "
	      "map_t.v6.daddr: 0x%x, map_t.v6.frag_offset: %d, "
	      "map_t.v6.l4_offset: %d, map_t.v6.l4_protocol: %d, "
	      "map.t.checksum_offset: %d",
	      o->map_t.map_domain_index,
	      o->map_t.v6.saddr,
	      o->map_t.v6.daddr,
	      (u32) (o->map_t.v6.frag_offset), (u32) (o->map_t.v6.l4_offset),
	      (u32) (o->map_t.v6.l4_protocol),
	      (u32) (o->map_t.checksum_offset));
  vec_add1 (s, '\n');

  s = format (s,
	      "map_t.v6.l4_protocol: %d, map_t.checksum_offset: %d, "
	      "map_t.mtu: %d",
	      (u32) (o->map_t.v6.l4_protocol),
	      (u32) (o->map_t.checksum_offset), (u32) (o->map_t.mtu));
  vec_add1 (s, '\n');

  s = format (s,
	      "ip_frag.mtu: %d, ip_frag.next_index: %d, ip_frag.flags: 0x%x",
	      (u32) (o->ip_frag.mtu),
	      (u32) (o->ip_frag.next_index), (u32) (o->ip_frag.flags));
  vec_add1 (s, '\n');

  s = format (s, "cop.current_config_index: %d", o->cop.current_config_index);
  vec_add1 (s, '\n');

  s = format (s, "lisp.overlay_afi: %d", (u32) (o->lisp.overlay_afi));
  vec_add1 (s, '\n');

  s = format
    (s,
     "tcp.connection_index: %d, tcp.seq_number: %d, tcp.next_node_opaque: %d "
     "tcp.seq_end: %d, tcp.ack_number: %d, tcp.hdr_offset: %d, "
     "tcp.data_offset: %d", o->tcp.connection_index, o->tcp.next_node_opaque,
     o->tcp.seq_number, o->tcp.seq_end, o->tcp.ack_number,
     (u32) (o->tcp.hdr_offset), (u32) (o->tcp.data_offset));
  vec_add1 (s, '\n');

  s = format (s,
	      "tcp.data_len: %d, tcp.flags: 0x%x",
	      (u32) (o->tcp.data_len), (u32) (o->tcp.flags));
  vec_add1 (s, '\n');

  s = format (s, "snat.flags: 0x%x", o->snat.flags);
  vec_add1 (s, '\n');

  for (i = 0; i < vec_len (im->buffer_opaque_format_helpers); i++)
    {
      helper_fp = im->buffer_opaque_format_helpers[i];
      s = (*helper_fp) (b, s);
    }

  return s;
}

u8 *
format_vnet_buffer_opaque2 (u8 * s, va_list * args)
{
  vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
  vnet_buffer_opaque2_t *o = (vnet_buffer_opaque2_t *) b->opaque2;
  vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
  vnet_buffer_opquae_formatter_t helper_fp;

  int i;

  s = format (s, "raw: ");

  for (i = 0; i < ARRAY_LEN (b->opaque2); i++)
    s = format (s, "%08x ", b->opaque2[i]);
  vec_add1 (s, '\n');

  s = format (s, "qos.bits: %x, qos.source: %x",
	      (u32) (o->qos.bits), (u32) (o->qos.source));
  vec_add1 (s, '\n');
  s = format (s, "loop_counter: %d", o->loop_counter);
  vec_add1 (s, '\n');

  s = format (s, "gso_size: %d, gso_l4_hdr_sz: %d",
	      (u32) (o->gso_size), (u32) (o->gso_l4_hdr_sz));
  vec_add1 (s, '\n');

  for (i = 0; i < vec_len (im->buffer_opaque2_format_helpers); i++)
    {
      helper_fp = im->buffer_opaque2_format_helpers[i];
      s = (*helper_fp) (b, s);
    }

  return s;
}

void
vnet_register_format_buffer_opaque_helper (vnet_buffer_opquae_formatter_t fp)
{
  vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
  vec_add1 (im->buffer_opaque_format_helpers, fp);
}

void
vnet_register_format_buffer_opaque2_helper (vnet_buffer_opquae_formatter_t fp)
{
  vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
  vec_add1 (im->buffer_opaque2_format_helpers, fp);
}


uword
unformat_vnet_buffer_flags (unformat_input_t * input, va_list * args)
{
  u32 *flagp = va_arg (*args, u32 *);
  int rv = 0;
  u32 flags = 0;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      /* Red herring, there is no such buffer flag */
      if (unformat (input, "avail10"))
	return 0;
#define _(bit,enum,str,verbose)                                 \
      else if (unformat (input, str))                           \
        {                                                       \
          flags |= (1 << LOG2_VLIB_BUFFER_FLAG_USER(bit));      \
          rv = 1;                                               \
        }
      foreach_vnet_buffer_flag
#undef _
	else
	break;
    }
  if (rv)
    *flagp = flags;
  return rv;
}

uword
unformat_vnet_buffer_offload_flags (unformat_input_t *input, va_list *args)
{
  u32 *flagp = va_arg (*args, u32 *);
  int rv = 0;
  vnet_buffer_oflags_t oflags = 0;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (0)
	;
#define _(bit, enum, str, verbose)                                            \
  else if (unformat (input, str))                                             \
  {                                                                           \
    oflags |= (1 << bit);                                                     \
    rv = 1;                                                                   \
  }
      foreach_vnet_buffer_offload_flag
#undef _
	else break;
    }
  if (rv)
    *flagp = (u32) oflags;
  return rv;
}

uword
unformat_vnet_hw_interface (unformat_input_t * input, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  u32 *hw_if_index = va_arg (*args, u32 *);
  vnet_interface_main_t *im = &vnm->interface_main;
  vnet_device_class_t *c;

  /* Try per device class functions first. */
  vec_foreach (c, im->device_classes)
  {
    if (c->unformat_device_name
	&& unformat_user (input, c->unformat_device_name, hw_if_index))
      return 1;
  }

  return unformat_user (input, unformat_hash_vec_string,
			im->hw_interface_by_name, hw_if_index);
}

uword
unformat_vnet_sw_interface (unformat_input_t * input, va_list * args)
{
  vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
  u32 *result = va_arg (*args, u32 *);
  vnet_hw_interface_t *hi;
  u32 hw_if_index, id, id_specified;
  u32 sw_if_index;
  u8 *if_name = 0;
  uword *p, error = 0;

  id = ~0;
  if (unformat (input, "%_%v.%d%_", &if_name, &id)
      && ((p = hash_get (vnm->interface_main.hw_interface_by_name, if_name))))
    {
      hw_if_index = p[0];
      id_specified = 1;
    }
  else
    if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
    id_specified = 0;
  else
    goto done;

  hi = vnet_get_hw_interface (vnm, hw_if_index);
  if (!id_specified)
    {
      sw_if_index = hi->sw_if_index;
    }
  else
    {
      if (!(p = hash_get (hi->sub_interface_sw_if_index_by_id, id)))
	goto done;
      sw_if_index = p[0];
    }
  if (!vnet_sw_interface_is_api_visible (vnm, sw_if_index))
    goto done;
  *result = sw_if_index;
  error = 1;
done:
  vec_free (if_name);
  return error;
}

uword
unformat_vnet_sw_interface_flags (unformat_input_t * input, va_list * args)
{
  u32 *result = va_arg (*args, u32 *);
  u32 flags = 0;

  if (unformat (input, "up"))
    flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP;
  else if (unformat (input, "down"))
    flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
  else if (unformat (input, "punt"))
    flags |= VNET_SW_INTERFACE_FLAG_PUNT;
  else if (unformat (input, "enable"))
    flags &= ~VNET_SW_INTERFACE_FLAG_PUNT;
  else
    return 0;

  *result = flags;
  return 1;
}

uword
unformat_vnet_hw_interface_flags (unformat_input_t * input, va_list * args)
{
  u32 *result = va_arg (*args, u32 *);
  u32 flags = 0;

  if (unformat (input, "up"))
    flags |= VNET_HW_INTERFACE_FLAG_LINK_UP;
  else if (unformat (input, "down"))
    flags &= ~VNET_HW_INTERFACE_FLAG_LINK_UP;
  else
    return 0;

  *result = flags;
  return 1;
}

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