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