blob: 0488b354e60c9f33e5a96db98243ace97c3b3ba3 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.intent;
2
Sho SHIMIZU54739912014-07-21 18:55:39 -07003import com.google.common.base.Objects;
Toshio Koidea03915e2014-07-01 18:39:52 -07004import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
Toshio Koidea03915e2014-07-01 18:39:52 -07005
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -07006import static com.google.common.base.Preconditions.checkNotNull;
7
Toshio Koidea03915e2014-07-01 18:39:52 -07008/**
Sho SHIMIZU54739912014-07-21 18:55:39 -07009 * The base class of an intent type.
10
Toshio Koidea03915e2014-07-01 18:39:52 -070011 * This class is sub-classed to provide other intent types like shortest path
12 * connectivity and bandwidth constrained shortest path connectivity.
Sho SHIMIZU54739912014-07-21 18:55:39 -070013
Toshio Koidea03915e2014-07-01 18:39:52 -070014 * 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 SHIMIZU54739912014-07-21 18:55:39 -070018 *
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 Koidea03915e2014-07-01 18:39:52 -070021 */
22public abstract class Intent implements IBatchOperationTarget {
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070023 private final IntentId id;
Toshio Koidea03915e2014-07-01 18:39:52 -070024
25 /**
Sho SHIMIZU54739912014-07-21 18:55:39 -070026 * Constructs an intent, which is activated permanently until it is removed explicitly.
Toshio Koidea03915e2014-07-01 18:39:52 -070027 *
Sho SHIMIZU54739912014-07-21 18:55:39 -070028 * @param id ID for this intent object.
Toshio Koidea03915e2014-07-01 18:39:52 -070029 */
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070030 protected Intent(IntentId id) {
31 this.id = checkNotNull(id);
Toshio Koidea03915e2014-07-01 18:39:52 -070032 }
33
34 /**
Sho SHIMIZU54739912014-07-21 18:55:39 -070035 * Returns ID for this Intent object.
Toshio Koidea03915e2014-07-01 18:39:52 -070036 *
37 * @return ID for this Intent object.
38 */
39 @Override
Toshio Koide025a9152014-07-21 11:00:34 -070040 public IntentId getId() {
Toshio Koidea03915e2014-07-01 18:39:52 -070041 return id;
42 }
43
Sho SHIMIZU54739912014-07-21 18:55:39 -070044 @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 Koidea03915e2014-07-01 18:39:52 -070069}