Committed by
Gerrit Code Review
[ONOS-3499] Add the set treatments of ARP_SPA, ARP_SHA and ARP_OP.
Change-Id: I7e1927bcf26e7c25fede43aa864a1b71ae2e8b49
Showing
5 changed files
with
253 additions
and
1 deletions
... | @@ -489,6 +489,21 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { | ... | @@ -489,6 +489,21 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { |
489 | } | 489 | } |
490 | 490 | ||
491 | @Override | 491 | @Override |
492 | + public Builder setArpSpa(IpAddress addr) { | ||
493 | + return add(Instructions.modArpSpa(addr)); | ||
494 | + } | ||
495 | + | ||
496 | + @Override | ||
497 | + public Builder setArpSha(MacAddress addr) { | ||
498 | + return add(Instructions.modArpSha(addr)); | ||
499 | + } | ||
500 | + | ||
501 | + @Override | ||
502 | + public Builder setArpOp(short op) { | ||
503 | + return add(Instructions.modL3ArpOp(op)); | ||
504 | + } | ||
505 | + | ||
506 | + @Override | ||
492 | public TrafficTreatment.Builder extension(ExtensionTreatment extension, | 507 | public TrafficTreatment.Builder extension(ExtensionTreatment extension, |
493 | DeviceId deviceId) { | 508 | DeviceId deviceId) { |
494 | return add(Instructions.extension(extension, deviceId)); | 509 | return add(Instructions.extension(extension, deviceId)); | ... | ... |
... | @@ -424,6 +424,30 @@ public interface TrafficTreatment { | ... | @@ -424,6 +424,30 @@ public interface TrafficTreatment { |
424 | Builder setUdpDst(TpPort port); | 424 | Builder setUdpDst(TpPort port); |
425 | 425 | ||
426 | /** | 426 | /** |
427 | + * Sets the arp src ip address. | ||
428 | + * | ||
429 | + * @param addr an ip | ||
430 | + * @return a treatment builder | ||
431 | + */ | ||
432 | + Builder setArpSpa(IpAddress addr); | ||
433 | + | ||
434 | + /** | ||
435 | + * Sets the arp src mac address. | ||
436 | + * | ||
437 | + * @param addr a macaddress | ||
438 | + * @return a treatment builder | ||
439 | + */ | ||
440 | + Builder setArpSha(MacAddress addr); | ||
441 | + | ||
442 | + /** | ||
443 | + * Sets the arp operation. | ||
444 | + * | ||
445 | + * @param op the value of arp operation. | ||
446 | + * @return a treatment builder. | ||
447 | + */ | ||
448 | + Builder setArpOp(short op); | ||
449 | + | ||
450 | + /** | ||
427 | * Uses an extension treatment. | 451 | * Uses an extension treatment. |
428 | * | 452 | * |
429 | * @param extension extension treatment | 453 | * @param extension extension treatment | ... | ... |
... | @@ -35,6 +35,9 @@ import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSig | ... | @@ -35,6 +35,9 @@ import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSig |
35 | import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction; | 35 | import org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction; |
36 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; | 36 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType; |
37 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | 37 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
38 | +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction; | ||
39 | +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction; | ||
40 | +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction; | ||
38 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; | 41 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
39 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; | 42 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction; |
40 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType; | 43 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType; |
... | @@ -299,6 +302,39 @@ public final class Instructions { | ... | @@ -299,6 +302,39 @@ public final class Instructions { |
299 | } | 302 | } |
300 | 303 | ||
301 | /** | 304 | /** |
305 | + * Creates a L3 ARP IP src modification. | ||
306 | + * | ||
307 | + * @param addr the ip address to modify to | ||
308 | + * @return a L3 modification | ||
309 | + */ | ||
310 | + public static L3ModificationInstruction modArpSpa(IpAddress addr) { | ||
311 | + checkNotNull(addr, "Src l3 ARP IP address cannot be null"); | ||
312 | + return new ModArpIPInstruction(L3SubType.ARP_SPA, addr); | ||
313 | + } | ||
314 | + | ||
315 | + /** | ||
316 | + * Creates a l3 ARP Ether src modification. | ||
317 | + * | ||
318 | + * @param addr the mac address to modify to | ||
319 | + * @return a l3 modification | ||
320 | + */ | ||
321 | + public static L3ModificationInstruction modArpSha(MacAddress addr) { | ||
322 | + checkNotNull(addr, "Src l3 ARP address cannot be null"); | ||
323 | + return new ModArpEthInstruction(L3SubType.ARP_SHA, addr); | ||
324 | + } | ||
325 | + | ||
326 | + /** | ||
327 | + * Creates a l3 ARP operation modification. | ||
328 | + * | ||
329 | + * @param op the ARP operation to modify to | ||
330 | + * @return a l3 modification | ||
331 | + */ | ||
332 | + public static L3ModificationInstruction modL3ArpOp(short op) { | ||
333 | + checkNotNull(op, "Arp operation cannot be null"); | ||
334 | + return new ModArpOpInstruction(L3SubType.ARP_OP, op); | ||
335 | + } | ||
336 | + | ||
337 | + /** | ||
302 | * Creates a push MPLS header instruction. | 338 | * Creates a push MPLS header instruction. |
303 | * | 339 | * |
304 | * @return a L2 modification. | 340 | * @return a L2 modification. | ... | ... |
... | @@ -20,6 +20,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -20,6 +20,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
20 | import java.util.Objects; | 20 | import java.util.Objects; |
21 | 21 | ||
22 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
23 | +import org.onlab.packet.MacAddress; | ||
23 | 24 | ||
24 | /** | 25 | /** |
25 | * Abstraction of a single traffic treatment step. | 26 | * Abstraction of a single traffic treatment step. |
... | @@ -68,7 +69,22 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -68,7 +69,22 @@ public abstract class L3ModificationInstruction implements Instruction { |
68 | /** | 69 | /** |
69 | * Copy TTL in. | 70 | * Copy TTL in. |
70 | */ | 71 | */ |
71 | - TTL_IN | 72 | + TTL_IN, |
73 | + | ||
74 | + /** | ||
75 | + * ARP IP src modification. | ||
76 | + */ | ||
77 | + ARP_SPA, | ||
78 | + | ||
79 | + /** | ||
80 | + * ARP Ether src modification. | ||
81 | + */ | ||
82 | + ARP_SHA, | ||
83 | + | ||
84 | + /** | ||
85 | + * Arp operation modification. | ||
86 | + */ | ||
87 | + ARP_OP | ||
72 | 88 | ||
73 | //TODO: remaining types | 89 | //TODO: remaining types |
74 | } | 90 | } |
... | @@ -133,6 +149,150 @@ public abstract class L3ModificationInstruction implements Instruction { | ... | @@ -133,6 +149,150 @@ public abstract class L3ModificationInstruction implements Instruction { |
133 | } | 149 | } |
134 | 150 | ||
135 | /** | 151 | /** |
152 | + * Represents a L3 ARP IP src/dst modification instruction. | ||
153 | + */ | ||
154 | + public static final class ModArpIPInstruction extends L3ModificationInstruction { | ||
155 | + | ||
156 | + private final L3SubType subtype; | ||
157 | + private final IpAddress ip; | ||
158 | + | ||
159 | + ModArpIPInstruction(L3SubType subType, IpAddress addr) { | ||
160 | + | ||
161 | + this.subtype = subType; | ||
162 | + this.ip = addr; | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public L3SubType subtype() { | ||
167 | + return this.subtype; | ||
168 | + } | ||
169 | + | ||
170 | + public IpAddress ip() { | ||
171 | + return this.ip; | ||
172 | + } | ||
173 | + | ||
174 | + @Override | ||
175 | + public String toString() { | ||
176 | + return toStringHelper(subtype().toString()) | ||
177 | + .add("ip", ip).toString(); | ||
178 | + } | ||
179 | + | ||
180 | + @Override | ||
181 | + public int hashCode() { | ||
182 | + return Objects.hash(type(), subtype(), ip); | ||
183 | + } | ||
184 | + | ||
185 | + @Override | ||
186 | + public boolean equals(Object obj) { | ||
187 | + if (this == obj) { | ||
188 | + return true; | ||
189 | + } | ||
190 | + if (obj instanceof ModArpIPInstruction) { | ||
191 | + ModArpIPInstruction that = (ModArpIPInstruction) obj; | ||
192 | + return Objects.equals(ip, that.ip) && | ||
193 | + Objects.equals(this.subtype(), that.subtype()); | ||
194 | + } | ||
195 | + return false; | ||
196 | + } | ||
197 | + } | ||
198 | + | ||
199 | + /** | ||
200 | + * Represents a L3 ARP Ether src/dst modification instruction. | ||
201 | + */ | ||
202 | + public static final class ModArpEthInstruction extends L3ModificationInstruction { | ||
203 | + | ||
204 | + private final L3SubType subtype; | ||
205 | + private final MacAddress mac; | ||
206 | + | ||
207 | + ModArpEthInstruction(L3SubType subType, MacAddress addr) { | ||
208 | + | ||
209 | + this.subtype = subType; | ||
210 | + this.mac = addr; | ||
211 | + } | ||
212 | + | ||
213 | + @Override | ||
214 | + public L3SubType subtype() { | ||
215 | + return this.subtype; | ||
216 | + } | ||
217 | + | ||
218 | + public MacAddress mac() { | ||
219 | + return this.mac; | ||
220 | + } | ||
221 | + | ||
222 | + @Override | ||
223 | + public String toString() { | ||
224 | + return toStringHelper(subtype().toString()) | ||
225 | + .add("mac", mac).toString(); | ||
226 | + } | ||
227 | + | ||
228 | + @Override | ||
229 | + public int hashCode() { | ||
230 | + return Objects.hash(type(), subtype(), mac); | ||
231 | + } | ||
232 | + | ||
233 | + @Override | ||
234 | + public boolean equals(Object obj) { | ||
235 | + if (this == obj) { | ||
236 | + return true; | ||
237 | + } | ||
238 | + if (obj instanceof ModArpEthInstruction) { | ||
239 | + ModArpEthInstruction that = (ModArpEthInstruction) obj; | ||
240 | + return Objects.equals(mac, that.mac) && | ||
241 | + Objects.equals(this.subtype(), that.subtype()); | ||
242 | + } | ||
243 | + return false; | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * Represents a L3 ARP operation modification instruction. | ||
249 | + */ | ||
250 | + public static final class ModArpOpInstruction extends L3ModificationInstruction { | ||
251 | + | ||
252 | + private final L3SubType subtype; | ||
253 | + private final short op; | ||
254 | + | ||
255 | + ModArpOpInstruction(L3SubType subType, short op) { | ||
256 | + | ||
257 | + this.subtype = subType; | ||
258 | + this.op = op; | ||
259 | + } | ||
260 | + | ||
261 | + @Override | ||
262 | + public L3SubType subtype() { | ||
263 | + return this.subtype; | ||
264 | + } | ||
265 | + | ||
266 | + public long op() { | ||
267 | + return this.op; | ||
268 | + } | ||
269 | + | ||
270 | + @Override | ||
271 | + public String toString() { | ||
272 | + return toStringHelper(subtype().toString()) | ||
273 | + .add("op", op).toString(); | ||
274 | + } | ||
275 | + | ||
276 | + @Override | ||
277 | + public int hashCode() { | ||
278 | + return Objects.hash(type(), subtype(), op); | ||
279 | + } | ||
280 | + | ||
281 | + @Override | ||
282 | + public boolean equals(Object obj) { | ||
283 | + if (this == obj) { | ||
284 | + return true; | ||
285 | + } | ||
286 | + if (obj instanceof ModArpOpInstruction) { | ||
287 | + ModArpOpInstruction that = (ModArpOpInstruction) obj; | ||
288 | + return Objects.equals(op, that.op) && | ||
289 | + Objects.equals(this.subtype(), that.subtype()); | ||
290 | + } | ||
291 | + return false; | ||
292 | + } | ||
293 | + } | ||
294 | + | ||
295 | + /** | ||
136 | * Represents a L3 IPv6 Flow Label (RFC 6437) modification instruction | 296 | * Represents a L3 IPv6 Flow Label (RFC 6437) modification instruction |
137 | * (20 bits unsigned integer). | 297 | * (20 bits unsigned integer). |
138 | */ | 298 | */ | ... | ... |
providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
... | @@ -45,6 +45,9 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPc | ... | @@ -45,6 +45,9 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPc |
45 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions; | 45 | import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions; |
46 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; | 46 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
47 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | 47 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; |
48 | +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction; | ||
49 | +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction; | ||
50 | +import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction; | ||
48 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; | 51 | import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction; |
49 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; | 52 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; |
50 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction; | 53 | import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction; |
... | @@ -61,6 +64,7 @@ import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue; | ... | @@ -61,6 +64,7 @@ import org.projectfloodlight.openflow.protocol.action.OFActionSetQueue; |
61 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; | 64 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
62 | import org.projectfloodlight.openflow.protocol.match.Match; | 65 | import org.projectfloodlight.openflow.protocol.match.Match; |
63 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; | 66 | import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
67 | +import org.projectfloodlight.openflow.types.ArpOpcode; | ||
64 | import org.projectfloodlight.openflow.types.CircuitSignalID; | 68 | import org.projectfloodlight.openflow.types.CircuitSignalID; |
65 | import org.projectfloodlight.openflow.types.EthType; | 69 | import org.projectfloodlight.openflow.types.EthType; |
66 | import org.projectfloodlight.openflow.types.IPv4Address; | 70 | import org.projectfloodlight.openflow.types.IPv4Address; |
... | @@ -430,6 +434,19 @@ public class FlowModBuilderVer13 extends FlowModBuilder { | ... | @@ -430,6 +434,19 @@ public class FlowModBuilderVer13 extends FlowModBuilder { |
430 | int flowLabel = flowLabelInstruction.flowLabel(); | 434 | int flowLabel = flowLabelInstruction.flowLabel(); |
431 | oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel)); | 435 | oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel)); |
432 | break; | 436 | break; |
437 | + case ARP_SPA: | ||
438 | + ModArpIPInstruction aip = (ModArpIPInstruction) i; | ||
439 | + ip4 = aip.ip().getIp4Address(); | ||
440 | + oxm = factory().oxms().arpSpa(IPv4Address.of(ip4.toInt())); | ||
441 | + break; | ||
442 | + case ARP_SHA: | ||
443 | + ModArpEthInstruction ei = (ModArpEthInstruction) i; | ||
444 | + oxm = factory().oxms().arpSha(MacAddress.of(ei.mac().toLong())); | ||
445 | + break; | ||
446 | + case ARP_OP: | ||
447 | + ModArpOpInstruction oi = (ModArpOpInstruction) i; | ||
448 | + oxm = factory().oxms().arpOp(ArpOpcode.of((int) oi.op())); | ||
449 | + break; | ||
433 | case DEC_TTL: | 450 | case DEC_TTL: |
434 | return factory().actions().decNwTtl(); | 451 | return factory().actions().decNwTtl(); |
435 | case TTL_IN: | 452 | case TTL_IN: | ... | ... |
-
Please register or login to post a comment