
/*
 * 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.
 */
#include <vppinfra/error.h>
#include <vppinfra/hash.h>
#include <vnet/vnet.h>
#include <vnet/ip/ip.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/vxlan/vxlan.h>

/* Statistics (not all errors) */
#define foreach_vxlan_encap_error    \
_(ENCAPSULATED, "good packets encapsulated")

static char * vxlan_encap_error_strings[] = {
#define _(sym,string) string,
  foreach_vxlan_encap_error
#undef _
};

typedef enum {
#define _(sym,str) VXLAN_ENCAP_ERROR_##sym,
    foreach_vxlan_encap_error
#undef _
    VXLAN_ENCAP_N_ERROR,
} vxlan_encap_error_t;

typedef enum {
    VXLAN_ENCAP_NEXT_DROP,
    VXLAN_ENCAP_N_NEXT,
} vxlan_encap_next_t;

typedef struct {
  u32 tunnel_index;
  u32 vni;
} vxlan_encap_trace_t;

u8 * format_vxlan_encap_trace (u8 * s, va_list * args)
{
  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
  vxlan_encap_trace_t * t 
      = va_arg (*args, vxlan_encap_trace_t *);

  s = format (s, "VXLAN encap to vxlan_tunnel%d vni %d", 
	      t->tunnel_index, t->vni);
  return s;
}

