2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * The data-path object representing receiveing the packet, i.e. it's for-us
19 #include <vlib/vlib.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/dpo/receive_dpo.h>
24 * @brief pool of all receive DPOs
26 receive_dpo_t *receive_dpo_pool;
29 dpo_is_receive (const dpo_id_t *dpo)
31 return (dpo->dpoi_type == DPO_RECEIVE);
34 static receive_dpo_t *
35 receive_dpo_alloc (void)
41 dpo_pool_barrier_sync (vm, receive_dpo_pool, did_barrier_sync);
42 pool_get_aligned(receive_dpo_pool, rd, CLIB_CACHE_LINE_BYTES);
43 dpo_pool_barrier_release (vm, did_barrier_sync);
45 clib_memset(rd, 0, sizeof(*rd));
50 static receive_dpo_t *
51 receive_dpo_get_from_dpo (const dpo_id_t *dpo)
53 ASSERT(DPO_RECEIVE == dpo->dpoi_type);
55 return (receive_dpo_get(dpo->dpoi_index));
60 * receive_dpo_add_or_lock
62 * The next_hop address here is used for source address selection in the DP.
63 * The local adj is added to an interface's receive prefix, the next-hop
64 * passed here is the local prefix on the same interface.
67 receive_dpo_add_or_lock (dpo_proto_t proto,
69 const ip46_address_t *nh_addr,
74 rd = receive_dpo_alloc();
76 rd->rd_sw_if_index = sw_if_index;
79 rd->rd_addr = *nh_addr;
82 dpo_set(dpo, DPO_RECEIVE, proto, (rd - receive_dpo_pool));
86 receive_dpo_lock (dpo_id_t *dpo)
90 rd = receive_dpo_get_from_dpo(dpo);
95 receive_dpo_unlock (dpo_id_t *dpo)
99 rd = receive_dpo_get_from_dpo(dpo);
102 if (0 == rd->rd_locks)
104 pool_put(receive_dpo_pool, rd);
109 format_receive_dpo (u8 *s, va_list *ap)
111 CLIB_UNUSED(index_t index) = va_arg(*ap, index_t);
112 CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
113 vnet_main_t * vnm = vnet_get_main();
116 if (pool_is_free_index(receive_dpo_pool, index))
118 return (format(s, "dpo-receive DELETED"));
121 rd = receive_dpo_get(index);
123 if (~0 != rd->rd_sw_if_index)
125 return (format(s, "dpo-receive: %U on %U",
126 format_ip46_address, &rd->rd_addr, IP46_TYPE_ANY,
127 format_vnet_sw_interface_name, vnm,
128 vnet_get_sw_interface(vnm, rd->rd_sw_if_index)));
132 return (format(s, "dpo-receive"));
137 receive_dpo_mem_show (void)
139 fib_show_memory_usage("Receive",
140 pool_elts(receive_dpo_pool),
141 pool_len(receive_dpo_pool),
142 sizeof(receive_dpo_t));
145 const static dpo_vft_t receive_vft = {
146 .dv_lock = receive_dpo_lock,
147 .dv_unlock = receive_dpo_unlock,
148 .dv_format = format_receive_dpo,
149 .dv_mem_show = receive_dpo_mem_show,
153 * @brief The per-protocol VLIB graph nodes that are assigned to a receive
156 * this means that these graph nodes are ones from which a receive is the
157 * parent object in the DPO-graph.
159 const static char* const receive_ip4_nodes[] =
164 const static char* const receive_ip6_nodes[] =
170 const static char* const * const receive_nodes[DPO_PROTO_NUM] =
172 [DPO_PROTO_IP4] = receive_ip4_nodes,
173 [DPO_PROTO_IP6] = receive_ip6_nodes,
174 [DPO_PROTO_MPLS] = NULL,
178 receive_dpo_module_init (void)
180 dpo_register(DPO_RECEIVE, &receive_vft, receive_nodes);