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 |
| 411 | * @param yangNetwork Network node in YANG model |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 412 | * @return TE subsystem node |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 413 | */ |
| 414 | public static org.onosproject.tetopology.management.api.node.NetworkNode |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 415 | yang2TeSubsystemNode(Node yangNode, Network yangNetwork) { |
| 416 | checkNotNull(yangNode, E_NULL_YANG_NODE); |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 417 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 418 | org.onosproject.tetopology.management.api.node.DefaultNetworkNode node; |
| 419 | List<NetworkNodeKey> spNodes = null; |
| 420 | TeNode teNode = null; |
| 421 | Map<KeyId, TerminationPoint> tps = null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 422 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 423 | if (yangNode.supportingNode() != null) { |
| 424 | spNodes = Lists.newArrayList(); |
| 425 | for (SupportingNode yangSpNode : yangNode.supportingNode()) { |
| 426 | NetworkNodeKey nodeKey = new NetworkNodeKey(KeyId.keyId(yangSpNode.nodeRef().uri().toString()), |
| 427 | KeyId.keyId(yangSpNode.networkRef().uri().toString())); |
| 428 | spNodes.add(nodeKey); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | if (yangNode.yangAugmentedInfoMap() != null |
| 433 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 434 | |
| 435 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 436 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 437 | if (yang2TeSubsystemTpNodeAugment(yangTpNodeAugment) != null) { |
| 438 | tps = yang2TeSubsystemTpNodeAugment(yangTpNodeAugment); |
| 439 | } |
| 440 | |
| 441 | AugmentedNwNode yangNodeAugment = (AugmentedNwNode) yangNode |
| 442 | .yangAugmentedInfo(AugmentedNwNode.class); |
| 443 | if (yangNodeAugment != null && yangNodeAugment.te() != null && yangNodeAugment.te().teNodeId() != null) { |
| 444 | Te yangNodeAugTe = yangNodeAugment.te(); |
| 445 | teNode = yang2TeSubsystemNodeAugment(yangNodeAugTe, |
| 446 | yangNetwork, |
| 447 | yangNode, |
| 448 | tps); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | node = new org.onosproject.tetopology.management.api.node |
| 453 | .DefaultNetworkNode(KeyId.keyId(yangNode.nodeId().uri().string()), spNodes, teNode, tps); |
| 454 | return node; |
| 455 | } |
| 456 | |
| 457 | // TODO: convert connectivity matrix from yang to te |
| 458 | private static Map<Long, ConnectivityMatrix> |
| 459 | yang2TeSubsystemNodeConnectivityMatrix(String networkId, |
| 460 | String nodeId, |
| 461 | List<org.onosproject.yang.gen.v1.urn.ietf |
| 462 | .params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 463 | .ietftetopology.tenodeconnectivitymatrix. |
| 464 | ConnectivityMatrix> yangMatrix) { |
| 465 | |
| 466 | Map<Long, ConnectivityMatrix> teCmList = Maps.newHashMap(); |
| 467 | |
| 468 | |
| 469 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te |
| 470 | .topology.rev20160708.ietftetopology.tenodeconnectivitymatrix. |
| 471 | ConnectivityMatrix cmYang : yangMatrix) { |
| 472 | |
| 473 | ElementType from = new TeLinkId((long) cmYang.from().tpRef()); // is this correct? |
| 474 | |
| 475 | UnderlayAbstractPath underlayPath = null; // ignore |
| 476 | |
| 477 | List<ElementType> mergingList = Lists.newArrayList(); // empty merging list for now |
| 478 | |
| 479 | List<ElementType> constrainingElements = Lists.newArrayList(); |
| 480 | ElementType to = new TeLinkId((long) cmYang.to().tpRef()); // is this correct? |
| 481 | constrainingElements.add(to); |
| 482 | |
| 483 | BitSet flags = new BitSet(); // what are the flags in cmYang? |
| 484 | |
| 485 | List<Long> srlgs = Lists.newArrayList(); |
| 486 | if (cmYang.teSrlgs() != null) { |
| 487 | for (Srlg srlg : cmYang.teSrlgs().value()) { |
| 488 | srlgs.add(srlg.uint32()); |
| 489 | } |
| 490 | } |
| 491 | TePathAttributes teAttributes = new |
| 492 | TePathAttributes(cmYang.teDefaultMetric(), |
| 493 | cmYang.performanceMetric().measurement().unidirectionalDelay(), |
| 494 | srlgs); |
| 495 | ConnectivityMatrix coreCm = new ConnectivityMatrix(cmYang.id(), |
| 496 | from, |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 497 | mergingList, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 498 | constrainingElements, |
| 499 | flags, |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 500 | teAttributes, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 501 | underlayPath); |
| 502 | |
| 503 | teCmList.put(cmYang.id(), coreCm); |
| 504 | } |
| 505 | |
| 506 | return teCmList; |
| 507 | } |
| 508 | |
| 509 | private static TeTopologyKey yang2TeSubsystemNodeUnderlayTopology(UnderlayTopology ut) { |
| 510 | TeTopologyKey tetopokey = new TeTopologyKey((Long) ut.providerIdRef(), |
| 511 | (Long) ut.clientIdRef(), |
| 512 | (Long) ut.teTopologyIdRef()); |
| 513 | return tetopokey; |
| 514 | } |
| 515 | |
| 516 | // TODO: retrieve the details of tunnel termiantion points from yang to te |
| 517 | private static Map<Long, org.onosproject.tetopology.management.api.node. |
| 518 | TunnelTerminationPoint> yang2TeSubsystemTtp(List<TunnelTerminationPoint> ttps) { |
| 519 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttpsMap = Maps |
| 520 | .newHashMap(); |
| 521 | for (TunnelTerminationPoint ttpYang : ttps) { |
| 522 | |
| 523 | SwitchingType switchingLayer = null; // how to find switching type? |
| 524 | EncodingType encodingLayer = null; // TODO: find proper encoding type from ttpYang.config().encoding(); |
| 525 | BitSet flags = new BitSet(); // how to set flags? |
| 526 | List<Long> interLayerLockList = Lists.newArrayList(); |
| 527 | interLayerLockList.add(ttpYang.config().interLayerLockId()); // interLayerLock in yang is not a list |
| 528 | |
| 529 | List<LocalLinkConnectivity> localLinkConnectivityList = Lists.newArrayList(); |
| 530 | // FIXME: once new yang model is used, we can make llc |
| 531 | // LocalLinkConnectivity llc = new LocalLinkConnectivity(constrainingElements, |
| 532 | // flags, |
| 533 | // teAttributes, |
| 534 | // underlayPath) |
| 535 | |
| 536 | float[] availAdaptBandwidth = null; // how to find availableBandwidth? |
| 537 | |
| 538 | org.onosproject.tetopology.management.api.node. |
| 539 | TunnelTerminationPoint ttpTe = new |
| 540 | org.onosproject.tetopology.management.api.node. |
| 541 | DefaultTunnelTerminationPoint(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 542 | switchingLayer, |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 543 | encodingLayer, |
| 544 | flags, |
| 545 | interLayerLockList, |
| 546 | localLinkConnectivityList, |
| 547 | availAdaptBandwidth); |
| 548 | |
| 549 | ttpsMap.put(ByteUtils.bytesToLong(ttpYang.tunnelTpId()), ttpTe); |
| 550 | } |
| 551 | |
| 552 | return ttpsMap; |
| 553 | } |
| 554 | |
| 555 | private static TeNode yang2TeSubsystemNodeAugment(Te yangNodeAugTe, |
| 556 | Network yangNetwork, |
| 557 | Node yangNode, |
| 558 | Map<KeyId, TerminationPoint> yangTps) { |
| 559 | |
| 560 | |
| 561 | NodeId yangNodeId = yangNode.nodeId(); |
| 562 | List<SupportingNode> yangSupportNodes = yangNode.supportingNode(); |
| 563 | |
| 564 | NetworkId yangNetworkId = yangNetwork.networkId(); |
| 565 | |
| 566 | long teNodeId = Ip4Address.valueOf(yangNodeAugTe.teNodeId().dottedQuad().string()).toInt(); |
| 567 | |
| 568 | TeTopologyKey underlayTopologyIdId = null; |
| 569 | |
| 570 | // FIXME: yang has a list of supporting nodes, but TeNode only has one |
| 571 | // supportTeNodeId. How ro retrieve providerId, clientId, topologyId, teNodeId? |
| 572 | TeNodeKey supportTeNodeId = null; |
| 573 | // supportTeNodeId = new TeNodeKey(providerId, clientId, topologyId, teNodeId) |
| 574 | // yangSupportNodes.get(0). |
| 575 | |
| 576 | TeNodeKey sourceTeNodeId = null; //ignore |
| 577 | CommonNodeData teData = null; |
| 578 | Map<Long, ConnectivityMatrix> connMatrices = null; |
| 579 | Map<Long, org.onosproject.tetopology.management.api.node.TunnelTerminationPoint> ttps = null; |
| 580 | List<Long> teLinkIds = Lists.newArrayList(); |
| 581 | List<Long> teTpIds = Lists.newArrayList(); |
| 582 | |
| 583 | // ********************************************** to find teLinkIds |
| 584 | if (yangNetwork.yangAugmentedInfo(AugmentedNdNetwork.class) != null) { |
| 585 | AugmentedNdNetwork augmentLink = |
| 586 | (AugmentedNdNetwork) yangNetwork.yangAugmentedInfo(AugmentedNdNetwork.class); |
| 587 | for (Link link : augmentLink.link()) { |
| 588 | if (link.source().sourceNode().equals(yangNodeAugTe.teNodeId())) { |
| 589 | teLinkIds.add(Long.valueOf(link.linkId().uri().string())); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | // ********************************************** to find teTpIds |
| 594 | if (yangNode.yangAugmentedInfoMap() != null |
| 595 | && !yangNode.yangAugmentedInfoMap().isEmpty()) { |
| 596 | |
| 597 | AugmentedNdNode yangTpNodeAugment = (AugmentedNdNode) yangNode |
| 598 | .yangAugmentedInfo(AugmentedNdNode.class); |
| 599 | |
| 600 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 601 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 602 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 603 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 604 | teTpIds.add(Long.valueOf(yangTpnode.tpId().uri().string())); |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | // ********************************************** |
| 609 | |
| 610 | Config ynodeAugCfg = yangNodeAugTe.config(); |
| 611 | |
| 612 | if (ynodeAugCfg != null) { |
| 613 | TeNodeAttributes teNodeAttr = ynodeAugCfg.teNodeAttributes(); |
| 614 | if (teNodeAttr != null) { |
| 615 | |
| 616 | if (teNodeAttr.underlayTopology() != null) { |
| 617 | |
| 618 | underlayTopologyIdId = yang2TeSubsystemNodeUnderlayTopology(teNodeAttr |
| 619 | .underlayTopology()); |
| 620 | } |
| 621 | BitSet flags = new BitSet(); |
| 622 | if (teNodeAttr.isAbstract()) { |
| 623 | flags.set(TeNode.BIT_ABSTRACT); |
| 624 | } |
| 625 | teData = new CommonNodeData( |
| 626 | teNodeAttr.name().string(), |
| 627 | EnumConverter.yang2TeSubsystemAdminStatus(teNodeAttr.adminStatus()), |
| 628 | EnumConverter.yang2TeSubsystemOpStatus(yangNodeAugTe.state().operStatus()), |
| 629 | flags); |
| 630 | |
| 631 | if (teNodeAttr.connectivityMatrix() != null) { |
| 632 | connMatrices = yang2TeSubsystemNodeConnectivityMatrix(yangNetworkId.uri().toString(), |
| 633 | yangNodeId.uri().toString(), |
| 634 | teNodeAttr.connectivityMatrix()); |
| 635 | } |
| 636 | |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | if (yangNodeAugTe.tunnelTerminationPoint() != null) { |
| 641 | ttps = yang2TeSubsystemTtp(yangNodeAugTe.tunnelTerminationPoint()); |
| 642 | } |
| 643 | |
| 644 | TeNode teNode = new DefaultTeNode(teNodeId, |
| 645 | underlayTopologyIdId, |
| 646 | supportTeNodeId, |
| 647 | sourceTeNodeId, |
| 648 | teData, |
| 649 | connMatrices, |
| 650 | teLinkIds, |
| 651 | ttps, |
| 652 | teTpIds); |
| 653 | return teNode; |
| 654 | } |
| 655 | |
| 656 | private static Map<KeyId, TerminationPoint> yang2TeSubsystemTpNodeAugment(AugmentedNdNode yangTpNodeAugment) { |
| 657 | Map<KeyId, TerminationPoint> tps; |
| 658 | if (yangTpNodeAugment.terminationPoint() != null) { |
| 659 | tps = Maps.newHashMap(); |
| 660 | for (org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology |
| 661 | .rev20151208.ietfnetworktopology.networks.network.node.augmentedndnode.TerminationPoint |
| 662 | yangTpnode : yangTpNodeAugment.terminationPoint()) { |
| 663 | tps.put(KeyId.keyId(yangTpnode.tpId().uri().toString()), |
| 664 | TerminationPointConverter.yang2teSubsystemTerminationPoint(yangTpnode)); |
| 665 | } |
| 666 | return tps; |
| 667 | } |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 668 | return null; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 669 | } |
| 670 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 671 | /** |
| 672 | * Converts a TE Topology node event from the data format used in |
| 673 | * the core to its corresponding YANG Object (YO) format. |
| 674 | * |
| 675 | * @param eventType Node event type |
| 676 | * @param nodeData TE Topology node event data |
| 677 | * @return YANG Object converted from nodeData |
| 678 | */ |
| 679 | public static TeNodeEvent teNetworkNode2yangTeNodeEvent(TeTopologyEventTypeEnum eventType, |
| 680 | NetworkNode nodeData) { |
| 681 | TeNodeEvent.TeNodeEventBuilder builder = new DefaultTeNodeEvent.TeNodeEventBuilder(); |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 682 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 683 | TeTopologyEventType yangEventType = new TeTopologyEventType(eventType); |
| 684 | builder.eventType(yangEventType); |
| 685 | |
| 686 | NodeId nodeId = NodeId.fromString(nodeData.nodeId().toString()); |
| 687 | builder.nodeRef(nodeId); |
| 688 | |
| 689 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 690 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 691 | TeNodeAttributes teNodeAttributes = teNode2YangTeNodeAttributes(nodeData.teNode()); |
| 692 | builder.teNodeAttributes(teNodeAttributes); |
| 693 | |
| 694 | return builder.build(); |
| 695 | } |
| 696 | |
| 697 | private static org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
| 698 | ietf.te.topology.rev20160708.ietftetopology. |
| 699 | tenodeconfigattributesnotification. |
| 700 | TeNodeAttributes teNode2YangTeNodeAttributes(TeNode teNode) { |
| 701 | |
| 702 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 703 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 704 | TeNodeAttributes.TeNodeAttributesBuilder attrBuilder = |
| 705 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 706 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 707 | DefaultTeNodeAttributes.builder(); |
| 708 | |
| 709 | if (teNode.connectivityMatrices() != null) { |
| 710 | |
| 711 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 712 | .tenodeconnectivitymatrixabs.DefaultConnectivityMatrix |
| 713 | .ConnectivityMatrixBuilder connectivityMatrixConfigBuilder = org.onosproject.yang.gen.v1.urn.ietf. |
| 714 | params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology.tenodeconnectivitymatrixabs. |
| 715 | DefaultConnectivityMatrix.builder(); |
| 716 | for (Map.Entry<Long, ConnectivityMatrix> teCmEntry : |
| 717 | teNode.connectivityMatrices().entrySet()) { |
| 718 | connectivityMatrixConfigBuilder = connectivityMatrixConfigBuilder |
| 719 | .id(teCmEntry.getKey()) |
| 720 | .isAllowed(!teCmEntry.getValue().flags() |
| 721 | .get(ConnectivityMatrix.BIT_DISALLOWED)) |
| 722 | .from(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 723 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix.DefaultFrom |
| 724 | .FromBuilder() // TODO: for now, assuming that there is |
| 725 | // only one 'from', and mergingList is empty |
| 726 | .tpRef(teCmEntry.getValue().from()) |
| 727 | .build()) |
| 728 | .to(new org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708 |
| 729 | .ietftetopology.tenodeconnectivitymatrixabs.connectivitymatrix |
| 730 | .DefaultTo.ToBuilder() // TODO: for now, assuming that there is only |
| 731 | // one item in constrainingElements list |
| 732 | .tpRef(teCmEntry.getValue().constrainingElements().get(0)) |
| 733 | .build()); |
| 734 | attrBuilder = attrBuilder |
| 735 | .addToConnectivityMatrix(connectivityMatrixConfigBuilder |
| 736 | .build()); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology. |
| 741 | rev20160708.ietftetopology.tenodeconfigattributesnotification. |
| 742 | TeNodeAttributes teNodeAttributes = attrBuilder.build(); |
| 743 | |
| 744 | return teNodeAttributes; |
| 745 | } |
| 746 | |
| 747 | public static NetworkNodeKey yangNodeEvent2NetworkNodeKey(TeNodeEvent yangNodeEvent) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 748 | //TODO: implementation to be submitted as separate review |
| 749 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 750 | NetworkId networkRef = (NetworkId) (yangNodeEvent.networkRef()); |
| 751 | NodeId nodeRef = (NodeId) (yangNodeEvent.nodeRef()); |
| 752 | KeyId networkId = KeyId.keyId(networkRef.uri().toString()); |
| 753 | KeyId nodeId = KeyId.keyId(nodeRef.uri().toString()); |
| 754 | |
| 755 | NetworkNodeKey networkNodeKey = new NetworkNodeKey(networkId, nodeId); |
| 756 | |
| 757 | return networkNodeKey; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 758 | } |
| 759 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 760 | public static NetworkNode yangNodeEvent2NetworkNode(TeNodeEvent yangNodeEvent, |
| 761 | TeTopologyService teTopologyService) { |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 762 | //TODO: implementation to be submitted as separate review |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 763 | |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 764 | KeyId networkNodeId = yangNodeEvent2NetworkNodeKey(yangNodeEvent).nodeId(); |
| 765 | |
Ray Milkey | 8cd9a66 | 2016-11-30 16:55:40 -0800 | [diff] [blame] | 766 | org.onosproject.tetopology.management.api.Network network = teTopologyService.network( |
| 767 | yangNodeEvent2NetworkNodeKey(yangNodeEvent).networkId()); |
Hesam Rahimi | 39bdc00 | 2016-11-10 15:01:26 -0500 | [diff] [blame] | 768 | if (network == null) { |
| 769 | return null; |
| 770 | } |
| 771 | |
| 772 | NetworkNode networkNode = network.node(networkNodeId); |
| 773 | if (networkNode == null) { |
| 774 | return null; |
| 775 | } |
| 776 | |
| 777 | List<NetworkNodeKey> supportingNodeIds = networkNode.supportingNodeIds(); |
| 778 | Map<KeyId, TerminationPoint> tps = networkNode.terminationPoints(); |
| 779 | |
| 780 | TeNode teNode = networkNode.teNode(); |
| 781 | if (teNode == null) { |
| 782 | return null; |
| 783 | } |
| 784 | |
| 785 | TeNode updatedTeNode = yangNodeEvent2TeNode(yangNodeEvent, teNode); |
| 786 | |
| 787 | NetworkNode updatedNetworkNode = new DefaultNetworkNode(networkNodeId, supportingNodeIds, updatedTeNode, tps); |
| 788 | |
| 789 | return updatedNetworkNode; |
| 790 | } |
| 791 | |
| 792 | private static TeNode yangNodeEvent2TeNode(TeNodeEvent yangNodeEvent, TeNode oldTeNode) { |
| 793 | |
| 794 | long teNodeId = oldTeNode.teNodeId(); |
| 795 | TeTopologyKey underlayTopoId = oldTeNode.underlayTeTopologyId(); |
| 796 | TeNodeKey supportTeNodeId = oldTeNode.sourceTeNodeId(); |
| 797 | TeNodeKey sourceTeNodeId = oldTeNode.sourceTeNodeId(); |
| 798 | Map<Long, ConnectivityMatrix> connMatrices = oldTeNode.connectivityMatrices(); |
| 799 | List<Long> teLinkIds = oldTeNode.teLinkIds(); |
| 800 | Map<Long, org.onosproject.tetopology.management. |
| 801 | api.node.TunnelTerminationPoint> ttps = oldTeNode.tunnelTerminationPoints(); |
| 802 | List<Long> teTpIds = oldTeNode.teLinkIds(); |
| 803 | String name = oldTeNode.name(); |
| 804 | TeStatus adminStatus = oldTeNode.adminStatus(); |
| 805 | TeStatus opStatus = oldTeNode.opStatus(); |
| 806 | BitSet flags = oldTeNode.flags(); |
| 807 | |
| 808 | org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160708.ietftetopology |
| 809 | .tenodeconfigattributesnotification |
| 810 | .TeNodeAttributes yangTeNodeAttrs = yangNodeEvent.teNodeAttributes(); |
| 811 | |
| 812 | if (yangTeNodeAttrs != null) { |
| 813 | TeAdminStatus yangAdminStatus = yangTeNodeAttrs.adminStatus(); |
| 814 | if (yangAdminStatus != null) { |
| 815 | adminStatus = EnumConverter.yang2TeSubsystemAdminStatus(yangAdminStatus); |
| 816 | } |
| 817 | |
| 818 | BitSet yangFlags = yangTeNodeAttrs.selectLeafFlags(); |
| 819 | if (yangFlags != null) { |
| 820 | flags = yangFlags; |
| 821 | } |
| 822 | |
| 823 | List<org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang. |
| 824 | ietf.te.topology.rev20160708.ietftetopology |
| 825 | .tenodeconnectivitymatrixabs.ConnectivityMatrix> yangConnMatrices = yangTeNodeAttrs |
| 826 | .connectivityMatrix(); |
| 827 | if (yangConnMatrices != null) { |
| 828 | for (org.onosproject.yang.gen.v1. |
| 829 | urn.ietf.params.xml.ns.yang. |
| 830 | ietf.te.topology |
| 831 | .rev20160708.ietftetopology |
| 832 | .tenodeconnectivitymatrixabs |
| 833 | .ConnectivityMatrix yangConnMatrix : yangConnMatrices) { |
| 834 | Long cmId = new Long(yangConnMatrix.id()); |
| 835 | ConnectivityMatrix oldConnMatrix = connMatrices.get(new Long(yangConnMatrix.id())); |
| 836 | if (oldConnMatrix != null) { |
| 837 | ConnectivityMatrix newConnMatrix = yangNodeEvent2TeConnectivityMatrix(yangConnMatrix, |
| 838 | oldConnMatrix); |
| 839 | connMatrices.remove(cmId); |
| 840 | connMatrices.put(cmId, newConnMatrix); |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | CommonNodeData teData = new CommonNodeData(name, adminStatus, opStatus, flags); |
| 847 | TeNode updatedTeNode = new DefaultTeNode(teNodeId, underlayTopoId, supportTeNodeId, sourceTeNodeId, teData, |
| 848 | connMatrices, teLinkIds, ttps, teTpIds); |
| 849 | |
| 850 | return updatedTeNode; |
| 851 | } |
| 852 | |
| 853 | private static ConnectivityMatrix yangNodeEvent2TeConnectivityMatrix(org.onosproject.yang.gen.v1. |
| 854 | urn.ietf.params.xml.ns.yang. |
| 855 | ietf.te.topology |
| 856 | .rev20160708.ietftetopology |
| 857 | .tenodeconnectivitymatrixabs |
| 858 | .ConnectivityMatrix yangConnMatrix, |
| 859 | ConnectivityMatrix oldTeConnMatrix) { |
| 860 | |
| 861 | long id = yangConnMatrix.id(); |
| 862 | ElementType from = new TeLinkId((long) (yangConnMatrix.from().tpRef())); |
| 863 | UnderlayAbstractPath underlayPath = null; |
| 864 | List<ElementType> mergingList = Lists.newArrayList(); |
| 865 | |
| 866 | List<ElementType> constrainingElements = Lists.newArrayList(); |
| 867 | ElementType to = new TeLinkId((long) (yangConnMatrix.to().tpRef())); |
| 868 | constrainingElements.add(to); |
| 869 | |
| 870 | BitSet flags = oldTeConnMatrix.flags(); |
| 871 | |
| 872 | TePathAttributes teAttributes = oldTeConnMatrix.teAttributes(); |
| 873 | |
| 874 | ConnectivityMatrix updatedConnMatrix = new ConnectivityMatrix(id, |
| 875 | from, |
| 876 | mergingList, |
| 877 | constrainingElements, |
| 878 | flags, |
| 879 | teAttributes, |
| 880 | underlayPath); |
| 881 | return updatedConnMatrix; |
Yixiao Chen | 39828a6 | 2016-09-14 14:37:06 -0400 | [diff] [blame] | 882 | } |
| 883 | } |