blob: 58532aef5f10380c36dafd8c6537230d65f6cd56 [file] [log] [blame]
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
Yuta HIGUCHIb5107282014-02-14 17:18:24 -08003import java.nio.ByteBuffer;
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -08004import java.util.ArrayList;
5import java.util.List;
6
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08007/**
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -08008 * Self-contained Switch and Port event Object
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08009 *
10 * TODO: We probably want common base class/interface for Self-Contained Event Object
11 *
12 */
13public class SwitchEvent {
14 private final Long dpid;
15
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -080016 private List<PortEvent> ports;
17
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080018 public SwitchEvent(Long dpid) {
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -080019 this(dpid, new ArrayList<PortEvent>());
20 }
21
22 public SwitchEvent(Long dpid, List<PortEvent> ports) {
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080023 this.dpid = dpid;
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -080024 this.ports = ports;
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080025 }
26
27 public Long getDpid() {
28 return dpid;
29 }
30
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -080031 public List<PortEvent> getPorts() {
32 return ports;
33 }
34
35 public void setPorts(List<PortEvent> ports) {
36 this.ports = ports;
37 }
38
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080039 @Override
40 public String toString() {
41 return "[SwitchEvent 0x" + Long.toHexString(dpid) + "]";
42 }
43
Yuta HIGUCHIb5107282014-02-14 17:18:24 -080044 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 HIGUCHI54ab8cd2014-02-11 09:43:34 -080054}