2 * Copyright (c) 2017 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.
16 #include <vnet/ip/ip.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vnet/udp/udp.h>
19 #include <ioam/ipfixcollector/ipfixcollector.h>
21 ipfix_collector_main_t ipfix_collector_main;
24 * @brief IP-FIX SetID registration function.
26 * This function can be used by other VPP graph nodes to receive IP-FIX packets
27 * with a particular setid.
29 * @param vlib_main_t Vlib main of the graph node which is interseted in
30 * getting IP-Fix packet.
31 * @param ipfix_client_add_del_t Structure describing the client node which
32 * is interested in getting the IP-Fix packets for
35 * @returns 0 on success.
36 * @returns Error codes(<0) otherwise.
39 ipfix_collector_reg_setid (vlib_main_t * vm, ipfix_client_add_del_t * info)
41 ipfix_collector_main_t *cm = &ipfix_collector_main;
44 ipfix_client *client = 0;
46 if ((!info) || (!info->client_name))
47 return IPFIX_COLLECTOR_ERR_INVALID_PARAM;
49 p = hash_get (cm->client_reg_table, info->ipfix_setid);
50 client = p ? pool_elt_at_index (cm->client_reg_pool, (*p)) : NULL;
55 return 0; //There is no registered handler, so send success
57 hash_unset (cm->client_reg_table, info->ipfix_setid);
58 vec_free (client->client_name);
59 pool_put (cm->client_reg_pool, client);
64 return IPFIX_COLLECTOR_ERR_REG_EXISTS;
66 pool_get (cm->client_reg_pool, client);
67 i = client - cm->client_reg_pool;
68 client->client_name = vec_dup (info->client_name);
69 client->client_node = info->client_node;
70 client->client_next_node = vlib_node_add_next (vm,
71 ipfix_collector_node.index,
73 client->set_id = info->ipfix_setid;
75 hash_set (cm->client_reg_table, info->ipfix_setid, i);
80 ipfix_collector_init (vlib_main_t * vm)
82 clib_error_t *error = 0;
83 ipfix_collector_main_t *cm = &ipfix_collector_main;
86 cm->vnet_main = vnet_get_main ();
88 cm->client_reg_pool = NULL;
89 cm->client_reg_table = hash_create (0, sizeof (uword));
91 udp_register_dst_port (vm,
93 ipfix_collector_node.index, 1 /* is_ip4 */ );
97 VLIB_INIT_FUNCTION (ipfix_collector_init);
100 * fd.io coding-style-patch-verification: ON
103 * eval: (c-set-style "gnu")