blob: 753834b5c3161f450492fb635d6d6b9ca988551e [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;
23
24/**
25 * Implementation of OMS port (Optical Multiplexing Section).
26 * Also referred to as a WDM port or W-port.
27 * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
28 *
29 * Assumes we only support fixed grid for now.
30 */
31public class OmsPort extends DefaultPort {
32
33 private final Frequency minFrequency; // Minimum frequency
34 private final Frequency maxFrequency; // Maximum frequency
35 private final Frequency grid; // Grid spacing frequency
36
37
38 /**
39 * Creates an OMS port in the specified network element.
40 *
41 * @param element parent network element
42 * @param number port number
43 * @param isEnabled port enabled state
44 * @param minFrequency minimum frequency
45 * @param maxFrequency maximum frequency
46 * @param grid grid spacing frequency
47 * @param annotations optional key/value annotations
48 */
49 public OmsPort(Element element, PortNumber number, boolean isEnabled,
50 Frequency minFrequency, Frequency maxFrequency, Frequency grid, Annotations... annotations) {
51 super(element, number, isEnabled, Type.OMS, 0, annotations);
52 this.minFrequency = minFrequency;
53 this.maxFrequency = maxFrequency;
54 this.grid = grid;
55 }
56
57 /**
58 * Returns the total number of channels on the port.
59 *
60 * @return total number of channels
61 */
62 public short totalChannels() {
63 Frequency diff = maxFrequency.subtract(minFrequency);
64 return (short) (diff.asHz() / (grid.asHz() + 1));
65 }
66
67 /**
68 * Returns the minimum frequency.
69 *
70 * @return minimum frequency
71 */
72 public Frequency minFrequency() {
73 return minFrequency;
74 }
75
76 /**
77 * Returns the maximum frequency.
78 *
79 * @return maximum frequency
80 */
81 public Frequency maxFrequency() {
82 return maxFrequency;
83 }
84
85 /**
86 * Returns the grid spacing frequency.
87 *
88 * @return grid spacing frequency
89 */
90 public Frequency grid() {
91 return grid;
92 }
93
94 @Override
95 public int hashCode() {
96 return Objects.hash(number(), isEnabled(), type(),
97 minFrequency, maxFrequency, grid, annotations());
98 }
99
100 @Override
101 public boolean equals(Object obj) {
102 if (this == obj) {
103 return true;
104 }
105 if (obj instanceof OmsPort) {
106 final OmsPort other = (OmsPort) obj;
107 return Objects.equals(this.element().id(), other.element().id()) &&
108 Objects.equals(this.number(), other.number()) &&
109 Objects.equals(this.isEnabled(), other.isEnabled()) &&
110 Objects.equals(this.minFrequency, other.minFrequency) &&
111 Objects.equals(this.maxFrequency, other.maxFrequency) &&
112 Objects.equals(this.grid, other.grid) &&
113 Objects.equals(this.annotations(), other.annotations());
114 }
115 return false;
116 }
117
118 @Override
119 public String toString() {
120 return toStringHelper(this)
121 .add("element", element().id())
122 .add("number", number())
123 .add("isEnabled", isEnabled())
124 .add("type", type())
125 .add("minFrequency", minFrequency)
126 .add("maxFrequency", maxFrequency)
127 .add("grid", grid)
128 .toString();
129 }
130
131}