summaryrefslogtreecommitdiffstats
path: root/src/vnet/bier/bier_update.c
blob: 4108d09f51e5738cad1789a8383f0ad876b7d729 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
 * 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 <vnet/vnet.h>
#include <vnet/mpls/mpls.h>

#include <vnet/bier/bier_table.h>
#include <vnet/bier/bier_types.h>
#include <vnet/bier/bier_update.h>

clib_error_t *
vnet_bier_table_cmd (vlib_main_t * vm,
                     unformat_input_t * input,
                     vlib_cli_command_t * cmd)
{
    u32 hdr_len, local_label;
    clib_error_t * error = 0;
    bier_table_id_t bti = {
        .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
    };
    u32 is_add = 0;

    local_label = MPLS_LABEL_INVALID;

    while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
        if (unformat (input, "del")) {
            is_add = 0;
        } else if (unformat (input, "add")) {
            is_add = 1;
        } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
        } else if (unformat (input, "set %d", &bti.bti_set)) {
        } else if (unformat (input, "bsl %d", &hdr_len)) {
        } else if (unformat (input, "mpls %d", &local_label)) {
        } else {
            error = unformat_parse_error (input);
            goto done;
        }
    }

    bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
    // FIXME
    bti.bti_type = BIER_TABLE_MPLS_SPF;

    if (is_add)
    {
        bier_table_add_or_lock(&bti, local_label);
    }
    else
    {
        bier_table_unlock(&bti);
    }

done:
    return (error);
}

VLIB_CLI_COMMAND (bier_table_command) = {
  .path = "bier table",
  .short_help = "bier table [add|del] sd <sub-domain> set <SET> bsl <bit-string-length> [mpls <label>]",
  .function = vnet_bier_table_cmd,
};

clib_error_t *
vnet_bier_route_cmd (vlib_main_t * vm,
                     unformat_input_t * input,
                     vlib_cli_command_t * cmd)
{
    clib_error_t * error = NULL;
    fib_route_path_t *brps = NULL, brp = {
        .frp_flags = FIB_ROUTE_PATH_BIER_FMASK,
    };
    u32 hdr_len, payload_proto;
    bier_table_id_t bti = {
        .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
    };
    bier_bp_t bp;
    u32 add = 1;

    payload_proto = DPO_PROTO_BIER;

    while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
        if (unformat (input, "del")) {
            add = 0;
        } else if (unformat (input, "add")) {
            add = 1;
        } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
        } else if (unformat (input, "set %d", &bti.bti_set)) {
        } else if (unformat (input, "bsl %d", &hdr_len)) {
        } else if (unformat (input, "bp %d", &bp)) {
        } else if (unformat (input, "via %U",
                             unformat_fib_route_path,
                             &brp, &payload_proto)) {
        } else {
            error = unformat_parse_error (input);
            goto done;
        }
    }

    vec_add1(brps, brp);
    bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
    // FIXME
    bti.bti_type    = BIER_TABLE_MPLS_SPF;

    if (add)
    {
        bier_table_route_path_add(&bti, bp, brps);
    }
    else
    {
        bier_table_route_path_remove(&bti, bp, brps);
    }

done:
    vec_free(brps);
    return (error);
}

VLIB_CLI_COMMAND (bier_route_command) = {
  .path = "bier route",
  .short_help = "bier route [add|del] sd <sud-domain> set <set> bsl <bit-string-length> bp <bit-position> via [next-hop-address] [next-hop-interface] [next-hop-table <value>] [weight <value>] [preference <value>] [udp-encap-id <value>] [ip4-lookup-in-table <value>] [ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] [resolve-via-host] [resolve-via-connected] [rx-ip4 <interface>] [out-labels <value value value>]",
  .function = vnet_bier_route_cmd,
};

static clib_error_t *
show_bier_fib_command_fn (vlib_main_t * vm,
                          unformat_input_t * input,
                          vlib_cli_command_t * cmd)
{
    bier_show_flags_t flags;
    index_t bti, bei;
    bier_bp_t bp;

    bp = BIER_BP_INVALID;
    bti = bei = INDEX_INVALID;
    flags = BIER_SHOW_BRIEF;

    while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
        if (unformat (input, "%d %d", &bti, &bp))
        {
            flags = BIER_SHOW_DETAIL;
        }
        else if (unformat (input, "%d", &bti))
        {
            flags = BIER_SHOW_DETAIL;
        }
        else
        {
            break;
        }
    }

    if (INDEX_INVALID == bti)
    {
        bier_table_show_all(vm, flags);
    }
    else
    {
        if (!pool_is_free_index(bier_table_pool, bti))
        {
            if (BIER_BP_INVALID == bp)
            {
                vlib_cli_output (vm, "%U", format_bier_table, bti, flags);
            }
            else
            {
                vlib_cli_output (vm, "%U", format_bier_table_entry, bti, bp);
            }
        }
    }
    return (NULL);
}

