/* * Test suite for class VppOM * * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ #define BOOST_TEST_MODULE "VPP OBJECT MODEL" #define BOOST_TEST_DYN_LINK #include #include #include #include #include "vom/om.hpp" #include "vom/interface.hpp" #include "vom/interface_cmds.hpp" #include "vom/bond_interface_cmds.hpp" #include "vom/bond_group_binding.hpp" #include "vom/bond_group_binding_cmds.hpp" #include "vom/l2_binding.hpp" #include "vom/l2_binding_cmds.hpp" #include "vom/l2_vtr_cmds.hpp" #include "vom/l2_xconnect.hpp" #include "vom/l2_xconnect_cmds.hpp" #include "vom/l3_binding.hpp" #include "vom/l3_binding_cmds.hpp" #include "vom/bridge_domain.hpp" #include "vom/bridge_domain_entry.hpp" #include "vom/bridge_domain_arp_entry.hpp" #include "vom/bridge_domain_cmds.hpp" #include "vom/bridge_domain_entry_cmds.hpp" #include "vom/bridge_domain_arp_entry_cmds.hpp" #include "vom/prefix.hpp" #include "vom/route.hpp" #include "vom/route_cmds.hpp" #include "vom/mroute_cmds.hpp" #include "vom/route_domain.hpp" #include "vom/route_domain_cmds.hpp" #include "vom/vxlan_tunnel.hpp" #include "vom/vxlan_tunnel_cmds.hpp" #include "vom/sub_interface.hpp" #include "vom/sub_interface_cmds.hpp" #include "vom/acl_ethertype.hpp" #include "vom/acl_ethertype_cmds.hpp" #include "vom/acl_l2_list.hpp" #include "vom/acl_l3_list.hpp" #include "vom/acl_binding.hpp" #include "vom/acl_list_cmds.hpp" #include "vom/acl_binding_cmds.hpp" #include "vom/acl_l3_rule.hpp" #include "vom/acl_l2_rule.hpp" #include "vom/arp_proxy_config.hpp" #include "vom/arp_proxy_binding.hpp" #include "vom/arp_proxy_config_cmds.hpp" #include "vom/arp_proxy_binding_cmds.hpp" #include "vom/igmp_binding.hpp" #include "vom/igmp_binding_cmds.hpp" #include "vom/igmp_listen.hpp" #include "vom/igmp_listen_cmds.hpp" #include "vom/ip_punt_redirect.hpp" #include "vom/ip_punt_redirect_cmds.hpp" #include "vom/ip_unnumbered.hpp" #include "vom/ip_unnumbered_cmds.hpp" #include "vom/interface_ip6_nd.hpp" #include "vom/interface_span.hpp" #include "vom/interface_span_cmds.hpp" #include "vom/neighbour.hpp" #include "vom/neighbour_cmds.hpp" #include "vom/nat_static.hpp" #include "vom/nat_static_cmds.hpp" #include "vom/nat_binding.hpp" #include "vom/nat_binding_cmds.hpp" #include "vom/pipe.hpp" #include "vom/pipe_cmds.hpp" #include "vom/qos_mark.hpp" #include "vom/qos_mark_cmds.hpp" #include "vom/qos_map.hpp" #include "vom/qos_map_cmds.hpp" #include "vom/qos_record.hpp" #include "vom/qos_record_cmds.hpp" #include "vom/qos_store.hpp" #include "vom/qos_store_cmds.hpp" using namespace boost; using namespace VOM; /** * An expectation exception */ class ExpException { public: ExpException(unsigned int number) { // a neat place to add a break point // std::cout << " ExpException here: " << number << std::endl; } }; class MockListener : public interface::event_listener, public interface::stat_listener { void handle_interface_stat(const interface& itf) { } void handle_interface_event(std::vector events) { } }; class MockCmdQ : public HW::cmd_q { public: MockCmdQ(): m_strict_order(true) { } virtual ~MockCmdQ() { } void expect(cmd *f) { m_exp_queue.push_back(f); } void enqueue(cmd *f) { m_act_queue.push_back(f); } void enqueue(std::queue &cmds) { while (cmds.size()) { m_act_queue.push_back(cmds.front()); cmds.pop(); } } void enqueue(std::shared_ptr f) { m_act_queue.push_back(f.get()); } void dequeue(cmd *f) { } void dequeue(std::shared_ptr cmd) { } void strict_order(bool on) { m_strict_order = on; } bool is_empty() { return ((0 == m_exp_queue.size()) && (0 == m_act_queue.size())); } rc_t write() { cmd *f_exp, *f_act; rc_t rc = rc_t::OK; while (m_act_queue.size()) { bool matched = false; auto it_exp = m_exp_queue.begin(); auto it_act = m_act_queue.begin(); f_act = *it_act; std::cout << " Act: " << f_act->to_string() << std::endl; while (it_exp != m_exp_queue.end()) { f_exp = *it_exp; try { std::cout << " Exp: " << f_exp->to_string() << std::endl; if (typeid(*f_exp) != typeid(*f_act)) { throw ExpException(1); } if (typeid(*f_exp) == typeid(interface_cmds::af_packet_create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::loopback_create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::bvi_create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::vhost_create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bond_interface_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::loopback_delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::bvi_delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::af_packet_delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::vhost_delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bond_interface_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::state_change_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::set_table_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::set_mac_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_cmds::set_tag)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bond_group_binding_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(route_domain_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(route_domain_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(route::ip_route_cmds::update_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(route::ip_route_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::update_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(route::ip_mroute_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(neighbour_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(neighbour_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l3_binding_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l3_binding_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bridge_domain_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bridge_domain_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bridge_domain_entry_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(bridge_domain_arp_entry_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l2_binding_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l2_binding_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l2_vtr_cmds::set_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(l2_xconnect_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(vxlan_tunnel_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(sub_interface_cmds::create_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(sub_interface_cmds::delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::acl_ethertype_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_update_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::list_cmds::l3_delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l3_unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_update_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::list_cmds::l2_delete_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ACL::binding_cmds::l2_unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(arp_proxy_binding_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::config_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(arp_proxy_config_cmds::unconfig_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(igmp_binding_cmds::bind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(igmp_binding_cmds::unbind_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(igmp_listen_cmds::listen_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(igmp_listen_cmds::unlisten_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::config_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip_punt_redirect_cmds::unconfig_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::config_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip_unnumbered_cmds::unconfig_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip6nd_ra_config::config_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip6nd_ra_config::unconfig_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::config_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(ip6nd_ra_prefix::unconfig_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_span_cmds::config_cmd)) { rc = handle_derived(f_exp, f_act); } else if (typeid(*f_exp) == typeid(interface_span_cmds::unconfig_cm
/*
 * 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 <vnet/ip/ip.h>
#include <vnet/ip/ip_punt_drop.h>
#include <vnet/policer/policer.h>
#include <vnet/policer/police_inlines.h>

/* *INDENT-OFF* */
VNET_FEATURE_ARC_INIT (ip4_punt) =
{
  .arc_name  = "ip4-punt",
  .start_nodes = VNET_FEATURES ("ip4-punt"),
};

VNET_FEATURE_ARC_INIT (ip4_drop) =
{
  .arc_name  = "ip4-drop",
  .start_nodes = VNET_FEATURES ("ip4-drop", "ip4-not-enabled"),
};
/* *INDENT-ON* */

extern ip_punt_policer_t ip4_punt_policer_cfg;

#ifndef CLIB_MARCH_VARIANT
u8 *
format_ip_punt_policer_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 *);
  ip_punt_policer_trace_t *t = va_arg (*args, ip_punt_policer_trace_t *);

  s = format (s, "policer_index %d next %d", t->policer_index, t->next);
  return s;
}

