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