blob: f7a216793d8d753837e561c7480e12d0211bbae4 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08002
Brian O'Connor6dc44e92014-02-24 21:23:46 -08003import java.util.Arrays;
4
Brian O'Connor7f8e3012014-02-15 23:59:29 -08005import net.floodlightcontroller.util.MACAddress;
Jonathan Hart472062d2014-04-03 10:56:48 -07006//import net.onrc.onos.core.topology.Port;
7//import net.onrc.onos.core.topology.Switch;
Jonathan Hart23701d12014-04-03 10:45:48 -07008import net.onrc.onos.core.util.FlowEntryMatch;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08009
10/**
Brian O'Connor7f8e3012014-02-15 23:59:29 -080011 * @author Brian O'Connor <bocon@onlab.us>
Brian O'Connor7f8e3012014-02-15 23:59:29 -080012 */
13
14public class Match {
Ray Milkey269ffb92014-04-03 14:43:30 -070015 protected long sw;
16 protected MACAddress srcMac;
17 protected MACAddress dstMac;
18 protected long srcPort;
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080019
Ray Milkey269ffb92014-04-03 14:43:30 -070020 public Match(long sw, long srcPort,
21 MACAddress srcMac, MACAddress dstMac) {
22 this.sw = sw;
23 this.srcPort = srcPort;
24 this.srcMac = srcMac;
25 this.dstMac = dstMac;
26 }
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080027
Ray Milkey269ffb92014-04-03 14:43:30 -070028 @Override
29 public boolean equals(Object obj) {
30 if (obj instanceof Match) {
31 Match other = (Match) obj;
32 return this.sw == other.sw &&
33 this.srcMac.equals(other.srcMac) &&
34 this.dstMac.equals(other.dstMac) &&
35 this.srcPort == other.srcPort;
36 } else {
37 return false;
38 }
39 }
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080040
Ray Milkey269ffb92014-04-03 14:43:30 -070041 public FlowEntryMatch getFlowEntryMatch() {
42 FlowEntryMatch match = new FlowEntryMatch();
43 match.enableSrcMac(srcMac);
44 match.enableDstMac(dstMac);
45 match.enableInPort(new net.onrc.onos.core.util.Port((short) srcPort));
46 return match;
47 }
48
49 @Override
50 public String toString() {
51 return "Sw:" + sw + " (" + srcPort + "," + srcMac + "," + dstMac + ")";
52 }
53
54 @Override
55 public int hashCode() {
56 long[] nums = new long[4];
57 nums[0] = sw;
58 nums[1] = srcPort;
59 nums[2] = srcMac.toLong();
60 nums[3] = dstMac.toLong();
61 return Arrays.hashCode(nums);
62 }
Brian O'Connor7f8e3012014-02-15 23:59:29 -080063}