BitOhenry
Committed by Gerrit Code Review

[ONOS-3469] Add arp_op Criteria to onos

Change-Id: I4b6c84d3a4145e698f2845d492db54d0b2e2738b
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
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 +package org.onosproject.net.flow.criteria;
17 +
18 +import static com.google.common.base.MoreObjects.toStringHelper;
19 +
20 +import java.util.Objects;
21 +
22 +/**
23 + * Implementation of arp operation type criterion.
24 + */
25 +public final class ArpOpCriterion implements Criterion {
26 + private final int arpOp;
27 + private final Type type;
28 +
29 + /**
30 + * Constructor.
31 + *
32 + * @param arpOp the arp operation type to match.
33 + * @param type the match type. Should be the following:
34 + * Type.ARP_OP
35 + */
36 + ArpOpCriterion(int arpOp, Type type) {
37 + this.arpOp = arpOp;
38 + this.type = type;
39 + }
40 +
41 + @Override
42 + public Type type() {
43 + return this.type;
44 + }
45 +
46 + /**
47 + * Gets the arp operation type to match.
48 + *
49 + * @return the arp operation type to match
50 + */
51 + public int arpOp() {
52 + return this.arpOp;
53 + }
54 +
55 + @Override
56 + public String toString() {
57 + return toStringHelper(type().toString())
58 + .add("arpOp", arpOp).toString();
59 + }
60 +
61 + @Override
62 + public int hashCode() {
63 + return Objects.hash(type().ordinal(), arpOp);
64 + }
65 +
66 + @Override
67 + public boolean equals(Object obj) {
68 + if (this == obj) {
69 + return true;
70 + }
71 + if (obj instanceof ArpOpCriterion) {
72 + ArpOpCriterion that = (ArpOpCriterion) obj;
73 + return Objects.equals(arpOp, that.arpOp) &&
74 + Objects.equals(type, that.type);
75 + }
76 + return false;
77 + }
78 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -549,6 +549,16 @@ public final class Criteria { ...@@ -549,6 +549,16 @@ public final class Criteria {
549 return new ArpHaCriterion(mac, Type.ARP_SHA); 549 return new ArpHaCriterion(mac, Type.ARP_SHA);
550 } 550 }
551 551
552 + /**
553 + * Creates a match on arp operation type field using the specified value.
554 + *
555 + * @param arpOp arp operation type value
556 + * @return match criterion
557 + */
558 + public static Criterion matchArpOp(int arpOp) {
559 + return new ArpOpCriterion(arpOp, Type.ARP_OP);
560 + }
561 +
552 public static Criterion dummy() { 562 public static Criterion dummy() {
553 return new DummyCriterion(); 563 return new DummyCriterion();
554 } 564 }
......