Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
Brian O'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 3 | import java.util.Arrays; |
| 4 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 5 | import net.floodlightcontroller.util.MACAddress; |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 6 | //import net.onrc.onos.ofcontroller.networkgraph.Port; |
| 7 | //import net.onrc.onos.ofcontroller.networkgraph.Switch; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 8 | import net.onrc.onos.ofcontroller.util.FlowEntryMatch; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 9 | |
| 10 | /** |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 11 | * |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 12 | * @author Brian O'Connor <bocon@onlab.us> |
| 13 | * |
| 14 | */ |
| 15 | |
| 16 | public class Match { |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 17 | protected long sw; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 18 | protected MACAddress srcMac; |
| 19 | protected MACAddress dstMac; |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 20 | protected long srcPort; |
| 21 | |
| 22 | public Match(long sw, long srcPort, |
| 23 | MACAddress srcMac, MACAddress dstMac) { |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 24 | this.sw = sw; |
| 25 | this.srcPort = srcPort; |
| 26 | this.srcMac = srcMac; |
| 27 | this.dstMac = dstMac; |
| 28 | } |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 29 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 30 | @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'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 35 | this.srcMac.equals(other.srcMac) && |
| 36 | this.dstMac.equals(other.dstMac) && |
| 37 | this.srcPort == other.srcPort; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 38 | } |
| 39 | else { |
| 40 | return false; |
| 41 | } |
| 42 | } |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 43 | |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 44 | public FlowEntryMatch getFlowEntryMatch(){ |
| 45 | FlowEntryMatch match = new FlowEntryMatch(); |
| 46 | match.enableSrcMac(srcMac); |
| 47 | match.enableDstMac(dstMac); |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 48 | match.enableInPort(new net.onrc.onos.ofcontroller.util.Port((short) srcPort)); |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 49 | return match; |
| 50 | } |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 51 | |
| 52 | @Override |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 53 | public String toString() { |
Brian O'Connor | 488e5ed | 2014-02-20 19:50:01 -0800 | [diff] [blame] | 54 | return "Sw:" + sw + " (" + srcPort + "," + srcMac + "," + dstMac + ")"; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 55 | } |
Brian O'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 56 | |
| 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'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 66 | } |