Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [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.teyang.utils.topology; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.onosproject.tetopology.management.api.KeyId; |
| 23 | import org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability; |
| 24 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
| 25 | import org.onosproject.tetopology.management.api.node.TeNetworkTopologyId; |
| 26 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 27 | import org.onosproject.tetopology.management.api.node.TerminationCapability; |
| 28 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
| 29 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
| 30 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName; |
| 31 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
| 32 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 33 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 34 | .ietfnetwork.networks.network.DefaultNode; |
| 35 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 36 | .ietfnetwork.networks.network.Node; |
| 37 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 38 | .ietfnetwork.networks.network.node.DefaultSupportingNode; |
| 39 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 40 | .ietfnetwork.networks.network.node.SupportingNode; |
| 41 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 42 | .ietfnetworktopology.TpId; |
| 43 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 44 | .ietfnetworktopology.networks.network.node.AugmentedNdNode; |
| 45 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 46 | .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode; |
| 47 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 48 | .ietftetopology.networks.network.node.AugmentedNwNode; |
| 49 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 50 | .ietftetopology.networks.network.node.DefaultAugmentedNwNode; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe; |
| 52 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe.TeBuilder; |
| 53 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.Te; |
| 54 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.Config; |
| 55 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultConfig; |
| 56 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultState; |
| 57 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint; |
| 58 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.State; |
| 59 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.TunnelTerminationPoint; |
| 60 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes; |
| 61 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes; |
| 62 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.ConnectivityMatrix; |
| 63 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix; |
| 64 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultFrom; |
| 65 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultTo; |
| 66 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology; |
| 67 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.UnderlayTopology; |
| 68 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.DefaultTerminationCapability; |
| 69 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.DefaultTerminationCapability.TerminationCapabilityBuilder; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 70 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId; |
| 71 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyId; |
| 72 | |
| 73 | import com.google.common.collect.Lists; |
| 74 | |
| 75 | /** |
| 76 | * Node conversion functions. |
| 77 | */ |
| 78 | public final class NodeConverter { |
| 79 | |
| 80 | private static final String E_NULL_TE_SUBSYSTEM_TE_NODE = "TeSubsystem teNode object cannot be null"; |
| 81 | private static final String E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP = "TeSubsystem teTunnelTp object cannot be null"; |
| 82 | private static final String E_NULL_TE_SUBSYSTEM_NODE = "TeSubsystem ndoe object cannot be null"; |
| 83 | private static final String E_NULL_YANG_NODE = "Yang node object cannot be null"; |
| 84 | |
| 85 | // no instantiation |
| 86 | private NodeConverter() { |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * TE Node Config object conversion from TE Topology subsystem to YANG. |
| 91 | * |
| 92 | * @param teSubsystemTeNode TE node object |
| 93 | * @return TE Node Config YANG object |
| 94 | */ |
| 95 | private static Config teNode2YangConfig(TeNode teSubsystemTeNode) { |
| 96 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 97 | TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesConfigBuilder = |
| 98 | DefaultTeNodeAttributes.builder() |
| 99 | .isAbstract(teSubsystemTeNode.isAbstract()); |
| 100 | if (teSubsystemTeNode.adminStatus() != null) { |
| 101 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 102 | .adminStatus(EnumConverter |
| 103 | .teSubsystem2YangAdminStatus(teSubsystemTeNode |
| 104 | .adminStatus())); |
| 105 | } |
| 106 | |
| 107 | if (teSubsystemTeNode.name() != null) { |
| 108 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 109 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 110 | } |
| 111 | |
| 112 | if (teSubsystemTeNode.underlayTopology() != null) { |
| 113 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 114 | .underlayTopology(teNode2YangUnderlayConfig(teSubsystemTeNode.underlayTopology())); |
| 115 | } |
| 116 | |
| 117 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
| 118 | ConnectivityMatrix.ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = |
| 119 | DefaultConnectivityMatrix.builder(); |
| 120 | for (org.onosproject.tetopology.management.api.node.ConnectivityMatrix teCm : teSubsystemTeNode. |
| 121 | connectivityMatrices()) { |
| 122 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 123 | .id(teCm.id()) |
| 124 | .isAllowed(teCm.isAllowed()) |
| 125 | .from(new DefaultFrom.FromBuilder() |
| 126 | .tpRef(TpId.fromString(teCm.from().tpId() |
| 127 | .toString())) |
| 128 | .build()) |
| 129 | .to(new DefaultTo.ToBuilder() |
| 130 | .tpRef(TpId.fromString(teCm.to().tpId() |
| 131 | .toString())) |
| 132 | .build()); |
| 133 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 134 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
| 135 | .build()); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | |
| 140 | Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder(); |
| 141 | yangConfigBuilder = yangConfigBuilder.teNodeAttributes(teNodeAttributesConfigBuilder.build()); |
| 142 | |
| 143 | return yangConfigBuilder.build(); |
| 144 | } |
| 145 | |
| 146 | private static UnderlayTopology teNode2YangUnderlayConfig(TeNetworkTopologyId underlayTopology) { |
| 147 | UnderlayTopology.UnderlayTopologyBuilder underlayConfigBuilder = DefaultUnderlayTopology |
| 148 | .builder() |
| 149 | .networkIdRef(NetworkId.fromString(underlayTopology.getNetworkId().toString())) |
| 150 | .teTopologyIdRef(TeTopologyId |
| 151 | .fromString(underlayTopology |
| 152 | .getTopologyId().topologyId())); |
| 153 | return underlayConfigBuilder.build(); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * TE Node State object conversion from TE Topology subsystem to YANG. |
| 158 | * |
| 159 | * @param teSubsystemTeNode TE node object |
| 160 | * @return TE Node State YANG object |
| 161 | */ |
| 162 | private static State teNode2YangState(TeNode teSubsystemTeNode) { |
| 163 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 164 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 165 | TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesStateBuilder = DefaultTeNodeAttributes |
| 166 | .builder() |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 167 | .isAbstract(teSubsystemTeNode.isAbstract()); |
| 168 | |
| 169 | if (teSubsystemTeNode.adminStatus() != null) { |
| 170 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 171 | .adminStatus(EnumConverter |
| 172 | .teSubsystem2YangAdminStatus(teSubsystemTeNode |
| 173 | .adminStatus())); |
| 174 | } |
| 175 | |
| 176 | if (teSubsystemTeNode.name() != null) { |
| 177 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 178 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 179 | } |
| 180 | |
| 181 | if (teSubsystemTeNode.underlayTopology() != null) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 182 | UnderlayTopology.UnderlayTopologyBuilder underlayStateBuilder = DefaultUnderlayTopology |
| 183 | .builder(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 184 | underlayStateBuilder = underlayStateBuilder |
| 185 | .networkIdRef(NetworkId.fromString(teSubsystemTeNode |
| 186 | .underlayTopology().getNetworkId().toString())) |
| 187 | .teTopologyIdRef(TeTopologyId.fromString(teSubsystemTeNode |
| 188 | .underlayTopology().getTopologyId().topologyId())); |
| 189 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 190 | .underlayTopology(underlayStateBuilder.build()); |
| 191 | } |
| 192 | |
| 193 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 194 | ConnectivityMatrix.ConnectivityMatrixBuilder connectivityMatrixStateBuilder = DefaultConnectivityMatrix |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 195 | .builder(); |
| 196 | for (org.onosproject.tetopology.management.api.node.ConnectivityMatrix teCm : teSubsystemTeNode |
| 197 | .connectivityMatrices()) { |
| 198 | connectivityMatrixStateBuilder = connectivityMatrixStateBuilder |
| 199 | .id(teCm.id()) |
| 200 | .isAllowed(teCm.isAllowed()) |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 201 | .from(new DefaultFrom.FromBuilder() |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 202 | .tpRef(TpId.fromString(teCm.from().tpId() |
| 203 | .toString())) |
| 204 | .build()) |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 205 | .to(new DefaultTo.ToBuilder() |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 206 | .tpRef(TpId.fromString(teCm.to().tpId() |
| 207 | .toString())) |
| 208 | .build()); |
| 209 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 210 | .addToConnectivityMatrix(connectivityMatrixStateBuilder |
| 211 | .build()); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | State.StateBuilder yangStateBuilder = DefaultState.builder(); |
| 216 | yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build()); |
| 217 | |
| 218 | if (teSubsystemTeNode.opStatus() != null) { |
| 219 | yangStateBuilder = yangStateBuilder.operStatus(EnumConverter |
| 220 | .teSubsystem2YangOperStatus(teSubsystemTeNode |
| 221 | .opStatus())); |
| 222 | } |
| 223 | |
| 224 | return yangStateBuilder.build(); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG. |
| 229 | * |
| 230 | * @param teTunnelTp TE TunnelTerminationPoint object |
| 231 | * @return TunnelTerminationPoint YANG object |
| 232 | */ |
| 233 | private static TunnelTerminationPoint teSubsystem2YangTtp( |
| 234 | org.onosproject.tetopology.management.api.node.TunnelTerminationPoint teTunnelTp) { |
| 235 | checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP); |
| 236 | |
| 237 | TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder = |
| 238 | DefaultTunnelTerminationPoint.builder().tunnelTpId(teTunnelTp.getTunnelTpId()); |
| 239 | |
| 240 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 241 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint. |
| 242 | Config.ConfigBuilder ttpConfigBuilder = |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 243 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 244 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 245 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 246 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint. |
| 247 | State.StateBuilder ttpStateBuilder = |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 248 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 249 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 250 | |
| 251 | if (Long.valueOf(teTunnelTp.getInterLayerLockId()) != null) { |
| 252 | ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.getInterLayerLockId()); |
| 253 | ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.getInterLayerLockId()); |
| 254 | } |
| 255 | |
| 256 | if (teTunnelTp.getSwitchingCapabilities() != null) { |
| 257 | // FIXME: switchingCapabilities is a list in |
| 258 | // teSubsystem, but is not a list in yang. how to handle |
| 259 | // this? |
| 260 | for (InterfaceSwitchingCapability iscTe : teTunnelTp.getSwitchingCapabilities()) { |
| 261 | // ttpConfigBuilder = |
| 262 | // ttpConfigBuilder.switchingCapability(switchingCapability) |
| 263 | // ttpStateBuilder = |
| 264 | // ttpStateBuilder.switchingCapability(switchingCapability) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | if (teTunnelTp.getTerminationCapabilities() != null) { |
| 269 | for (TerminationCapability tcap : teTunnelTp.getTerminationCapabilities()) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 270 | TerminationCapabilityBuilder tcapBuilder = DefaultTerminationCapability |
| 271 | .builder(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 272 | // FIXME: at this moment, tcap does not have any getter or setter. |
| 273 | // add the following getLinkTpId possibly other attributes to Core data structure |
| 274 | // tcapConfigBuilder = |
| 275 | // tcapConfigBuilder.linkTp(TpId.fromString(tcap.getLinkTpId.toString())); |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 276 | ttpConfigBuilder = ttpConfigBuilder |
| 277 | .addToTerminationCapability(tcapBuilder.build()); |
| 278 | ttpStateBuilder = ttpStateBuilder |
| 279 | .addToTerminationCapability(tcapBuilder.build()); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
| 283 | tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build()) |
| 284 | .state(ttpStateBuilder.build()); |
| 285 | |
| 286 | return tunnelTpBuilder.build(); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Node object conversion from TE Topology subsystem to YANG. |
| 291 | * |
| 292 | * @param teSubsystem TE subsystem node object |
| 293 | * @return YANG node object |
| 294 | */ |
| 295 | public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem) { |
| 296 | checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE); |
| 297 | |
| 298 | NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString()); |
| 299 | Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId); |
| 300 | |
| 301 | if (teSubsystem.getSupportingNodeIds() != null) { |
| 302 | List<SupportingNode> sNodes = Lists.newArrayList(); |
| 303 | SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode |
| 304 | .builder(); |
| 305 | for (NetworkNodeKey nodeKey : teSubsystem.getSupportingNodeIds()) { |
| 306 | sNodes.add(spNodeBuilder |
| 307 | .networkRef(NetworkId |
| 308 | .fromString(nodeKey.networkId().toString())) |
| 309 | .nodeRef(NodeId.fromString(nodeKey.nodeId().toString())) |
| 310 | .build()); |
| 311 | } |
| 312 | builder = builder.supportingNode(sNodes); |
| 313 | } |
| 314 | |
| 315 | if (teSubsystem.getTerminationPoints() != null) { |
| 316 | AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode |
| 317 | .builder(); |
| 318 | List<TerminationPoint> teSubsystemTeTp = teSubsystem |
| 319 | .getTerminationPoints(); |
| 320 | for (TerminationPoint teTp : teSubsystemTeTp) { |
| 321 | tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter |
| 322 | .teSubsystem2YangTerminationPoint(teTp)); |
| 323 | } |
| 324 | builder.addYangAugmentedInfo(tpAugmentBuilder.build(), |
| 325 | AugmentedNdNode.class); |
| 326 | } |
| 327 | |
| 328 | if (teSubsystem.getTe() != null) { |
| 329 | AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode |
| 330 | .builder(); |
| 331 | |
| 332 | TeNode teSubsystemTeNode = teSubsystem.getTe(); |
| 333 | |
| 334 | TeBuilder yangTeBuilder = DefaultTe.builder(); |
| 335 | |
| 336 | if (teSubsystemTeNode.teNodeId() != null) { |
| 337 | yangTeBuilder = yangTeBuilder.teNodeId(TeNodeId |
| 338 | .fromString(teSubsystemTeNode.teNodeId().toString())); |
| 339 | } |
| 340 | |
| 341 | // Set configuration data |
| 342 | // Set state data |
| 343 | yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode)) |
| 344 | .state(teNode2YangState(teSubsystemTeNode)); |
| 345 | |
| 346 | if (teSubsystemTeNode.tunnelTerminationPoints() != null) { |
| 347 | for (org.onosproject.tetopology.management.api.node.TunnelTerminationPoint |
| 348 | teTunnelTp : teSubsystemTeNode.tunnelTerminationPoints()) { |
| 349 | yangTeBuilder = yangTeBuilder.addToTunnelTerminationPoint(teSubsystem2YangTtp(teTunnelTp)); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build()); |
| 354 | builder.addYangAugmentedInfo(nodeAugmentBuilder.build(), |
| 355 | AugmentedNwNode.class); |
| 356 | } |
| 357 | return builder.build(); |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Node object conversion from YANG to TE Topology subsystem. |
| 362 | * |
| 363 | * @param yangNode YANG node object |
| 364 | * @param yangNetworkId YANG networkId object |
| 365 | * @return TE subsystem node object |
| 366 | */ |
| 367 | public static org.onosproject.tetopology.management.api.node.NetworkNode |
| 368 | yang2TeSubsystemNode(Node yangNode, NetworkId yangNetworkId) { |
| 369 | checkNotNull(yangNode, E_NULL_YANG_NODE); |
| 370 | |
| 371 | org.onosproject.tetopology.management.api.node.DefaultNetworkNode node = |
| 372 | new org.onosproject.tetopology.management.api.node.DefaultNetworkNode( |
| 373 | KeyId.keyId(yangNode.nodeId().uri().string())); |
| 374 | |
| 375 | if (yangNode.supportingNode() != null) { |
| 376 | List<NetworkNodeKey> spNodes = Lists.newArrayList(); |
| 377 | for (SupportingNode yangSpNode : yangNode.supportingNode()) { |
| 378 | NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()), |
| 379 | KeyId.keyId(yangSpNode.networkRef().uri().toString())); |
| 380 | spNodes.add(nodeKey); |
| 381 | } |
| 382 | node.setSupportingNodeIds(spNodes); |
| 383 | } |
| 384 | |
| 385 | if (yangNode.yangAugmentedInfoMap() != null |
| 386 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 387 | |
| 388 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 389 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 390 | if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) { |
| 391 | node.setTerminationPoints(yang2TeSubsystemTpNodeAugment(yangTpNodeAugment)); |
| 392 | } |
| 393 | |
| 394 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode |
| 395 | .yangAugmentedInfo(AugmentedNwNode.class); |
| 396 | if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.te().teNodeId() != null) { |
| 397 | Te yangNodeAugTe = yangNodeAugment.te(); |
| 398 | TeNode teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, yangNetworkId, yangNode.nodeId()); |
| 399 | node.setTe(teNode); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return node; |
| 404 | } |
| 405 | |
| 406 | private static TeNode yang2TeSubsystemNodeConnectivityMatrix(TeNode teNode, |
| 407 | String networkId, String nodeId, List<ConnectivityMatrix> yangMatrix) { |
| 408 | List<org.onosproject.tetopology.management.api.node.ConnectivityMatrix> teCmList = |
| 409 | Lists.newArrayList(); |
| 410 | for (ConnectivityMatrix cmYang : yangMatrix) { |
| 411 | Long id = cmYang.id(); |
| 412 | TerminationPointKey from = new TerminationPointKey( |
| 413 | KeyId.keyId(networkId), |
| 414 | KeyId.keyId(nodeId), |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 415 | KeyId.keyId(cmYang.from().tpRef().toString())); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 416 | TerminationPointKey to = new TerminationPointKey( |
| 417 | KeyId.keyId(networkId), |
| 418 | KeyId.keyId(nodeId), |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 419 | KeyId.keyId(cmYang.to().tpRef().toString())); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 420 | boolean isAllowed = cmYang.isAllowed(); |
| 421 | org.onosproject.tetopology.management.api.node.ConnectivityMatrix cmTe = |
| 422 | new org.onosproject.tetopology.management.api.node.ConnectivityMatrix( |
| 423 | id, from, to, isAllowed); |
| 424 | teCmList.add(cmTe); |
| 425 | } |
| 426 | teNode.setConnectivityMatrices(teCmList); |
| 427 | return teNode; |
| 428 | } |
| 429 | |
| 430 | private static TeNode yang2TeSubsystemNodeUnderlayTopology(TeNode teNode, |
| 431 | UnderlayTopology ut) { |
| 432 | TeNetworkTopologyId underlayTopology = |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 433 | new TeNetworkTopologyId(KeyId.keyId(ut.networkIdRef().toString()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 434 | new org.onosproject.tetopology.management.api.TeTopologyId( |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 435 | ((long) ut.providerIdRef()), |
| 436 | ((long) ut.clientIdRef()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 437 | ut.teTopologyIdRef().toString())); |
| 438 | teNode.setUnderlayTopology(underlayTopology); |
| 439 | return teNode; |
| 440 | } |
| 441 | |
| 442 | private static TeNode yang2TeSubsystemTtp(TeNode teNode, |
| 443 | List<TunnelTerminationPoint> ttps) { |
| 444 | List<org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpTeList = |
| 445 | Lists.newArrayList(); |
| 446 | for (TunnelTerminationPoint ttpYang : ttps) { |
| 447 | org.onosproject.tetopology.management.api.node.TunnelTerminationPoint ttpTe = |
| 448 | new org.onosproject.tetopology.management.api.node.TunnelTerminationPoint( |
| 449 | ttpYang.tunnelTpId()); |
| 450 | ttpTe.setInterLayerLockId(ttpYang.config().interLayerLockId()); |
| 451 | // FIXME: go through |
| 452 | // ttpYang.config().switchingCapability() and populate |
| 453 | // ttpTe.setSwitchingCapabilities(switchingCapabilities); |
| 454 | // FIXME: go through |
| 455 | // ttpYang.config().terminationCapability() and populate |
| 456 | // ttpTe.setTerminationCapability(terminationCapability); |
| 457 | ttpTeList.add(ttpTe); |
| 458 | } |
| 459 | teNode.setTunnelTerminationPoints(ttpTeList); |
| 460 | |
| 461 | return teNode; |
| 462 | } |
| 463 | |
| 464 | private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe, |
| 465 | NetworkId yangNetworkId, NodeId yangNodeId) { |
| 466 | TeNode teNode = new TeNode(yangNodeAugTe.teNodeId().toString()); |
| 467 | Config ynodeAugCfg = yangNodeAugTe.config(); |
| 468 | if (ynodeAugCfg != null) { |
| 469 | TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes(); |
| 470 | if (teNodeAttr != null) { |
| 471 | teNode.setAbstract(teNodeAttr.isAbstract()); |
| 472 | |
| 473 | if (teNodeAttr.adminStatus() != null) { |
| 474 | teNode.setAdminStatus(EnumConverter.yang2TeSubsystemAdminStatus( |
| 475 | ynodeAugCfg.teNodeAttributes().adminStatus())); |
| 476 | } |
| 477 | |
| 478 | if (yangNodeAugTe.state() != null && |
| 479 | yangNodeAugTe.state().operStatus() != null) { |
| 480 | teNode.setOpStatus(EnumConverter.yang2TeSubsystemOpStatus( |
| 481 | yangNodeAugTe.state().operStatus())); |
| 482 | } |
| 483 | |
| 484 | if (teNodeAttr.connectivityMatrix() != null) { |
| 485 | teNode = yang2TeSubsystemNodeConnectivityMatrix(teNode, |
| 486 | yangNetworkId.uri().toString(), |
| 487 | yangNodeId.uri().toString(), |
| 488 | teNodeAttr.connectivityMatrix()); |
| 489 | } |
| 490 | |
| 491 | if (teNodeAttr.underlayTopology() != null) { |
| 492 | teNode = yang2TeSubsystemNodeUnderlayTopology(teNode, |
| 493 | teNodeAttr.underlayTopology()); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | if (yangNodeAugTe.tunnelTerminationPoint() != null) { |
| 499 | teNode = yang2TeSubsystemTtp(teNode, yangNodeAugTe.tunnelTerminationPoint()); |
| 500 | } |
| 501 | return teNode; |
| 502 | } |
| 503 | |
| 504 | private static List<TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) { |
| 505 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 506 | List<TerminationPoint> teTpList = Lists.newArrayList(); |
| 507 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 508 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 509 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 510 | teTpList.add(TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode)); |
| 511 | } |
| 512 | return teTpList; |
| 513 | } |
| 514 | return null; |
| 515 | } |
| 516 | } |