blob: 886fb64773ac023187c1e8a241baa2e796f9d9f0 [file] [log] [blame]
Brian O'Connor7f8e3012014-02-15 23:59:29 -08001package net.onrc.onos.intent;
2
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;
Brian O'Connor488e5ed2014-02-20 19:50:01 -08006//import net.onrc.onos.ofcontroller.networkgraph.Port;
7//import net.onrc.onos.ofcontroller.networkgraph.Switch;
Brian O'Connor67c6e662014-02-17 15:20:44 -08008import net.onrc.onos.ofcontroller.util.FlowEntryMatch;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08009
10/**
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080011 *
Brian O'Connor7f8e3012014-02-15 23:59:29 -080012 * @author Brian O'Connor <bocon@onlab.us>
13 *
14 */
15
16public class Match {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080017 protected long sw;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080018 protected MACAddress srcMac;
19 protected MACAddress dstMac;
Brian O'Connor488e5ed2014-02-20 19:50:01 -080020 protected long srcPort;
21
22 public Match(long sw, long srcPort,
23 MACAddress srcMac, MACAddress dstMac) {
Brian O'Connor7f8e3012014-02-15 23:59:29 -080024 this.sw = sw;
25 this.srcPort = srcPort;
26 this.srcMac = srcMac;
27 this.dstMac = dstMac;
28 }
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080029
Brian O'Connor7f8e3012014-02-15 23:59:29 -080030 @Override
31 public boolean equals(Object obj) {
32 if(obj instanceof Match) {
33 Match other = (Match) obj;
34 return this.sw == other.sw &&
Brian O'Connor6dc44e92014-02-24 21:23:46 -080035 this.srcMac.equals(other.srcMac) &&
36 this.dstMac.equals(other.dstMac) &&
37 this.srcPort == other.srcPort;
Brian O'Connor7f8e3012014-02-15 23:59:29 -080038 }
39 else {
40 return false;
41 }
42 }
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080043
Brian O'Connor67c6e662014-02-17 15:20:44 -080044 public FlowEntryMatch getFlowEntryMatch(){
45 FlowEntryMatch match = new FlowEntryMatch();
46 match.enableSrcMac(srcMac);
47 match.enableDstMac(dstMac);
Brian O'Connor488e5ed2014-02-20 19:50:01 -080048 match.enableInPort(new net.onrc.onos.ofcontroller.util.Port((short) srcPort));
Brian O'Connor67c6e662014-02-17 15:20:44 -080049 return match;
50 }
Yuta HIGUCHIe80664e2014-02-20 22:41:57 -080051
52 @Override
Brian O'Connor7f8e3012014-02-15 23:59:29 -080053 public String toString() {
Brian O'Connor488e5ed2014-02-20 19:50:01 -080054 return "Sw:" + sw + " (" + srcPort + "," + srcMac + "," + dstMac + ")";
Brian O'Connor7f8e3012014-02-15 23:59:29 -080055 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080056
57 @Override
58 public int hashCode() {
59 long[] nums = new long[4];
60 nums[0] = sw;
61 nums[1] = srcPort;
62 nums[2] = srcMac.toLong();
63 nums[3] = dstMac.toLong();
64 return Arrays.hashCode(nums);
65 }
Brian O'Connor7f8e3012014-02-15 23:59:29 -080066}