Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import static org.onosproject.net.PortNumber.P0; |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 19 | |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Representation of a network edge location where an end-station host is |
| 22 | * connected. |
| 23 | */ |
tom | bb58c20 | 2014-09-07 22:51:50 -0700 | [diff] [blame] | 24 | public class HostLocation extends ConnectPoint { |
| 25 | |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Represents a no location or an unknown location. |
| 28 | */ |
| 29 | public static final HostLocation NONE = new HostLocation(DeviceId.NONE, P0, 0L); |
| 30 | |
tom | a56d5fe | 2014-09-17 11:05:47 -0700 | [diff] [blame] | 31 | // Note that time is explicitly excluded from the notion of equality. |
tom | bb58c20 | 2014-09-07 22:51:50 -0700 | [diff] [blame] | 32 | private final long time; |
| 33 | |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Creates a new host location using the supplied device & port. |
| 36 | * |
| 37 | * @param deviceId device identity |
| 38 | * @param portNumber device port number |
| 39 | * @param time time when detected, in millis since start of epoch |
| 40 | */ |
tom | bb58c20 | 2014-09-07 22:51:50 -0700 | [diff] [blame] | 41 | public HostLocation(DeviceId deviceId, PortNumber portNumber, long time) { |
| 42 | super(deviceId, portNumber); |
| 43 | this.time = time; |
| 44 | } |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
tom | 297dfc0 | 2014-10-08 10:42:56 -0700 | [diff] [blame] | 47 | * Creates a new host location derived from the supplied connection point. |
| 48 | * |
| 49 | * @param connectPoint connection point |
| 50 | * @param time time when detected, in millis since start of epoch |
| 51 | */ |
| 52 | public HostLocation(ConnectPoint connectPoint, long time) { |
| 53 | super(connectPoint.deviceId(), connectPoint.port()); |
| 54 | this.time = time; |
| 55 | } |
| 56 | |
| 57 | /** |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 58 | * Returns the time when the location was established, given in |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 59 | * milliseconds since start of epoch. |
| 60 | * |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 61 | * @return time in milliseconds since start of epoch |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 62 | */ |
tom | bb58c20 | 2014-09-07 22:51:50 -0700 | [diff] [blame] | 63 | public long time() { |
| 64 | return time; |
| 65 | } |
| 66 | |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 67 | @Override |
| 68 | public String toString() { |
| 69 | return deviceId() + "/" + port(); |
| 70 | } |
tom | b36046e | 2014-08-27 00:22:24 -0700 | [diff] [blame] | 71 | } |