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; |
| 7 | import net.onrc.onos.api.batchoperation.IBatchOperationTarget; |
| 8 | import net.onrc.onos.core.matchaction.action.IAction; |
| 9 | import net.onrc.onos.core.matchaction.action.OutputAction; |
| 10 | import net.onrc.onos.core.matchaction.match.IMatch; |
| 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 | */ |
| 20 | public class MatchAction implements IBatchOperationTarget { |
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; |
| 23 | protected List<IMatch> matches; |
| 24 | protected List<IAction> actions; |
| 25 | |
| 26 | /** |
| 27 | * Constructor. |
| 28 | * |
| 29 | * @param id ID for this MatchAction object. |
| 30 | * @param port Switch DPID |
| 31 | * @param matches The list of IMatch objects as match condition on the port. |
| 32 | * @param actions The list of IAction objects as actions on the switch. |
| 33 | */ |
| 34 | public MatchAction(String id, SwitchPort port, List<IMatch> matches, |
| 35 | List<IAction> 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), |
| 62 | Arrays.asList((IMatch) new PacketMatch(srcMac, dstMac, srcIp, dstIp)), |
| 63 | Arrays.asList((IAction) new OutputAction(dstPort))); |
| 64 | } |
| 65 | |
| 66 | @Override |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 67 | public MatchActionId getId() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 68 | return id; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Gets the switch-port which is the target of this match-action. |
| 73 | * |
| 74 | * @return The target switch-port of this match-action. |
| 75 | */ |
| 76 | public SwitchPort getSwitchPort() { |
| 77 | return port; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Gets the traffic filter of the match-action. |
| 82 | * |
| 83 | * @return The traffic filter. |
| 84 | */ |
| 85 | public List<IMatch> getMatches() { |
| 86 | return matches; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Gets the list of actions of the match-action. |
| 91 | * |
| 92 | * @return The list of actions. |
| 93 | */ |
| 94 | public List<IAction> getActions() { |
| 95 | return actions; |
| 96 | } |
| 97 | } |