blob: b42bf1e592a2024a6eb99571ad1d39551672aab7 [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
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080016 /**
17 * Default constructor.
18 */
19 public SwitchPort() {
20 dpid = null;
21 number = null;
22 }
23
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080024 public SwitchPort(Long dpid, Long number) {
25 this.dpid = dpid;
26 this.number = number;
27 }
28
29 public Long getDpid() {
30 return dpid;
31 }
32
33 public Long getNumber() {
34 return number;
35 }
36
37 @Override
38 public String toString() {
39 return "(" + Long.toHexString(dpid) + "@" + number + ")";
40 }
41
42 }
43
44 private final SwitchPort id;
45 // TODO Add Hardware Address
46 // TODO Add Description
47
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080048 /**
49 * Default constructor.
50 */
51 public PortEvent() {
52 id = null;
53 }
54
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080055 public PortEvent(Long dpid, Long number) {
56 this.id = new SwitchPort(dpid, number);
57 }
58
59 public Long getDpid() {
60 return id.dpid;
61 }
62
63 public Long getNumber() {
64 return id.number;
65 }
66
67 @Override
68 public String toString() {
69 return "[PortEvent 0x" + Long.toHexString(id.dpid) + "@" + id.number + "]";
70 }
71
Yuta HIGUCHIb5107282014-02-14 17:18:24 -080072 public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8;
73
74 public static byte[] getPortID(Long dpid, Long number) {
75 if (dpid == null) {
76 throw new IllegalArgumentException("dpid cannot be null");
77 }
78 if (number == null) {
79 throw new IllegalArgumentException("number cannot be null");
80 }
81 return ByteBuffer.allocate(PortEvent.PORTID_BYTES).putChar('S').putLong(dpid)
82 .putChar('P').putLong(number).array();
83 }
84
Pavlin Radoslavov45ec04b2014-02-14 23:29:33 -080085 public byte[] getID() {
86 return getPortID(getDpid(), getNumber());
87 }
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080088}