Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
| 3 | import java.net.InetAddress; |
| 4 | import java.util.Collection; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 5 | import java.util.Collections; |
| 6 | import java.util.HashSet; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 7 | import java.util.LinkedList; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 8 | import java.util.Set; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 9 | |
| 10 | import net.floodlightcontroller.util.MACAddress; |
| 11 | |
| 12 | /** |
| 13 | * @author Toshio Koide (t-koide@onlab.us) |
| 14 | */ |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 15 | public class DeviceImpl extends NetworkGraphObject implements Device { |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 16 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 17 | private final MACAddress macAddr; |
| 18 | // These should be ConcurrentCollecton if Graph is going to be |
| 19 | protected LinkedList<Port> attachmentPoints; |
| 20 | protected Set<InetAddress> ipAddresses; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 21 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 22 | public DeviceImpl(NetworkGraph graph, MACAddress mac) { |
| 23 | super(graph); |
| 24 | this.macAddr = mac; |
| 25 | this.attachmentPoints = new LinkedList<>(); |
| 26 | this.ipAddresses = new HashSet<>(); |
| 27 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 28 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 29 | @Override |
| 30 | public MACAddress getMacAddress() { |
| 31 | return this.macAddr; |
| 32 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 33 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 34 | @Override |
| 35 | public Collection<InetAddress> getIpAddress() { |
| 36 | return Collections.unmodifiableSet(ipAddresses); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public Iterable<Port> getAttachmentPoints() { |
| 41 | return Collections.unmodifiableList(this.attachmentPoints); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public long getLastSeenTime() { |
| 46 | // TODO Auto-generated method stub |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String toString() { |
| 52 | return macAddr.toString(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Only {@link NetworkGraphImpl} should use this method |
| 57 | * @param p |
| 58 | */ |
| 59 | void addAttachmentPoint(Port p) { |
| 60 | this.attachmentPoints.remove(p); |
| 61 | this.attachmentPoints.addFirst(p); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Only {@link NetworkGraphImpl} should use this method |
| 66 | * @param p |
| 67 | */ |
| 68 | boolean removeAttachmentPoint(Port p) { |
| 69 | return this.attachmentPoints.remove(p); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Only {@link NetworkGraphImpl} should use this method |
| 74 | * @param p |
| 75 | */ |
| 76 | boolean addIpAddress(InetAddress addr) { |
| 77 | return this.ipAddresses.add(addr); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Only {@link NetworkGraphImpl} should use this method |
| 82 | * @param p |
| 83 | */ |
| 84 | boolean removeIpAddress(InetAddress addr) { |
| 85 | return this.ipAddresses.remove(addr); |
| 86 | } |
| 87 | |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 88 | } |