blob: 2f21bafc179fd3531d9753f7a9e7185ff4f19fc3 [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;
7import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
8import 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 */
20public class MatchAction implements IBatchOperationTarget {
21 protected String id;
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) {
36 this.id = id;
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
67 public String getId() {
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}