blob: fdf1fc711d6822320e6db4cbe5cb417fff600680 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.core.matchaction;
2
Toshio Koidea03915e2014-07-01 18:39:52 -07003import java.util.List;
4
Toshio Koidefad1cd52014-08-07 17:10:07 -07005import net.onrc.onos.api.batchoperation.BatchOperationTarget;
Toshio Koided8b077a2014-08-13 10:47:21 -07006import net.onrc.onos.core.matchaction.action.Action;
Toshio Koided8b077a2014-08-13 10:47:21 -07007import net.onrc.onos.core.matchaction.match.Match;
Toshio Koidea03915e2014-07-01 18:39:52 -07008import net.onrc.onos.core.util.SwitchPort;
9
10/**
Ray Milkeyc127a5a2014-08-20 11:22:12 -070011 * A filter and actions for traffic. Objects of this class are immutable.
Toshio Koidea03915e2014-07-01 18:39:52 -070012 */
Brian O'Connordee2e6b2014-08-12 11:34:51 -070013public final class MatchAction implements BatchOperationTarget {
Toshio Koide80db1842014-08-11 17:08:32 -070014 private final MatchActionId id;
15 private final SwitchPort port;
16 private final Match match;
17 private final List<Action> actions;
Toshio Koidea03915e2014-07-01 18:39:52 -070018
19 /**
20 * Constructor.
21 *
Toshio Koide80db1842014-08-11 17:08:32 -070022 * @param id ID for this MatchAction object
Brian O'Connordee2e6b2014-08-12 11:34:51 -070023 * @param port switch port to apply changes to
Toshio Koide80db1842014-08-11 17:08:32 -070024 * @param match the Match object as match condition on the port
25 * @param actions the list of Action objects as actions on the switch
Toshio Koidea03915e2014-07-01 18:39:52 -070026 */
Ray Milkey9ed4b962014-08-20 15:43:40 -070027 public MatchAction(MatchActionId id, SwitchPort port, Match match, List<Action> actions) {
28 this.id = id;
29 this.port = port;
30 this.match = match;
31 this.actions = actions;
32 }
33
34 /**
Brian O'Connor0efc9062014-09-02 14:47:28 -070035 * no-arg constructor for Kryo.
36 */
37 protected MatchAction() {
38 id = null;
39 port = null;
40 match = null;
41 actions = null;
42 }
43
44 /**
Ray Milkey9ed4b962014-08-20 15:43:40 -070045 * Constructor. TEMPORARY
46 *
47 * @param id ID for this MatchAction object
48 * @param port switch port to apply changes to
49 * @param match the Match object as match condition on the port
50 * @param actions the list of Action objects as actions on the switch
51 */
Toshio Koide80db1842014-08-11 17:08:32 -070052 public MatchAction(String id, SwitchPort port, Match match, List<Action> actions) {
Ray Milkey9ed4b962014-08-20 15:43:40 -070053 this.id = null;
Toshio Koidea03915e2014-07-01 18:39:52 -070054 this.port = port;
Toshio Koide80db1842014-08-11 17:08:32 -070055 this.match = match;
Toshio Koidea03915e2014-07-01 18:39:52 -070056 this.actions = actions;
57 }
58
59 /**
Toshio Koide80db1842014-08-11 17:08:32 -070060 * Gets ID for this object.
Toshio Koidea03915e2014-07-01 18:39:52 -070061 *
Toshio Koide80db1842014-08-11 17:08:32 -070062 * @return the ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070063 */
Toshio Koide025a9152014-07-21 11:00:34 -070064 public MatchActionId getId() {
Toshio Koidea03915e2014-07-01 18:39:52 -070065 return id;
66 }
67
68 /**
69 * Gets the switch-port which is the target of this match-action.
70 *
Toshio Koide80db1842014-08-11 17:08:32 -070071 * @return the target switch-port of this match-action
Toshio Koidea03915e2014-07-01 18:39:52 -070072 */
73 public SwitchPort getSwitchPort() {
74 return port;
75 }
76
77 /**
78 * Gets the traffic filter of the match-action.
79 *
Toshio Koide80db1842014-08-11 17:08:32 -070080 * @return the traffic filter
Toshio Koidea03915e2014-07-01 18:39:52 -070081 */
Toshio Koide80db1842014-08-11 17:08:32 -070082 public Match getMatch() {
83 return match;
Toshio Koidea03915e2014-07-01 18:39:52 -070084 }
85
86 /**
87 * Gets the list of actions of the match-action.
88 *
Toshio Koide80db1842014-08-11 17:08:32 -070089 * @return the list of actions
Toshio Koidea03915e2014-07-01 18:39:52 -070090 */
Toshio Koided8b077a2014-08-13 10:47:21 -070091 public List<Action> getActions() {
Toshio Koidea03915e2014-07-01 18:39:52 -070092 return actions;
93 }
Ray Milkeyc127a5a2014-08-20 11:22:12 -070094
95 @Override
96 public int hashCode() {
97 return id.hashCode();
98 }
99
100 @Override
101 public boolean equals(Object obj) {
102 if (obj instanceof MatchAction) {
103 MatchAction other = (MatchAction) obj;
104 return (id.equals(other.id));
105 }
106 return false;
107 }
Toshio Koidea03915e2014-07-01 18:39:52 -0700108}