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 | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame] | 6 | import static com.google.common.base.Preconditions.checkNotNull; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 7 | import net.floodlightcontroller.util.MACAddress; |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.util.SwitchPort; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 9 | |
| 10 | /** |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 11 | * Handler to Host object stored in In-memory Topology snapshot. |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 12 | */ |
Yuta HIGUCHI | bfc77f0 | 2014-07-14 22:50:25 -0700 | [diff] [blame] | 13 | public class HostImpl extends TopologyObject implements Host { |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 14 | |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 15 | private final MACAddress id; |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 16 | |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 19 | * Creates a Host handler object. |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 20 | * |
| 21 | * @param topology Topology instance this object belongs to |
| 22 | * @param mac MAC address of the host |
| 23 | */ |
Yuta HIGUCHI | 9e6223d | 2014-08-26 00:01:32 -0700 | [diff] [blame] | 24 | HostImpl(BaseInternalTopology topology, MACAddress mac) { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 25 | super(topology); |
Pavlin Radoslavov | a5637c0 | 2014-07-30 15:55:11 -0700 | [diff] [blame] | 26 | this.id = checkNotNull(mac); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 27 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 28 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 29 | @Override |
| 30 | public MACAddress getMacAddress() { |
Yuta HIGUCHI | 8b389a7 | 2014-07-18 13:50:00 -0700 | [diff] [blame] | 31 | return id; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 32 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 33 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 34 | @Override |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 35 | public Iterable<Port> getAttachmentPoints() { |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 36 | List<Port> ports = new ArrayList<>(); |
Yuta HIGUCHI | 9e6223d | 2014-08-26 00:01:32 -0700 | [diff] [blame] | 37 | final BaseTopologyAdaptor topo = new BaseTopologyAdaptor(topology); |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 38 | for (SwitchPort swp : getHostData().getAttachmentPoints()) { |
Yuta HIGUCHI | 9e6223d | 2014-08-26 00:01:32 -0700 | [diff] [blame] | 39 | Port port = topo.getPort(swp); |
| 40 | if (port != null) { |
| 41 | ports.add(port); |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 42 | } |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 43 | } |
| 44 | return ports; |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public long getLastSeenTime() { |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 49 | return this.topology.getHostData(id).getLastSeenTime(); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public String toString() { |
Yuta HIGUCHI | bf0a871 | 2014-06-30 18:59:46 -0700 | [diff] [blame] | 54 | return getMacAddress().toString(); |
TeruU | d1c5b65 | 2014-03-24 13:58:46 -0700 | [diff] [blame] | 55 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 56 | |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 57 | /** |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 58 | * Gets the current HostData. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | * |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 60 | * @return HostData |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 61 | */ |
Yuta HIGUCHI | 93d35ea | 2014-08-31 23:26:13 -0700 | [diff] [blame] | 62 | private HostData getHostData() { |
| 63 | return this.topology.getHostData(id); |
Yuta HIGUCHI | c036627 | 2014-02-10 21:04:57 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
Praseed Balakrishnan | 57ed843 | 2014-06-26 11:49:56 -0700 | [diff] [blame] | 67 | * Returns the type of topology object. |
| 68 | * |
| 69 | * @return the type of the topology object |
| 70 | */ |
| 71 | @Override |
| 72 | public String getType() { |
Pavlin Radoslavov | 53b208a | 2014-07-28 13:16:11 -0700 | [diff] [blame] | 73 | // FIXME assuming Host is always in packet layer for now. |
Yuta HIGUCHI | dbc3312 | 2014-07-10 13:32:32 -0700 | [diff] [blame] | 74 | return TopologyElement.TYPE_PACKET_LAYER; |
Praseed Balakrishnan | 57ed843 | 2014-06-26 11:49:56 -0700 | [diff] [blame] | 75 | } |
Praseed Balakrishnan | 2aa6c0b | 2014-07-17 11:42:05 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Returns the config state of topology element. |
| 79 | * |
| 80 | * @return ConfigState |
| 81 | */ |
| 82 | @Override |
| 83 | public ConfigState getConfigState() { |
| 84 | return ConfigState.NOT_CONFIGURED; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Returns the status of topology element. |
| 89 | * |
| 90 | * @return AdminStatus |
| 91 | */ |
| 92 | @Override |
| 93 | public AdminStatus getStatus() { |
| 94 | return AdminStatus.ACTIVE; |
| 95 | } |
Toshio Koide | 5799b60 | 2014-02-10 15:29:06 -0800 | [diff] [blame] | 96 | } |