always_inline uword
vxlan_encap_inline (vlib_main_t * vm,
		    vlib_node_runtime_t * node,
		    vlib_frame_t * from_frame,
		    u8 is_ip4, u8 csum_offload)
{
  u32 n_left_from, next_index, * from, * to_next;
  vxlan_main_t * vxm = &vxlan_main;
  vnet_main_t * vnm = vxm->vnet_main;
  vnet_interface_main_t * im = &vnm->interface_main;
  vlib_combined_counter_main_t * tx_counter = 
      im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX;
  u32 pkts_encapsulated = 0;
  u32 thread_index = vlib_get_thread_index();
  u32 sw_if_index0 = 0, sw_if_index1 = 0;
  u32 next0 = 0, next1 = 0;
  vxlan_tunnel_t * t0 = NULL, * t1 = NULL;
  index_t dpoi_idx0 = INDEX_INVALID, dpoi_idx1 = INDEX_INVALID;

  from = vlib_frame_vector_args (from_frame);
  n_left_from = from_frame->n_vectors;

  next_index = node->cached_next_index;

  STATIC_ASSERT_SIZEOF(ip6_vxlan_header_t, 56);
  STATIC_ASSERT_SIZEOF(ip4_vxlan_header_t, 36);

  word const underlay_hdr_len = is_ip4 ?
    sizeof(ip4_vxlan_header_t) : sizeof(ip6_vxlan_header_t);
  u16 const l3_len = is_ip4 ? sizeof(ip4_header_t) : sizeof(ip6_header_t);
  u32 const csum_flags = is_ip4 ?
    VNET_BUFFER_F_OFFLOAD_IP_CKSUM | VNET_BUFFER_F_IS_IP4 |
    VNET_BUFFER_F_OFFLOAD_UDP_CKSUM :
    VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;

  while (n_left_from > 0)
    {
      u32 n_left_to_next;

      vlib_get_next_frame (vm, node, next_index,
			   to_next, n_left_to_next);

      while (n_left_from >= 4 && n_left_to_next >= 2)
	{
	  /* Prefetch next iteration. */
	  {
	    vlib_buffer_t * p2, * p3;

	    p2 = vlib_get_buffer (vm, from[2]);
	    p3 = vlib_get_buffer (vm, from[3]);

	    vlib_prefetch_buffer_header (p2, LOAD);
	    vlib_prefetch_buffer_header (p3, LOAD);

	    CLIB_PREFETCH (p2->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
	    CLIB_PREFETCH (p3->data, 2*CLIB_CACHE_LINE_BYTES, LOAD);
	  }

	  u32 bi0 = from[0];
	  u32 bi1 = from[1];

	  vlib_buffer_t * b0 = vlib_get_buffer (vm, bi0);
	  vlib_buffer_t * b1 = vlib_get_buffer (vm, bi1);
          u32 flow_hash0 = vnet_l2_compute_flow_hash (b0);
          u32 flow_hash1 = vnet_l2_compute_flow_hash (b1);

	  to_next[0] = bi0;
	  to_next[1] = bi1;
	  from += 2;
	  to_next += 2;
	  n_left_to_next -= 2;
	  n_left_from -= 2;

	  /* Get next node index and adj index from tunnel next_dpo */
	  if (sw_if_index0 != vnet_buffer(b0)->sw_if_index[VLIB_TX])
	    {
	      sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
	      vnet_hw_interface_t *hi0 = 
		  vnet_get_sup_hw_interface (vnm, sw_if_index0);
	      t0 = &vxm->tunnels[hi0->dev_instance];
	      /* Note: change to always set next0 if it may set to drop */
	      next0 = t0->next_dpo.dpoi_next_node;
	      dpoi_idx0 = t0->next_dpo.dpoi_index;
	    }

	  /* Get next node index and adj index from tunnel next_dpo */
	  if (sw_if_index1 != vnet_buffer(b1)->sw_if_index[VLIB_TX])
	    {
	      if (sw_if_index0 == vnet_buffer(b1)->sw_if_index[VLIB_TX])
	        {
		  sw_if_index1 = sw_if_index0;
		  t1 = t0;
		  next1 = next0;
		  dpoi_idx1 = dpoi_idx0;
	        }
	      else
	        {
		  sw_if_index1 = vnet_buffer(b1)->sw_if_index[VLIB_TX];
		  vnet_hw_interface_t *hi1 = 
		      vnet_get_sup_hw_interface (vnm, sw_if_index1);
		  t1 = &vxm->tunnels[hi1->dev_instance];
		  /* Note: change to always set next1 if it may set to drop */
		  next1 = t1->next_dpo.dpoi_next_node;
		  dpoi_idx1 = t1->next_dpo.dpoi_index;
	        }
	    }

          vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpoi_idx0;
          vnet_buffer(b1)->ip.adj_index[VLIB_TX] = dpoi_idx1;

          ASSERT(vec_len(t0->rewrite) == underlay_hdr_len);
          ASSERT(vec_len(t1->rewrite) == underlay_hdr_len);

          vlib_buffer_advance (b0, -underlay_hdr_len);
          vlib_buffer_advance (b1, -underlay_hdr_len);

 	  u32 len0 = vlib_buffer_length_in_chain (vm, b0);
 	  u32 len1 = vlib_buffer_length_in_chain (vm, b1);
          u16 payload_l0 = clib_host_to_net_u16 (len0 - l3_len);
          u16 payload_l1 = clib_host_to_net_u16 (len1 - l3_len);

          ip4_header_t * ip4_0, * ip4_1;
          ip6_header_t * ip6_0, * ip6_1;
          udp_header_t * udp0, * udp1;
          u8 * l3_0, * l3_1;
	  if (is_ip4)
	    {
              ip4_vxlan_header_t * hdr0 = vlib_buffer_get_current(b0);
              ip4_vxlan_header_t * rewrite0 = (void *)t0->rewrite;
              ip4_vxlan_header_t * hdr1 = vlib_buffer_get_current(b1);
              ip4_vxlan_header_t * rewrite1 = (void *)t1->rewrite;
              *hdr0 = *rewrite0;
              *hdr1 = *rewrite1;

	      /* Fix the IP4 checksum and length */
	      ip4_0 = &hdr0->ip4;
	      ip4_1 = &hdr1->ip4;
              ip4_0->length = clib_host_to_net_u16 (len0);
              ip4_1->length = clib_host_to_net_u16 (len1);

              l3_0 = (u8 *)ip4_0;
              l3_1 = (u8 *)ip4_1;
	      udp0 = &hdr0->udp;
	      udp1 = &hdr1->udp;
	    }
	  else /* ipv6 */
	    {
              ip6_vxlan_header_t * hdr0 = vlib_buffer_get_current(b0);
              ip6_vxlan_header_t * rewrite0 = (void *) t0->rewrite;
              ip6_vxlan_header_t * hdr1 = vlib_buffer_get_current(b0);
              ip6_vxlan_header_t * rewrite1 = (void *) t1->rewrite;
              *hdr0 = *rewrite0;
              *hdr1 = *rewrite1;

	      /* Fix IP6 payload length */
              ip6_0 = &hdr0->ip6;
              ip6_1 = &hdr1->ip6;
	      ip6_0->payload_length = payload_l0;
	      ip6_1->payload_length = payload_l1;

              l3_0 = (u8 *)ip6_0;
              l3_1 = (u8 *)ip6_1;
              udp0 = &hdr0->udp;
              udp1 = &hdr1->udp;
	    }

          /* Fix UDP length  and set source port */
          udp0->length = payload_l0;
          udp0->src_port = flow_hash0;
          udp1->length = payload_l1;
          udp1->src_port = flow_hash1;

          if (csum_offload)
            {
              b0->flags |= csum_flags;
              vnet_buffer (b0)->l3_hdr_offset = l3_0 - b0->data;
              vnet_buffer (b0)->l4_hdr_offset = (u8 *) udp0 - b0->data;
              b1->flags |= csum_flags;
              vnet_buffer (b1)->l3_hdr_offset = l3_1 - b1->data;
              vnet_buffer (b1)->l4_hdr_offset = (u8 *) udp1 - b1->data;
            }
          /* IPv4 UDP checksum only if checksum offload is used */
          else if (is_ip4)
            {
              ip_csum_t sum0 = ip4_0->checksum;
              sum0 = ip_csum_update (sum0, 0, ip4_0->length, ip4_header_t,
                  length /* changed member */);
              ip4_0->checksum = ip_csum_fold (sum0);
              ip_csum_t sum1 = ip4_1->checksum;
              sum1 = ip_csum_update (sum1, 0, ip4_1->length, ip4_header_t,
                  length /* changed member */);
              ip4_1->checksum = ip_csum_fold (sum1);
            }
          /* IPv6 UDP checksum is mandatory */
          else
            {
              int bogus = 0;

              udp0->checksum = ip6_tcp_udp_icmp_compute_checksum
                (vm, b0, ip6_0, &bogus);
              ASSERT(bogus == 0);
              if (udp0->checksum == 0)
                udp0->checksum = 0xffff;
              udp1->checksum = ip6_tcp_udp_icmp_compute_checksum
                (vm, b1, ip6_1, &bogus);
              ASSERT(bogus == 0);
              if (udp1->checksum == 0)
                udp1->checksum = 0xffff;
            }

          vlib_increment_combined_counter (tx_counter, thread_index,
              sw_if_index0, 1, len0);
          vlib_increment_combined_counter (tx_counter, thread_index,
              sw_if_index1, 1, len1);
          pkts_encapsulated += 2;

	  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) 
            {
              vxlan_encap_trace_t *tr = 
                vlib_add_trace (vm, node, b0, sizeof (*tr));
              tr->tunnel_index = t0 - vxm->tunnels;
              tr->vni = t0->vni;
           }

          if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) 
            {
              vxlan_encap_trace_t *tr = 
                vlib_add_trace (vm, node, b1, sizeof (*tr));
              tr->tunnel_index = t1 - vxm->tunnels;
              tr->vni = t1->vni;
            }

	  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, bi1, next0, next1);
	}

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  u32 bi0 = from[0];
	  vlib_buffer_t * b0 = vlib_get_buffer (vm, bi0);
          u32 flow_hash0 = vnet_l2_compute_flow_hash(b0);

	  to_next[0] = bi0;
	  from += 1;
	  to_next += 1;
	  n_left_from -= 1;
	  n_left_to_next -= 1;

	  /* Get next node index and adj index from tunnel next_dpo */
	  if (sw_if_index0 != vnet_buffer(b0)->sw_if_index[VLIB_TX])
	    {
	      sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_TX];
	      vnet_hw_interface_t *hi0 = 
		  vnet_get_sup_hw_interface (vnm, sw_if_index0);
	      t0 = &vxm->tunnels[hi0->dev_instance];
	      /* Note: change to always set next0 if it may be set to drop */
	      next0 = t0->next_dpo.dpoi_next_node;
	      dpoi_idx0 = t0->next_dpo.dpoi_index;
	    }
	  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpoi_idx0;

          ASSERT(vec_len(t0->rewrite) == underlay_hdr_len);
          vlib_buffer_advance (b0, -underlay_hdr_len);

 	  u32 len0 = vlib_buffer_length_in_chain (vm, b0);
          u16 payload_l0 = clib_host_to_net_u16 (len0 - l3_len);

          udp_header_t * udp0;
          ip4_header_t * ip4_0;
          ip6_header_t * ip6_0;
          u8 * l3_0;
	  if (is_ip4)
	    {
              ip4_vxlan_header_t * rewrite = (void *)t0->rewrite;
              ip4_vxlan_header_t * hdr = vlib_buffer_get_current(b0);
              *hdr = *rewrite;

	      /* Fix the IP4 checksum and length */
              ip4_0 = &hdr->ip4;
              ip4_0->length = clib_host_to_net_u16 (len0);

              l3_0 = (u8*)ip4_0;
	      udp0 = &hdr->udp;
	    }
	  else /* ip6 path */
	    {
              ip6_vxlan_header_t * hdr = vlib_buffer_get_current(b0);
              ip6_vxlan_header_t * rewrite = (void *) t0->rewrite;
              *hdr = *rewrite;

	      /* Fix IP6 payload length */
              ip6_0 = &hdr->ip6;
	      ip6_0->payload_length = payload_l0;

              l3_0 = (u8 *)ip6_0;
              udp0 = &hdr->udp;
	    }

          /* Fix UDP length  and set source port */
          udp0->length = payload_l0;
          udp0->src_port = flow_hash0;

          if (csum_offload)
            {
              b0->flags |= csum_flags;
              vnet_buffer (b0)->l3_hdr_offset = l3_0 - b0->data;
              vnet_buffer (b0)->l4_hdr_offset = (u8 *) udp0 - b0->data;
            }
          /* IPv4 UDP checksum only if checksum offload is used */
          else if (is_ip4)
            {
              ip_csum_t sum0 = ip4_0->checksum;
              sum0 = ip_csum_update (sum0, 0, ip4_0->length, ip4_header_t,
                  length /* changed member */);
              ip4_0->checksum = ip_csum_fold (sum0);
            }
          /* IPv6 UDP checksum is mandatory */
          else
            {
              int bogus = 0;

              udp0->checksum = ip6_tcp_udp_icmp_compute_checksum
                (vm, b0, ip6_0, &bogus);
              ASSERT(bogus == 0);
              if (udp0->checksum == 0)
                udp0->checksum = 0xffff;
            }

          vlib_increment_combined_counter (tx_counter, thread_index,
              sw_if_index0, 1, len0);
          pkts_encapsulated ++;

          if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) 
            {
              vxlan_encap_trace_t *tr = 
                vlib_add_trace (vm, node, b0, sizeof (*tr));
              tr->tunnel_index = t0 - vxm->tunnels;
              tr->vni = t0->vni;
            }
	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
					   to_next, n_left_to_next,
					   bi0, next0);
	}

      vlib_put_next_frame (vm, node, next_index, n_left_to_next);
    }

  /* Do we still need this now that tunnel tx stats is kept? */
  vlib_node_increment_counter (vm, node->node_index, 
                               VXLAN_ENCAP_ERROR_ENCAPSULATED, 
                               pkts_encapsulated);

  return from_frame->n_vectors;
}

