summaryrefslogtreecommitdiffstats
path: root/src/vnet/ethernet/mac_address.h
AgeCommit message (Collapse)AuthorFilesLines
2020-03-18ethernet: Copy only 6 bytes of mac address into a u64Jon Loeliger1-3/+3
Rather than leaving 2 bytes of junk in the upper word of a mac address represented as a u64, zero them out. That way later compairsons stand a chance of matching when deleting a bridge's arp termination entries. The volatile qualifier shouldn't be needed here, but without it the compiler removes the clib_memcpy() at -O2. Bad compiler. No biscuit. Type: fix commit: faf22cb303b65e2a6bf8dad959d7f5ee6d031c4f Change-Id: Iebcf35fdd421293dccbcaefadef767f7e139438e Signed-off-by: Jon Loeliger <jdl@netgate.com>
2020-02-24ethernet: trivial additionsNeale Ranns1-0/+6
Type: improvement - macros to identify SENDER and TARGET in ARP header - count the number of bits set in a mac_address Signed-off-by: Neale Ranns <nranns@cisco.com> Change-Id: Id31e27a4f5f01a8cfb70d3798416bb2519981654
2019-12-17ip: Protocol Independent IP NeighborsNeale Ranns1-0/+1
Type: feature - ip-neighbour: generic neighbour handling; APIs, DBs, event handling, aging - arp: ARP protocol implementation - ip6-nd; IPv6 neighbor discovery implementation; separate ND, MLD, RA - ip6-link; manage link-local addresses - l2-arp-term; events separated from IP neighbours, since they are not the same. vnet retains just enough education to perform ND/ARP packet construction. arp and ip6-nd to be moved to plugins soon. Change-Id: I88dedd0006b299344f4c7024a0aa5baa6b9a8bbe Signed-off-by: Neale Ranns <nranns@cisco.com>
2019-03-28Add RDMA ibverb driver pluginBenoît Ganne1-0/+11
RDMA ibverb is a userspace API to efficiently rx/tx packets. This is an initial, unoptimized driver targeting Mellanox cards. Next steps should include batching, multiqueue and additional cards. Change-Id: I0309c7a543f75f2f9317eaf63ca502ac7a093ef9 Signed-off-by: Benoît Ganne <bganne@cisco.com>
2019-01-30Use IP and MAC API types for neighborsNeale Ranns1-4/+64
use address_t and mac_address_t for IPv6 and ARP entries and all other API calls in ip.api aprat from the route ones, that will follow in a separate commit Change-Id: I67161737c2184d3f8fc1e79ebd2b55121c5b0191 Signed-off-by: Neale Ranns <nranns@cisco.com>
2018-11-18mac_address_t: size to 6 bytes so it represents wire formatNeale Ranns1-7/+15
Change-Id: I4d6b505a2b1e0cb960a4145796351ad1bc7e860d Signed-off-by: Neale Ranns <nranns@cisco.com>
2018-11-07GBP Endpoint LearningNeale Ranns1-0/+13
Learning GBP endpoints over vxlan-gbp tunnels Change-Id: I1db9fda5a16802d9ad8b4efd4e475614f3b21502 Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
2018-11-06BD ARP entry use common API typesNeale Ranns1-5/+13
Change-Id: I29f20dbaf2c2d735faff297cee552ed648f6f61b Signed-off-by: Neale Ranns <nranns@cisco.com>
2018-11-05Genric API types format/unformat support for VAT and custom dumpNeale Ranns1-0/+2
Change-Id: I8bc3a991f0ede0605d78b51ba609fbe5889513f2 Signed-off-by: Neale Ranns <nranns@cisco.com>
2018-08-31Introduce a mac_address_t on the API and in VPPNeale Ranns1-0/+62
Change-Id: I05d6c2cb5d34de469eb050e4ee10dc6b954c986d Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
ight .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 */ }
/*
  Copyright (c) 2011 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/anneal.h>

/*
 * Optimize an objective function by simulated annealing
 *
 * Here are a couple of short, easily-understood
 * descriptions of simulated annealing:
 *
 * http://www.cs.sandia.gov/opt/survey/sa.html
 * Numerical Recipes in C, 2nd ed., 444ff
 *
 * The description in the Wikipedia is not helpful.
 *
 * The algorithm tries to produce a decent answer to combinatorially
 * explosive optimization problems by analogy to slow cooling
 * of hot metal, aka annealing.
 *
 * There are (at least) three problem-dependent annealing parameters
 * to consider:
 *
 * t0, the initial "temperature. Should be set so that the probability
 * of accepting a transition to a higher cost configuration is
 * initially about 0.8.
 *
 * ntemps, the number of temperatures to use. Each successive temperature
 * is some fraction of the previous temperature.
 *
 * nmoves_per_temp, the number of configurations to try at each temperature
 *
 * It is a black art to set ntemps, nmoves_per_temp, and the rate
 * at which the temperature drops. Go too fast with too few iterations,
 * and the computation falls into a local minimum instead of the
 * (desired) global minimum.
 */

