aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/suite_no_topo_test.go
diff options
context:
space:
mode:
authorMaros Ondrejicka <mondreji@cisco.com>2023-02-23 13:19:15 +0100
committerFlorin Coras <florin.coras@gmail.com>2023-02-27 17:26:41 +0000
commit40cba405c5c06a3dc086a55143cb3ffd1094597e (patch)
tree0263e3834a316d73863b1a6cc2da9beac916ac45 /extras/hs-test/suite_no_topo_test.go
parent9cb3e15c9f5b0eed296c3517c6475bd17a33441e (diff)
hs-test: refactor netconfig
This joins separate representations of veth and tap interfaces into a single struct. It removes the need for type interface and embedding which simplifies the code. Type: test Signed-off-by: Maros Ondrejicka <mondreji@cisco.com> Change-Id: I1b2c368bfe90a5bdfaaa9a5129c27d7d96f8fe3b
Diffstat (limited to 'extras/hs-test/suite_no_topo_test.go')
-rw-r--r--extras/hs-test/suite_no_topo_test.go22
1 files changed, 5 insertions, 17 deletions
diff --git a/extras/hs-test/suite_no_topo_test.go b/extras/hs-test/suite_no_topo_test.go
index 01958b0a804..12b939e435f 100644
--- a/extras/hs-test/suite_no_topo_test.go
+++ b/extras/hs-test/suite_no_topo_test.go
@@ -4,8 +4,7 @@ const (
singleTopoContainerVpp = "vpp"
singleTopoContainerNginx = "nginx"
- tapNameVpp = "vppTap"
- tapNameHost = "hostTap"
+ tapInterfaceName = "hst_tap_host"
)
type NoTopoSuite struct {
@@ -13,19 +12,9 @@ type NoTopoSuite struct {
}
func (s *NoTopoSuite) SetupSuite() {
- s.loadContainerTopology("single")
-
- s.addresser = NewAddresser(&s.HstSuite)
-
- var vppTapDevConfig = NetDevConfig{"name": tapNameVpp}
- vppTap, _ := NewTap(vppTapDevConfig, s.addresser)
+ s.loadNetworkTopology("tap")
- var hostTapDevConfig = NetDevConfig{"name": tapNameHost}
- hostTap, _ := NewTap(hostTapDevConfig, s.addresser)
-
- s.netInterfaces = make(map[string]NetInterface)
- s.netInterfaces[vppTap.Name()] = &vppTap
- s.netInterfaces[hostTap.Name()] = &hostTap
+ s.loadContainerTopology("single")
}
func (s *NoTopoSuite) SetupTest() {
@@ -43,8 +32,7 @@ func (s *NoTopoSuite) SetupTest() {
vpp, _ := container.newVppInstance(startupConfig)
vpp.start()
- vppTapAddress := s.netInterfaces[tapNameVpp].AddressWithPrefix()
- hostTapAddress := s.netInterfaces[tapNameHost].IP4AddressWithPrefix()
+ tapInterface := s.netInterfaces[tapInterfaceName]
- vpp.createTap("tap0", hostTapAddress, vppTapAddress)
+ vpp.createTap(1, tapInterface)
}
#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 */ }
/*
 * 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 <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vppinfra/error.h>

#include <vnet/ip/ip.h>

#include <vppinfra/hash.h>
#include <vppinfra/error.h>
#include <vppinfra/elog.h>

#include <vnet/ip/ip6_hop_by_hop.h>
#include "ip6_ioam_e2e.h"

ioam_e2e_main_t ioam_e2e_main;

static u8 * ioam_e2e_trace_handler (u8 * s,
                                    ip6_hop_by_hop_option_t *opt)
{
  ioam_e2e_option_t * e2e = (ioam_e2e_option_t *)opt;
  u32 seqno = 0;

  if (e2e)
    {
      seqno = clib_net_to_host_u32 (e2e->e2e_hdr.e2e_data);
    }

  s = format (s, "SeqNo = 0x%Lx", seqno);
  return s;
}

int
ioam_e2e_config_handler (void *data, u8 disable)
{
  int *analyse = data;

  /* Register hanlders if enabled */
  if (!disable)
    {
      /* If encap node register for encap handler */
      if (0 == *analyse)
        {
          if (ip6_hbh_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
                                      ioam_seqno_encap_handler,
                                      ioam_e2e_trace_handler) < 0)
            {
              return (-1);
            }
        }
      /* If analyze node then register for decap handler */
      else
        {
          if (ip6_hbh_pop_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
                                          ioam_seqno_decap_handler) < 0)
            {
              return (-1);
            }
        }
      return 0;
    }

  /* UnRegister handlers */
  (void) ip6_hbh_unregister_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE);
  (void) ip6_hbh_pop_unregister_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE);
  return 0;
}

