blob: 1215b6fed079e4353424ac0bcf4a61c529e74064 [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 /**
209 * Returns the set of actions of this rule.
210 *
211 * @return rule's set of actions
212 */
213 Set<NicRuleAction> actions();
214
215 /**
216 * Adds a new action to the set of actions of this rule.
217 *
218 * @param action rule action
219 */
220 void addAction(NicRuleAction action);
221
222 /**
223 * Returns the queue number of this rule's action (if any).
224 *
225 * @return rule action's queue number
226 */
227 long queueNumber();
228
229 /**
230 * Creates rule using NIC-specific rule format.
231 *
232 * @return rule creation command as a string
233 */
234 abstract String createRule();
235
236 /**
237 * Removes rule using NIC-specific rule format.
238 *
239 * @return rule removal command as a string
240 */
241 abstract String removeRule();
242
243 /**
244 * Forms a NIC rule body.
245 *
246 * @return rule body as a string
247 */
248 abstract String ruleBody();
249
250 /**
251 * A builder for NIC rules.
252 */
253 interface Builder {
254
255 /**
256 * Creates a NIC rule out of an ONOS FlowRule.
257 *
258 * @param flowRule an ONOS FlowRule object
259 * @return this
260 */
261 Builder fromFlowRule(FlowRule flowRule);
262
263 /**
264 * Creates a NIC rule with a given traffic class ID.
265 *
266 * @param trafficClassId a traffic class ID
267 * @return this
268 */
269 Builder withTrafficClassId(String trafficClassId);
270
271 /**
272 * Sets the interface name for this NIC rule.
273 *
274 * @param interfaceName an interface's name
275 * @return this
276 */
277 Builder withInterfaceName(String interfaceName);
278
279 /**
280 * Sets the interface number for this NIC rule.
281 *
282 * @param interfaceNumber an interface's number
283 * @return this
284 */
285 Builder withInterfaceNumber(long interfaceNumber);
286
287 /**
288 * Sets the CPU core index to accommodate the traffic
289 * matched by this NIC rule.
290 *
291 * @param cpuCoreIndex a CPU core index
292 * @return this
293 */
294 Builder assignedToCpuCore(long cpuCoreIndex);
295
296 /**
297 * Sets the scope for this NIC rule.
298 *
299 * @param scope an NIC rule scope
300 * @return this
301 */
302 Builder withScope(NicRuleScope scope);
303
304 /**
305 * Builds a NIC rule object.
306 *
307 * @return a NIC rule.
308 */
309 abstract NicFlowRule build();
310
311 }
312
313}