Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [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 | */ |
| 16 | package org.onosproject.net; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | |
| 20 | import java.util.Arrays; |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import org.onlab.util.HexString; |
| 24 | |
| 25 | import com.google.common.base.MoreObjects; |
| 26 | /** |
| 27 | * Implementation of ODU Signal ID. |
| 28 | * |
| 29 | * <p> |
| 30 | * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)". |
| 31 | * </p> |
| 32 | */ |
| 33 | public class OduSignalId { |
| 34 | |
| 35 | private final int tributaryPortNumber; // Tributary Port number |
| 36 | private final int tributarySlotLength; // Number of Tributary Slots included in tsmap |
| 37 | private final byte[] tributarySlotBitmap; // Tributary slot bitmap |
| 38 | |
| 39 | public static final int TRIBUTARY_SLOT_BITMAP_SIZE = 10; |
| 40 | |
| 41 | /** |
| 42 | * Creates an instance with the specified arguments. |
| 43 | * |
| 44 | * @param tributaryPortNumber tributary port number |
| 45 | * @param tributarySlotLen tributary slot len |
| 46 | * @param tributarySlotBitmap tributary slot bitmap |
| 47 | */ |
| 48 | public OduSignalId(int tributaryPortNumber, int tributarySlotLen, |
| 49 | byte[] tributarySlotBitmap) { |
| 50 | |
Jian Li | 68c4fc4 | 2016-01-11 16:07:03 -0800 | [diff] [blame] | 51 | checkArgument(tributaryPortNumber <= 80, |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 52 | "tributaryPortNumber %s must be <= 80 ", |
| 53 | tributaryPortNumber); |
| 54 | |
| 55 | checkArgument(tributarySlotBitmap.length == TRIBUTARY_SLOT_BITMAP_SIZE, |
| 56 | "number of elements in list " + HexString.toHexString(tributarySlotBitmap) |
| 57 | + " must be equal to " + TRIBUTARY_SLOT_BITMAP_SIZE); |
| 58 | |
Jian Li | 68c4fc4 | 2016-01-11 16:07:03 -0800 | [diff] [blame] | 59 | checkArgument(tributarySlotLen <= 80, |
Yafit Hadar | 52d8155 | 2015-10-07 12:26:52 +0300 | [diff] [blame] | 60 | "tributarySlotLen %s must be <= 80 ", |
| 61 | tributarySlotLen); |
| 62 | |
| 63 | this.tributaryPortNumber = tributaryPortNumber; |
| 64 | this.tributarySlotLength = tributarySlotLen; |
| 65 | this.tributarySlotBitmap = Arrays.copyOf(tributarySlotBitmap, tributarySlotBitmap.length); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the OduSignalId representing the specified parameters. |
| 70 | * |
| 71 | * @param tributaryPortNumber tributary port number |
| 72 | * @param tributarySlotLen tributary slot len |
| 73 | * @param tributarySlotBitmap tributary slot bitmap |
| 74 | * @return OduSignalId |
| 75 | */ |
| 76 | public static OduSignalId oduSignalId(int tributaryPortNumber, int tributarySlotLen, |
| 77 | byte[] tributarySlotBitmap) { |
| 78 | return new OduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | /** |
| 83 | * Returns tributary port number. |
| 84 | * |
| 85 | * @return the tributaryPortNumber |
| 86 | */ |
| 87 | public int tributaryPortNumber() { |
| 88 | return tributaryPortNumber; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns tributary slot length. |
| 93 | * |
| 94 | * @return the tributarySlotLen |
| 95 | */ |
| 96 | public int tributarySlotLength() { |
| 97 | return tributarySlotLength; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns tributary slot bitmap. |
| 102 | * |
| 103 | * @return the tributarySlotBitmap |
| 104 | */ |
| 105 | public byte[] tributarySlotBitmap() { |
| 106 | return Arrays.copyOf(tributarySlotBitmap, tributarySlotBitmap.length); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public int hashCode() { |
| 111 | return Objects.hash(tributaryPortNumber, tributarySlotLength, Arrays.hashCode(tributarySlotBitmap)); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public boolean equals(Object obj) { |
| 116 | if (this == obj) { |
| 117 | return true; |
| 118 | } |
| 119 | if (!(obj instanceof OduSignalId)) { |
| 120 | return false; |
| 121 | } |
| 122 | final OduSignalId other = (OduSignalId) obj; |
| 123 | return Objects.equals(this.tributaryPortNumber, other.tributaryPortNumber) |
| 124 | && Objects.equals(this.tributarySlotLength, other.tributarySlotLength) |
| 125 | && Arrays.equals(tributarySlotBitmap, other.tributarySlotBitmap); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public String toString() { |
| 130 | return MoreObjects.toStringHelper(this) |
| 131 | .omitNullValues() |
| 132 | .add("tributaryPortNumber", tributaryPortNumber) |
| 133 | .add("tributarySlotLength", tributarySlotLength) |
| 134 | .add("tributarySlotBitmap", HexString.toHexString(tributarySlotBitmap)) |
| 135 | .toString(); |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | |