/*
 * 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.
 */
/*
 * ethernet_format.c: ethernet formatting/parsing.
 *
 * 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 <vlib/vlib.h>
#include <vnet/ethernet/ethernet.h>

u8 *
format_ethernet_address (u8 * s, va_list * args)
{
  ethernet_main_t *em = &ethernet_main;
  u8 *a = va_arg (*args, u8 *);

  if (em->format_ethernet_address_16bit)
    return format (s, "%02x%02x.%02x%02x.%02x%02x",
		   a[0], a[1], a[2], a[3], a[4], a[5]);
  else
    return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
		   a[0], a[1], a[2], a[3], a[4], a[5]);
}

u8 *
format_ethernet_type (u8 * s, va_list * args)
{
  ethernet_type_t type = va_arg (*args, u32);
  ethernet_main_t *em = &ethernet_main;
  ethernet_type_info_t *t = ethernet_get_type_info (em, type);

  if (t)
    s = format (s, "%s", t->name);
  else
    s = format (s, "0x%04x", type);

  return s;
}

u8 *
format_ethernet_vlan_tci (u8 * s, va_list * va)
{
  u32 vlan_tci = va_arg (*va, u32);

  u32 vid = (vlan_tci & 0xfff);
  u32 cfi = (vlan_tci >> 12) & 1;
  u32 pri = (vlan_tci >> 13);

  s = format (s, "%d", vid);
  if (pri != 0)
    s = format (s, " priority %d", pri);
  if (cfi != 0)
    s = format (s, " cfi");

  return s;
}

u8 *
format_ethernet_pbb (u8 * s, va_list * va)
{
  u32 b_tag = va_arg (*va, u32);
  u32 i_tag = va_arg (*va, u32);
  u32 vid = (b_tag & 0xfff);
  u32 bdei = (b_tag >> 12) & 1;
  u32 bpcp = (b_tag >> 13);
  u32 sid = (i_tag & 0xffffff);
  u8 ires = (i_tag >> 24) & 3;
  u8 iuca = (i_tag >> 27) & 1;
  u8 idei = (i_tag >> 28) & 1;
  u8 ipcp = (i_tag >> 29);

  s =
    format (s, "B_tag %04X (vid %d, dei %d, pcp %d), ", b_tag, vid, bdei,
	    bpcp);
  s =
    format (s, "I_tag %08X (sid %d, res %d, dei %d, pcp %d)", i_tag, sid,
	    ires, iuca, idei, ipcp);

  return s;
}

u8 *
format_ethernet_header_with_length (u8 * s, va_list * args)
{
  ethernet_pbb_header_packed_t *ph =
    va_arg (*args, ethernet_pbb_header_packed_t *);
  ethernet_max_header_t *m = (ethernet_max_header_t *) ph;
  u32 max_header_bytes = va_arg (*args, u32);
  ethernet_main_t *em = &ethernet_main;
  ethernet_header_t *e = &m->ethernet;
  ethernet_vlan_header_t *v;
  ethernet_type_t type = clib_net_to_host_u16 (e->type);
  ethernet_type_t vlan_type[ARRAY_LEN (m->vlan)];
  u32 n_vlan = 0, i, header_bytes;
  uword indent;

  while ((type == ETHERNET_TYPE_VLAN || type == ETHERNET_TYPE_DOT1AD
	  || type == ETHERNET_TYPE_DOT1AH) && n_vlan < ARRAY_LEN (m->vlan))
    {
      vlan_type[n_vlan] = type;
      if (type != ETHERNET_TYPE_DOT1AH)
	{
	  v = m->vlan + n_vlan;
	  type = clib_net_to_host_u16 (v->type);
	}
      n_vlan++;
    }

  header_bytes = sizeof (e[0]) + n_vlan * sizeof (v[0]);
  if (max_header_bytes != 0 && header_bytes > max_header_bytes)
    return format (s, "ethernet header truncated");

  indent = format_get_indent (s);

  s = format (s, "%U: %U -> %U",
	      format_ethernet_type, type,
	      format_ethernet_address, e->src_address,
	      format_ethernet_address, e->dst_address);

  if (type != ETHERNET_TYPE_DOT1AH)
    {
      for (i = 0; i < n_vlan; i++)
	{
	  u32 v = clib_net_to_host_u16 (m->vlan[i].priority_cfi_and_id);
	  if (*vlan_type == ETHERNET_TYPE_VLAN)
	    s = format (s, " 802.1q vlan %U", format_ethernet_vlan_tci, v);
	  else
	    s = format (s, " 802.1ad vlan %U", format_ethernet_vlan_tci, v);
	}

      if (max_header_bytes != 0 && header_bytes < max_header_bytes)
	{
	  ethernet_type_info_t *ti;
	  vlib_node_t *node = 0;

	  ti = ethernet_get_type_info (em, type);
	  if (ti && ti->node_index != ~0)
	    node = vlib_get_node (em->vlib_main, ti->node_index);
	  if (node && node->format_buffer)
	    s = format (s, "\n%U%U",
			format_white_space, indent,
			node->format_buffer, (void *) m + header_bytes,
			max_header_bytes - header_bytes);
	}
    }
  else
    {
      s = format (s, "\n%UPBB header : %U", format_white_space, indent,
		  format_ethernet_pbb,
		  clib_net_to_host_u16 (ph->priority_dei_id),
		  clib_net_to_host_u32 (ph->priority_dei_uca_res_sid));
    }

  return s;
}

u8 *
format_ethernet_header (u8 * s, va_list * args)
{
  ethernet_max_header_t *m = va_arg (*args, ethernet_max_header_t *);
  return format (s, "%U", format_ethernet_header_with_length, m, 0);
}

/* Parse X:X:X:X:X:X unix style ethernet address. */
static uword
unformat_ethernet_address_unix (unformat_input_t * input, va_list * args)
{
  u8 *result = va_arg (*args, u8 *);
  u32 i, a[6];

  if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
		 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
    return 0;

  /* Check range. */
  for (i = 0; i < ARRAY_LEN (a); i++)
    if (a[i] >= (1 << 8))
      return 0;

  for (i = 0; i < ARRAY_LEN (a); i++)
    result[i] = a[i];

  return 1;
}

