blob: f0d09cb298ab9f3d0bcc4a0e39640a50a5a28693 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08002
Jonathan Hart23701d12014-04-03 10:45:48 -07003import net.onrc.onos.core.util.FlowEntryAction;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08004
5/**
Brian O'Connora84723c2014-06-13 00:26:49 -07006 * A class to represent the OpenFlow forwarding action.
Brian O'Connor7f8e3012014-02-15 23:59:29 -08007 */
8
9class ForwardAction extends Action {
Ray Milkey269ffb92014-04-03 14:43:30 -070010 protected long dstPort;
Brian O'Connor67c6e662014-02-17 15:20:44 -080011
Brian O'Connora84723c2014-06-13 00:26:49 -070012 /**
13 * Constructor.
14 *
15 * @param dstPort the destination port to forward packets
16 */
Ray Milkey269ffb92014-04-03 14:43:30 -070017 public ForwardAction(long dstPort) {
18 this.dstPort = dstPort;
19 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080020
Brian O'Connora84723c2014-06-13 00:26:49 -070021 /**
22 * Returns a String representation of this ForwardAction.
23 *
24 * @return the destination port as a String
25 */
Ray Milkey269ffb92014-04-03 14:43:30 -070026 public String toString() {
27 return Long.toString(dstPort);
28 }
29
Brian O'Connora84723c2014-06-13 00:26:49 -070030 /**
31 * Converts the FowardAction into a legacy FlowEntryAction object.
32 *
33 * @return an equivalent FlowEntryAction object
34 */
Ray Milkey269ffb92014-04-03 14:43:30 -070035 @Override
36 public FlowEntryAction getFlowEntryAction() {
37 FlowEntryAction action = new FlowEntryAction();
38 action.setActionOutput(new net.onrc.onos.core.util.Port((short) dstPort));
39 return action;
40 }
41
Brian O'Connora84723c2014-06-13 00:26:49 -070042 /**
43 * A simple hash function that just used the destination port.
44 *
45 * @return hashcode
46 */
Ray Milkey269ffb92014-04-03 14:43:30 -070047 public int hashCode() {
48 return (int) dstPort;
49 }
50
Brian O'Connora84723c2014-06-13 00:26:49 -070051 /**
52 * Objects are equal if they share a destination port.
53 *
54 * @params o another object to compare to this
55 * @return true if equal, false otherwise
56 */
Ray Milkey269ffb92014-04-03 14:43:30 -070057 public boolean equals(Object o) {
58 if (!(o instanceof ForwardAction)) {
59 return false;
60 }
61 ForwardAction action = (ForwardAction) o;
62 return this.dstPort == action.dstPort;
63 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080064}