blob: 35840387ffd73f11344342310cd6b586f682287a [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.core.matchaction.match;
2
Sho SHIMIZUcdc50132014-07-22 09:21:01 -07003import com.google.common.base.Objects;
Toshio Koidea03915e2014-07-01 18:39:52 -07004import net.floodlightcontroller.util.MACAddress;
5import net.onrc.onos.core.util.IPv4;
6
7/**
8 * A match object (traffic specifier) for packet nodes, flow-paths and intents.
9 * <p>
10 * This class does not have a switch ID and a port number. They are handled by
11 * MatchAction, IFlow or Intent class.
12 */
13public class PacketMatch implements IMatch {
14
15 // Match fields
16 protected MACAddress srcMacAddress;
17 protected MACAddress dstMacAddress;
18 protected IPv4 srcIpAddress;
19 protected IPv4 dstIpAddress;
20
21 /**
22 * Constructor.
23 */
24 public PacketMatch() {
25 this(null, null, null, null);
26 }
27
28 /**
29 * Constructor.
30 *
31 * @param srcMac Source Host MAC Address
32 * @param dstMac Destination Host MAC Address
33 * @param srcIp Source IP Address
34 * @param dstIp Destination IP Address
35 */
36 public PacketMatch(MACAddress srcMac, MACAddress dstMac,
37 IPv4 srcIp, IPv4 dstIp) {
38 this.srcMacAddress = srcMac;
39 this.dstMacAddress = dstMac;
40 this.srcIpAddress = srcIp;
41 this.dstIpAddress = dstIp;
42 }
43
44 /**
45 * Gets the source host MAC address.
46 *
47 * @return The source host MAC address.
48 */
49 public MACAddress getSrcMacAddress() {
50 return srcMacAddress;
51 }
52
53 /**
54 * Gets the destination host MAC address.
55 *
56 * @return The destination host MAC address.
57 */
58 public MACAddress getDstMacAddress() {
59 return dstMacAddress;
60 }
61
62 /**
63 * Gets the source host IP address.
64 *
65 * @return The source host IP address.
66 */
67 public IPv4 getSrcIpAddress() {
68 return srcIpAddress;
69 }
70
71 /**
72 * Gets the destination host IP address.
73 *
74 * @return The destination host IP address.
75 */
76 public IPv4 getDstIpAddress() {
77 return dstIpAddress;
78 }
Sho SHIMIZUcdc50132014-07-22 09:21:01 -070079
80 @Override
81 public int hashCode() {
82 return Objects.hashCode(srcMacAddress, dstMacAddress, srcIpAddress, dstIpAddress);
83 }
84
85 @Override
86 public boolean equals(Object obj) {
87 if (obj == this) {
88 return true;
89 }
90
91 if (!(obj instanceof PacketMatch)) {
92 return false;
93 }
94
95 PacketMatch that = (PacketMatch) obj;
96 return Objects.equal(this.srcMacAddress, that.srcMacAddress)
97 && Objects.equal(this.dstMacAddress, that.dstMacAddress)
98 && Objects.equal(this.srcIpAddress, that.srcIpAddress)
99 && Objects.equal(this.dstIpAddress, that.dstIpAddress);
100 }
101
102 @Override
103 public String toString() {
104 return Objects.toStringHelper(this)
105 .add("srcMacAddress", srcMacAddress)
106 .add("dstMacAddress", dstMacAddress)
107 .add("srcIpAddress", srcIpAddress)
108 .add("dstIpAddress", dstIpAddress)
109 .toString();
110 }
Toshio Koidea03915e2014-07-01 18:39:52 -0700111}