blob: 5a3bb7331d7001ee266363b5839625ef6f36b097 [file] [log] [blame]
Marc De Leenheerbb382352015-04-23 18:20:34 -07001/*
2 * Copyright 2015 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 */
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.
31 */
32public class OmsPort extends DefaultPort {
33
34 private final Frequency minFrequency; // Minimum frequency
35 private final Frequency maxFrequency; // Maximum frequency
36 private final Frequency grid; // Grid spacing frequency
37
38
39 /**
40 * Creates an OMS port in the specified network element.
41 *
42 * @param element parent network element
43 * @param number port number
44 * @param isEnabled port enabled state
45 * @param minFrequency minimum frequency
46 * @param maxFrequency maximum frequency
47 * @param grid grid spacing frequency
48 * @param annotations optional key/value annotations
49 */
50 public OmsPort(Element element, PortNumber number, boolean isEnabled,
51 Frequency minFrequency, Frequency maxFrequency, Frequency grid, Annotations... annotations) {
52 super(element, number, isEnabled, Type.OMS, 0, annotations);
Toru Furusawa0f5da692016-01-07 14:51:47 -080053 this.minFrequency = checkNotNull(minFrequency);
54 this.maxFrequency = checkNotNull(maxFrequency);
55 this.grid = checkNotNull(grid);
Marc De Leenheerbb382352015-04-23 18:20:34 -070056 }
57
58 /**
59 * Returns the total number of channels on the port.
60 *
61 * @return total number of channels
62 */
63 public short totalChannels() {
64 Frequency diff = maxFrequency.subtract(minFrequency);
Rimon Ashkenazye3201032016-01-11 14:27:30 +020065 return (short) (diff.asHz() / grid.asHz());
Marc De Leenheerbb382352015-04-23 18:20:34 -070066 }
67
68 /**
69 * Returns the minimum frequency.
70 *
71 * @return minimum frequency
72 */
73 public Frequency minFrequency() {
74 return minFrequency;
75 }
76
77 /**
78 * Returns the maximum frequency.
79 *
80 * @return maximum frequency
81 */
82 public Frequency maxFrequency() {
83 return maxFrequency;
84 }
85
86 /**
87 * Returns the grid spacing frequency.
88 *
89 * @return grid spacing frequency
90 */
91 public Frequency grid() {
92 return grid;
93 }
94
95 @Override
96 public int hashCode() {
97 return Objects.hash(number(), isEnabled(), type(),
98 minFrequency, maxFrequency, grid, annotations());
99 }
100
101 @Override
102 public boolean equals(Object obj) {
103 if (this == obj) {
104 return true;
105 }
Satish K7cfdc632015-11-27 19:48:41 +0530106 if (obj != null && getClass() == obj.getClass()) {
Marc De Leenheerbb382352015-04-23 18:20:34 -0700107 final OmsPort other = (OmsPort) obj;
108 return Objects.equals(this.element().id(), other.element().id()) &&
109 Objects.equals(this.number(), other.number()) &&
110 Objects.equals(this.isEnabled(), other.isEnabled()) &&
111 Objects.equals(this.minFrequency, other.minFrequency) &&
112 Objects.equals(this.maxFrequency, other.maxFrequency) &&
113 Objects.equals(this.grid, other.grid) &&
114 Objects.equals(this.annotations(), other.annotations());
115 }
116 return false;
117 }
118
119 @Override
120 public String toString() {
121 return toStringHelper(this)
122 .add("element", element().id())
123 .add("number", number())
124 .add("isEnabled", isEnabled())
125 .add("type", type())
126 .add("minFrequency", minFrequency)
127 .add("maxFrequency", maxFrequency)
128 .add("grid", grid)
129 .toString();
130 }
131
132}