blob: a3792d1b1945b9a35370e1d4a8f1e76772476a62 [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
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07006import org.projectfloodlight.openflow.protocol.OFFactory;
7import org.projectfloodlight.openflow.protocol.action.OFAction;
8import org.projectfloodlight.openflow.types.OFPort;
9
Brian O'Connor7f8e3012014-02-15 23:59:29 -080010/**
Brian O'Connora84723c2014-06-13 00:26:49 -070011 * A class to represent the OpenFlow forwarding action.
Brian O'Connor7f8e3012014-02-15 23:59:29 -080012 */
13
14class ForwardAction extends Action {
Ray Milkey269ffb92014-04-03 14:43:30 -070015 protected long dstPort;
Brian O'Connor67c6e662014-02-17 15:20:44 -080016
Brian O'Connora84723c2014-06-13 00:26:49 -070017 /**
18 * Constructor.
19 *
20 * @param dstPort the destination port to forward packets
21 */
Ray Milkey269ffb92014-04-03 14:43:30 -070022 public ForwardAction(long dstPort) {
23 this.dstPort = dstPort;
24 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080025
Brian O'Connora84723c2014-06-13 00:26:49 -070026 /**
27 * Returns a String representation of this ForwardAction.
28 *
29 * @return the destination port as a String
30 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070031 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070032 public String toString() {
33 return Long.toString(dstPort);
34 }
35
Brian O'Connora84723c2014-06-13 00:26:49 -070036 /**
37 * Converts the FowardAction into a legacy FlowEntryAction object.
38 *
39 * @return an equivalent FlowEntryAction object
40 */
Ray Milkey269ffb92014-04-03 14:43:30 -070041 @Override
42 public FlowEntryAction getFlowEntryAction() {
43 FlowEntryAction action = new FlowEntryAction();
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070044 action.setActionOutput(new PortNumber((short) dstPort));
Ray Milkey269ffb92014-04-03 14:43:30 -070045 return action;
46 }
47
Brian O'Connorc67f9fa2014-08-07 18:17:46 -070048 @Override
49 public OFAction getOFAction(OFFactory factory) {
50 return factory.actions().output(OFPort.of((int) dstPort), Short.MAX_VALUE);
51 }
52
Brian O'Connora84723c2014-06-13 00:26:49 -070053 /**
54 * A simple hash function that just used the destination port.
55 *
56 * @return hashcode
57 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070058 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070059 public int hashCode() {
60 return (int) dstPort;
61 }
62
Brian O'Connora84723c2014-06-13 00:26:49 -070063 /**
64 * Objects are equal if they share a destination port.
65 *
Yuta HIGUCHI441585c2014-06-16 21:49:58 -070066 * @param o another object to compare to this
Brian O'Connora84723c2014-06-13 00:26:49 -070067 * @return true if equal, false otherwise
68 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070069 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070070 public boolean equals(Object o) {
71 if (!(o instanceof ForwardAction)) {
72 return false;
73 }
74 ForwardAction action = (ForwardAction) o;
75 return this.dstPort == action.dstPort;
76 }
Brian O'Connor6dc44e92014-02-24 21:23:46 -080077}