blob: 31200151a36e5012060d7ffc24105cf9fd1247a8 [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
6import org.apache.commons.lang.Validate;
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);
28 Validate.notNull(mac);
29 this.id = mac;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080030 }
Toshio Koide5799b602014-02-10 15:29:06 -080031
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080032 @Override
33 public MACAddress getMacAddress() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070034 return id;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080035 }
Toshio Koide5799b602014-02-10 15:29:06 -080036
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080037 @Override
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080038 public Iterable<Port> getAttachmentPoints() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070039 List<Port> ports = new ArrayList<>();
40 topology.acquireReadLock();
41 try {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070042 for (SwitchPort swp : getHostEvent().getAttachmentPoints()) {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070043 Port p = this.topology.getPort(swp);
44 if (p != null) {
45 ports.add(p);
46 }
47 }
48 } finally {
49 topology.releaseReadLock();
50 }
51 return ports;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080052 }
53
54 @Override
55 public long getLastSeenTime() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070056 return this.topology.getHostEvent(id).getLastSeenTime();
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080057 }
58
59 @Override
60 public String toString() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070061 return getMacAddress().toString();
TeruUd1c5b652014-03-24 13:58:46 -070062 }
Ray Milkey269ffb92014-04-03 14:43:30 -070063
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080064 /**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070065 * Gets the current HostEvent.
Ray Milkey269ffb92014-04-03 14:43:30 -070066 *
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070067 * @return HostEvent
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080068 */
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070069 private HostEvent getHostEvent() {
70 return this.topology.getHostEvent(id);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080071 }
72
73 /**
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070074 * Returns the type of topology object.
75 *
76 * @return the type of the topology object
77 */
78 @Override
79 public String getType() {
Yuta HIGUCHI1222ac52014-07-09 16:50:28 -070080 // FIXME assuming device is always in packet layer for now.
Yuta HIGUCHIdbc33122014-07-10 13:32:32 -070081 return TopologyElement.TYPE_PACKET_LAYER;
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070082 }
Praseed Balakrishnan2aa6c0b2014-07-17 11:42:05 -070083
84 /**
85 * Returns the config state of topology element.
86 *
87 * @return ConfigState
88 */
89 @Override
90 public ConfigState getConfigState() {
91 return ConfigState.NOT_CONFIGURED;
92 }
93
94 /**
95 * Returns the status of topology element.
96 *
97 * @return AdminStatus
98 */
99 @Override
100 public AdminStatus getStatus() {
101 return AdminStatus.ACTIVE;
102 }
Toshio Koide5799b602014-02-10 15:29:06 -0800103}