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; |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 4 | import java.util.ArrayList; |
| 5 | import java.util.List; |
| 6 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 7 | /** |
Pavlin Radoslavov | 018d533 | 2014-02-19 23:08:35 -0800 | [diff] [blame] | 8 | * Self-contained Switch Object |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 9 | * |
| 10 | * TODO: We probably want common base class/interface for Self-Contained Event Object |
| 11 | * |
| 12 | */ |
| 13 | public class SwitchEvent { |
| 14 | private final Long dpid; |
| 15 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 16 | /** |
| 17 | * Default constructor. |
| 18 | */ |
| 19 | public SwitchEvent() { |
| 20 | dpid = null; |
| 21 | } |
| 22 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 23 | public SwitchEvent(Long dpid) { |
| 24 | this.dpid = dpid; |
| 25 | } |
| 26 | |
| 27 | public Long getDpid() { |
| 28 | return dpid; |
| 29 | } |
| 30 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 31 | @Override |
| 32 | public String toString() { |
| 33 | return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]"; |
| 34 | } |
| 35 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame] | 36 | public static final int SWITCHID_BYTES = 2 + 8; |
| 37 | |
| 38 | public static byte[] getSwitchID(Long dpid) { |
| 39 | if (dpid == null) { |
| 40 | throw new IllegalArgumentException("dpid cannot be null"); |
| 41 | } |
| 42 | return ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid) |
| 43 | .array(); |
| 44 | } |
| 45 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 46 | public byte[] getID() { |
| 47 | return getSwitchID(dpid); |
| 48 | } |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 49 | } |