summaryrefslogtreecommitdiffstats
path: root/src/vnet/fib/fib_entry_src_mpls.c
blob: f3d1dc0bd509960e6aa632dc3551125cd453f586 (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
190
191
192
193
194
195
196
197
/*
 * 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/mpls/mpls_types.h>
#include <vnet/dpo/drop_dpo.h>

#include <vnet/fib/fib_table.h>
#include <vnet/fib/fib_entry.h>
#include <vnet/fib/fib_entry_src.h>
#include <vnet/fib/mpls_fib.h>

/**
 * Source initialisation Function
 */
static void
fib_entry_src_mpls_init (fib_entry_src_t *src)
{
    mpls_eos_bit_t eos;

    src->fes_flags = FIB_ENTRY_SRC_FLAG_NONE;
    src->u.mpls.fesm_label = MPLS_LABEL_INVALID;

    FOR_EACH_MPLS_EOS_BIT(eos)
    {
        src->u.mpls.fesm_lfes[eos] = FIB_NODE_INDEX_INVALID;
    }
}

/**
 * Source deinitialisation Function
 */
static void
fib_entry_src_mpls_deinit (fib_entry_src_t *src)
{
}

static void
fib_entry_src_mpls_remove (fib_entry_src_t *src)
{
    src->fes_pl = FIB_NODE_INDEX_INVALID;
    src->u.mpls.fesm_label = MPLS_LABEL_INVALID;
}

static void
fib_entry_src_mpls_add (fib_entry_src_t *src,
                        const fib_entry_t *entry,
                        fib_entry_flag_t flags,
                        dpo_proto_t proto,
                        const dpo_id_t *dpo)
{
    src->fes_pl =
        fib_path_list_create_special(proto,
                                     FIB_PATH_LIST_FLAG_DROP,
                                     drop_dpo_get(proto));
}

static void
fib_entry_src_mpls_set_data (fib_entry_src_t *src,
                             const fib_entry_t *entry,
                             const void *data)
{
    fib_protocol_t payload_proto;
    fib_node_index_t fei;
    mpls_label_t label;
    mpls_eos_bit_t eos;

    /*
     * post MPLS table alloc and the possible rea-alloc of fib entrys
     * the entry pointer will no longer be valid. so save its index
     */
    payload_proto = entry->fe_prefix.fp_proto;
    fei = fib_entry_get_index(entry);
    label = *(mpls_label_t*)data;

    if (MPLS_LABEL_INVALID == label)
    {
        /*
         * removing the local label
         */
        FOR_EACH_MPLS_EOS_BIT(eos)
        {
            fib_table_entry_delete_index(src->u.mpls.fesm_lfes[eos],
                                         FIB_SOURCE_SPECIAL);
        }
        fib_table_unlock(MPLS_FIB_DEFAULT_TABLE_ID,
                         FIB_PROTOCOL_MPLS,
                         FIB_SOURCE_MPLS);
        src->u.mpls.fesm_label = label;
    }
    else
    {
        fib_prefix_t prefix = {
            .fp_proto = FIB_PROTOCOL_MPLS,
            .fp_label = label,
        };
        fib_node_index_t fib_index;
        dpo_id_t dpo = DPO_INVALID;

        /*
         * adding a new local label. make sure the MPLS fib exists.
         */
        if (MPLS_LABEL_INVALID == src->u.mpls.fesm_label)
        {
            fib_index =
                fib_table_find_or_create_and_lock(FIB_PROTOCOL_MPLS,
                                                  MPLS_FIB_DEFAULT_TABLE_ID,
                                                  FIB_SOURCE_MPLS);
        }
        else
        {
            fib_index = mpls_fib_index_from_table_id(MPLS_FIB_DEFAULT_TABLE_ID);

            /*
             * if this is a change in label, remove the old one first
             */
            if (src->u.mpls.fesm_label != label)
            {
                FOR_EACH_MPLS_EOS_BIT(eos)
                {
                    ASSERT(FIB_NODE_INDEX_INVALID != src->u.mpls.fesm_lfes[eos]);
                    fib_table_entry_delete_index(src->u.mpls.fesm_lfes[eos],
                                                 FIB_SOURCE_SPECIAL);
                }
            }
        }

        src->u.mpls.fesm_label = label;

        FOR_EACH_MPLS_EOS_BIT(eos)
        {
            prefix.fp_eos = eos;
            prefix.fp_payload_proto = fib_proto_to_dpo(payload_proto);

            fib_entry_contribute_forwarding(fei,
                                            (eos ?
                                             FIB_FORW_CHAIN_TYPE_MPLS_EOS :
                                             FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS),
                                            &dpo);
            src->u.mpls.fesm_lfes[eos] =
                fib_table_entry_special_dpo_add(fib_index,
                                                &prefix,
                                                FIB_SOURCE_SPECIAL,
                                                FIB_ENTRY_FLAG_EXCLUSIVE,
                                                &dpo);
            dpo_reset(&dpo);
        }
    }
}

static const void *
fib_entry_src_mpls_get_data (fib_entry_src_t *src,
                             const fib_entry_t *entry)
{
    return (&(src->u.mpls.fesm_label));
}

static u8*
fib_entry_src_mpls_format (fib_entry_src_t *src,
                           u8* s)
{
    return (format(s, " local-label:%d", src->u.mpls.fesm_label));
}

const static fib_entry_src_vft_t mpls_src_vft = {
    .fesv_init = fib_entry_src_mpls_init,
    .fesv_deinit = fib_entry_src_mpls_deinit,
    .fesv_add = fib_entry_src_mpls_add,
    .fesv_remove = fib_entry_src_mpls_remove,
    .fesv_format = fib_entry_src_mpls_format,
    .fesv_set_data = fib_entry_src_mpls_set_data,
    .fesv_get_data = fib_entry_src_mpls_get_data,
    /*
     * .fesv_fwd_update = fib_entry_src_mpls_fwd_update,
     *  When the forwarding for the IP entry is updated, any MPLS chains
     * it has created are also updated. Since the MPLS entry will have already
     * installed that chain/load-balance there is no need to update the netry
     * FIXME: later: propagate any walk to the children of the MPLS entry. for SR
     */
};

void
fib_entry_src_mpls_register (void)
{
    fib_entry_src_register(FIB_SOURCE_MPLS, &mpls_src_vft);
}
an> (vm, hm->frame_queue_index, from, thread_indices, frame->n_vectors, 1); if (n_enq < frame->n_vectors) vlib_node_increment_counter (vm, node->node_index, WORKER_HANDOFF_ERROR_CONGESTION_DROP, frame->n_vectors - n_enq); return frame->n_vectors; } /* *INDENT-OFF* */ VLIB_REGISTER_NODE (worker_handoff_node) = { .name = "worker-handoff", .vector_size = sizeof (u32), .format_trace = format_worker_handoff_trace, .type = VLIB_NODE_TYPE_INTERNAL, .n_errors = ARRAY_LEN(worker_handoff_error_strings), .error_strings = worker_handoff_error_strings, .n_next_nodes = 1, .next_nodes = { [0] = "error-drop", }, }; /* *INDENT-ON* */ #ifndef CLIB_MARCH_VARIANT int interface_handoff_enable_disable (vlib_main_t * vm, u32 sw_if_index, uword * bitmap, int enable_disable) { handoff_main_t *hm = &handoff_main; vnet_sw_interface_t *sw; vnet_main_t *vnm = vnet_get_main (); per_inteface_handoff_data_t *d; int i, rv = 0; if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index)) return VNET_API_ERROR_INVALID_SW_IF_INDEX; sw = vnet_get_sw_interface (vnm, sw_if_index); if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) return VNET_API_ERROR_INVALID_SW_IF_INDEX; if (clib_bitmap_last_set (bitmap) >= hm->num_workers) return VNET_API_ERROR_INVALID_WORKER; if (hm->frame_queue_index == ~0) { vlib_node_t *n = vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); hm->frame_queue_index = vlib_frame_queue_main_init (n->index, 0); } vec_validate (hm->if_data, sw_if_index); d = vec_elt_at_index (hm->if_data, sw_if_index); vec_free (d->workers); vec_free (d->workers_bitmap); if (enable_disable) { d->workers_bitmap = bitmap; /* *INDENT-OFF* */ clib_bitmap_foreach (i, bitmap, ({ vec_add1(d->workers, i); })); /* *INDENT-ON* */ } vnet_feature_enable_disable ("device-input", "worker-handoff", sw_if_index, enable_disable, 0, 0); return rv; } static clib_error_t * set_interface_handoff_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { handoff_main_t *hm = &handoff_main; u32 sw_if_index = ~0; int enable_disable = 1; uword *bitmap = 0; u32 sym = ~0; int rv = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "disable")) enable_disable = 0; else if (unformat (input, "workers %U", unformat_bitmap_list, &bitmap)) ; else if (unformat (input, "%U", unformat_vnet_sw_interface, vnet_get_main (), &sw_if_index)) ; else if (unformat (input, "symmetrical")) sym = 1; else if (unformat (input, "asymmetrical")) sym = 0; else break; } if (sw_if_index == ~0) return clib_error_return (0, "Please specify an interface..."); if (bitmap == 0) return clib_error_return (0, "Please specify list of workers..."); rv = interface_handoff_enable_disable (vm, sw_if_index, bitmap, enable_disable); switch (rv) { case 0: break; case VNET_API_ERROR_INVALID_SW_IF_INDEX: return clib_error_return (0, "Invalid interface"); break; case VNET_API_ERROR_INVALID_WORKER: return clib_error_return (0, "Invalid worker(s)"); break; case VNET_API_ERROR_UNIMPLEMENTED: return clib_error_return (0, "Device driver doesn't support redirection"); break; default: return clib_error_return (0, "unknown return value %d", rv); } if (sym == 1) hm->hash_fn = eth_get_sym_key; else if (sym == 0) hm->hash_fn = eth_get_key; return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_interface_handoff_command, static) = { .path = "set interface handoff", .short_help = "set interface handoff <interface-name> workers <workers-list> [symmetrical|asymmetrical]", .function = set_interface_handoff_command_fn, }; /* *INDENT-ON* */ clib_error_t * handoff_init (vlib_main_t * vm) { handoff_main_t *hm = &handoff_main; vlib_thread_main_t *tm = vlib_get_thread_main (); clib_error_t *error; uword *p; if ((error = vlib_call_init_function (vm, threads_init))) return error; vlib_thread_registration_t *tr; /* Only the standard vnet worker threads are supported */ p = hash_get_mem (tm->thread_registrations_by_name, "workers"); if (p) { tr = (vlib_thread_registration_t *) p[0]; if (tr) { hm->num_workers = tr->count; hm->first_worker_index = tr->first_index; } } hm->hash_fn = eth_get_key; hm->frame_queue_index = ~0; return 0; } VLIB_INIT_FUNCTION (handoff_init); #endif /* CLIB_MARCH_VARIANT */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */