Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 2 | |
| 3 | import net.floodlightcontroller.util.MACAddress; |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.topology.web.serializers.ShortestPathIntentSerializer; |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.Dpid; |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 6 | import org.codehaus.jackson.map.annotate.JsonSerialize; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 7 | |
| 8 | /** |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 9 | * The ShortestPathIntent is a simple, "high-level" intent that |
| 10 | * provides shortest path connectivity between two end points in |
| 11 | * the network. |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 12 | */ |
Ray Milkey | 2fa6ca4 | 2014-06-13 15:38:20 -0700 | [diff] [blame] | 13 | @JsonSerialize(using = ShortestPathIntentSerializer.class) |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 14 | public class ShortestPathIntent extends Intent { |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame] | 15 | public static final long EMPTYMACADDRESS = 0; |
| 16 | public static final int EMPTYIPADDRESS = 0; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 17 | protected long srcSwitchDpid; |
| 18 | protected long srcPortNumber; |
| 19 | protected long srcMacAddress; |
| 20 | protected long dstSwitchDpid; |
| 21 | protected long dstPortNumber; |
| 22 | protected long dstMacAddress; |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame] | 23 | protected int srcIpAddress; |
| 24 | protected int dstIpAddress; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | protected String pathIntentId = null; |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 26 | protected int idleTimeout; |
| 27 | protected int hardTimeout; |
| 28 | protected int firstSwitchIdleTimeout; |
Jonathan Hart | 4dc8d87 | 2014-05-30 14:23:25 -0700 | [diff] [blame] | 29 | protected int firstSwitchHardTimeout; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 30 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | /** |
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 32 | * Default constructor for Kryo deserialization. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 33 | */ |
| 34 | protected ShortestPathIntent() { |
| 35 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 36 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Constructor for ShortestPathIntent. |
| 39 | * |
| 40 | * @param id Intent ID |
| 41 | * @param srcSwitch Source Switch DPID |
| 42 | * @param srcPort Source Port |
| 43 | * @param srcMac Source Host MAC Address |
| 44 | * @param dstSwitch Destination Switch DPID |
| 45 | * @param dstPort Destination Port |
| 46 | * @param dstMac Destination Host MAC Address |
| 47 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | public ShortestPathIntent(String id, |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 49 | long srcSwitch, long srcPort, long srcMac, |
| 50 | long dstSwitch, long dstPort, long dstMac) { |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame] | 51 | this(id, srcSwitch, srcPort, srcMac, EMPTYIPADDRESS, dstSwitch, dstPort, dstMac, EMPTYIPADDRESS); |
| 52 | } |
| 53 | |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 54 | /** |
| 55 | * Constructor. |
| 56 | * |
| 57 | * @param id Intent ID |
| 58 | * @param srcSwitch Source Switch DPID |
| 59 | * @param srcPort Source Port |
| 60 | * @param srcMac Source Host MAC Address |
| 61 | * @param srcIp Source IP Address |
| 62 | * @param dstSwitch Destination Switch DPID |
| 63 | * @param dstPort Destination Port |
| 64 | * @param dstMac Destination Host MAC Address |
| 65 | * @param dstIp Destination IP Address |
| 66 | */ |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame] | 67 | // CHECKSTYLE:OFF suppress the warning about too many parameters |
| 68 | public ShortestPathIntent(String id, |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 69 | long srcSwitch, long srcPort, long srcMac, int srcIp, |
| 70 | long dstSwitch, long dstPort, long dstMac, int dstIp ) { |
| 71 | // CHECKSTYLE:ON |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 72 | super(id); |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame] | 73 | this.srcSwitchDpid = srcSwitch; |
| 74 | this.srcPortNumber = srcPort; |
| 75 | this.srcMacAddress = srcMac; |
| 76 | this.dstSwitchDpid = dstSwitch; |
| 77 | this.dstPortNumber = dstPort; |
| 78 | this.dstMacAddress = dstMac; |
| 79 | this.srcIpAddress = srcIp; |
| 80 | this.dstIpAddress = dstIp; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 81 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 82 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Gets the source Switch DPID. |
| 85 | * |
| 86 | * @return Source Switch DPID |
| 87 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | public long getSrcSwitchDpid() { |
| 89 | return srcSwitchDpid; |
| 90 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 91 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Gets the source Port. |
| 94 | * |
| 95 | * @return Source Port |
| 96 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 97 | public long getSrcPortNumber() { |
| 98 | return srcPortNumber; |
| 99 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 100 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 101 | /** |
| 102 | * Gets the source Host MAC Address. |
| 103 | * |
| 104 | * @return Source Host MAC Address |
| 105 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 106 | public long getSrcMac() { |
| 107 | return srcMacAddress; |
| 108 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 109 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Gets the destination Switch DPID. |
| 112 | * |
| 113 | * @return Destination Switch DPID |
| 114 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 115 | public long getDstSwitchDpid() { |
| 116 | return dstSwitchDpid; |
| 117 | } |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 118 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Gets the destination Port. |
| 121 | * |
| 122 | * @return Destination Port |
| 123 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | public long getDstPortNumber() { |
| 125 | return dstPortNumber; |
| 126 | } |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 127 | |
Yuta HIGUCHI | ce4a06b | 2014-04-25 19:37:57 -0700 | [diff] [blame] | 128 | /** |
| 129 | * Gets the destination Host MAC Address. |
| 130 | * |
| 131 | * @return Destination Host MAC Address |
| 132 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 133 | public long getDstMac() { |
| 134 | return dstMacAddress; |
| 135 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 136 | |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 137 | /** |
| 138 | * Get the source IP address. |
| 139 | * |
| 140 | * @return source IP address |
| 141 | */ |
| 142 | public int getSrcIp() { |
| 143 | return srcIpAddress; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Get the destination IP address. |
| 148 | * |
| 149 | * @return destination IP address |
| 150 | */ |
| 151 | public int getDstIp() { |
| 152 | return dstIpAddress; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Set the low-level PathIntent ID. |
| 157 | * |
| 158 | * @param pathIntent new PathIntent |
| 159 | */ |
| 160 | public void setPathIntentId(PathIntent pathIntent) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 161 | pathIntentId = pathIntent.getId(); |
| 162 | } |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 163 | |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 164 | /** |
| 165 | * Get the low-level PathIntent ID. |
| 166 | * |
| 167 | * @return the ID of the low-level PathIntent |
| 168 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 169 | public String getPathIntentId() { |
| 170 | return pathIntentId; |
| 171 | } |
Toshio Koide | a10c037 | 2014-02-20 17:28:10 -0800 | [diff] [blame] | 172 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 173 | // TODO - this is intended to be refactored and removed |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 174 | public int getIdleTimeout() { |
| 175 | return idleTimeout; |
| 176 | } |
| 177 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 178 | // TODO - this is intended to be refactored and removed |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 179 | public int getHardTimeout() { |
| 180 | return hardTimeout; |
| 181 | } |
| 182 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 183 | // TODO - this is intended to be refactored and removed |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 184 | public void setIdleTimeout(int idleTimeout) { |
| 185 | this.idleTimeout = idleTimeout; |
| 186 | } |
| 187 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 188 | // TODO - this is intended to be refactored and removed |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 189 | public void setHardTimeout(int hardTimeout) { |
| 190 | this.hardTimeout = hardTimeout; |
| 191 | } |
| 192 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 193 | // TODO - this is intended to be refactored and removed |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 194 | public int getFirstSwitchIdleTimeout() { |
| 195 | return firstSwitchIdleTimeout; |
| 196 | } |
| 197 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 198 | // TODO - this is intended to be refactored and removed |
Jonathan Hart | 33e1f30 | 2014-05-30 14:37:09 -0700 | [diff] [blame] | 199 | public int getFirstSwitchHardTimeout() { |
Jonathan Hart | 4dc8d87 | 2014-05-30 14:23:25 -0700 | [diff] [blame] | 200 | return firstSwitchHardTimeout; |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 203 | // TODO - this is intended to be refactored and removed |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 204 | public void setFirstSwitchIdleTimeout(int firstSwitchIdleTimeout) { |
| 205 | this.firstSwitchIdleTimeout = firstSwitchIdleTimeout; |
| 206 | } |
| 207 | |
Ray Milkey | ff73514 | 2014-05-22 19:06:02 -0700 | [diff] [blame] | 208 | // TODO - this is intended to be refactored and removed |
Jonathan Hart | 33e1f30 | 2014-05-30 14:37:09 -0700 | [diff] [blame] | 209 | public void setFirstSwitchHardTimeout(int firstSwitchHardTimeout) { |
| 210 | this.firstSwitchHardTimeout = firstSwitchHardTimeout; |
TeruU | 30c0c93 | 2014-05-15 16:47:41 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 213 | /** |
| 214 | * Generates a hash code using the Intent ID. |
| 215 | * |
| 216 | * @return hashcode |
| 217 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 218 | @Override |
Pavlin Radoslavov | 7fb1641 | 2014-04-11 18:45:19 -0700 | [diff] [blame] | 219 | public int hashCode() { |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 220 | return super.hashCode(); |
Pavlin Radoslavov | 7fb1641 | 2014-04-11 18:45:19 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 223 | /** |
| 224 | * Compares two intent object by type (class) and Intent ID. |
| 225 | * |
| 226 | * @param obj other Intent |
| 227 | * @return true if equal, false otherwise |
| 228 | */ |
Pavlin Radoslavov | 7fb1641 | 2014-04-11 18:45:19 -0700 | [diff] [blame] | 229 | @Override |
| 230 | public boolean equals(Object obj) { |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 231 | return super.equals(obj); |
Pavlin Radoslavov | 7fb1641 | 2014-04-11 18:45:19 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Brian O'Connor | a581b9d | 2014-06-15 23:32:36 -0700 | [diff] [blame^] | 234 | /** |
| 235 | * Returns a String representation of this Intent. |
| 236 | * |
| 237 | * @return comma separated list of Intent parameters |
| 238 | */ |
Pavlin Radoslavov | 7fb1641 | 2014-04-11 18:45:19 -0700 | [diff] [blame] | 239 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 240 | public String toString() { |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 241 | return String.format("id:%s, state:%s, srcDpid:%s, srcPort:%d, " + |
| 242 | "srcMac:%s, srcIP:%s, dstDpid:%s, dstPort:%d, dstMac:%s, dstIP:%s", |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 243 | getId(), getState(), |
Jonathan Hart | c00f5c2 | 2014-06-10 15:14:40 -0700 | [diff] [blame] | 244 | new Dpid(srcSwitchDpid), srcPortNumber, |
| 245 | MACAddress.valueOf(srcMacAddress), Integer.toString(srcIpAddress), |
| 246 | new Dpid(dstSwitchDpid), dstPortNumber, |
| 247 | MACAddress.valueOf(dstMacAddress), Integer.toString(dstIpAddress)); |
Komal Shah | 399a292 | 2014-05-28 01:57:40 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 250 | } |