summaryrefslogtreecommitdiffstats
path: root/test/test_l2xc.py
AgeCommit message (Collapse)AuthorFilesLines
2016-12-23make test: improve handling of packet capturesKlement Sekera1-6/+2
Perform accounting of expected packets based on created packet infos. Use this accounting info to automatically expect (and verify) the correct number of packets to be captured. Automatically retry the read of the capture file if scapy raises an exception while doing so to handle rare cases when capture file is read while only partially written during busy wait. Don't fail assert_nothing_captured if only junk packets arrived. Change-Id: I16ec2e9410ef510d313ec16b7e13c57d0b2a63f5 Signed-off-by: Klement Sekera <ksekera@cisco.com>
2016-12-05make test: fix missing log/packet messagesKlement Sekera1-3/+2
Change-Id: Idb3119792943664748c4abc3829ad723f4156dfe Signed-off-by: Klement Sekera <ksekera@cisco.com>
2016-11-11Add single-loop test variant to L2BD and L2XC testsJan1-65/+119
- create single-loop version of tests - update doc strings - add possibility to log CLI string for logging level "info" Change-Id: Ibc9e5650b8a33d2ed168a8440c2ae03227be60bb Signed-off-by: Jan <jgelety@cisco.com>
2016-11-11Add IRB testMatej Klotton1-2/+2
- JIRA: CSIT-255 - create loopback interfaces - move pg-interface specific arp and neighbor discovery from vpp_interface to vpp_pg_interface - base configuration of IRB tests - IP test scenario Change-Id: I9945a188163652a4e22325877aef008c4d029557 Signed-off-by: Matej Klotton <mklotton@cisco.com>
2016-10-31add vpp debugging support to test frameworkKlement Sekera1-7/+5
improve test documentation Change-Id: Ia9678aa2532ecb4cb33736aedb4a31aa3f2a3f93 Signed-off-by: Klement Sekera <ksekera@cisco.com>
2016-10-26refactor test frameworkKlement Sekera1-170/+106
Change-Id: I31da3b1857b6399f9899276a2d99cdd19436296c Signed-off-by: Klement Sekera <ksekera@cisco.com> Signed-off-by: Matej Klotton <mklotton@cisco.com> Signed-off-by: Jan Gelety <jgelety@cisco.com> Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
2016-10-03test: new test infrastructureDamjan Marion1-0/+243
Change-Id: I73ca19c431743f6b39669c583d9222a6559346ef Signed-off-by: Jan Gelety <jgelety@cisco.com> Signed-off-by: Juraj Sloboda <jsloboda@cisco.com> Signed-off-by: Stefan Kobza <skobza@cisco.com> Signed-off-by: Matej Klotton <mklotton@cisco.com> Signed-off-by: Maciek Konstantynowicz <mkonstan@cisco.com> Signed-off-by: Damjan Marion <damarion@cisco.com>
href='#n240'>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
/*
 * 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 <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vppinfra/error.h>
#include <srv6-am/am.h>


/******************************* Packet tracing *******************************/

typedef struct
{
  u32 localsid_index;
} srv6_am_localsid_trace_t;

typedef struct
{
  ip6_address_t src, dst;
} srv6_am_rewrite_trace_t;

static u8 *
format_srv6_am_localsid_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 *);
  srv6_am_localsid_trace_t *t = va_arg (*args, srv6_am_localsid_trace_t *);

  return format (s, "SRv6-AM-localsid: localsid_index %d", t->localsid_index);
}

static u8 *
format_srv6_am_rewrite_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 *);
  srv6_am_rewrite_trace_t *t = va_arg (*args, srv6_am_rewrite_trace_t *);

  return format (s, "SRv6-AM-rewrite: src %U dst %U",
		 format_ip6_address, &t->src, format_ip6_address, &t->dst);
}


/***************************** Node registration ******************************/

vlib_node_registration_t srv6_am_rewrite_node;


/****************************** Packet counters *******************************/

#define foreach_srv6_am_rewrite_counter \
_(PROCESSED, "srv6-am rewritten packets") \
_(NO_SRH, "(Error) No SRH.")

