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 | /** |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 8 | * Self-contained Switch and Port event 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 | |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 16 | private List<PortEvent> ports; |
| 17 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 18 | /** |
| 19 | * Default constructor. |
| 20 | */ |
| 21 | public SwitchEvent() { |
| 22 | dpid = null; |
| 23 | } |
| 24 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 25 | public SwitchEvent(Long dpid) { |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 26 | this(dpid, new ArrayList<PortEvent>()); |
| 27 | } |
| 28 | |
| 29 | public SwitchEvent(Long dpid, List<PortEvent> ports) { |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 30 | this.dpid = dpid; |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 31 | this.ports = ports; |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | public Long getDpid() { |
| 35 | return dpid; |
| 36 | } |
| 37 | |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 38 | public List<PortEvent> getPorts() { |
| 39 | return ports; |
| 40 | } |
| 41 | |
| 42 | public void setPorts(List<PortEvent> ports) { |
| 43 | this.ports = ports; |
| 44 | } |
| 45 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 46 | @Override |
| 47 | public String toString() { |
| 48 | return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]"; |
| 49 | } |
| 50 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame] | 51 | public static final int SWITCHID_BYTES = 2 + 8; |
| 52 | |
| 53 | public static byte[] getSwitchID(Long dpid) { |
| 54 | if (dpid == null) { |
| 55 | throw new IllegalArgumentException("dpid cannot be null"); |
| 56 | } |
| 57 | return ByteBuffer.allocate(SwitchEvent.SWITCHID_BYTES).putChar('S').putLong(dpid) |
| 58 | .array(); |
| 59 | } |
| 60 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 61 | public byte[] getID() { |
| 62 | return getSwitchID(dpid); |
| 63 | } |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 64 | } |