VLIB_CLI_COMMAND (show_bier_fib_command, static) = {
    .path = "show bier fib",
    .short_help = "show bier fib [table-index] [bit-position]",
    .function = show_bier_fib_command_fn,
};
types contribute to 1 to the depth. */ #define FIB_NODE_GRAPH_MAX_DEPTH ((u32)32) /** * A callback function for walking a node dependency list */ typedef int (*fib_node_ptr_walk_t)(fib_node_ptr_t *depend, void *ctx); /** * A list of dependent nodes. * This is currently implemented as a hash_table of fib_node_ptr_t */ typedef fib_node_ptr_t fib_node_ptr_list_t; /** * Return code from a back walk function */ typedef enum fib_node_back_walk_rc_t_ { FIB_NODE_BACK_WALK_MERGE, FIB_NODE_BACK_WALK_CONTINUE, } fib_node_back_walk_rc_t; /** * Function definition to backwalk a FIB node */ typedef fib_node_back_walk_rc_t (*fib_node_back_walk_t)( struct fib_node_t_ *node, fib_node_back_walk_ctx_t *ctx); /** * Function definition to get a FIB node from its index */ typedef struct fib_node_t_* (*fib_node_get_t)(fib_node_index_t index); /** * Function definition to inform the FIB node that its last lock has gone. */ typedef void (*fib_node_last_lock_gone_t)(struct fib_node_t_ *node); /** * Function definition to display the amount of memory used by a type. * Implementations should call fib_show_memory_usage() */ typedef void (*fib_node_memory_show_t)(void); /** * A FIB graph nodes virtual function table */ typedef struct fib_node_vft_t_ { fib_node_get_t fnv_get; fib_node_last_lock_gone_t fnv_last_lock; fib_node_back_walk_t fnv_back_walk; format_function_t *fnv_format; fib_node_memory_show_t fnv_mem_show; } fib_node_vft_t; /** * An node in the FIB graph * * Objects in the FIB form a graph. */ typedef struct fib_node_t_ { /** * The node's type. make sure we are dynamic/down casting correctly */ fib_node_type_t fn_type; /** * Some pad space the concrete/derived type is free to use */ u16 fn_pad; /** * Vector of nodes that depend upon/use/share this node */ fib_node_list_t fn_children; /** * Number of dependents on this node. This number includes the number * of children */ u32 fn_locks; } fib_node_t; STATIC_ASSERT(sizeof(fib_node_t) == 12, "FIB node type is growing"); /** * @brief * Register the function table for a given type * * @param ft * FIB node type * * @param vft * virtual function table */ extern void fib_node_register_type (fib_node_type_t ft, const fib_node_vft_t *vft); /** * @brief * Create a new FIB node type and Register the function table for it. * * @param vft * virtual function table * * @return new FIB node type */ extern fib_node_type_t fib_node_register_new_type (const fib_node_vft_t *vft); /** * @brief Show the memory usage for a type * * This should be invoked by the type in response to the infra calling * its registered memory show function * * @param name the name of the type * @param in_use_elts The number of elements in use * @param allocd_elts The number of allocated pool elemenets * @param size_elt The size of one element */ extern void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt); extern void fib_node_init(fib_node_t *node, fib_node_type_t ft); extern void fib_node_deinit(fib_node_t *node); extern void fib_node_lock(fib_node_t *node); extern void fib_node_unlock(fib_node_t *node); extern u32 fib_node_get_n_children(fib_node_type_t parent_type, fib_node_index_t parent_index); extern u32 fib_node_child_add(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_type_t child_type, fib_node_index_t child_index); extern void fib_node_child_remove(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_index_t sibling_index); extern fib_node_back_walk_rc_t fib_node_back_walk_one(fib_node_ptr_t *ptr, fib_node_back_walk_ctx_t *ctx); extern u8* fib_node_children_format(fib_node_list_t list, u8 *s); extern const char* fib_node_type_get_name(fib_node_type_t type); static inline int fib_node_index_is_valid (fib_node_index_t ni) { return (FIB_NODE_INDEX_INVALID != ni); } #endif