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