ip_punt_policer_t ip4_punt_policer_cfg = {
  .policer_index = ~0,
};
#endif /* CLIB_MARCH_VARIANT */

static char *ip4_punt_policer_handoff_error_strings[] = { "congestion drop" };

VLIB_NODE_FN (ip4_punt_policer_handoff_node)
(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
{
  return policer_handoff (vm, node, frame, ip4_punt_policer_cfg.fq_index,
			  ip4_punt_policer_cfg.policer_index);
}

VLIB_REGISTER_NODE (ip4_punt_policer_handoff_node) = {
  .name = "ip4-punt-policer-handoff",
  .vector_size = sizeof (u32),
  .format_trace = format_policer_handoff_trace,
  .type = VLIB_NODE_TYPE_INTERNAL,
  .n_errors = ARRAY_LEN(ip4_punt_policer_handoff_error_strings),
  .error_strings = ip4_punt_policer_handoff_error_strings,

  .n_next_nodes = 1,
  .next_nodes = {
    [0] = "error-drop",
  },
};

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

VLIB_NODE_FN (ip4_punt_policer_node) (vlib_main_t * vm,
				      vlib_node_runtime_t * node,
				      vlib_frame_t * frame)
{
  return (ip_punt_policer (vm, node, frame,
			   vnet_feat_arc_ip4_punt.feature_arc_index,
			   ip4_punt_policer_cfg.policer_index));
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_punt_policer_node) = {
  .name = "ip4-punt-policer",
  .vector_size = sizeof (u32),
  .n_next_nodes = IP_PUNT_POLICER_N_NEXT,
  .format_trace = format_ip_punt_policer_trace,
  .n_errors = ARRAY_LEN(ip4_punt_policer_error_strings),
  .error_strings = ip4_punt_policer_error_strings,

  .next_nodes = {
    [IP_PUNT_POLICER_NEXT_DROP] = "ip4-drop",
    [IP_PUNT_POLICER_NEXT_HANDOFF] = "ip4-punt-policer-handoff",
  },
};

VNET_FEATURE_INIT (ip4_punt_policer_node) = {
  .arc_name = "ip4-punt",
  .node_name = "ip4-punt-policer",
  .runs_before = VNET_FEATURES("ip4-punt-redirect"),
};
/* *INDENT-ON* */


#define foreach_ip4_punt_redirect_error         \
_(DROP, "ip4 punt redirect drop")

typedef enum
{
#define _(sym,str) IP4_PUNT_REDIRECT_ERROR_##sym,
  foreach_ip4_punt_redirect_error
#undef _
    IP4_PUNT_REDIRECT_N_ERROR,
} ip4_punt_redirect_error_t;

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

VLIB_NODE_FN (ip4_punt_redirect_node) (vlib_main_t * vm,
				       vlib_node_runtime_t * node,
				       vlib_frame_t * frame)
{
  return (ip_punt_redirect (vm, node, frame,
			    vnet_feat_arc_ip4_punt.feature_arc_index,
			    FIB_PROTOCOL_IP4));
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_punt_redirect_node) = {
  .name = "ip4-punt-redirect",
  .vector_size = sizeof (u32),
  .n_next_nodes = IP_PUNT_REDIRECT_N_NEXT,
  .format_trace = format_ip_punt_redirect_trace,
  .n_errors = ARRAY_LEN(ip4_punt_redirect_error_strings),
  .error_strings = ip4_punt_redirect_error_strings,

  /* edit / add dispositions here */
  .next_nodes = {
    [IP_PUNT_REDIRECT_NEXT_DROP] = "ip4-drop",
    [IP_PUNT_REDIRECT_NEXT_TX] = "ip4-rewrite",
    [IP_PUNT_REDIRECT_NEXT_ARP] = "ip4-arp",
  },
};

VNET_FEATURE_INIT (ip4_punt_redirect_node, static) = {
  .arc_name = "ip4-punt",
  .node_name = "ip4-punt-redirect",
  .runs_before = VNET_FEATURES("error-punt"),
};
/* *INDENT-ON* */

VLIB_NODE_FN (ip4_drop_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
			      vlib_frame_t * frame)
{
  if (node->flags & VLIB_NODE_FLAG_TRACE)
    ip4_forward_next_trace (vm, node, frame, VLIB_TX);

  return ip_drop_or_punt (vm, node, frame,
			  vnet_feat_arc_ip4_drop.feature_arc_index);

}

VLIB_NODE_FN (ip4_not_enabled_node) (vlib_main_t * vm,
				     vlib_node_runtime_t * node,
				     vlib_frame_t * frame)
{
  if (node->flags & VLIB_NODE_FLAG_TRACE)
    ip4_forward_next_trace (vm, node, frame, VLIB_TX);

  return ip_drop_or_punt (vm, node, frame,
			  vnet_feat_arc_ip4_drop.feature_arc_index);
}

static uword
ip4_punt (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
{
  if (node->flags & VLIB_NODE_FLAG_TRACE)
    ip4_forward_next_trace (vm, node, frame, VLIB_TX);

  return ip_drop_or_punt (vm, node, frame,
			  vnet_feat_arc_ip4_punt.feature_arc_index);
}

/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ip4_drop_node) =
{
  .name = "ip4-drop",
  .vector_size = sizeof (u32),
  .format_trace = format_ip4_forward_next_trace,
  .n_next_nodes = 1,
  .next_nodes = {
    [0] = "error-drop",
  },
};

VLIB_REGISTER_NODE (ip4_not_enabled_node) =
{
  .name = "ip4-not-enabled",
  .vector_size = sizeof (u32),
  .format_trace = format_ip4_forward_next_trace,
  .sibling_of = "ip4-drop",
};

VLIB_REGISTER_NODE (ip4_punt_node) =
{
  .function = ip4_punt,
  .name = "ip4-punt",
  .vector_size = sizeof (u32),
  .format_trace = format_ip4_forward_next_trace,
  .n_next_nodes = 1,
  .next_nodes = {
    [0] = "error-punt",
  },
};

VNET_FEATURE_INIT (ip4_punt_end_of_arc, static) = {
  .arc_name = "ip4-punt",
  .node_name = "error-punt",
  .runs_before = 0, /* not before any other features */
};

VNET_FEATURE_INIT (ip4_drop_end_of_arc, static) = {
  .arc_name = "ip4-drop",
  .node_name = "error-drop",
  .runs_before = 0, /* not before any other features */
};
/* *INDENT-ON */

#ifndef CLIB_MARCH_VARIANT
void
ip4_punt_policer_add_del (u8 is_add, u32 policer_index)
{
  ip4_punt_policer_cfg.policer_index = policer_index;

  vnet_feature_enable_disable ("ip4-punt", "ip4-punt-policer",
                               0, is_add, 0, 0);
}
#endif /* CLIB_MARCH_VARIANT */

static clib_error_t *
ip4_punt_police_cmd (vlib_main_t * vm,
                     unformat_input_t * main_input,
                     vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  clib_error_t *error = 0;
  u32 policer_index;
  u8 is_add = 1;

  policer_index = ~0;

  if (!unformat_user (main_input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "%d", &policer_index))
        ;
      else if (unformat (line_input, "del"))
        is_add = 0;
      else if (unformat (line_input, "add"))
        is_add = 1;
      else
        {
          error = unformat_parse_error (line_input);
          goto done;
        }
    }

  if (is_add && ~0 == policer_index)
  {
      error = clib_error_return (0, "expected policer index `%U'",
                                 format_unformat_error, line_input);
      goto done;
  }
  if (!is_add)
      policer_index = ~0;

  ip4_punt_policer_add_del(is_add, policer_index);

done:
  unformat_free (line_input);
  return (error);
}

