Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 2 | |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 3 | |
| 4 | import java.util.Objects; |
Brian O'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 5 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 6 | import net.floodlightcontroller.util.MACAddress; |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 7 | import net.onrc.onos.core.packet.Ethernet; |
Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 8 | //import net.onrc.onos.core.topology.Port; |
| 9 | //import net.onrc.onos.core.topology.Switch; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 10 | import net.onrc.onos.core.util.FlowEntryMatch; |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 11 | import net.onrc.onos.core.util.IPv4; |
| 12 | import net.onrc.onos.core.util.IPv4Net; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 13 | |
| 14 | /** |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 15 | * @author Brian O'Connor <bocon@onlab.us> |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | public class Match { |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 19 | private static final short IPV4_PREFIX_LEN = 32; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 20 | protected long sw; |
| 21 | protected MACAddress srcMac; |
| 22 | protected MACAddress dstMac; |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 23 | protected int srcIp; |
| 24 | protected int dstIp; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | protected long srcPort; |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 26 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | public Match(long sw, long srcPort, |
| 28 | MACAddress srcMac, MACAddress dstMac) { |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 29 | this(sw, srcPort, srcMac, dstMac, ShortestPathIntent.EMPTYIPADDRESS, ShortestPathIntent.EMPTYIPADDRESS); |
| 30 | } |
| 31 | |
| 32 | public Match(long sw, long srcPort, MACAddress srcMac, MACAddress dstMac, |
| 33 | int srcIp, int dstIp) { |
| 34 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | this.sw = sw; |
| 36 | this.srcPort = srcPort; |
| 37 | this.srcMac = srcMac; |
| 38 | this.dstMac = dstMac; |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 39 | this.srcIp = srcIp; |
| 40 | this.dstIp = dstIp; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | } |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 42 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | @Override |
| 44 | public boolean equals(Object obj) { |
| 45 | if (obj instanceof Match) { |
| 46 | Match other = (Match) obj; |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 47 | if (this.sw != other.sw) { |
| 48 | return false; |
| 49 | } |
| 50 | if (!Objects.equals(srcMac, other.srcMac)) { |
| 51 | return false; |
| 52 | } |
| 53 | if (!Objects.equals(dstMac, other.dstMac)) { |
| 54 | return false; |
| 55 | } |
| 56 | if (srcIp != other.srcIp) { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | if (dstIp != other.dstIp) { |
| 61 | return false; |
| 62 | } |
| 63 | if (this.srcPort != other.srcPort) { |
| 64 | return false; |
| 65 | } |
| 66 | return true; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 67 | } else { |
| 68 | return false; |
| 69 | } |
| 70 | } |
Yuta HIGUCHI | e80664e | 2014-02-20 22:41:57 -0800 | [diff] [blame] | 71 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | public FlowEntryMatch getFlowEntryMatch() { |
| 73 | FlowEntryMatch match = new FlowEntryMatch(); |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 74 | if (srcMac != null) { |
| 75 | match.enableSrcMac(srcMac); |
| 76 | } |
| 77 | if (dstMac != null) { |
| 78 | match.enableDstMac(dstMac); |
| 79 | } |
| 80 | if (srcIp != ShortestPathIntent.EMPTYIPADDRESS) { |
| 81 | match.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
| 82 | IPv4 srcIPv4 = new IPv4(srcIp); |
| 83 | IPv4Net srcIP = new IPv4Net(srcIPv4, IPV4_PREFIX_LEN); |
| 84 | match.enableSrcIPv4Net(srcIP); |
| 85 | } |
| 86 | if (dstIp != ShortestPathIntent.EMPTYIPADDRESS) { |
| 87 | match.enableEthernetFrameType(Ethernet.TYPE_IPV4); |
| 88 | IPv4 dstIPv4 = new IPv4(dstIp); |
| 89 | IPv4Net dstIP = new IPv4Net(dstIPv4, IPV4_PREFIX_LEN); |
| 90 | match.enableDstIPv4Net(dstIP); |
| 91 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | match.enableInPort(new net.onrc.onos.core.util.Port((short) srcPort)); |
| 93 | return match; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public String toString() { |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 98 | return "Sw:" + sw + " (" + srcPort + "," + srcMac + "," + dstMac + "," + srcIp + "," + dstIp + ")"; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public int hashCode() { |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame^] | 103 | return Objects.hash(sw, srcPort, srcMac, dstMac, srcIp, dstIp); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 104 | } |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 105 | } |