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