/* * Copyright (c) 2017 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 #include static clib_error_t * lisp_show_adjacencies_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_adjacency_t *adjs, *adj; vlib_cli_output (vm, "%s %40s\n", "leid", "reid"); unformat_input_t _line_input, *line_input = &_line_input; u32 vni = ~0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "vni %d", &vni)) ; else { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); unformat_free (line_input); return 0; } } unformat_free (line_input); if (~0 == vni) { vlib_cli_output (vm, "error: no vni specified!"); return 0; } adjs = vnet_lisp_adjacencies_get_by_vni (vni); vec_foreach (adj, adjs) { vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid, format_gid_address, &adj->reid); } vec_free (adjs); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_adjacencies_command) = { .path = "show one adjacencies", .short_help = "show one adjacencies", .function = lisp_show_adjacencies_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_map_server_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { int rv = 0; u8 is_add = 1, ip_set = 0; ip_address_t ip; unformat_input_t _line_input, *line_input = &_line_input; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "add")) is_add = 1; else if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "%U", unformat_ip_address, &ip)) ip_set = 1; else { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); unformat_free (line_input); return 0; } } unformat_free (line_input); if (!ip_set) { vlib_cli_output (vm, "map-server ip address not set!"); return 0; } rv = vnet_lisp_add_del_map_server (&ip, is_add); if (!rv) vlib_cli_output (vm, "failed to %s map-server!", is_add ? "add" : "delete"); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_add_del_map_server_command) = { .path = "one map-server", .short_help = "one map-server add|del ", .function = lisp_add_del_map_server_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_local_eid_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); unformat_input_t _line_input, *line_input = &_line_input; u8 is_add = 1; gid_address_t eid; gid_address_t *eids = 0; clib_error_t *error = 0; u8 *locator_set_name = 0; u32 locator_set_index = 0, map_index = 0; uword *p; vnet_lisp_add_del_mapping_args_t _a, *a = &_a; int rv = 0; u32 vni = 0; u8 *key = 0; u32 key_id = 0; clib_memset (&eid, 0, sizeof (eid)); clib_memset (a, 0, sizeof (*a)); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "add")) is_add = 1; else if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "eid %U", unformat_gid_address, &eid)) ; else if (unformat (line_input, "vni %d", &vni)) gid_address_vni (&eid) = vni; else if (unformat (line_input, "secret-key %_%v%_", &key)) ; else if (unformat (line_input, "key-id %U", unformat_hmac_key_id, &key_id)) ; else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) { vec_terminate_c_string (locator_set_name); p = hash_get_mem (lcm->locator_set_index_by_name, locator_set_name); if (!p) { error = clib_error_return (0, "locator-set %s doesn't exist", locator_set_name); goto done; } locator_set_index = p[0]; } else if (unformat (line_input, "authoritative")) a->authoritative = 1; else { error = unformat_parse_error (line_input); goto done; } } /* XXX treat batch configuration */ if (GID_ADDR_SRC_DST == gid_address_type (&eid)) { error = clib_error_return (0, "src/dst is not supported for local EIDs!"); goto done; } if (key && (0 == key_id)) { vlib_cli_output (vm, "invalid key_id!"); goto done; } gid_address_copy (&a->eid, &eid); a->is_add = is_add; a->locator_set_index = locator_set_index; a->local = 1; a->key = key; a->key_id = key_id; rv = vnet_lisp_add_del_local_mapping (a, &map_index); if (0 != rv) { error = clib_error_return (0, "failed to %s local mapping!", is_add ? "add" : "delete"); } done: vec_free (eids); if (locator_set_name) vec_free (locator_set_name); gid_address_free (&a->eid); vec_free (a->key); unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_add_del_local_eid_command) = { .path = "one eid-table", .short_help = "one eid-table add/del [vni ] eid " "locator-set [key key-id sha1|sha256 ]", .function = lisp_add_del_local_eid_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_eid_table_map_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 is_add = 1, is_l2 = 0; u32 vni = 0, dp_id = 0; unformat_input_t _line_input, *line_input = &_line_input; clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (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, "vni %d", &vni)) ; else if (unformat (line_input, "vrf %d", &dp_id)) ; else if (unformat (line_input, "bd %d", &dp_id)) is_l2 = 1; else { error = unformat_parse_error (line_input); goto done; } } vnet_lisp_eid_table_map (vni, dp_id, is_l2, is_add); done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_eid_table_map_command) = { .path = "one eid-table map", .short_help = "one eid-table map [del] vni vrf | bd ", .function = lisp_eid_table_map_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_ndp_entry_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; clib_error_t *error = NULL; int rc = 0; u8 hw_addr[6], bd = 0; ip6_address_t ip6; u32 hw_addr_set = 0, ip_set = 0, is_add = 1; gid_address_t _g, *g = &_g; clib_memset (&ip6, 0, sizeof (ip6)); clib_memset (hw_addr, 0, sizeof (hw_addr)); clib_memset (g, 0, sizeof (*g)); if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) hw_addr_set = 1; else if (unformat (line_input, "ip %U", unformat_ip6_address, &ip6)) ip_set = 1; else if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "bd %d", &bd)) ; else { error = clib_error_return (0, "parse error"); goto done; } } if (!ip_set || (!hw_addr_set && is_add)) { vlib_cli_output (vm, "expected IP and MAC addresses!"); return 0; } /* build GID address */ ip_address_set (&gid_address_arp_ndp_ip (g), &ip6, IP6); gid_address_ndp_bd (g) = bd; gid_address_type (g) = GID_ADDR_NDP; rc = vnet_lisp_add_del_l2_arp_ndp_entry (g, hw_addr, is_add); if (rc) clib_warning ("Failed to %s ndp entry!", is_add ? "add" : "delete"); done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_add_del_ndp_entry_command) = { .path = "one ndp", .short_help = "one ndp [del] bd mac ip ", .function = lisp_add_del_ndp_entry_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_l2_arp_entry_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; clib_error_t *error = NULL; int rc = 0; u8 hw_addr[6], bd = 0; ip4_address_t ip4; u32 hw_addr_set = 0, ip_set = 0, is_add = 1; gid_address_t _arp, *arp = &_arp; clib_memset (&ip4, 0, sizeof (ip4)); clib_memset (hw_addr, 0, sizeof (hw_addr)); clib_memset (arp, 0, sizeof (*arp)); if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "mac %U", unformat_mac_address, hw_addr)) hw_addr_set = 1; else if (unformat (line_input, "ip %U", unformat_ip4_address, &ip4)) ip_set = 1; else if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "bd %d", &bd)) ; else { error = clib_error_return (0, "parse error"); goto done; } } if (!ip_set || (!hw_addr_set && is_add)) { vlib_cli_output (vm, "expected IP and MAC addresses!"); return 0; } /* build GID address */ gid_address_arp_ip4 (arp) = ip4; gid_address_arp_bd (arp) = bd; gid_address_type (arp) = GID_ADDR_ARP; rc = vnet_lisp_add_del_l2_arp_ndp_entry (arp, hw_addr, is_add); if (rc) clib_warning ("Failed to %s l2 arp entry!", is_add ? "add" : "delete"); done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_add_del_l2_arp_entry_command) = { .path = "one l2 arp", .short_help = "one l2 arp [del] bd mac ip ", .function = lisp_add_del_l2_arp_entry_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_l2_arp_entries_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u32 *ht = vnet_lisp_l2_arp_bds_get (); lisp_api_l2_arp_entry_t *entries, *e; hash_pair_t *p; /* *INDENT-OFF* */ hash_foreach_pair (p, ht, ({ entries = vnet_lisp_l2_arp_entries_get_by_bd (p->key); vlib_cli_output (vm, "Table: %d", p->key); vec_foreach (e, entries) { vlib_cli_output (vm, "\t%U -> %U", format_ip4_address, &e->ip4, format_mac_address, e->mac); } vec_free (entries); })); /* *INDENT-ON* */ hash_free (ht); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_l2_arp_entries_command) = { .path = "show one l2 arp entries", .short_help = "Show ONE L2 ARP entries", .function = lisp_show_l2_arp_entries_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_ndp_entries_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u32 *ht = vnet_lis
/*
 * 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.
 */
/**
 * \brief
 * The load-balance object represents an ECMP choice. The buckets of a load
 * balance object point to the sub-graph after the choice is made.
 * THe load-balance object is also object type returned from a FIB table lookup.
 * As such it needs to represent the case where there is only one coice. It may
 * seem like overkill to use a load-balance object in this case, but the reason
 * is for performance. If the load-balance object were not the result of the FIB
 * lookup, then some other object would be. The case where there was ECMP
 * this other object would need a load-balance as a parent and hence just add
 * an unnecessary indirection.
 *
 * It is also the object in the DP that represents a via-fib-entry in a recursive
 * route.
 *
 */

#ifndef __LOAD_BALANCE_H__
#define __LOAD_BALANCE_H__

#include <vlib/vlib.h>
#include <vnet/ip/lookup.h>
#include <vnet/dpo/dpo.h>
#include <vnet/fib/fib_types.h>
#include <vnet/fib/fib_entry.h>

/**
 * Load-balance main
 */
typedef struct load_balance_main_t_
{
    vlib_combined_counter_main_t lbm_to_counters;
    vlib_combined_counter_main_t lbm_via_counters;
} load_balance_main_t;

extern load_balance_main_t load_balance_main;

/**
 * The number of buckets that a load-balance object can have and still
 * fit in one cache-line
 */
#define LB_NUM_INLINE_BUCKETS 4

/**
 * @brief One path from an [EU]CMP set that the client wants to add to a
 * load-balance object
 */
typedef struct load_balance_path_t_ {
    /**
     * ID of the Data-path object.
     */
    dpo_id_t path_dpo;

    /**
     * The index of the FIB path
     */
    fib_node_index_t path_index;

    /**
     * weight for the path.
     */
    u32 path_weight;
} load_balance_path_t;

/**
 * The FIB DPO provieds;
 *  - load-balancing over the next DPOs in the chain/graph
 *  - per-route counters
 */
typedef struct load_balance_t_ {
    /**
     * number of buckets in the load-balance. always a power of 2.
     */
    u16 lb_n_buckets;
    /**
     * number of buckets in the load-balance - 1. used in the switch path
     * as part of the hash calculation.
     */
    u16 lb_n_buckets_minus_1;

   /**
     * The protocol of packets that traverse this LB.
     * need in combination with the flow hash config to determine how to hash.
     * u8.
     */
    dpo_proto_t lb_proto;

    /**
     * Flags from the load-balance's associated fib_entry_t
     */
    fib_entry_flag_t lb_fib_entry_flags;

    /**
     * The number of locks, which is approximately the number of users,
     * of this load-balance.
     * Load-balance objects of via-entries are heavily shared by recursives,
     * so the lock count is a u32.
     */
    u32 lb_locks;

    /**
     * index of the load-balance map, INVALID if this LB does not use one
     */
    index_t lb_map;

    /**
     * This is the index of the uRPF list for this LB
     */
    index_t lb_urpf;

    /**
     * the hash config to use when selecting a bucket. this is a u16
     */
    flow_hash_config_t lb_hash_config;

    /**
     * Vector of buckets containing the next DPOs, sized as lbo_num
     */
    dpo_id_t *lb_buckets;

    /**
     * The rest of the cache line is used for buckets. In the common case
     * where there there are less than 4 buckets, then the buckets are
     * on the same cachlie and we save ourselves a pointer dereferance in 
     * the data-path.
     */
    dpo_id_t lb_buckets_inline[LB_NUM_INLINE_BUCKETS];
} load_balance_t;

STATIC_ASSERT(sizeof(load_balance_t) <= CLIB_CACHE_LINE_BYTES,
	      "A load_balance object size exceeds one cachline");

/**
 * Flags controlling load-balance formatting/display
 */
typedef enum load_balance_format_flags_t_ {
    LOAD_BALANCE_FORMAT_NONE,
    LOAD_BALANCE_FORMAT_DETAIL = (1 << 0),
} load_balance_format_flags_t;

/**
 * Flags controlling load-balance creation and modification
 */
typedef enum load_balance_flags_t_ {
    LOAD_BALANCE_FLAG_NONE = 0,
    LOAD_BALANCE_FLAG_USES_MAP = (1 << 0),
} load_balance_flags_t;

extern index_t load_balance_create(u32 num_buckets,
				   dpo_proto_t lb_proto,
				   flow_hash_config_t fhc);
extern void load_balance_multipath_update(
    const dpo_id_t *dpo,
    const load_balance_path_t * raw_next_hops,
    load_balance_flags_t flags);

extern void load_balance_set_bucket(index_t lbi,
				    u32 bucket,
				    const dpo_id_t *next);
extern void load_balance_set_urpf(index_t lbi,
				  index_t urpf);
extern void load_balance_set_fib_entry_flags(index_t lbi,
                                             fib_entry_flag_t flags);
extern index_t load_balance_get_urpf(index_t lbi);

extern u8* format_load_balance(u8 * s, va_list * args);

extern const dpo_id_t *load_balance_get_bucket(index_t lbi,
					       u32 bucket);
extern int load_balance_is_drop(const dpo_id_t *dpo);

extern f64 load_balance_get_multipath_tolerance(void);

/**
 * The encapsulation breakages are for fast DP access
 */
extern load_balance_t *load_balance_pool;
static inline load_balance_t*
load_balance_get (index_t lbi)
{
    return (pool_elt_at_index(load_balance_pool, lbi));
}

#define LB_HAS_INLINE_BUCKETS(_lb)		\
    ((_lb)->lb_n_buckets <= LB_NUM_INLINE_BUCKETS)

static inline const dpo_id_t *
load_balance_get_bucket_i (const load_balance_t *lb,
			   u32 bucket)
{
    ASSERT(bucket < lb->lb_n_buckets);

    if (PREDICT_TRUE(LB_HAS_INLINE_BUCKETS(lb)))
    {
	return (&lb->lb_buckets_inline[bucket]);
    }
    else
    {
	return (&lb->lb_buckets[bucket]);
    }
}

extern void load_balance_module_init(void);

#endif
cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); goto done; } } if (!is_set) { vlib_cli_output (vm, "state not set!"); goto done; } vnet_lisp_map_register_enable_disable (is_enabled); done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_map_register_enable_disable_command) = { .path = "one map-register", .short_help = "one map-register [enable|disable]", .function = lisp_map_register_enable_disable_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_rloc_probe_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u8 is_enabled = 0; u8 is_set = 0; clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return clib_error_return (0, "expected enable | disable"); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "enable")) { is_set = 1; is_enabled = 1; } else if (unformat (line_input, "disable")) is_set = 1; else { vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, line_input); goto done; } } if (!is_set) { vlib_cli_output (vm, "state not set!"); goto done; } vnet_lisp_rloc_probe_enable_disable (is_enabled); done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_rloc_probe_enable_disable_command) = { .path = "one rloc-probe", .short_help = "one rloc-probe [enable|disable]", .function = lisp_rloc_probe_enable_disable_command_fn, }; /* *INDENT-ON* */ static u8 * format_lisp_status (u8 * s, va_list * args) { lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); return format (s, "%s", lcm->is_enabled ? "enabled" : "disabled"); } static clib_error_t * lisp_show_status_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 *msg = 0; msg = format (msg, "feature: %U\ngpe: %U\n", format_lisp_status, format_vnet_lisp_gpe_status); vlib_cli_output (vm, "%v", msg); vec_free (msg); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_status_command) = { .path = "show one status", .short_help = "show one status", .function = lisp_show_status_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_eid_table_map_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { hash_pair_t *p; unformat_input_t _line_input, *line_input = &_line_input; lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); uword *vni_table = 0; u8 is_l2 = 0; clib_error_t *error = NULL; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "l2")) { vni_table = lcm->bd_id_by_vni; is_l2 = 1; } else if (unformat (line_input, "l3")) { vni_table = lcm->table_id_by_vni; is_l2 = 0; } else { error = clib_error_return (0, "parse error: '%U'", format_unformat_error, line_input); goto done; } } if (!vni_table) { vlib_cli_output (vm, "Error: expected l2|l3 param!\n"); goto done; } vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF"); /* *INDENT-OFF* */ hash_foreach_pair (p, vni_table, ({ vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]); })); /* *INDENT-ON* */ done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_eid_table_map_command) = { .path = "show one eid-table map", .short_help = "show one eid-table l2|l3", .function = lisp_show_eid_table_map_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_locator_set_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_gpe_main_t *lgm = &lisp_gpe_main; vnet_main_t *vnm = lgm->vnet_main; unformat_input_t _line_input, *line_input = &_line_input; u8 is_add = 1; clib_error_t *error = 0; u8 *locator_set_name = 0; locator_t locator, *locators = 0; vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; u32 ls_index = 0; int rv = 0; clib_memset (&locator, 0, sizeof (locator)); clib_memset (a, 0, sizeof (a[0])); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "add %_%v%_", &locator_set_name)) is_add = 1; else if (unformat (line_input, "del %_%v%_", &locator_set_name)) is_add = 0; else if (unformat (line_input, "iface %U p %d w %d", unformat_vnet_sw_interface, vnm, &locator.sw_if_index, &locator.priority, &locator.weight)) { locator.local = 1; locator.state = 1; vec_add1 (locators, locator); } else { error = unformat_parse_error (line_input); goto done; } } vec_terminate_c_string (locator_set_name); a->name = locator_set_name; a->locators = locators; a->is_add = is_add; a->local = 1; rv = vnet_lisp_add_del_locator_set (a, &ls_index); if (0 != rv) { error = clib_error_return (0, "failed to %s locator-set!", is_add ? "add" : "delete"); } done: vec_free (locators); if (locator_set_name) vec_free (locator_set_name); unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_cp_add_del_locator_set_command) = { .path = "one locator-set", .short_help = "one locator-set add/del [iface " "p w ]", .function = lisp_add_del_locator_set_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_locator_in_set_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_gpe_main_t *lgm = &lisp_gpe_main; vnet_main_t *vnm = lgm->vnet_main; unformat_input_t _line_input, *line_input = &_line_input; u8 is_add = 1; clib_error_t *error = 0; u8 *locator_set_name = 0; u8 locator_set_name_set = 0; locator_t locator, *locators = 0; vnet_lisp_add_del_locator_set_args_t _a, *a = &_a; u32 ls_index = 0; clib_memset (&locator, 0, sizeof (locator)); clib_memset (a, 0, sizeof (a[0])); /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "add")) is_add = 1; else if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "locator-set %_%v%_", &locator_set_name)) locator_set_name_set = 1; else if (unformat (line_input, "iface %U p %d w %d", unformat_vnet_sw_interface, vnm, &locator.sw_if_index, &locator.priority, &locator.weight)) { locator.local = 1; vec_add1 (locators, locator); } else { error = unformat_parse_error (line_input); goto done; } } if (!locator_set_name_set) { error = clib_error_return (0, "locator_set name not set!"); goto done; } vec_terminate_c_string (locator_set_name); a->name = locator_set_name; a->locators = locators; a->is_add = is_add; a->local = 1; vnet_lisp_add_del_locator (a, 0, &ls_index); done: vec_free (locators); vec_free (locator_set_name); unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_cp_add_del_locator_in_set_command) = { .path = "one locator", .short_help = "one locator add/del locator-set iface " "p w ", .function = lisp_add_del_locator_in_set_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { locator_set_t *lsit; locator_t *loc; u32 *locit; lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator", "Priority", "Weight"); /* *INDENT-OFF* */ pool_foreach (lsit, lcm->locator_set_pool, ({ u8 * msg = 0; int next_line = 0; if (lsit->local) { msg = format (msg, "%s", lsit->name); } else { msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool); } vec_foreach (locit, lsit->locator_indices) { if (next_line) { msg = format (msg, "%16s", " "); } loc = pool_elt_at_index (lcm->locator_pool, locit[0]); if (loc->local) msg = format (msg, "%16d%16d%16d\n", loc->sw_if_index, loc->priority, loc->weight); else msg = format (msg, "%16U%16d%16d\n", format_ip_address, &gid_address_ip(&loc->address), loc->priority, loc->weight); next_line = 1; } vlib_cli_output (vm, "%v", msg); vec_free (msg); })); /* *INDENT-ON* */ return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_cp_show_locator_sets_command) = { .path = "show one locator-set", .short_help = "Shows locator-sets", .function = lisp_cp_show_locator_sets_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_map_resolver_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u8 is_add = 1, addr_set = 0; ip_address_t ip_addr; clib_error_t *error = 0; int rv = 0; vnet_lisp_add_del_map_resolver_args_t _a, *a = &_a; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "add")) is_add = 1; else if (unformat (line_input, "del")) is_add = 0; else if (unformat (line_input, "%U", unformat_ip_address, &ip_addr)) addr_set = 1; else { error = unformat_parse_error (line_input); goto done; } } if (!addr_set) { error = clib_error_return (0, "Map-resolver address must be set!"); goto done; } a->is_add = is_add; a->address = ip_addr; rv = vnet_lisp_add_del_map_resolver (a); if (0 != rv) { error = clib_error_return (0, "failed to %s map-resolver!", is_add ? "add" : "delete"); } done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_add_del_map_resolver_command) = { .path = "one map-resolver", .short_help = "one map-resolver add/del ", .function = lisp_add_del_map_resolver_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_add_del_mreq_itr_rlocs_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u8 is_add = 1; u8 *locator_set_name = 0; clib_error_t *error = 0; int rv = 0; vnet_lisp_add_del_mreq_itr_rloc_args_t _a, *a = &_a; /* Get a line of input. */ if (!unformat_user (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 %_%v%_", &locator_set_name)) is_add = 1; else { error = unformat_parse_error (line_input); goto done; } } vec_terminate_c_string (locator_set_name); a->is_add = is_add; a->locator_set_name = locator_set_name; rv = vnet_lisp_add_del_mreq_itr_rlocs (a); if (0 != rv) { error = clib_error_return (0, "failed to %s map-request itr-rlocs!", is_add ? "add" : "delete"); } done: vec_free (locator_set_name); unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_add_del_map_request_command) = { .path = "one map-request itr-rlocs", .short_help = "one map-request itr-rlocs add/del ", .function = lisp_add_del_mreq_itr_rlocs_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_mreq_itr_rlocs_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); locator_set_t *loc_set; vlib_cli_output (vm, "%=20s", "itr-rlocs"); if (~0 == lcm->mreq_itr_rlocs) { return 0; } loc_set = pool_elt_at_index (lcm->locator_set_pool, lcm->mreq_itr_rlocs); vlib_cli_output (vm, "%=20s", loc_set->name); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_map_request_command) = { .path = "show one map-request itr-rlocs", .short_help = "Shows map-request itr-rlocs", .function = lisp_show_mreq_itr_rlocs_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_use_petr_set_locator_set_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 is_add = 1, ip_set = 0; unformat_input_t _line_input, *line_input = &_line_input; clib_error_t *error = 0; ip_address_t ip; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U", unformat_ip_address, &ip)) ip_set = 1; else if (unformat (line_input, "disable")) is_add = 0; else { error = clib_error_return (0, "parse error"); goto done; } } if (!ip_set) { clib_warning ("No petr IP specified!"); goto done; } if (vnet_lisp_use_petr (&ip, is_add)) { error = clib_error_return (0, "failed to %s petr!", is_add ? "add" : "delete"); } done: unformat_free (line_input); return error; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_use_petr_set_locator_set_command) = { .path = "one use-petr", .short_help = "one use-petr [disable] ", .function = lisp_use_petr_set_locator_set_command_fn, }; static clib_error_t * lisp_show_petr_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); mapping_t *m; locator_set_t *ls; locator_t *loc; u8 *tmp_str = 0; u8 use_petr = lcm->flags & LISP_FLAG_USE_PETR; vlib_cli_output (vm, "%=20s%=16s", "petr", use_petr ? "ip" : ""); if (!use_petr) { vlib_cli_output (vm, "%=20s", "disable"); return 0; } if (~0 == lcm->petr_map_index) { tmp_str = format (0, "N/A"); } else { m = pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index); if (~0 != m->locator_set_index) { ls = pool_elt_at_index(lcm->locator_set_pool, m->locator_set_index); loc = pool_elt_at_index (lcm->locator_pool, ls->locator_indices[0]); tmp_str = format (0, "%U", format_ip_address, &loc->address); } else { tmp_str = format (0, "N/A"); } } vec_add1 (tmp_str, 0); vlib_cli_output (vm, "%=20s%=16s", "enable", tmp_str); vec_free (tmp_str); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_petr_command) = { .path = "show one petr", .short_help = "Show petr", .function = lisp_show_petr_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_map_servers_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_msmr_t *ms; lisp_cp_main_t *lcm = vnet_lisp_cp_get_main (); vec_foreach (ms, lcm->map_servers) { vlib_cli_output (vm, "%U", format_ip_address, &ms->address); } return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_map_servers_command) = { .path = "show one map-servers", .short_help = "show one map servers", .function = lisp_show_map_servers_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_map_register_state_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 *msg = 0; u8 is_enabled = vnet_lisp_map_register_state_get (); msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); vlib_cli_output (vm, "%v", msg); vec_free (msg); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_map_register_state_command) = { .path = "show one map-register state", .short_help = "show one map-register state", .function = lisp_show_map_register_state_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_rloc_probe_state_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 *msg = 0; u8 is_enabled = vnet_lisp_rloc_probe_state_get (); msg = format (msg, "%s\n", is_enabled ? "enabled" : "disabled"); vlib_cli_output (vm, "%v", msg); vec_free (msg); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = { .path = "show one rloc state", .short_help = "show one RLOC state", .function = lisp_show_rloc_probe_state_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_stats_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 is_enabled = vnet_lisp_stats_enable_disable_state (); vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled"); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_stats_command) = { .path = "show one statistics status", .short_help = "show ONE statistics enable/disable status", .function = lisp_show_stats_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_stats_details_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { lisp_api_stats_t *stat, *stats = vnet_lisp_get_stats (); if (vec_len (stats) > 0) vlib_cli_output (vm, "[src-EID, dst-EID] [loc-rloc, rmt-rloc] count bytes\n"); else vlib_cli_output (vm, "No statistics found.\n"); vec_foreach (stat, stats) { vlib_cli_output (vm, "[%U, %U] [%U, %U] %7u %7u\n", format_fid_address, &stat->seid, format_fid_address, &stat->deid, format_ip_address, &stat->loc_rloc, format_ip_address, &stat->rmt_rloc, stat->counters.packets, stat->counters.bytes); } vec_free (stats); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_show_stats_details_command) = { .path = "show one statistics details", .short_help = "show ONE statistics", .function = lisp_show_stats_details_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_stats_enable_disable_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; u8 enable = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) return clib_error_return (0, "expected enable | disable"); while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "enable")) enable = 1; else if (unformat (line_input, "disable")) enable = 0; else { clib_warning ("Error: expected enable/disable!"); goto done; } } vnet_lisp_stats_enable_disable (enable); done: unformat_free (line_input); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_stats_enable_disable_command) = { .path = "one statistics", .short_help = "enable/disable ONE statistics collecting", .function = lisp_stats_enable_disable_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_stats_flush_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { vnet_lisp_flush_stats (); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_stats_flush_command) = { .path = "one statistics flush", .short_help = "Flush ONE statistics", .function = lisp_stats_flush_command_fn, }; /* *INDENT-ON* */ static clib_error_t * lisp_show_one_modes_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { u8 pitr_mode = vnet_lisp_get_pitr_mode (); u8 petr_mode = vnet_lisp_get_petr_mode (); u8 xtr_mode = vnet_lisp_get_xtr_mode (); vlib_cli_output (vm, "xTR: %s\n", xtr_mode ? "enabled" : "disabled"); vlib_cli_output (vm, "P-ITR: %s\n", pitr_mode ? "enabled" : "disabled"); vlib_cli_output (vm, "P-ETR: %s\n", petr_mode ? "enabled" : "disabled"); return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (one_cp_show_one_modes_modes_command) = { .path = "show one modes", .short_help = "show one modes", .function = lisp_show_one_modes_command_fn, }; /* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */