summaryrefslogtreecommitdiffstats
path: root/hicn-light/src/config/controlRoot.h
blob: a62126ebaf54ab49a08a399fa3f47c7b99d42376 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Copyright (c) 2017-2019 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.
 */

/**
 * @file control_Root.h
 * @brief Root of the command tree
 *
 * Implements the root of the command tree.  This is the one module that
 * needs to be seeded to the control state to build the whole tree.
 *
 */

#ifndef Control_Root_h
#define Control_Root_h

#include <src/config/controlState.h>
CommandOps *controlRoot_Create(ControlState *state);
CommandOps *controlRoot_HelpCreate(ControlState *state);
#endif  // Control_Root_h
old } /* 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 */ }
/* SPDX-License-Identifier: Apache-2.0
 * Copyright(c) 2021 Cisco Systems, Inc.
 */

#include <vppinfra/format.h>
#include <vppinfra/test/test.h>
#include <vppinfra/vector/ip_csum.h>

typedef struct
{
  struct
  {
    u8 *src;
    u32 count;
  } chunk[5];
  u16 result;
} ip_csum_test_t;

static u8 test1[] = { 0x45, 0x00, 0x00, 0x73, 0x00, 0x00, 0x40,
		      0x00, 0x40, 0x11, 0x00, 0x00, 0xc0, 0xa8,
		      0x00, 0x01, 0xc0, 0xa8, 0x00, 0xc7, 0x00 };
#define TEST_LEN(x) (ARRAY_LEN (x) - 1)

static ip_csum_test_t tests[] = { {
				    .chunk[0].src = test1,
				    .chunk[0].count = TEST_LEN (test1),
				    .result = 0x61b8,
				  },
				  {
				    .chunk[0].src = test1,
				    .chunk[0].count = 1,
				    .chunk[1].src = test1 + 1,
				    .chunk[1].count = 2,
				    .chunk[2].src = test1 + 3,
				    .chunk[2].count = 3,
				    .chunk[3].src = test1 + 6,
				    .chunk[3].count = 4,
				    .chunk[4].src = test1 + 10,
				    .chunk[4].count = TEST_LEN (test1) - 10,
				    .result = 0x61b8,
				  },
				  {
				    .chunk[0].count = 1,
				    .result = 0xff0f,
				  },
				  {
				    .chunk[0].count = 2,
				    .result = 0x080f,
				  },
				  {
				    .chunk[0].count = 3,
				    .result = 0x0711,
				  },
				  {
				    .chunk[0].count = 4,
				    .result = 0x1210,
				  },
				  {
				    .chunk[0].count = 63,
				    .result = 0xda01,
				  },
				  {
				    .chunk[0].count = 64,
				    .result = 0xe100,
				  },
				  {
				    .chunk[0].count = 65,
				    .result = 0xe010,
				  },
				  {
				    .chunk[0].count = 65535,
				    .result = 0xfc84,
				  },
				  {
				    .chunk[0].count = 65536,
				    .result = 0xffff,
				  } };

static clib_error_t *
test_clib_ip_csum (clib_error_t *err)
{
  u8 *buf;
  buf = test_mem_alloc (65536);
  for (int i = 0; i < 65536; i++)
    buf[i] = 0xf0 + ((i * 7) & 0xf);

  for (int i = 0; i < ARRAY_LEN (tests); i++)
    {
      clib_ip_csum_t c = {};
      ip_csum_test_t *t = tests + i;
      u16 rv;

      for (int j = 0; j < ARRAY_LEN (((ip_csum_test_t *) 0)->chunk); j++)
	if (t->chunk[j].count > 0)
	  {
	    if (t->chunk[j].src == 0)
	      clib_ip_csum_chunk (&c, buf, t->chunk[j].count);
	    else
	      clib_ip_csum_chunk (&c, t->chunk[j].src, t->chunk[j].count);
	  }
      rv = clib_ip_csum_fold (&c);

      if (rv != tests[i].result)
	{
	  err = clib_error_return (err,
				   "bad checksum in test case %u (expected "
				   "0x%04x, calculated 0x%04x)",
				   i, tests[i].result, rv);
	  goto done;
	}
    }
done:
  test_mem_free (buf);
  return err;
}

void __test_perf_fn
perftest_ip4_hdr (test_perf_t *tp)
{
  u32 n = tp->n_ops;
  u8 *data = test_mem_alloc_and_splat (20, n, (void *) &test1);
  u16 *res = test_mem_alloc (n * sizeof (u16));

  test_perf_event_enable (tp);
  for (int i = 0; i < n; i++)
    res[i] = clib_ip_csum (data + i * 20, 20);
  test_perf_event_disable (tp);

  test_mem_free (data);
  test_mem_free (res);
}

void __test_perf_fn
perftest_tcp_payload (test_perf_t *tp)
{
  u32 n = tp->n_ops;
  volatile uword *lenp = &tp->arg0;
  u8 *data = test_mem_alloc_and_splat (20, n, (void *) &test1);
  u16 *res = test_mem_alloc (n * sizeof (u16));

  test_perf_event_enable (tp);
  for (int i = 0; i < n; i++)
    res[i] = clib_ip_csum (data + i * lenp[0], lenp[0]);
  test_perf_event_disable (tp);

  test_mem_free (data);
  test_mem_free (res);
}

void __test_perf_fn
perftest_byte (test_perf_t *tp)
{
  volatile uword *np = &tp->n_ops;
  u8 *data = test_mem_alloc_and_fill_inc_u8 (*np, 0, 0);
  u16 *res = test_mem_alloc (sizeof (u16));

  test_perf_event_enable (tp);
  res[0] = clib_ip_csum (data, np[0]);
  test_perf_event_disable (tp);

  test_mem_free (data);
  test_mem_free (res);
}

REGISTER_TEST (clib_ip_csum) = {
  .name = "clib_ip_csum",
  .fn = test_clib_ip_csum,
  .perf_tests = PERF_TESTS (
    { .name = "fixed size (per IPv4 Header)",
      .n_ops = 1024,
      .fn = perftest_ip4_hdr },
    { .name = "fixed size (per 1460 byte block)",
      .n_ops = 16,
      .arg0 = 1460,
      .fn = perftest_tcp_payload },
    { .name = "variable size (per byte)", .n_ops = 16384, .fn = perftest_byte }

    ),
};