void
clib_anneal (clib_anneal_param_t * p)
{
  f64 t;
  f64 cost, prev_cost, delta_cost, initial_cost, best_cost;
  f64 random_accept, delta_cost_over_t;
  f64 total_increase = 0.0, average_increase;
  u32 i, j;
  u32 number_of_increases = 0;
  u32 accepted_this_temperature;
  u32 best_saves_this_temperature;
  int accept;

  t = p->initial_temperature;
  best_cost = initial_cost = prev_cost = p->anneal_metric (p->opaque);
  p->anneal_save_best_configuration (p->opaque);

  if (p->flags & CLIB_ANNEAL_VERBOSE)
    fformat (stdout, "Initial cost %.2f\n", initial_cost);

  for (i = 0; i < p->number_of_temperatures; i++)
    {
      accepted_this_temperature = 0;
      best_saves_this_temperature = 0;

      p->anneal_restore_best_configuration (p->opaque);
      cost = best_cost;

      for (j = 0; j < p->number_of_configurations_per_temperature; j++)
	{
	  p->anneal_new_configuration (p->opaque);
	  cost = p->anneal_metric (p->opaque);

	  delta_cost = cost - prev_cost;

	  /* cost function looks better, accept this move */
	  if (p->flags & CLIB_ANNEAL_MINIMIZE)
	    accept = delta_cost < 0.0;
	  else
	    accept = delta_cost > 0.0;

	  if (accept)
	    {
	      if (p->flags & CLIB_ANNEAL_MINIMIZE)
		if (cost < best_cost)
		  {
		    if (p->flags & CLIB_ANNEAL_VERBOSE)
		      fformat (stdout, "New best cost %.2f\n", cost);
		    best_cost = cost;
		    p->anneal_save_best_configuration (p->opaque);
		    best_saves_this_temperature++;
		  }

	      accepted_this_temperature++;
	      prev_cost = cost;
	      continue;
	    }

	  /* cost function worse, keep stats to suggest t0 */
	  total_increase += (p->flags & CLIB_ANNEAL_MINIMIZE) ?
	    delta_cost : -delta_cost;

	  number_of_increases++;

	  /*
	   * Accept a higher cost with Pr { e^(-(delta_cost / T)) },
	   * equivalent to rnd[0,1] < e^(-(delta_cost / T))
	   *
	   * AKA, the Boltzmann factor.
	   */
	  random_accept = random_f64 (&p->random_seed);

	  delta_cost_over_t = delta_cost / t;

	  if (random_accept < exp (-delta_cost_over_t))
	    {
	      accepted_this_temperature++;
	      prev_cost = cost;
	      continue;
	    }
	  p->anneal_restore_previous_configuration (p->opaque);
	}

      if (p->flags & CLIB_ANNEAL_VERBOSE)
	{
	  fformat (stdout, "Temp %.2f, cost %.2f, accepted %d, bests %d\n", t,
		   prev_cost, accepted_this_temperature,
		   best_saves_this_temperature);
	  fformat (stdout, "Improvement %.2f\n", initial_cost - prev_cost);
	  fformat (stdout, "-------------\n");
	}

      t = t * p->temperature_step;
    }

  /*
   * Empirically, one wants the probability of accepting a move
   * at the initial temperature to be about 0.8.
   */
  average_increase = total_increase / (f64) number_of_increases;
  p->suggested_initial_temperature = average_increase / 0.22;	/* 0.22 = -ln (0.8) */

  p->final_temperature = t;
  p->final_metric = p->anneal_metric (p->opaque);

  if (p->flags & CLIB_ANNEAL_VERBOSE)
    {
      fformat (stdout, "Average cost increase from a bad move: %.2f\n",
	       average_increase);
      fformat (stdout, "Suggested t0 = %.2f\n",
	       p->suggested_initial_temperature);
    }
}

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