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 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 16 | /** |
| 17 | * Default constructor. |
| 18 | */ |
| 19 | public SwitchPort() { |
| 20 | dpid = null; |
| 21 | number = null; |
| 22 | } |
| 23 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 24 | public SwitchPort(Long dpid, Long number) { |
| 25 | this.dpid = dpid; |
| 26 | this.number = number; |
| 27 | } |
| 28 | |
| 29 | public Long getDpid() { |
| 30 | return dpid; |
| 31 | } |
| 32 | |
| 33 | public Long getNumber() { |
| 34 | return number; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public String toString() { |
| 39 | return "(" + Long.toHexString(dpid) + "@" + number + ")"; |
| 40 | } |
| 41 | |
| 42 | } |
| 43 | |
| 44 | private final SwitchPort id; |
| 45 | // TODO Add Hardware Address |
| 46 | // TODO Add Description |
| 47 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 48 | /** |
| 49 | * Default constructor. |
| 50 | */ |
| 51 | public PortEvent() { |
| 52 | id = null; |
| 53 | } |
| 54 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 55 | public PortEvent(Long dpid, Long number) { |
| 56 | this.id = new SwitchPort(dpid, number); |
| 57 | } |
| 58 | |
| 59 | public Long getDpid() { |
| 60 | return id.dpid; |
| 61 | } |
| 62 | |
| 63 | public Long getNumber() { |
| 64 | return id.number; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public String toString() { |
| 69 | return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]"; |
| 70 | } |
| 71 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame] | 72 | public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8; |
| 73 | |
| 74 | public static byte[] getPortID(Long dpid, Long number) { |
| 75 | if (dpid == null) { |
| 76 | throw new IllegalArgumentException("dpid cannot be null"); |
| 77 | } |
| 78 | if (number == null) { |
| 79 | throw new IllegalArgumentException("number cannot be null"); |
| 80 | } |
| 81 | return ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid) |
| 82 | .putChar('P').putLong(number).array(); |
| 83 | } |
| 84 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 85 | public byte[] getID() { |
| 86 | return getPortID(getDpid(), getNumber()); |
| 87 | } |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 88 | } |