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; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 36 | import org.onosproject.tetopology.management.api.link.NetworkLinkEventSubject; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 37 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 38 | import org.onosproject.tetopology.management.api.link.PathElement; |
| 39 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 40 | import org.onosproject.tetopology.management.api.link.TeLinkTpGlobalKey; |
| 41 | import org.onosproject.tetopology.management.api.link.TeLinkTpKey; |
| 42 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 43 | import org.onosproject.tetopology.management.api.link.TeTunnelId; |
| 44 | import org.onosproject.tetopology.management.api.link.TunnelProtectionType; |
| 45 | import org.onosproject.tetopology.management.api.link.UnderlayBackupPath; |
| 46 | import org.onosproject.tetopology.management.api.link.UnderlayPath; |
| 47 | import org.onosproject.tetopology.management.api.node.NodeTpKey; |
| 48 | import org.onosproject.tetopology.management.api.node.TeNode; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 49 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 50 | 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] | 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.Networks; |
| 52 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 53 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network; |
| 54 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.network.Node; |
| 55 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 56 | .ietfnetworktopology.LinkId; |
| 57 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 58 | .ietfnetworktopology.TpId; |
| 59 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.AugmentedNdNetwork; |
| 60 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 61 | .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink; |
| 62 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 63 | .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink.LinkBuilder; |
| 64 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 65 | .ietfnetworktopology.networks.network.augmentedndnetwork.Link; |
| 66 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 67 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultDestination; |
| 68 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 69 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSource; |
| 70 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 71 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSupportingLink; |
| 72 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 73 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.Destination |
| 74 | .DestinationBuilder; |
| 75 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 76 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.Source.SourceBuilder; |
| 77 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 78 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink; |
| 79 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 80 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink |
| 81 | .SupportingLinkBuilder; |
| 82 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.node.AugmentedNdNode; |
| 83 | 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] | 84 | 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] | 85 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState; |
| 86 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.InformationSourceState; |
| 87 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.DefaultTopology; |
| 88 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.Topology; |
| 89 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.AugmentedNwNetwork; |
| 90 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 91 | .ietftetopology.networks.network.link.AugmentedNtLink; |
| 92 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 93 | .ietftetopology.networks.network.link.DefaultAugmentedNtLink; |
| 94 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 95 | .ietftetopology.networks.network.link.DefaultAugmentedNtLink.AugmentedNtLinkBuilder; |
| 96 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.AugmentedNwNode; |
| 97 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.networks.network.node.terminationpoint.AugmentedNtTerminationPoint; |
| 98 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe; |
| 99 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe.TeBuilder; |
| 100 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.Config; |
| 101 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig; |
| 102 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig.ConfigBuilder; |
| 103 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState; |
| 104 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState.StateBuilder; |
| 105 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.State; |
| 106 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes; |
| 107 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes.TeLinkAttributesBuilder; |
| 108 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.TeLinkAttributes; |
| 109 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain; |
| 110 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain.ExternalDomainBuilder; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 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()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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 | } |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 300 | if (teLink.maxBandwidth() != null) { |
| 301 | // maxBandwidth is an array of float[], but in yang is just a big decimal |
| 302 | attrBuilder = attrBuilder.maxLinkBandwidth(BigDecimal.valueOf(teLink.maxBandwidth()[0])); |
| 303 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 437 | TeLink teLink, TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 461 | pathBuilder = pathBuilder.networkIdRef(teTopologyService.networkId(teLink.underlayTeTopologyId())); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 462 | |
| 463 | return yangBuilder.underlayPrimaryPath(pathBuilder.build()); |
| 464 | } |
| 465 | |
| 466 | private static UnderlayBuilder te2YangConfigUnderlayBackupPaths(UnderlayBuilder yangBuilder, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 467 | TeLink teLink, |
| 468 | TeTopologyService teTopologyService) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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()); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 478 | |
| 479 | pathBuilder = pathBuilder.networkIdRef(teTopologyService.networkId(teLink.underlayTeTopologyId())); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 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, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 508 | yangLink.source().sourceNode()); |
| 509 | long teNodeIdLong = -1; |
| 510 | if (teNodeId != null && teNodeId.dottedQuad() != null) { |
| 511 | teNodeIdLong = Ip4Address.valueOf(teNodeId.dottedQuad().string()) |
| 512 | .toInt(); |
| 513 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 514 | |
| 515 | TeLinkTpKey teLinkKey = new TeLinkTpKey(teNodeIdLong, |
| 516 | findTeTpId(yangNetwork, |
| 517 | yangLink.source().sourceNode(), |
| 518 | yangLink.source().sourceTp())); |
| 519 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 520 | TeNodeId teNodeIdDest = null; |
| 521 | if (yangLink.destination() != null) { |
| 522 | teNodeIdDest = findTeNodeId(yangNetwork, |
| 523 | yangLink.destination().destNode()); |
| 524 | } |
| 525 | long teNodeIdDestLong = -1; |
| 526 | if (teNodeIdDest != null && teNodeIdDest.dottedQuad() != null) { |
| 527 | teNodeIdDestLong = Ip4Address.valueOf(teNodeIdDest.dottedQuad().string()).toInt(); |
| 528 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 529 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 530 | TeLinkTpKey peerTeLinkKey = null; |
| 531 | if (yangLink.destination() != null) { |
| 532 | peerTeLinkKey = new TeLinkTpKey(teNodeIdDestLong, |
| 533 | findTeTpId(yangNetwork, |
| 534 | yangLink.destination().destNode(), |
| 535 | yangLink.destination().destTp())); |
| 536 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 537 | |
| 538 | TeLinkTpGlobalKey supportTeLinkId = findSupportTeLinkId(yangNetworks, yangLink); |
| 539 | |
| 540 | org.onosproject.tetopology.management.api.TeStatus opStatus = null; |
| 541 | if (opState != null && opState.operStatus() != null) { |
| 542 | opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState.operStatus()); |
| 543 | } |
| 544 | |
| 545 | |
| 546 | TeLink teLink = yangLinkAttr2TeLinkAttributes(yangLinkAttr, opStatus, teNodeIdLong, teNodeIdDestLong, teLinkKey, |
| 547 | peerTeLinkKey, supportTeLinkId); |
| 548 | |
| 549 | return teLink; |
| 550 | } |
| 551 | |
| 552 | private static TeLink yangLinkAttr2TeLinkAttributes(TeLinkAttributes yangLinkAtrr, |
| 553 | org.onosproject.tetopology.management.api.TeStatus opStatus, |
| 554 | long teNodeIdLong, |
| 555 | long teNodeIdDestLong, |
| 556 | TeLinkTpKey teLinkKey, |
| 557 | TeLinkTpKey peerTeLinkKey, |
| 558 | TeLinkTpGlobalKey supportTeLinkId) { |
| 559 | org.onosproject.tetopology.management.api.TeStatus adminStatus = null; |
| 560 | |
| 561 | TeLinkTpGlobalKey sourceTeLinkId = null; // from yang to core, we can ignore sourceTeLinkId |
| 562 | TeTopologyKey underlayTopologyId = null; |
| 563 | CommonLinkData teData = null; |
| 564 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 565 | if (yangLinkAtrr != null && yangLinkAtrr.underlay() != null && |
| 566 | yangLinkAtrr.underlay().underlayPrimaryPath() != null) { |
| 567 | underlayTopologyId = new |
| 568 | TeTopologyKey((long) yangLinkAtrr.underlay().underlayPrimaryPath().providerIdRef(), |
| 569 | (long) yangLinkAtrr.underlay().underlayPrimaryPath().clientIdRef(), |
| 570 | (long) yangLinkAtrr.underlay().underlayPrimaryPath().teTopologyIdRef()); |
| 571 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 572 | |
| 573 | if (yangLinkAtrr.adminStatus() != null) { |
| 574 | adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangLinkAtrr.adminStatus()); |
| 575 | } |
| 576 | |
| 577 | BitSet flags = new BitSet(); |
| 578 | if (yangLinkAtrr.isAbstract()) { |
| 579 | flags.set(TeLink.BIT_ABSTRACT); |
| 580 | } |
| 581 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 582 | ExternalLink externalLink = null; |
| 583 | if (yangLinkAtrr != null && yangLinkAtrr.externalDomain() != null) { |
| 584 | externalLink = new ExternalLink(null, yangLinkAtrr.externalDomain().plugId()); |
| 585 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 586 | |
| 587 | UnderlayPath underlayPath = null; |
| 588 | underlayPath = yang2TeSubsystemUnderlayPath(yangLinkAtrr, teNodeIdLong, |
| 589 | teNodeIdDestLong); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 590 | Long adminGroup = null; |
| 591 | if (yangLinkAtrr != null && yangLinkAtrr.administrativeGroup() != null) { |
| 592 | adminGroup = Long.valueOf(yangLinkAtrr.administrativeGroup().toString()); |
| 593 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 594 | List<Long> interLayerLocks = null; // FIXME: how to find interLayerLocks? |
| 595 | |
| 596 | List<UnreservedBandwidth> listOfUnreservedBandwidth = yangLinkAtrr.unreservedBandwidth(); |
| 597 | float[] availBandwidth = new float[listOfUnreservedBandwidth.size()]; |
| 598 | int i = 0; |
| 599 | for (UnreservedBandwidth urbw : listOfUnreservedBandwidth) { |
| 600 | availBandwidth[i] = urbw.bandwidth().floatValue(); |
| 601 | i++; |
| 602 | } |
| 603 | |
| 604 | float[] maxBandwidth = new float[1]; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 605 | if (yangLinkAtrr.maxLinkBandwidth() != null) { |
| 606 | maxBandwidth[0] = yangLinkAtrr.maxLinkBandwidth().floatValue(); |
| 607 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 608 | |
| 609 | float[] maxAvailLspBandwidth = null; // FIXME: how to find this? |
| 610 | float[] minAvailLspBandwidth = null; // FIXME: how to find this? |
| 611 | LinkBandwidth bandwidth = new LinkBandwidth( |
| 612 | maxBandwidth, |
| 613 | availBandwidth, |
| 614 | maxAvailLspBandwidth, |
| 615 | minAvailLspBandwidth, |
| 616 | null); // FIXME: how to find odu resource? |
| 617 | List<Long> srlgs = Lists.newArrayList(); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 618 | if (yangLinkAtrr.teSrlgs() != null |
| 619 | && yangLinkAtrr.teSrlgs().value() != null |
| 620 | && !yangLinkAtrr.teSrlgs().value().isEmpty()) { |
| 621 | for (Srlg srlg : yangLinkAtrr.teSrlgs().value()) { |
| 622 | srlgs.add(srlg.uint32()); |
| 623 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 624 | } |
| 625 | TePathAttributes teAttributes = |
| 626 | new TePathAttributes(yangLinkAtrr.teDefaultMetric(), |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 627 | yangLinkAtrr.performanceMetric() == null ? null : |
| 628 | (yangLinkAtrr.performanceMetric().measurement() == null ? null : |
| 629 | yangLinkAtrr.performanceMetric().measurement().unidirectionalDelay()), |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 630 | srlgs); |
| 631 | teData = new CommonLinkData(adminStatus, |
| 632 | opStatus, |
| 633 | flags, |
| 634 | null, // switchingLayer |
| 635 | null, // encodingLayer |
| 636 | externalLink, |
| 637 | underlayPath, |
| 638 | teAttributes, |
| 639 | adminGroup, |
| 640 | interLayerLocks, |
| 641 | bandwidth); |
| 642 | |
| 643 | TeLink te = new DefaultTeLink(teLinkKey, peerTeLinkKey, |
| 644 | underlayTopologyId, supportTeLinkId, |
| 645 | sourceTeLinkId, teData); |
| 646 | return te; |
| 647 | } |
| 648 | |
| 649 | private static TeLinkTpGlobalKey findSupportTeLinkId(Networks yangNetworks, |
| 650 | Link yangLink) { |
| 651 | Network teNetworkFound = null; |
| 652 | LinkId teLinkIdFound = null; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 653 | TeLinkTpGlobalKey supportTeLinkId = null; |
| 654 | |
| 655 | if (yangLink != null && yangLink.supportingLink() != null && !yangLink.supportingLink().isEmpty()) { |
| 656 | if (yangNetworks.network() != null && !yangNetworks.network().isEmpty()) { |
| 657 | for (Network ynetItem : yangNetworks.network()) { |
| 658 | if (ynetItem.networkId() != null) { |
| 659 | if (ynetItem.networkId().equals(yangLink.supportingLink().get(0).networkRef())) { |
| 660 | teNetworkFound = ynetItem; |
| 661 | teLinkIdFound = yangLink.supportingLink().get(0).linkRef(); |
| 662 | break; |
| 663 | } |
| 664 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 665 | } |
| 666 | } |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 667 | Link teLinkFound = null; |
| 668 | if (teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class) != null) { |
| 669 | AugmentedNdNetwork augmentLink = |
| 670 | (AugmentedNdNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNdNetwork.class); |
| 671 | for (Link link : augmentLink.link()) { |
| 672 | if (link.linkId().equals(teLinkIdFound)) { |
| 673 | teLinkFound = link; |
| 674 | break; |
| 675 | } |
| 676 | } |
| 677 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 678 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 679 | TeNodeId teSupportNodeId = findTeNodeId(teNetworkFound, |
| 680 | teLinkFound.source().sourceNode()); |
| 681 | long tenIdLong = -1; |
| 682 | if (teSupportNodeId != null) { |
| 683 | tenIdLong = Ip4Address.valueOf(teSupportNodeId.dottedQuad().string()).toInt(); |
| 684 | } |
| 685 | long teSupportLinkTpId = findTeTpId(teNetworkFound, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 686 | teLinkFound.source().sourceNode(), |
| 687 | teLinkFound.source().sourceTp()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 688 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 689 | org.onosproject.tetopology.management.api.TeTopologyId teTopologyId = null; |
| 690 | if (teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class) != null) { |
| 691 | AugmentedNwNetwork augmentTeIds = |
| 692 | (AugmentedNwNetwork) teNetworkFound.yangAugmentedInfo(AugmentedNwNetwork.class); |
| 693 | teTopologyId = |
| 694 | new org.onosproject.tetopology.management.api.TeTopologyId( |
| 695 | augmentTeIds.te().clientId().uint32(), |
| 696 | augmentTeIds.te().providerId().uint32(), |
| 697 | augmentTeIds.te().teTopologyId().string()); |
| 698 | } |
| 699 | |
| 700 | supportTeLinkId = new TeLinkTpGlobalKey(teTopologyId.providerId(), |
| 701 | teTopologyId.clientId(), |
| 702 | Long.valueOf(teTopologyId |
| 703 | .topologyId()), |
| 704 | tenIdLong, teSupportLinkTpId); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 705 | } |
| 706 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 707 | return supportTeLinkId; |
| 708 | } |
| 709 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 710 | private static TeNodeId findTeNodeId(Network yangNetwork, NodeId yangNodeId) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 711 | TeNodeId teNodeId = null; |
| 712 | for (Node node : yangNetwork.node()) { |
| 713 | if (node.nodeId().equals(yangNodeId)) { |
| 714 | if (node.yangAugmentedInfoMap() != null |
| 715 | && !node.yangAugmentedInfoMap().isEmpty()) { |
| 716 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) node |
| 717 | .yangAugmentedInfo(AugmentedNwNode.class); |
| 718 | if (yangNodeAugment != null && yangNodeAugment.te() != null |
| 719 | && yangNodeAugment.te().teNodeId() != null) { |
| 720 | Te yangNodeAugTe = yangNodeAugment.te(); |
| 721 | teNodeId = yangNodeAugTe.teNodeId(); |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | return teNodeId; |
| 727 | } |
| 728 | |
| 729 | private static long findTeTpId(Network yangNetwork, NodeId yangNodeId, TpId yangTpId) { |
| 730 | long teTpId = 0; |
| 731 | for (Node node : yangNetwork.node()) { |
| 732 | if (node.nodeId().equals(yangNodeId)) { |
| 733 | if (node.yangAugmentedInfoMap() != null |
| 734 | && !node.yangAugmentedInfoMap().isEmpty()) { |
| 735 | |
| 736 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) node |
| 737 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 738 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 739 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 740 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 741 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 742 | if (yangTpnode.tpId().equals(yangTpId)) { |
| 743 | if (yangTpnode.yangAugmentedInfoMap() != null |
| 744 | && !yangTpnode.yangAugmentedInfoMap() |
| 745 | .isEmpty()) { |
| 746 | AugmentedNtTerminationPoint yangTpAugment = |
| 747 | (AugmentedNtTerminationPoint) yangTpnode |
| 748 | .yangAugmentedInfo(AugmentedNtTerminationPoint.class); |
| 749 | if (yangTpAugment.te() != null && yangTpAugment.te().teTpId() != null) { |
| 750 | teTpId = Long.valueOf(yangTpAugment.te().teTpId().toString()); |
| 751 | } |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | return teTpId; |
| 760 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 761 | /** |
| 762 | * Link object conversion from YANG to TE Topology subsystem. |
| 763 | * |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 764 | * @param yangLink YANG link |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 765 | * @param yangNetwork YANG network |
| 766 | * @param yangNetworks YANG networks |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 767 | * @return TE subsystem link |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 768 | */ |
| 769 | public static org.onosproject.tetopology.management.api.link.NetworkLink |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 770 | yang2TeSubsystemLink(Link yangLink, Network yangNetwork, |
| 771 | Networks yangNetworks) { |
| 772 | NetworkId networkId = yangNetwork.networkId(); |
| 773 | checkNotNull(yangLink, E_NULL_YANG_TELINK); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 774 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 775 | KeyId linkId = KeyId.keyId(yangLink.linkId().uri().toString()); |
| 776 | NodeTpKey sourceNodeTpKey = null; |
| 777 | NodeTpKey destinationNodeTpKey = null; |
| 778 | List<NetworkLinkKey> spLinkIds = null; |
| 779 | TeLink te = null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 780 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 781 | if (yangLink.supportingLink() != null) { |
| 782 | spLinkIds = Lists.newArrayList(); |
| 783 | for (SupportingLink yangSpLink : yangLink.supportingLink()) { |
| 784 | NetworkLinkKey linkKey = new NetworkLinkKey(KeyId.keyId(yangSpLink.networkRef().uri().toString()), |
| 785 | KeyId.keyId(yangSpLink.linkRef().uri().toString())); |
| 786 | spLinkIds.add(linkKey); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | if (yangLink.source() != null) { |
| 791 | TerminationPointKey source = new TerminationPointKey( |
| 792 | KeyId.keyId(networkId.uri().toString()), |
| 793 | KeyId.keyId(yangLink.source().sourceNode().uri().toString()), |
| 794 | KeyId.keyId(yangLink.source().sourceTp().uri().toString())); |
| 795 | sourceNodeTpKey = new NodeTpKey(source.nodeId(), source.tpId()); |
| 796 | } |
| 797 | |
| 798 | if (yangLink.destination() != null) { |
| 799 | TerminationPointKey destination = new TerminationPointKey( |
| 800 | KeyId.keyId(networkId.uri().toString()), |
| 801 | KeyId.keyId(yangLink.destination().destNode().uri().toString()), |
| 802 | KeyId.keyId(yangLink.destination().destTp().uri().toString())); |
| 803 | destinationNodeTpKey = new NodeTpKey(destination.nodeId(), destination.tpId()); |
| 804 | } |
| 805 | |
| 806 | if (yangLink.yangAugmentedInfoMap() != null && !yangLink.yangAugmentedInfoMap().isEmpty()) { |
| 807 | |
| 808 | AugmentedNtLink yangLinkAugment = |
| 809 | (AugmentedNtLink) yangLink.yangAugmentedInfo(AugmentedNtLink.class); |
| 810 | if (yangLinkAugment != null && |
| 811 | yangLinkAugment.te() != null && |
| 812 | yangLinkAugment.te().config() != null) { |
| 813 | TeLinkAttributes yangLinkAtrr = |
| 814 | yangLinkAugment.te().config().teLinkAttributes(); |
| 815 | if (yangLinkAtrr != null && yangLinkAtrr.linkIndex() != null) { |
| 816 | te = yang2TeLinkAttributes(yangLinkAtrr, |
| 817 | yangLinkAugment.te().state(), |
| 818 | yangLink, yangNetwork, |
| 819 | yangNetworks); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | org.onosproject.tetopology.management.api.link.DefaultNetworkLink link = |
| 825 | new DefaultNetworkLink(linkId, |
| 826 | sourceNodeTpKey, |
| 827 | destinationNodeTpKey, |
| 828 | spLinkIds, |
| 829 | te); |
| 830 | return link; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 831 | } |
| 832 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 833 | private static org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath |
| 834 | yang2TeSubsystemUnderlayPrimaryPath(UnderlayPrimaryPath yangpath, |
| 835 | long teNodeId) { |
| 836 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath teUnderlayPrimaryPath = null; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 837 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 838 | List<PathElement> pathElementList = Lists.newArrayList(); |
| 839 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 840 | .telinkunderlayattributes.underlayprimarypath. |
| 841 | PathElement pathElementConfigYang : yangpath.pathElement()) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 842 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 843 | // TODO: find the proper type (ElementType) from pathElementConfigYang.type() |
| 844 | PathElement tePathElement = new PathElement(pathElementConfigYang.pathElementId(), |
| 845 | teNodeId, |
| 846 | null, |
| 847 | false); // FIXME: how to find the proper value for loose? |
| 848 | pathElementList.add(tePathElement); |
| 849 | } |
| 850 | |
| 851 | teUnderlayPrimaryPath = new org.onosproject.tetopology.management.api.link. |
| 852 | UnderlayPrimaryPath(pathElementList, false); // FIXME: how to find the proper value for loose? |
| 853 | |
| 854 | return teUnderlayPrimaryPath; |
| 855 | } |
| 856 | |
| 857 | private static List<UnderlayBackupPath> |
| 858 | yang2TeSubsystemUnderlayBackupPaths( |
| 859 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 860 | rev20160708.ietftetopology.telinkunderlayattributes. |
| 861 | UnderlayBackupPath> yangpaths, |
| 862 | long teNodeId) { |
| 863 | |
| 864 | List<UnderlayBackupPath> underlayBackupPathsList = Lists.newArrayList(); |
| 865 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 866 | .ietftetopology.telinkunderlayattributes. |
| 867 | UnderlayBackupPath yangConfig : yangpaths) { |
| 868 | UnderlayBackupPath ubp = null; |
| 869 | List<PathElement> backupPathElementList = Lists.newArrayList(); |
| 870 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 871 | .telinkunderlayattributes.underlaybackuppath. |
| 872 | PathElement pathElementBackupYang : yangConfig.pathElement()) { |
| 873 | |
| 874 | PathElement tePathElementBackup = new PathElement(pathElementBackupYang.pathElementId(), |
| 875 | teNodeId, |
| 876 | null, // FIXME: find the proper ElementType |
| 877 | // from pathElementBackupYang.type() |
| 878 | false); // FIXME: find the proper value for loose |
| 879 | backupPathElementList.add(tePathElementBackup); |
| 880 | } |
| 881 | ubp = new UnderlayBackupPath(yangConfig.index(), |
| 882 | backupPathElementList, |
| 883 | null); // FIXME: find the proper value for loose |
| 884 | underlayBackupPathsList.add(ubp); |
| 885 | } |
| 886 | |
| 887 | return underlayBackupPathsList; |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * TE Link underlay path Config object conversion from YANG to TE Topology subsystem. |
| 892 | * |
| 893 | * @param yangLinkAtrr YANG link Config YANG object |
| 894 | * @return teSubsystem TE underlay path object |
| 895 | */ |
| 896 | private static org.onosproject.tetopology.management.api.link.UnderlayPath |
| 897 | yang2TeSubsystemUnderlayPath(TeLinkAttributes yangLinkAtrr, long srcTeNodeId, long dstTeNodeId) { |
| 898 | |
| 899 | checkNotNull(yangLinkAtrr, E_NULL_YANG_TELINK_CONFIG); |
| 900 | |
| 901 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath underlayPrimaryPath = null; |
| 902 | List<UnderlayBackupPath> underlayBackupPathsList = null; |
| 903 | TeTunnelId teTunnelId = new TeTunnelId(srcTeNodeId, dstTeNodeId, 0); // FIXME: how to find teTunnelId? |
| 904 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 905 | if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().underlayPrimaryPath() != null) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 906 | underlayPrimaryPath = |
| 907 | yang2TeSubsystemUnderlayPrimaryPath(yangLinkAtrr.underlay().underlayPrimaryPath(), srcTeNodeId); |
| 908 | } |
| 909 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 910 | if (yangLinkAtrr.underlay() != null && yangLinkAtrr.underlay().underlayBackupPath() != null) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 911 | underlayBackupPathsList = |
| 912 | yang2TeSubsystemUnderlayBackupPaths(yangLinkAtrr.underlay().underlayBackupPath(), srcTeNodeId); |
| 913 | } |
| 914 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 915 | org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay = null; |
| 916 | if (yangLinkAtrr.underlay() != null) { |
| 917 | teUnderlay = new org.onosproject.tetopology.management.api.link. |
| 918 | UnderlayPath(underlayPrimaryPath, |
| 919 | underlayBackupPathsList, |
| 920 | TunnelProtectionType.of(yangLinkAtrr.underlay().underlayProtectionType()), |
| 921 | (long) yangLinkAtrr.underlay().underlayTrailSrc().tpRef(), // Is this correct? |
| 922 | (long) yangLinkAtrr.underlay().underlayTrailDes().tpRef(), // Is this correct? |
| 923 | teTunnelId); |
| 924 | } |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 925 | |
| 926 | return teUnderlay; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Converts a TE Topology link event from the data format used in |
| 931 | * the core to its corresponding YANG Object (YO) format. |
| 932 | * |
| 933 | * @param eventType Link event type |
| 934 | * @param linkData TE Topology link event data |
| 935 | * @return YANG Object converted from linkData |
| 936 | */ |
| 937 | public static TeLinkEvent teNetworkLink2yangTeLinkEvent(TeTopologyEventTypeEnum eventType, |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 938 | NetworkLinkEventSubject linkData) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 939 | TeLinkEvent.TeLinkEventBuilder builder = new DefaultTeLinkEvent.TeLinkEventBuilder(); |
| 940 | |
| 941 | TeTopologyEventType yangEventType = new TeTopologyEventType(eventType); |
| 942 | builder.eventType(yangEventType); |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 943 | NetworkId newtorkId = NetworkId.fromString(linkData.key().networkId().toString()); |
| 944 | builder.networkRef(newtorkId); |
| 945 | LinkId linkId = LinkId.fromString(linkData.key().linkId().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 946 | builder.linkRef(linkId); |
| 947 | |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 948 | NetworkLink link = linkData.networkLink(); |
| 949 | TeLinkAttributes teLinkAttributes = link == null ? null |
| 950 | : teLink2YangConfig(link.teLink()).teLinkAttributes(); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 951 | builder.teLinkAttributes(teLinkAttributes); |
| 952 | |
| 953 | return builder.build(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | public static NetworkLinkKey yangLinkEvent2NetworkLinkKey(TeLinkEvent yangLinkEvent) { |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 957 | NetworkId networkRef = NetworkId.fromString(yangLinkEvent.networkRef().toString()); |
| 958 | LinkId linkRef = LinkId.fromString(yangLinkEvent.linkRef().toString()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 959 | KeyId networkId = KeyId.keyId(networkRef.uri().toString()); |
| 960 | KeyId linkId = KeyId.keyId(linkRef.uri().toString()); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 961 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 962 | NetworkLinkKey networkLinkKey = new NetworkLinkKey(networkId, linkId); |
| 963 | |
| 964 | return networkLinkKey; |
Hesam Rahimi | 4120810 | 2016-12-09 17:54:03 -0500 | [diff] [blame^] | 965 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | public static NetworkLink yangLinkEvent2NetworkLink(TeLinkEvent yangLinkEvent, |
| 969 | TeTopologyService teTopologyService) { |
| 970 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 971 | KeyId linkId = yangLinkEvent2NetworkLinkKey(yangLinkEvent).linkId(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 972 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 973 | org.onosproject.tetopology.management.api. |
| 974 | Network network = teTopologyService.network( |
| 975 | yangLinkEvent2NetworkLinkKey(yangLinkEvent).networkId()); |
| 976 | if (network == null) { |
| 977 | return null; |
| 978 | } |
| 979 | |
| 980 | NetworkLink networkLink = network.link(linkId); |
| 981 | if (networkLink == null) { |
| 982 | return null; |
| 983 | } |
| 984 | |
| 985 | NodeTpKey sourceTp = networkLink.source(); |
| 986 | NodeTpKey destTp = networkLink.destination(); |
| 987 | |
| 988 | List<NetworkLinkKey> supportingLinkIds = networkLink.supportingLinkIds(); |
| 989 | TeLink teLink = networkLink.teLink(); |
| 990 | if (teLink == null) { |
| 991 | return null; |
| 992 | } |
| 993 | |
| 994 | TeOperStatus opState = yangLinkEvent.operStatus(); |
| 995 | org.onosproject.tetopology.management.api. |
| 996 | TeStatus opStatus = EnumConverter.yang2TeSubsystemOpStatus(opState); |
| 997 | |
| 998 | TeLink updatedTeLink = yangLinkEvent2TeLinkAttributes(yangLinkEvent, teLink, opStatus); |
| 999 | |
| 1000 | |
| 1001 | NetworkLink updatedNetworkLink = new DefaultNetworkLink(linkId, sourceTp, destTp, supportingLinkIds, |
| 1002 | updatedTeLink); |
| 1003 | |
| 1004 | return updatedNetworkLink; |
| 1005 | } |
| 1006 | |
| 1007 | private static TeLink yangLinkEvent2TeLinkAttributes(TeLinkEvent yangLinkEvent, TeLink oldTeLink, TeStatus |
| 1008 | opStatus) { |
| 1009 | |
| 1010 | TeLinkAttributes yangTeLinkAttrs = yangLinkEvent.teLinkAttributes(); |
| 1011 | |
| 1012 | TeLinkTpKey teLinkKey = oldTeLink.teLinkKey(); |
| 1013 | |
| 1014 | |
| 1015 | long teNodeIdDest = oldTeLink.peerTeLinkKey().teNodeId(); |
| 1016 | long teNodeId = oldTeLink.teLinkKey().teNodeId(); |
| 1017 | TeLinkTpGlobalKey supportTeLinkId = oldTeLink.supportingTeLinkId(); |
| 1018 | TeLinkTpKey peerTeLinkKey = oldTeLink.peerTeLinkKey(); |
| 1019 | |
| 1020 | TeLink updatedTeLink = yangLinkAttr2TeLinkAttributes(yangTeLinkAttrs, opStatus, teNodeId, teNodeIdDest, |
| 1021 | teLinkKey, peerTeLinkKey, supportTeLinkId); |
| 1022 | |
| 1023 | return updatedTeLink; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1024 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1025 | } |