/*?
 *
 * @cliexpar
 * @cliexcmd{set ip punt policer <INDEX>}
 ?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (ip4_punt_policer_command, static) =
{
  .path = "ip punt policer",
  .function = ip4_punt_police_cmd,
  .short_help = "ip punt policer [add|del] <index>",
};
/* *INDENT-ON* */

#ifndef CLIB_MARCH_VARIANT

void
ip4_punt_redirect_add (u32 rx_sw_if_index,
		       u32 tx_sw_if_index, ip46_address_t * nh)
{
  /* *INDENT-OFF* */
  fib_route_path_t *rpaths = NULL, rpath = {
    .frp_proto = DPO_PROTO_IP4,
    .frp_addr = *nh,
    .frp_sw_if_index = tx_sw_if_index,
    .frp_weight = 1,
    .frp_fib_index = ~0,
  };
  /* *INDENT-ON* */

  vec_add1 (rpaths, rpath);

  ip4_punt_redirect_add_paths (rx_sw_if_index, rpaths);

  vec_free (rpaths);
}

void
ip4_punt_redirect_add_paths (u32 rx_sw_if_index, fib_route_path_t * rpaths)
{
  ip_punt_redirect_add (FIB_PROTOCOL_IP4,
			rx_sw_if_index,
			FIB_FORW_CHAIN_TYPE_UNICAST_IP4, rpaths);

  vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 1, 0, 0);
}

