blob: 808d4a6aef41872b4a69547541e291b5b2e11393 [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;
18 // These should be ConcurrentCollecton if Graph is going to be
19 protected LinkedList<Port> attachmentPoints;
20 protected Set<InetAddress> ipAddresses;
Toshio Koide5799b602014-02-10 15:29:06 -080021
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080022 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 Koide5799b602014-02-10 15:29:06 -080028
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080029 @Override
30 public MACAddress getMacAddress() {
31 return this.macAddr;
32 }
Toshio Koide5799b602014-02-10 15:29:06 -080033
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080034 @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 Koide5799b602014-02-10 15:29:06 -080088}