Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [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 | */ |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 16 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 17 | package org.onosproject.teyang.utils.topology; |
| 18 | |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 20 | import org.onosproject.tetopology.management.api.DefaultNetwork; |
| 21 | import org.onosproject.tetopology.management.api.DefaultNetworks; |
| 22 | import org.onosproject.tetopology.management.api.KeyId; |
| 23 | import org.onosproject.tetopology.management.api.Network; |
| 24 | import org.onosproject.tetopology.management.api.Networks; |
| 25 | import org.onosproject.tetopology.management.api.TeTopologyId; |
| 26 | import org.onosproject.tetopology.management.api.link.DefaultNetworkLink; |
| 27 | import org.onosproject.tetopology.management.api.link.LinkProtectionType; |
| 28 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 29 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 30 | import org.onosproject.tetopology.management.api.link.TeLinkAccessType; |
| 31 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrix; |
| 32 | import org.onosproject.tetopology.management.api.node.DefaultNetworkNode; |
| 33 | import org.onosproject.tetopology.management.api.node.DefaultTerminationPoint; |
| 34 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
| 35 | import org.onosproject.tetopology.management.api.node.TeNetworkTopologyId; |
| 36 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 37 | import org.onosproject.tetopology.management.api.node.TeStatus; |
| 38 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
| 39 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
| 40 | |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 41 | import java.math.BigInteger; |
| 42 | import java.util.List; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Builds a sample Topology, which consists of two Nodes, one link, |
| 46 | * and each node has two termination points. |
| 47 | */ |
| 48 | public final class DefaultBuilder { |
| 49 | |
| 50 | private static final String HUAWEI_NETWORK_NEW = "HUAWEI_NETWORK_NEW"; |
| 51 | private static final String HUAWEI_ROADM_1 = "HUAWEI_ROADM_1"; |
| 52 | private static final String CLIENT1_NODE1 = "CLIENT1_NODE1"; |
| 53 | private static final String LINE1_NODE1 = "LINE1_NODE1"; |
| 54 | private static final String NODE1_IP = "10.11.12.33"; |
| 55 | private static final String HUAWEI_ROADM_2 = "HUAWEI_ROADM_2"; |
| 56 | private static final String CLIENT1_NODE2 = "CLIENT1_NODE2"; |
| 57 | private static final String LINE1_NODE2 = "LINE1_NODE2"; |
| 58 | private static final String NODE2_IP = "10.11.12.34"; |
| 59 | private static final String LINK1FORNETWORK1 = "LINK1FORNETWORK1"; |
| 60 | private static final String HUAWEI_TE_TOPOLOGY_NEW = "HUAWEI_TE_TOPOLOGY_NEW"; |
| 61 | |
| 62 | // no instantiation |
| 63 | private DefaultBuilder() { |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns a sample TeSubsystem Networks object. |
| 68 | * |
| 69 | * @return the Networks object |
| 70 | */ |
| 71 | public static Networks sampleTeSubsystemNetworksBuilder() { |
| 72 | DefaultNetworks defaultNetworks = new DefaultNetworks(); |
| 73 | List<Network> networks = Lists.newArrayList(); |
| 74 | networks.add(sampleTeSubsystemNetworkBuilder()); |
| 75 | defaultNetworks.setNetworks(networks); |
| 76 | return defaultNetworks; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns a sample TeSubsystem Network object. |
| 81 | * |
| 82 | * @return the Network object |
| 83 | */ |
| 84 | public static Network sampleTeSubsystemNetworkBuilder() { |
| 85 | DefaultNetwork huaweiNetworkNew = new DefaultNetwork(KeyId.keyId(HUAWEI_NETWORK_NEW)); |
| 86 | huaweiNetworkNew.setServerProvided(true); |
| 87 | List<NetworkNode> nodes = Lists.newArrayList(); |
| 88 | |
| 89 | |
| 90 | DefaultNetworkNode node1 = new DefaultNetworkNode(KeyId.keyId(HUAWEI_ROADM_1)); |
| 91 | |
| 92 | DefaultTerminationPoint tp11 = new DefaultTerminationPoint(KeyId.keyId(CLIENT1_NODE1)); |
| 93 | DefaultTerminationPoint tp12 = new DefaultTerminationPoint(KeyId.keyId(LINE1_NODE1)); |
| 94 | |
| 95 | List<TerminationPoint> tps1 = Lists.newArrayList(); |
| 96 | tps1.add(tp11); |
| 97 | tps1.add(tp12); |
| 98 | node1.setTerminationPoints(tps1); |
| 99 | |
| 100 | TeNode teNode1 = new TeNode(NODE1_IP); |
| 101 | teNode1.setAdminStatus(TeStatus.UP); |
| 102 | teNode1.setAbstract(false); |
| 103 | ConnectivityMatrix cMatrix1 = |
| 104 | new ConnectivityMatrix(1, |
| 105 | new TerminationPointKey(huaweiNetworkNew.networkId(), |
| 106 | node1.nodeId(), tp11.id()), |
| 107 | new TerminationPointKey(huaweiNetworkNew.networkId(), |
| 108 | node1.nodeId(), tp12.id()), |
| 109 | true); |
| 110 | List<ConnectivityMatrix> connMatrices = Lists.newArrayList(); |
| 111 | connMatrices.add(cMatrix1); |
| 112 | teNode1.setConnectivityMatrices(connMatrices); |
| 113 | node1.setTe(teNode1); |
| 114 | |
| 115 | DefaultNetworkNode node2 = new DefaultNetworkNode(KeyId.keyId(HUAWEI_ROADM_2)); |
| 116 | |
| 117 | DefaultTerminationPoint tp21 = new DefaultTerminationPoint(KeyId.keyId(CLIENT1_NODE2)); |
| 118 | DefaultTerminationPoint tp22 = new DefaultTerminationPoint(KeyId.keyId(LINE1_NODE2)); |
| 119 | |
| 120 | List<TerminationPoint> tps2 = Lists.newArrayList(); |
| 121 | tps2.add(tp21); |
| 122 | tps2.add(tp22); |
| 123 | node2.setTerminationPoints(tps2); |
| 124 | |
| 125 | TeNode teNode2 = new TeNode(NODE2_IP); |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 126 | teNode2.setAdminStatus(TeStatus.UP); |
| 127 | teNode2.setAbstract(false); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 128 | ConnectivityMatrix cMatrix2 = |
| 129 | new ConnectivityMatrix(1, |
| 130 | new TerminationPointKey(huaweiNetworkNew.networkId(), |
| 131 | node2.nodeId(), tp21.id()), |
| 132 | new TerminationPointKey(huaweiNetworkNew.networkId(), |
| 133 | node2.nodeId(), tp22.id()), |
| 134 | true); |
| 135 | List<ConnectivityMatrix> connMatrices2 = Lists.newArrayList(); |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 136 | connMatrices2.add(cMatrix2); |
| 137 | teNode2.setConnectivityMatrices(connMatrices2); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 138 | node2.setTe(teNode2); |
| 139 | |
| 140 | nodes.add(node1); |
| 141 | nodes.add(node2); |
| 142 | huaweiNetworkNew.setNodes(nodes); |
| 143 | |
| 144 | List<NetworkLink> links = Lists.newArrayList(); |
| 145 | |
| 146 | DefaultNetworkLink link1 = new DefaultNetworkLink(KeyId.keyId(LINK1FORNETWORK1)); |
| 147 | link1.setSource(new TerminationPointKey(huaweiNetworkNew.networkId(), |
| 148 | node1.nodeId(), |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 149 | tp12.id())); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 150 | link1.setDestination(new TerminationPointKey(huaweiNetworkNew.networkId(), |
| 151 | node2.nodeId(), |
Henry Yu | a4e34f8 | 2016-11-06 18:30:59 -0500 | [diff] [blame] | 152 | tp22.id())); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 153 | TeLink teLink1 = new TeLink(BigInteger.valueOf(1)); |
| 154 | teLink1.setIsAbstract(false); |
| 155 | teLink1.setAdminStatus(TeStatus.UP); |
| 156 | teLink1.setAccessType(TeLinkAccessType.POINT_TO_POINT); |
| 157 | teLink1.setLinkProtectionType(LinkProtectionType.UNPROTECTED); |
| 158 | List<Long> teSrlgs = Lists.newArrayList(); |
| 159 | teSrlgs.add(1000L); |
| 160 | teSrlgs.add(2000L); |
| 161 | teLink1.setTeSrlgs(teSrlgs); |
| 162 | link1.setTe(teLink1); |
| 163 | links.add(link1); |
| 164 | huaweiNetworkNew.setLinks(links); |
| 165 | |
| 166 | TeNetworkTopologyId teNetwork = |
| 167 | new TeNetworkTopologyId(new TeTopologyId(22222L, 44444L, HUAWEI_TE_TOPOLOGY_NEW)); |
| 168 | huaweiNetworkNew.setTeTopologyId(teNetwork.getTopologyId()); |
| 169 | |
| 170 | return huaweiNetworkNew; |
| 171 | } |
| 172 | } |