blob: 2ff3299a2cb5b1c1b85336ac7c49487d0e2550e1 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.core.matchaction;
2
3import java.util.Arrays;
4import java.util.List;
5
6import net.floodlightcontroller.util.MACAddress;
Toshio Koidefad1cd52014-08-07 17:10:07 -07007import net.onrc.onos.api.batchoperation.BatchOperationTarget;
Toshio Koided8b077a2014-08-13 10:47:21 -07008import net.onrc.onos.core.matchaction.action.Action;
Toshio Koidea03915e2014-07-01 18:39:52 -07009import net.onrc.onos.core.matchaction.action.OutputAction;
Toshio Koided8b077a2014-08-13 10:47:21 -070010import net.onrc.onos.core.matchaction.match.Match;
Toshio Koidea03915e2014-07-01 18:39:52 -070011import net.onrc.onos.core.matchaction.match.PacketMatch;
12import net.onrc.onos.core.util.Dpid;
13import net.onrc.onos.core.util.IPv4;
14import net.onrc.onos.core.util.PortNumber;
15import net.onrc.onos.core.util.SwitchPort;
16
17/**
18 * A filter and actions for traffic.
19 */
Toshio Koidefad1cd52014-08-07 17:10:07 -070020public class MatchAction implements BatchOperationTarget {
Toshio Koide025a9152014-07-21 11:00:34 -070021 protected final MatchActionId id;
Toshio Koidea03915e2014-07-01 18:39:52 -070022 protected SwitchPort port;
Toshio Koided8b077a2014-08-13 10:47:21 -070023 protected List<Match> matches;
24 protected List<Action> actions;
Toshio Koidea03915e2014-07-01 18:39:52 -070025
26 /**
27 * Constructor.
28 *
29 * @param id ID for this MatchAction object.
30 * @param port Switch DPID
Toshio Koided8b077a2014-08-13 10:47:21 -070031 * @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 Koidea03915e2014-07-01 18:39:52 -070033 */
Toshio Koided8b077a2014-08-13 10:47:21 -070034 public MatchAction(String id, SwitchPort port, List<Match> matches,
35 List<Action> actions) {
Toshio Koide025a9152014-07-21 11:00:34 -070036 this.id = new MatchActionId(id);
Toshio Koidea03915e2014-07-01 18:39:52 -070037 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 Koided8b077a2014-08-13 10:47:21 -070062 Arrays.asList((Match) new PacketMatch(srcMac, dstMac, srcIp, dstIp)),
63 Arrays.asList((Action) new OutputAction(dstPort)));
Toshio Koidea03915e2014-07-01 18:39:52 -070064 }
65
Toshio Koide025a9152014-07-21 11:00:34 -070066 public MatchActionId getId() {
Toshio Koidea03915e2014-07-01 18:39:52 -070067 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 Koided8b077a2014-08-13 10:47:21 -070084 public List<Match> getMatches() {
Toshio Koidea03915e2014-07-01 18:39:52 -070085 return matches;
86 }
87
88 /**
89 * Gets the list of actions of the match-action.
90 *
91 * @return The list of actions.
92 */
Toshio Koided8b077a2014-08-13 10:47:21 -070093 public List<Action> getActions() {
Toshio Koidea03915e2014-07-01 18:39:52 -070094 return actions;
95 }
96}