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