Jonathan Hart | 472062d | 2014-04-03 10:56:48 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.topology; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 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; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 18 | protected LinkedList<Port> attachmentPoints; |
19 | protected Set<InetAddress> ipAddresses; | ||||
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 20 | private long lastSeenTime; |
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) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 23 | super(graph); |
24 | this.macAddr = mac; | ||||
25 | this.attachmentPoints = new LinkedList<>(); | ||||
26 | this.ipAddresses = new HashSet<>(); | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 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() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | return this.macAddr; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 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() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 36 | return Collections.unmodifiableSet(ipAddresses); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 37 | } |
38 | |||||
39 | @Override | ||||
40 | public Iterable<Port> getAttachmentPoints() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | return Collections.unmodifiableList(this.attachmentPoints); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 42 | } |
43 | |||||
44 | @Override | ||||
45 | public long getLastSeenTime() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 46 | return lastSeenTime; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 47 | } |
48 | |||||
49 | @Override | ||||
50 | public String toString() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | return macAddr.toString(); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 52 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 53 | |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 54 | void setLastSeenTime(long lastSeenTime) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | this.lastSeenTime = lastSeenTime; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 56 | } |
57 | |||||
58 | /** | ||||
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 59 | * Only {@link TopologyManager} should use this method. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 60 | * |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 61 | * @param p |
62 | */ | ||||
63 | void addAttachmentPoint(Port p) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | this.attachmentPoints.remove(p); |
65 | this.attachmentPoints.addFirst(p); | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 66 | } |
67 | |||||
68 | /** | ||||
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 69 | * Only {@link TopologyManager} should use this method. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 70 | * |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 71 | * @param p |
72 | */ | ||||
73 | boolean removeAttachmentPoint(Port p) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 74 | return this.attachmentPoints.remove(p); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 75 | } |
76 | |||||
77 | /** | ||||
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 78 | * Only {@link TopologyManager} should use this method. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 79 | * |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 80 | * @param p |
81 | */ | ||||
82 | boolean addIpAddress(InetAddress addr) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 83 | return this.ipAddresses.add(addr); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 84 | } |
85 | |||||
86 | /** | ||||
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 87 | * Only {@link TopologyManager} should use this method. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | * |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 89 | * @param p |
90 | */ | ||||
91 | boolean removeIpAddress(InetAddress addr) { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | return this.ipAddresses.remove(addr); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 93 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 94 | } |