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