Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 3 | import java.util.List; |
| 4 | |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 5 | import net.onrc.onos.api.batchoperation.BatchOperationTarget; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.matchaction.action.Action; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.matchaction.match.Match; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.util.SwitchPort; |
| 9 | |
| 10 | /** |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 11 | * A filter and actions for traffic. Objects of this class are immutable. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 12 | */ |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 13 | public final class MatchAction implements BatchOperationTarget { |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 14 | private final MatchActionId id; |
| 15 | private final SwitchPort port; |
| 16 | private final Match match; |
| 17 | private final List<Action> actions; |
Sangho Shin | 6f47dd3 | 2014-10-17 23:10:39 -0700 | [diff] [blame] | 18 | private final int priority; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Constructor. |
| 22 | * |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 23 | * @param id ID for this MatchAction object |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 24 | * @param port switch port to apply changes to |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 25 | * @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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 27 | */ |
Ray Milkey | 9ed4b96 | 2014-08-20 15:43:40 -0700 | [diff] [blame] | 28 | 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 Shin | 6f47dd3 | 2014-10-17 23:10:39 -0700 | [diff] [blame] | 33 | 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 Milkey | 9ed4b96 | 2014-08-20 15:43:40 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 54 | * no-arg constructor for Kryo. |
| 55 | */ |
| 56 | protected MatchAction() { |
| 57 | id = null; |
| 58 | port = null; |
| 59 | match = null; |
| 60 | actions = null; |
Sangho Shin | 6f47dd3 | 2014-10-17 23:10:39 -0700 | [diff] [blame] | 61 | priority = 0; |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 65 | * Gets ID for this object. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 66 | * |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 67 | * @return the ID for this object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 68 | */ |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 69 | public MatchActionId getId() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 70 | return id; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Gets the switch-port which is the target of this match-action. |
| 75 | * |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 76 | * @return the target switch-port of this match-action |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 77 | */ |
| 78 | public SwitchPort getSwitchPort() { |
| 79 | return port; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Gets the traffic filter of the match-action. |
| 84 | * |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 85 | * @return the traffic filter |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 86 | */ |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 87 | public Match getMatch() { |
| 88 | return match; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets the list of actions of the match-action. |
| 93 | * |
Toshio Koide | 80db184 | 2014-08-11 17:08:32 -0700 | [diff] [blame] | 94 | * @return the list of actions |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 95 | */ |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 96 | public List<Action> getActions() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 97 | return actions; |
| 98 | } |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 99 | |
Sangho Shin | 6f47dd3 | 2014-10-17 23:10:39 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Get the priority of the match action |
| 102 | * |
| 103 | * @return priority |
| 104 | */ |
| 105 | public int getPriority() { |
| 106 | return priority; |
| 107 | } |
| 108 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 109 | @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 Shin | 6f47dd3 | 2014-10-17 23:10:39 -0700 | [diff] [blame] | 122 | |
| 123 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 124 | } |