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