aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/java/jvpp-registry/io/fd
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2017-07-31 02:30:50 -0700
committerDamjan Marion <dmarion.lists@gmail.com>2017-10-10 16:42:39 +0000
commitd91c1dbdb31f80db7d967f2f57c43d0a81d65297 (patch)
treec7d323cd6980b6fc7c5d96157607a07e51efa468 /src/vpp-api/java/jvpp-registry/io/fd
parent268e64e312257b0ab36e0d5b9124cc3f2a1841a7 (diff)
punt and drop features:
- new IPv4 and IPv6 feature arcs on the punt and drop nodes - new features: - redirect punted traffic to an interface and nexthop - police punted traffic. Change-Id: I53be8bf4e06545add8a3619e462de5ffedd0a95c Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vpp-api/java/jvpp-registry/io/fd')
0 files changed, 0 insertions, 0 deletions
6 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
/*
 * Copyright (c) 2016 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/vxlan-gpe/vxlan_gpe.h>
#include <vnet/vxlan-gpe/vxlan_gpe_packet.h>
#include <vnet/ip/format.h>
#include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
#include <vnet/fib/ip6_fib.h>
#include <vnet/fib/ip4_fib.h>
#include <vnet/fib/fib_entry.h>

vxlan_gpe_ioam_main_t vxlan_gpe_ioam_main;

int
vxlan_gpe_ioam_set_rewrite (vxlan_gpe_tunnel_t * t, int has_trace_option,
			    int has_pot_option, int has_ppc_option,
			    u8 ipv6_set)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  u32 size;
  vxlan_gpe_ioam_hdr_t *vxlan_gpe_ioam_hdr;
  u8 *current;
  u8 trace_data_size = 0;
  u8 pot_data_size = 0;

  if (has_trace_option == 0 && has_pot_option == 0)
    return -1;

  /* Work out how much space we need */
  size = sizeof (vxlan_gpe_ioam_hdr_t);

  if (has_trace_option
      && hm->add_options[VXLAN_GPE_OPTION_TYPE_IOAM_TRACE] != 0)
    {
      size += sizeof (vxlan_gpe_ioam_option_t);
      size += hm->options_size[VXLAN_GPE_OPTION_TYPE_IOAM_TRACE];
    }
  if (has_pot_option
      && hm->add_options[VXLAN_GPE_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] != 0)
    {
      size += sizeof (vxlan_gpe_ioam_option_t);
      size += hm->options_size[VXLAN_GPE_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT];
    }

  t->rewrite_size = size;

  if (!ipv6_set)
    {
      vxlan4_gpe_rewrite (t, size, VXLAN_GPE_PROTOCOL_IOAM,
			  hm->encap_v4_next_node);
      vxlan_gpe_ioam_hdr =
	(vxlan_gpe_ioam_hdr_t *) (t->rewrite +
				  sizeof (ip4_vxlan_gpe_header_t));
    }
  else
    {
      vxlan6_gpe_rewrite (t, size, VXLAN_GPE_PROTOCOL_IOAM,
			  VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
      vxlan_gpe_ioam_hdr =
	(vxlan_gpe_ioam_hdr_t *) (t->rewrite +
				  sizeof (ip6_vxlan_gpe_header_t));
    }


  vxlan_gpe_ioam_hdr->type = VXLAN_GPE_PROTOCOL_IOAM;
  /* Length of the header in octets */
  vxlan_gpe_ioam_hdr->length = size;
  vxlan_gpe_ioam_hdr->protocol = t->protocol;
  current = (u8 *) vxlan_gpe_ioam_hdr + sizeof (vxlan_gpe_ioam_hdr_t);

  if (has_trace_option
      && hm->add_options[VXLAN_GPE_OPTION_TYPE_IOAM_TRACE] != 0)
    {
      if (0 != hm->add_options[VXLAN_GPE_OPTION_TYPE_IOAM_TRACE] (current,
								  &trace_data_size))
	return -1;
      current += trace_data_size;
    }
  if (has_pot_option
      && hm->add_options[VXLAN_GPE_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT] != 0)
    {
      pot_data_size =
	hm->options_size[VXLAN_GPE_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT];
      if (0 ==
	  hm->add_options[VXLAN_GPE_OPTION_TYPE_IOAM_PROOF_OF_TRANSIT]
	  (current, &pot_data_size))
	current += pot_data_size;
    }

  return 0;
}

