Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame^] | 3 | import java.nio.ByteBuffer; |
| 4 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 5 | /** |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 6 | * Self-contained Port event Object |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 7 | * |
| 8 | * TODO: We probably want common base class/interface for Self-Contained Event Object |
| 9 | * |
| 10 | */ |
| 11 | public class PortEvent { |
| 12 | public static class SwitchPort { |
| 13 | public final Long dpid; |
| 14 | public final Long number; |
| 15 | |
| 16 | public SwitchPort(Long dpid, Long number) { |
| 17 | this.dpid = dpid; |
| 18 | this.number = number; |
| 19 | } |
| 20 | |
| 21 | public Long getDpid() { |
| 22 | return dpid; |
| 23 | } |
| 24 | |
| 25 | public Long getNumber() { |
| 26 | return number; |
| 27 | } |
| 28 | |
| 29 | @Override |
| 30 | public String toString() { |
| 31 | return "(" + Long.toHexString(dpid) + "@" + number + ")"; |
| 32 | } |
| 33 | |
| 34 | } |
| 35 | |
| 36 | private final SwitchPort id; |
| 37 | // TODO Add Hardware Address |
| 38 | // TODO Add Description |
| 39 | |
| 40 | public PortEvent(Long dpid, Long number) { |
| 41 | this.id = new SwitchPort(dpid, number); |
| 42 | } |
| 43 | |
| 44 | public Long getDpid() { |
| 45 | return id.dpid; |
| 46 | } |
| 47 | |
| 48 | public Long getNumber() { |
| 49 | return id.number; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public String toString() { |
| 54 | return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]"; |
| 55 | } |
| 56 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame^] | 57 | public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8; |
| 58 | |
| 59 | public static byte[] getPortID(Long dpid, Long number) { |
| 60 | if (dpid == null) { |
| 61 | throw new IllegalArgumentException("dpid cannot be null"); |
| 62 | } |
| 63 | if (number == null) { |
| 64 | throw new IllegalArgumentException("number cannot be null"); |
| 65 | } |
| 66 | return ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid) |
| 67 | .putChar('P').putLong(number).array(); |
| 68 | } |
| 69 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 70 | } |