Carmelo Cascone | e4da909 | 2016-04-26 12:14:08 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.bmv2.api.runtime; |
| 18 | |
| 19 | import com.google.common.base.Objects; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * Representation of a BMv2 device. |
| 25 | */ |
| 26 | public final class Bmv2Device { |
| 27 | |
| 28 | private final String thriftServerHost; |
| 29 | private final int thriftServerPort; |
| 30 | private final int internalDeviceId; |
| 31 | |
| 32 | /** |
| 33 | * Creates a new Bmv2 device object. |
| 34 | * |
| 35 | * @param thriftServerHost the host of the Thrift runtime server running inside the device |
| 36 | * @param thriftServerPort the port of the Thrift runtime server running inside the device |
| 37 | * @param internalDeviceId the internal device id |
| 38 | */ |
| 39 | public Bmv2Device(String thriftServerHost, int thriftServerPort, int internalDeviceId) { |
| 40 | this.thriftServerHost = checkNotNull(thriftServerHost, "host cannot be null"); |
| 41 | this.thriftServerPort = checkNotNull(thriftServerPort, "port cannot be null"); |
| 42 | this.internalDeviceId = internalDeviceId; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the hostname (or IP address) of the Thrift runtime server running inside the device. |
| 47 | * |
| 48 | * @return a string value |
| 49 | */ |
| 50 | public String thriftServerHost() { |
| 51 | return thriftServerHost; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Returns the port of the Thrift runtime server running inside the device. |
| 56 | * |
| 57 | * @return an integer value |
| 58 | */ |
| 59 | public int thriftServerPort() { |
| 60 | return thriftServerPort; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Returns the BMv2-internal device ID, which is an integer arbitrary chosen at device boot. |
| 65 | * Such an ID must not be confused with the ONOS-internal {@link org.onosproject.net.DeviceId}. |
| 66 | * |
| 67 | * @return an integer value |
| 68 | */ |
| 69 | public int getInternalDeviceId() { |
| 70 | return internalDeviceId; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int hashCode() { |
| 75 | return Objects.hashCode(thriftServerHost, thriftServerPort, internalDeviceId); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object obj) { |
| 80 | if (this == obj) { |
| 81 | return true; |
| 82 | } |
| 83 | if (obj == null || getClass() != obj.getClass()) { |
| 84 | return false; |
| 85 | } |
| 86 | final Bmv2Device other = (Bmv2Device) obj; |
| 87 | return Objects.equal(this.thriftServerHost, other.thriftServerHost) |
| 88 | && Objects.equal(this.thriftServerPort, other.thriftServerPort) |
| 89 | && Objects.equal(this.internalDeviceId, other.internalDeviceId); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return thriftServerHost + ":" + thriftServerPort + "/" + internalDeviceId; |
| 95 | } |
| 96 | } |