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