static uword
vxlan4_encap (vlib_main_t * vm,
	      vlib_node_runtime_t * node,
	      vlib_frame_t * from_frame)
{
  /* Disable chksum offload as setup overhead in tx node is not worthwhile
     for ip4 header checksum only, unless udp checksum is also required */
  return vxlan_encap_inline (vm, node, from_frame, /* is_ip4 */ 1, 
			     /* csum_offload */ 0);
}

static uword
vxlan6_encap (vlib_main_t * vm,
	      vlib_node_runtime_t * node,
	      vlib_frame_t * from_frame)
{
  /* Enable checksum offload for ip6 as udp checksum is mandatory, */
  return vxlan_encap_inline (vm, node, from_frame, /* is_ip4 */ 0, 
			     /* csum_offload */ 1);
}

VLIB_REGISTER_NODE (vxlan4_encap_node) = {
  .function = vxlan4_encap,
  .name = "vxlan4-encap",
  .vector_size = sizeof (u32),
  .format_trace = format_vxlan_encap_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_errors = ARRAY_LEN(vxlan_encap_error_strings),
  .error_strings = vxlan_encap_error_strings,
  .n_next_nodes = VXLAN_ENCAP_N_NEXT,
  .next_nodes = {
        [VXLAN_ENCAP_NEXT_DROP] = "error-drop",
  },
};

VLIB_NODE_FUNCTION_MULTIARCH (vxlan4_encap_node, vxlan4_encap)

VLIB_REGISTER_NODE (vxlan6_encap_node) = {
  .function = vxlan6_encap,
  .name = "vxlan6-encap",
  .vector_size = sizeof (u32),
  .format_trace = format_vxlan_encap_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_errors = ARRAY_LEN(vxlan_encap_error_strings),
  .error_strings = vxlan_encap_error_strings,
  .n_next_nodes = VXLAN_ENCAP_N_NEXT,
  .next_nodes = {
        [VXLAN_ENCAP_NEXT_DROP] = "error-drop",
  },
};

VLIB_NODE_FUNCTION_MULTIARCH (vxlan6_encap_node, vxlan6_encap)