int
vxlan_gpe_ioam_clear_rewrite (vxlan_gpe_tunnel_t * t, int has_trace_option,
			      int has_pot_option, int has_ppc_option,
			      u8 ipv6_set)
{

  t->rewrite_size = 0;

  if (!ipv6_set)
    {
      vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP);
    }
  else
    {
      vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP);
    }


  return 0;
}

clib_error_t *
vxlan_gpe_ioam_clear (vxlan_gpe_tunnel_t * t,
		      int has_trace_option, int has_pot_option,
		      int has_ppc_option, u8 ipv6_set)
{
  int rv;
  rv = vxlan_gpe_ioam_clear_rewrite (t, 0, 0, 0, 0);

  if (rv == 0)
    {
      return (0);
    }
  else
    {
      return clib_error_return_code (0, rv, 0,
				     "vxlan_gpe_ioam_clear_rewrite returned %d",
				     rv);
    }

}


clib_error_t *
vxlan_gpe_ioam_set (vxlan_gpe_tunnel_t * t,
		    int has_trace_option, int has_pot_option,
		    int has_ppc_option, u8 ipv6_set)
{
  int rv;
  rv = vxlan_gpe_ioam_set_rewrite (t, has_trace_option,
				   has_pot_option, has_ppc_option, ipv6_set);

  if (rv == 0)
    {
      return (0);
    }
  else
    {
      return clib_error_return_code (0, rv, 0,
				     "vxlan_gpe_ioam_set_rewrite returned %d",
				     rv);
    }

}

static void
vxlan_gpe_set_clear_output_feature_on_intf (vlib_main_t * vm,
					    u32 sw_if_index0, u8 is_add)
{



  vnet_feature_enable_disable ("ip4-output", "vxlan-gpe-transit-ioam",
			       sw_if_index0, is_add,
			       0 /* void *feature_config */ ,
			       0 /* u32 n_feature_config_bytes */ );
  return;
}

void
vxlan_gpe_clear_output_feature_on_all_intfs (vlib_main_t * vm)
{
  vnet_sw_interface_t *si = 0;
  vnet_main_t *vnm = vnet_get_main ();
  vnet_interface_main_t *im = &vnm->interface_main;

  pool_foreach (si, im->sw_interfaces, (
					 {
					 vxlan_gpe_set_clear_output_feature_on_intf
					 (vm, si->sw_if_index, 0);
					 }));
  return;
}


extern fib_forward_chain_type_t
fib_entry_get_default_chain_type (const fib_entry_t * fib_entry);

