blob: e1e54ca4c29dc5d9257d7c6f5a23be391f5d9a46 [file] [log] [blame]
Marc De Leenheerbb382352015-04-23 18:20:34 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Marc De Leenheerbb382352015-04-23 18:20:34 -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 */
16package org.onosproject.net;
17
18import org.onlab.util.Frequency;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
Toru Furusawa0f5da692016-01-07 14:51:47 -080023import static com.google.common.base.Preconditions.checkNotNull;
Marc De Leenheerbb382352015-04-23 18:20:34 -070024
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 Yuta95d83e82016-04-26 12:13:48 -070031 *
32 * @deprecated in Goldeneye (1.6.0)
Marc De Leenheerbb382352015-04-23 18:20:34 -070033 */
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -070034@Deprecated
Marc De Leenheerbb382352015-04-23 18:20:34 -070035public 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 Furusawa0f5da692016-01-07 14:51:47 -080056 this.minFrequency = checkNotNull(minFrequency);
57 this.maxFrequency = checkNotNull(maxFrequency);
58 this.grid = checkNotNull(grid);
Marc De Leenheerbb382352015-04-23 18:20:34 -070059 }
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 Ashkenazye3201032016-01-11 14:27:30 +020068 return (short) (diff.asHz() / grid.asHz());
Marc De Leenheerbb382352015-04-23 18:20:34 -070069 }
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 K7cfdc632015-11-27 19:48:41 +0530109 if (obj != null && getClass() == obj.getClass()) {
Marc De Leenheerbb382352015-04-23 18:20:34 -0700110 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}