Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 2 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 3 | import net.onrc.onos.core.util.FlowEntryAction; |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 4 | import net.onrc.onos.core.util.PortNumber; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 5 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 6 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 7 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 8 | import org.projectfloodlight.openflow.types.OFPort; |
| 9 | |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 10 | /** |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 11 | * A class to represent the OpenFlow forwarding action. |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | class ForwardAction extends Action { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 15 | protected long dstPort; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame] | 16 | |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 17 | /** |
| 18 | * Constructor. |
| 19 | * |
| 20 | * @param dstPort the destination port to forward packets |
| 21 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 22 | public ForwardAction(long dstPort) { |
| 23 | this.dstPort = dstPort; |
| 24 | } |
Brian O'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 25 | |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Returns a String representation of this ForwardAction. |
| 28 | * |
| 29 | * @return the destination port as a String |
| 30 | */ |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 31 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 32 | public String toString() { |
| 33 | return Long.toString(dstPort); |
| 34 | } |
| 35 | |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Converts the FowardAction into a legacy FlowEntryAction object. |
| 38 | * |
| 39 | * @return an equivalent FlowEntryAction object |
| 40 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | @Override |
| 42 | public FlowEntryAction getFlowEntryAction() { |
| 43 | FlowEntryAction action = new FlowEntryAction(); |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 44 | action.setActionOutput(new PortNumber((short) dstPort)); |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | return action; |
| 46 | } |
| 47 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame^] | 48 | @Override |
| 49 | public OFAction getOFAction(OFFactory factory) { |
| 50 | return factory.actions().output(OFPort.of((int) dstPort), Short.MAX_VALUE); |
| 51 | } |
| 52 | |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 53 | /** |
| 54 | * A simple hash function that just used the destination port. |
| 55 | * |
| 56 | * @return hashcode |
| 57 | */ |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 58 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | public int hashCode() { |
| 60 | return (int) dstPort; |
| 61 | } |
| 62 | |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 63 | /** |
| 64 | * Objects are equal if they share a destination port. |
| 65 | * |
Yuta HIGUCHI | 441585c | 2014-06-16 21:49:58 -0700 | [diff] [blame] | 66 | * @param o another object to compare to this |
Brian O'Connor | a84723c | 2014-06-13 00:26:49 -0700 | [diff] [blame] | 67 | * @return true if equal, false otherwise |
| 68 | */ |
Yuta HIGUCHI | fb56450 | 2014-06-16 21:29:00 -0700 | [diff] [blame] | 69 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | 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'Connor | 6dc44e9 | 2014-02-24 21:23:46 -0800 | [diff] [blame] | 77 | } |