Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame^] | 2 | * Copyright 2016 Open Networking Foundation |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 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 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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.TerminationPointKey; |
| 24 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
| 25 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 26 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 27 | .ietfnetworktopology.TpId; |
| 28 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 29 | .ietfnetworktopology.networks.network.node.augmentedndnode.DefaultTerminationPoint; |
| 30 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 31 | .ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint; |
| 32 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 33 | .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint |
| 34 | .DefaultSupportingTerminationPoint; |
| 35 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 36 | .ietfnetworktopology.networks.network.node.augmentedndnode.terminationpoint |
| 37 | .SupportingTerminationPoint; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 38 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.interfaceswitchingcapabilitylist.DefaultInterfaceSwitchingCapability; |
| 39 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.interfaceswitchingcapabilitylist.InterfaceSwitchingCapability; |
| 40 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110 |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 41 | .ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 42 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110 |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 43 | .ietftetopology.networks.network.node.terminationpoint.DefaultAugmentedNtTerminationPoint; |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 44 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkiscdattributes.DefaultMaxLspBandwidth; |
| 45 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.telinkiscdattributes.MaxLspBandwidth; |
| 46 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.DefaultTe; |
| 47 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.DefaultTe.TeBuilder; |
| 48 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.Config; |
| 49 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.DefaultConfig; |
| 50 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.DefaultState; |
| 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20170110.ietftetopology.teterminationpointaugment.te.State; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 52 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId; |
| 53 | |
| 54 | import com.google.common.collect.Lists; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * The termination point translations. |
| 58 | */ |
| 59 | public final class TerminationPointConverter { |
| 60 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 61 | private static final String E_NULL_TE_SUBSYSTEM_TP = |
| 62 | "TeSubsystem terminationPoint object cannot be null"; |
| 63 | private static final String E_NULL_YANG_TP = |
| 64 | "YANG terminationPoint object cannot be null"; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 65 | |
| 66 | // no instantiation |
| 67 | private TerminationPointConverter() { |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * TerminationPoint object translation from TE Topology subsystem to YANG. |
| 72 | * |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 73 | * @param teSubsystem TE Topology subsystem termination point |
| 74 | * @return Termination point in YANG Java data structure |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 75 | */ |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 76 | public static TerminationPoint teSubsystem2YangTerminationPoint(org.onosproject.tetopology.management.api.node. |
| 77 | TerminationPoint teSubsystem) { |
| 78 | checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_TP); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 79 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 80 | TpId tpId = TpId.fromString(teSubsystem.tpId().toString()); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 81 | // TpId tpId = TpId.fromString("0"); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 82 | TerminationPoint.TerminationPointBuilder builder = |
| 83 | new DefaultTerminationPoint.TerminationPointBuilder().tpId(tpId); |
| 84 | |
| 85 | if (teSubsystem.supportingTpIds() != null) { |
| 86 | List<SupportingTerminationPoint> tps = Lists.newArrayList(); |
| 87 | SupportingTerminationPoint.SupportingTerminationPointBuilder |
| 88 | spTpBuilder = DefaultSupportingTerminationPoint.builder(); |
| 89 | for (TerminationPointKey tpKey : teSubsystem.supportingTpIds()) { |
| 90 | tps.add(spTpBuilder.networkRef(NetworkId.fromString(tpKey.networkId().toString())) |
| 91 | .nodeRef(NodeId.fromString(tpKey.nodeId().toString())) |
| 92 | .tpRef(TpId.fromString(tpKey.tpId().toString())) |
| 93 | .build()); |
| 94 | } |
| 95 | builder = builder.supportingTerminationPoint(tps); |
| 96 | } |
| 97 | |
| 98 | if (teSubsystem.teTpId() != null) { |
| 99 | AugmentedNtTerminationPoint.AugmentedNtTerminationPointBuilder |
| 100 | tpAugmentBuilder = DefaultAugmentedNtTerminationPoint.builder(); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 101 | tpAugmentBuilder.teTpId(TeTpId.fromString((String.valueOf(teSubsystem.teTpId())))); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 102 | TeBuilder yangTeBuilder = DefaultTe.builder(); |
| 103 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 104 | // Config yConfig = teSubsystem2YangTeAugConfig(teSubsystem); |
| 105 | // yangTeBuilder = yangTeBuilder.config(yConfig); |
| 106 | // |
| 107 | // State yState = teSubsystem2YangTeAugState(teSubsystem); |
| 108 | // yangTeBuilder = yangTeBuilder.state(yState); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 109 | |
| 110 | tpAugmentBuilder = tpAugmentBuilder.te(yangTeBuilder.build()); |
| 111 | builder.addYangAugmentedInfo(tpAugmentBuilder.build(), AugmentedNtTerminationPoint.class); |
| 112 | } |
| 113 | |
| 114 | return builder.build(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 117 | private static State teSubsystem2YangTeAugState(org.onosproject.tetopology.management.api.node. |
| 118 | TerminationPoint teSubsystemTe) { |
| 119 | State.StateBuilder yangStateBuilder = DefaultState.builder(); |
| 120 | // FIXME: interLayerLocks is a list in core but not in yang |
| 121 | // yangStateBuilder = yangStateBuilder.interLayerLockId(teLink.interLayerLocks().get(0)); |
| 122 | |
| 123 | return yangStateBuilder.build(); |
| 124 | } |
| 125 | |
| 126 | private static Config teSubsystem2YangTeAugConfig(org.onosproject.tetopology.management.api.node. |
| 127 | TerminationPoint teSubsystemTe) { |
| 128 | Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder(); |
| 129 | //FIXME: interLayerLocks is a list in core but not in yang |
| 130 | // yangConfigBuilder = |
| 131 | // yangConfigBuilder.interLayerLockId(teLink.interLayerLocks().get(0)); |
| 132 | |
| 133 | InterfaceSwitchingCapability.InterfaceSwitchingCapabilityBuilder isc = |
| 134 | DefaultInterfaceSwitchingCapability.builder(); |
| 135 | |
| 136 | MaxLspBandwidth.MaxLspBandwidthBuilder maxlspBW = DefaultMaxLspBandwidth |
| 137 | .builder(); |
| 138 | // for (float f : teLink.maxAvialLspBandwidth()) { |
| 139 | // // is converting from float to long ok? |
| 140 | // maxlspBW = maxlspBW.bandwidth(BigDecimal.valueOf((long) f)); |
| 141 | // isc = isc.addToMaxLspBandwidth(maxlspBW.build()); |
| 142 | // } |
| 143 | |
| 144 | yangConfigBuilder = yangConfigBuilder.addToInterfaceSwitchingCapability(isc.build()); |
| 145 | |
| 146 | return yangConfigBuilder.build(); |
| 147 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * TerminationPoint object translation from YANG to TE Topology subsystem. |
| 151 | * |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 152 | * @param yangTp Termination point in YANG Java data structure |
| 153 | * @return TerminationPoint TE Topology subsystem termination point |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 154 | */ |
| 155 | public static org.onosproject.tetopology.management.api.node.TerminationPoint |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 156 | yang2teSubsystemTerminationPoint(TerminationPoint yangTp) { |
| 157 | checkNotNull(yangTp, E_NULL_YANG_TP); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 158 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 159 | org.onosproject.tetopology.management.api.node.DefaultTerminationPoint tp = null; |
| 160 | List<org.onosproject.tetopology.management.api.node.TerminationPointKey> spTps = null; |
| 161 | KeyId teTpId = null; |
| 162 | |
| 163 | if (yangTp.supportingTerminationPoint() != null) { |
| 164 | spTps = Lists.newArrayList(); |
| 165 | for (SupportingTerminationPoint yangSptp : yangTp.supportingTerminationPoint()) { |
| 166 | org.onosproject.tetopology.management.api.node.TerminationPointKey tpKey = |
| 167 | new org.onosproject.tetopology.management.api.node.TerminationPointKey( |
| 168 | KeyId.keyId(yangSptp.networkRef().uri().string()), |
| 169 | KeyId.keyId(yangSptp.nodeRef().uri().string()), |
| 170 | KeyId.keyId(yangSptp.tpRef().uri().string())); |
| 171 | spTps.add(tpKey); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (yangTp.yangAugmentedInfoMap() != null && !yangTp.yangAugmentedInfoMap().isEmpty()) { |
| 176 | AugmentedNtTerminationPoint yangTpAugment = |
| 177 | (AugmentedNtTerminationPoint) yangTp.yangAugmentedInfo(AugmentedNtTerminationPoint.class); |
Hesam Rahimi | 01f6ae0 | 2017-02-01 13:57:00 -0500 | [diff] [blame] | 178 | if (yangTpAugment.teTpId() != null) { |
| 179 | teTpId = KeyId.keyId(yangTpAugment.teTpId().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | tp = new org.onosproject.tetopology.management.api.node |
| 184 | .DefaultTerminationPoint(KeyId.keyId(yangTp.tpId().uri().string()), |
| 185 | spTps, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame] | 186 | teTpId == null ? null : Long.valueOf(teTpId.toString())); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 187 | return tp; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | } |