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 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 3 | import java.util.Collections; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 4 | import java.util.LinkedList; |
5 | |||||
6 | import net.floodlightcontroller.util.MACAddress; | ||||
7 | |||||
8 | /** | ||||
Yuta HIGUCHI | d4acc80 | 2014-06-19 22:30:31 -0700 | [diff] [blame] | 9 | * Device Object stored in In-memory Topology. |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 10 | */ |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 11 | public class DeviceImpl extends TopologyObject implements Device { |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 12 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 13 | private final MACAddress macAddr; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 14 | protected LinkedList<Port> attachmentPoints; |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 15 | private long lastSeenTime; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 16 | |
Jonathan Hart | e37e4e2 | 2014-05-13 19:12:02 -0700 | [diff] [blame] | 17 | public DeviceImpl(Topology topology, MACAddress mac) { |
18 | super(topology); | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | this.macAddr = mac; |
20 | this.attachmentPoints = new LinkedList<>(); | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 21 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 22 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 23 | @Override |
24 | public MACAddress getMacAddress() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 25 | return this.macAddr; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 26 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 27 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 28 | @Override |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 29 | public Iterable<Port> getAttachmentPoints() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 30 | return Collections.unmodifiableList(this.attachmentPoints); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 31 | } |
32 | |||||
33 | @Override | ||||
34 | public long getLastSeenTime() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 35 | return lastSeenTime; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 36 | } |
37 | |||||
38 | @Override | ||||
39 | public String toString() { | ||||
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 40 | return macAddr.toString(); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 41 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 43 | void setLastSeenTime(long lastSeenTime) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | this.lastSeenTime = lastSeenTime; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 45 | } |
46 | |||||
47 | /** | ||||
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 48 | * Only {@link TopologyManager} should use this method. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 49 | * |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 50 | * @param port the port that the device is attached to |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 51 | */ |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 52 | void addAttachmentPoint(Port port) { |
53 | this.attachmentPoints.remove(port); | ||||
54 | this.attachmentPoints.addFirst(port); | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 55 | } |
56 | |||||
57 | /** | ||||
Ray Milkey | b41100a | 2014-04-10 10:42:15 -0700 | [diff] [blame] | 58 | * Only {@link TopologyManager} should use this method. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | * |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 60 | * @param port the port that the device is attached to |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 61 | */ |
TeruU | 5d2c939 | 2014-06-09 20:02:02 -0700 | [diff] [blame] | 62 | boolean removeAttachmentPoint(Port port) { |
63 | return this.attachmentPoints.remove(port); | ||||
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 64 | } |
Praseed Balakrishnan | 57ed843 | 2014-06-26 11:49:56 -0700 | [diff] [blame^] | 65 | |
66 | |||||
67 | /** | ||||
68 | * Returns the type of topology object. | ||||
69 | * | ||||
70 | * @return the type of the topology object | ||||
71 | */ | ||||
72 | @Override | ||||
73 | public String getType() { | ||||
74 | throw new UnsupportedOperationException("Not implemented yet"); | ||||
75 | } | ||||
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 76 | } |