blob: 980b63e471c72cad6b64fa1d2b5264a9723462cd [file] [log] [blame]
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -07001/*
2 * Copyright 2016-present 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.optical.impl;
17
18import static com.google.common.base.Preconditions.checkNotNull;
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070019import static org.onosproject.net.optical.device.OmsPortHelper.stripHandledAnnotations;
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -070020
21import java.util.Objects;
22
23import org.onlab.util.Frequency;
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070024import org.onosproject.net.Annotations;
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -070025import org.onosproject.net.Port;
26import org.onosproject.net.optical.OmsPort;
HIGUCHI Yutaf46dc4f2016-05-13 11:24:13 -070027import org.onosproject.net.utils.ForwardingPort;
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -070028
29import com.google.common.annotations.Beta;
30
31/**
32 * Implementation of OMS port (Optical Multiplexing Section).
33 * Also referred to as a WDM port or W-port.
34 * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
35 *
36 * Assumes we only support fixed grid for now.
37 */
38@Beta
39public class DefaultOmsPort extends ForwardingPort implements OmsPort {
40
41 private final Frequency minFrequency; // Minimum frequency
42 private final Frequency maxFrequency; // Maximum frequency
43 private final Frequency grid; // Grid spacing frequency
44
45 /**
46 * Creates an OMS port.
47 *
48 * @param delegate Port
49 * @param minFrequency minimum frequency
50 * @param maxFrequency maximum frequency
51 * @param grid grid spacing frequency
52 */
53 public DefaultOmsPort(Port delegate, Frequency minFrequency, Frequency maxFrequency, Frequency grid) {
54 super(delegate);
55
56 this.minFrequency = checkNotNull(minFrequency);
57 this.maxFrequency = checkNotNull(maxFrequency);
58 this.grid = checkNotNull(grid);
59 }
60
61 @Override
62 public Type type() {
63 return Type.OMS;
64 }
65
66 @Override
67 public long portSpeed() {
68 return 0;
69 }
70
71 @Override
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -070072 public Annotations unhandledAnnotations() {
73 return stripHandledAnnotations(super.annotations());
74 }
75
76
77 @Override
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -070078 public Frequency minFrequency() {
79 return minFrequency;
80 }
81
82 @Override
83 public Frequency maxFrequency() {
84 return maxFrequency;
85 }
86
87 @Override
88 public Frequency grid() {
89 return grid;
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(super.hashCode(),
95 minFrequency(),
96 maxFrequency(),
97 grid());
98 }
99
100 @Override
101 public boolean equals(Object obj) {
102 if (this == obj) {
103 return true;
104 }
105
106 if (obj != null && getClass() == obj.getClass()) {
107 final DefaultOmsPort that = (DefaultOmsPort) obj;
108 return super.toEqualsBuilder(that)
109 .append(this.minFrequency(), that.minFrequency())
110 .append(this.maxFrequency(), that.maxFrequency())
111 .append(this.grid(), that.grid())
112 .isEquals();
113 }
114 return false;
115 }
116
117 @Override
118 public String toString() {
119 return super.toStringHelper()
120 .add("minFrequency", minFrequency())
121 .add("maxFrequency", maxFrequency())
122 .add("grid", grid())
Yuta HIGUCHI1d547bf2016-08-02 21:44:48 -0700123 .add("annotations", unhandledAnnotations())
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -0700124 .toString();
125 }
126
127}