blob: 5f7d9fb7fa246488b77eb5b9dd015ce861366b85 [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 /**
35 * Constructor. TEMPORARY
36 *
37 * @param id ID for this MatchAction object
38 * @param port switch port to apply changes to
39 * @param match the Match object as match condition on the port
40 * @param actions the list of Action objects as actions on the switch
41 */
Toshio Koide80db1842014-08-11 17:08:32 -070042 public MatchAction(String id, SwitchPort port, Match match, List<Action> actions) {
Ray Milkey9ed4b962014-08-20 15:43:40 -070043 this.id = null;
Toshio Koidea03915e2014-07-01 18:39:52 -070044 this.port = port;
Toshio Koide80db1842014-08-11 17:08:32 -070045 this.match = match;
Toshio Koidea03915e2014-07-01 18:39:52 -070046 this.actions = actions;
47 }
48
49 /**
Toshio Koide80db1842014-08-11 17:08:32 -070050 * Gets ID for this object.
Toshio Koidea03915e2014-07-01 18:39:52 -070051 *
Toshio Koide80db1842014-08-11 17:08:32 -070052 * @return the ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070053 */
Toshio Koide025a9152014-07-21 11:00:34 -070054 public MatchActionId getId() {
Toshio Koidea03915e2014-07-01 18:39:52 -070055 return id;
56 }
57
58 /**
59 * Gets the switch-port which is the target of this match-action.
60 *
Toshio Koide80db1842014-08-11 17:08:32 -070061 * @return the target switch-port of this match-action
Toshio Koidea03915e2014-07-01 18:39:52 -070062 */
63 public SwitchPort getSwitchPort() {
64 return port;
65 }
66
67 /**
68 * Gets the traffic filter of the match-action.
69 *
Toshio Koide80db1842014-08-11 17:08:32 -070070 * @return the traffic filter
Toshio Koidea03915e2014-07-01 18:39:52 -070071 */
Toshio Koide80db1842014-08-11 17:08:32 -070072 public Match getMatch() {
73 return match;
Toshio Koidea03915e2014-07-01 18:39:52 -070074 }
75
76 /**
77 * Gets the list of actions of the match-action.
78 *
Toshio Koide80db1842014-08-11 17:08:32 -070079 * @return the list of actions
Toshio Koidea03915e2014-07-01 18:39:52 -070080 */
Toshio Koided8b077a2014-08-13 10:47:21 -070081 public List<Action> getActions() {
Toshio Koidea03915e2014-07-01 18:39:52 -070082 return actions;
83 }
Ray Milkeyc127a5a2014-08-20 11:22:12 -070084
85 @Override
86 public int hashCode() {
87 return id.hashCode();
88 }
89
90 @Override
91 public boolean equals(Object obj) {
92 if (obj instanceof MatchAction) {
93 MatchAction other = (MatchAction) obj;
94 return (id.equals(other.id));
95 }
96 return false;
97 }
Toshio Koidea03915e2014-07-01 18:39:52 -070098}