int
vxlan_gpe_enable_disable_ioam_for_dest (vlib_main_t * vm,
					ip46_address_t dst_addr,
					u32 outer_fib_index,
					u8 is_ipv4, u8 is_add)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  u32 fib_index0 = 0;
  u32 sw_if_index0 = ~0;

  fib_node_index_t fei = ~0;
  fib_entry_t *fib_entry;
  u32 adj_index0;
  ip_adjacency_t *adj0;
  fib_prefix_t fib_prefix;
  //fib_forward_chain_type_t fct;
  load_balance_t *lb_m, *lb_b;
  const dpo_id_t *dpo0, *dpo1;
  u32 i, j;
  //vnet_hw_interface_t *hw;

  if (is_ipv4)
    {
      memset (&fib_prefix, 0, sizeof (fib_prefix_t));
      fib_prefix.fp_len = 32;
      fib_prefix.fp_proto = FIB_PROTOCOL_IP4;
      fib_prefix.fp_addr = dst_addr;
    }
  else
    {
      return 0;
    }

  fei = fib_table_lookup (fib_index0, &fib_prefix);
  fib_entry = fib_entry_get (fei);

  //fct = fib_entry_get_default_chain_type (fib_entry);

  if (!dpo_id_is_valid (&fib_entry->fe_lb /*[fct] */ ))
    {
      return (-1);
    }

  lb_m = load_balance_get (fib_entry->fe_lb /*[fct] */ .dpoi_index);

  for (i = 0; i < lb_m->lb_n_buckets; i++)
    {
      dpo0 = load_balance_get_bucket_i (lb_m, i);

      if (dpo0->dpoi_type == DPO_LOAD_BALANCE)
	{
	  lb_b = load_balance_get (dpo0->dpoi_index);

	  for (j = 0; j < lb_b->lb_n_buckets; j++)
	    {
	      dpo1 = load_balance_get_bucket_i (lb_b, j);

	      if (dpo1->dpoi_type == DPO_ADJACENCY)
		{
		  adj_index0 = dpo1->dpoi_index;

		  if (ADJ_INDEX_INVALID == adj_index0)
		    {
		      continue;
		    }

		  adj0 =
		    ip_get_adjacency (&(ip4_main.lookup_main), adj_index0);
		  sw_if_index0 = adj0->rewrite_header.sw_if_index;

		  if (~0 == sw_if_index0)
		    {
		      continue;
		    }


		  if (is_add)
		    {
		      vnet_feature_enable_disable ("ip4-output",
						   "vxlan-gpe-transit-ioam",
						   sw_if_index0, is_add, 0
						   /* void *feature_config */
						   , 0	/* u32 n_feature_config_bytes */
			);

		      vec_validate_init_empty (hm->bool_ref_by_sw_if_index,
					       sw_if_index0, ~0);
		      hm->bool_ref_by_sw_if_index[sw_if_index0] = 1;
		    }
		  else
		    {
		      hm->bool_ref_by_sw_if_index[sw_if_index0] = ~0;
		    }
		}
	    }
	}
    }

  if (is_ipv4)
    {

      uword *t = NULL;
      vxlan_gpe_ioam_dest_tunnels_t *t1;
      fib_prefix_t key4, *key4_copy;
      hash_pair_t *hp;
      memset (&key4, 0, sizeof (key4));
      key4.fp_proto = FIB_PROTOCOL_IP4;
      key4.fp_addr.ip4.as_u32 = fib_prefix.fp_addr.ip4.as_u32;
      t = hash_get_mem (hm->dst_by_ip4, &key4);
      if (is_add)
	{
	  if (t)
	    {
	      return 0;
	    }
	  pool_get_aligned (hm->dst_tunnels, t1, CLIB_CACHE_LINE_BYTES);
	  memset (t1, 0, sizeof (*t1));
	  t1->fp_proto = FIB_PROTOCOL_IP4;
	  t1->dst_addr.ip4.as_u32 = fib_prefix.fp_addr.ip4.as_u32;
	  key4_copy = clib_mem_alloc (sizeof (*key4_copy));
	  clib_memcpy (key4_copy, &key4, sizeof (*key4_copy));
	  hash_set_mem (hm->dst_by_ip4, key4_copy, t1 - hm->dst_tunnels);
	  /*
	   * Attach to the FIB entry for the VxLAN-GPE destination
	   * and become its child. The dest route will invoke a callback
	   * when the fib entry changes, it can be used to
	   * re-program the output feature on the egress interface.
	   */

	  const fib_prefix_t tun_dst_pfx = {
	    .fp_len = 32,
	    .fp_proto = FIB_PROTOCOL_IP4,
	    .fp_addr = {.ip4 = t1->dst_addr.ip4,}
	  };

	  t1->fib_entry_index =
	    fib_table_entry_special_add (outer_fib_index,
					 &tun_dst_pfx,
					 FIB_SOURCE_RR,
					 FIB_ENTRY_FLAG_NONE,
					 ADJ_INDEX_INVALID);
	  t1->sibling_index =
	    fib_entry_child_add (t1->fib_entry_index,
				 hm->fib_entry_type, t1 - hm->dst_tunnels);
	  t1->outer_fib_index = outer_fib_index;

	}
      else
	{
	  if (!t)
	    {
	      return 0;
	    }
	  t1 = pool_elt_at_index (hm->dst_tunnels, t[0]);
	  hp = hash_get_pair (hm->dst_by_ip4, &key4);
	  key4_copy = (void *) (hp->key);
	  hash_unset_mem (hm->dst_by_ip4, &key4);
	  clib_mem_free (key4_copy);
	  pool_put (hm->dst_tunnels, t1);
	}
    }
  else
    {
      // TBD for IPv6
    }

  return 0;
}

