Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
| 3 | import java.util.Arrays; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import net.floodlightcontroller.util.MACAddress; |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 7 | import net.onrc.onos.api.batchoperation.BatchOperationTarget; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 8 | import net.onrc.onos.core.matchaction.action.Action; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.matchaction.action.OutputAction; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 10 | import net.onrc.onos.core.matchaction.match.Match; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 11 | import net.onrc.onos.core.matchaction.match.PacketMatch; |
| 12 | import net.onrc.onos.core.util.Dpid; |
| 13 | import net.onrc.onos.core.util.IPv4; |
| 14 | import net.onrc.onos.core.util.PortNumber; |
| 15 | import net.onrc.onos.core.util.SwitchPort; |
| 16 | |
| 17 | /** |
| 18 | * A filter and actions for traffic. |
| 19 | */ |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 20 | public class MatchAction implements BatchOperationTarget { |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 21 | protected final MatchActionId id; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 22 | protected SwitchPort port; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 23 | protected List<Match> matches; |
| 24 | protected List<Action> actions; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | * |
| 29 | * @param id ID for this MatchAction object. |
| 30 | * @param port Switch DPID |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 31 | * @param matches The list of Match objects as match condition on the port. |
| 32 | * @param actions The list of Action objects as actions on the switch. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 33 | */ |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 34 | public MatchAction(String id, SwitchPort port, List<Match> matches, |
| 35 | List<Action> actions) { |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 36 | this.id = new MatchActionId(id); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 37 | this.port = port; |
| 38 | this.matches = matches; |
| 39 | this.actions = actions; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Constructor. |
| 44 | * <p> |
| 45 | * MEMO: This is a sample constructor to create a packet layer match action. |
| 46 | * |
| 47 | * @param id ID for this MatchAction object. |
| 48 | * @param dpid Switch DPID |
| 49 | * @param srcPort Source Port |
| 50 | * @param srcMac Source Host MAC Address |
| 51 | * @param dstMac Destination Host MAC Address |
| 52 | * @param srcIp Source IP Address |
| 53 | * @param dstIp Destination IP Address |
| 54 | * @param dstPort Destination Port |
| 55 | */ |
| 56 | // CHECKSTYLE:OFF suppress the warning about too many parameters |
| 57 | public MatchAction(String id, Dpid dpid, PortNumber srcPort, |
| 58 | MACAddress srcMac, MACAddress dstMac, |
| 59 | IPv4 srcIp, IPv4 dstIp, PortNumber dstPort) { |
| 60 | // CHECKSTYLE:ON |
| 61 | this(id, new SwitchPort(dpid, srcPort), |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 62 | Arrays.asList((Match) new PacketMatch(srcMac, dstMac, srcIp, dstIp)), |
| 63 | Arrays.asList((Action) new OutputAction(dstPort))); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 66 | public MatchActionId getId() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 67 | return id; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Gets the switch-port which is the target of this match-action. |
| 72 | * |
| 73 | * @return The target switch-port of this match-action. |
| 74 | */ |
| 75 | public SwitchPort getSwitchPort() { |
| 76 | return port; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Gets the traffic filter of the match-action. |
| 81 | * |
| 82 | * @return The traffic filter. |
| 83 | */ |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 84 | public List<Match> getMatches() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 85 | return matches; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Gets the list of actions of the match-action. |
| 90 | * |
| 91 | * @return The list of actions. |
| 92 | */ |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame^] | 93 | public List<Action> getActions() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 94 | return actions; |
| 95 | } |
| 96 | } |