blob: 28a7796125af1a0f7c19ac3e0d3588716b342e41 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Toshio Koide5799b602014-02-10 15:29:06 -08002
3import java.net.InetAddress;
4import java.util.Collection;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -08005import java.util.Collections;
6import java.util.HashSet;
Toshio Koide5799b602014-02-10 15:29:06 -08007import java.util.LinkedList;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -08008import java.util.Set;
Toshio Koide5799b602014-02-10 15:29:06 -08009
10import net.floodlightcontroller.util.MACAddress;
11
12/**
13 * @author Toshio Koide (t-koide@onlab.us)
14 */
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080015public class DeviceImpl extends NetworkGraphObject implements Device {
Toshio Koide5799b602014-02-10 15:29:06 -080016
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080017 private final MACAddress macAddr;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080018 protected LinkedList<Port> attachmentPoints;
19 protected Set<InetAddress> ipAddresses;
TeruUd1c5b652014-03-24 13:58:46 -070020 private long lastSeenTime;
Toshio Koide5799b602014-02-10 15:29:06 -080021
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080022 public DeviceImpl(NetworkGraph graph, MACAddress mac) {
Ray Milkey269ffb92014-04-03 14:43:30 -070023 super(graph);
24 this.macAddr = mac;
25 this.attachmentPoints = new LinkedList<>();
26 this.ipAddresses = new HashSet<>();
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080027 }
Toshio Koide5799b602014-02-10 15:29:06 -080028
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080029 @Override
30 public MACAddress getMacAddress() {
Ray Milkey269ffb92014-04-03 14:43:30 -070031 return this.macAddr;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080032 }
Toshio Koide5799b602014-02-10 15:29:06 -080033
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080034 @Override
35 public Collection<InetAddress> getIpAddress() {
Ray Milkey269ffb92014-04-03 14:43:30 -070036 return Collections.unmodifiableSet(ipAddresses);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080037 }
38
39 @Override
40 public Iterable<Port> getAttachmentPoints() {
Ray Milkey269ffb92014-04-03 14:43:30 -070041 return Collections.unmodifiableList(this.attachmentPoints);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080042 }
43
44 @Override
45 public long getLastSeenTime() {
Ray Milkey269ffb92014-04-03 14:43:30 -070046 return lastSeenTime;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080047 }
48
49 @Override
50 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070051 return macAddr.toString();
TeruUd1c5b652014-03-24 13:58:46 -070052 }
Ray Milkey269ffb92014-04-03 14:43:30 -070053
TeruUd1c5b652014-03-24 13:58:46 -070054 void setLastSeenTime(long lastSeenTime) {
Ray Milkey269ffb92014-04-03 14:43:30 -070055 this.lastSeenTime = lastSeenTime;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080056 }
57
58 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070059 * Only {@link TopologyManager} should use this method.
Ray Milkey269ffb92014-04-03 14:43:30 -070060 *
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080061 * @param p
62 */
63 void addAttachmentPoint(Port p) {
Ray Milkey269ffb92014-04-03 14:43:30 -070064 this.attachmentPoints.remove(p);
65 this.attachmentPoints.addFirst(p);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080066 }
67
68 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070069 * Only {@link TopologyManager} should use this method.
Ray Milkey269ffb92014-04-03 14:43:30 -070070 *
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080071 * @param p
72 */
73 boolean removeAttachmentPoint(Port p) {
Ray Milkey269ffb92014-04-03 14:43:30 -070074 return this.attachmentPoints.remove(p);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080075 }
76
77 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070078 * Only {@link TopologyManager} should use this method.
Ray Milkey269ffb92014-04-03 14:43:30 -070079 *
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080080 * @param p
81 */
82 boolean addIpAddress(InetAddress addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -070083 return this.ipAddresses.add(addr);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080084 }
85
86 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070087 * Only {@link TopologyManager} should use this method.
Ray Milkey269ffb92014-04-03 14:43:30 -070088 *
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080089 * @param p
90 */
91 boolean removeIpAddress(InetAddress addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -070092 return this.ipAddresses.remove(addr);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080093 }
Toshio Koide5799b602014-02-10 15:29:06 -080094}