Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 16 | package org.onlab.packet; |
| 17 | |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 18 | import org.onlab.util.Identifier; |
| 19 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 20 | /** |
| 21 | * The class representing a network device chassisId. |
| 22 | * This class is immutable. |
| 23 | */ |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 24 | public final class ChassisId extends Identifier<Long> { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 25 | |
| 26 | private static final long UNKNOWN = 0; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Default constructor. |
| 30 | */ |
| 31 | public ChassisId() { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 32 | super(ChassisId.UNKNOWN); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Constructor from a long value. |
| 37 | * |
| 38 | * @param value the value to use. |
| 39 | */ |
| 40 | public ChassisId(long value) { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 41 | super(value); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Constructor from a string. |
| 46 | * |
| 47 | * @param value the value to use. |
| 48 | */ |
| 49 | public ChassisId(String value) { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 50 | super(Long.parseLong(value, 16)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get the value of the chassis id. |
| 55 | * |
| 56 | * @return the value of the chassis id. |
| 57 | */ |
| 58 | public long value() { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 59 | return identifier; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Convert the Chassis Id value to a ':' separated hexadecimal string. |
| 64 | * |
| 65 | * @return the Chassis Id value as a ':' separated hexadecimal string. |
| 66 | */ |
| 67 | @Override |
| 68 | public String toString() { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 69 | return Long.toHexString(identifier); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 74 | return Long.hashCode(identifier); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 75 | } |
| 76 | } |