Naoki Shiota | 5a05606 | 2016-05-05 18:43:59 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 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.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; |
| 36 | // established=false represents that this (packet) link is expected to be |
| 37 | // discovered after underlying (optical) path has been provisioned. |
| 38 | private boolean established; |
| 39 | |
| 40 | /** |
| 41 | * Creates instance with specified parameters. |
| 42 | * |
| 43 | * @param src source connect point |
| 44 | * @param dst destination connect point |
| 45 | * @param realizingIntentKey key of Optical*Intent that realizes packet link between src and dst |
| 46 | * @param bandwidth assigned bandwidth |
| 47 | */ |
| 48 | public PacketLinkRealizedByOptical(ConnectPoint src, ConnectPoint dst, |
| 49 | Key realizingIntentKey, Bandwidth bandwidth) { |
| 50 | this.src = src; |
| 51 | this.dst = dst; |
| 52 | this.realizingIntentKey = realizingIntentKey; |
| 53 | this.bandwidth = bandwidth; |
| 54 | this.established = false; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Creates PacketLinkRealizedByOptical instance with specified connect points and OpticalCircuitIntent. |
| 59 | * Assigned bandwidth is taken from physical limit of optical link. |
| 60 | * |
| 61 | * @param src source connect point |
| 62 | * @param dst destination connect point |
| 63 | * @param intent OpticalCircuitIntent that realizes packet link between src and dst |
| 64 | * @return |
| 65 | */ |
| 66 | public static PacketLinkRealizedByOptical create(ConnectPoint src, ConnectPoint dst, |
| 67 | OpticalCircuitIntent intent) { |
| 68 | checkNotNull(src); |
| 69 | checkNotNull(dst); |
| 70 | checkNotNull(intent); |
| 71 | |
| 72 | long rate = intent.getSignalType().bitRate(); |
| 73 | return new PacketLinkRealizedByOptical(src, dst, intent.key(), Bandwidth.bps(rate)); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Creates PacketLinkRealizedByOptical instance with specified connect points and OpticalConnectivityIntent. |
| 78 | * Assigned bandwidth is taken from physical limit of optical link. |
| 79 | * |
| 80 | * @param src source connect point |
| 81 | * @param dst destination connect point |
| 82 | * @param intent OpticalConnectivityIntent that realizes packet link between src and dst |
| 83 | * @return |
| 84 | */ |
| 85 | public static PacketLinkRealizedByOptical create(ConnectPoint src, ConnectPoint dst, |
| 86 | OpticalConnectivityIntent intent) { |
| 87 | checkNotNull(src); |
| 88 | checkNotNull(dst); |
| 89 | checkNotNull(intent); |
| 90 | |
| 91 | long rate = intent.getSignalType().bitRate(); |
| 92 | return new PacketLinkRealizedByOptical(src, dst, intent.key(), Bandwidth.bps(rate)); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns source connect point. |
| 97 | * |
| 98 | * @return source connect point |
| 99 | */ |
| 100 | public ConnectPoint src() { |
| 101 | return src; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns destination connect point. |
| 106 | * |
| 107 | * @return destination connect point |
| 108 | */ |
| 109 | public ConnectPoint dst() { |
| 110 | return dst; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns assigned bandwidth. |
| 115 | * |
| 116 | * @return assigned bandwidth |
| 117 | */ |
| 118 | public Bandwidth bandwidth() { |
| 119 | return bandwidth; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns intent key. |
| 124 | * |
| 125 | * @return intent key |
| 126 | */ |
| 127 | public Key realizingIntentKey() { |
| 128 | return realizingIntentKey; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns whether packet link is realized or not. |
| 133 | * |
| 134 | * @return true if packet link is realized. false if not. |
| 135 | */ |
| 136 | public boolean isEstablished() { |
| 137 | return established; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Sets packet link to be established. |
| 142 | * |
| 143 | * @param established status of packet link |
| 144 | */ |
| 145 | public void setEstablished(boolean established) { |
| 146 | this.established = established; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Check if packet link is between specified two connect points. |
| 151 | * |
| 152 | * @param src source connect point |
| 153 | * @param dst destination connect point |
| 154 | * @return true if this link is between src and dst. false if not. |
| 155 | */ |
| 156 | public boolean isBetween(ConnectPoint src, ConnectPoint dst) { |
| 157 | return (this.src.equals(src) && this.dst.equals(dst)); |
| 158 | } |
| 159 | |
| 160 | } |