aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
AgeCommit message (Collapse)AuthorFilesLines
2017-09-28General documentation updatesChris Luke1-7/+8
- We now have several developer-focused docs, so create an index page for them. - Rework several docs to fit into the index structure. - Experiment with code highlighting; tweak the CSS slightly to make it slightly nicer to look at. Change-Id: I4185a18f84fa0764745ca7a3148276064a3155c6 Signed-off-by: Chris Luke <chrisy@flirble.org>
2017-06-09Sample plugin: Add sample plugin documentationRay Kinsella1-1/+1
Added some user documentation to sample plugin. Change-Id: I518910f80499307e8fcac8dcef7baaeab5ea8e35 Signed-off-by: Ray Kinsella <ray.kinsella@intel.com>
2017-04-20Move vagrant stuff to extras/Damjan Marion1-2/+2
Change-Id: I7e3d6ecc3f23d862004c273e23e36e234ceb6015 Signed-off-by: Damjan Marion <damarion@cisco.com>
2017-02-22Add ref to test framework docs in doxygen output.Dave Wallace1-2/+6
Change-Id: If3081c4a9dde00cd522d1fc5a7daa9b1849684bf Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
2016-12-28Repair Doxygen build infrastructureChris Luke1-15/+15
After Gerrit 4430 much of the documentation failed to build, but silently so it was easily missed; equally missing that several paths have been missing for a while. - Correct paths after directory tree changes. - Doxygen now bails when input paths don't exist. - Fix up some of the less deranged entries in the documentation index. - Exclude the LUA tree, its documentation is a mess. Change-Id: I35e6b433feee5e05bca772d93aa1635c724db734 Signed-off-by: Chris Luke <chrisy@flirble.org>
2016-09-21Copy the 16.09 release notes to masterChris Luke1-7/+12
- Copy the 16.09 release notes to master - Add some notes for 16.06 (from the press release) - Add some structure around notes for each release - Add skeleton for next release Change-Id: Id5a5d8bf02fce1bbaed303e6c6e4f8908c7e7d75 Signed-off-by: Chris Luke <chrisy@flirble.org>
2016-09-20Add structure to some of the documentation; VPP-223Chris Luke1-1/+4
Moves the random .md files, when rendered by Doxygen, into a config examples tree. We may later flesh this out into a more complete user documentation section. Change-Id: If423b82f1047f1c84f90876a786313054b5f7c77 Signed-off-by: Chris Luke <chrisy@flirble.org>
2016-07-26VPP-165 Update directory list in READMEChris Luke1-1/+1
Change-Id: I7bc983860d6cc40f264e509e74b92978667324bc Signed-off-by: Chris Luke <chrisy@flirble.org>
2016-05-13VPP-57 Add Doxygen to VPPChris Luke1-0/+94
- Configures Doxygen. - Adds a source filter to do magic on our use of the preprocessor to do constructor stuff to make Doxygen grok it better. - Adds a convenience helper to the root Makefile. - Adds a README.md to the root directory (and which Doxygem uses as its "mainpage". - Add several other documentative files. - Currently using SVG for call graphs, though this may have a load-time performance impact in browsers. Change-Id: I25fc6fb5bf634319dcb36a7f0e32031921c125ac Signed-off-by: Chris Luke <chrisy@flirble.org>
lor: #f92672 } /* Operator */ .highlight .p { color: #f8f8f2 } /* Punctuation */ .highlight .ch { color: #75715e } /* Comment.Hashbang */ .highlight .cm { color: #75715e } /* Comment.Multiline */ .highlight .cp { color: #75715e } /* Comment.Preproc */ .highlight .cpf { color: #75715e } /* Comment.PreprocFile */ .highlight .c1 { color: #75715e } /* Comment.Single */ .highlight .cs { color: #75715e } /* Comment.Special */ .highlight .gd { color: #f92672 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gi { color: #a6e22e } /* Generic.Inserted */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #75715e } /* Generic.Subheading */ .highlight .kc { color: #66d9ef } /* Keyword.Constant */ .highlight .kd { color: #66d9ef } /* Keyword.Declaration */ .highlight .kn { color: #f92672 } /* Keyword.Namespace */ .highlight .kp { color: #66d9ef } /* Keyword.Pseudo */ .highlight .kr { color: #66d9ef } /* Keyword.Reserved */ .highlight .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .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 */ }
/*
 * p2p_ethernet.c: p2p ethernet
 *
 * Copyright (c) 2012 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/bihash_16_8.h>
#include <vnet/vnet.h>
#include <vnet/ethernet/p2p_ethernet.h>
#include <vnet/l2/l2_input.h>

p2p_ethernet_main_t p2p_main;

static void
create_p2pe_key (p2p_key_t * p2pe_key, u32 parent_if_index, u8 * client_mac)
{
  clib_memcpy (p2pe_key->mac, client_mac, 6);
  p2pe_key->pad1 = 0;
  p2pe_key->hw_if_index = parent_if_index;
  p2pe_key->pad2 = 0;
}

u32
p2p_ethernet_lookup (u32 parent_if_index, u8 * client_mac)
{
  p2p_ethernet_main_t *p2pm = &p2p_main;
  p2p_key_t p2pe_key;
  uword *p;

  create_p2pe_key (&p2pe_key, parent_if_index, client_mac);
  p = hash_get_mem (p2pm->p2p_ethernet_by_key, &p2pe_key);
  if (p)
    return p[0];

  return ~0;
}

int
p2p_ethernet_add_del (vlib_main_t * vm, u32 parent_if_index,
		      u8 * client_mac, u32 p2pe_subif_id, int is_add,
		      u32 * p2pe_if_index)
{
  vnet_main_t *vnm = vnet_get_main ();
  p2p_ethernet_main_t *p2pm = &p2p_main;
  vnet_interface_main_t *im = &vnm->interface_main;

  u32 p2pe_sw_if_index = ~0;
  p2pe_sw_if_index = p2p_ethernet_lookup (parent_if_index, client_mac);

  if (p2pe_if_index)
    *p2pe_if_index = ~0;

  if (is_add)
    {
      if (p2pe_sw_if_index == ~0)
	{
	  vnet_hw_interface_t *hi;

	  hi = vnet_get_hw_interface (vnm, parent_if_index);
	  if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
	    return VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED;

	  u64 sup_and_sub_key =
	    ((u64) (hi->sw_if_index) << 32) | (u64) p2pe_subif_id;
	  uword *p;
	  p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
	  if (p)
	    {
	      if (CLIB_DEBUG > 0)
		clib_warning
		  ("p2p ethernet sub-interface on sw_if_index %d with sub id %d already exists\n",
		   hi->sw_if_index, p2pe_subif_id);
	      return VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
	    }
	  vnet_sw_interface_t template = {
	    .type = VNET_SW_INTERFACE_TYPE_P2P,
	    .flood_class = VNET_FLOOD_CLASS_NORMAL,
	    .sup_sw_if_index = hi->sw_if_index,
	    .sub.id = p2pe_subif_id
	  };

	  clib_memcpy (template.p2p.client_mac, client_mac,
		       sizeof (template.p2p.client_mac));

	  if (vnet_create_sw_interface (vnm, &template, &p2pe_sw_if_index))
	    return VNET_API_ERROR_SUBIF_CREATE_FAILED;

	  /* Allocate counters for this interface. */
	  {
	    u32 i;

	    vnet_interface_counter_lock (im);

	    for (i = 0; i < vec_len (im->sw_if_counters); i++)
	      {
		vlib_validate_simple_counter (&im->sw_if_counters[i],
					      p2pe_sw_if_index);
		vlib_zero_simple_counter (&im->sw_if_counters[i],
					  p2pe_sw_if_index);
	      }

	    for (i = 0; i < vec_len (im->combined_sw_if_counters); i++)
	      {
		vlib_validate_combined_counter (&im->combined_sw_if_counters
						[i], p2pe_sw_if_index);
		vlib_zero_combined_counter (&im->combined_sw_if_counters[i],
					    p2pe_sw_if_index);
	      }

	    vnet_interface_counter_unlock (im);
	  }

	  vnet_interface_main_t *im = &vnm->interface_main;
	  sup_and_sub_key =
	    ((u64) (hi->sw_if_index) << 32) | (u64) p2pe_subif_id;
	  u64 *kp = clib_mem_alloc (sizeof (*kp));

	  *kp = sup_and_sub_key;
	  hash_set (hi->sub_interface_sw_if_index_by_id, p2pe_subif_id,
		    p2pe_sw_if_index);
	  hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, p2pe_sw_if_index);

	  p2p_key_t *p_p2pe_key;
	  p_p2pe_key = clib_mem_alloc (sizeof (*p_p2pe_key));
	  create_p2pe_key (p_p2pe_key, parent_if_index, client_mac);
	  hash_set_mem (p2pm->p2p_ethernet_by_key, p_p2pe_key,
			p2pe_sw_if_index);

	  if (p2pe_if_index)
	    *p2pe_if_index = p2pe_sw_if_index;

	  vec_validate (p2pm->p2p_ethernet_by_sw_if_index, parent_if_index);
	  if (p2pm->p2p_ethernet_by_sw_if_index[parent_if_index] == 0)
	    {
	      vnet_feature_enable_disable ("device-input",
					   "p2p-ethernet-input",
					   parent_if_index, 1, 0, 0);
	      /* Set promiscuous mode on the l2 interface */
	      ethernet_set_flags (vnm, parent_if_index,
				  ETHERNET_INTERFACE_FLAG_ACCEPT_ALL);

	    }
	  p2pm->p2p_ethernet_by_sw_if_index[parent_if_index]++;
	  /* set the interface mode */
	  set_int_l2_mode (vm, vnm, MODE_L3, p2pe_subif_id, 0, 0, 0, 0);
	  return 0;
	}
      return VNET_API_ERROR_SUBIF_ALREADY_EXISTS;
    }
  else
    {
      if (p2pe_sw_if_index == ~0)
	return VNET_API_ERROR_SUBIF_DOESNT_EXIST;
      else
	{
	  int rv = 0;
	  rv = vnet_delete_sub_interface (p2pe_sw_if_index);
	  if (!rv)
	    {
	      vec_validate (p2pm->p2p_ethernet_by_sw_if_index,
			    parent_if_index);
	      if (p2pm->p2p_ethernet_by_sw_if_index[parent_if_index] == 1)
		{
		  vnet_feature_enable_disable ("device-input",
					       "p2p-ethernet-input",
					       parent_if_index, 0, 0, 0);
		  /* Disable promiscuous mode on the l2 interface */
		  ethernet_set_flags (vnm, parent_if_index, 0);
		}
	      p2pm->p2p_ethernet_by_sw_if_index[parent_if_index]--;

	      /* Remove p2p_ethernet from hash map */
	      p2p_key_t *p_p2pe_key;
	      p_p2pe_key = clib_mem_alloc (sizeof (*p_p2pe_key));
	      create_p2pe_key (p_p2pe_key, parent_if_index, client_mac);
	      hash_unset_mem (p2pm->p2p_ethernet_by_key, p_p2pe_key);
	    }
	  return rv;
	}
    }
}