void
vxlan_gpe_refresh_output_feature_on_all_dest (void)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  vxlan_gpe_ioam_dest_tunnels_t *t;
  u32 i;
  if (pool_elts (hm->dst_tunnels) == 0)
    return;
  vxlan_gpe_clear_output_feature_on_all_intfs (hm->vlib_main);
  i = vec_len (hm->bool_ref_by_sw_if_index);
  vec_free (hm->bool_ref_by_sw_if_index);
  vec_validate_init_empty (hm->bool_ref_by_sw_if_index, i, ~0);
  pool_foreach (t, hm->dst_tunnels, (
				      {
				      vxlan_gpe_enable_disable_ioam_for_dest
				      (hm->vlib_main,
				       t->dst_addr,
				       t->outer_fib_index,
				       (t->fp_proto == FIB_PROTOCOL_IP4), 1
				       /* is_add */
				      );
				      }
		));
  return;
}

void
vxlan_gpe_clear_output_feature_on_select_intfs (void)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  u32 sw_if_index0 = 0;
  for (sw_if_index0 = 0;
       sw_if_index0 < vec_len (hm->bool_ref_by_sw_if_index); sw_if_index0++)
    {
      if (hm->bool_ref_by_sw_if_index[sw_if_index0] == 0xFF)
	{
	  vxlan_gpe_set_clear_output_feature_on_intf
	    (hm->vlib_main, sw_if_index0, 0);
	}
    }

  return;
}

static clib_error_t *
vxlan_gpe_set_ioam_rewrite_command_fn (vlib_main_t *
				       vm,
				       unformat_input_t
				       * input, vlib_cli_command_t * cmd)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  ip46_address_t local, remote;
  u8 local_set = 0;
  u8 remote_set = 0;
  u8 ipv4_set = 0;
  u8 ipv6_set = 0;
  u32 vni;
  u8 vni_set = 0;
  u8 disable = 0;
  clib_error_t *rv = 0;
  vxlan4_gpe_tunnel_key_t key4;
  vxlan6_gpe_tunnel_key_t key6;
  uword *p;
  vxlan_gpe_main_t *gm = &vxlan_gpe_main;
  vxlan_gpe_tunnel_t *t = 0;
  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "local %U", unformat_ip4_address, &local.ip4))
	{
	  local_set = 1;
	  ipv4_set = 1;
	}
      else
	if (unformat (input, "remote %U", unformat_ip4_address, &remote.ip4))
	{
	  remote_set = 1;
	  ipv4_set = 1;
	}
      else if (unformat (input, "local %U", unformat_ip6_address, &local.ip6))
	{
	  local_set = 1;
	  ipv6_set = 1;
	}
      else
	if (unformat (input, "remote %U", unformat_ip6_address, &remote.ip6))
	{
	  remote_set = 1;
	  ipv6_set = 1;
	}
      else if (unformat (input, "vni %d", &vni))
	vni_set = 1;
      else if (unformat (input, "disable"))
	disable = 1;
      else
	break;
    }

  if (local_set == 0)
    return clib_error_return (0, "tunnel local address not specified");
  if (remote_set == 0)
    return clib_error_return (0, "tunnel remote address not specified");
  if (ipv4_set && ipv6_set)
    return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
  if ((ipv4_set
       && memcmp (&local.ip4, &remote.ip4,
		  sizeof (local.ip4)) == 0) || (ipv6_set
						&&
						memcmp
						(&local.ip6,
						 &remote.ip6,
						 sizeof (local.ip6)) == 0))
    return clib_error_return (0, "src and dst addresses are identical");
  if (vni_set == 0)
    return clib_error_return (0, "vni not specified");
  if (!ipv6_set)
    {
      key4.local = local.ip4.as_u32;
      key4.remote = remote.ip4.as_u32;
      key4.vni = clib_host_to_net_u32 (vni << 8);
      key4.pad = 0;
      p = hash_get_mem (gm->vxlan4_gpe_tunnel_by_key, &key4);
    }
  else
    {
      key6.local.as_u64[0] = local.ip6.as_u64[0];
      key6.local.as_u64[1] = local.ip6.as_u64[1];
      key6.remote.as_u64[0] = remote.ip6.as_u64[0];
      key6.remote.as_u64[1] = remote.ip6.as_u64[1];
      key6.vni = clib_host_to_net_u32 (vni << 8);
      p = hash_get_mem (gm->vxlan6_gpe_tunnel_by_key, &key6);
    }

  if (!p)
    return clib_error_return (0, "VxLAN Tunnel not found");
  t = pool_elt_at_index (gm->tunnels, p[0]);
  if (!disable)
    {
      rv =
	vxlan_gpe_ioam_set (t, hm->has_trace_option,
			    hm->has_pot_option, hm->has_ppc_option, ipv6_set);
    }
  else
    {
      rv = vxlan_gpe_ioam_clear (t, 0, 0, 0, 0);
    }
  return rv;
}


