Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
| 3 | import java.net.InetAddress; |
| 4 | import java.util.HashSet; |
| 5 | import java.util.LinkedList; |
| 6 | import java.util.List; |
| 7 | import java.util.Set; |
| 8 | |
| 9 | import net.floodlightcontroller.util.MACAddress; |
| 10 | import net.onrc.onos.ofcontroller.networkgraph.PortEvent.SwitchPort; |
| 11 | |
| 12 | /** |
Yuta HIGUCHI | 8d762e9 | 2014-02-12 14:10:25 -0800 | [diff] [blame] | 13 | * 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 HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 21 | * |
| 22 | * TODO: We probably want common base class/interface for Self-Contained Event Object |
| 23 | * |
| 24 | */ |
| 25 | public class DeviceEvent { |
| 26 | private final MACAddress mac; |
| 27 | protected List<SwitchPort> attachmentPoints; |
| 28 | protected Set<InetAddress> ipAddresses; |
| 29 | |
| 30 | public DeviceEvent(MACAddress mac) { |
Yuta HIGUCHI | 8d762e9 | 2014-02-12 14:10:25 -0800 | [diff] [blame] | 31 | if (mac == null) { |
| 32 | throw new IllegalArgumentException("Device mac cannot be null"); |
| 33 | } |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 34 | 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 HIGUCHI | 8d762e9 | 2014-02-12 14:10:25 -0800 | [diff] [blame] | 47 | public Set<InetAddress> getIpAddresses() { |
| 48 | return ipAddresses; |
| 49 | } |
| 50 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 51 | public void setAttachmentPoints(List<SwitchPort> attachmentPoints) { |
| 52 | this.attachmentPoints = attachmentPoints; |
| 53 | } |
| 54 | |
Yuta HIGUCHI | 8d762e9 | 2014-02-12 14:10:25 -0800 | [diff] [blame] | 55 | public void addAttachmentPoint(SwitchPort attachmentPoint) { |
| 56 | // may need to maintain uniqness |
| 57 | this.attachmentPoints.add(0, attachmentPoint); |
| 58 | } |
| 59 | |
| 60 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 61 | 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 | } |