int
ioam_e2e_rewrite_handler (u8 *rewrite_string,
                          u8 *rewrite_size)
{
  ioam_e2e_option_t *e2e_option;

  if (rewrite_string && *rewrite_size == sizeof(ioam_e2e_option_t))
    {
      e2e_option = (ioam_e2e_option_t *)rewrite_string;
      e2e_option->hdr.type = HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE
          | HBH_OPTION_TYPE_SKIP_UNKNOWN;
      e2e_option->hdr.length = sizeof (ioam_e2e_option_t) -
          sizeof (ip6_hop_by_hop_option_t);
      return(0);
    }
  return(-1);
}

u32
ioam_e2e_flow_handler (u32 ctx, u8 add)
{
  ioam_e2e_data_t *data;
  u16 i;

  if (add)
    {
      pool_get(ioam_e2e_main.e2e_data, data);
      data->flow_ctx =  ctx;
      ioam_seqno_init_data(&data->seqno_data);
      return ((u32) (data - ioam_e2e_main.e2e_data));
    }

  /* Delete case */
  for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
    {
      if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
        continue;

      data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
      if (data && (data->flow_ctx == ctx))
        {
          pool_put_index(ioam_e2e_main.e2e_data, i);
          return (0);
        }
    }
  return 0;
}

static clib_error_t *
ioam_show_e2e_cmd_fn (vlib_main_t * vm,
                      unformat_input_t * input,
                      vlib_cli_command_t * cmd)
{
  ioam_e2e_data_t *e2e_data;
  u8 *s = 0;
  int i;

  vec_reset_length(s);

  s = format(0, "IOAM E2E information: \n");
  for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
    {
      if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
        continue;

      e2e_data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
      s = format(s, "Flow name: %s\n", get_flow_name_from_flow_ctx(e2e_data->flow_ctx));

      s = show_ioam_seqno_cmd_fn(s,
                                 &e2e_data->seqno_data,
                                 !IOAM_DEAP_ENABLED(e2e_data->flow_ctx));
    }

  vlib_cli_output(vm, "%v", s);
  return 0;
}


VLIB_CLI_COMMAND (ioam_show_e2e_cmd, static) = {
    .path = "show ioam e2e ",
    .short_help = "show ioam e2e information",
    .function = ioam_show_e2e_cmd_fn,
};

/*
 * Init handler E2E headet handling.
 * Init hanlder registers encap, decap, trace and Rewrite handlers.
 */
static clib_error_t *
ioam_e2e_init (vlib_main_t * vm)
{
  /*
   * As of now we have only PPC under E2E header.
   */
  if (ip6_hbh_config_handler_register(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
                                      ioam_e2e_config_handler) < 0)
    {
      return (clib_error_create("Registration of "
          "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
    }

  if (ip6_hbh_add_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
                                  sizeof(ioam_e2e_option_t),
                                  ioam_e2e_rewrite_handler) < 0)
    {
      return (clib_error_create("Registration of "
          "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
    }

  if (ip6_hbh_flow_handler_register(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
                                    ioam_e2e_flow_handler) < 0)
    {
      return (clib_error_create("Registration of "
          "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE Flow handler failed"));
    }

  ioam_e2e_main.vlib_main = vm;
  ioam_e2e_main.vnet_main = vnet_get_main();

  return (0);
}

/*
 * Init function for the E2E lib.
 * ip6_hop_by_hop_ioam_e2e_init gets called during init.
 */
/* *INDENT-OFF* */
VLIB_INIT_FUNCTION (ioam_e2e_init) =
{
    .runs_after = VLIB_INITS("ip6_hop_by_hop_ioam_init"),
};
/* *INDENT-ON* */