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 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.List; |
| 21 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 22 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.IpAddress.Version; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 25 | import org.onosproject.tetopology.management.api.KeyId; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 26 | import org.onosproject.tetopology.management.api.link.ElementType; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 27 | import org.onosproject.tetopology.management.api.link.ExternalDomain; |
| 28 | import org.onosproject.tetopology.management.api.link.LinkProtectionType; |
| 29 | import org.onosproject.tetopology.management.api.link.NetworkLinkKey; |
| 30 | import org.onosproject.tetopology.management.api.link.PathElement; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 31 | import org.onosproject.tetopology.management.api.link.TeIpv4; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 32 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 33 | import org.onosproject.tetopology.management.api.link.UnderlayBackupPath; |
| 34 | import org.onosproject.tetopology.management.api.link.UnderlayPath; |
| 35 | import org.onosproject.tetopology.management.api.node.TeNetworkTopologyId; |
| 36 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
| 37 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
| 38 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 39 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 40 | .ietfnetworktopology.LinkId; |
| 41 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 42 | .ietfnetworktopology.TpId; |
| 43 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 44 | .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink; |
| 45 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 46 | .ietfnetworktopology.networks.network.augmentedndnetwork.DefaultLink.LinkBuilder; |
| 47 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 48 | .ietfnetworktopology.networks.network.augmentedndnetwork.Link; |
| 49 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 50 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultDestination; |
| 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 52 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSource; |
| 53 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 54 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.DefaultSupportingLink; |
| 55 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 56 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.Destination |
| 57 | .DestinationBuilder; |
| 58 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 59 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.Source.SourceBuilder; |
| 60 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 61 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink; |
| 62 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 63 | .ietfnetworktopology.networks.network.augmentedndnetwork.link.SupportingLink |
| 64 | .SupportingLinkBuilder; |
| 65 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 66 | .ietftetopology.networks.network.link.AugmentedNtLink; |
| 67 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 68 | .ietftetopology.networks.network.link.DefaultAugmentedNtLink; |
| 69 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 70 | .ietftetopology.networks.network.link.DefaultAugmentedNtLink.AugmentedNtLinkBuilder; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 71 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe; |
| 72 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.DefaultTe.TeBuilder; |
| 73 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.Config; |
| 74 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig; |
| 75 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultConfig.ConfigBuilder; |
| 76 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState; |
| 77 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.DefaultState.StateBuilder; |
| 78 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkaugment.te.State; |
| 79 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes; |
| 80 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes.TeLinkAttributesBuilder; |
| 81 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.TeLinkAttributes; |
| 82 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain; |
| 83 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultExternalDomain.ExternalDomainBuilder; |
| 84 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay; |
| 85 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay.UnderlayBuilder; |
| 86 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconfigattributes.telinkattributes.Underlay; |
| 87 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs; |
| 88 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultTeSrlgs.TeSrlgsBuilder; |
| 89 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth; |
| 90 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.DefaultUnreservedBandwidth.UnreservedBandwidthBuilder; |
| 91 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkconnectivityattributes.UnreservedBandwidth; |
| 92 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkinfoattributes.LinkProtectionTypeEnum; |
| 93 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayBackupPath; |
| 94 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayBackupPath.UnderlayBackupPathBuilder; |
| 95 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayPrimaryPath; |
| 96 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayPrimaryPath.UnderlayPrimaryPathBuilder; |
| 97 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayTrailDes.UnderlayTrailDesBuilder; |
| 98 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.DefaultUnderlayTrailSrc.UnderlayTrailSrcBuilder; |
| 99 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.UnderlayPrimaryPath; |
| 100 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.underlayprimarypath.DefaultPathElement; |
| 101 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.telinkunderlayattributes.underlayprimarypath.DefaultPathElement.PathElementBuilder; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 102 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg; |
| 103 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeLinkAccessType; |
| 104 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId; |
| 105 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyId; |
| 106 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTpId; |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 107 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.Type; |
| 108 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.AsNumber; |
| 109 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultAsNumber; |
| 110 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultIpv4Address; |
| 111 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.DefaultUnnumberedLink; |
| 112 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.Ipv4Address; |
| 113 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.explicitroutesubobject.type.UnnumberedLink; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 114 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705 |
| 115 | .ietftetypes.telinkaccesstype.TeLinkAccessTypeEnum; |
| 116 | |
| 117 | import com.google.common.collect.Lists; |
| 118 | |
| 119 | /** |
| 120 | * The conversion functions. |
| 121 | */ |
| 122 | public final class LinkConverter { |
| 123 | private static final String |
| 124 | E_NULL_TELINK_UNDERLAY_PATH = "TeSubsystem link underlayPath object cannot be null"; |
| 125 | private static final String |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 126 | E_NULL_TELINK_DATA = "TeSubsystem teLinkAttrBuilder data cannot be null"; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 127 | private static final String |
| 128 | E_NULL_TELINK = "TeSubsystem teLink object cannot be null"; |
| 129 | private static final String |
| 130 | E_NULL_YANG_TELINK_CONFIG = "YANG telink config object cannot be null"; |
| 131 | private static final String |
| 132 | E_NULL_YANG_TELINK = "YANG Link object cannot be null"; |
| 133 | |
| 134 | // no instantiation |
| 135 | private LinkConverter() { |
| 136 | } |
| 137 | |
| 138 | private static UnderlayBuilder te2YangConfigUnderlayPrimaryPath( |
| 139 | UnderlayBuilder yangBuilder, |
| 140 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath tePath) { |
| 141 | UnderlayPrimaryPathBuilder pathBuilder = |
| 142 | DefaultUnderlayPrimaryPath.builder(); |
| 143 | if (tePath.pathElements() != null) { |
| 144 | for (PathElement pathElementTe : tePath.pathElements()) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 145 | PathElementBuilder pathElementYangBuilder = DefaultPathElement |
| 146 | .builder(); |
| 147 | pathElementYangBuilder = pathElementYangBuilder |
| 148 | .pathElementId(pathElementTe.pathElementId()) |
| 149 | .type(findYangTypeConfigPrimaryPath(pathElementTe.type())); |
| 150 | pathBuilder = pathBuilder |
| 151 | .addToPathElement(pathElementYangBuilder.build()); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | pathBuilder = pathBuilder.networkIdRef(NetworkId.fromString( |
| 155 | tePath.ref().getNetworkId().toString())) |
| 156 | .teTopologyIdRef(TeTopologyId.fromString( |
| 157 | tePath.ref().getTopologyId().topologyId())); |
| 158 | return yangBuilder.underlayPrimaryPath(pathBuilder.build()); |
| 159 | } |
| 160 | |
| 161 | private static UnderlayBuilder te2YangConfigUnderlayBackupPaths( |
| 162 | UnderlayBuilder yangBuilder, |
| 163 | List<org.onosproject.tetopology.management.api.link.UnderlayBackupPath> tePaths) { |
| 164 | |
| 165 | for (UnderlayBackupPath tePath : tePaths) { |
| 166 | UnderlayBackupPathBuilder pathBuilder = DefaultUnderlayBackupPath.builder(); |
| 167 | pathBuilder = pathBuilder.index(tePath.index()); |
| 168 | pathBuilder = pathBuilder.networkIdRef(NetworkId.fromString( |
| 169 | tePath.ref().getNetworkId().toString())) |
| 170 | .teTopologyIdRef(TeTopologyId.fromString( |
| 171 | tePath.ref().getTopologyId().topologyId())); |
| 172 | for (PathElement backupPathElementTe : tePath.pathElements()) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 173 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 174 | .ietftetopology.telinkunderlayattributes.underlaybackuppath.DefaultPathElement. |
| 175 | PathElementBuilder backupPathElementYangBuilder = |
| 176 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 177 | .ietftetopology.telinkunderlayattributes.underlaybackuppath.DefaultPathElement.builder(); |
| 178 | backupPathElementYangBuilder = backupPathElementYangBuilder |
| 179 | .pathElementId(backupPathElementTe.pathElementId()); |
| 180 | backupPathElementYangBuilder = backupPathElementYangBuilder |
| 181 | .type(findYangTypeConfigPrimaryPath(backupPathElementTe |
| 182 | .type())); |
| 183 | pathBuilder = pathBuilder.addToPathElement(backupPathElementYangBuilder.build()); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 184 | } |
| 185 | yangBuilder = yangBuilder.addToUnderlayBackupPath(pathBuilder.build()); |
| 186 | } |
| 187 | |
| 188 | return yangBuilder; |
| 189 | } |
| 190 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 191 | private static Type findYangTypeConfigPrimaryPath(ElementType type) { |
| 192 | if (type instanceof org.onosproject.tetopology.management.api.link.AsNumber) { |
| 193 | AsNumber.AsNumberBuilder yangAsNumberBuilder = DefaultAsNumber |
| 194 | .builder(); |
| 195 | yangAsNumberBuilder.asNumber(((AsNumber) type).asNumber()); |
| 196 | return yangAsNumberBuilder.build(); |
| 197 | } else if (type instanceof TeIpv4) { |
| 198 | Ipv4Address.Ipv4AddressBuilder yangIpv4AddrBuilder = DefaultIpv4Address |
| 199 | .builder(); |
| 200 | yangIpv4AddrBuilder = yangIpv4AddrBuilder |
| 201 | .v4Address(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types |
| 202 | .rev20130715.ietfinettypes.Ipv4Address(((TeIpv4) type) |
| 203 | .v4Address().toString())); |
| 204 | yangIpv4AddrBuilder = yangIpv4AddrBuilder |
| 205 | .v4Loose(((TeIpv4) type).v4Loose()); |
| 206 | yangIpv4AddrBuilder = yangIpv4AddrBuilder |
| 207 | .v4PrefixLength((((TeIpv4) type).v4PrefixLength())); |
| 208 | return yangIpv4AddrBuilder.build(); |
| 209 | } else if (type instanceof org.onosproject.tetopology.management.api.link.UnnumberedLink) { |
| 210 | UnnumberedLink.UnnumberedLinkBuilder unnumberedLinkBuilder = DefaultUnnumberedLink.builder(); |
| 211 | unnumberedLinkBuilder.routerId(org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf |
| 212 | .inet.types.rev20130715.ietfinettypes.IpAddress |
| 213 | .fromString(((org.onosproject.tetopology.management.api.link.UnnumberedLink) type) |
| 214 | .routerId().toString())) |
| 215 | .interfaceId(((org.onosproject.tetopology.management.api.link.UnnumberedLink) type) |
| 216 | .interfaceId()); |
| 217 | return unnumberedLinkBuilder.build(); |
| 218 | } |
| 219 | return null; |
| 220 | } |
| 221 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 222 | /** |
| 223 | * TE Link underlay path Config object conversion from TE Topology subsystem to YANG. |
| 224 | * |
| 225 | * @param tePath TE underlay path object |
| 226 | * @return Link underlay path Config YANG object |
| 227 | */ |
| 228 | private static Underlay teSubsystem2YangConfigUnderlayPath(UnderlayPath tePath) { |
| 229 | checkNotNull(tePath, E_NULL_TELINK_UNDERLAY_PATH); |
| 230 | UnderlayBuilder builder = |
| 231 | DefaultUnderlay.builder().underlayProtectionType(tePath.protectionType()); |
| 232 | |
| 233 | if (tePath.primaryPath() != null) { |
| 234 | builder = te2YangConfigUnderlayPrimaryPath(builder, tePath.primaryPath()); |
| 235 | } |
| 236 | if (tePath.trailSrc() != null) { |
| 237 | builder = builder.underlayTrailSrc( |
| 238 | new UnderlayTrailSrcBuilder() |
| 239 | .networkRef(NetworkId.fromString( |
| 240 | tePath.trailSrc().networkId().toString())) |
| 241 | .nodeRef(NodeId.fromString( |
| 242 | tePath.trailSrc().nodeId().toString())) |
| 243 | .tpRef(TpId.fromString( |
| 244 | tePath.trailSrc().tpId().toString())) |
| 245 | .build()); |
| 246 | } |
| 247 | if (tePath.trailDes() != null) { |
| 248 | builder = builder.underlayTrailDes( |
| 249 | new UnderlayTrailDesBuilder() |
| 250 | .networkRef(NetworkId.fromString( |
| 251 | tePath.trailDes().networkId().toString())) |
| 252 | .nodeRef(NodeId.fromString( |
| 253 | tePath.trailDes().nodeId().toString())) |
| 254 | .tpRef(TpId.fromString( |
| 255 | tePath.trailDes().tpId().toString())) |
| 256 | .build()); |
| 257 | } |
| 258 | if (tePath.backupPaths() != null) { |
| 259 | builder = te2YangConfigUnderlayBackupPaths(builder, tePath.backupPaths()); |
| 260 | } |
| 261 | |
| 262 | return builder.build(); |
| 263 | } |
| 264 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 265 | private static Config teLink2YangConfig(TeLinkAttributesBuilder teLinkAttrBuilder) { |
| 266 | checkNotNull(teLinkAttrBuilder, E_NULL_TELINK_DATA); |
| 267 | |
| 268 | ConfigBuilder yangConfigBuilder = DefaultConfig.builder() |
| 269 | .teLinkAttributes(teLinkAttrBuilder.build()); |
| 270 | return yangConfigBuilder.build(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 273 | private static TeLinkAttributesBuilder teLink2YangAttrBuilder(TeLink teLink) { |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 274 | checkNotNull(teLink, E_NULL_TELINK_DATA); |
| 275 | |
| 276 | TeLinkAttributesBuilder attrBuilder = DefaultTeLinkAttributes.builder(); |
| 277 | if (teLink.linkIndex() != null) { |
| 278 | attrBuilder = attrBuilder.linkIndex(teLink.linkIndex()); |
| 279 | } |
| 280 | if (teLink.name() != null) { |
| 281 | attrBuilder = attrBuilder.name(teLink.name()); |
| 282 | } |
| 283 | if (teLink.adminStatus() != null) { |
| 284 | attrBuilder = attrBuilder |
| 285 | .adminStatus(EnumConverter |
| 286 | .teSubsystem2YangAdminStatus(teLink |
| 287 | .adminStatus())); |
| 288 | } |
| 289 | if (teLink.accessType() != null) { |
| 290 | attrBuilder = attrBuilder |
| 291 | .accessType(teSubsystem2YangTeLinkAccess(teLink |
| 292 | .accessType())); |
| 293 | } |
| 294 | if (teLink.linkProtectionType() != null) { |
| 295 | attrBuilder = attrBuilder |
| 296 | .linkProtectionType(teSubsystem2YangLinkProtectionType(teLink |
| 297 | .linkProtectionType())); |
| 298 | } |
| 299 | if (teLink.maxLinkBandwidth() != null) { |
| 300 | attrBuilder = attrBuilder.maxLinkBandwidth(teLink.maxLinkBandwidth()); |
| 301 | } |
| 302 | if (teLink.maxResvLinkBandwidth() != null) { |
| 303 | attrBuilder = attrBuilder.maxResvLinkBandwidth(teLink.maxResvLinkBandwidth()); |
| 304 | } |
| 305 | attrBuilder = attrBuilder.teDefaultMetric(teLink.teDefaultMetric()); |
| 306 | if (teLink.teSrlgs() != null) { |
| 307 | TeSrlgsBuilder teSrlgsBuilder = DefaultTeSrlgs.builder(); |
| 308 | for (Long srlgLongVal : teLink.teSrlgs()) { |
| 309 | teSrlgsBuilder = teSrlgsBuilder.addToValue(new Srlg(srlgLongVal)); |
| 310 | } |
| 311 | attrBuilder = attrBuilder.teSrlgs(teSrlgsBuilder.build()); |
| 312 | } |
| 313 | attrBuilder = attrBuilder.isAbstract(teLink.isAbstract()); |
| 314 | if (teLink.underlayPath() != null) { |
| 315 | attrBuilder = attrBuilder.underlay( |
| 316 | teSubsystem2YangConfigUnderlayPath(teLink.underlayPath())); |
| 317 | } |
| 318 | if (teLink.externalDomain() != null) { |
| 319 | ExternalDomainBuilder edBuilder = |
| 320 | DefaultExternalDomain.builder() |
| 321 | .plugId(teLink.externalDomain().plugId()) |
| 322 | .remoteTeLinkTpId(TeTpId.fromString( |
| 323 | teLink.externalDomain().remoteTeLinkTpId().toString())) |
| 324 | .remoteTeNodeId(TeNodeId.fromString( |
| 325 | teLink.externalDomain().remoteTeNodeId().toString())); |
| 326 | attrBuilder = attrBuilder.externalDomain(edBuilder.build()); |
| 327 | } |
| 328 | |
| 329 | if (teLink.unreservedBandwidths() != null) { |
| 330 | for (org.onosproject.tetopology.management.api.link.UnreservedBandwidth unResBwTe : |
| 331 | teLink.unreservedBandwidths()) { |
| 332 | UnreservedBandwidthBuilder urBuilder = |
| 333 | DefaultUnreservedBandwidth.builder() |
| 334 | .bandwidth(unResBwTe.bandwidth()) |
| 335 | .priority(unResBwTe.priority()); |
| 336 | attrBuilder = attrBuilder.addToUnreservedBandwidth(urBuilder.build()); |
| 337 | } |
| 338 | } |
| 339 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 340 | return attrBuilder; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | private static LinkProtectionTypeEnum |
| 344 | teSubsystem2YangLinkProtectionType(LinkProtectionType linkProtectionType) { |
| 345 | switch (linkProtectionType) { |
| 346 | case ENHANCED: |
| 347 | return LinkProtectionTypeEnum.ENHANCED; |
| 348 | case EXTRA_TRAFFIC: |
| 349 | return LinkProtectionTypeEnum.EXTRA_TRAFFIC; |
| 350 | case SHARED: |
| 351 | return LinkProtectionTypeEnum.SHARED; |
| 352 | case UNPROTECTED: |
| 353 | return LinkProtectionTypeEnum.UNPROTECTED; |
| 354 | case YANGAUTOPREFIX1_FOR_1: |
| 355 | return LinkProtectionTypeEnum.YANGAUTOPREFIX1_FOR_1; |
| 356 | case YANGAUTOPREFIX1_PLUS_1: |
| 357 | return LinkProtectionTypeEnum.YANGAUTOPREFIX1_PLUS_1; |
| 358 | default: |
| 359 | return null; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | private static TeLinkAccessType teSubsystem2YangTeLinkAccess( |
| 364 | org.onosproject.tetopology.management.api.link.TeLinkAccessType accessType) { |
| 365 | switch (accessType) { |
| 366 | case MULTI_ACCESS: |
| 367 | return TeLinkAccessType.of(TeLinkAccessTypeEnum.MULTI_ACCESS); |
| 368 | case POINT_TO_POINT: |
| 369 | return TeLinkAccessType.of(TeLinkAccessTypeEnum.POINT_TO_POINT); |
| 370 | default: |
| 371 | return null; |
| 372 | } |
| 373 | } |
| 374 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 375 | private static State teLink2YangState(TeLinkAttributesBuilder teLinkAttrBuilder, TeLink teLink) { |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 376 | StateBuilder yangStateBuilder = DefaultState.builder() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 377 | .teLinkAttributes(teLinkAttrBuilder.build()); |
| 378 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 379 | if (teLink.opStatus() != null) { |
| 380 | yangStateBuilder = yangStateBuilder |
| 381 | .operStatus(EnumConverter |
| 382 | .teSubsystem2YangOperStatus(teLink |
| 383 | .opStatus())); |
| 384 | } |
| 385 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 386 | // TODO: once stateDerived Underlay is available in core TE Topology |
| 387 | // object model, set the value properly |
| 388 | // stateDerivedUnderlay = org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology |
| 389 | // .rev20160708.ietftetopology.telinkstatederived.Underlay |
| 390 | // yangStateBuilder = yangStateBuilder.underlay(stateDerivedUnderlay); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 391 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 392 | return yangStateBuilder.build(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Link object conversion from TE Topology subsystem to YANG. |
| 397 | * |
| 398 | * @param teLink TE subsystem link object |
| 399 | * @return YANG link object |
| 400 | */ |
| 401 | public static Link teSubsystem2YangLink( |
| 402 | org.onosproject.tetopology.management.api.link.NetworkLink teLink) { |
| 403 | checkNotNull(teLink, E_NULL_TELINK); |
| 404 | |
| 405 | LinkId linkId = LinkId.fromString(teLink.linkId().toString()); |
| 406 | LinkBuilder builder = DefaultLink.builder().linkId(linkId); |
| 407 | if (teLink.getSupportingLinkIds() != null) { |
| 408 | List<SupportingLink> slinks = Lists.newArrayList(); |
| 409 | SupportingLinkBuilder spLinkBuilder = DefaultSupportingLink.builder(); |
| 410 | for (NetworkLinkKey linkKey : teLink.getSupportingLinkIds()) { |
| 411 | slinks.add(spLinkBuilder.networkRef(NetworkId.fromString( |
| 412 | linkKey.networkId().toString())) |
| 413 | .linkRef(LinkId.fromString( |
| 414 | linkKey.linkId().toString())) |
| 415 | .build()); |
| 416 | } |
| 417 | builder = builder.supportingLink(slinks); |
| 418 | } |
| 419 | if (teLink.getSource() != null) { |
| 420 | SourceBuilder sourceBuilder = DefaultSource |
| 421 | .builder() |
| 422 | .sourceNode(NodeId.fromString( |
| 423 | teLink.getSource().nodeId().toString())) |
| 424 | .sourceTp(TpId.fromString( |
| 425 | teLink.getSource().tpId().toString())); |
| 426 | builder = builder.source(sourceBuilder.build()); |
| 427 | } |
| 428 | if (teLink.getDestination() != null) { |
| 429 | DestinationBuilder destBuilder = DefaultDestination |
| 430 | .builder() |
| 431 | .destNode(NodeId.fromString( |
| 432 | teLink.getDestination().nodeId().toString())) |
| 433 | .destTp(TpId.fromString( |
| 434 | teLink.getDestination().tpId().toString())); |
| 435 | builder = builder.destination(destBuilder.build()); |
| 436 | } |
| 437 | |
| 438 | if (teLink.getTe() != null) { |
| 439 | TeLink teData = teLink.getTe(); |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 440 | TeLinkAttributesBuilder attrBuilder = teLink2YangAttrBuilder(teData); |
| 441 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 442 | TeBuilder yangTeBuilder = DefaultTe.builder() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 443 | .config(teLink2YangConfig(attrBuilder)) |
| 444 | .state(teLink2YangState(attrBuilder, teData)); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 445 | AugmentedNtLinkBuilder linkAugmentBuilder = |
| 446 | DefaultAugmentedNtLink.builder() |
| 447 | .te(yangTeBuilder.build()); |
| 448 | builder.addYangAugmentedInfo(linkAugmentBuilder.build(), AugmentedNtLink.class); |
| 449 | } |
| 450 | |
| 451 | return builder.build(); |
| 452 | } |
| 453 | |
| 454 | private static org.onosproject.tetopology.management.api.link.UnderlayPath |
| 455 | yang2TeSubsystemUnderlayPrimaryPath( |
| 456 | org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay, |
| 457 | UnderlayPrimaryPath yangpath) { |
| 458 | org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath teUnderlayPrimaryPath = |
| 459 | new org.onosproject.tetopology.management.api.link.UnderlayPrimaryPath(); |
| 460 | teUnderlayPrimaryPath.setRef(new TeNetworkTopologyId(KeyId.keyId( |
| 461 | yangpath.networkIdRef().toString()), |
| 462 | new org.onosproject.tetopology.management.api.TeTopologyId( |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 463 | ((long) yangpath.providerIdRef()), |
| 464 | ((long) yangpath.clientIdRef()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 465 | yangpath.teTopologyIdRef().toString()))); |
| 466 | |
| 467 | List<PathElement> pathElementList = Lists.newArrayList(); |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 468 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 469 | .telinkunderlayattributes.underlayprimarypath.PathElement pathElementConfigYang : |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 470 | yangpath.pathElement()) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 471 | PathElement tePathElement = new PathElement(pathElementConfigYang.pathElementId(), |
| 472 | findElementType(pathElementConfigYang.type())); |
| 473 | pathElementList.add(tePathElement); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 474 | } |
| 475 | teUnderlayPrimaryPath.setPathElement(pathElementList); |
| 476 | teUnderlay.setPrimaryPath(teUnderlayPrimaryPath); |
| 477 | |
| 478 | return teUnderlay; |
| 479 | } |
| 480 | |
| 481 | private static org.onosproject.tetopology.management.api.link.UnderlayPath |
| 482 | yang2TeSubsystemUnderlayBackupPaths( |
| 483 | org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay, |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 484 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology |
| 485 | .rev20160708.ietftetopology.telinkunderlayattributes.UnderlayBackupPath> yangpaths) { |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 486 | List<UnderlayBackupPath> underlayBackupPathsList = Lists.newArrayList(); |
| 487 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 488 | .ietftetopology.telinkunderlayattributes.UnderlayBackupPath yangConfig : yangpaths) { |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 489 | UnderlayBackupPath ubp = new UnderlayBackupPath(); |
| 490 | ubp.setIndex(yangConfig.index()); |
| 491 | ubp.setRef(new TeNetworkTopologyId(KeyId.keyId(yangConfig.networkIdRef().toString()), |
| 492 | new org.onosproject.tetopology.management.api.TeTopologyId( |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 493 | ((long) yangConfig.providerIdRef()), |
| 494 | ((long) yangConfig.clientIdRef()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 495 | yangConfig.teTopologyIdRef().toString() |
| 496 | ))); |
| 497 | List<PathElement> backupPathElementList = Lists.newArrayList(); |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 498 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 499 | .ietftetopology.telinkunderlayattributes.underlaybackuppath.PathElement |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 500 | pathElementBackupYang : yangConfig.pathElement()) { |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 501 | PathElement tePathElementBackup = |
| 502 | new PathElement(pathElementBackupYang.pathElementId(), |
| 503 | findElementType(pathElementBackupYang.type())); |
| 504 | backupPathElementList.add(tePathElementBackup); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 505 | } |
| 506 | ubp.setPathElement(backupPathElementList); |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 507 | underlayBackupPathsList.add(ubp); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 508 | } |
| 509 | teUnderlay.setBackupPath(underlayBackupPathsList); |
| 510 | |
| 511 | return teUnderlay; |
| 512 | } |
| 513 | |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 514 | private static ElementType findElementType(Type type) { |
| 515 | ElementType el = null; |
| 516 | if (type instanceof AsNumber) { |
| 517 | org.onosproject.tetopology.management.api.link.AsNumber elementTypeAsNumber = new org.onosproject |
| 518 | .tetopology.management.api.link.AsNumber(((AsNumber) type).asNumber()); |
| 519 | return elementTypeAsNumber; |
| 520 | } else if (type instanceof Ipv4Address) { |
| 521 | TeIpv4 elementTypeIpv4 = new TeIpv4(); |
| 522 | String ipVal = ((Ipv4Address) type).v4Address().toString(); |
| 523 | elementTypeIpv4.setV4Address(Ip4Address.valueOf(Version.INET, ipVal.getBytes()).getIp4Address()); |
| 524 | boolean v4Loose = ((Ipv4Address) type).v4Loose(); |
| 525 | elementTypeIpv4.setV4Loose(v4Loose); |
| 526 | short v4PrefixLength = ((Ipv4Address) type).v4PrefixLength(); |
| 527 | elementTypeIpv4.setV4PrefixLength(v4PrefixLength); |
| 528 | return elementTypeIpv4; |
| 529 | } else if (type instanceof UnnumberedLink) { |
| 530 | org.onosproject.tetopology.management.api.link.UnnumberedLink elementTypeUnnumberedLink = new org |
| 531 | .onosproject.tetopology.management.api.link.UnnumberedLink(); |
| 532 | long interfaceId = ((UnnumberedLink) type).interfaceId(); |
| 533 | elementTypeUnnumberedLink.setInterfaceId(interfaceId); |
| 534 | IpAddress routerId = IpAddress.valueOf(((UnnumberedLink) type).routerId().toString()); |
| 535 | elementTypeUnnumberedLink.setRouterId(routerId); |
| 536 | return elementTypeUnnumberedLink; |
| 537 | } |
| 538 | // TODO: as an improvement in future, construct the tePathElement object |
| 539 | // properly using pathElementConfigYang |
| 540 | // More types need to be added to the above if/else statements. |
| 541 | // Now, I only have AsNumber, Ipv4Address, and UnnumberedLink |
| 542 | return el; |
| 543 | } |
| 544 | |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 545 | /** |
| 546 | * TE Link underlay path Config object conversion from YANG to TE Topology subsystem. |
| 547 | * |
| 548 | * @param yangLinkAtrr YANG link Config YANG object |
| 549 | * @return teSubsystem TE underlay path object |
| 550 | */ |
| 551 | private static org.onosproject.tetopology.management.api.link.UnderlayPath |
| 552 | yang2TeSubsystemUnderlayPath(TeLinkAttributes yangLinkAtrr) { |
| 553 | checkNotNull(yangLinkAtrr, E_NULL_YANG_TELINK_CONFIG); |
| 554 | |
| 555 | org.onosproject.tetopology.management.api.link.UnderlayPath teUnderlay = |
| 556 | new org.onosproject.tetopology.management.api.link.UnderlayPath(); |
| 557 | |
| 558 | teUnderlay.setProtectionType(yangLinkAtrr.underlay().underlayProtectionType()); |
| 559 | |
| 560 | if (yangLinkAtrr.underlay().underlayPrimaryPath() != null) { |
| 561 | teUnderlay = yang2TeSubsystemUnderlayPrimaryPath(teUnderlay, |
| 562 | yangLinkAtrr.underlay().underlayPrimaryPath()); |
| 563 | } |
| 564 | |
| 565 | if (yangLinkAtrr.underlay().underlayBackupPath() != null) { |
| 566 | teUnderlay = yang2TeSubsystemUnderlayBackupPaths(teUnderlay, |
| 567 | yangLinkAtrr.underlay().underlayBackupPath()); |
| 568 | } |
| 569 | |
| 570 | if (yangLinkAtrr.underlay().underlayTrailSrc() != null) { |
| 571 | teUnderlay.setTrailSrc(new TerminationPointKey( |
| 572 | KeyId.keyId(yangLinkAtrr.underlay().underlayTrailSrc() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 573 | .networkRef().toString()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 574 | KeyId.keyId(yangLinkAtrr.underlay().underlayTrailSrc() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 575 | .nodeRef().toString()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 576 | KeyId.keyId(yangLinkAtrr.underlay().underlayTrailSrc() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 577 | .tpRef().toString()))); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | if (yangLinkAtrr.underlay().underlayTrailDes() != null) { |
| 581 | teUnderlay.setTrailDes(new TerminationPointKey( |
| 582 | KeyId.keyId(yangLinkAtrr.underlay().underlayTrailDes() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 583 | .networkRef().toString()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 584 | KeyId.keyId(yangLinkAtrr.underlay().underlayTrailDes() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 585 | .nodeRef().toString()), |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 586 | KeyId.keyId(yangLinkAtrr.underlay().underlayTrailDes() |
Hesam Rahimi | e96d0be | 2016-10-19 15:51:11 -0400 | [diff] [blame] | 587 | .tpRef().toString()))); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | return teUnderlay; |
| 591 | } |
| 592 | |
| 593 | private static TeLink yang2TeLinkAttributes(TeLinkAttributes yangLinkAtrr, |
| 594 | State opState) { |
| 595 | TeLink te = new TeLink(yangLinkAtrr.linkIndex()); |
| 596 | if (yangLinkAtrr.name() != null) { |
| 597 | te.setName(yangLinkAtrr.name()); |
| 598 | } |
| 599 | if (yangLinkAtrr.adminStatus() != null) { |
| 600 | te.setAdminStatus(EnumConverter.yang2TeSubsystemAdminStatus( |
| 601 | yangLinkAtrr.adminStatus())); |
| 602 | } |
| 603 | if (opState != null && opState.operStatus() != null) { |
| 604 | te.setOpStatus(EnumConverter.yang2TeSubsystemOpStatus( |
| 605 | opState.operStatus())); |
| 606 | } |
| 607 | if (yangLinkAtrr.accessType() != null) { |
| 608 | te.setAccessType(yang2TeSubsystemAccessType( |
| 609 | yangLinkAtrr.accessType())); |
| 610 | } |
| 611 | if (yangLinkAtrr.linkProtectionType() != null) { |
| 612 | te.setLinkProtectionType(yang2TeSubsystemLinkProtectionType( |
| 613 | yangLinkAtrr.linkProtectionType())); |
| 614 | } |
| 615 | if (yangLinkAtrr.maxLinkBandwidth() != null) { |
| 616 | te.setMaxLinkBandwidth(yangLinkAtrr.maxLinkBandwidth()); |
| 617 | } |
| 618 | if (yangLinkAtrr.maxResvLinkBandwidth() != null) { |
| 619 | te.setMaxResvLinkBandwidth(yangLinkAtrr.maxResvLinkBandwidth()); |
| 620 | } |
| 621 | te.setTeDefaultMetric(yangLinkAtrr.teDefaultMetric()); |
| 622 | te.setIsAbstract(yangLinkAtrr.isAbstract()); |
| 623 | if (yangLinkAtrr.teSrlgs() != null) { |
| 624 | List<Long> srlgs = Lists.newArrayList(); |
| 625 | for (Srlg srlgConfigYang : yangLinkAtrr.teSrlgs().value()) { |
| 626 | srlgs.add(srlgConfigYang.uint32()); |
| 627 | } |
| 628 | te.setTeSrlgs(srlgs); |
| 629 | } |
| 630 | if (yangLinkAtrr.externalDomain() != null) { |
| 631 | te.setExternalDomain(new ExternalDomain( |
| 632 | KeyId.keyId(yangLinkAtrr.externalDomain() |
| 633 | .remoteTeNodeId().toString()), |
| 634 | KeyId.keyId(yangLinkAtrr.externalDomain() |
| 635 | .remoteTeLinkTpId().toString()), |
| 636 | yangLinkAtrr.externalDomain().plugId())); |
| 637 | } |
| 638 | if (yangLinkAtrr.underlay() != null) { |
| 639 | te.setUnderlayPath(yang2TeSubsystemUnderlayPath(yangLinkAtrr)); |
| 640 | } |
| 641 | if (yangLinkAtrr.unreservedBandwidth() != null) { |
| 642 | List<org.onosproject.tetopology.management.api.link.UnreservedBandwidth> |
| 643 | unreservedBandwidths = Lists.newArrayList(); |
| 644 | for (UnreservedBandwidth urBwYang : yangLinkAtrr.unreservedBandwidth()) { |
| 645 | org.onosproject.tetopology.management.api.link.UnreservedBandwidth unResBw = |
| 646 | new org.onosproject.tetopology.management.api.link.UnreservedBandwidth( |
| 647 | urBwYang.priority(), |
| 648 | urBwYang.bandwidth()); |
| 649 | unreservedBandwidths.add(unResBw); |
| 650 | } |
| 651 | te.setUnreservedBandwidths(unreservedBandwidths); |
| 652 | } |
| 653 | return te; |
| 654 | } |
| 655 | |
| 656 | private static LinkProtectionType |
| 657 | yang2TeSubsystemLinkProtectionType(LinkProtectionTypeEnum linkProtectionType) { |
| 658 | switch (linkProtectionType) { |
| 659 | case ENHANCED: |
| 660 | return LinkProtectionType.ENHANCED; |
| 661 | case EXTRA_TRAFFIC: |
| 662 | return LinkProtectionType.EXTRA_TRAFFIC; |
| 663 | case SHARED: |
| 664 | return LinkProtectionType.SHARED; |
| 665 | case UNPROTECTED: |
| 666 | return LinkProtectionType.UNPROTECTED; |
| 667 | case YANGAUTOPREFIX1_FOR_1: |
| 668 | return LinkProtectionType.YANGAUTOPREFIX1_FOR_1; |
| 669 | case YANGAUTOPREFIX1_PLUS_1: |
| 670 | return LinkProtectionType.YANGAUTOPREFIX1_PLUS_1; |
| 671 | default: |
| 672 | return null; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | private static org.onosproject.tetopology.management.api.link.TeLinkAccessType |
| 677 | yang2TeSubsystemAccessType(TeLinkAccessType accessType) { |
| 678 | switch (accessType.enumeration()) { |
| 679 | case MULTI_ACCESS: |
| 680 | return org.onosproject.tetopology.management.api.link.TeLinkAccessType.MULTI_ACCESS; |
| 681 | case POINT_TO_POINT: |
| 682 | return org.onosproject.tetopology.management.api.link.TeLinkAccessType.POINT_TO_POINT; |
| 683 | default: |
| 684 | return null; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * Link object conversion from YANG to TE Topology subsystem. |
| 690 | * |
| 691 | * @param yangLink YANG link object |
| 692 | * @param networkId YANG networkId object |
| 693 | * @return TE subsystem link object |
| 694 | */ |
| 695 | public static org.onosproject.tetopology.management.api.link.NetworkLink |
| 696 | yang2TeSubsystemLink(Link yangLink, NetworkId networkId) { |
| 697 | checkNotNull(yangLink, E_NULL_YANG_TELINK); |
| 698 | |
| 699 | org.onosproject.tetopology.management.api.link.DefaultNetworkLink link = |
| 700 | new org.onosproject.tetopology.management.api.link.DefaultNetworkLink( |
| 701 | KeyId.keyId(yangLink.linkId().uri().toString())); |
| 702 | |
| 703 | if (yangLink.supportingLink() != null) { |
| 704 | List<NetworkLinkKey> spLinkIds = Lists.newArrayList(); |
| 705 | for (SupportingLink yangSpLink : yangLink.supportingLink()) { |
| 706 | NetworkLinkKey linkKey = new NetworkLinkKey(KeyId.keyId(yangSpLink.networkRef().uri().toString()), |
| 707 | KeyId.keyId(yangSpLink.linkRef().uri().toString())); |
| 708 | spLinkIds.add(linkKey); |
| 709 | } |
| 710 | link.setSupportingLinkIds(spLinkIds); |
| 711 | } |
| 712 | |
| 713 | if (yangLink.source() != null) { |
| 714 | TerminationPointKey source = new TerminationPointKey( |
| 715 | KeyId.keyId(networkId.uri().toString()), |
| 716 | KeyId.keyId(yangLink.source().sourceNode().uri().toString()), |
| 717 | KeyId.keyId(yangLink.source().sourceTp().uri().toString())); |
| 718 | link.setSource(source); |
| 719 | } |
| 720 | |
| 721 | if (yangLink.destination() != null) { |
| 722 | TerminationPointKey destination = new TerminationPointKey( |
| 723 | KeyId.keyId(networkId.uri().toString()), |
| 724 | KeyId.keyId(yangLink.destination().destNode().uri().toString()), |
| 725 | KeyId.keyId(yangLink.destination().destTp().uri().toString())); |
| 726 | link.setDestination(destination); |
| 727 | } |
| 728 | |
| 729 | if (yangLink.yangAugmentedInfoMap() != null && !yangLink.yangAugmentedInfoMap().isEmpty()) { |
| 730 | |
| 731 | AugmentedNtLink yangLinkAugment = |
| 732 | (AugmentedNtLink) yangLink.yangAugmentedInfo(AugmentedNtLink.class); |
| 733 | if (yangLinkAugment != null && |
| 734 | yangLinkAugment.te() != null && |
| 735 | yangLinkAugment.te().config() != null) { |
| 736 | TeLinkAttributes yangLinkAtrr = |
| 737 | yangLinkAugment.te().config().teLinkAttributes(); |
| 738 | if (yangLinkAtrr != null && yangLinkAtrr.linkIndex() != null) { |
| 739 | TeLink te = yang2TeLinkAttributes(yangLinkAtrr, yangLinkAugment.te().state()); |
| 740 | link.setTe(te); |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | return link; |
| 745 | } |
| 746 | |
| 747 | } |