blob: 5891f116b3b0baaa7e64cb25704b37187a94f31e [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;
Sangho Shin6f47dd32014-10-17 23:10:39 -070018 private final int priority;
Toshio Koidea03915e2014-07-01 18:39:52 -070019
20 /**
21 * Constructor.
22 *
Toshio Koide80db1842014-08-11 17:08:32 -070023 * @param id ID for this MatchAction object
Brian O'Connordee2e6b2014-08-12 11:34:51 -070024 * @param port switch port to apply changes to
Toshio Koide80db1842014-08-11 17:08:32 -070025 * @param match the Match object as match condition on the port
26 * @param actions the list of Action objects as actions on the switch
Toshio Koidea03915e2014-07-01 18:39:52 -070027 */
Ray Milkey9ed4b962014-08-20 15:43:40 -070028 public MatchAction(MatchActionId id, SwitchPort port, Match match, List<Action> actions) {
29 this.id = id;
30 this.port = port;
31 this.match = match;
32 this.actions = actions;
Sangho Shin6f47dd32014-10-17 23:10:39 -070033 this.priority = 0;
34 }
35
36 /**
37 * Constructor.
38 *
39 * @param id ID for this MatchAction object
40 * @param port switch port to apply changes to
41 * @param match the Match object as match condition on the port
42 * @param actions the list of Action objects as actions on the switch
43 * @param priority the priority of the MatchAction
44 */
45 public MatchAction(MatchActionId id, SwitchPort port, Match match, int priority, List<Action> actions) {
46 this.id = id;
47 this.port = port;
48 this.match = match;
49 this.actions = actions;
50 this.priority = priority;
Ray Milkey9ed4b962014-08-20 15:43:40 -070051 }
52
53 /**
Brian O'Connor0efc9062014-09-02 14:47:28 -070054 * no-arg constructor for Kryo.
55 */
56 protected MatchAction() {
57 id = null;
58 port = null;
59 match = null;
60 actions = null;
Sangho Shin6f47dd32014-10-17 23:10:39 -070061 priority = 0;
Brian O'Connor0efc9062014-09-02 14:47:28 -070062 }
63
64 /**
Toshio Koide80db1842014-08-11 17:08:32 -070065 * Gets ID for this object.
Toshio Koidea03915e2014-07-01 18:39:52 -070066 *
Toshio Koide80db1842014-08-11 17:08:32 -070067 * @return the ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070068 */
Toshio Koide025a9152014-07-21 11:00:34 -070069 public MatchActionId getId() {
Toshio Koidea03915e2014-07-01 18:39:52 -070070 return id;
71 }
72
73 /**
74 * Gets the switch-port which is the target of this match-action.
75 *
Toshio Koide80db1842014-08-11 17:08:32 -070076 * @return the target switch-port of this match-action
Toshio Koidea03915e2014-07-01 18:39:52 -070077 */
78 public SwitchPort getSwitchPort() {
79 return port;
80 }
81
82 /**
83 * Gets the traffic filter of the match-action.
84 *
Toshio Koide80db1842014-08-11 17:08:32 -070085 * @return the traffic filter
Toshio Koidea03915e2014-07-01 18:39:52 -070086 */
Toshio Koide80db1842014-08-11 17:08:32 -070087 public Match getMatch() {
88 return match;
Toshio Koidea03915e2014-07-01 18:39:52 -070089 }
90
91 /**
92 * Gets the list of actions of the match-action.
93 *
Toshio Koide80db1842014-08-11 17:08:32 -070094 * @return the list of actions
Toshio Koidea03915e2014-07-01 18:39:52 -070095 */
Toshio Koided8b077a2014-08-13 10:47:21 -070096 public List<Action> getActions() {
Toshio Koidea03915e2014-07-01 18:39:52 -070097 return actions;
98 }
Ray Milkeyc127a5a2014-08-20 11:22:12 -070099
Sangho Shin6f47dd32014-10-17 23:10:39 -0700100 /**
101 * Get the priority of the match action
102 *
103 * @return priority
104 */
105 public int getPriority() {
106 return priority;
107 }
108
Ray Milkeyc127a5a2014-08-20 11:22:12 -0700109 @Override
110 public int hashCode() {
111 return id.hashCode();
112 }
113
114 @Override
115 public boolean equals(Object obj) {
116 if (obj instanceof MatchAction) {
117 MatchAction other = (MatchAction) obj;
118 return (id.equals(other.id));
119 }
120 return false;
121 }
Sangho Shin6f47dd32014-10-17 23:10:39 -0700122
123
Toshio Koidea03915e2014-07-01 18:39:52 -0700124}