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