typedef enum
{
#define _(sym,str) SRV6_AM_REWRITE_COUNTER_##sym,
  foreach_srv6_am_rewrite_counter
#undef _
    SRV6_AM_REWRITE_N_COUNTERS,
} srv6_am_rewrite_counters;

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


/********************************* Next nodes *********************************/

typedef enum
{
  SRV6_AM_LOCALSID_NEXT_ERROR,
  SRV6_AM_LOCALSID_NEXT_REWRITE,
  SRV6_AM_LOCALSID_N_NEXT,
} srv6_am_localsid_next_t;

typedef enum
{
  SRV6_AM_REWRITE_NEXT_ERROR,
  SRV6_AM_REWRITE_NEXT_LOOKUP,
  SRV6_AM_REWRITE_N_NEXT,
} srv6_am_rewrite_next_t;


/******************************* Local SID node *******************************/

/**
 * @brief SRv6 masquerading.
 */
static_always_inline void
end_am_processing (vlib_buffer_t * b0,
		   ip6_header_t * ip0,
		   ip6_sr_header_t * sr0,
		   ip6_sr_localsid_t * ls0, u32 * next0)
{
  ip6_address_t *new_dst0;

  if (PREDICT_FALSE (ip0->protocol != IP_PROTOCOL_IPV6_ROUTE ||
		     sr0->type != ROUTING_HEADER_TYPE_SR))
    {
      *next0 = SRV6_AM_LOCALSID_NEXT_ERROR;
      return;
    }

  if (PREDICT_FALSE (sr0->segments_left == 0))
    {
      *next0 = SRV6_AM_LOCALSID_NEXT_ERROR;
      return;
    }

  /* Decrement Segments Left */
  sr0->segments_left -= 1;

  /* Set Destination Address to Last Segment (index 0) */
  new_dst0 = (ip6_address_t *) (sr0->segments);
  ip0->dst_address.as_u64[0] = new_dst0->as_u64[0];
  ip0->dst_address.as_u64[1] = new_dst0->as_u64[1];

  /* Set Xconnect adjacency to VNF */
  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
}

/**
 * @brief Graph node for applying SRv6 masquerading.
 */
static uword
srv6_am_localsid_fn (vlib_main_t * vm,
		     vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  ip6_sr_main_t *sm = &sr_main;
  u32 n_left_from, next_index, *from, *to_next;
  u32 cnt_packets = 0;

  from = vlib_frame_vector_args (frame);
  n_left_from = frame->n_vectors;
  next_index = node->cached_next_index;

  u32 thread_index = vlib_get_thread_index ();

  while (n_left_from > 0)
    {
      u32 n_left_to_next;

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

      /* TODO: Dual/quad loop */

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  u32 bi0;
	  vlib_buffer_t *b0;
	  ip6_header_t *ip0 = 0;
	  ip6_sr_header_t *sr0;
	  ip6_sr_localsid_t *ls0;
	  u32 next0 = SRV6_AM_LOCALSID_NEXT_REWRITE;

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

	  b0 = vlib_get_buffer (vm, bi0);
	  ip0 = vlib_buffer_get_current (b0);
	  sr0 = (ip6_sr_header_t *) (ip0 + 1);

	  /* Lookup the SR End behavior based on IP DA (adj) */
	  ls0 = pool_elt_at_index (sm->localsids,
				   vnet_buffer (b0)->ip.adj_index[VLIB_TX]);

	  /* SRH processing */
	  end_am_processing (b0, ip0, sr0, ls0, &next0);

	  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
	    {
	      srv6_am_localsid_trace_t *tr =
		vlib_add_trace (vm, node, b0, sizeof *tr);
	      tr->localsid_index = ls0 - sm->localsids;
	    }

	  /* This increments the SRv6 per LocalSID counters. */
	  vlib_increment_combined_counter (((next0 ==
					     SRV6_AM_LOCALSID_NEXT_ERROR) ?
					    &(sm->sr_ls_invalid_counters) :
					    &(sm->sr_ls_valid_counters)),
					   thread_index, ls0 - sm->localsids,
					   1, vlib_buffer_length_in_chain (vm,
									   b0));

	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
					   n_left_to_next, bi0, next0);

	  cnt_packets++;
	}

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

  return frame->n_vectors;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (srv6_am_localsid_node) = {
  .function = srv6_am_localsid_fn,
  .name = "srv6-am-localsid",
  .vector_size = sizeof (u32),
  .format_trace = format_srv6_am_localsid_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_next_nodes = SRV6_AM_LOCALSID_N_NEXT,
  .next_nodes = {
    [SRV6_AM_LOCALSID_NEXT_REWRITE] = "ip6-rewrite",
    [SRV6_AM_LOCALSID_NEXT_ERROR] = "error-drop",
  },
};
/* *INDENT-ON* */