/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vxlan_gpe_set_ioam_rewrite_cmd, static) = {
  .path = "set vxlan-gpe-ioam",
  .short_help = "set vxlan-gpe-ioam vxlan <src-ip> <dst_ip> <vnid> [disable]",
  .function = vxlan_gpe_set_ioam_rewrite_command_fn,
};
/* *INDENT-ON* */



clib_error_t *
vxlan_gpe_ioam_enable (int has_trace_option,
		       int has_pot_option, int has_ppc_option)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  hm->has_trace_option = has_trace_option;
  hm->has_pot_option = has_pot_option;
  hm->has_ppc_option = has_ppc_option;
  if (hm->has_trace_option)
    {
      vxlan_gpe_trace_profile_setup ();
    }

  return 0;
}

clib_error_t *
vxlan_gpe_ioam_disable (int
			has_trace_option,
			int has_pot_option, int has_ppc_option)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  hm->has_trace_option = has_trace_option;
  hm->has_pot_option = has_pot_option;
  hm->has_ppc_option = has_ppc_option;
  if (!hm->has_trace_option)
    {
      vxlan_gpe_trace_profile_cleanup ();
    }

  return 0;
}

void
vxlan_gpe_set_next_override (uword next)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  hm->decap_v4_next_override = next;
  return;
}

static clib_error_t *
vxlan_gpe_set_ioam_flags_command_fn (vlib_main_t * vm,
				     unformat_input_t
				     * input, vlib_cli_command_t * cmd)
{
  int has_trace_option = 0;
  int has_pot_option = 0;
  int has_ppc_option = 0;
  clib_error_t *rv = 0;
  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "trace"))
	has_trace_option = 1;
      else if (unformat (input, "pot"))
	has_pot_option = 1;
      else if (unformat (input, "ppc encap"))
	has_ppc_option = PPC_ENCAP;
      else if (unformat (input, "ppc decap"))
	has_ppc_option = PPC_DECAP;
      else if (unformat (input, "ppc none"))
	has_ppc_option = PPC_NONE;
      else
	break;
    }


  rv =
    vxlan_gpe_ioam_enable (has_trace_option, has_pot_option, has_ppc_option);
  return rv;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vxlan_gpe_set_ioam_flags_cmd, static) =
{
.path = "set vxlan-gpe-ioam rewrite",
.short_help = "set vxlan-gpe-ioam [trace] [pot] [ppc <encap|decap>]",
.function = vxlan_gpe_set_ioam_flags_command_fn,};
/* *INDENT-ON* */


int vxlan_gpe_ioam_disable_for_dest
  (vlib_main_t * vm, ip46_address_t dst_addr, u32 outer_fib_index,
   u8 ipv4_set)
{
  vxlan_gpe_ioam_dest_tunnels_t *t;
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;

  vxlan_gpe_enable_disable_ioam_for_dest (hm->vlib_main,
					  dst_addr, outer_fib_index, ipv4_set,
					  0);
  if (pool_elts (hm->dst_tunnels) == 0)
    {
      vxlan_gpe_clear_output_feature_on_select_intfs ();
      return 0;
    }

  pool_foreach (t, hm->dst_tunnels, (
				      {
				      vxlan_gpe_enable_disable_ioam_for_dest
				      (hm->vlib_main,
				       t->dst_addr,
				       t->outer_fib_index,
				       (t->fp_proto ==
					FIB_PROTOCOL_IP4), 1 /* is_add */ );
				      }
		));
  vxlan_gpe_clear_output_feature_on_select_intfs ();
  return (0);

}

