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