HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 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; |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 19 | import static org.onosproject.net.optical.device.OmsPortHelper.stripHandledAnnotations; |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import org.onlab.util.Frequency; |
Yuta HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 24 | import org.onosproject.net.Annotations; |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 25 | import org.onosproject.net.Port; |
| 26 | import org.onosproject.net.optical.OmsPort; |
HIGUCHI Yuta | f46dc4f | 2016-05-13 11:24:13 -0700 | [diff] [blame] | 27 | import org.onosproject.net.utils.ForwardingPort; |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 28 | |
| 29 | import 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 |
| 39 | public 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 HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 72 | public Annotations unhandledAnnotations() { |
| 73 | return stripHandledAnnotations(super.annotations()); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | @Override |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 78 | 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 HIGUCHI | 1d547bf | 2016-08-02 21:44:48 -0700 | [diff] [blame] | 123 | .add("annotations", unhandledAnnotations()) |
HIGUCHI Yuta | 95d83e8 | 2016-04-26 12:13:48 -0700 | [diff] [blame] | 124 | .toString(); |
| 125 | } |
| 126 | |
| 127 | } |