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