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