blob: ecb1d6b82e3f6db833454c5c81e59a0cb5f434e7 [file] [log] [blame]
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -07001package net.onrc.onos.api.newintent;
2
3import com.google.common.base.Objects;
4import net.onrc.onos.core.matchaction.action.Action;
5import net.onrc.onos.core.matchaction.match.Match;
6
7import static com.google.common.base.Preconditions.checkNotNull;
8
9/**
10 * Abstraction of connectivity intent for traffic matching some criteria.
11 */
12public abstract class ConnectivityIntent extends AbstractIntent {
13
14 // TODO: other forms of intents should be considered for this family:
15 // point-to-point with constraints (waypoints/obstacles)
16 // multi-to-single point with constraints (waypoints/obstacles)
17 // single-to-multi point with constraints (waypoints/obstacles)
18 // concrete path (with alternate)
19 // ...
20
21 private final Match match;
22 // TODO: should consider which is better for multiple actions,
23 // defining compound action class or using list of actions.
24 private final Action action;
25
26 /**
27 * Creates a connectivity intent that matches on the specified intent
28 * and applies the specified action.
29 *
30 * @param id intent identifier
31 * @param match traffic match
32 * @param action action
33 * @throws NullPointerException if the match or action is null
34 */
35 protected ConnectivityIntent(IntentId id, Match match, Action action) {
36 super(id);
37 this.match = checkNotNull(match);
38 this.action = checkNotNull(action);
39 }
40
41 /**
42 * Returns the match specifying the type of traffic.
43 *
44 * @return traffic match
45 */
46 public Match getMatch() {
47 return match;
48 }
49
50 /**
51 * Returns the action applied to the traffic.
52 *
53 * @return applied action
54 */
55 public Action getAction() {
56 return action;
57 }
58
59 @Override
60 public boolean equals(Object o) {
61 if (!super.equals(o)) {
62 return false;
63 }
64 ConnectivityIntent that = (ConnectivityIntent) o;
65 return Objects.equal(this.match, that.match)
66 && Objects.equal(this.action, that.action);
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hashCode(super.hashCode(), match, action);
72 }
73
74}