blob: 36cf8cfee10f8233606dceb239c6dd63d2a8cb81 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08002
Yuta HIGUCHIb5107282014-02-14 17:18:24 -08003import java.nio.ByteBuffer;
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -08004
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08005/**
Ray Milkeyb41100a2014-04-10 10:42:15 -07006 * Self-contained Switch Object.
Ray Milkey269ffb92014-04-03 14:43:30 -07007 * <p/>
Ray Milkeyb41100a2014-04-10 10:42:15 -07008 * TODO: We probably want common base class/interface for Self-Contained Event Object.
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08009 */
10public class SwitchEvent {
Yuta HIGUCHIf65bcd52014-02-23 15:09:57 -080011 protected final Long dpid;
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080012
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080013 /**
Yuta HIGUCHI9cc421b2014-02-24 15:34:44 -080014 * Default constructor for Serializer to use.
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080015 */
Yuta HIGUCHI9cc421b2014-02-24 15:34:44 -080016 @Deprecated
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080017 public SwitchEvent() {
Ray Milkey269ffb92014-04-03 14:43:30 -070018 dpid = null;
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080019 }
20
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080021 public SwitchEvent(Long dpid) {
Ray Milkey269ffb92014-04-03 14:43:30 -070022 this.dpid = dpid;
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080023 }
24
25 public Long getDpid() {
Ray Milkey269ffb92014-04-03 14:43:30 -070026 return dpid;
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080027 }
28
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080029 @Override
30 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070031 return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]";
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080032 }
33
Yuta HIGUCHIb5107282014-02-14 17:18:24 -080034 public static final int SWITCHID_BYTES = 2 + 8;
35
Yuta HIGUCHIa341b112014-02-23 15:42:00 -080036 public static ByteBuffer getSwitchID(Long dpid) {
Ray Milkey269ffb92014-04-03 14:43:30 -070037 if (dpid == null) {
38 throw new IllegalArgumentException("dpid cannot be null");
39 }
40 return (ByteBuffer) ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid).flip();
Yuta HIGUCHIb5107282014-02-14 17:18:24 -080041 }
42
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080043 public byte[] getID() {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 return getSwitchID(dpid).array();
Yuta HIGUCHIa341b112014-02-23 15:42:00 -080045 }
46
47 public ByteBuffer getIDasByteBuffer() {
Ray Milkey269ffb92014-04-03 14:43:30 -070048 return getSwitchID(dpid);
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080049 }
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080050}