blob: e4caee5383a126988960b622158a387679392236 [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;
4
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08005/**
Yuta HIGUCHIdac4caa2014-02-11 18:51:35 -08006 * Self-contained Port event Object
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08007 *
8 * TODO: We probably want common base class/interface for Self-Contained Event Object
9 *
10 */
11public class PortEvent {
12 public static class SwitchPort {
13 public final Long dpid;
14 public final Long number;
15
16 public SwitchPort(Long dpid, Long number) {
17 this.dpid = dpid;
18 this.number = number;
19 }
20
21 public Long getDpid() {
22 return dpid;
23 }
24
25 public Long getNumber() {
26 return number;
27 }
28
29 @Override
30 public String toString() {
31 return "(" + Long.toHexString(dpid) + "@" + number + ")";
32 }
33
34 }
35
36 private final SwitchPort id;
37 // TODO Add Hardware Address
38 // TODO Add Description
39
40 public PortEvent(Long dpid, Long number) {
41 this.id = new SwitchPort(dpid, number);
42 }
43
44 public Long getDpid() {
45 return id.dpid;
46 }
47
48 public Long getNumber() {
49 return id.number;
50 }
51
52 @Override
53 public String toString() {
54 return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]";
55 }
56
Yuta HIGUCHIb5107282014-02-14 17:18:24 -080057 public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8;
58
59 public static byte[] getPortID(Long dpid, Long number) {
60 if (dpid == null) {
61 throw new IllegalArgumentException("dpid cannot be null");
62 }
63 if (number == null) {
64 throw new IllegalArgumentException("number cannot be null");
65 }
66 return ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
67 .putChar('P').putLong(number).array();
68 }
69
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080070}