blob: 014fc43617d8bb0e3034c1e110d899e92a0c1aa3 [file] [log] [blame]
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
3import java.net.InetAddress;
4import java.util.HashSet;
5import java.util.LinkedList;
6import java.util.List;
7import java.util.Set;
8
9import net.floodlightcontroller.util.MACAddress;
10import net.onrc.onos.ofcontroller.networkgraph.PortEvent.SwitchPort;
11
12/**
Yuta HIGUCHI8d762e92014-02-12 14:10:25 -080013 * Self-contained Device event(s) Object
14 *
15 * Device event differ from other events.
16 * Device Event represent add/remove of attachmentPoint or ipAddress.
17 * Not add/remove of the DeviceObject itself.
18 *
19 * Multiple attachmentPoints can be specified to batch events into 1 object.
20 * Each should be treated as independent events.
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080021 *
22 * TODO: We probably want common base class/interface for Self-Contained Event Object
23 *
24 */
25public class DeviceEvent {
26 private final MACAddress mac;
27 protected List<SwitchPort> attachmentPoints;
28 protected Set<InetAddress> ipAddresses;
29
30 public DeviceEvent(MACAddress mac) {
Yuta HIGUCHI8d762e92014-02-12 14:10:25 -080031 if (mac == null) {
32 throw new IllegalArgumentException("Device mac cannot be null");
33 }
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080034 this.mac = mac;
35 this.attachmentPoints = new LinkedList<>();
36 this.ipAddresses = new HashSet<>();
37 }
38
39 public MACAddress getMac() {
40 return mac;
41 }
42
43 public List<SwitchPort> getAttachmentPoints() {
44 return attachmentPoints;
45 }
46
Yuta HIGUCHI8d762e92014-02-12 14:10:25 -080047 public Set<InetAddress> getIpAddresses() {
48 return ipAddresses;
49 }
50
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080051 public void setAttachmentPoints(List<SwitchPort> attachmentPoints) {
52 this.attachmentPoints = attachmentPoints;
53 }
54
Yuta HIGUCHI8d762e92014-02-12 14:10:25 -080055 public void addAttachmentPoint(SwitchPort attachmentPoint) {
56 // may need to maintain uniqness
57 this.attachmentPoints.add(0, attachmentPoint);
58 }
59
60
Yuta HIGUCHI54ab8cd2014-02-11 09:43:34 -080061 boolean addIpAddress(InetAddress addr) {
62 return this.ipAddresses.add(addr);
63 }
64
65 boolean removeIpAddress(InetAddress addr) {
66 return this.ipAddresses.remove(addr);
67 }
68
69 @Override
70 public String toString() {
71 return "[DeviceEvent " + mac + " attachmentPoints:" + attachmentPoints + " ipAddr:" + ipAddresses + "]";
72 }
73
74
75}