DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FlowControl.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2017 Mellanox Technologies, Ltd
3 */
4
6
7#include "logging/Logging.hpp"
8
9#include <rte_byteorder.h>
10#include <rte_ether.h>
11#include <rte_flow.h>
12#include <rte_ip.h>
13
14namespace dunedaq {
15namespace dpdklibs {
16
40/* Function responsible for creating the flow rule. 8< */
41struct rte_flow *
42generate_ipv4_flow(uint16_t port_id, uint16_t rx_q,
43 uint32_t src_ip, uint32_t src_mask,
44 uint32_t dest_ip, uint32_t dest_mask,
45 struct rte_flow_error *error)
46{
47 // Declaring structs being used.
48 struct rte_flow_attr attr;
49 struct rte_flow_item pattern[MAX_PATTERN_NUM];
50 struct rte_flow_action action[MAX_ACTION_NUM];
51 struct rte_flow *flow = NULL;
52 struct rte_flow_action_queue queue = { .index = rx_q };
53 struct rte_flow_item_ipv4 ip_spec;
54 struct rte_flow_item_ipv4 ip_mask;
55
56 int res;
57
58 memset(pattern, 0, sizeof(pattern));
59 memset(action, 0, sizeof(action));
60
61 // Set the rule attribute, only ingress packets will be checked.
62 memset(&attr, 0, sizeof(struct rte_flow_attr));
63 attr.ingress = 1;
64
65 /*
66 * create the action sequence.
67 * one action only, move packet to queue
68 */
69 action[0].type = RTE_FLOW_ACTION_TYPE_QUEUE;
70 action[0].conf = &queue;
71 action[1].type = RTE_FLOW_ACTION_TYPE_END;
72
73 /*
74 * set the first level of the pattern (ETH).
75 * since in this example we just want to get the
76 * ipv4 we set this level to allow all.
77 */
78
79 // Set this level to allow all.
80
81 /*
82 * setting the second level of the pattern (IP).
83 * in this example this is the level we care about
84 * so we set it according to the parameters.
85 */
86
87 // Setting the second level of the pattern.
88 memset(&ip_spec, 0, sizeof(struct rte_flow_item_ipv4));
89 memset(&ip_mask, 0, sizeof(struct rte_flow_item_ipv4));
90 ip_spec.hdr.dst_addr = htonl(dest_ip);
91 ip_mask.hdr.dst_addr = 0;
92 ip_spec.hdr.src_addr = htonl(src_ip);
93 ip_mask.hdr.src_addr = src_mask;
94
95 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
96
97 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
98 pattern[1].spec = &ip_spec;
99 pattern[1].mask = &ip_mask;
100
101
102 pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
103
104 // Validate the rule and create it.
105 res = rte_flow_validate(port_id, &attr, pattern, action, error);
106 if (not res) {
107 flow = rte_flow_create(port_id, &attr, pattern, action, error);
108 }
109
110 return flow;
111}
112
113// Droppign all the traffic that did pass a flow with higher priority
114struct rte_flow *
115generate_drop_flow(uint16_t port_id, struct rte_flow_error *error)
116{
117 struct rte_flow_attr attr;
118 struct rte_flow_item pattern[MAX_PATTERN_NUM];
119 struct rte_flow_action action[MAX_ACTION_NUM];
120 struct rte_flow *flow = NULL;
121 int res;
122
123 memset(pattern, 0, sizeof(pattern));
124 memset(action, 0, sizeof(action));
125
126 // Set the rule attribute, only ingress packets will be checked.
127 memset(&attr, 0, sizeof(struct rte_flow_attr));
128 attr.ingress = 1;
129 attr.egress = 0;
130 attr.priority = 1; // TODO the higher the lower?
131
132 /*
133 * create the action sequence.
134 * one action only, Drop the packet
135 */
136 action[0].type = RTE_FLOW_ACTION_TYPE_DROP;
137 action[1].type = RTE_FLOW_ACTION_TYPE_END;
138
139 /*
140 * set the first level of the pattern (ETH).
141 * since in this example we just want to get the
142 * ipv4 we set this level to allow all.
143 */
144
145 // Set this level to allow all.
146 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
147
148 /*
149 * setting the second level of the pattern (IP).
150 * in this example this is the level we care about
151 * so we set it according to the parameters.
152 */
153
154 // The final level must be always type end.
155 pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
156
157 // Validate the rule and create it.
158 res = rte_flow_validate(port_id, &attr, pattern, action, error);
159 if (not res) {
160 flow = rte_flow_create(port_id, &attr, pattern, action, error);
161 }
162
163 return flow;
164}
165
166// ARP packets to specific
167struct rte_flow *
168generate_arp_flow(uint16_t port_id, uint16_t rx_q, struct rte_flow_error *error)
169{
170 struct rte_flow_attr attr;
171 struct rte_flow_item pattern[MAX_PATTERN_NUM];
172 struct rte_flow_action action[MAX_ACTION_NUM];
173 struct rte_flow *flow = NULL;
174 struct rte_flow_action_queue queue = { .index = rx_q };
175 int res;
176
177 memset(pattern, 0, sizeof(pattern));
178 memset(action, 0, sizeof(action));
179
180 // Set the rule attribute, only ingress packets will be checked.
181 memset(&attr, 0, sizeof(struct rte_flow_attr));
182 attr.ingress = 1;
183 attr.egress = 0;
184 attr.priority = 1; // TODO the higher the lower?
185
186 // Action -> queue steering
187 action[0].type = RTE_FLOW_ACTION_TYPE_QUEUE;
188 action[0].conf = &queue;
189 action[1].type = RTE_FLOW_ACTION_TYPE_END;
190
191 // Rule prep
192 struct rte_flow_item_eth item_eth_mask = {};
193 struct rte_flow_item_eth item_eth_spec = {};
194 // Rule marker
195 item_eth_spec.hdr.ether_type = RTE_BE16(RTE_ETHER_TYPE_ARP);
196 item_eth_mask.hdr.ether_type = RTE_BE16(0xFFFF);
197 // Rule pattern
198 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
199 pattern[0].mask = &item_eth_mask;
200 pattern[0].spec = &item_eth_spec;
201 pattern[1].type = RTE_FLOW_ITEM_TYPE_END;
202
203 // Validate the rule and create it.
204 res = rte_flow_validate(port_id, &attr, pattern, action, error);
205 if (not res) {
206 flow = rte_flow_create(port_id, &attr, pattern, action, error);
207 }
208
209 return flow;
210}
211
212} // namespace dpdklibs
213} // namespace dunedaq
static constexpr uint32_t MAX_ACTION_NUM
struct rte_flow * generate_ipv4_flow(uint16_t port_id, uint16_t rx_q, uint32_t src_ip, uint32_t src_mask, uint32_t dest_ip, uint32_t dest_mask, struct rte_flow_error *error)
static constexpr uint32_t MAX_PATTERN_NUM
struct rte_flow * generate_arp_flow(uint16_t port_id, uint16_t rx_q, struct rte_flow_error *error)
struct rte_flow * generate_drop_flow(uint16_t port_id, struct rte_flow_error *error)
Including Qt Headers.
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34