static clib_error_t *vxlan_gpe_set_ioam_transit_rewrite_command_fn
  (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  ip46_address_t dst_addr;
  u8 dst_addr_set = 0;
  u8 ipv4_set = 0;
  u8 ipv6_set = 0;
  u8 disable = 0;
  clib_error_t *rv = 0;
  u32 outer_fib_index = 0;
  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "dst-ip %U", unformat_ip4_address, &dst_addr.ip4))
	{
	  dst_addr_set = 1;
	  ipv4_set = 1;
	}
      else
	if (unformat
	    (input, "dst-ip %U", unformat_ip6_address, &dst_addr.ip6))
	{
	  dst_addr_set = 1;
	  ipv6_set = 1;
	}
      else if (unformat (input, "outer-fib-index %d", &outer_fib_index))
	{
	}

      else if (unformat (input, "disable"))
	disable = 1;
      else
	break;
    }

  if (dst_addr_set == 0)
    return clib_error_return (0, "tunnel destination address not specified");
  if (ipv4_set && ipv6_set)
    return clib_error_return (0, "both IPv4 and IPv6 addresses specified");
  if (!disable)
    {
      vxlan_gpe_enable_disable_ioam_for_dest (hm->vlib_main,
					      dst_addr, outer_fib_index,
					      ipv4_set, 1);
    }
  else
    {
      vxlan_gpe_ioam_disable_for_dest
	(vm, dst_addr, outer_fib_index, ipv4_set);
    }
  return rv;
}

       /* *INDENT-OFF* */
VLIB_CLI_COMMAND (vxlan_gpe_set_ioam_transit_rewrite_cmd, static) = {
  .path = "set vxlan-gpe-ioam-transit",
  .short_help = "set vxlan-gpe-ioam-transit dst-ip <dst_ip> [outer-fib-index <outer_fib_index>] [disable]",
  .function = vxlan_gpe_set_ioam_transit_rewrite_command_fn,
};
/* *INDENT-ON* */

clib_error_t *clear_vxlan_gpe_ioam_rewrite_command_fn
  (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{
  return (vxlan_gpe_ioam_disable (0, 0, 0));
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (vxlan_gpe_clear_ioam_flags_cmd, static) =
{
.path = "clear vxlan-gpe-ioam rewrite",
.short_help = "clear vxlan-gpe-ioam rewrite",
.function = clear_vxlan_gpe_ioam_rewrite_command_fn,
};
/* *INDENT-ON* */


/**
 * Function definition to backwalk a FIB node
 */
static fib_node_back_walk_rc_t
vxlan_gpe_ioam_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx)
{
  vxlan_gpe_refresh_output_feature_on_all_dest ();
  return (FIB_NODE_BACK_WALK_CONTINUE);
}

/**
 * Function definition to get a FIB node from its index
 */
static fib_node_t *
vxlan_gpe_ioam_fib_node_get (fib_node_index_t index)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  return (&hm->node);
}

/**
 * Function definition to inform the FIB node that its last lock has gone.
 */
static void
vxlan_gpe_ioam_last_lock_gone (fib_node_t * node)
{
  ASSERT (0);
}


/*
 * Virtual function table registered by MPLS GRE tunnels
 * for participation in the FIB object graph.
 */
const static fib_node_vft_t vxlan_gpe_ioam_vft = {
  .fnv_get = vxlan_gpe_ioam_fib_node_get,
  .fnv_last_lock = vxlan_gpe_ioam_last_lock_gone,
  .fnv_back_walk = vxlan_gpe_ioam_back_walk,
};

void
vxlan_gpe_ioam_interface_init (void)
{
  vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
  hm->fib_entry_type = fib_node_register_new_type (&vxlan_gpe_ioam_vft);
  return;
}

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