blob: ef6dd00a9d75e3cb29a5efe19e5128744a338964 [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;
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07004import net.onrc.onos.core.util.PortNumber;
Brian O'Connor7f8e3012014-02-15 23:59:29 -08005
6/**
Brian O'Connora84723c2014-06-13 00:26:49 -07007 * A class to represent the OpenFlow forwarding action.
Brian O'Connor7f8e3012014-02-15 23:59:29 -08008 */
9
10class ForwardAction extends Action {
Ray Milkey269ffb92014-04-03 14:43:30 -070011 protected long dstPort;
Brian O'Connor67c6e662014-02-17 15:20:44 -080012
Brian O'Connora84723c2014-06-13 00:26:49 -070013 /**
14 * Constructor.
15 *
16 * @param dstPort the destination port to forward packets
17 */
Ray Milkey269ffb92014-04-03 14:43:30 -070018 public ForwardAction(long dstPort) {
19 this.dstPort = dstPort;
20 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080021
Brian O'Connora84723c2014-06-13 00:26:49 -070022 /**
23 * Returns a String representation of this ForwardAction.
24 *
25 * @return the destination port as a String
26 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070027 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070028 public String toString() {
29 return Long.toString(dstPort);
30 }
31
Brian O'Connora84723c2014-06-13 00:26:49 -070032 /**
33 * Converts the FowardAction into a legacy FlowEntryAction object.
34 *
35 * @return an equivalent FlowEntryAction object
36 */
Ray Milkey269ffb92014-04-03 14:43:30 -070037 @Override
38 public FlowEntryAction getFlowEntryAction() {
39 FlowEntryAction action = new FlowEntryAction();
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070040 action.setActionOutput(new PortNumber((short) dstPort));
Ray Milkey269ffb92014-04-03 14:43:30 -070041 return action;
42 }
43
Brian O'Connora84723c2014-06-13 00:26:49 -070044 /**
45 * A simple hash function that just used the destination port.
46 *
47 * @return hashcode
48 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070049 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070050 public int hashCode() {
51 return (int) dstPort;
52 }
53
Brian O'Connora84723c2014-06-13 00:26:49 -070054 /**
55 * Objects are equal if they share a destination port.
56 *
Yuta HIGUCHI441585c2014-06-16 21:49:58 -070057 * @param o another object to compare to this
Brian O'Connora84723c2014-06-13 00:26:49 -070058 * @return true if equal, false otherwise
59 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070060 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070061 public boolean equals(Object o) {
62 if (!(o instanceof ForwardAction)) {
63 return false;
64 }
65 ForwardAction action = (ForwardAction) o;
66 return this.dstPort == action.dstPort;
67 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080068}