blob: 2b8930b8ecfb66d976963d30bc59138b7a5a1693 [file] [log] [blame]
Toshio Koide5799b602014-02-10 15:29:06 -08001package net.onrc.onos.ofcontroller.networkgraph;
2
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;
Toshio Koide5799b602014-02-10 15:29:06 -080020
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080021 public DeviceImpl(NetworkGraph graph, MACAddress mac) {
22 super(graph);
23 this.macAddr = mac;
24 this.attachmentPoints = new LinkedList<>();
25 this.ipAddresses = new HashSet<>();
26 }
Toshio Koide5799b602014-02-10 15:29:06 -080027
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080028 @Override
29 public MACAddress getMacAddress() {
30 return this.macAddr;
31 }
Toshio Koide5799b602014-02-10 15:29:06 -080032
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080033 @Override
34 public Collection<InetAddress> getIpAddress() {
35 return Collections.unmodifiableSet(ipAddresses);
36 }
37
38 @Override
39 public Iterable<Port> getAttachmentPoints() {
40 return Collections.unmodifiableList(this.attachmentPoints);
41 }
42
43 @Override
44 public long getLastSeenTime() {
45 // TODO Auto-generated method stub
46 return 0;
47 }
48
49 @Override
50 public String toString() {
51 return macAddr.toString();
52 }
53
54 /**
Pavlin Radoslavovdb7dbb22014-02-18 14:45:10 -080055 * Only {@link TopologyManager} should use this method
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080056 * @param p
57 */
58 void addAttachmentPoint(Port p) {
59 this.attachmentPoints.remove(p);
60 this.attachmentPoints.addFirst(p);
61 }
62
63 /**
Pavlin Radoslavovdb7dbb22014-02-18 14:45:10 -080064 * Only {@link TopologyManager} should use this method
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080065 * @param p
66 */
67 boolean removeAttachmentPoint(Port p) {
68 return this.attachmentPoints.remove(p);
69 }
70
71 /**
Pavlin Radoslavovdb7dbb22014-02-18 14:45:10 -080072 * Only {@link TopologyManager} should use this method
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080073 * @param p
74 */
75 boolean addIpAddress(InetAddress addr) {
76 return this.ipAddresses.add(addr);
77 }
78
79 /**
Pavlin Radoslavovdb7dbb22014-02-18 14:45:10 -080080 * Only {@link TopologyManager} should use this method
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080081 * @param p
82 */
83 boolean removeIpAddress(InetAddress addr) {
84 return this.ipAddresses.remove(addr);
85 }
Toshio Koide5799b602014-02-10 15:29:06 -080086}