blob: 0533b450122a47bae65707bbf5e91c1abb37f986 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 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 */
Juraj Sloboda819ec6f2016-08-07 23:40:03 -070015#ifndef __included_flow_report_classify_h__
16#define __included_flow_report_classify_h__
Ed Warnickecb9cada2015-12-08 15:45:58 -070017
Juraj Slobodaffa652a2016-08-07 23:43:42 -070018#define foreach_ipfix_ip4_field \
19_(ip->src_address.as_u32, ((u32[]){0xFFFFFFFF}), sourceIPv4Address, 4) \
20_(ip->dst_address.as_u32, ((u32[]){0xFFFFFFFF}), destinationIPv4Address, 4) \
21_(ip->protocol, ((u8[]){0xFF}), protocolIdentifier, 1)
22
23#define foreach_ipfix_ip6_field \
24_(ip6->src_address.as_u8, \
25 ((u32[]){0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}), \
26 sourceIPv6Address, 16) \
27_(ip6->dst_address.as_u8, \
28 ((u32[]){0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF}), \
29 destinationIPv6Address, 16) \
30_(ip6->protocol, ((u8[]){0xFF}), protocolIdentifier, 1)
31
32#define foreach_ipfix_tcpudp_field \
33_(tcpudp->src_port, ((u16[]){0xFFFF}), sourceTransportPort, 2) \
34_(tcpudp->dst_port, ((u16[]){0xFFFF}), destinationTransportPort, 2)
35
36#define foreach_ipfix_tcp_field \
37_(tcpudp->src_port, ((u16[]){0xFFFF}), tcpSourcePort, 2) \
38_(tcpudp->dst_port, ((u16[]){0xFFFF}), tcpDestinationPort, 2)
39
40#define foreach_ipfix_udp_field \
41_(tcpudp->src_port, ((u16[]){0xFFFF}), udpSourcePort, 2) \
42_(tcpudp->dst_port, ((u16[]){0xFFFF}), udpDestinationPort, 2)
43
44#define foreach_ipfix_transport_protocol_field \
45 switch (transport_protocol) { \
46 case 255: \
47 foreach_ipfix_tcpudp_field; \
48 break; \
49 case 6: \
50 foreach_ipfix_tcp_field; \
51 break; \
52 case 17: \
53 foreach_ipfix_udp_field; \
54 break; \
55 }
56
57#define foreach_ipfix_field \
58 if (ip_version == 4) { \
59 ip = (ip4_header_t *)ip_start; \
60 tcpudp = (tcpudp_header_t *)(ip+1); \
61 foreach_ipfix_ip4_field; \
62 } else { \
63 ip6 = (ip6_header_t *)ip_start; \
64 tcpudp = (tcpudp_header_t *)(ip6+1); \
65 foreach_ipfix_ip6_field; \
66 } \
67 foreach_ipfix_transport_protocol_field
68
Swarup Nayak6bcac062017-11-26 23:11:40 +053069typedef struct
70{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070071 u32 classify_table_index;
72 u8 ip_version;
73 u8 transport_protocol;
74} ipfix_classify_table_t;
75
Swarup Nayak6bcac062017-11-26 23:11:40 +053076typedef struct
77{
Juraj Slobodaffa652a2016-08-07 23:43:42 -070078 u32 domain_id;
79 u16 src_port;
Swarup Nayak6bcac062017-11-26 23:11:40 +053080 ipfix_classify_table_t *tables;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070081} flow_report_classify_main_t;
82
83extern flow_report_classify_main_t flow_report_classify_main;
84
Swarup Nayak6bcac062017-11-26 23:11:40 +053085static_always_inline u8
86ipfix_classify_table_index_valid (u32 index)
Juraj Slobodaffa652a2016-08-07 23:43:42 -070087{
Swarup Nayak6bcac062017-11-26 23:11:40 +053088 flow_report_classify_main_t *fcm = &flow_report_classify_main;
89 return index < vec_len (fcm->tables) &&
90 fcm->tables[index].classify_table_index != ~0;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070091}
92
Swarup Nayak6bcac062017-11-26 23:11:40 +053093static_always_inline ipfix_classify_table_t *
94ipfix_classify_add_table (void)
Juraj Slobodaffa652a2016-08-07 23:43:42 -070095{
Swarup Nayak6bcac062017-11-26 23:11:40 +053096 flow_report_classify_main_t *fcm = &flow_report_classify_main;
Juraj Slobodaffa652a2016-08-07 23:43:42 -070097 u32 i;
Swarup Nayak6bcac062017-11-26 23:11:40 +053098 for (i = 0; i < vec_len (fcm->tables); i++)
99 if (!ipfix_classify_table_index_valid (i))
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700100 return &fcm->tables[i];
Swarup Nayak6bcac062017-11-26 23:11:40 +0530101 u32 index = vec_len (fcm->tables);
102 vec_validate (fcm->tables, index);
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700103 return &fcm->tables[index];
104}
105
Swarup Nayak6bcac062017-11-26 23:11:40 +0530106static_always_inline void
107ipfix_classify_delete_table (u32 index)
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700108{
Swarup Nayak6bcac062017-11-26 23:11:40 +0530109 flow_report_classify_main_t *fcm = &flow_report_classify_main;
110 ASSERT (index < vec_len (fcm->tables));
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700111 ASSERT (fcm->tables[index].classify_table_index != ~0);
112 fcm->tables[index].classify_table_index = ~0;
113}
114
Swarup Nayak6bcac062017-11-26 23:11:40 +0530115u8 *ipfix_classify_template_rewrite (flow_report_main_t * frm,
116 flow_report_t * fr,
117 ip4_address_t * collector_address,
118 ip4_address_t * src_address,
119 u16 collector_port);
Juraj Slobodaffa652a2016-08-07 23:43:42 -0700120
Swarup Nayak6bcac062017-11-26 23:11:40 +0530121vlib_frame_t *ipfix_classify_send_flows (flow_report_main_t * frm,
122 flow_report_t * fr,
123 vlib_frame_t * f,
124 u32 * to_next, u32 node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125
Juraj Sloboda819ec6f2016-08-07 23:40:03 -0700126#endif /* __included_flow_report_classify_h__ */
Swarup Nayak6bcac062017-11-26 23:11:40 +0530127
128/*
129 * fd.io coding-style-patch-verification: ON
130 *
131 * Local Variables:
132 * eval: (c-set-style "gnu")
133 * End:
134 */