/******************************* Rewriting node *******************************/

/**
 * @brief SRv6 de-masquerading.
 */
static_always_inline void
end_am_rewriting (vlib_node_runtime_t * node,
		  vlib_buffer_t * b0,
		  ip6_header_t * ip0, ip6_sr_header_t * sr0, u32 * next0)
{
  if (PREDICT_FALSE (ip0->protocol != IP_PROTOCOL_IPV6_ROUTE ||
		     sr0->type != ROUTING_HEADER_TYPE_SR))
    {
      b0->error = node->errors[SRV6_AM_REWRITE_COUNTER_NO_SRH];
      *next0 = SRV6_AM_REWRITE_NEXT_ERROR;
      return;
    }

  /* Restore Destination Address to active segment (index SL) */
  if (sr0->segments_left != 0)
    {
      ip6_address_t *new_dst0;
      new_dst0 = (ip6_address_t *) (sr0->segments) + sr0->segments_left;
      ip0->dst_address.as_u64[0] = new_dst0->as_u64[0];
      ip0->dst_address.as_u64[1] = new_dst0->as_u64[1];
    }
}

/**
 * @brief Graph node for applying SRv6 de-masquerading.
 */
static uword
srv6_am_rewrite_fn (vlib_main_t * vm,
		    vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  u32 n_left_from, next_index, *from, *to_next;
  u32 cnt_packets = 0;

  from = vlib_frame_vector_args (frame);
  n_left_from = frame->n_vectors;
  next_index = node->cached_next_index;

  while (n_left_from > 0)
    {
      u32 n_left_to_next;

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

      /* TODO: Dual/quad loop */

      while (n_left_from > 0 && n_left_to_next > 0)
	{
	  u32 bi0;
	  vlib_buffer_t *b0;
	  ip6_header_t *ip0 = 0;
	  ip6_sr_header_t *sr0;
	  u32 next0 = SRV6_AM_REWRITE_NEXT_LOOKUP;

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

	  b0 = vlib_get_buffer (vm, bi0);
	  ip0 = vlib_buffer_get_current (b0);
	  sr0 = (ip6_sr_header_t *) (ip0 + 1);

	  /* SRH processing */
	  end_am_rewriting (node, b0, ip0, sr0, &next0);

	  if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
	      PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
	    {
	      srv6_am_rewrite_trace_t *tr =
		vlib_add_trace (vm, node, b0, sizeof *tr);
	      clib_memcpy (tr->src.as_u8, ip0->src_address.as_u8,
			   sizeof tr->src.as_u8);
	      clib_memcpy (tr->dst.as_u8, ip0->dst_address.as_u8,
			   sizeof tr->dst.as_u8);
	    }

	  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
					   n_left_to_next, bi0, next0);

	  cnt_packets++;
	}

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

  /* Update counters */
  vlib_node_increment_counter (vm, srv6_am_rewrite_node.index,
			       SRV6_AM_REWRITE_COUNTER_PROCESSED,
			       cnt_packets);

  return frame->n_vectors;
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (srv6_am_rewrite_node) = {
  .function = srv6_am_rewrite_fn,
  .name = "srv6-am-rewrite",
  .vector_size = sizeof (u32),
  .format_trace = format_srv6_am_rewrite_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_errors = SRV6_AM_REWRITE_N_COUNTERS,
  .error_strings = srv6_am_rewrite_counter_strings,
  .n_next_nodes = SRV6_AM_REWRITE_N_NEXT,
  .next_nodes = {
      [SRV6_AM_REWRITE_NEXT_LOOKUP] = "ip6-lookup",
      [SRV6_AM_REWRITE_NEXT_ERROR] = "error-drop",
  },
};
/* *INDENT-ON* */

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