void
ip4_punt_redirect_del (u32 rx_sw_if_index)
{
  vnet_feature_enable_disable ("ip4-punt", "ip4-punt-redirect", 0, 0, 0, 0);

  ip_punt_redirect_del (FIB_PROTOCOL_IP4, rx_sw_if_index);
}
#endif /* CLIB_MARCH_VARIANT */

static clib_error_t *
ip4_punt_redirect_cmd (vlib_main_t * vm,
		       unformat_input_t * main_input,
		       vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  fib_route_path_t *rpaths = NULL, rpath;
  dpo_proto_t payload_proto = DPO_PROTO_IP4;
  clib_error_t *error = 0;
  u32 rx_sw_if_index = ~0;
  vnet_main_t *vnm;
  u8 is_add;

  is_add = 1;
  vnm = vnet_get_main ();

  if (!unformat_user (main_input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "del"))
	is_add = 0;
      else if (unformat (line_input, "add"))
	is_add = 1;
      else if (unformat (line_input, "rx all"))
	rx_sw_if_index = 0;
      else if (unformat (line_input, "rx %U",
			 unformat_vnet_sw_interface, vnm, &rx_sw_if_index))
	;
      else if (unformat (line_input, "via %U", unformat_fib_route_path, &rpath,
			 &payload_proto))
	vec_add1 (rpaths, rpath);
      else
	{
	  error = unformat_parse_error (line_input);
	  goto done;
	}
    }

  if (~0 == rx_sw_if_index)
    {
      error = unformat_parse_error (line_input);
      goto done;
    }

  if (is_add)
    {
      if (vec_len (rpaths))
	ip4_punt_redirect_add_paths (rx_sw_if_index, rpaths);
    }
  else
    {
      ip4_punt_redirect_del (rx_sw_if_index);
    }

done:
  vec_free (rpaths);
  unformat_free (line_input);
  return (error);
}

/*?
 *
 * @cliexpar
 * @cliexcmd{set ip punt policer}
 ?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (ip4_punt_redirect_command, static) =
{
  .path = "ip punt redirect",
  .function = ip4_punt_redirect_cmd,
  .short_help = "ip punt redirect [add|del] rx [<interface>|all] via [<nh>] <tx_interface>",
};
/* *INDENT-ON* */

static clib_error_t *
ip4_punt_redirect_show_cmd (vlib_main_t * vm,
			    unformat_input_t * main_input,
			    vlib_cli_command_t * cmd)
{
  vlib_cli_output (vm, "%U", format_ip_punt_redirect, FIB_PROTOCOL_IP4);

  return (NULL);
}

