blob: f6823a9e492101fcc4ecb94483faeaa10abce25f [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net;
tomb36046e2014-08-27 00:22:24 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import static org.onosproject.net.PortNumber.P0;
tom545708e2014-10-09 17:10:02 -070019
tomb36046e2014-08-27 00:22:24 -070020/**
21 * Representation of a network edge location where an end-station host is
22 * connected.
23 */
tombb58c202014-09-07 22:51:50 -070024public class HostLocation extends ConnectPoint {
25
tom545708e2014-10-09 17:10:02 -070026 /**
27 * Represents a no location or an unknown location.
28 */
29 public static final HostLocation NONE = new HostLocation(DeviceId.NONE, P0, 0L);
30
toma56d5fe2014-09-17 11:05:47 -070031 // Note that time is explicitly excluded from the notion of equality.
tombb58c202014-09-07 22:51:50 -070032 private final long time;
33
tomf5d85d42014-10-02 05:27:56 -070034 /**
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 */
tombb58c202014-09-07 22:51:50 -070041 public HostLocation(DeviceId deviceId, PortNumber portNumber, long time) {
42 super(deviceId, portNumber);
43 this.time = time;
44 }
tomb36046e2014-08-27 00:22:24 -070045
46 /**
tom297dfc02014-10-08 10:42:56 -070047 * 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 /**
tomf5d85d42014-10-02 05:27:56 -070058 * Returns the time when the location was established, given in
tomb36046e2014-08-27 00:22:24 -070059 * milliseconds since start of epoch.
60 *
tomf5d85d42014-10-02 05:27:56 -070061 * @return time in milliseconds since start of epoch
tomb36046e2014-08-27 00:22:24 -070062 */
tombb58c202014-09-07 22:51:50 -070063 public long time() {
64 return time;
65 }
66
Charles Chancd06c692017-04-27 20:46:06 -070067 @Override
68 public String toString() {
69 return deviceId() + "/" + port();
70 }
tomb36046e2014-08-27 00:22:24 -070071}