blob: 7370be0e4a8398ceca151e4d48f2343c921a4dd9 [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 HIGUCHIbf0a8712014-06-30 18:59:46 -07003import java.util.ArrayList;
4import java.util.List;
5
Pavlin Radoslavova5637c02014-07-30 15:55:11 -07006import static com.google.common.base.Preconditions.checkNotNull;
Toshio Koide5799b602014-02-10 15:29:06 -08007
8import net.floodlightcontroller.util.MACAddress;
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -07009import net.onrc.onos.core.util.SwitchPort;
Toshio Koide5799b602014-02-10 15:29:06 -080010
11/**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070012 * Handler to Host object stored in In-memory Topology snapshot.
13 * <p/>
Toshio Koide5799b602014-02-10 15:29:06 -080014 */
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070015public class HostImpl extends TopologyObject implements Host {
Toshio Koide5799b602014-02-10 15:29:06 -080016
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070017 private final MACAddress id;
Toshio Koide5799b602014-02-10 15:29:06 -080018
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070019
20 /**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070021 * Creates a Host handler object.
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070022 *
23 * @param topology Topology instance this object belongs to
24 * @param mac MAC address of the host
25 */
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070026 HostImpl(TopologyInternal topology, MACAddress mac) {
27 super(topology);
Pavlin Radoslavova5637c02014-07-30 15:55:11 -070028 this.id = checkNotNull(mac);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080029 }
Toshio Koide5799b602014-02-10 15:29:06 -080030
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080031 @Override
32 public MACAddress getMacAddress() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070033 return id;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080034 }
Toshio Koide5799b602014-02-10 15:29:06 -080035
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080036 @Override
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080037 public Iterable<Port> getAttachmentPoints() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070038 List<Port> ports = new ArrayList<>();
39 topology.acquireReadLock();
40 try {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070041 for (SwitchPort swp : getHostEvent().getAttachmentPoints()) {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070042 Port p = this.topology.getPort(swp);
43 if (p != null) {
44 ports.add(p);
45 }
46 }
47 } finally {
48 topology.releaseReadLock();
49 }
50 return ports;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080051 }
52
53 @Override
54 public long getLastSeenTime() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070055 return this.topology.getHostEvent(id).getLastSeenTime();
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080056 }
57
58 @Override
59 public String toString() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070060 return getMacAddress().toString();
TeruUd1c5b652014-03-24 13:58:46 -070061 }
Ray Milkey269ffb92014-04-03 14:43:30 -070062
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080063 /**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070064 * Gets the current HostEvent.
Ray Milkey269ffb92014-04-03 14:43:30 -070065 *
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070066 * @return HostEvent
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080067 */
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070068 private HostEvent getHostEvent() {
69 return this.topology.getHostEvent(id);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080070 }
71
72 /**
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070073 * Returns the type of topology object.
74 *
75 * @return the type of the topology object
76 */
77 @Override
78 public String getType() {
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070079 // FIXME assuming Host is always in packet layer for now.
Yuta HIGUCHIdbc33122014-07-10 13:32:32 -070080 return TopologyElement.TYPE_PACKET_LAYER;
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070081 }
Praseed Balakrishnan2aa6c0b2014-07-17 11:42:05 -070082
83 /**
84 * Returns the config state of topology element.
85 *
86 * @return ConfigState
87 */
88 @Override
89 public ConfigState getConfigState() {
90 return ConfigState.NOT_CONFIGURED;
91 }
92
93 /**
94 * Returns the status of topology element.
95 *
96 * @return AdminStatus
97 */
98 @Override
99 public AdminStatus getStatus() {
100 return AdminStatus.ACTIVE;
101 }
Toshio Koide5799b602014-02-10 15:29:06 -0800102}