Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.teyang.utils.topology; |
| 17 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.nio.ByteBuffer; |
| 21 | import java.util.BitSet; |
| 22 | import java.util.List; |
| 23 | import java.util.Map; |
| 24 | |
| 25 | import org.onlab.packet.Ip4Address; |
| 26 | import org.onosproject.tetopology.management.api.EncodingType; |
| 27 | import org.onosproject.tetopology.management.api.KeyId; |
| 28 | import org.onosproject.tetopology.management.api.SwitchingType; |
| 29 | import org.onosproject.tetopology.management.api.TeStatus; |
| 30 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 31 | import org.onosproject.tetopology.management.api.TeTopologyService; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 32 | import org.onosproject.tetopology.management.api.link.ElementType; |
| 33 | import org.onosproject.tetopology.management.api.link.NetworkLink; |
| 34 | import org.onosproject.tetopology.management.api.link.TeLinkId; |
| 35 | import org.onosproject.tetopology.management.api.link.TePathAttributes; |
| 36 | import org.onosproject.tetopology.management.api.link.UnderlayAbstractPath; |
| 37 | import org.onosproject.tetopology.management.api.node.CommonNodeData; |
| 38 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrix; |
| 39 | import org.onosproject.tetopology.management.api.node.ConnectivityMatrixKey; |
| 40 | import org.onosproject.tetopology.management.api.node.DefaultNetworkNode; |
| 41 | import org.onosproject.tetopology.management.api.node.DefaultTeNode; |
| 42 | import org.onosproject.tetopology.management.api.node.LocalLinkConnectivity; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 43 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 44 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 45 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 46 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 47 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
| 48 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev20130715.ietfinettypes.DomainName; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 49 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NetworkId; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 50 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.NodeId; |
| 51 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ietfnetwork.networks.Network; |
| 52 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 53 | .ietfnetwork.networks.network.DefaultNode; |
| 54 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 55 | .ietfnetwork.networks.network.Node; |
| 56 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 57 | .ietfnetwork.networks.network.node.DefaultSupportingNode; |
| 58 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208 |
| 59 | .ietfnetwork.networks.network.node.SupportingNode; |
| 60 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.TpId; |
| 61 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.AugmentedNdNetwork; |
| 62 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ietfnetworktopology.networks.network.augmentedndnetwork.Link; |
| 63 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 64 | .ietfnetworktopology.networks.network.node.AugmentedNdNode; |
| 65 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208 |
| 66 | .ietfnetworktopology.networks.network.node.DefaultAugmentedNdNode; |
| 67 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.DefaultTeNodeEvent; |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 68 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.TeNodeEvent; |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 69 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState; |
| 70 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.InformationSourceState; |
| 71 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.DefaultInformationSourceState.InformationSourceStateBuilder; |
| 72 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.DefaultTopology; |
| 73 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.informationsourceattributes.informationsourcestate.Topology; |
| 74 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 75 | .ietftetopology.networks.network.node.AugmentedNwNode; |
| 76 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 77 | .ietftetopology.networks.network.node.DefaultAugmentedNwNode; |
| 78 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe; |
| 79 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.DefaultTe.TeBuilder; |
| 80 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.Te; |
| 81 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.Config; |
| 82 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultConfig; |
| 83 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultState; |
| 84 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.DefaultTunnelTerminationPoint; |
| 85 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.State; |
| 86 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeaugment.te.TunnelTerminationPoint; |
| 87 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.DefaultTeNodeAttributes; |
| 88 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes; |
| 89 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconfigattributes.TeNodeAttributes.TeNodeAttributesBuilder; |
| 90 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix; |
| 91 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.DefaultConnectivityMatrix.ConnectivityMatrixBuilder; |
| 92 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultFrom; |
| 93 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrix.connectivitymatrix.DefaultTo; |
| 94 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.DefaultUnderlayTopology; |
| 95 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeinfoattributes.UnderlayTopology; |
| 96 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.DefaultTerminationCapability; |
| 97 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodetunnelterminationcapability.TerminationCapability; |
| 98 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.Srlg; |
| 99 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeAdminStatus; |
| 100 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeNodeId; |
| 101 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyEventType; |
| 102 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.TeTopologyId; |
| 103 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.types.rev20160705.ietftetypes.tetopologyeventtype.TeTopologyEventTypeEnum; |
| 104 | |
| 105 | import com.google.common.collect.Lists; |
| 106 | import com.google.common.collect.Maps; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Node conversion functions. |
| 110 | */ |
| 111 | public final class NodeConverter { |
| 112 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 113 | private static final String E_NULL_TE_SUBSYSTEM_TE_NODE = |
| 114 | "TeSubsystem teNode object cannot be null"; |
| 115 | private static final String E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP = |
| 116 | "TeSubsystem teTunnelTp object cannot be null"; |
| 117 | private static final String E_NULL_TE_SUBSYSTEM_NODE = |
| 118 | "TeSubsystem ndoe object cannot be null"; |
| 119 | private static final String E_NULL_YANG_NODE = |
| 120 | "Yang node object cannot be null"; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 121 | |
| 122 | // no instantiation |
| 123 | private NodeConverter() { |
| 124 | } |
| 125 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 126 | /** |
| 127 | * TE Node Config object conversion from TE Topology subsystem to YANG. |
| 128 | * |
| 129 | * @param teSubsystemTeNode TE node object |
| 130 | * @return TE Node Config YANG object |
| 131 | */ |
| 132 | private static Config teNode2YangConfig(TeNode teSubsystemTeNode) { |
| 133 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 134 | |
| 135 | TeNodeAttributes.TeNodeAttributesBuilder teNodeAttributesConfigBuilder = DefaultTeNodeAttributes |
| 136 | .builder(); |
| 137 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 138 | .isAbstract(teSubsystemTeNode.flags() |
| 139 | .get(TeNode.BIT_ABSTRACT)); |
| 140 | |
| 141 | if (teSubsystemTeNode.adminStatus() != null) { |
| 142 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 143 | .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus())); |
| 144 | } |
| 145 | |
| 146 | if (teSubsystemTeNode.name() != null) { |
| 147 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 148 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 149 | } |
| 150 | |
| 151 | if (teSubsystemTeNode.underlayTeTopologyId() != null) { |
| 152 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 153 | .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode |
| 154 | .underlayTeTopologyId())); |
| 155 | } |
| 156 | |
| 157 | // TODO: should we ignore this from te to yang? as we've already set yang supportingNode |
| 158 | if (teSubsystemTeNode.supportingTeNodeId() != null) { |
| 159 | } |
| 160 | |
| 161 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
| 162 | teNodeAttributesConfigBuilder = te2YangConnectivityMatrix(teNodeAttributesConfigBuilder, |
| 163 | teSubsystemTeNode.connectivityMatrices()); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | Config.ConfigBuilder yangConfigBuilder = DefaultConfig.builder(); |
| 168 | yangConfigBuilder = yangConfigBuilder.teNodeAttributes(teNodeAttributesConfigBuilder.build()); |
| 169 | |
| 170 | return yangConfigBuilder.build(); |
| 171 | } |
| 172 | |
| 173 | private static TeNodeAttributesBuilder |
| 174 | te2YangConnectivityMatrix(TeNodeAttributesBuilder teNodeAttributesConfigBuilder, |
| 175 | Map<Long, ConnectivityMatrix> connectivityMatrices) { |
| 176 | ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = DefaultConnectivityMatrix.builder(); |
| 177 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
| 178 | connectivityMatrices.entrySet()) { |
| 179 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 180 | .id(teCmEntry.getKey()) |
| 181 | .isAllowed(!teCmEntry.getValue().flags() |
| 182 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
| 183 | .from(new DefaultFrom.FromBuilder() // TODO: for now, assuming that there is |
| 184 | // only one 'from', and mergingList is empty |
| 185 | .tpRef(teCmEntry.getValue().from()) |
| 186 | .build()) |
| 187 | .to(new DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
| 188 | // one item in constrainingElements list |
| 189 | .tpRef(teCmEntry.getValue().constrainingElements().get(0)) |
| 190 | .build()); |
| 191 | teNodeAttributesConfigBuilder = teNodeAttributesConfigBuilder |
| 192 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
| 193 | .build()); |
| 194 | } |
| 195 | return teNodeAttributesConfigBuilder; |
| 196 | } |
| 197 | |
| 198 | private static UnderlayTopology teNode2YangUnderlay(TeTopologyKey underlayTopology) { |
| 199 | UnderlayTopology.UnderlayTopologyBuilder underlayBuilder = DefaultUnderlayTopology |
| 200 | .builder() |
| 201 | .teTopologyIdRef(TeTopologyId |
| 202 | .fromString(String.valueOf(underlayTopology.topologyId()))) |
| 203 | .clientIdRef(underlayTopology.clientId()) |
| 204 | .providerIdRef(underlayTopology.providerId()); |
| 205 | // TODO: find networkId from the service |
| 206 | // .networkIdRef(networkIdRef) |
| 207 | return underlayBuilder.build(); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * TE Node State object conversion from TE Topology subsystem to YANG. |
| 212 | * |
| 213 | * @param teSubsystemTeNode TE node object |
| 214 | * @return TE Node State YANG object |
| 215 | */ |
| 216 | private static State teNode2YangState(TeNode teSubsystemTeNode) { |
| 217 | checkNotNull(teSubsystemTeNode, E_NULL_TE_SUBSYSTEM_TE_NODE); |
| 218 | |
| 219 | TeNodeAttributes |
| 220 | .TeNodeAttributesBuilder teNodeAttributesStateBuilder = |
| 221 | DefaultTeNodeAttributes.builder() |
| 222 | .isAbstract(teSubsystemTeNode.flags() |
| 223 | .get(TeNode.BIT_ABSTRACT)); |
| 224 | |
| 225 | if (teSubsystemTeNode.adminStatus() != null) { |
| 226 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 227 | .adminStatus(EnumConverter.teSubsystem2YangAdminStatus(teSubsystemTeNode.adminStatus())); |
| 228 | } |
| 229 | |
| 230 | if (teSubsystemTeNode.name() != null) { |
| 231 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 232 | .name(DomainName.fromString(teSubsystemTeNode.name())); |
| 233 | } |
| 234 | |
| 235 | if (teSubsystemTeNode.underlayTeTopologyId() != null) { |
| 236 | teNodeAttributesStateBuilder = teNodeAttributesStateBuilder |
| 237 | .underlayTopology(teNode2YangUnderlay(teSubsystemTeNode |
| 238 | .underlayTeTopologyId())); |
| 239 | } |
| 240 | |
| 241 | if (teSubsystemTeNode.connectivityMatrices() != null) { |
| 242 | teNodeAttributesStateBuilder = te2YangConnectivityMatrix(teNodeAttributesStateBuilder, |
| 243 | teSubsystemTeNode.connectivityMatrices()); |
| 244 | } |
| 245 | |
| 246 | // TODO: should we ignore this from te to yang? as we've already set yang supportingNode |
| 247 | if (teSubsystemTeNode.supportingTeNodeId() != null) { |
| 248 | } |
| 249 | |
| 250 | State.StateBuilder yangStateBuilder = DefaultState.builder(); |
| 251 | yangStateBuilder = yangStateBuilder.teNodeAttributes(teNodeAttributesStateBuilder.build()); |
| 252 | |
| 253 | if (teSubsystemTeNode.opStatus() != null) { |
| 254 | yangStateBuilder = yangStateBuilder.operStatus(EnumConverter |
| 255 | .teSubsystem2YangOperStatus(teSubsystemTeNode.opStatus())); |
| 256 | } |
| 257 | |
| 258 | if (teSubsystemTeNode.sourceTeNodeId() != null) { |
| 259 | InformationSourceState.InformationSourceStateBuilder issBuilder = DefaultInformationSourceState.builder(); |
| 260 | |
| 261 | Topology.TopologyBuilder topologyBuilder = DefaultTopology.builder(); |
| 262 | topologyBuilder = |
| 263 | topologyBuilder.clientIdRef(teSubsystemTeNode.sourceTeNodeId().clientId()) |
| 264 | .providerIdRef(teSubsystemTeNode.sourceTeNodeId().providerId()) |
| 265 | // is this correct? Why not sourceTeNodeId().teTopologyKey()? |
| 266 | .teTopologyIdRef(teSubsystemTeNode |
| 267 | .sourceTeNodeId().topologyId()); |
| 268 | issBuilder = issBuilder.topology(topologyBuilder.build()); |
| 269 | yangStateBuilder.informationSourceState(issBuilder.build()); |
| 270 | } |
| 271 | |
| 272 | return yangStateBuilder.build(); |
| 273 | } |
| 274 | |
| 275 | private static class ByteUtils { |
| 276 | private static ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); |
| 277 | |
| 278 | public static byte[] longToBytes(long x) { |
| 279 | buffer.putLong(0, x); |
| 280 | return buffer.array(); |
| 281 | } |
| 282 | |
| 283 | public static long bytesToLong(byte[] bytes) { |
| 284 | buffer.put(bytes, 0, bytes.length); |
| 285 | buffer.flip(); // need flip |
| 286 | return buffer.getLong(); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * TE Node TunnelTerminationPoint object conversion from TE Topology subsystem to YANG. |
| 292 | * |
| 293 | * @param teTunnelTp TE TunnelTerminationPoint object |
| 294 | * @return TunnelTerminationPoint YANG object |
| 295 | */ |
| 296 | private static TunnelTerminationPoint teSubsystem2YangTtp( |
| 297 | org.onosproject.tetopology.management.api.node |
| 298 | .TunnelTerminationPoint teTunnelTp, Long teTpId) { |
| 299 | checkNotNull(teTunnelTp, E_NULL_TE_SUBSYSTEM_TE_TUNNEL_TP); |
| 300 | |
| 301 | TunnelTerminationPoint.TunnelTerminationPointBuilder tunnelTpBuilder = |
| 302 | DefaultTunnelTerminationPoint.builder().tunnelTpId(ByteUtils.longToBytes(teTpId.longValue())); |
| 303 | |
| 304 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 305 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.Config.ConfigBuilder ttpConfigBuilder = |
| 306 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 307 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultConfig.builder(); |
| 308 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 309 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.State.StateBuilder ttpStateBuilder = |
| 310 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 311 | .ietftetopology.tenodeaugment.te.tunnelterminationpoint.DefaultState.builder(); |
| 312 | |
| 313 | // Assuming teTunnelTp only has one interLayerLock |
| 314 | if (teTunnelTp.interLayerLockList() != null && !teTunnelTp.interLayerLockList().isEmpty()) { |
| 315 | ttpConfigBuilder = ttpConfigBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0)); |
| 316 | ttpStateBuilder = ttpStateBuilder.interLayerLockId(teTunnelTp.interLayerLockList().get(0)); |
| 317 | } |
| 318 | |
| 319 | TerminationCapability.TerminationCapabilityBuilder |
| 320 | tcapConfigBuilder = DefaultTerminationCapability.builder(); |
| 321 | // TODO: retrieve more attributes from teTunnelTp and assign to tcapConfigBuilder. |
| 322 | // For which ones we can do the conversion? |
| 323 | // FIXME: once new yang model is used, we can make llc from teTunnelTp.localLinkConnectivityList() |
| 324 | ttpConfigBuilder = ttpConfigBuilder.addToTerminationCapability(tcapConfigBuilder.build()); |
| 325 | |
| 326 | TerminationCapability.TerminationCapabilityBuilder tcapStateBuilder = |
| 327 | DefaultTerminationCapability.builder(); |
| 328 | // TODO: retrieve more attributes from teTunnelTp and assign to tcapStateBuilder |
| 329 | // For which ones we can do the conversion? |
| 330 | ttpStateBuilder = ttpStateBuilder.addToTerminationCapability(tcapStateBuilder.build()); |
| 331 | |
| 332 | tunnelTpBuilder = tunnelTpBuilder.config(ttpConfigBuilder.build()) |
| 333 | .state(ttpStateBuilder.build()); |
| 334 | |
| 335 | return tunnelTpBuilder.build(); |
| 336 | } |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 337 | |
| 338 | /** |
| 339 | * Node object conversion from TE Topology subsystem to YANG. |
| 340 | * |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 341 | * @param teSubsystem TE subsystem node |
| 342 | * @return YANG node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 343 | */ |
| 344 | public static Node teSubsystem2YangNode(org.onosproject.tetopology.management.api.node.NetworkNode teSubsystem) { |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 345 | checkNotNull(teSubsystem, E_NULL_TE_SUBSYSTEM_NODE); |
| 346 | |
| 347 | NodeId nodeId = NodeId.fromString(teSubsystem.nodeId().toString()); |
| 348 | Node.NodeBuilder builder = DefaultNode.builder().nodeId(nodeId); |
| 349 | |
| 350 | if (teSubsystem.supportingNodeIds() != null) { |
| 351 | List<SupportingNode> sNodes = Lists.newArrayList(); |
| 352 | SupportingNode.SupportingNodeBuilder spNodeBuilder = DefaultSupportingNode |
| 353 | .builder(); |
| 354 | for (NetworkNodeKey nodeKey : teSubsystem.supportingNodeIds()) { |
| 355 | sNodes.add(spNodeBuilder |
| 356 | .networkRef(NetworkId |
| 357 | .fromString(nodeKey.networkId().toString())) |
| 358 | .nodeRef(NodeId.fromString(nodeKey.nodeId().toString())) |
| 359 | .build()); |
| 360 | } |
| 361 | builder = builder.supportingNode(sNodes); |
| 362 | } |
| 363 | |
| 364 | if (teSubsystem.terminationPoints() != null) { |
| 365 | AugmentedNdNode.AugmentedNdNodeBuilder tpAugmentBuilder = DefaultAugmentedNdNode |
| 366 | .builder(); |
| 367 | Map<KeyId, TerminationPoint> teSubsystemTeTp = teSubsystem |
| 368 | .terminationPoints(); |
| 369 | |
| 370 | for (TerminationPoint teTp : teSubsystemTeTp.values()) { |
| 371 | tpAugmentBuilder.addToTerminationPoint(TerminationPointConverter |
| 372 | .teSubsystem2YangTerminationPoint(teTp)); |
| 373 | } |
| 374 | builder.addYangAugmentedInfo(tpAugmentBuilder.build(), |
| 375 | AugmentedNdNode.class); |
| 376 | } |
| 377 | |
| 378 | if (teSubsystem.teNode() != null) { |
| 379 | AugmentedNwNode.AugmentedNwNodeBuilder nodeAugmentBuilder = DefaultAugmentedNwNode |
| 380 | .builder(); |
| 381 | |
| 382 | TeNode teSubsystemTeNode = teSubsystem.teNode(); |
| 383 | |
| 384 | TeBuilder yangTeBuilder = DefaultTe.builder(); |
| 385 | |
| 386 | yangTeBuilder = yangTeBuilder.teNodeId(TeNodeId |
| 387 | .fromString(String.valueOf(teSubsystemTeNode.teNodeId()))); |
| 388 | |
| 389 | // Set configuration data |
| 390 | // Set state data |
| 391 | yangTeBuilder = yangTeBuilder.config(teNode2YangConfig(teSubsystemTeNode)) |
| 392 | .state(teNode2YangState(teSubsystemTeNode)); |
| 393 | |
| 394 | if (teSubsystemTeNode.tunnelTerminationPoints() != null) { |
| 395 | for (Map.Entry<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> entry : |
| 396 | teSubsystemTeNode.tunnelTerminationPoints().entrySet()) { |
| 397 | yangTeBuilder = yangTeBuilder |
| 398 | .addToTunnelTerminationPoint(teSubsystem2YangTtp(entry |
| 399 | .getValue(), entry.getKey())); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | nodeAugmentBuilder = nodeAugmentBuilder.te(yangTeBuilder.build()); |
| 404 | builder.addYangAugmentedInfo(nodeAugmentBuilder.build(), |
| 405 | AugmentedNwNode.class); |
| 406 | } |
| 407 | return builder.build(); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Node object conversion from YANG to TE Topology subsystem. |
| 412 | * |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 413 | * @param yangNode Node in YANG model |
| 414 | * @param yangNetwork YANG network |
| 415 | * @param yangNetwork Network node in YANG model |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 416 | * @return TE subsystem node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 417 | */ |
| 418 | public static org.onosproject.tetopology.management.api.node.NetworkNode |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 419 | yang2TeSubsystemNode(Node yangNode, Network yangNetwork) { |
| 420 | checkNotNull(yangNode, E_NULL_YANG_NODE); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 421 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 422 | org.onosproject.tetopology.management.api.node.DefaultNetworkNode node; |
| 423 | List<NetworkNodeKey> spNodes = null; |
| 424 | TeNode teNode = null; |
| 425 | Map<KeyId, TerminationPoint> tps = null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 426 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 427 | if (yangNode.supportingNode() != null) { |
| 428 | spNodes = Lists.newArrayList(); |
| 429 | for (SupportingNode yangSpNode : yangNode.supportingNode()) { |
| 430 | NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()), |
| 431 | KeyId.keyId(yangSpNode.networkRef().uri().toString())); |
| 432 | spNodes.add(nodeKey); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (yangNode.yangAugmentedInfoMap() != null |
| 437 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 438 | |
| 439 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 440 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 441 | if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) { |
| 442 | tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment); |
| 443 | } |
| 444 | |
| 445 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode |
| 446 | .yangAugmentedInfo(AugmentedNwNode.class); |
| 447 | if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.te().teNodeId() != null) { |
| 448 | Te yangNodeAugTe = yangNodeAugment.te(); |
| 449 | teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, |
| 450 | yangNetwork, |
| 451 | yangNode, |
| 452 | tps); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | node = new org.onosproject.tetopology.management.api.node |
| 457 | .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps); |
| 458 | return node; |
| 459 | } |
| 460 | |
| 461 | // TODO: convert connectivity matrix from yang to te |
| 462 | private static Map<Long, ConnectivityMatrix> |
| 463 | yang2TeSubsystemNodeConnectivityMatrix(String networkId, |
| 464 | String nodeId, |
| 465 | List<org.onosproject.yang.gen.v1.urn.ietf |
| 466 | .params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 467 | .ietftetopology.tenodeconnectivitymatrix. |
| 468 | ConnectivityMatrix> yangMatrix) { |
| 469 | |
| 470 | Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap(); |
| 471 | |
| 472 | |
| 473 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te |
| 474 | .topology.rev20160708.ietftetopology.tenodeconnectivitymatrix. |
| 475 | ConnectivityMatrix cmYang : yangMatrix) { |
| 476 | |
| 477 | ElementType from = new TeLinkId((long) cmYang.from().tpRef()); // is this correct? |
| 478 | |
| 479 | UnderlayAbstractPath underlayPath = null; // ignore |
| 480 | |
| 481 | List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now |
| 482 | |
| 483 | List<ElementType> constrainingElements = Lists.newArrayList(); |
| 484 | ElementType to = new TeLinkId((long) cmYang.to().tpRef()); // is this correct? |
| 485 | constrainingElements.add(to); |
| 486 | |
| 487 | BitSet flags = new BitSet(); // what are the flags in cmYang? |
| 488 | |
| 489 | List<Long> srlgs = Lists.newArrayList(); |
| 490 | if (cmYang.teSrlgs() != null) { |
| 491 | for (Srlg srlg : cmYang.teSrlgs().value()) { |
| 492 | srlgs.add(srlg.uint32()); |
| 493 | } |
| 494 | } |
| 495 | TePathAttributes teAttributes = new |
| 496 | TePathAttributes(cmYang.teDefaultMetric(), |
| 497 | cmYang.performanceMetric().measurement().unidirectionalDelay(), |
| 498 | srlgs); |
| 499 | ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(), |
| 500 | from, |
| 501 | mergingList , |
| 502 | constrainingElements, |
| 503 | flags, |
| 504 | teAttributes , |
| 505 | underlayPath); |
| 506 | |
| 507 | teCmList.put(cmYang.id(), coreCm); |
| 508 | } |
| 509 | |
| 510 | return teCmList; |
| 511 | } |
| 512 | |
| 513 | private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut) { |
| 514 | TeTopologyKey tetopokey = new TeTopologyKey((Long) ut.providerIdRef(), |
| 515 | (Long) ut.clientIdRef(), |
| 516 | (Long) ut.teTopologyIdRef()); |
| 517 | return tetopokey; |
| 518 | } |
| 519 | |
| 520 | // TODO: retrieve the details of tunnel termiantion points from yang to te |
| 521 | private static Map<Long, org.onosproject.tetopology.management.api.node. |
| 522 | TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps) { |
| 523 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps |
| 524 | .newHashMap(); |
| 525 | for (TunnelTerminationPoint ttpYang : ttps) { |
| 526 | |
| 527 | SwitchingType switchingLayer = null; // how to find switching type? |
| 528 | EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding(); |
| 529 | BitSet flags = new BitSet(); // how to set flags? |
| 530 | List<Long> interLayerLockList = Lists.newArrayList(); |
| 531 | interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list |
| 532 | |
| 533 | List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList(); |
| 534 | // FIXME: once new yang model is used, we can make llc |
| 535 | // LocalLinkConnectivity llc = new LocalLinkConnectivity(constrainingElements, |
| 536 | // flags, |
| 537 | // teAttributes, |
| 538 | // underlayPath) |
| 539 | |
| 540 | float[] availAdaptBandwidth = null; // how to find availableBandwidth? |
| 541 | |
| 542 | org.onosproject.tetopology.management.api.node. |
| 543 | TunnelTerminationPoint ttpTe = new |
| 544 | org.onosproject.tetopology.management.api.node. |
| 545 | DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), |
| 546 | switchingLayer , |
| 547 | encodingLayer, |
| 548 | flags, |
| 549 | interLayerLockList, |
| 550 | localLinkConnectivityList, |
| 551 | availAdaptBandwidth); |
| 552 | |
| 553 | ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe); |
| 554 | } |
| 555 | |
| 556 | return ttpsMap; |
| 557 | } |
| 558 | |
| 559 | private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe, |
| 560 | Network yangNetwork, |
| 561 | Node yangNode, |
| 562 | Map<KeyId, TerminationPoint> yangTps) { |
| 563 | |
| 564 | |
| 565 | NodeId yangNodeId = yangNode.nodeId(); |
| 566 | List<SupportingNode> yangSupportNodes = yangNode.supportingNode(); |
| 567 | |
| 568 | NetworkId yangNetworkId = yangNetwork.networkId(); |
| 569 | |
| 570 | long teNodeId = Ip4Address.valueOf(yangNodeAugTe.teNodeId().dottedQuad().string()).toInt(); |
| 571 | |
| 572 | TeTopologyKey underlayTopologyIdId = null; |
| 573 | |
| 574 | // FIXME: yang has a list of supporting nodes, but TeNode only has one |
| 575 | // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId? |
| 576 | TeNodeKey supportTeNodeId = null; |
| 577 | // supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId) |
| 578 | // yangSupportNodes.get(0). |
| 579 | |
| 580 | TeNodeKey sourceTeNodeId = null; //ignore |
| 581 | CommonNodeData teData = null; |
| 582 | Map<Long, ConnectivityMatrix> connMatrices = null; |
| 583 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null; |
| 584 | List<Long> teLinkIds = Lists.newArrayList(); |
| 585 | List<Long> teTpIds = Lists.newArrayList(); |
| 586 | |
| 587 | // ********************************************** to find teLinkIds |
| 588 | if (yangNetwork.yangAugmentedInfo(AugmentedNdNetwork.class) != null) { |
| 589 | AugmentedNdNetwork augmentLink = |
| 590 | (AugmentedNdNetwork) yangNetwork.yangAugmentedInfo(AugmentedNdNetwork.class); |
| 591 | for (Link link : augmentLink.link()) { |
| 592 | if (link.source().sourceNode().equals(yangNodeAugTe.teNodeId())) { |
| 593 | teLinkIds.add(Long.valueOf(link.linkId().uri().string())); |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | // ********************************************** to find teTpIds |
| 598 | if (yangNode.yangAugmentedInfoMap() != null |
| 599 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 600 | |
| 601 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 602 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 603 | |
| 604 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 605 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 606 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 607 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 608 | teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string())); |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | // ********************************************** |
| 613 | |
| 614 | Config ynodeAugCfg = yangNodeAugTe.config(); |
| 615 | |
| 616 | if (ynodeAugCfg != null) { |
| 617 | TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes(); |
| 618 | if (teNodeAttr != null) { |
| 619 | |
| 620 | if (teNodeAttr.underlayTopology() != null) { |
| 621 | |
| 622 | underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr |
| 623 | .underlayTopology()); |
| 624 | } |
| 625 | BitSet flags = new BitSet(); |
| 626 | if (teNodeAttr.isAbstract()) { |
| 627 | flags.set(TeNode.BIT_ABSTRACT); |
| 628 | } |
| 629 | teData = new CommonNodeData( |
| 630 | teNodeAttr.name().string(), |
| 631 | EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()), |
| 632 | EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()), |
| 633 | flags); |
| 634 | |
| 635 | if (teNodeAttr.connectivityMatrix() != null) { |
| 636 | connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(), |
| 637 | yangNodeId.uri().toString(), |
| 638 | teNodeAttr.connectivityMatrix()); |
| 639 | } |
| 640 | |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | if (yangNodeAugTe.tunnelTerminationPoint() != null) { |
| 645 | ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint()); |
| 646 | } |
| 647 | |
| 648 | TeNode teNode = new DefaultTeNode(teNodeId, |
| 649 | underlayTopologyIdId, |
| 650 | supportTeNodeId, |
| 651 | sourceTeNodeId, |
| 652 | teData, |
| 653 | connMatrices, |
| 654 | teLinkIds, |
| 655 | ttps, |
| 656 | teTpIds); |
| 657 | return teNode; |
| 658 | } |
| 659 | |
| 660 | private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) { |
| 661 | Map<KeyId, TerminationPoint> tps; |
| 662 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 663 | tps = Maps.newHashMap(); |
| 664 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 665 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 666 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 667 | tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()), |
| 668 | TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode)); |
| 669 | } |
| 670 | return tps; |
| 671 | } |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 672 | return null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 673 | } |
| 674 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 675 | /** |
| 676 | * Converts a TE Topology node event from the data format used in |
| 677 | * the core to its corresponding YANG Object (YO) format. |
| 678 | * |
| 679 | * @param eventType Node event type |
| 680 | * @param nodeData TE Topology node event data |
| 681 | * @return YANG Object converted from nodeData |
| 682 | */ |
| 683 | public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType, |
| 684 | NetworkNode nodeData) { |
| 685 | TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 686 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 687 | TeTopologyEventType yangEventType = new TeTopologyEventType(eventType); |
| 688 | builder.eventType(yangEventType); |
| 689 | |
| 690 | NodeId nodeId = NodeId.fromString(nodeData.nodeId().toString()); |
| 691 | builder.nodeRef(nodeId); |
| 692 | |
| 693 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 694 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 695 | TeNodeAttributes teNodeAttributes = teNode2YangTeNodeAttributes(nodeData.teNode()); |
| 696 | builder.teNodeAttributes(teNodeAttributes); |
| 697 | |
| 698 | return builder.build(); |
| 699 | } |
| 700 | |
| 701 | private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
| 702 | ietf.te.topology.rev20160708.ietftetopology. |
| 703 | tenodeconfigattributesnotification. |
| 704 | TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) { |
| 705 | |
| 706 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 707 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 708 | TeNodeAttributes.TeNodeAttributesBuilder attrBuilder = |
| 709 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 710 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 711 | DefaultTeNodeAttributes.builder(); |
| 712 | |
| 713 | if (teNode.connectivityMatrices() != null) { |
| 714 | |
| 715 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 716 | .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix |
| 717 | .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf. |
| 718 | params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrixabs. |
| 719 | DefaultConnectivityMatrix.builder(); |
| 720 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
| 721 | teNode.connectivityMatrices().entrySet()) { |
| 722 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 723 | .id(teCmEntry.getKey()) |
| 724 | .isAllowed(!teCmEntry.getValue().flags() |
| 725 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
| 726 | .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 727 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom |
| 728 | .FromBuilder() // TODO: for now, assuming that there is |
| 729 | // only one 'from', and mergingList is empty |
| 730 | .tpRef(teCmEntry.getValue().from()) |
| 731 | .build()) |
| 732 | .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 733 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix |
| 734 | .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
| 735 | // one item in constrainingElements list |
| 736 | .tpRef(teCmEntry.getValue().constrainingElements().get(0)) |
| 737 | .build()); |
| 738 | attrBuilder = attrBuilder |
| 739 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
| 740 | .build()); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 745 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 746 | TeNodeAttributes teNodeAttributes = attrBuilder.build(); |
| 747 | |
| 748 | return teNodeAttributes; |
| 749 | } |
| 750 | |
| 751 | public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 752 | //TODO: implementation to be submitted as separate review |
| 753 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 754 | NetworkId networkRef = (NetworkId) (yangNodeEvent.networkRef()); |
| 755 | NodeId nodeRef = (NodeId) (yangNodeEvent.nodeRef()); |
| 756 | KeyId networkId = KeyId.keyId(networkRef.uri().toString()); |
| 757 | KeyId nodeId = KeyId.keyId(nodeRef.uri().toString()); |
| 758 | |
| 759 | NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId); |
| 760 | |
| 761 | return networkNodeKey; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 762 | } |
| 763 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 764 | public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent, |
| 765 | TeTopologyService teTopologyService) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 766 | //TODO: implementation to be submitted as separate review |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 767 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame^] | 768 | KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId(); |
| 769 | |
| 770 | org.onosproject.tetopology.management.api.Network network = teTopologyService.network |
| 771 | (yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId()); |
| 772 | if (network == null) { |
| 773 | return null; |
| 774 | } |
| 775 | |
| 776 | NetworkNode networkNode = network.node(networkNodeId); |
| 777 | if (networkNode == null) { |
| 778 | return null; |
| 779 | } |
| 780 | |
| 781 | List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds(); |
| 782 | Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints(); |
| 783 | |
| 784 | TeNode teNode = networkNode.teNode(); |
| 785 | if (teNode == null) { |
| 786 | return null; |
| 787 | } |
| 788 | |
| 789 | TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode); |
| 790 | |
| 791 | NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps); |
| 792 | |
| 793 | return updatedNetworkNode; |
| 794 | } |
| 795 | |
| 796 | private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) { |
| 797 | |
| 798 | long teNodeId = oldTeNode.teNodeId(); |
| 799 | TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId(); |
| 800 | TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId(); |
| 801 | TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId(); |
| 802 | Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices(); |
| 803 | List<Long> teLinkIds = oldTeNode.teLinkIds(); |
| 804 | Map<Long, org.onosproject.tetopology.management. |
| 805 | api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints(); |
| 806 | List<Long> teTpIds = oldTeNode.teLinkIds(); |
| 807 | String name = oldTeNode.name(); |
| 808 | TeStatus adminStatus = oldTeNode.adminStatus(); |
| 809 | TeStatus opStatus = oldTeNode.opStatus(); |
| 810 | BitSet flags = oldTeNode.flags(); |
| 811 | |
| 812 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 813 | .tenodeconfigattributesnotification |
| 814 | .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes(); |
| 815 | |
| 816 | if (yangTeNodeAttrs != null) { |
| 817 | TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus(); |
| 818 | if (yangAdminStatus != null) { |
| 819 | adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus); |
| 820 | } |
| 821 | |
| 822 | BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags(); |
| 823 | if (yangFlags != null) { |
| 824 | flags = yangFlags; |
| 825 | } |
| 826 | |
| 827 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
| 828 | ietf.te.topology.rev20160708.ietftetopology |
| 829 | .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs |
| 830 | .connectivityMatrix(); |
| 831 | if (yangConnMatrices != null) { |
| 832 | for (org.onosproject.yang.gen.v1. |
| 833 | urn.ietf.params.xml.ns.yang. |
| 834 | ietf.te.topology |
| 835 | .rev20160708.ietftetopology |
| 836 | .tenodeconnectivitymatrixabs |
| 837 | .ConnectivityMatrix yangConnMatrix : yangConnMatrices) { |
| 838 | Long cmId = new Long(yangConnMatrix.id()); |
| 839 | ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id())); |
| 840 | if (oldConnMatrix != null) { |
| 841 | ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix, |
| 842 | oldConnMatrix); |
| 843 | connMatrices.remove(cmId); |
| 844 | connMatrices.put(cmId, newConnMatrix); |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags); |
| 851 | TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData, |
| 852 | connMatrices, teLinkIds, ttps, teTpIds); |
| 853 | |
| 854 | return updatedTeNode; |
| 855 | } |
| 856 | |
| 857 | private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1. |
| 858 | urn.ietf.params.xml.ns.yang. |
| 859 | ietf.te.topology |
| 860 | .rev20160708.ietftetopology |
| 861 | .tenodeconnectivitymatrixabs |
| 862 | .ConnectivityMatrix yangConnMatrix, |
| 863 | ConnectivityMatrix oldTeConnMatrix) { |
| 864 | |
| 865 | long id = yangConnMatrix.id(); |
| 866 | ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef())); |
| 867 | UnderlayAbstractPath underlayPath = null; |
| 868 | List<ElementType> mergingList = Lists.newArrayList(); |
| 869 | |
| 870 | List<ElementType> constrainingElements = Lists.newArrayList(); |
| 871 | ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef())); |
| 872 | constrainingElements.add(to); |
| 873 | |
| 874 | BitSet flags = oldTeConnMatrix.flags(); |
| 875 | |
| 876 | TePathAttributes teAttributes = oldTeConnMatrix.teAttributes(); |
| 877 | |
| 878 | ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id, |
| 879 | from, |
| 880 | mergingList, |
| 881 | constrainingElements, |
| 882 | flags, |
| 883 | teAttributes, |
| 884 | underlayPath); |
| 885 | return updatedConnMatrix; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 886 | } |
| 887 | } |