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 | |
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.math.BigDecimal; |
| 21 | import java.math.BigInteger; |
| 22 | import java.util.ArrayList; |
| 23 | import java.util.BitSet; |
| 24 | import java.util.List; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | import org.onlab.packet.Ip4Address; |
| 28 | import org.onosproject.tetopology.management.api.KeyId; |
| 29 | import org.onosproject.tetopology.management.api.TeStatus; |
| 30 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 31 | import org.onosproject.tetopology.management.api.TeTopologyService; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 32 | import org.onosproject.tetopology.management.api.link.CommonLinkData; |
| 33 | import org.onosproject.tetopology.management.api.link.DefaultNetworkLink; |
| 34 | import org.onosproject.tetopology.management.api.link.DefaultTeLink; |
| 35 | import org.onosproject.tetopology.management.api.link.ElementType; |
| 36 | import org.onosproject.tetopology.management.api.link.ExternalLink; |
| 37 | import org.onosproject.tetopology.management.api.link.LinkBandwidth; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 38 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 39 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 40 | import org.onosproject.tetopology.management.api.link.OduResource; |
| 41 | import org.onosproject.tetopology.management.api.link.PathElement; |
| 42 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 43 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
| 44 | import org.onosproject.tetopology.management.api.link.TeLinkTpKey; |
| 45 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 46 | import org.onosproject.tetopology.management.api.link.TeTunnelId; |
| 47 | import org.onosproject.tetopology.management.api.link.TunnelProtectionType; |
| 48 | import org.onosproject.tetopology.management.api.link.UnderlayBackupPath; |
| 49 | import org.onosproject.tetopology.management.api.link.UnderlayPath; |
| 50 | import org.onosproject.tetopology.management.api.node.NodeTpKey; |
| 51 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 52 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 53 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 54 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 55 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks; |
| 56 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 57 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network; |
| 58 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.network.Node; |
| 59 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 60 | .ietfnetworktopology.LinkId; |
| 61 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 62 | .ietfnetworktopology.TpId; |
| 63 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.AugmentedNdNetwork; |
| 64 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 65 | .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink; |
| 66 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 67 | .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink.LinkBuilder; |
| 68 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 69 | .ietfnetworktopology.networks.network.augmentedndnetwork.Link; |
| 70 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 71 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultDestination; |
| 72 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 73 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSource; |
| 74 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 75 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSupportingLink; |
| 76 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 77 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.Destination |
| 78 | .DestinationBuilder; |
| 79 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 80 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.Source.SourceBuilder; |
| 81 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 82 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink; |
| 83 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 84 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink |
| 85 | .SupportingLinkBuilder; |
| 86 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.node.AugmentedNdNode; |
| 87 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.DefaultTeLinkEvent; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 88 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeLinkEvent; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 89 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState; |
| 90 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.InformationSourceState; |
| 91 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.DefaultTopology; |
| 92 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.Topology; |
| 93 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.AugmentedNwNetwork; |
| 94 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 95 | .ietftetopology.networks.network.link.AugmentedNtLink; |
| 96 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 97 | .ietftetopology.networks.network.link.DefaultAugmentedNtLink; |
| 98 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 99 | .ietftetopology.networks.network.link.DefaultAugmentedNtLink.AugmentedNtLinkBuilder; |
| 100 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.AugmentedNwNode; |
| 101 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint; |
| 102 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe; |
| 103 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe.TeBuilder; |
| 104 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.Config; |
| 105 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig; |
| 106 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig.ConfigBuilder; |
| 107 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState; |
| 108 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState.StateBuilder; |
| 109 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.State; |
| 110 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes; |
| 111 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes.TeLinkAttributesBuilder; |
| 112 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.TeLinkAttributes; |
| 113 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain; |
| 114 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain.ExternalDomainBuilder; |
| 115 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay; |
| 116 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay.UnderlayBuilder; |
| 117 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.ExternalDomain; |
| 118 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs; |
| 119 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs.TeSrlgsBuilder; |
| 120 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth; |
| 121 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth.UnreservedBandwidthBuilder; |
| 122 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.Te; |
| 123 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.TeSrlgs; |
| 124 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.UnreservedBandwidth; |
| 125 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkinfoattributes.LinkProtectionTypeEnum; |
| 126 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayBackupPath; |
| 127 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayBackupPath.UnderlayBackupPathBuilder; |
| 128 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayPrimaryPath; |
| 129 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayPrimaryPath.UnderlayPrimaryPathBuilder; |
| 130 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.UnderlayPrimaryPath; |
| 131 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.underlayprimarypath.DefaultPathElement; |
| 132 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg; |
| 133 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId; |
| 134 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeOperStatus; |
| 135 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType; |
| 136 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId; |
| 137 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.tetopologyeventtype.TeTopologyEventTypeEnum; |
| 138 | |
| 139 | import com.google.common.collect.Lists; |
| 140 | import com.google.common.collect.Maps; |
| 141 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * The conversion functions. |
| 145 | */ |
| 146 | public final class LinkConverter { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 147 | private static final String E_NULL_TELINK_UNDERLAY_PATH = |
| 148 | "TeSubsystem link underlayPath object cannot be null"; |
| 149 | private static final String E_NULL_TELINK_DATA = |
| 150 | "TeSubsystem teLinkAttrBuilder data cannot be null"; |
| 151 | private static final String E_NULL_TELINK = |
| 152 | "TeSubsystem teLink object cannot be null"; |
| 153 | private static final String E_NULL_YANG_TELINK_CONFIG = |
| 154 | "YANG telink config object cannot be null"; |
| 155 | private static final String E_NULL_YANG_TELINK = |
| 156 | "YANG Link object cannot be null"; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 157 | |
| 158 | // no instantiation |
| 159 | private LinkConverter() { |
| 160 | } |
| 161 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 162 | private static LinkProtectionTypeEnum teSubsystem2YangLinkProtectionType(TunnelProtectionType linkProtectionType) { |
| 163 | switch (linkProtectionType) { |
| 164 | case ENHANCED: |
| 165 | return LinkProtectionTypeEnum.ENHANCED; |
| 166 | case EXTRA_TRAFFIC: |
| 167 | return LinkProtectionTypeEnum.EXTRA_TRAFFIC; |
| 168 | case SHARED: |
| 169 | return LinkProtectionTypeEnum.SHARED; |
| 170 | case UNPROTECTED: |
| 171 | return LinkProtectionTypeEnum.UNPROTECTED; |
| 172 | case ONE_FOR_ONE: |
| 173 | return LinkProtectionTypeEnum.YANGAUTOPREFIX1_FOR_1; |
| 174 | case ONE_PLUS_ONE: |
| 175 | return LinkProtectionTypeEnum.YANGAUTOPREFIX1_PLUS_1; |
| 176 | default: |
| 177 | return null; |
| 178 | } |
| 179 | } |
| 180 | /** |
| 181 | * TE Link Config object conversion from TE Topology subsystem to YANG. |
| 182 | * |
| 183 | * @param teLink TE link object |
| 184 | * @return TE Link Config YANG object |
| 185 | */ |
| 186 | private static Config teLink2YangConfig(TeLink teLink) { |
| 187 | checkNotNull(teLink, E_NULL_TELINK_DATA); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 188 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 189 | TeLinkAttributesBuilder attrBuilder = DefaultTeLinkAttributes.builder(); |
| 190 | |
| 191 | if (teLink.teLinkKey() != null) { |
| 192 | // what is link index? for now I used teLinkTpId |
| 193 | attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId())); |
| 194 | } |
| 195 | |
| 196 | if (teLink.adminStatus() != null) { |
| 197 | attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus())); |
| 198 | } |
| 199 | |
| 200 | if (teLink.tunnelProtectionType() != null) { |
| 201 | attrBuilder = attrBuilder |
| 202 | .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink |
| 203 | .tunnelProtectionType())); |
| 204 | } |
| 205 | |
| 206 | attrBuilder = attrBuilder.teDefaultMetric(teLink.cost()); |
| 207 | |
| 208 | if (teLink.srlgs() != null) { |
| 209 | TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder(); |
| 210 | for (Long srlgLongVal : teLink.srlgs()) { |
| 211 | teSrlgsBuilder = teSrlgsBuilder.addToValue(new Srlg(srlgLongVal)); |
| 212 | } |
| 213 | attrBuilder = attrBuilder.teSrlgs(teSrlgsBuilder.build()); |
| 214 | } |
| 215 | attrBuilder = attrBuilder.isAbstract(teLink.flags().get(TeNode.BIT_ABSTRACT)); |
| 216 | |
| 217 | if (teLink.externalLink() != null) { |
| 218 | ExternalDomainBuilder edBuilder = |
| 219 | DefaultExternalDomain.builder(); |
| 220 | if (teLink.externalLink().plugId() != null) { |
| 221 | edBuilder.plugId(teLink.externalLink().plugId()); |
| 222 | } |
| 223 | if (teLink.externalLink().externalLinkKey() != null) { |
| 224 | edBuilder = edBuilder |
| 225 | .remoteTeLinkTpId(TeTpId.fromString( |
| 226 | String.valueOf(teLink |
| 227 | .externalLink() |
| 228 | .externalLinkKey() |
| 229 | .teLinkTpId()))) |
| 230 | .remoteTeNodeId(TeNodeId.fromString( |
| 231 | String.valueOf(teLink |
| 232 | .externalLink() |
| 233 | .externalLinkKey() |
| 234 | .teNodeId()))); |
| 235 | } |
| 236 | attrBuilder = attrBuilder.externalDomain(edBuilder.build()); |
| 237 | } |
| 238 | |
| 239 | if (teLink.availBandwidth() != null) { |
| 240 | short i = 0; |
| 241 | for (float f : teLink.availBandwidth()) { |
| 242 | UnreservedBandwidthBuilder urBuilder = |
| 243 | DefaultUnreservedBandwidth.builder() |
| 244 | .bandwidth(BigDecimal.valueOf(f)) |
| 245 | .priority(i); |
| 246 | i++; |
| 247 | attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build()); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if (teLink.maxBandwidth() != null) { |
| 252 | // maxBandwidth is an array of float[], but in yang is just a big decimal |
| 253 | attrBuilder = attrBuilder.maxLinkBandwidth(BigDecimal.valueOf(teLink.maxBandwidth()[0])); |
| 254 | } |
| 255 | // FIXME: how to retrieve maxResvLinkBandwidth from teLink |
| 256 | // if (teLink.maxResvLinkBandwidth() != null) { |
| 257 | // attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth()); |
| 258 | // } |
| 259 | |
| 260 | UnderlayBuilder builder = DefaultUnderlay.builder(); |
| 261 | if (teLink.primaryPath() != null) { |
| 262 | |
| 263 | // TODO: what is underlayProtectionType in tePath? |
| 264 | // builder = builder.underlayProtectionType(tePath.protectionType()); |
| 265 | |
| 266 | builder = te2YangConfigUnderlayPrimaryPath(builder, teLink); |
| 267 | } |
| 268 | |
| 269 | if (teLink.backupPaths() != null) { |
| 270 | builder = te2YangConfigUnderlayBackupPaths(builder, teLink); |
| 271 | } |
| 272 | |
| 273 | attrBuilder = attrBuilder.underlay(builder.build()); |
| 274 | |
| 275 | ConfigBuilder yangConfigBuilder = DefaultConfig.builder() |
| 276 | .teLinkAttributes(attrBuilder.build()); |
| 277 | return yangConfigBuilder.build(); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * TE Link State object conversion from TE Topology subsystem to YANG. |
| 282 | * |
| 283 | * @param teLink TE link object |
| 284 | * @return TE Link State YANG object |
| 285 | */ |
| 286 | private static State teLink2YangState(TeLink teLink) { |
| 287 | TeLinkAttributes |
| 288 | .TeLinkAttributesBuilder attrBuilder = |
| 289 | DefaultTeLinkAttributes |
| 290 | .builder() |
| 291 | .teDefaultMetric(teLink.cost()) |
| 292 | .isAbstract(teLink.flags().get(TeLink.BIT_ABSTRACT)); |
| 293 | if (teLink.teLinkKey() != null) { |
| 294 | // what is link index? for now I used teLinkTpId |
| 295 | attrBuilder = attrBuilder.linkIndex(BigInteger.valueOf(teLink.teLinkKey().teLinkTpId())); |
| 296 | } |
| 297 | |
| 298 | if (teLink.adminStatus() != null) { |
| 299 | attrBuilder = attrBuilder.adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teLink.adminStatus())); |
| 300 | } |
| 301 | if (teLink.tunnelProtectionType() != null) { |
| 302 | attrBuilder = attrBuilder |
| 303 | .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink |
| 304 | .tunnelProtectionType())); |
| 305 | } |
| 306 | // FIXME: maxBandwidth stuff are array[] in TE but not in yang... |
| 307 | // if (teLink.maxLinkBandwidth() != null) { |
| 308 | // attrBuilder = attrBuilder.maxLinkBandwidth(teLink.maxLinkBandwidth()); |
| 309 | // } |
| 310 | // if (teLink.maxResvLinkBandwidth() != null) { |
| 311 | // attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth()); |
| 312 | // } |
| 313 | if (teLink.srlgs() != null) { |
| 314 | TeSrlgs.TeSrlgsBuilder srlgsBuilder = DefaultTeSrlgs.builder(); |
| 315 | for (Long srlgLongVal : teLink.srlgs()) { |
| 316 | srlgsBuilder = srlgsBuilder.addToValue(new Srlg(srlgLongVal)); |
| 317 | } |
| 318 | attrBuilder = attrBuilder.teSrlgs(srlgsBuilder.build()); |
| 319 | } |
| 320 | |
| 321 | if (teLink.externalLink() != null) { |
| 322 | ExternalDomain.ExternalDomainBuilder edBuilder = DefaultExternalDomain |
| 323 | .builder(); |
| 324 | if (teLink.externalLink().plugId() != null) { |
| 325 | edBuilder = edBuilder.plugId(teLink.externalLink().plugId()); |
| 326 | } |
| 327 | if (teLink.externalLink().externalLinkKey() != null) { |
| 328 | edBuilder = edBuilder |
| 329 | .remoteTeLinkTpId(TeTpId.fromString(String.valueOf(teLink |
| 330 | .externalLink() |
| 331 | .externalLinkKey() |
| 332 | .teLinkTpId()))) |
| 333 | .remoteTeNodeId(TeNodeId.fromString(String.valueOf(teLink |
| 334 | .externalLink() |
| 335 | .externalLinkKey() |
| 336 | .teNodeId()))); |
| 337 | } |
| 338 | attrBuilder = attrBuilder.externalDomain(edBuilder.build()); |
| 339 | |
| 340 | } |
| 341 | |
| 342 | if (teLink.availBandwidth() != null) { |
| 343 | short i = 0; |
| 344 | for (float f : teLink.availBandwidth()) { |
| 345 | UnreservedBandwidth.UnreservedBandwidthBuilder urBuilder = DefaultUnreservedBandwidth |
| 346 | .builder() |
| 347 | .bandwidth(BigDecimal.valueOf(f)) |
| 348 | .priority(i); |
| 349 | i++; |
| 350 | attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build()); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | StateBuilder yangStateBuilder = DefaultState.builder() |
| 355 | .teLinkAttributes(attrBuilder.build()); |
| 356 | if (teLink.opStatus() != null) { |
| 357 | yangStateBuilder = yangStateBuilder.operStatus(EnumConverter |
| 358 | .teSubsystem2YangOperStatus(teLink.opStatus())); |
| 359 | } |
| 360 | |
| 361 | if (teLink.sourceTeLinkId() != null) { |
| 362 | InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder(); |
| 363 | |
| 364 | Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder(); |
| 365 | topologyBuilder = topologyBuilder.clientIdRef(teLink.sourceTeLinkId().clientId()) |
| 366 | .providerIdRef(teLink.sourceTeLinkId().providerId()) |
| 367 | .teTopologyIdRef(teLink.sourceTeLinkId().topologyId()); |
| 368 | issBuilder = issBuilder.topology(topologyBuilder.build()); |
| 369 | yangStateBuilder.informationSourceState(issBuilder.build()); |
| 370 | } |
| 371 | |
| 372 | // Once stateDerived underlay is available in yang and core TE Topology |
| 373 | // object model, set the value properly |
| 374 | // stateDerivedUnderlay = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology |
| 375 | // .rev20160708.ietftetopology.telinkstatederived.Underlay |
| 376 | // yangStateBuilder = yangStateBuilder.underlay(stateDerivedUnderlay); |
| 377 | |
| 378 | return yangStateBuilder.build(); |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Link object conversion from TE Topology subsystem to YANG. |
| 383 | * |
| 384 | * @param teSubsNetworkLink TE subsystem link object |
| 385 | * @return YANG link object |
| 386 | */ |
| 387 | public static Link teSubsystem2YangLink( |
| 388 | org.onosproject.tetopology.management.api.link.NetworkLink teSubsNetworkLink) { |
| 389 | checkNotNull(teSubsNetworkLink, E_NULL_TELINK); |
| 390 | |
| 391 | LinkId linkId = LinkId.fromString(teSubsNetworkLink.linkId().toString()); |
| 392 | LinkBuilder builder = DefaultLink.builder().linkId(linkId); |
| 393 | if (teSubsNetworkLink.supportingLinkIds() != null) { |
| 394 | List<SupportingLink> slinks = Lists.newArrayList(); |
| 395 | SupportingLinkBuilder spLinkBuilder = DefaultSupportingLink.builder(); |
| 396 | for (NetworkLinkKey linkKey : teSubsNetworkLink.supportingLinkIds()) { |
| 397 | slinks.add(spLinkBuilder.networkRef(NetworkId.fromString( |
| 398 | linkKey.networkId().toString())) |
| 399 | .linkRef(LinkId.fromString( |
| 400 | linkKey.linkId().toString())) |
| 401 | .build()); |
| 402 | } |
| 403 | builder = builder.supportingLink(slinks); |
| 404 | } |
| 405 | if (teSubsNetworkLink.source() != null) { |
| 406 | SourceBuilder sourceBuilder = DefaultSource |
| 407 | .builder() |
| 408 | .sourceNode(NodeId.fromString( |
| 409 | teSubsNetworkLink.source().nodeId().toString())) |
| 410 | .sourceTp(TpId.fromString( |
| 411 | teSubsNetworkLink.source().tpId().toString())); |
| 412 | builder = builder.source(sourceBuilder.build()); |
| 413 | } |
| 414 | if (teSubsNetworkLink.destination() != null) { |
| 415 | DestinationBuilder destBuilder = DefaultDestination |
| 416 | .builder() |
| 417 | .destNode(NodeId.fromString( |
| 418 | teSubsNetworkLink.destination().nodeId().toString())) |
| 419 | .destTp(TpId.fromString( |
| 420 | teSubsNetworkLink.destination().tpId().toString())); |
| 421 | builder = builder.destination(destBuilder.build()); |
| 422 | } |
| 423 | |
| 424 | if (teSubsNetworkLink.teLink() != null) { |
| 425 | TeLink teData = teSubsNetworkLink.teLink(); |
| 426 | TeBuilder yangTeBuilder = DefaultTe.builder() |
| 427 | .config(teLink2YangConfig(teData)) |
| 428 | .state(teLink2YangState(teData)); |
| 429 | // ignoring supportingTeLinkId when converting from core to yang? |
| 430 | // if (teData.supportingTeLinkId() != null) { |
| 431 | // } |
| 432 | AugmentedNtLinkBuilder linkAugmentBuilder = |
| 433 | DefaultAugmentedNtLink.builder() |
| 434 | .te(yangTeBuilder.build()); |
| 435 | builder.addYangAugmentedInfo(linkAugmentBuilder.build(), AugmentedNtLink.class); |
| 436 | } |
| 437 | |
| 438 | return builder.build(); |
| 439 | } |
| 440 | |
| 441 | private static UnderlayBuilder te2YangConfigUnderlayPrimaryPath( |
| 442 | UnderlayBuilder yangBuilder, |
| 443 | TeLink teLink) { |
| 444 | |
| 445 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath tePath = teLink.primaryPath(); |
| 446 | |
| 447 | UnderlayPrimaryPathBuilder pathBuilder = |
| 448 | DefaultUnderlayPrimaryPath.builder(); |
| 449 | if (tePath.pathElements() != null) { |
| 450 | for (PathElement pathElementTe : tePath.pathElements()) { |
| 451 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 452 | .ietftetopology.telinkunderlayattributes.underlayprimarypath.PathElement |
| 453 | .PathElementBuilder pathElementYangBuilder = DefaultPathElement.builder(); |
| 454 | |
| 455 | pathElementYangBuilder = pathElementYangBuilder.pathElementId(pathElementTe.pathElementId()); |
| 456 | //TODO: add some Type cross converter |
| 457 | // pathElementYangBuilder = pathElementYangBuilder.type(Type pathElementTe.type()) |
| 458 | |
| 459 | pathBuilder = pathBuilder.addToPathElement(pathElementYangBuilder.build()); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | pathBuilder = pathBuilder.clientIdRef(teLink.underlayTeTopologyId().clientId()) |
| 464 | .providerIdRef(teLink.underlayTeTopologyId().providerId()) |
| 465 | .teTopologyIdRef(teLink.underlayTeTopologyId().topologyId()); |
| 466 | |
| 467 | // TODO: get networkRefId from service |
| 468 | // pathBuilder = pathBuilder.networkIdRef(networkIdRef); |
| 469 | |
| 470 | return yangBuilder.underlayPrimaryPath(pathBuilder.build()); |
| 471 | } |
| 472 | |
| 473 | private static UnderlayBuilder te2YangConfigUnderlayBackupPaths(UnderlayBuilder yangBuilder, |
| 474 | TeLink teLink) { |
| 475 | List<UnderlayBackupPath> tePaths = teLink.backupPaths(); |
| 476 | |
| 477 | for (UnderlayBackupPath tePath : tePaths) { |
| 478 | UnderlayBackupPathBuilder pathBuilder = DefaultUnderlayBackupPath |
| 479 | .builder(); |
| 480 | pathBuilder = pathBuilder.index(tePath.index()); |
| 481 | pathBuilder = pathBuilder.clientIdRef(teLink.underlayTeTopologyId().clientId()) |
| 482 | .providerIdRef(teLink.underlayTeTopologyId().providerId()) |
| 483 | .teTopologyIdRef(teLink.underlayTeTopologyId().topologyId()); |
| 484 | // TODO: find networkIdRef from the service |
| 485 | // pathBuilder = pathBuilder.networkIdRef(networkIdRef); |
| 486 | |
| 487 | for (PathElement backupPathElementTe : tePath.pathElements()) { |
| 488 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 489 | .ietftetopology.telinkunderlayattributes.underlaybackuppath.PathElement |
| 490 | .PathElementBuilder elementBuilder = |
| 491 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 492 | .ietftetopology.telinkunderlayattributes.underlaybackuppath.DefaultPathElement |
| 493 | .builder(); |
| 494 | |
| 495 | elementBuilder = elementBuilder.pathElementId(backupPathElementTe.pathElementId()); |
| 496 | // TODO: add some Type cross conversion |
| 497 | // elementBuilder.type(type); |
| 498 | |
| 499 | pathBuilder = pathBuilder |
| 500 | .addToPathElement(elementBuilder.build()); |
| 501 | } |
| 502 | yangBuilder = yangBuilder |
| 503 | .addToUnderlayBackupPath(pathBuilder.build()); |
| 504 | } |
| 505 | |
| 506 | return yangBuilder; |
| 507 | } |
| 508 | |
| 509 | private static TeLink yang2TeLinkAttributes(TeLinkAttributes yangLinkAttr, |
| 510 | State opState, Link yangLink, |
| 511 | Network yangNetwork, |
| 512 | Networks yangNetworks) { |
| 513 | TeNodeId teNodeId = findTeNodeId(yangNetwork, |
| 514 | yangLink.source().sourceNode(), |
| 515 | yangLink.source().sourceTp()); |
| 516 | long teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string()).toInt(); |
| 517 | |
| 518 | TeLinkTpKey teLinkKey = new TeLinkTpKey(teNodeIdLong, |
| 519 | findTeTpId(yangNetwork, |
| 520 | yangLink.source().sourceNode(), |
| 521 | yangLink.source().sourceTp())); |
| 522 | |
| 523 | TeNodeId teNodeIdDest = findTeNodeId(yangNetwork, |
| 524 | yangLink.destination().destNode(), |
| 525 | yangLink.destination().destTp()); |
| 526 | long teNodeIdDestLong = Ip4Address.valueOf(teNodeIdDest.dottedQuad().string()).toInt(); |
| 527 | |
| 528 | TeLinkTpKey peerTeLinkKey = new TeLinkTpKey(teNodeIdDestLong, |
| 529 | findTeTpId(yangNetwork, |
| 530 | yangLink.destination().destNode(), |
| 531 | yangLink.destination().destTp())); |
| 532 | |
| 533 | TeLinkTpGlobalKey supportTeLinkId = findSupportTeLinkId(yangNetworks, yangLink); |
| 534 | |
| 535 | org.onosproject.tetopology.management.api.TeStatus opStatus = null; |
| 536 | if (opState != null && opState.operStatus() != null) { |
| 537 | opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState.operStatus()); |
| 538 | } |
| 539 | |
| 540 | |
| 541 | TeLink teLink = yangLinkAttr2TeLinkAttributes(yangLinkAttr, opStatus, teNodeIdLong, teNodeIdDestLong, teLinkKey, |
| 542 | peerTeLinkKey, supportTeLinkId); |
| 543 | |
| 544 | return teLink; |
| 545 | } |
| 546 | |
| 547 | private static TeLink yangLinkAttr2TeLinkAttributes(TeLinkAttributes yangLinkAtrr, |
| 548 | org.onosproject.tetopology.management.api.TeStatus opStatus, |
| 549 | long teNodeIdLong, |
| 550 | long teNodeIdDestLong, |
| 551 | TeLinkTpKey teLinkKey, |
| 552 | TeLinkTpKey peerTeLinkKey, |
| 553 | TeLinkTpGlobalKey supportTeLinkId) { |
| 554 | org.onosproject.tetopology.management.api.TeStatus adminStatus = null; |
| 555 | |
| 556 | TeLinkTpGlobalKey sourceTeLinkId = null; // from yang to core, we can ignore sourceTeLinkId |
| 557 | TeTopologyKey underlayTopologyId = null; |
| 558 | CommonLinkData teData = null; |
| 559 | |
| 560 | underlayTopologyId = new TeTopologyKey((long) yangLinkAtrr.underlay().underlayPrimaryPath().providerIdRef(), |
| 561 | (long) yangLinkAtrr.underlay().underlayPrimaryPath().clientIdRef(), |
| 562 | (long) yangLinkAtrr.underlay().underlayPrimaryPath().teTopologyIdRef()); |
| 563 | |
| 564 | if (yangLinkAtrr.adminStatus() != null) { |
| 565 | adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangLinkAtrr.adminStatus()); |
| 566 | } |
| 567 | |
| 568 | BitSet flags = new BitSet(); |
| 569 | if (yangLinkAtrr.isAbstract()) { |
| 570 | flags.set(TeLink.BIT_ABSTRACT); |
| 571 | } |
| 572 | |
| 573 | ExternalLink externalLink = new ExternalLink(null, yangLinkAtrr.externalDomain().plugId()); |
| 574 | |
| 575 | UnderlayPath underlayPath = null; |
| 576 | underlayPath = yang2TeSubsystemUnderlayPath(yangLinkAtrr, teNodeIdLong, |
| 577 | teNodeIdDestLong); |
| 578 | Long adminGroup = Long.valueOf(yangLinkAtrr.administrativeGroup().toString()); |
| 579 | List<Long> interLayerLocks = null; // FIXME: how to find interLayerLocks? |
| 580 | |
| 581 | List<UnreservedBandwidth> listOfUnreservedBandwidth = yangLinkAtrr.unreservedBandwidth(); |
| 582 | float[] availBandwidth = new float[listOfUnreservedBandwidth.size()]; |
| 583 | int i = 0; |
| 584 | for (UnreservedBandwidth urbw : listOfUnreservedBandwidth) { |
| 585 | availBandwidth[i] = urbw.bandwidth().floatValue(); |
| 586 | i++; |
| 587 | } |
| 588 | |
| 589 | float[] maxBandwidth = new float[1]; |
| 590 | maxBandwidth[0] = yangLinkAtrr.maxLinkBandwidth().floatValue(); |
| 591 | |
| 592 | float[] maxAvailLspBandwidth = null; // FIXME: how to find this? |
| 593 | float[] minAvailLspBandwidth = null; // FIXME: how to find this? |
| 594 | LinkBandwidth bandwidth = new LinkBandwidth( |
| 595 | maxBandwidth, |
| 596 | availBandwidth, |
| 597 | maxAvailLspBandwidth, |
| 598 | minAvailLspBandwidth, |
| 599 | null); // FIXME: how to find odu resource? |
| 600 | List<Long> srlgs = Lists.newArrayList(); |
| 601 | for (Srlg srlg : yangLinkAtrr.teSrlgs().value()) { |
| 602 | srlgs.add(srlg.uint32()); |
| 603 | } |
| 604 | TePathAttributes teAttributes = |
| 605 | new TePathAttributes(yangLinkAtrr.teDefaultMetric(), |
| 606 | yangLinkAtrr.performanceMetric().measurement().unidirectionalDelay(), |
| 607 | srlgs); |
| 608 | teData = new CommonLinkData(adminStatus, |
| 609 | opStatus, |
| 610 | flags, |
| 611 | null, // switchingLayer |
| 612 | null, // encodingLayer |
| 613 | externalLink, |
| 614 | underlayPath, |
| 615 | teAttributes, |
| 616 | adminGroup, |
| 617 | interLayerLocks, |
| 618 | bandwidth); |
| 619 | |
| 620 | TeLink te = new DefaultTeLink(teLinkKey, peerTeLinkKey, |
| 621 | underlayTopologyId, supportTeLinkId, |
| 622 | sourceTeLinkId, teData); |
| 623 | return te; |
| 624 | } |
| 625 | |
| 626 | private static TeLinkTpGlobalKey findSupportTeLinkId(Networks yangNetworks, |
| 627 | Link yangLink) { |
| 628 | Network teNetworkFound = null; |
| 629 | LinkId teLinkIdFound = null; |
| 630 | for (Network ynetItem : yangNetworks.network()) { |
| 631 | if (ynetItem.networkId().equals(yangLink.supportingLink().get(0).networkRef())) { |
| 632 | teNetworkFound = ynetItem; |
| 633 | teLinkIdFound = yangLink.supportingLink().get(0).linkRef(); |
| 634 | break; |
| 635 | } |
| 636 | } |
| 637 | Link teLinkFound = null; |
| 638 | if (teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class) != null) { |
| 639 | AugmentedNdNetwork augmentLink = |
| 640 | (AugmentedNdNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class); |
| 641 | for (Link link : augmentLink.link()) { |
| 642 | if (link.linkId().equals(teLinkIdFound)) { |
| 643 | teLinkFound = link; |
| 644 | break; |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | TeNodeId teSupportNodeId = findTeNodeId(teNetworkFound, |
| 650 | teLinkFound.source().sourceNode(), |
| 651 | teLinkFound.source().sourceTp()); |
| 652 | long tenIdLong = Ip4Address.valueOf(teSupportNodeId.dottedQuad().string()).toInt(); |
| 653 | long teSupportLinkTpId = findTeTpId(teNetworkFound, |
| 654 | teLinkFound.source().sourceNode(), |
| 655 | teLinkFound.source().sourceTp()); |
| 656 | |
| 657 | org.onosproject.tetopology.management.api.TeTopologyId teTopologyId = null; |
| 658 | if (teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class) != null) { |
| 659 | AugmentedNwNetwork augmentTeIds = |
| 660 | (AugmentedNwNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class); |
| 661 | teTopologyId = |
| 662 | new org.onosproject.tetopology.management.api.TeTopologyId( |
| 663 | augmentTeIds.te().clientId().uint32(), |
| 664 | augmentTeIds.te().providerId().uint32(), |
| 665 | augmentTeIds.te().teTopologyId().string()); |
| 666 | } |
| 667 | |
| 668 | TeLinkTpGlobalKey supportTeLinkId = new TeLinkTpGlobalKey(teTopologyId.providerId(), |
| 669 | teTopologyId.clientId(), |
| 670 | Long.valueOf(teTopologyId |
| 671 | .topologyId()), |
| 672 | tenIdLong, teSupportLinkTpId); |
| 673 | |
| 674 | return supportTeLinkId; |
| 675 | } |
| 676 | |
| 677 | private static TeNodeId findTeNodeId(Network yangNetwork, NodeId yangNodeId, TpId yangTpId) { |
| 678 | TeNodeId teNodeId = null; |
| 679 | for (Node node : yangNetwork.node()) { |
| 680 | if (node.nodeId().equals(yangNodeId)) { |
| 681 | if (node.yangAugmentedInfoMap() != null |
| 682 | && !node.yangAugmentedInfoMap().isEmpty()) { |
| 683 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) node |
| 684 | .yangAugmentedInfo(AugmentedNwNode.class); |
| 685 | if (yangNodeAugment != null && yangNodeAugment.te() != null |
| 686 | && yangNodeAugment.te().teNodeId() != null) { |
| 687 | Te yangNodeAugTe = yangNodeAugment.te(); |
| 688 | teNodeId = yangNodeAugTe.teNodeId(); |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | return teNodeId; |
| 694 | } |
| 695 | |
| 696 | private static long findTeTpId(Network yangNetwork, NodeId yangNodeId, TpId yangTpId) { |
| 697 | long teTpId = 0; |
| 698 | for (Node node : yangNetwork.node()) { |
| 699 | if (node.nodeId().equals(yangNodeId)) { |
| 700 | if (node.yangAugmentedInfoMap() != null |
| 701 | && !node.yangAugmentedInfoMap().isEmpty()) { |
| 702 | |
| 703 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) node |
| 704 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 705 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 706 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 707 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 708 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 709 | if (yangTpnode.tpId().equals(yangTpId)) { |
| 710 | if (yangTpnode.yangAugmentedInfoMap() != null |
| 711 | && !yangTpnode.yangAugmentedInfoMap() |
| 712 | .isEmpty()) { |
| 713 | AugmentedNtTerminationPoint yangTpAugment = |
| 714 | (AugmentedNtTerminationPoint) yangTpnode |
| 715 | .yangAugmentedInfo(AugmentedNtTerminationPoint.class); |
| 716 | if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) { |
| 717 | teTpId = Long.valueOf(yangTpAugment.te().teTpId().toString()); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | return teTpId; |
| 727 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 728 | /** |
| 729 | * Link object conversion from YANG to TE Topology subsystem. |
| 730 | * |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 731 | * @param yangLink YANG link |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 732 | * @param yangNetwork YANG network |
| 733 | * @param yangNetworks YANG networks |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 734 | * @return TE subsystem link |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 735 | */ |
| 736 | public static org.onosproject.tetopology.management.api.link.NetworkLink |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 737 | yang2TeSubsystemLink(Link yangLink, Network yangNetwork, |
| 738 | Networks yangNetworks) { |
| 739 | NetworkId networkId = yangNetwork.networkId(); |
| 740 | checkNotNull(yangLink, E_NULL_YANG_TELINK); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 741 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 742 | KeyId linkId = KeyId.keyId(yangLink.linkId().uri().toString()); |
| 743 | NodeTpKey sourceNodeTpKey = null; |
| 744 | NodeTpKey destinationNodeTpKey = null; |
| 745 | List<NetworkLinkKey> spLinkIds = null; |
| 746 | TeLink te = null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 747 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 748 | if (yangLink.supportingLink() != null) { |
| 749 | spLinkIds = Lists.newArrayList(); |
| 750 | for (SupportingLink yangSpLink : yangLink.supportingLink()) { |
| 751 | NetworkLinkKey linkKey = new NetworkLinkKey(KeyId.keyId(yangSpLink.networkRef().uri().toString()), |
| 752 | KeyId.keyId(yangSpLink.linkRef().uri().toString())); |
| 753 | spLinkIds.add(linkKey); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | if (yangLink.source() != null) { |
| 758 | TerminationPointKey source = new TerminationPointKey( |
| 759 | KeyId.keyId(networkId.uri().toString()), |
| 760 | KeyId.keyId(yangLink.source().sourceNode().uri().toString()), |
| 761 | KeyId.keyId(yangLink.source().sourceTp().uri().toString())); |
| 762 | sourceNodeTpKey = new NodeTpKey(source.nodeId(), source.tpId()); |
| 763 | } |
| 764 | |
| 765 | if (yangLink.destination() != null) { |
| 766 | TerminationPointKey destination = new TerminationPointKey( |
| 767 | KeyId.keyId(networkId.uri().toString()), |
| 768 | KeyId.keyId(yangLink.destination().destNode().uri().toString()), |
| 769 | KeyId.keyId(yangLink.destination().destTp().uri().toString())); |
| 770 | destinationNodeTpKey = new NodeTpKey(destination.nodeId(), destination.tpId()); |
| 771 | } |
| 772 | |
| 773 | if (yangLink.yangAugmentedInfoMap() != null && !yangLink.yangAugmentedInfoMap().isEmpty()) { |
| 774 | |
| 775 | AugmentedNtLink yangLinkAugment = |
| 776 | (AugmentedNtLink) yangLink.yangAugmentedInfo(AugmentedNtLink.class); |
| 777 | if (yangLinkAugment != null && |
| 778 | yangLinkAugment.te() != null && |
| 779 | yangLinkAugment.te().config() != null) { |
| 780 | TeLinkAttributes yangLinkAtrr = |
| 781 | yangLinkAugment.te().config().teLinkAttributes(); |
| 782 | if (yangLinkAtrr != null && yangLinkAtrr.linkIndex() != null) { |
| 783 | te = yang2TeLinkAttributes(yangLinkAtrr, |
| 784 | yangLinkAugment.te().state(), |
| 785 | yangLink, yangNetwork, |
| 786 | yangNetworks); |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | org.onosproject.tetopology.management.api.link.DefaultNetworkLink link = |
| 792 | new DefaultNetworkLink(linkId, |
| 793 | sourceNodeTpKey, |
| 794 | destinationNodeTpKey, |
| 795 | spLinkIds, |
| 796 | te); |
| 797 | return link; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 798 | } |
| 799 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 800 | private static org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath |
| 801 | yang2TeSubsystemUnderlayPrimaryPath(UnderlayPrimaryPath yangpath, |
| 802 | long teNodeId) { |
| 803 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath teUnderlayPrimaryPath = null; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 804 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 805 | List<PathElement> pathElementList = Lists.newArrayList(); |
| 806 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 807 | .telinkunderlayattributes.underlayprimarypath. |
| 808 | PathElement pathElementConfigYang : yangpath.pathElement()) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 809 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 810 | // TODO: find the proper type (ElementType) from pathElementConfigYang.type() |
| 811 | PathElement tePathElement = new PathElement(pathElementConfigYang.pathElementId(), |
| 812 | teNodeId, |
| 813 | null, |
| 814 | false); // FIXME: how to find the proper value for loose? |
| 815 | pathElementList.add(tePathElement); |
| 816 | } |
| 817 | |
| 818 | teUnderlayPrimaryPath = new org.onosproject.tetopology.management.api.link. |
| 819 | UnderlayPrimaryPath(pathElementList, false); // FIXME: how to find the proper value for loose? |
| 820 | |
| 821 | return teUnderlayPrimaryPath; |
| 822 | } |
| 823 | |
| 824 | private static List<UnderlayBackupPath> |
| 825 | yang2TeSubsystemUnderlayBackupPaths( |
| 826 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 827 | rev20160708.ietftetopology.telinkunderlayattributes. |
| 828 | UnderlayBackupPath> yangpaths, |
| 829 | long teNodeId) { |
| 830 | |
| 831 | List<UnderlayBackupPath> underlayBackupPathsList = Lists.newArrayList(); |
| 832 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 833 | .ietftetopology.telinkunderlayattributes. |
| 834 | UnderlayBackupPath yangConfig : yangpaths) { |
| 835 | UnderlayBackupPath ubp = null; |
| 836 | List<PathElement> backupPathElementList = Lists.newArrayList(); |
| 837 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 838 | .telinkunderlayattributes.underlaybackuppath. |
| 839 | PathElement pathElementBackupYang : yangConfig.pathElement()) { |
| 840 | |
| 841 | PathElement tePathElementBackup = new PathElement(pathElementBackupYang.pathElementId(), |
| 842 | teNodeId, |
| 843 | null, // FIXME: find the proper ElementType |
| 844 | // from pathElementBackupYang.type() |
| 845 | false); // FIXME: find the proper value for loose |
| 846 | backupPathElementList.add(tePathElementBackup); |
| 847 | } |
| 848 | ubp = new UnderlayBackupPath(yangConfig.index(), |
| 849 | backupPathElementList, |
| 850 | null); // FIXME: find the proper value for loose |
| 851 | underlayBackupPathsList.add(ubp); |
| 852 | } |
| 853 | |
| 854 | return underlayBackupPathsList; |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * TE Link underlay path Config object conversion from YANG to TE Topology subsystem. |
| 859 | * |
| 860 | * @param yangLinkAtrr YANG link Config YANG object |
| 861 | * @return teSubsystem TE underlay path object |
| 862 | */ |
| 863 | private static org.onosproject.tetopology.management.api.link.UnderlayPath |
| 864 | yang2TeSubsystemUnderlayPath(TeLinkAttributes yangLinkAtrr, long srcTeNodeId, long dstTeNodeId) { |
| 865 | |
| 866 | checkNotNull(yangLinkAtrr, E_NULL_YANG_TELINK_CONFIG); |
| 867 | |
| 868 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath underlayPrimaryPath = null; |
| 869 | List<UnderlayBackupPath> underlayBackupPathsList = null; |
| 870 | TeTunnelId teTunnelId = new TeTunnelId(srcTeNodeId, dstTeNodeId, 0); // FIXME: how to find teTunnelId? |
| 871 | |
| 872 | if (yangLinkAtrr.underlay().underlayPrimaryPath() != null) { |
| 873 | underlayPrimaryPath = |
| 874 | yang2TeSubsystemUnderlayPrimaryPath(yangLinkAtrr.underlay().underlayPrimaryPath(), srcTeNodeId); |
| 875 | } |
| 876 | |
| 877 | if (yangLinkAtrr.underlay().underlayBackupPath() != null) { |
| 878 | underlayBackupPathsList = |
| 879 | yang2TeSubsystemUnderlayBackupPaths(yangLinkAtrr.underlay().underlayBackupPath(), srcTeNodeId); |
| 880 | } |
| 881 | |
| 882 | org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay = |
| 883 | new org.onosproject.tetopology.management.api.link. |
| 884 | UnderlayPath(underlayPrimaryPath, |
| 885 | underlayBackupPathsList, |
| 886 | TunnelProtectionType.of(yangLinkAtrr.underlay().underlayProtectionType()), |
| 887 | (long) yangLinkAtrr.underlay().underlayTrailSrc().tpRef(), // Is this correct? |
| 888 | (long) yangLinkAtrr.underlay().underlayTrailDes().tpRef(), // Is this correct? |
| 889 | teTunnelId); |
| 890 | |
| 891 | return teUnderlay; |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * Converts a TE Topology link event from the data format used in |
| 896 | * the core to its corresponding YANG Object (YO) format. |
| 897 | * |
| 898 | * @param eventType Link event type |
| 899 | * @param linkData TE Topology link event data |
| 900 | * @return YANG Object converted from linkData |
| 901 | */ |
| 902 | public static TeLinkEvent teNetworkLink2yangTeLinkEvent(TeTopologyEventTypeEnum eventType, |
| 903 | NetworkLink linkData) { |
| 904 | TeLinkEvent.TeLinkEventBuilder builder = new DefaultTeLinkEvent.TeLinkEventBuilder(); |
| 905 | |
| 906 | TeTopologyEventType yangEventType = new TeTopologyEventType(eventType); |
| 907 | builder.eventType(yangEventType); |
| 908 | LinkId linkId = LinkId.fromString(linkData.linkId().toString()); |
| 909 | builder.linkRef(linkId); |
| 910 | |
| 911 | TeLinkAttributes teLinkAttributes = teLink2YangConfig(linkData.teLink()).teLinkAttributes(); |
| 912 | builder.teLinkAttributes(teLinkAttributes); |
| 913 | |
| 914 | return builder.build(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | public static NetworkLinkKey yangLinkEvent2NetworkLinkKey(TeLinkEvent yangLinkEvent) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 918 | //TODO: Implementation will be submitted as a separate review |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 919 | NetworkId networkRef = (NetworkId) (yangLinkEvent.networkRef()); |
| 920 | LinkId linkRef = (LinkId) (yangLinkEvent.linkRef()); |
| 921 | KeyId networkId = KeyId.keyId(networkRef.uri().toString()); |
| 922 | KeyId linkId = KeyId.keyId(linkRef.uri().toString()); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 923 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 924 | NetworkLinkKey networkLinkKey = new NetworkLinkKey(networkId, linkId); |
| 925 | |
| 926 | return networkLinkKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | public static NetworkLink yangLinkEvent2NetworkLink(TeLinkEvent yangLinkEvent, |
| 930 | TeTopologyService teTopologyService) { |
| 931 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 932 | KeyId linkId = yangLinkEvent2NetworkLinkKey(yangLinkEvent).linkId(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 933 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 934 | org.onosproject.tetopology.management.api. |
| 935 | Network network = teTopologyService.network( |
| 936 | yangLinkEvent2NetworkLinkKey(yangLinkEvent).networkId()); |
| 937 | if (network == null) { |
| 938 | return null; |
| 939 | } |
| 940 | |
| 941 | NetworkLink networkLink = network.link(linkId); |
| 942 | if (networkLink == null) { |
| 943 | return null; |
| 944 | } |
| 945 | |
| 946 | NodeTpKey sourceTp = networkLink.source(); |
| 947 | NodeTpKey destTp = networkLink.destination(); |
| 948 | |
| 949 | List<NetworkLinkKey> supportingLinkIds = networkLink.supportingLinkIds(); |
| 950 | TeLink teLink = networkLink.teLink(); |
| 951 | if (teLink == null) { |
| 952 | return null; |
| 953 | } |
| 954 | |
| 955 | TeOperStatus opState = yangLinkEvent.operStatus(); |
| 956 | org.onosproject.tetopology.management.api. |
| 957 | TeStatus opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState); |
| 958 | |
| 959 | TeLink updatedTeLink = yangLinkEvent2TeLinkAttributes(yangLinkEvent, teLink, opStatus); |
| 960 | |
| 961 | |
| 962 | NetworkLink updatedNetworkLink = new DefaultNetworkLink(linkId, sourceTp, destTp, supportingLinkIds, |
| 963 | updatedTeLink); |
| 964 | |
| 965 | return updatedNetworkLink; |
| 966 | } |
| 967 | |
| 968 | private static TeLink yangLinkEvent2TeLinkAttributes(TeLinkEvent yangLinkEvent, TeLink oldTeLink, TeStatus |
| 969 | opStatus) { |
| 970 | |
| 971 | TeLinkAttributes yangTeLinkAttrs = yangLinkEvent.teLinkAttributes(); |
| 972 | |
| 973 | TeLinkTpKey teLinkKey = oldTeLink.teLinkKey(); |
| 974 | |
| 975 | |
| 976 | long teNodeIdDest = oldTeLink.peerTeLinkKey().teNodeId(); |
| 977 | long teNodeId = oldTeLink.teLinkKey().teNodeId(); |
| 978 | TeLinkTpGlobalKey supportTeLinkId = oldTeLink.supportingTeLinkId(); |
| 979 | TeLinkTpKey peerTeLinkKey = oldTeLink.peerTeLinkKey(); |
| 980 | |
| 981 | TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeId, teNodeIdDest, |
| 982 | teLinkKey, peerTeLinkKey, supportTeLinkId); |
| 983 | |
| 984 | return updatedTeLink; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 985 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 986 | } |