blob: f8ec5c2fb3fb7b670ba4ac97ca98345487274330 [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.
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070010 *
11 * <p>
Toshio Koidea03915e2014-07-01 18:39:52 -070012 * This class is sub-classed to provide other intent types like shortest path
13 * connectivity and bandwidth constrained shortest path connectivity.
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070014 * </p>
15 *
16 * <p>
Toshio Koidea03915e2014-07-01 18:39:52 -070017 * 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 SHIMIZU9beddc02014-08-04 11:32:11 -070021 * </p>
Sho SHIMIZU54739912014-07-21 18:55:39 -070022 *
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070023 * <p>
Sho SHIMIZU54739912014-07-21 18:55:39 -070024 * It is assumed that any kinds of intents are immutable.
25 * Developers that will define a new intent type should ensure its immutability.
Sho SHIMIZU9beddc02014-08-04 11:32:11 -070026 * </p>
Toshio Koidea03915e2014-07-01 18:39:52 -070027 */
28public abstract class Intent implements IBatchOperationTarget {
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070029 private final IntentId id;
Toshio Koidea03915e2014-07-01 18:39:52 -070030
31 /**
Sho SHIMIZU54739912014-07-21 18:55:39 -070032 * Constructs an intent, which is activated permanently until it is removed explicitly.
Toshio Koidea03915e2014-07-01 18:39:52 -070033 *
Sho SHIMIZU54739912014-07-21 18:55:39 -070034 * @param id ID for this intent object.
Toshio Koidea03915e2014-07-01 18:39:52 -070035 */
Sho SHIMIZUec4f5a72014-07-21 18:21:23 -070036 protected Intent(IntentId id) {
37 this.id = checkNotNull(id);
Toshio Koidea03915e2014-07-01 18:39:52 -070038 }
39
40 /**
Sho SHIMIZU54739912014-07-21 18:55:39 -070041 * Returns ID for this Intent object.
Toshio Koidea03915e2014-07-01 18:39:52 -070042 *
43 * @return ID for this Intent object.
44 */
Toshio Koide025a9152014-07-21 11:00:34 -070045 public IntentId getId() {
Toshio Koidea03915e2014-07-01 18:39:52 -070046 return id;
47 }
48
Sho SHIMIZU54739912014-07-21 18:55:39 -070049 @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 Koidea03915e2014-07-01 18:39:52 -070074}