blob: d070570369ca75c2fcc7fbbcd8507bdc3e7b8ca7 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Toshio Koide5799b602014-02-10 15:29:06 -08002
Yuta HIGUCHIc0366272014-02-10 21:04:57 -08003import java.util.Collections;
Toshio Koide5799b602014-02-10 15:29:06 -08004import java.util.LinkedList;
5
6import net.floodlightcontroller.util.MACAddress;
7
8/**
9 * @author Toshio Koide (t-koide@onlab.us)
10 */
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080011public class DeviceImpl extends NetworkGraphObject implements Device {
Toshio Koide5799b602014-02-10 15:29:06 -080012
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080013 private final MACAddress macAddr;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080014 protected LinkedList<Port> attachmentPoints;
TeruUd1c5b652014-03-24 13:58:46 -070015 private long lastSeenTime;
Toshio Koide5799b602014-02-10 15:29:06 -080016
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080017 public DeviceImpl(NetworkGraph graph, MACAddress mac) {
Ray Milkey269ffb92014-04-03 14:43:30 -070018 super(graph);
19 this.macAddr = mac;
20 this.attachmentPoints = new LinkedList<>();
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080021 }
Toshio Koide5799b602014-02-10 15:29:06 -080022
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080023 @Override
24 public MACAddress getMacAddress() {
Ray Milkey269ffb92014-04-03 14:43:30 -070025 return this.macAddr;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080026 }
Toshio Koide5799b602014-02-10 15:29:06 -080027
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080028 @Override
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080029 public Iterable<Port> getAttachmentPoints() {
Ray Milkey269ffb92014-04-03 14:43:30 -070030 return Collections.unmodifiableList(this.attachmentPoints);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080031 }
32
33 @Override
34 public long getLastSeenTime() {
Ray Milkey269ffb92014-04-03 14:43:30 -070035 return lastSeenTime;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080036 }
37
38 @Override
39 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070040 return macAddr.toString();
TeruUd1c5b652014-03-24 13:58:46 -070041 }
Ray Milkey269ffb92014-04-03 14:43:30 -070042
TeruUd1c5b652014-03-24 13:58:46 -070043 void setLastSeenTime(long lastSeenTime) {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 this.lastSeenTime = lastSeenTime;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080045 }
46
47 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070048 * Only {@link TopologyManager} should use this method.
Ray Milkey269ffb92014-04-03 14:43:30 -070049 *
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080050 * @param p
51 */
52 void addAttachmentPoint(Port p) {
Ray Milkey269ffb92014-04-03 14:43:30 -070053 this.attachmentPoints.remove(p);
54 this.attachmentPoints.addFirst(p);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080055 }
56
57 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070058 * Only {@link TopologyManager} should use this method.
Ray Milkey269ffb92014-04-03 14:43:30 -070059 *
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080060 * @param p
61 */
62 boolean removeAttachmentPoint(Port p) {
Ray Milkey269ffb92014-04-03 14:43:30 -070063 return this.attachmentPoints.remove(p);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080064 }
Toshio Koide5799b602014-02-10 15:29:06 -080065}