static clib_error_t *
vnet_p2p_ethernet_add_del (vlib_main_t * vm, unformat_input_t * input,
			   vlib_cli_command_t * cmd)
{
  vnet_main_t *vnm = vnet_get_main ();

  int is_add = 1;
  int remote_mac = 0;
  u32 hw_if_index = ~0;
  u32 sub_id = ~0;
  u8 client_mac[6];

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat
	  (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
	;
      else if (unformat (input, "%U", unformat_ethernet_address, &client_mac))
	remote_mac = 1;
      else if (unformat (input, "sub-id %d", &sub_id))
	;
      else if (unformat (input, "del"))
	is_add = 0;
      else
	break;
    }

  if (hw_if_index == ~0)
    return clib_error_return (0, "Please specify parent interface ...");
  if (!remote_mac)
    return clib_error_return (0, "Please specify client MAC address ...");
  if (sub_id == ~0 && is_add)
    return clib_error_return (0, "Please specify sub-interface id ...");

  u32 rv;
  rv = p2p_ethernet_add_del (vm, hw_if_index, client_mac, sub_id, is_add, 0);
  switch (rv)
    {
    case VNET_API_ERROR_BOND_SLAVE_NOT_ALLOWED:
      return clib_error_return (0,
				"not allowed as parent interface belongs to a BondEthernet interface");
    case -1:
      return clib_error_return (0,
				"p2p ethernet for given parent interface and client mac already exists");
    case -2:
      return clib_error_return (0,
				"couldn't create p2p ethernet subinterface");
    case -3:
      return clib_error_return (0,
				"p2p ethernet for given parent interface and client mac doesn't exist");
    default:
      break;
    }
  return 0;
}

VLIB_CLI_COMMAND (p2p_ethernet_add_del_command, static) =
{
.path = "p2p_ethernet ",.function = vnet_p2p_ethernet_add_del,.short_help =
    "p2p_ethernet <intfc> <mac-address> [sub-id <id> | del]",};

static clib_error_t *
p2p_ethernet_init (vlib_main_t * vm)
{
  p2p_ethernet_main_t *p2pm = &p2p_main;

  p2pm->vlib_main = vm;
  p2pm->vnet_main = vnet_get_main ();
  p2pm->p2p_ethernet_by_key =
    hash_create_mem (0, sizeof (p2p_key_t), sizeof (uword));

  return 0;
}

VLIB_INIT_FUNCTION (p2p_ethernet_init);

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