blob: 90833958600799d19e84f8e7d798a1d2c4d55ed3 [file] [log] [blame]
Georgios Katsikas70671b32018-07-02 18:47:27 +02001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.drivers.server.devices.nic;
18
19import org.onosproject.net.flow.FlowRule;
20
21import org.onlab.packet.EthType;
22import org.onlab.packet.MacAddress;
Georgios Katsikas3e6d0f02018-07-25 17:04:04 +020023import org.onlab.packet.Ip4Address;
Georgios Katsikas70671b32018-07-02 18:47:27 +020024import org.onlab.packet.Ip4Prefix;
25
26import java.util.Set;
27
28/**
29 * Definition of a network interface card (NIC) flow rule.
30 */
31public interface NicFlowRule extends FlowRule {
32
33 /**
34 * Returns parent FlowRule object associated with this NIC rule.
35 *
36 * @return FlowRule object
37 */
38 FlowRule flowRule();
39
40 /**
41 * Returns the traffic class ID associated with this NIC rule.
42 * This ID is related to the software module that processes the
43 * traffic matched by this rule.
44 *
45 * @return traffic class ID
46 */
47 String trafficClassId();
48
49 /**
50 * Returns the NIC's interface name to accommodate this rule.
51 *
52 * @return NIC's interface name
53 */
54 String interfaceName();
55
56 /**
57 * Returns the NIC's interface number to accommodate this rule.
58 *
59 * @return NIC's interface number
60 */
61 long interfaceNumber();
62
63 /**
64 * Returns the CPU core index that handles the traffic matched
65 * by this NIC rule.
66 *
67 * @return CPU core index
68 */
69 long cpuCoreIndex();
70
71 /**
72 * Returns the scope of this rule.
73 *
74 * @return rule scope
75 */
76 NicRuleScope scope();
77
78 /**
79 * Returns the Ethernet type field of this rule
80 * or NULL if no Ethernet type exists in the traffic selector.
81 *
82 * @return Ethernet type field
83 */
84 EthType ethernetType();
85
86 /**
87 * Returns the Ethernet type value field of this rule
88 * or negative if no Ethernet type value exists in the traffic selector.
89 *
90 * @return Ethernet type value field
91 */
92 short ethernetTypeValue();
93
94 /**
95 * Returns the source MAC address field of this rule
96 * or NULL if no source MAC address exists in the traffic selector.
97 *
98 * @return source MAC address field
99 */
100 MacAddress ethernetSrcAddress();
101
102 /**
103 * Returns the destination MAC address field of this rule
104 * or NULL if no destination MAC address exists in the traffic selector.
105 *
106 * @return destination MAC address field
107 */
108 MacAddress ethernetDstAddress();
109
110 /**
111 * Returns whether Ethernet fields are present in this rule.
112 *
113 * @return boolean Ethernet fields' presence
114 */
115 boolean hasEthernet();
116
117 /**
118 * Returns the IP protocol field of this rule
119 * or negative if no IP protocol field exists in the traffic selector.
120 *
121 * @return IP protocol field
122 */
123 short ipv4Protocol();
124
125 /**
126 * Returns the source IP address field of this rule
127 * or null if no source IP address field exists in the traffic selector.
128 *
129 * @return source IP address field
130 */
Georgios Katsikas3e6d0f02018-07-25 17:04:04 +0200131 Ip4Address ipv4SrcAddress();
Georgios Katsikas70671b32018-07-02 18:47:27 +0200132
133 /**
134 * Returns the source IP mask field of this rule
135 * or null if no source IP mask exists in the traffic selector.
136 *
137 * @return source IP mask field
138 */
139 Ip4Prefix ipv4SrcMask();
140
141 /**
142 * Returns the destination IP address field of this rule
143 * or null if no destination IP address field exists in the traffic selector.
144 *
145 * @return destination IP address field
146 */
Georgios Katsikas3e6d0f02018-07-25 17:04:04 +0200147 Ip4Address ipv4DstAddress();
Georgios Katsikas70671b32018-07-02 18:47:27 +0200148
149 /**
150 * Returns the destination IP mask field of this rule
151 * or null if no destination IP mask exists in the traffic selector.
152 *
153 * @return destination IP mask field
154 */
155 Ip4Prefix ipv4DstMask();
156
157 /**
158 * Returns whether IPv4 fields are present in this rule.
159 *
160 * @return boolean IPv4 fields' presence
161 */
162 boolean hasIpv4();
163
164 /**
165 * Returns whether IPv6 fields are present in this rule.
166 *
167 * @return boolean IPv6 fields' presence
168 */
169 boolean hasIpv6();
170
171 /**
172 * Returns the source port field of this rule
173 * or negative if no source port field exists in the traffic selector.
174 *
175 * @return source port field
176 */
177 int sourcePort();
178
179 /**
180 * Returns the destination port field of this rule
181 * or negative if no destination port field exists in the traffic selector.
182 *
183 * @return destination port field
184 */
185 int destinationPort();
186
187 /**
188 * Returns whether UDP header fields are present in this rule.
189 *
190 * @return boolean UDP header fields' presence
191 */
192 boolean hasUdp();
193
194 /**
195 * Returns whether TCP header fields are present in this rule.
196 *
197 * @return boolean TCP header fields' presence
198 */
199 boolean hasTcp();
200
201 /**
202 * Returns whether transport header fields are present in this rule.
203 *
204 * @return boolean transport header fields' presence
205 */
206 boolean hasTransport();
207
208 /**
Georgios Katsikas6dc11c12018-12-20 08:43:29 +0100209 * Returns whether this rule is a full wildcard or not.
210 *
211 * @return boolean full wildcard status
212 */
213 boolean isFullWildcard();
214
215 /**
Georgios Katsikas70671b32018-07-02 18:47:27 +0200216 * Returns the set of actions of this rule.
217 *
218 * @return rule's set of actions
219 */
220 Set<NicRuleAction> actions();
221
222 /**
223 * Adds a new action to the set of actions of this rule.
224 *
225 * @param action rule action
226 */
227 void addAction(NicRuleAction action);
228
229 /**
230 * Returns the queue number of this rule's action (if any).
231 *
232 * @return rule action's queue number
233 */
234 long queueNumber();
235
236 /**
237 * Creates rule using NIC-specific rule format.
238 *
239 * @return rule creation command as a string
240 */
241 abstract String createRule();
242
243 /**
244 * Removes rule using NIC-specific rule format.
245 *
246 * @return rule removal command as a string
247 */
248 abstract String removeRule();
249
250 /**
251 * Forms a NIC rule body.
252 *
253 * @return rule body as a string
254 */
255 abstract String ruleBody();
256
257 /**
258 * A builder for NIC rules.
259 */
260 interface Builder {
261
262 /**
263 * Creates a NIC rule out of an ONOS FlowRule.
264 *
265 * @param flowRule an ONOS FlowRule object
266 * @return this
267 */
268 Builder fromFlowRule(FlowRule flowRule);
269
270 /**
271 * Creates a NIC rule with a given traffic class ID.
272 *
273 * @param trafficClassId a traffic class ID
274 * @return this
275 */
276 Builder withTrafficClassId(String trafficClassId);
277
278 /**
279 * Sets the interface name for this NIC rule.
280 *
281 * @param interfaceName an interface's name
282 * @return this
283 */
284 Builder withInterfaceName(String interfaceName);
285
286 /**
287 * Sets the interface number for this NIC rule.
288 *
289 * @param interfaceNumber an interface's number
290 * @return this
291 */
292 Builder withInterfaceNumber(long interfaceNumber);
293
294 /**
295 * Sets the CPU core index to accommodate the traffic
296 * matched by this NIC rule.
297 *
298 * @param cpuCoreIndex a CPU core index
299 * @return this
300 */
301 Builder assignedToCpuCore(long cpuCoreIndex);
302
303 /**
304 * Sets the scope for this NIC rule.
305 *
306 * @param scope an NIC rule scope
307 * @return this
308 */
309 Builder withScope(NicRuleScope scope);
310
311 /**
312 * Builds a NIC rule object.
313 *
314 * @return a NIC rule.
315 */
316 abstract NicFlowRule build();
317
318 }
319
320}