blob: 10238065fda99cf538d75605260a4d4fbb65efa9 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Toshio Koide5799b602014-02-10 15:29:06 -08002
Sangho Shin2f263692014-09-15 14:09:41 -07003import static com.google.common.base.Preconditions.checkNotNull;
4
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -07005import java.util.ArrayList;
6import java.util.List;
7
Toshio Koide5799b602014-02-10 15:29:06 -08008import 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.
Toshio Koide5799b602014-02-10 15:29:06 -080013 */
Yuta HIGUCHIbfc77f02014-07-14 22:50:25 -070014public class HostImpl extends TopologyObject implements Host {
Toshio Koide5799b602014-02-10 15:29:06 -080015
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070016 private final MACAddress id;
Sangho Shin2f263692014-09-15 14:09:41 -070017 private final int ipAddress;
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 HIGUCHI9e6223d2014-08-26 00:01:32 -070026 HostImpl(BaseInternalTopology topology, MACAddress mac) {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070027 super(topology);
Pavlin Radoslavova5637c02014-07-30 15:55:11 -070028 this.id = checkNotNull(mac);
Sangho Shin2f263692014-09-15 14:09:41 -070029 this.ipAddress = 0;
30 }
31
32 /**
33 * Creates a Host handler object.
34 *
35 * @param topology Topology instance this object belongs to
36 * @param mac MAC address of the host
37 * @param ipv4Address IP address of ths host
38 */
39 HostImpl(BaseInternalTopology topology, MACAddress mac, int ipv4Address) {
40 super(topology);
41 this.id = checkNotNull(mac);
42 this.ipAddress = ipv4Address;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080043 }
Toshio Koide5799b602014-02-10 15:29:06 -080044
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080045 @Override
46 public MACAddress getMacAddress() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070047 return id;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080048 }
Toshio Koide5799b602014-02-10 15:29:06 -080049
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080050 @Override
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080051 public Iterable<Port> getAttachmentPoints() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070052 List<Port> ports = new ArrayList<>();
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070053 final BaseTopologyAdaptor topo = new BaseTopologyAdaptor(topology);
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070054 for (SwitchPort swp : getHostData().getAttachmentPoints()) {
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070055 Port port = topo.getPort(swp);
56 if (port != null) {
57 ports.add(port);
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070058 }
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070059 }
60 return ports;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080061 }
62
63 @Override
64 public long getLastSeenTime() {
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070065 return this.topology.getHostData(id).getLastSeenTime();
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080066 }
67
68 @Override
69 public String toString() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070070 return getMacAddress().toString();
TeruUd1c5b652014-03-24 13:58:46 -070071 }
Ray Milkey269ffb92014-04-03 14:43:30 -070072
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080073 /**
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070074 * Gets the current HostData.
Ray Milkey269ffb92014-04-03 14:43:30 -070075 *
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070076 * @return HostData
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080077 */
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070078 private HostData getHostData() {
79 return this.topology.getHostData(id);
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080080 }
81
82 /**
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070083 * Returns the type of topology object.
84 *
85 * @return the type of the topology object
86 */
87 @Override
88 public String getType() {
Pavlin Radoslavov53b208a2014-07-28 13:16:11 -070089 // FIXME assuming Host is always in packet layer for now.
Yuta HIGUCHIdbc33122014-07-10 13:32:32 -070090 return TopologyElement.TYPE_PACKET_LAYER;
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070091 }
Praseed Balakrishnan2aa6c0b2014-07-17 11:42:05 -070092
93 /**
94 * Returns the config state of topology element.
95 *
96 * @return ConfigState
97 */
98 @Override
99 public ConfigState getConfigState() {
100 return ConfigState.NOT_CONFIGURED;
101 }
102
103 /**
104 * Returns the status of topology element.
105 *
106 * @return AdminStatus
107 */
108 @Override
109 public AdminStatus getStatus() {
110 return AdminStatus.ACTIVE;
111 }
Sangho Shin2f263692014-09-15 14:09:41 -0700112
113
114 /**
115 * Returns the IP address of the Host
116 */
117 @Override
118 public int getIpAddress() {
119 // TODO Auto-generated method stub
120 return ipAddress;
121 }
Toshio Koide5799b602014-02-10 15:29:06 -0800122}