blob: 57ade4ea92750a69784b148b2d2fed7e05f2f9de [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;
23import org.onlab.packet.Ip4Prefix;
24
25import java.util.Set;
26
27/**
28 * Definition of a network interface card (NIC) flow rule.
29 */
30public interface NicFlowRule extends FlowRule {
31
32 /**
33 * Returns parent FlowRule object associated with this NIC rule.
34 *
35 * @return FlowRule object
36 */
37 FlowRule flowRule();
38
39 /**
40 * Returns the traffic class ID associated with this NIC rule.
41 * This ID is related to the software module that processes the
42 * traffic matched by this rule.
43 *
44 * @return traffic class ID
45 */
46 String trafficClassId();
47
48 /**
49 * Returns the NIC's interface name to accommodate this rule.
50 *
51 * @return NIC's interface name
52 */
53 String interfaceName();
54
55 /**
56 * Returns the NIC's interface number to accommodate this rule.
57 *
58 * @return NIC's interface number
59 */
60 long interfaceNumber();
61
62 /**
63 * Returns the CPU core index that handles the traffic matched
64 * by this NIC rule.
65 *
66 * @return CPU core index
67 */
68 long cpuCoreIndex();
69
70 /**
71 * Returns the scope of this rule.
72 *
73 * @return rule scope
74 */
75 NicRuleScope scope();
76
77 /**
78 * Returns the Ethernet type field of this rule
79 * or NULL if no Ethernet type exists in the traffic selector.
80 *
81 * @return Ethernet type field
82 */
83 EthType ethernetType();
84
85 /**
86 * Returns the Ethernet type value field of this rule
87 * or negative if no Ethernet type value exists in the traffic selector.
88 *
89 * @return Ethernet type value field
90 */
91 short ethernetTypeValue();
92
93 /**
94 * Returns the source MAC address field of this rule
95 * or NULL if no source MAC address exists in the traffic selector.
96 *
97 * @return source MAC address field
98 */
99 MacAddress ethernetSrcAddress();
100
101 /**
102 * Returns the destination MAC address field of this rule
103 * or NULL if no destination MAC address exists in the traffic selector.
104 *
105 * @return destination MAC address field
106 */
107 MacAddress ethernetDstAddress();
108
109 /**
110 * Returns whether Ethernet fields are present in this rule.
111 *
112 * @return boolean Ethernet fields' presence
113 */
114 boolean hasEthernet();
115
116 /**
117 * Returns the IP protocol field of this rule
118 * or negative if no IP protocol field exists in the traffic selector.
119 *
120 * @return IP protocol field
121 */
122 short ipv4Protocol();
123
124 /**
125 * Returns the source IP address field of this rule
126 * or null if no source IP address field exists in the traffic selector.
127 *
128 * @return source IP address field
129 */
130 Ip4Prefix ipv4SrcAddress();
131
132 /**
133 * Returns the source IP mask field of this rule
134 * or null if no source IP mask exists in the traffic selector.
135 *
136 * @return source IP mask field
137 */
138 Ip4Prefix ipv4SrcMask();
139
140 /**
141 * Returns the destination IP address field of this rule
142 * or null if no destination IP address field exists in the traffic selector.
143 *
144 * @return destination IP address field
145 */
146 Ip4Prefix ipv4DstAddress();
147
148 /**
149 * Returns the destination IP mask field of this rule
150 * or null if no destination IP mask exists in the traffic selector.
151 *
152 * @return destination IP mask field
153 */
154 Ip4Prefix ipv4DstMask();
155
156 /**
157 * Returns whether IPv4 fields are present in this rule.
158 *
159 * @return boolean IPv4 fields' presence
160 */
161 boolean hasIpv4();
162
163 /**
164 * Returns whether IPv6 fields are present in this rule.
165 *
166 * @return boolean IPv6 fields' presence
167 */
168 boolean hasIpv6();
169
170 /**
171 * Returns the source port field of this rule
172 * or negative if no source port field exists in the traffic selector.
173 *
174 * @return source port field
175 */
176 int sourcePort();
177
178 /**
179 * Returns the destination port field of this rule
180 * or negative if no destination port field exists in the traffic selector.
181 *
182 * @return destination port field
183 */
184 int destinationPort();
185
186 /**
187 * Returns whether UDP header fields are present in this rule.
188 *
189 * @return boolean UDP header fields' presence
190 */
191 boolean hasUdp();
192
193 /**
194 * Returns whether TCP header fields are present in this rule.
195 *
196 * @return boolean TCP header fields' presence
197 */
198 boolean hasTcp();
199
200 /**
201 * Returns whether transport header fields are present in this rule.
202 *
203 * @return boolean transport header fields' presence
204 */
205 boolean hasTransport();
206
207 /**
208 * Returns the set of actions of this rule.
209 *
210 * @return rule's set of actions
211 */
212 Set<NicRuleAction> actions();
213
214 /**
215 * Adds a new action to the set of actions of this rule.
216 *
217 * @param action rule action
218 */
219 void addAction(NicRuleAction action);
220
221 /**
222 * Returns the queue number of this rule's action (if any).
223 *
224 * @return rule action's queue number
225 */
226 long queueNumber();
227
228 /**
229 * Creates rule using NIC-specific rule format.
230 *
231 * @return rule creation command as a string
232 */
233 abstract String createRule();
234
235 /**
236 * Removes rule using NIC-specific rule format.
237 *
238 * @return rule removal command as a string
239 */
240 abstract String removeRule();
241
242 /**
243 * Forms a NIC rule body.
244 *
245 * @return rule body as a string
246 */
247 abstract String ruleBody();
248
249 /**
250 * A builder for NIC rules.
251 */
252 interface Builder {
253
254 /**
255 * Creates a NIC rule out of an ONOS FlowRule.
256 *
257 * @param flowRule an ONOS FlowRule object
258 * @return this
259 */
260 Builder fromFlowRule(FlowRule flowRule);
261
262 /**
263 * Creates a NIC rule with a given traffic class ID.
264 *
265 * @param trafficClassId a traffic class ID
266 * @return this
267 */
268 Builder withTrafficClassId(String trafficClassId);
269
270 /**
271 * Sets the interface name for this NIC rule.
272 *
273 * @param interfaceName an interface's name
274 * @return this
275 */
276 Builder withInterfaceName(String interfaceName);
277
278 /**
279 * Sets the interface number for this NIC rule.
280 *
281 * @param interfaceNumber an interface's number
282 * @return this
283 */
284 Builder withInterfaceNumber(long interfaceNumber);
285
286 /**
287 * Sets the CPU core index to accommodate the traffic
288 * matched by this NIC rule.
289 *
290 * @param cpuCoreIndex a CPU core index
291 * @return this
292 */
293 Builder assignedToCpuCore(long cpuCoreIndex);
294
295 /**
296 * Sets the scope for this NIC rule.
297 *
298 * @param scope an NIC rule scope
299 * @return this
300 */
301 Builder withScope(NicRuleScope scope);
302
303 /**
304 * Builds a NIC rule object.
305 *
306 * @return a NIC rule.
307 */
308 abstract NicFlowRule build();
309
310 }
311
312}