Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.intent; |
| 2 | |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 3 | import com.google.common.base.Objects; |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 4 | import net.onrc.onos.api.batchoperation.BatchOperationTarget; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 5 | |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 6 | import static com.google.common.base.Preconditions.checkNotNull; |
| 7 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 8 | /** |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 9 | * The base class of an intent type. |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame] | 10 | * |
| 11 | * <p> |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 12 | * This class is sub-classed to provide other intent types like shortest path |
| 13 | * connectivity and bandwidth constrained shortest path connectivity. |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame] | 14 | * </p> |
| 15 | * |
| 16 | * <p> |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 17 | * The reasoning behind "intent" is that the applications can provide some |
| 18 | * abstract representation of how traffic should flow be handled by the |
| 19 | * networking, allowing the network OS to compile, reserve and optimize the |
| 20 | * data-plane to satisfy those constraints. |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame] | 21 | * </p> |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 22 | * |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame] | 23 | * <p> |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 24 | * It is assumed that any kinds of intents are immutable. |
| 25 | * Developers that will define a new intent type should ensure its immutability. |
Sho SHIMIZU | 9beddc0 | 2014-08-04 11:32:11 -0700 | [diff] [blame] | 26 | * </p> |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 27 | */ |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 28 | public abstract class Intent implements BatchOperationTarget { |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 29 | private final IntentId id; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 32 | * Constructs an intent, which is activated permanently until it is removed explicitly. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 33 | * |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 34 | * @param id ID for this intent object. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 35 | */ |
Sho SHIMIZU | ec4f5a7 | 2014-07-21 18:21:23 -0700 | [diff] [blame] | 36 | protected Intent(IntentId id) { |
| 37 | this.id = checkNotNull(id); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 41 | * Returns ID for this Intent object. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 42 | * |
| 43 | * @return ID for this Intent object. |
| 44 | */ |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 45 | public IntentId getId() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 46 | return id; |
| 47 | } |
| 48 | |
Sho SHIMIZU | 5473991 | 2014-07-21 18:55:39 -0700 | [diff] [blame] | 49 | @Override |
| 50 | public int hashCode() { |
| 51 | return id.hashCode(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean equals(Object obj) { |
| 56 | if (obj == this) { |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | if (!(obj instanceof Intent)) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | Intent that = (Intent) obj; |
| 65 | return Objects.equal(this.id, that.id); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String toString() { |
| 70 | return Objects.toStringHelper(this) |
| 71 | .add("id", id) |
| 72 | .toString(); |
| 73 | } |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 74 | } |