FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
ipfixcollector.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <vnet/ip/ip.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vnet/udp/udp.h>
20 
22 
23 /**
24  * @brief IP-FIX SetID registration function.
25  *
26  * This function can be used by other VPP graph nodes to receive IP-FIX packets
27  * with a particular setid.
28  *
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
33  * a SetID.
34  *
35  * @returns 0 on success.
36  * @returns Error codes(<0) otherwise.
37  */
38 int
40 {
42  uword *p = NULL;
43  int i;
44  ipfix_client *client = 0;
45 
46  if ((!info) || (!info->client_name))
48 
49  p = hash_get (cm->client_reg_table, info->ipfix_setid);
50  client = p ? pool_elt_at_index (cm->client_reg_pool, (*p)) : NULL;
51 
52  if (info->del)
53  {
54  if (!client)
55  return 0; //There is no registered handler, so send success
56 
58  vec_free (client->client_name);
59  pool_put (cm->client_reg_pool, client);
60  return 0;
61  }
62 
63  if (client)
65 
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;
72  client->client_node);
73  client->set_id = info->ipfix_setid;
74 
75  hash_set (cm->client_reg_table, info->ipfix_setid, i);
76  return 0;
77 }
78 
79 static clib_error_t *
81 {
82  clib_error_t *error = 0;
84 
85  cm->vlib_main = vm;
86  cm->vnet_main = vnet_get_main ();
87 
88  cm->client_reg_pool = NULL;
89  cm->client_reg_table = hash_create (0, sizeof (uword));
90 
92  UDP_DST_PORT_ipfix,
93  ipfix_collector_node.index, 1 /* is_ip4 */ );
94  return error;
95 }
96 
98 
99 /*
100  * fd.io coding-style-patch-verification: ON
101  *
102  * Local Variables:
103  * eval: (c-set-style "gnu")
104  * End:
105  */
u16 del
Add(0) or del(1) operation.
vnet_main_t * vnet_main
Pointer to vnet main for convenience.
#define hash_set(h, key, value)
Definition: hash.h:255
u16 ipfix_setid
Setid of IPFix for which client is intereseted in getting packets.
ipfix_client * client_reg_pool
Pool of Client node information for the IP-FIX SetID.
IP-FIX collector internal client structure to store SetID to client node ID.
#define hash_unset(h, key)
Definition: hash.h:261
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
ipfix_collector_main_t ipfix_collector_main
u32 client_next_node
ipfix-collector next index where packets have to be redirected.
uword * client_reg_table
Hash table to map IP-FIX setid to a client registration pool.
#define NULL
Definition: clib.h:58
u16 set_id
Setid of IPFix for which client is intereseted in getting packets.
int i
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
vlib_main_t * vlib_main
Pointer to VLib main for the node - ipfix-collector.
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u8 * client_name
String containing name of the client interested in getting ip-fix packets.
u32 client_node
Node index where packets have to be redirected.
vlib_node_registration_t ipfix_collector_node
(constructor) VLIB_REGISTER_NODE (ipfix_collector_node)
Definition: node.c:276
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:375
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static clib_error_t * ipfix_collector_init(vlib_main_t *vm)
#define hash_create(elts, value_bytes)
Definition: hash.h:696
u8 * client_name
String containing name of the client interested in getting ip-fix packets.
u64 uword
Definition: types.h:112
int ipfix_collector_reg_setid(vlib_main_t *vm, ipfix_client_add_del_t *info)
IP-FIX SetID registration function.
IP-FIX collector main structure to SetID to client node ID mapping.
#define IPFIX_COLLECTOR_ERR_REG_EXISTS
Structure other nodes to use for registering with IP-FIX collector.
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:484
#define IPFIX_COLLECTOR_ERR_INVALID_PARAM
u32 client_node
Node index where packets have to be redirected.