blob: 50e9b36445a95cfb05ed95ec1e8c655820608949 [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 OCh port (Optical Channel).
26 * Also referred to as a line side port (L-port) or narrow band port.
27 * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
28 */
29public class OchPort extends DefaultPort {
30
31 public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1);
32 public static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5);
33
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070034 private final OduSignalType signalType;
Marc De Leenheerbb382352015-04-23 18:20:34 -070035 private final boolean isTunable;
36 private final GridType gridType;
37 private final ChannelSpacing channelSpacing;
38 // Frequency = 193.1 THz + spacingMultiplier * channelSpacing
39 private final int spacingMultiplier;
40 // Slot width = slotGranularity * 12.5 GHz
41 private final int slotGranularity;
42
43
44 /**
45 * Creates an OCh port in the specified network element.
46 *
47 * @param element parent network element
48 * @param number port number
49 * @param isEnabled port enabled state
50 * @param signalType ODU signal type
51 * @param isTunable maximum frequency in MHz
52 * @param gridType grid type
53 * @param channelSpacing channel spacing
54 * @param spacingMultiplier channel spacing multiplier
55 * @param slotGranularity slot width granularity
56 * @param annotations optional key/value annotations
57 */
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070058 public OchPort(Element element, PortNumber number, boolean isEnabled, OduSignalType signalType,
Marc De Leenheerbb382352015-04-23 18:20:34 -070059 boolean isTunable, GridType gridType, ChannelSpacing channelSpacing,
60 int spacingMultiplier, int slotGranularity, Annotations... annotations) {
61 super(element, number, isEnabled, Type.OCH, 0, annotations);
62 this.signalType = signalType;
63 this.isTunable = isTunable;
64 this.gridType = gridType;
65 this.channelSpacing = channelSpacing;
66 this.spacingMultiplier = spacingMultiplier;
67 this.slotGranularity = slotGranularity;
68 }
69
70 /**
71 * Returns ODU signal type.
72 *
73 * @return ODU signal type
74 */
Sho SHIMIZU014c33a2015-04-30 11:40:37 -070075 public OduSignalType signalType() {
Marc De Leenheerbb382352015-04-23 18:20:34 -070076 return signalType;
77 }
78
79 /**
80 * Returns true if port is wavelength tunable.
81 *
82 * @return tunable wavelength capability
83 */
84 public boolean isTunable() {
85 return isTunable;
86 }
87
88 /**
89 * Returns grid type.
90 *
91 * @return grid type
92 */
93 public GridType gridType() {
94 return gridType;
95 }
96
97 /**
98 * Returns channel spacing.
99 *
100 * @return channel spacing
101 */
102 public ChannelSpacing channelSpacing() {
103 return channelSpacing;
104 }
105
106 /**
107 * Returns spacing multiplier.
108 *
109 * @return spacing multiplier
110 */
111 public int spacingMultiplier() {
112 return spacingMultiplier;
113 }
114
115 /**
116 * Returns slow width granularity.
117 *
118 * @return slow width granularity
119 */
120 public int slotGranularity() {
121 return slotGranularity;
122 }
123
124 /**
125 * Returns central frequency in MHz.
126 *
127 * @return frequency in MHz
128 */
129 public Frequency centralFrequency() {
130 return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier));
131 }
132
133 /**
134 * Returns slot width.
135 *
136 * @return slot width
137 */
138 public Frequency slotWidth() {
139 return FLEX_GRID_SLOT.multiply(slotGranularity);
140 }
141
142 @Override
143 public int hashCode() {
144 return Objects.hash(number(), isEnabled(), type(), signalType, isTunable,
145 gridType, channelSpacing, spacingMultiplier, slotGranularity, annotations());
146 }
147
148 @Override
149 public boolean equals(Object obj) {
150 if (this == obj) {
151 return true;
152 }
153 if (obj instanceof OchPort) {
154 final OchPort other = (OchPort) obj;
155 return Objects.equals(this.element().id(), other.element().id()) &&
156 Objects.equals(this.number(), other.number()) &&
157 Objects.equals(this.isEnabled(), other.isEnabled()) &&
158 Objects.equals(this.signalType, other.signalType) &&
159 Objects.equals(this.isTunable, other.isTunable) &&
160 Objects.equals(this.gridType, other.gridType) &&
161 Objects.equals(this.channelSpacing, other.channelSpacing) &&
162 Objects.equals(this.spacingMultiplier, other.spacingMultiplier) &&
163 Objects.equals(this.slotGranularity, other.slotGranularity) &&
164 Objects.equals(this.annotations(), other.annotations());
165 }
166 return false;
167 }
168
169 @Override
170 public String toString() {
171 return toStringHelper(this)
172 .add("element", element().id())
173 .add("number", number())
174 .add("isEnabled", isEnabled())
175 .add("type", type())
176 .add("signalType", signalType)
177 .add("isTunable", isTunable)
178 .add("gridType", gridType)
179 .add("channelSpacing", channelSpacing)
180 .add("spacingMultiplier", spacingMultiplier)
181 .add("slotGranularity", slotGranularity)
182 .toString();
183 }
184}