blob: d31ced82c7257559d051a2772162525e75496354 [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 Koidea03915e2014-07-01 18:39:52 -07008import net.onrc.onos.core.matchaction.action.IAction;
9import net.onrc.onos.core.matchaction.action.OutputAction;
10import net.onrc.onos.core.matchaction.match.IMatch;
11import 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;
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 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),
62 Arrays.asList((IMatch) new PacketMatch(srcMac, dstMac, srcIp, dstIp)),
63 Arrays.asList((IAction) new OutputAction(dstPort)));
64 }
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 */
84 public List<IMatch> getMatches() {
85 return matches;
86 }
87
88 /**
89 * Gets the list of actions of the match-action.
90 *
91 * @return The list of actions.
92 */
93 public List<IAction> getActions() {
94 return actions;
95 }
96}