Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -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 | */ |
| 16 | package org.onosproject.net; |
| 17 | |
| 18 | import org.onlab.util.Frequency; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
Toru Furusawa | 0f5da69 | 2016-01-07 14:51:47 -0800 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Implementation of OMS port (Optical Multiplexing Section). |
| 27 | * Also referred to as a WDM port or W-port. |
| 28 | * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)" |
| 29 | * |
| 30 | * Assumes we only support fixed grid for now. |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 31 | * |
| 32 | * @deprecated in Goldeneye (1.6.0) |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 33 | */ |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 34 | @Deprecated |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 35 | public class OmsPort extends DefaultPort { |
| 36 | |
| 37 | private final Frequency minFrequency; // Minimum frequency |
| 38 | private final Frequency maxFrequency; // Maximum frequency |
| 39 | private final Frequency grid; // Grid spacing frequency |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * Creates an OMS port in the specified network element. |
| 44 | * |
| 45 | * @param element parent network element |
| 46 | * @param number port number |
| 47 | * @param isEnabled port enabled state |
| 48 | * @param minFrequency minimum frequency |
| 49 | * @param maxFrequency maximum frequency |
| 50 | * @param grid grid spacing frequency |
| 51 | * @param annotations optional key/value annotations |
| 52 | */ |
| 53 | public OmsPort(Element element, PortNumber number, boolean isEnabled, |
| 54 | Frequency minFrequency, Frequency maxFrequency, Frequency grid, Annotations... annotations) { |
| 55 | super(element, number, isEnabled, Type.OMS, 0, annotations); |
Toru Furusawa | 0f5da69 | 2016-01-07 14:51:47 -0800 | [diff] [blame] | 56 | this.minFrequency = checkNotNull(minFrequency); |
| 57 | this.maxFrequency = checkNotNull(maxFrequency); |
| 58 | this.grid = checkNotNull(grid); |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the total number of channels on the port. |
| 63 | * |
| 64 | * @return total number of channels |
| 65 | */ |
| 66 | public short totalChannels() { |
| 67 | Frequency diff = maxFrequency.subtract(minFrequency); |
Rimon Ashkenazy | e320103 | 2016-01-11 14:27:30 +0200 | [diff] [blame] | 68 | return (short) (diff.asHz() / grid.asHz()); |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the minimum frequency. |
| 73 | * |
| 74 | * @return minimum frequency |
| 75 | */ |
| 76 | public Frequency minFrequency() { |
| 77 | return minFrequency; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the maximum frequency. |
| 82 | * |
| 83 | * @return maximum frequency |
| 84 | */ |
| 85 | public Frequency maxFrequency() { |
| 86 | return maxFrequency; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the grid spacing frequency. |
| 91 | * |
| 92 | * @return grid spacing frequency |
| 93 | */ |
| 94 | public Frequency grid() { |
| 95 | return grid; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hash(number(), isEnabled(), type(), |
| 101 | minFrequency, maxFrequency, grid, annotations()); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public boolean equals(Object obj) { |
| 106 | if (this == obj) { |
| 107 | return true; |
| 108 | } |
Satish K | 7cfdc63 | 2015-11-27 19:48:41 +0530 | [diff] [blame] | 109 | if (obj != null && getClass() == obj.getClass()) { |
Marc De Leenheer | bb38235 | 2015-04-23 18:20:34 -0700 | [diff] [blame] | 110 | final OmsPort other = (OmsPort) obj; |
| 111 | return Objects.equals(this.element().id(), other.element().id()) && |
| 112 | Objects.equals(this.number(), other.number()) && |
| 113 | Objects.equals(this.isEnabled(), other.isEnabled()) && |
| 114 | Objects.equals(this.minFrequency, other.minFrequency) && |
| 115 | Objects.equals(this.maxFrequency, other.maxFrequency) && |
| 116 | Objects.equals(this.grid, other.grid) && |
| 117 | Objects.equals(this.annotations(), other.annotations()); |
| 118 | } |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public String toString() { |
| 124 | return toStringHelper(this) |
| 125 | .add("element", element().id()) |
| 126 | .add("number", number()) |
| 127 | .add("isEnabled", isEnabled()) |
| 128 | .add("type", type()) |
| 129 | .add("minFrequency", minFrequency) |
| 130 | .add("maxFrequency", maxFrequency) |
| 131 | .add("grid", grid) |
| 132 | .toString(); |
| 133 | } |
| 134 | |
| 135 | } |