/*?
 *
 * @cliexpar
 * @cliexcmd{set ip punt redierect}
 ?*/
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_ip4_punt_redirect_command, static) =
{
  .path = "show ip punt redirect",
  .function = ip4_punt_redirect_show_cmd,
  .short_help = "show ip punt redirect",
  .is_mp_safe = 1,
};
/* *INDENT-ON* */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
ist_t pl_9_10 = {*path_9, *path_10}; HW::item hw_route_5(0, rc_t::OK); ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_9_10)); TRY_CHECK_RC(OM::write(ian, *route_5)); route_5->remove(*path_9); route::path_list_t pl_10 = {*path_10}; ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5, 0, pfx_5, pl_10)); TRY_CHECK_RC(OM::write(ian, *route_5)); delete path_9; /* * A route via interface 2 in the non-default table */ boost::asio::ip::address nh_11 = boost::asio::ip::address::from_string("11.11.11.10"); route::path *path_11 = new route::path(nh_11, *itf2); boost::asio::ip::address nh_12 = boost::asio::ip::address::from_string("11.11.11.12"); route::path *path_12 = new route::path(nh_12, *itf2); route::ip_route *route_5_2 = new route::ip_route(rd4, pfx_5); route::path_list_t pl_11 = {*path_11}; route_5_2->add(*path_11); HW::item hw_route_5_2(1, rc_t::OK); ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11)); TRY_CHECK_RC(OM::write(ian, *route_5_2)); route::path_list_t pl_11_12 = {*path_11, *path_12}; route_5_2->add(*path_12); ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_5_2, 1, pfx_5, pl_11_12)); TRY_CHECK_RC(OM::write(ian, *route_5_2)); /* * An ARP entry for the neighbour on itf1 */ HW::item hw_neighbour(0, rc_t::OK); mac_address_t mac_n({0,1,2,4,5,6}); neighbour *ne = new neighbour(itf1, nh_10, mac_n); ADD_EXPECT(neighbour_cmds::create_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10, neighbour::flags_t::STATIC)); TRY_CHECK_RC(OM::write(ian, *ne)); /* * A DVR route */ route::prefix_t pfx_6("6.6.6.6", 32); route::path *path_13 = new route::path(*itf2, nh_proto_t::ETHERNET); route::ip_route *route_dvr = new route::ip_route(pfx_6); route_dvr->add(*path_13); route::path_list_t pl_13 = {*path_13}; HW::item hw_route_dvr(2, rc_t::OK); ADD_EXPECT(route::ip_route_cmds::update_cmd(hw_route_dvr, 0, pfx_6, pl_13)); TRY_CHECK_RC(OM::write(ian, *route_dvr)); /* * a multicast route */ route::mprefix_t mpfx_4(boost::asio::ip::address::from_string("232.1.1.1"), 32); route::ip_mroute *mroute_4 = new route::ip_mroute(mpfx_4); route::path *mp1 = new route::path(itf1, nh_proto_t::IPV4); route::path *mp2 = new route::path(*itf2, nh_proto_t::IPV4); mroute_4->add(*mp1, route::itf_flags_t::FORWARD); mroute_4->add(*mp1, route::itf_flags_t::ACCEPT); mroute_4->add(*mp2, route::itf_flags_t::FORWARD); HW::item hw_mroute_4(true, rc_t::OK); ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4, *mp1, route::itf_flags_t::FORWARD)); ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4, *mp2, route::itf_flags_t::FORWARD)); ADD_EXPECT(route::ip_mroute_cmds::update_cmd(hw_mroute_4, 0, mpfx_4, *mp1, route::itf_flags_t::ACCEPT)); TRY_CHECK_RC(OM::write(ian, *mroute_4)); STRICT_ORDER_OFF(); // delete the stack objects that hold references to others // so the OM::remove is the call that removes the last reference delete l3_11; delete l3_10; delete itf2; delete route_5; delete route_5_2; delete route_dvr; delete ne; delete mroute_4; ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4, *mp1, route::itf_flags_t::FORWARD)); ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4, *mp2, route::itf_flags_t::FORWARD)); ADD_EXPECT(route::ip_mroute_cmds::delete_cmd(hw_mroute_4, 0, mpfx_4, *mp1, route::itf_flags_t::ACCEPT)); delete mp1; delete mp2; ADD_EXPECT(neighbour_cmds::delete_cmd(hw_neighbour, hw_ifh.data(), mac_n, nh_10, neighbour::flags_t::STATIC)); ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_dvr, 0, pfx_6)); ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5_2, 1, pfx_5)); ADD_EXPECT(route::ip_route_cmds::delete_cmd(hw_route_5, 0, pfx_5)); delete path_10; delete path_11; delete path_12; delete path_13; pl_9_10.clear(); pl_10.clear(); pl_13.clear(); pl_11_12.clear(); pl_11.clear(); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_10_unbind, hw_ifh.data(), pfx_10)); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_11_unbind, hw_ifh2.data(), pfx_11)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh)); ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf1_name)); ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV4, hw_ifh2)); ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd4_unbind, l3_proto_t::IPV6, hw_ifh2)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2)); ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf2_name)); ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd4_delete, l3_proto_t::IPV4, 1)); ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd6_delete, l3_proto_t::IPV6, 1)); TRY_CHECK(OM::remove(ian)); } BOOST_AUTO_TEST_CASE(test_nat) { VppInit vi; const std::string gs = "GeorgeSimenon"; rc_t rc = rc_t::OK; /* * Inside Interface */ std::string itf_in_name = "inside"; interface itf_in(itf_in_name, interface::type_t::AFPACKET, interface::admin_state_t::UP); HW::item hw_ifh(2, rc_t::OK); HW::item hw_as_up(interface::admin_state_t::UP, rc_t::OK); HW::item hw_as_down(interface::admin_state_t::DOWN, rc_t::OK); ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_in_name)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh)); TRY_CHECK_RC(OM::write(gs, itf_in)); /* * outside */ std::string itf_out_name = "port-to"; interface itf_out(itf_out_name, interface::type_t::AFPACKET, interface::admin_state_t::UP); HW::item hw_ifh2(4, rc_t::OK); HW::item hw_as_up2(interface::admin_state_t::UP, rc_t::OK); HW::item hw_as_down2(interface::admin_state_t::DOWN, rc_t::OK); ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh2, itf_out_name)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up2, hw_ifh2)); TRY_CHECK_RC(OM::write(gs, itf_out)); /* * A NAT static mapping */ boost::asio::ip::address in_addr = boost::asio::ip::address::from_string("10.0.0.1"); boost::asio::ip::address_v4 out_addr = boost::asio::ip::address_v4::from_string("1.1.1.1"); nat_static ns(in_addr, out_addr); HW::item hw_ns(true, rc_t::OK); ADD_EXPECT(nat_static_cmds::create_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr)); TRY_CHECK_RC(OM::write(gs, ns)); /* * bind nat inside and out */ nat_binding *nb_in = new nat_binding(itf_in, direction_t::INPUT, l3_proto_t::IPV4, nat_binding::zone_t::INSIDE); HW::item hw_nb_in(true, rc_t::OK); ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_in, hw_ifh.data().value(), nat_binding::zone_t::INSIDE)); TRY_CHECK_RC(OM::write(gs, *nb_in)); nat_binding *nb_out = new nat_binding(itf_out, direction_t::INPUT, l3_proto_t::IPV4, nat_binding::zone_t::OUTSIDE); HW::item hw_nb_out(true, rc_t::OK); ADD_EXPECT(nat_binding_cmds::bind_44_input_cmd(hw_nb_out, hw_ifh2.data().value(), nat_binding::zone_t::OUTSIDE)); TRY_CHECK_RC(OM::write(gs, *nb_out)); STRICT_ORDER_OFF(); delete nb_in; delete nb_out; ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_in, hw_ifh.data().value(), nat_binding::zone_t::INSIDE)); ADD_EXPECT(nat_binding_cmds::unbind_44_input_cmd(hw_nb_out, hw_ifh2.data().value(), nat_binding::zone_t::OUTSIDE)); ADD_EXPECT(nat_static_cmds::delete_44_cmd(hw_ns, 0, in_addr.to_v4(), out_addr)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh)); ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_in_name)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down2, hw_ifh2)); ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh2, itf_out_name)); TRY_CHECK(OM::remove(gs)); } BOOST_AUTO_TEST_CASE(test_interface_events) { VppInit vi; MockListener ml; HW::item hw_want(true, rc_t::OK); ADD_EXPECT(interface_cmds::events_cmd(ml)); cmd* itf = new interface_cmds::events_cmd(ml); HW::enqueue(itf); HW::write(); } BOOST_AUTO_TEST_CASE(test_interface_route_domain_change) { VppInit vi; const std::string rene = "ReneGoscinny"; rc_t rc = rc_t::OK; /* * Create an interface with two IP addresses */ std::string itf1_name = "host1"; interface itf1(itf1_name, interface::type_t::AFPACKET, interface::admin_state_t::UP); HW::item hw_ifh1(2, rc_t::OK); HW::item hw_as_up(interface::admin_state_t::UP, rc_t::OK); HW::item hw_as_down(interface::admin_state_t::DOWN, rc_t::OK); ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh1, itf1_name)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh1)); TRY_CHECK_RC(OM::write(rene, itf1)); route::prefix_t pfx_10("10.10.10.10", 24); l3_binding *l3_1 = new l3_binding(itf1, pfx_10); HW::item hw_l3_bind1(true, rc_t::OK); HW::item hw_l3_unbind1(false, rc_t::OK); ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10)); TRY_CHECK_RC(OM::write(rene, *l3_1)); route::prefix_t pfx_11("10.10.11.11", 24); l3_binding *l3_2 = new l3_binding(itf1, pfx_11); HW::item hw_l3_bind2(true, rc_t::OK); HW::item hw_l3_unbind2(false, rc_t::OK); ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11)); TRY_CHECK_RC(OM::write(rene, *l3_2)); route_domain rd(1); HW::item hw_rd_create(true, rc_t::OK); HW::item hw_rd_delete(false, rc_t::OK); HW::item hw_rd_bind(1, rc_t::OK); HW::item hw_rd_unbind(route::DEFAULT_TABLE, rc_t::OK); ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV4, 1)); ADD_EXPECT(route_domain_cmds::create_cmd(hw_rd_create, l3_proto_t::IPV6, 1)); TRY_CHECK_RC(OM::write(rene, rd)); /* * update the interface to change to a new route-domain * expect that the l3-bindings are removed and readded. */ interface *itf2 = new interface(itf1_name, interface::type_t::AFPACKET, interface::admin_state_t::UP, rd); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10)); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11)); ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV4, hw_ifh1)); ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_bind, l3_proto_t::IPV6, hw_ifh1)); ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10)); ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11)); TRY_CHECK_RC(OM::write(rene, *itf2)); /* * mve the interface back to the default route-domain */ interface itf3(itf1_name, interface::type_t::AFPACKET, interface::admin_state_t::UP); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10)); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11)); ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV4, hw_ifh1)); ADD_EXPECT(interface_cmds::set_table_cmd(hw_rd_unbind, l3_proto_t::IPV6, hw_ifh1)); ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind1, hw_ifh1.data(), pfx_10)); ADD_EXPECT(l3_binding_cmds::bind_cmd(hw_l3_bind2, hw_ifh1.data(), pfx_11)); TRY_CHECK_RC(OM::write(rene, itf3)); delete l3_1; delete l3_2; delete itf2; STRICT_ORDER_OFF(); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind1, hw_ifh1.data(), pfx_10)); ADD_EXPECT(l3_binding_cmds::unbind_cmd(hw_l3_unbind2, hw_ifh1.data(), pfx_11)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh1)); ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh1, itf1_name)); ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV4, 1)); ADD_EXPECT(route_domain_cmds::delete_cmd(hw_rd_delete, l3_proto_t::IPV6, 1)); TRY_CHECK(OM::remove(rene)); } BOOST_AUTO_TEST_CASE(test_prefixes) { route::prefix_t p6_s_16(boost::asio::ip::address::from_string("2001::"), 16); BOOST_CHECK(p6_s_16.mask() == boost::asio::ip::address::from_string("ffff::")); route::prefix_t p6_s_17(boost::asio::ip::address::from_string("2001:ff00::"), 17); BOOST_CHECK(p6_s_17.mask() == boost::asio::ip::address::from_string("ffff:8000::")); BOOST_CHECK(p6_s_17.low().address() == boost::asio::ip::address::from_string("2001:8000::")); route::prefix_t p6_s_15(boost::asio::ip::address::from_string("2001:ff00::"), 15); BOOST_CHECK(p6_s_15.mask() == boost::asio::ip::address::from_string("fffe::")); BOOST_CHECK(p6_s_15.low().address() == boost::asio::ip::address::from_string("2000::")); route::prefix_t p4_s_16(boost::asio::ip::address::from_string("192.168.0.0"), 16); BOOST_CHECK(p4_s_16.mask() == boost::asio::ip::address::from_string("255.255.0.0")); route::prefix_t p4_s_17(boost::asio::ip::address::from_string("192.168.127.0"), 17); BOOST_CHECK(p4_s_17.mask() == boost::asio::ip::address::from_string("255.255.128.0")); BOOST_CHECK(p4_s_17.low().address() == boost::asio::ip::address::from_string("192.168.0.0")); BOOST_CHECK(p4_s_17.high().address() == boost::asio::ip::address::from_string("192.168.127.255")); route::prefix_t p4_s_15(boost::asio::ip::address::from_string("192.168.255.255"), 15); BOOST_CHECK(p4_s_15.mask() == boost::asio::ip::address::from_string("255.254.0.0")); BOOST_CHECK(p4_s_15.low().address() == boost::asio::ip::address::from_string("192.168.0.0")); BOOST_CHECK(p4_s_15.high().address() == boost::asio::ip::address::from_string("192.169.255.255")); route::prefix_t p4_s_32(boost::asio::ip::address::from_string("192.168.1.1"), 32); BOOST_CHECK(p4_s_32.mask() == boost::asio::ip::address::from_string("255.255.255.255")); BOOST_CHECK(p4_s_32.low().address() == boost::asio::ip::address::from_string("192.168.1.1")); BOOST_CHECK(p4_s_32.high().address() == boost::asio::ip::address::from_string("192.168.1.1")); } BOOST_AUTO_TEST_CASE(test_pipes) { VppInit vi; const std::string gk = "GKChesterton"; const std::string pipe_name_1 = "pipe1"; VOM::pipe pipe1(1, interface::admin_state_t::UP); HW::item hw_hdl(4, rc_t::OK); HW::item hw_hdl_pair(std::make_pair(5,6), rc_t::OK); HW::item hw_as_up(interface::admin_state_t::UP, rc_t::OK); HW::item hw_as_down(interface::admin_state_t::DOWN, rc_t::OK); ADD_EXPECT(pipe_cmds::create_cmd(hw_hdl, pipe_name_1, 1, hw_hdl_pair)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_hdl)); TRY_CHECK_RC(OM::write(gk, pipe1)); pipe1.set_ends(hw_hdl_pair.data()); // put each end of the pipe in a BD bridge_domain bd1(33, bridge_domain::learning_mode_t::OFF, bridge_domain::arp_term_mode_t::OFF, bridge_domain::arp_ufwd_mode_t::ON, bridge_domain::flood_mode_t::OFF, bridge_domain::uu_flood_mode_t::ON, bridge_domain::mac_age_mode_t::ON); HW::item hw_bd(33, rc_t::OK); ADD_EXPECT(bridge_domain_cmds::create_cmd(hw_bd, bridge_domain::learning_mode_t::OFF, bridge_domain::arp_term_mode_t::OFF, bridge_domain::arp_ufwd_mode_t::ON, bridge_domain::flood_mode_t::OFF, bridge_domain::uu_flood_mode_t::ON, bridge_domain::mac_age_mode_t::ON)); TRY_CHECK_RC(OM::write(gk, bd1)); l2_binding *l2_1 = new l2_binding(*pipe1.east(), bd1); HW::item hw_l2_1_bind(true, rc_t::OK); ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_1_bind, pipe1.east()->handle(), hw_bd.data(), l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL)); TRY_CHECK_RC(OM::write(gk, *l2_1)); l2_binding *l2_2 = new l2_binding(*pipe1.west(), bd1); HW::item hw_l2_2_bind(true, rc_t::OK); ADD_EXPECT(l2_binding_cmds::bind_cmd(hw_l2_2_bind, pipe1.west()->handle(), hw_bd.data(), l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL)); TRY_CHECK_RC(OM::write(gk, *l2_2)); STRICT_ORDER_OFF(); delete l2_1; delete l2_2; ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind, pipe1.east()->handle(), hw_bd.data(), l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL)); ADD_EXPECT(l2_binding_cmds::unbind_cmd(hw_l2_1_bind, pipe1.west()->handle(), hw_bd.data(), l2_binding::l2_port_type_t::L2_PORT_TYPE_NORMAL)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_hdl)); ADD_EXPECT(pipe_cmds::delete_cmd(hw_hdl, hw_hdl_pair)); ADD_EXPECT(bridge_domain_cmds::delete_cmd(hw_bd)); TRY_CHECK(OM::remove(gk)); } BOOST_AUTO_TEST_CASE(test_qos) { VppInit vi; const std::string albert = "AlbertCamus"; rc_t rc = rc_t::OK; /* * Create an interface on which to enable QoS */ std::string itf_name = "host1"; interface itf(itf_name, interface::type_t::AFPACKET, interface::admin_state_t::UP); HW::item hw_ifh(2, rc_t::OK); HW::item hw_as_up(interface::admin_state_t::UP, rc_t::OK); HW::item hw_as_down(interface::admin_state_t::DOWN, rc_t::OK); ADD_EXPECT(interface_cmds::af_packet_create_cmd(hw_ifh, itf_name)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_up, hw_ifh)); TRY_CHECK_RC(OM::write(albert, itf)); QoS::map::outputs_t out; out[0][5] = 5; out[3][6] = 6; QoS::map qem(1, out); HW::item hw_qem(true, rc_t::OK); ADD_EXPECT(QoS::map_cmds::create_cmd(hw_qem, 1, out)); TRY_CHECK_RC(OM::write(albert, qem)); QoS::record *qr = new QoS::record(itf, QoS::source_t::IP); HW::item hw_qr(true, rc_t::OK); ADD_EXPECT(QoS::record_cmds::create_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP)); TRY_CHECK_RC(OM::write(albert, *qr)); QoS::store *qs = new QoS::store(itf, QoS::source_t::IP, 55); HW::item hw_qs(true, rc_t::OK); ADD_EXPECT(QoS::store_cmds::create_cmd(hw_qs, hw_ifh.data(), QoS::source_t::IP, 55)); TRY_CHECK_RC(OM::write(albert, *qs)); QoS::mark *qm = new QoS::mark(itf, qem, QoS::source_t::IP); HW::item hw_qm(true, rc_t::OK); ADD_EXPECT(QoS::mark_cmds::create_cmd(hw_qm, hw_ifh.data(), 1, QoS::source_t::IP)); TRY_CHECK_RC(OM::write(albert, *qm)); STRICT_ORDER_OFF(); delete qr; delete qm; delete qs; ADD_EXPECT(QoS::mark_cmds::delete_cmd(hw_qm, hw_ifh.data(), QoS::source_t::IP)); ADD_EXPECT(QoS::map_cmds::delete_cmd(hw_qem, 1)); ADD_EXPECT(QoS::record_cmds::delete_cmd(hw_qr, hw_ifh.data(), QoS::source_t::IP)); ADD_EXPECT(QoS::store_cmds::delete_cmd(hw_qs, hw_ifh.data(), QoS::source_t::IP)); ADD_EXPECT(interface_cmds::state_change_cmd(hw_as_down, hw_ifh)); ADD_EXPECT(interface_cmds::af_packet_delete_cmd(hw_ifh, itf_name)); TRY_CHECK(OM::remove(albert)); } BOOST_AUTO_TEST_SUITE_END()