lishuai
Committed by Gerrit Code Review

[ONOS-3172] Add arp_spa or arp_tpa Criteria to onos

Change-Id: I3eef59b71ba062ecb475f16decc7a6a0cd59032f
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 +import org.onlab.packet.Ip4Address;
23 +
24 +/**
25 + * Implementation of arp spa or tpa address criterion.
26 + */
27 +public final class ArpPaCriterion implements Criterion {
28 + private final Ip4Address ip;
29 + private final Type type;
30 +
31 + /**
32 + * Constructor.
33 + *
34 + * @param ip the Ip4 Address to match.
35 + * @param type the match type. Should be one of the following:
36 + * Type.ARP_SPA, Type.ARP_TPA
37 + */
38 + ArpPaCriterion(Ip4Address ip, Type type) {
39 + this.ip = ip;
40 + this.type = type;
41 + }
42 +
43 + @Override
44 + public Type type() {
45 + return this.type;
46 + }
47 +
48 + /**
49 + * Gets the Ip4 Address to match.
50 + *
51 + * @return the Ip4 Address to match
52 + */
53 + public Ip4Address ip() {
54 + return this.ip;
55 + }
56 +
57 + @Override
58 + public String toString() {
59 + return toStringHelper(type().toString())
60 + .add("ip", ip).toString();
61 + }
62 +
63 + @Override
64 + public int hashCode() {
65 + return Objects.hash(type().ordinal(), ip);
66 + }
67 +
68 + @Override
69 + public boolean equals(Object obj) {
70 + if (this == obj) {
71 + return true;
72 + }
73 + if (obj instanceof ArpPaCriterion) {
74 + ArpPaCriterion that = (ArpPaCriterion) obj;
75 + return Objects.equals(ip, that.ip) &&
76 + Objects.equals(type, that.type);
77 + }
78 + return false;
79 + }
80 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.flow.criteria; 16 package org.onosproject.net.flow.criteria;
17 17
18 import org.onlab.packet.EthType; 18 import org.onlab.packet.EthType;
19 +import org.onlab.packet.Ip4Address;
19 import org.onlab.packet.Ip6Address; 20 import org.onlab.packet.Ip6Address;
20 import org.onlab.packet.IpPrefix; 21 import org.onlab.packet.IpPrefix;
21 import org.onlab.packet.MacAddress; 22 import org.onlab.packet.MacAddress;
...@@ -25,11 +26,11 @@ import org.onlab.packet.VlanId; ...@@ -25,11 +26,11 @@ import org.onlab.packet.VlanId;
25 import org.onosproject.net.IndexedLambda; 26 import org.onosproject.net.IndexedLambda;
26 import org.onosproject.net.Lambda; 27 import org.onosproject.net.Lambda;
27 import org.onosproject.net.OchSignal; 28 import org.onosproject.net.OchSignal;
29 +import org.onosproject.net.OchSignalType;
28 import org.onosproject.net.OduSignalId; 30 import org.onosproject.net.OduSignalId;
29 import org.onosproject.net.OduSignalType; 31 import org.onosproject.net.OduSignalType;
30 import org.onosproject.net.PortNumber; 32 import org.onosproject.net.PortNumber;
31 import org.onosproject.net.flow.criteria.Criterion.Type; 33 import org.onosproject.net.flow.criteria.Criterion.Type;
32 -import org.onosproject.net.OchSignalType;
33 34
34 /** 35 /**
35 * Factory class to create various traffic selection criteria. 36 * Factory class to create various traffic selection criteria.
...@@ -508,6 +509,16 @@ public final class Criteria { ...@@ -508,6 +509,16 @@ public final class Criteria {
508 return new OduSignalTypeCriterion(signalType); 509 return new OduSignalTypeCriterion(signalType);
509 } 510 }
510 511
512 + /**
513 + * Creates a match on IPv4 source field using the specified value.
514 + *
515 + * @param ip ipv4 source value
516 + * @return match criterion
517 + */
518 + public static Criterion matchArpTpa(Ip4Address ip) {
519 + return new ArpPaCriterion(ip, Type.ARP_TPA);
520 + }
521 +
511 public static Criterion dummy() { 522 public static Criterion dummy() {
512 return new DummyCriterion(); 523 return new DummyCriterion();
513 } 524 }
......