Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -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.newoptical; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | import org.onlab.util.Bandwidth; |
| 20 | import org.onosproject.net.ConnectPoint; |
| 21 | import org.onosproject.net.intent.Key; |
| 22 | import org.onosproject.net.intent.OpticalCircuitIntent; |
| 23 | import org.onosproject.net.intent.OpticalConnectivityIntent; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Entity to represent packet link realized by optical intent. |
| 29 | */ |
| 30 | @Beta |
| 31 | public class PacketLinkRealizedByOptical { |
| 32 | private final ConnectPoint src, dst; |
| 33 | private final Bandwidth bandwidth; |
| 34 | // TODO should be list of Intent Key? |
| 35 | private final Key realizingIntentKey; |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Creates instance with specified parameters. |
| 39 | * |
| 40 | * @param src source connect point |
| 41 | * @param dst destination connect point |
| 42 | * @param realizingIntentKey key of Optical*Intent that realizes packet link between src and dst |
| 43 | * @param bandwidth assigned bandwidth |
| 44 | */ |
| 45 | public PacketLinkRealizedByOptical(ConnectPoint src, ConnectPoint dst, |
| 46 | Key realizingIntentKey, Bandwidth bandwidth) { |
| 47 | this.src = src; |
| 48 | this.dst = dst; |
| 49 | this.realizingIntentKey = realizingIntentKey; |
| 50 | this.bandwidth = bandwidth; |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Creates PacketLinkRealizedByOptical instance with specified connect points and OpticalCircuitIntent. |
| 55 | * Assigned bandwidth is taken from physical limit of optical link. |
| 56 | * |
| 57 | * @param src source connect point |
| 58 | * @param dst destination connect point |
| 59 | * @param intent OpticalCircuitIntent that realizes packet link between src and dst |
Ray Milkey | bb23e0b | 2016-08-02 17:00:21 -0700 | [diff] [blame] | 60 | * @return PacketLinkRealizedByOptical instance with specified connect points and OpticalCircuitIntent |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 61 | */ |
| 62 | public static PacketLinkRealizedByOptical create(ConnectPoint src, ConnectPoint dst, |
| 63 | OpticalCircuitIntent intent) { |
| 64 | checkNotNull(src); |
| 65 | checkNotNull(dst); |
| 66 | checkNotNull(intent); |
| 67 | |
| 68 | long rate = intent.getSignalType().bitRate(); |
| 69 | return new PacketLinkRealizedByOptical(src, dst, intent.key(), Bandwidth.bps(rate)); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Creates PacketLinkRealizedByOptical instance with specified connect points and OpticalConnectivityIntent. |
| 74 | * Assigned bandwidth is taken from physical limit of optical link. |
| 75 | * |
| 76 | * @param src source connect point |
| 77 | * @param dst destination connect point |
| 78 | * @param intent OpticalConnectivityIntent that realizes packet link between src and dst |
Ray Milkey | bb23e0b | 2016-08-02 17:00:21 -0700 | [diff] [blame] | 79 | * @return PacketLinkRealizedByOptical instance with specified connect points and OpticalConnectivityIntent |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 80 | */ |
| 81 | public static PacketLinkRealizedByOptical create(ConnectPoint src, ConnectPoint dst, |
| 82 | OpticalConnectivityIntent intent) { |
| 83 | checkNotNull(src); |
| 84 | checkNotNull(dst); |
| 85 | checkNotNull(intent); |
| 86 | |
| 87 | long rate = intent.getSignalType().bitRate(); |
| 88 | return new PacketLinkRealizedByOptical(src, dst, intent.key(), Bandwidth.bps(rate)); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Returns source connect point. |
| 93 | * |
| 94 | * @return source connect point |
| 95 | */ |
| 96 | public ConnectPoint src() { |
| 97 | return src; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns destination connect point. |
| 102 | * |
| 103 | * @return destination connect point |
| 104 | */ |
| 105 | public ConnectPoint dst() { |
| 106 | return dst; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns assigned bandwidth. |
| 111 | * |
| 112 | * @return assigned bandwidth |
| 113 | */ |
| 114 | public Bandwidth bandwidth() { |
| 115 | return bandwidth; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Returns intent key. |
| 120 | * |
| 121 | * @return intent key |
| 122 | */ |
| 123 | public Key realizingIntentKey() { |
| 124 | return realizingIntentKey; |
| 125 | } |
| 126 | |
| 127 | /** |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 128 | * Check if packet link is between specified two connect points. |
| 129 | * |
| 130 | * @param src source connect point |
| 131 | * @param dst destination connect point |
| 132 | * @return true if this link is between src and dst. false if not. |
| 133 | */ |
| 134 | public boolean isBetween(ConnectPoint src, ConnectPoint dst) { |
| 135 | return (this.src.equals(src) && this.dst.equals(dst)); |
| 136 | } |
| 137 | |
Naoki Shiota | 7c3111b | 2016-06-09 16:12:11 -0700 | [diff] [blame] | 138 | @Override |
| 139 | public boolean equals(Object o) { |
| 140 | if (this == o) { |
| 141 | return true; |
| 142 | } |
| 143 | if (o == null || getClass() != o.getClass()) { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | PacketLinkRealizedByOptical that = (PacketLinkRealizedByOptical) o; |
| 148 | |
| 149 | if (!src.equals(that.src)) { |
| 150 | return false; |
| 151 | } |
| 152 | if (!dst.equals(that.dst)) { |
| 153 | return false; |
| 154 | } |
| 155 | if (!bandwidth.equals(that.bandwidth)) { |
| 156 | return false; |
| 157 | } |
| 158 | return realizingIntentKey.equals(that.realizingIntentKey); |
| 159 | |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public int hashCode() { |
| 164 | int result = src.hashCode(); |
| 165 | result = 31 * result + dst.hashCode(); |
| 166 | result = 31 * result + bandwidth.hashCode(); |
| 167 | result = 31 * result + realizingIntentKey.hashCode(); |
| 168 | return result; |
| 169 | } |
Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame] | 170 | } |