Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [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.tetopology.management; |
| 17 | |
| 18 | import java.util.BitSet; |
| 19 | import java.util.List; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.tetopology.management.api.DefaultNetwork; |
| 25 | import org.onosproject.tetopology.management.api.EncodingType; |
| 26 | import org.onosproject.tetopology.management.api.KeyId; |
| 27 | import org.onosproject.tetopology.management.api.Network; |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame^] | 28 | import org.onosproject.tetopology.management.api.OptimizationType; |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 29 | import org.onosproject.tetopology.management.api.SwitchingType; |
| 30 | import org.onosproject.tetopology.management.api.TeConstants; |
| 31 | import org.onosproject.tetopology.management.api.TeStatus; |
| 32 | import org.onosproject.tetopology.management.api.TeTopologyId; |
| 33 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 34 | import org.onosproject.tetopology.management.api.link.CommonLinkData; |
| 35 | import org.onosproject.tetopology.management.api.link.DefaultNetworkLink; |
| 36 | import org.onosproject.tetopology.management.api.link.DefaultTeLink; |
| 37 | import org.onosproject.tetopology.management.api.link.ExternalLink; |
| 38 | import org.onosproject.tetopology.management.api.link.LinkBandwidth; |
| 39 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 40 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
| 41 | import org.onosproject.tetopology.management.api.link.OduResource; |
| 42 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 43 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
| 44 | import org.onosproject.tetopology.management.api.link.TeLinkTpKey; |
| 45 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 46 | import org.onosproject.tetopology.management.api.link.UnderlayPath; |
| 47 | import org.onosproject.tetopology.management.api.node.CommonNodeData; |
| 48 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrix; |
| 49 | import org.onosproject.tetopology.management.api.node.DefaultNetworkNode; |
| 50 | import org.onosproject.tetopology.management.api.node.DefaultTeNode; |
| 51 | import org.onosproject.tetopology.management.api.node.DefaultTerminationPoint; |
| 52 | import org.onosproject.tetopology.management.api.node.DefaultTunnelTerminationPoint; |
| 53 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
| 54 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
| 55 | import org.onosproject.tetopology.management.api.node.NodeTpKey; |
| 56 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 57 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 58 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
| 59 | import org.onosproject.tetopology.management.api.node.TunnelTerminationPoint; |
| 60 | import org.onosproject.tetopology.management.impl.TeMgrUtil; |
| 61 | |
| 62 | import com.google.common.collect.Lists; |
| 63 | import com.google.common.collect.Maps; |
| 64 | |
| 65 | /** |
| 66 | * Builds a sample abstract TE Topology, which consists of one node(represents |
| 67 | * an entire network), one inter-domain link and one TTP. |
| 68 | */ |
| 69 | public final class DefaultBuilder { |
| 70 | private static final String NODEIP = "100.10.10.10"; |
| 71 | // Bandwidth in GigaBits/second |
| 72 | private static final float[] ODU0BW = {1.25f, 1.25f, 1.25f, 1.25f, 1.25f, 1.25f, 1.25f, 1.25f}; |
| 73 | private static final float[] ODU2BW = {10, 10, 10, 10, 10, 10, 10, 10}; |
| 74 | private static final float[] ODU3BW = {40, 40, 40, 40, 40, 40, 40, 40}; |
| 75 | private static final float[] ODU4BW = {100, 100, 100, 100, 100, 100, 100, 100}; |
| 76 | |
| 77 | private static final String ODU2 = "ODU2"; |
| 78 | private static final String ODU3 = "ODU3"; |
| 79 | private static final String ODU4 = "ODU4"; |
| 80 | |
| 81 | private static final long PROVIDER_ID = 0x100; |
| 82 | private static final long CLIENT_ID = 0x0a0a0a0a; |
| 83 | private static final long CLIENT_NIL = 0; |
| 84 | private static final long ABSTRACT_TOPOLOGY_ID = 100; |
| 85 | private static final long NATIVE_TOPOLOGY_ID = 1; |
| 86 | private static final long NUM_TPS = 1; |
| 87 | private static final long NUM_TTPS = 1; |
| 88 | private static final boolean ABSTRACT = true; |
| 89 | private static final boolean UNABSTRACT = false; |
| 90 | private static final int FIRST_INDEX = 0; |
| 91 | private static final long INTER_DOMAIN_LINK_PLUGID = 100; |
| 92 | private static final long LINK_COST = 500; |
| 93 | private static final long LINK_DELAY = 2000; |
| 94 | private static final long LINK_SRLG = 150; |
| 95 | private static final String DOMAIN_ID = "DomainX"; |
| 96 | |
| 97 | private static NetworkNode networkNode; |
| 98 | private static TeNode teNode; |
| 99 | private static NetworkLink networkLink; |
| 100 | private static TeLink teLink; |
| 101 | private static Network network; |
| 102 | private static TunnelTerminationPoint ttp; |
| 103 | |
| 104 | private static TeTopologyKey teTopologyKey = new TeTopologyKey(PROVIDER_ID, |
| 105 | CLIENT_ID, |
| 106 | ABSTRACT_TOPOLOGY_ID); |
| 107 | |
| 108 | // no instantiation |
| 109 | private DefaultBuilder() { |
| 110 | } |
| 111 | |
| 112 | private static TunnelTerminationPoint ttpBuilder(long ttpId) { |
| 113 | return new DefaultTunnelTerminationPoint(ttpId, SwitchingType.OTN_TDM_CAPABLE, |
| 114 | EncodingType.LSP_ENCODING_ODUK, |
| 115 | new BitSet(TeConstants.FLAG_MAX_BITS), |
| 116 | null, null, |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 117 | ODU2BW, null); //10G for ODU2 |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | private static TerminationPoint tpBuilder(long teTpId) { |
| 121 | return new DefaultTerminationPoint(KeyId.keyId(Long.toString(teTpId)), null, teTpId); |
| 122 | } |
| 123 | |
| 124 | private static NetworkNode nodeBuilder(String nodeIp, long numTps, long numTtps, |
| 125 | TeTopologyKey underlayTopologyId, TeNodeKey supportTeNodeId, |
| 126 | TeNodeKey sourceTeNodeId, boolean isAbstract) { |
| 127 | long teNodeId = Ip4Address.valueOf(nodeIp).toInt(); |
| 128 | BitSet flags = new BitSet(TeConstants.FLAG_MAX_BITS); |
| 129 | |
| 130 | if (isAbstract) { |
| 131 | flags.set(TeNode.BIT_ABSTRACT); |
| 132 | } |
| 133 | CommonNodeData common = new CommonNodeData(nodeIp, TeStatus.UP, TeStatus.UP, flags); |
| 134 | Map<Long, ConnectivityMatrix> connMatrices = null; |
| 135 | List<Long> teTpIds = Lists.newArrayList(); |
| 136 | Map<KeyId, TerminationPoint> tps = Maps.newHashMap(); |
| 137 | for (long i = 0; i < numTps; i++) { |
| 138 | teTpIds.add(i); |
| 139 | tps.put(KeyId.keyId(Long.toString(i)), tpBuilder(i)); |
| 140 | } |
| 141 | //TTP |
| 142 | Map<Long, TunnelTerminationPoint> ttps = Maps.newHashMap(); |
| 143 | for (long i = 0; i < numTtps; i++) { |
| 144 | ttps.put(i, ttpBuilder(i)); |
| 145 | } |
| 146 | ttp = ttps.get(FIRST_INDEX); |
| 147 | //TeNode |
| 148 | teNode = new DefaultTeNode(teNodeId, underlayTopologyId, |
| 149 | supportTeNodeId, sourceTeNodeId, |
| 150 | common, connMatrices, teTpIds, ttps, teTpIds); |
| 151 | List<NetworkNodeKey> supportingNodeIds = null; |
| 152 | if (supportTeNodeId != null) { |
| 153 | supportingNodeIds = Lists |
| 154 | .newArrayList(TeMgrUtil.networkNodeKey(supportTeNodeId)); |
| 155 | } |
| 156 | |
| 157 | return new DefaultNetworkNode(KeyId.keyId(nodeIp), supportingNodeIds, teNode, tps); |
| 158 | } |
| 159 | |
| 160 | private static LinkBandwidth linkBwBuilder(String odu) { |
| 161 | |
| 162 | float[] maxBandwidth; //Maximum bandwidth, Size is MAX_PRIORITY + 1 |
| 163 | float[] avaiBandwidth; //Unreserved bandwidth, Size is MAX_PRIORITY + 1 |
| 164 | float[] maxAvialLspBandwidth; //Maximum available bandwidth for a LSP |
| 165 | float[] minAvialLspBandwidth; //Minimum available bandwidth for a LSP |
| 166 | short odu0s; |
| 167 | short odu1s; |
| 168 | short odu2s; |
| 169 | short odu2es = 0; |
| 170 | short odu3s; |
| 171 | short odu4s; |
| 172 | short oduFlexes = 0; |
| 173 | |
| 174 | switch (odu) { |
| 175 | case ODU3: |
| 176 | maxBandwidth = ODU3BW; |
| 177 | avaiBandwidth = ODU3BW; |
| 178 | maxAvialLspBandwidth = ODU3BW; |
| 179 | minAvialLspBandwidth = ODU0BW; |
| 180 | odu0s = 32; |
| 181 | odu1s = 16; |
| 182 | odu2s = 4; |
| 183 | odu3s = 1; |
| 184 | odu4s = 0; |
| 185 | break; |
| 186 | case ODU4: |
| 187 | maxBandwidth = ODU4BW; |
| 188 | avaiBandwidth = ODU4BW; |
| 189 | maxAvialLspBandwidth = ODU4BW; |
| 190 | minAvialLspBandwidth = ODU0BW; |
| 191 | odu0s = 80; |
| 192 | odu1s = 40; |
| 193 | odu2s = 10; |
| 194 | odu3s = 2; |
| 195 | odu4s = 1; |
| 196 | break; |
| 197 | default: |
| 198 | maxBandwidth = ODU2BW; |
| 199 | avaiBandwidth = ODU2BW; |
| 200 | maxAvialLspBandwidth = ODU2BW; |
| 201 | minAvialLspBandwidth = ODU0BW; |
| 202 | odu0s = 8; |
| 203 | odu1s = 4; |
| 204 | odu2s = 1; |
| 205 | odu3s = 0; |
| 206 | odu4s = 0; |
| 207 | } |
| 208 | |
| 209 | OduResource oduRrc = new OduResource(odu0s, odu1s, odu2s, odu2es, odu3s, |
| 210 | odu4s, oduFlexes); |
| 211 | return new LinkBandwidth(maxBandwidth, avaiBandwidth, maxAvialLspBandwidth, |
| 212 | minAvialLspBandwidth, oduRrc); |
| 213 | } |
| 214 | |
| 215 | private static NetworkLink linkBuilder(TeLinkTpKey teLinkKey, TeLinkTpKey peerTeLinkKey, |
| 216 | TeTopologyKey underlayTopologyId, TeLinkTpGlobalKey supportTeLinkId, |
| 217 | TeLinkTpGlobalKey sourceTeLinkId, boolean isAbstract, Long plugid, |
| 218 | Long cost, Long delay, List<Long> srlgs, String odu) { |
| 219 | //NetworkLink |
| 220 | KeyId linkId = TeMgrUtil.toNetworkLinkId(teLinkKey); |
Yixiao Chen | 29f0633 | 2016-12-07 16:14:29 -0500 | [diff] [blame] | 221 | NodeTpKey source = TeMgrUtil.nodeTpKey(teLinkKey); |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 222 | NodeTpKey destination = null; |
| 223 | if (peerTeLinkKey != null) { |
Yixiao Chen | 29f0633 | 2016-12-07 16:14:29 -0500 | [diff] [blame] | 224 | destination = TeMgrUtil.nodeTpKey(peerTeLinkKey); |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 225 | } |
| 226 | List<NetworkLinkKey> supportingLinkIds = null; |
| 227 | if (supportTeLinkId != null) { |
| 228 | supportingLinkIds = Lists |
| 229 | .newArrayList(TeMgrUtil.networkLinkKey(supportTeLinkId)); |
| 230 | } |
| 231 | BitSet flags = new BitSet(TeConstants.FLAG_MAX_BITS); |
| 232 | if (isAbstract) { |
| 233 | flags.set(TeLink.BIT_ABSTRACT); |
| 234 | } |
| 235 | ExternalLink externalLink = null; |
| 236 | |
| 237 | if (plugid != null) { |
| 238 | // Inter-Domain Link |
| 239 | flags.set(TeLink.BIT_ACCESS_INTERDOMAIN); |
| 240 | externalLink = new ExternalLink(null, plugid); |
| 241 | } |
| 242 | UnderlayPath underlayPath = null; |
| 243 | Long adminGroup = null; |
| 244 | List<Long> interLayerLocks = null; |
| 245 | teLink = new DefaultTeLink(teLinkKey, peerTeLinkKey, underlayTopologyId, |
| 246 | supportTeLinkId, sourceTeLinkId, |
| 247 | new CommonLinkData(TeStatus.UP, TeStatus.UP, flags, |
| 248 | SwitchingType.OTN_TDM_CAPABLE, |
| 249 | EncodingType.LSP_ENCODING_ODUK, |
| 250 | externalLink, underlayPath, |
| 251 | new TePathAttributes(cost, delay, srlgs), |
| 252 | adminGroup, interLayerLocks, linkBwBuilder(odu))); |
| 253 | return new DefaultNetworkLink(linkId, source, destination, supportingLinkIds, teLink); |
| 254 | } |
| 255 | |
| 256 | private static Network networkBuilder(TeTopologyId teTopologyId, KeyId supportingNetworkId, |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame^] | 257 | Map<KeyId, NetworkNode> nodes, |
| 258 | Map<KeyId, NetworkLink> links, |
| 259 | boolean serverProvided, |
| 260 | DeviceId ownerId, |
| 261 | OptimizationType optType) { |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 262 | KeyId networkId = TeMgrUtil.toNetworkId(teTopologyId); |
| 263 | List<KeyId> supportingNetworkIds = null; |
| 264 | if (supportingNetworkId != null) { |
| 265 | supportingNetworkIds = Lists.newArrayList(supportingNetworkId); |
| 266 | } |
| 267 | return new DefaultNetwork(networkId, supportingNetworkIds, nodes, links, teTopologyId, |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame^] | 268 | serverProvided, ownerId, optType); |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Returns the key for the sample TE Topology. |
| 273 | * |
| 274 | * @return value of TE Topology key |
| 275 | */ |
| 276 | public static TeTopologyKey teTopologyKey() { |
| 277 | return teTopologyKey; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Returns the abstract TE Node in the sample TE Topology. |
| 282 | * |
| 283 | * @return value of TE node |
| 284 | */ |
| 285 | public static TeNode teNode() { |
| 286 | return teNode; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Returns the TE link in the sample TE Topology. |
| 291 | * |
| 292 | * @return value of TE link |
| 293 | */ |
| 294 | public static TeLink teLink() { |
| 295 | return teLink; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Builds a sample abstract TE Topology, which consists of one abstract node |
| 300 | * representing an entire physical network, one inter-domain link and one |
| 301 | * TTP. |
| 302 | * |
| 303 | * @return value of network with an abstract TE Topology |
| 304 | */ |
| 305 | public static Network buildSampleAbstractNetwork() { |
| 306 | TeTopologyKey underlayTopologyId = new TeTopologyKey(PROVIDER_ID, |
| 307 | CLIENT_NIL, |
| 308 | NATIVE_TOPOLOGY_ID); |
| 309 | Map<KeyId, NetworkNode> nodes = Maps.newHashMap(); |
| 310 | networkNode = nodeBuilder(NODEIP, NUM_TPS, NUM_TTPS, underlayTopologyId, |
| 311 | null, null, ABSTRACT); |
| 312 | nodes.put(networkNode.nodeId(), networkNode); |
| 313 | |
| 314 | Map<KeyId, NetworkLink> links = Maps.newHashMap(); |
| 315 | TeLinkTpKey node1tp1 = new TeLinkTpKey(networkNode.teNode().teNodeId(), |
| 316 | networkNode.teNode() |
| 317 | .teTerminationPointIds() |
| 318 | .get(FIRST_INDEX)); |
| 319 | networkLink = linkBuilder(node1tp1, null, null, null, null, UNABSTRACT, |
| 320 | INTER_DOMAIN_LINK_PLUGID, LINK_COST, |
| 321 | LINK_DELAY, Lists.newArrayList(LINK_SRLG), |
| 322 | ODU4); |
| 323 | links.put(networkLink.linkId(), networkLink); |
| 324 | DeviceId ownerId = DeviceId.deviceId(DOMAIN_ID); |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame^] | 325 | TeTopologyId topologyId = new TeTopologyId(PROVIDER_ID, CLIENT_ID, |
| 326 | Long.toString(ABSTRACT_TOPOLOGY_ID)); |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 327 | network = networkBuilder(topologyId, null, nodes, links, false, |
Aihua Guo | 0bc1209 | 2017-02-10 09:53:55 -0500 | [diff] [blame^] | 328 | ownerId, OptimizationType.NOT_OPTIMIZED); |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 329 | return network; |
| 330 | } |
| 331 | |
| 332 | } |