Committed by
Gerrit Code Review
[ONOS-3273] Add arp_sha or arp_tha Criteria to onos
new file: core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java modified: core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java Change-Id: I4a7aa2e0de720aab7f49363a1f28ca93bf36d067
Showing
2 changed files
with
93 additions
and
0 deletions
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 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | + | ||
23 | +import org.onlab.packet.MacAddress; | ||
24 | + | ||
25 | +/** | ||
26 | + * Implementation of arp_eth_src address or arp_eth_dst address criterion. | ||
27 | + */ | ||
28 | +public final class ArpHaCriterion implements Criterion { | ||
29 | + private final MacAddress mac; | ||
30 | + private final Type type; | ||
31 | + | ||
32 | + /** | ||
33 | + * Constructor. | ||
34 | + * | ||
35 | + * @param mac the MAC Address to match. | ||
36 | + * @param type the match type. Should be one of the following: | ||
37 | + * Type.ARP_SHA, Type.ARP_THA | ||
38 | + */ | ||
39 | + ArpHaCriterion(MacAddress mac, Type type) { | ||
40 | + checkNotNull(mac, "mac cannot be null"); | ||
41 | + checkNotNull(type, "type cannot be null"); | ||
42 | + this.mac = mac; | ||
43 | + this.type = type; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public Type type() { | ||
48 | + return this.type; | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Gets the MAC Address to match. | ||
53 | + * | ||
54 | + * @return the MAC Address to match | ||
55 | + */ | ||
56 | + public MacAddress mac() { | ||
57 | + return this.mac; | ||
58 | + } | ||
59 | + | ||
60 | + @Override | ||
61 | + public String toString() { | ||
62 | + return toStringHelper(type().toString()) | ||
63 | + .add("mac", mac).toString(); | ||
64 | + } | ||
65 | + | ||
66 | + @Override | ||
67 | + public int hashCode() { | ||
68 | + return Objects.hash(type().ordinal(), mac); | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public boolean equals(Object obj) { | ||
73 | + if (this == obj) { | ||
74 | + return true; | ||
75 | + } | ||
76 | + if (obj instanceof ArpHaCriterion) { | ||
77 | + ArpHaCriterion that = (ArpHaCriterion) obj; | ||
78 | + return Objects.equals(mac, that.mac) && | ||
79 | + Objects.equals(type, that.type); | ||
80 | + } | ||
81 | + return false; | ||
82 | + } | ||
83 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -519,6 +519,16 @@ public final class Criteria { | ... | @@ -519,6 +519,16 @@ public final class Criteria { |
519 | return new ArpPaCriterion(ip, Type.ARP_TPA); | 519 | return new ArpPaCriterion(ip, Type.ARP_TPA); |
520 | } | 520 | } |
521 | 521 | ||
522 | + /** | ||
523 | + * Creates a match on MAC source field using the specified value. | ||
524 | + * | ||
525 | + * @param mac MAC source value | ||
526 | + * @return match criterion | ||
527 | + */ | ||
528 | + public static Criterion matchArpTha(MacAddress mac) { | ||
529 | + return new ArpHaCriterion(mac, Type.ARP_THA); | ||
530 | + } | ||
531 | + | ||
522 | public static Criterion dummy() { | 532 | public static Criterion dummy() { |
523 | return new DummyCriterion(); | 533 | return new DummyCriterion(); |
524 | } | 534 | } | ... | ... |
-
Please register or login to post a comment