/* Parse X.X.X cisco style ethernet address. */
static uword
unformat_ethernet_address_cisco (unformat_input_t * input, va_list * args)
{
  u8 *result = va_arg (*args, u8 *);
  u32 i, a[3];

  if (!unformat (input, "%_%x.%x.%x%_", &a[0], &a[1], &a[2]))
    return 0;

  /* Check range. */
  for (i = 0; i < ARRAY_LEN (a); i++)
    if (a[i] >= (1 << 16))
      return 0;

  result[0] = (a[0] >> 8) & 0xff;
  result[1] = (a[0] >> 0) & 0xff;
  result[2] = (a[1] >> 8) & 0xff;
  result[3] = (a[1] >> 0) & 0xff;
  result[4] = (a[2] >> 8) & 0xff;
  result[5] = (a[2] >> 0) & 0xff;

  return 1;
}

/* Parse ethernet address; accept either unix or style addresses. */
uword
unformat_ethernet_address (unformat_input_t * input, va_list * args)
{
  u8 *result = va_arg (*args, u8 *);
  return (unformat_user (input, unformat_ethernet_address_unix, result)
	  || unformat_user (input, unformat_ethernet_address_cisco, result));
}

/* Returns ethernet type as an int in host byte order. */
uword
unformat_ethernet_type_host_byte_order (unformat_input_t * input,
					va_list * args)
{
  u16 *result = va_arg (*args, u16 *);
  ethernet_main_t *em = &ethernet_main;
  int type, i;

  /* Numeric type. */
  if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
    {
      if (type >= (1 << 16))
	return 0;
      *result = type;
      return 1;
    }

  /* Named type. */
  if (unformat_user (input, unformat_vlib_number_by_name,
		     em->type_info_by_name, &i))
    {
      ethernet_type_info_t *ti = vec_elt_at_index (em->type_infos, i);
      *result = ti->type;
      return 1;
    }

  return 0;
}

uword
unformat_ethernet_type_net_byte_order (unformat_input_t * input,
				       va_list * args)
{
  u16 *result = va_arg (*args, u16 *);
  if (!unformat_user (input, unformat_ethernet_type_host_byte_order, result))
    return 0;

  *result = clib_host_to_net_u16 ((u16) * result);
  return 1;
}

uword
unformat_ethernet_header (unformat_input_t * input, va_list * args)
{
  u8 **result = va_arg (*args, u8 **);
  ethernet_max_header_t _m, *m = &_m;
  ethernet_header_t *e = &m->ethernet;
  u16 type;
  u32 n_vlan;

  if (!unformat (input, "%U: %U -> %U",
		 unformat_ethernet_type_host_byte_order, &type,
		 unformat_ethernet_address, &e->src_address,
		 unformat_ethernet_address, &e->dst_address))
    return 0;

  n_vlan = 0;
  while (unformat (input, "vlan"))
    {
      u32 id, priority;

      if (!unformat_user (input, unformat_vlib_number, &id)
	  || id >= ETHERNET_N_VLAN)
	return 0;

      if (unformat (input, "priority %d", &priority))
	{
	  if (priority >= 8)
	    return 0;
	  id |= priority << 13;
	}

      if (unformat (input, "cfi"))
	id |= 1 << 12;

      /* Too many vlans given. */
      if (n_vlan >= ARRAY_LEN (m->vlan))
	return 0;

      m->vlan[n_vlan].priority_cfi_and_id = clib_host_to_net_u16 (id);
      n_vlan++;
    }

  if (n_vlan == 0)
    e->type = clib_host_to_net_u16 (type);
  else
    {
      int i;

      e->type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
      for (i = 0; i < n_vlan - 1; i++)
	m->vlan[i].type = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
      m->vlan[n_vlan - 1].type = clib_host_to_net_u16 (type);
    }

  /* Add header to result. */
  {
    void *p;
    u32 n_bytes = sizeof (e[0]) + n_vlan * sizeof (m->vlan[0]);

    vec_add2 (*result, p, n_bytes);
    clib_memcpy (p, m, n_bytes);
  }

  return 1;
}

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