blob: cd0327263bbb85d7312846dccbfb69baf525d2bc [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 /**
Sho SHIMIZU1674fb32014-08-20 14:44:31 -070042 * Constructor for serializer.
43 */
44 protected ConnectivityIntent() {
45 super();
46 this.match = null;
47 this.action = null;
48 }
49
50 /**
Sho SHIMIZU15ed4fd2014-08-05 14:40:42 -070051 * Returns the match specifying the type of traffic.
52 *
53 * @return traffic match
54 */
55 public Match getMatch() {
56 return match;
57 }
58
59 /**
60 * Returns the action applied to the traffic.
61 *
62 * @return applied action
63 */
64 public Action getAction() {
65 return action;
66 }
67
68 @Override
69 public boolean equals(Object o) {
70 if (!super.equals(o)) {
71 return false;
72 }
73 ConnectivityIntent that = (ConnectivityIntent) o;
74 return Objects.equal(this.match, that.match)
75 && Objects.equal(this.action, that.action);
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hashCode(super.hashCode(), match, action);
81 }
82
83}