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.TeTerminationPoint; |
| 24 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
| 25 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
| 26 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 27 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 28 | .ietfnetworktopology.TpId; |
| 29 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 30 | .ietfnetworktopology.networks.network.node.augmentedndnode.DefaultTerminationPoint; |
| 31 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 32 | .ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint; |
| 33 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 34 | .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint |
| 35 | .DefaultSupportingTerminationPoint; |
| 36 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 37 | .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint |
| 38 | .SupportingTerminationPoint; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 39 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.interfaceswitchingcapabilitylist.DefaultInterfaceSwitchingCapability; |
| 40 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.interfaceswitchingcapabilitylist.InterfaceSwitchingCapability; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 41 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 42 | .ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint; |
| 43 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 44 | .ietftetopology.networks.network.node.terminationpoint.DefaultAugmentedNtTerminationPoint; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 45 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.DefaultTe; |
| 46 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.DefaultTe.TeBuilder; |
| 47 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.Config; |
| 48 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.DefaultConfig; |
| 49 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.DefaultState; |
| 50 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.teterminationpointaugment.te.State; |
| 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 52 | |
| 53 | import com.google.common.collect.Lists; |
| 54 | |
| 55 | /** |
| 56 | * The termination point translations. |
| 57 | */ |
| 58 | public final class TerminationPointConverter { |
| 59 | |
| 60 | private static final String E_NULL_TE_SUBSYSTEM_TP = "TeSubsystem terminationPoint object cannot be null"; |
| 61 | private static final String E_NULL_YANG_TP = "YANG terminationPoint object cannot be null"; |
| 62 | |
| 63 | // no instantiation |
| 64 | private TerminationPointConverter() { |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * TerminationPoint object translation from TE Topology subsystem to YANG. |
| 69 | * |
| 70 | * @param teSubsystem TE Topology subsystem termination point object |
| 71 | * @return TerminationPoint YANG object |
| 72 | */ |
| 73 | public static TerminationPoint teSubsystem2YangTerminationPoint( |
| 74 | org.onosproject.tetopology.management.api.node.TerminationPoint teSubsystem) { |
| 75 | checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_TP); |
| 76 | |
| 77 | TpId tpId = TpId.fromString(teSubsystem.id().toString()); |
| 78 | TerminationPoint.TerminationPointBuilder builder = |
| 79 | new DefaultTerminationPoint.TerminationPointBuilder().tpId(tpId); |
| 80 | |
| 81 | if (teSubsystem.getSupportingTpIds() != null) { |
| 82 | List<SupportingTerminationPoint> tps = Lists.newArrayList(); |
| 83 | SupportingTerminationPoint.SupportingTerminationPointBuilder |
| 84 | spTpBuilder = DefaultSupportingTerminationPoint.builder(); |
| 85 | for (TerminationPointKey tpKey : teSubsystem.getSupportingTpIds()) { |
| 86 | tps.add(spTpBuilder.networkRef(NetworkId.fromString(tpKey.networkId().toString())) |
| 87 | .nodeRef(NodeId.fromString(tpKey.nodeId().toString())) |
| 88 | .tpRef(TpId.fromString(tpKey.tpId().toString())) |
| 89 | .build()); |
| 90 | } |
| 91 | builder = builder.supportingTerminationPoint(tps); |
| 92 | } |
| 93 | |
| 94 | if (teSubsystem.getTe() != null) { |
| 95 | AugmentedNtTerminationPoint.AugmentedNtTerminationPointBuilder |
| 96 | tpAugmentBuilder = DefaultAugmentedNtTerminationPoint.builder(); |
| 97 | |
| 98 | TeTerminationPoint teSubsystemTe = teSubsystem.getTe(); |
| 99 | TeBuilder yangTeBuilder = DefaultTe.builder(); |
| 100 | |
| 101 | if (teSubsystemTe.teTpId() != null) { |
| 102 | yangTeBuilder = yangTeBuilder.teTpId(TeTpId.fromString(teSubsystemTe.teTpId().toString())); |
| 103 | } |
| 104 | |
| 105 | Config yConfig = teSubsystem2YangTeAugConfig(teSubsystemTe); |
| 106 | yangTeBuilder = yangTeBuilder.config(yConfig); |
| 107 | |
| 108 | State yState = teSubsystem2YangTeAugState(teSubsystemTe); |
| 109 | yangTeBuilder = yangTeBuilder.state(yState); |
| 110 | |
| 111 | tpAugmentBuilder = tpAugmentBuilder.te(yangTeBuilder.build()); |
| 112 | builder.addYangAugmentedInfo(tpAugmentBuilder.build(), AugmentedNtTerminationPoint.class); |
| 113 | } |
| 114 | |
| 115 | return builder.build(); |
| 116 | } |
| 117 | |
| 118 | private static State teSubsystem2YangTeAugState(TeTerminationPoint teSubsystemTe) { |
| 119 | State.StateBuilder yangStateBuilder = DefaultState.builder(); |
| 120 | yangStateBuilder.interLayerLockId(teSubsystemTe.getInterLayerLockId()); |
| 121 | |
| 122 | if (teSubsystemTe.interfaceSwitchingCapabilities() != null) { |
| 123 | for (org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability teIsc : |
| 124 | teSubsystemTe.interfaceSwitchingCapabilities()) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame^] | 125 | InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder isc = |
| 126 | DefaultInterfaceSwitchingCapability.builder(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 127 | // FIXME: teIsc at this moment is empty, therefore we cannot |
| 128 | // really add its attributes to isc |
| 129 | yangStateBuilder.addToInterfaceSwitchingCapability(isc.build()); |
| 130 | } |
| 131 | } |
| 132 | return yangStateBuilder.build(); |
| 133 | } |
| 134 | |
| 135 | private static Config teSubsystem2YangTeAugConfig(TeTerminationPoint teSubsystemTe) { |
| 136 | Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder(); |
| 137 | yangConfigBuilder = yangConfigBuilder.interLayerLockId(teSubsystemTe.getInterLayerLockId()); |
| 138 | if (teSubsystemTe.interfaceSwitchingCapabilities() != null) { |
| 139 | for (org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability teIsc : |
| 140 | teSubsystemTe.interfaceSwitchingCapabilities()) { |
| 141 | InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder |
| 142 | isc = DefaultInterfaceSwitchingCapability.builder(); |
| 143 | // FIXME: teIsc at this moment is empty, therefore we cannot |
| 144 | // really add its attributes to isc |
| 145 | yangConfigBuilder = yangConfigBuilder.addToInterfaceSwitchingCapability(isc.build()); |
| 146 | } |
| 147 | } |
| 148 | return yangConfigBuilder.build(); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * TerminationPoint object translation from YANG to TE Topology subsystem. |
| 153 | * |
| 154 | * @param yangTp TerminationPoint YANG object |
| 155 | * @return TerminationPoint TE Topology subsystem termination point object |
| 156 | */ |
| 157 | public static org.onosproject.tetopology.management.api.node.TerminationPoint |
| 158 | yang2teSubsystemTerminationPoint(TerminationPoint yangTp) { |
| 159 | checkNotNull(yangTp, E_NULL_YANG_TP); |
| 160 | |
| 161 | org.onosproject.tetopology.management.api.node.DefaultTerminationPoint tp = new org.onosproject.tetopology |
| 162 | .management.api.node.DefaultTerminationPoint(KeyId.keyId(yangTp.tpId().uri().string())); |
| 163 | |
| 164 | if (yangTp.supportingTerminationPoint() != null) { |
| 165 | List<org.onosproject.tetopology.management.api.node.TerminationPointKey> spTps = Lists.newArrayList(); |
| 166 | for (SupportingTerminationPoint yangSptp : yangTp.supportingTerminationPoint()) { |
| 167 | org.onosproject.tetopology.management.api.node.TerminationPointKey tpKey = |
| 168 | new org.onosproject.tetopology.management.api.node.TerminationPointKey( |
| 169 | KeyId.keyId(yangSptp.networkRef().uri().string()), |
| 170 | KeyId.keyId(yangSptp.nodeRef().uri().string()), |
| 171 | KeyId.keyId(yangSptp.tpRef().uri().string())); |
| 172 | spTps.add(tpKey); |
| 173 | } |
| 174 | tp.setSupportingTpIds(spTps); |
| 175 | } |
| 176 | |
| 177 | if (yangTp.yangAugmentedInfoMap() != null && !yangTp.yangAugmentedInfoMap().isEmpty()) { |
| 178 | AugmentedNtTerminationPoint yangTpAugment = |
| 179 | (AugmentedNtTerminationPoint) yangTp.yangAugmentedInfo(AugmentedNtTerminationPoint.class); |
| 180 | if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) { |
| 181 | KeyId teTpId = KeyId.keyId(yangTpAugment.te().teTpId().toString()); |
| 182 | if (yangTpAugment.te().config() != null) { |
| 183 | long interLayerLockId = yangTpAugment.te().config().interLayerLockId(); |
| 184 | List<org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability> |
| 185 | teIscList = Lists.newArrayList(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 186 | if (yangTpAugment.te().config().interfaceSwitchingCapability() != null) { |
| 187 | for (InterfaceSwitchingCapability iscConfigYang : |
| 188 | yangTpAugment.te().config().interfaceSwitchingCapability()) { |
| 189 | org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability iscTe = |
| 190 | new org.onosproject.tetopology.management.api.node.InterfaceSwitchingCapability(); |
| 191 | // FIXME: at this moment, iscTe does not have any |
| 192 | // attributes. Therefore, I cannot feed it with |
| 193 | // attributes of iscConfigYang |
| 194 | teIscList.add(iscTe); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | TeTerminationPoint teSubsystemTp = new TeTerminationPoint(teTpId, |
| 199 | teIscList, |
| 200 | interLayerLockId); |
| 201 | tp.setTe(teSubsystemTp); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | return tp; |
| 206 | } |
| 207 | |
| 208 | } |