2 * Copyright © 2017 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.common.mapping;
11 import com.google.common.util.concurrent.FluentFuture;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.math.BigInteger;
14 import java.nio.charset.StandardCharsets;
15 import java.util.ArrayList;
16 import java.util.Base64;
17 import java.util.Collection;
18 import java.util.Collections;
19 import java.util.Comparator;
20 import java.util.HashMap;
21 import java.util.List;
23 import java.util.Map.Entry;
24 import java.util.Optional;
25 import java.util.concurrent.ExecutionException;
26 import java.util.stream.Collectors;
27 import org.eclipse.jdt.annotation.NonNull;
28 import org.eclipse.jdt.annotation.Nullable;
29 import org.opendaylight.mdsal.binding.api.DataBroker;
30 import org.opendaylight.mdsal.binding.api.WriteTransaction;
31 import org.opendaylight.mdsal.common.api.CommitInfo;
32 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
33 import org.opendaylight.transportpce.common.StringConstants;
34 import org.opendaylight.transportpce.common.Timeouts;
35 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.Network;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.NetworkBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.Nodes;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.NodesBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.NodesKey;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.CpToDegree;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.CpToDegreeBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.CpToDegreeKey;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.Mapping;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.MappingBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.MappingKey;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.NodeInfo;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.NodeInfo.OpenroadmVersion;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev201012.network.nodes.NodeInfoBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.Direction;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.CircuitPack;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.connection.map.Destination;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.port.Interfaces;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpenROADMOpticalMultiplex;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpticalTransport;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.Lldp;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
79 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
80 import org.opendaylight.yangtools.yang.common.Uint16;
81 import org.opendaylight.yangtools.yang.common.Uint32;
82 import org.slf4j.Logger;
83 import org.slf4j.LoggerFactory;
85 public class PortMappingVersion121 {
87 private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion121.class);
89 private final DataBroker dataBroker;
90 private final DeviceTransactionManager deviceTransactionManager;
91 private final OpenRoadmInterfaces openRoadmInterfaces;
93 //FNV1 64 bit hash constants
94 private static final BigInteger FNV_PRIME = new BigInteger("100000001b3", 16);
95 private static final BigInteger FNV_INIT = new BigInteger("cbf29ce484222325", 16);
96 private static final BigInteger FNV_MOD = new BigInteger("2").pow(64);
98 public PortMappingVersion121(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
99 OpenRoadmInterfaces openRoadmInterfaces) {
100 this.dataBroker = dataBroker;
101 this.deviceTransactionManager = deviceTransactionManager;
102 this.openRoadmInterfaces = openRoadmInterfaces;
105 public boolean createMappingData(String nodeId) {
106 LOG.info("Create Mapping Data for node 1.2.1 {}", nodeId);
107 List<Mapping> portMapList = new ArrayList<>();
108 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
109 Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType
110 .OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
113 if (deviceInfoOptional.isPresent()) {
114 deviceInfo = deviceInfoOptional.get();
115 nodeInfo = createNodeInfo(deviceInfo);
116 if (nodeInfo == null) {
119 postPortMapping(nodeId, nodeInfo, null, null);
122 LOG.warn("Device info subtree is absent for {}", nodeId);
126 switch (deviceInfo.getNodeType()) {
129 // Get TTP port mapping
130 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
131 // return false if mapping creation for TTP's failed
132 LOG.warn("Unable to create mapping for TTP's on node {}", nodeId);
136 // Get PP port mapping
137 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
138 // return false if mapping creation for PP's failed
139 LOG.warn("Unable to create mapping for PP's on node {}", nodeId);
144 if (!createXpdrPortMapping(nodeId, portMapList)) {
145 LOG.warn("Unable to create mapping for Xponder on node {}", nodeId);
150 LOG.error("Unable to create mapping for node {} : unknown nodetype ", nodeId);
154 return postPortMapping(nodeId, nodeInfo, portMapList, null);
157 public boolean updateMapping(String nodeId, Mapping oldMapping) {
158 InstanceIdentifier<Ports> portIId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
159 .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
160 .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
161 if ((oldMapping != null) && (nodeId != null)) {
163 Optional<Ports> portObject = deviceTransactionManager.getDataFromDevice(nodeId,
164 LogicalDatastoreType.OPERATIONAL, portIId, Timeouts.DEVICE_READ_TIMEOUT,
165 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
166 if (portObject.isPresent()) {
167 Ports port = portObject.get();
168 Mapping newMapping = createMappingObject(nodeId, port, oldMapping.getSupportingCircuitPackName(),
169 oldMapping.getLogicalConnectionPoint());
170 LOG.info("Updating old mapping Data {} for {} of {} by new mapping data {}", oldMapping,
171 oldMapping.getLogicalConnectionPoint(), nodeId, newMapping);
172 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
173 InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
174 .child(Nodes.class, new NodesKey(nodeId))
175 .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
176 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
177 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
182 } catch (InterruptedException | ExecutionException e) {
183 LOG.error("Error updating Mapping {} for node {}", oldMapping.getLogicalConnectionPoint(), nodeId, e);
187 LOG.error("Impossible to update mapping");
192 private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
193 // Creating for Xponder Line and Client Ports
194 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
195 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
196 LogicalDatastoreType.OPERATIONAL, deviceIID,
197 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
199 // Variable to keep track of number of line ports
201 // Variable to keep track of number of client ports
203 if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) {
204 LOG.warn("Circuit Packs are not present for {}", nodeId);
206 // TODO return false or continue?
208 Map<String, String> lcpMap = new HashMap<>();
209 Map<String, Mapping> mappingMap = new HashMap<>();
211 // com.google.common.collect.ImmutableList implementation of List
212 List<CircuitPacks> circuitPackList = new ArrayList<>(deviceObject.get()
213 .nonnullCircuitPacks().values());
214 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
216 for (CircuitPacks cp : circuitPackList) {
217 String circuitPackName = cp.getCircuitPackName();
218 if (cp.getPorts() == null) {
219 LOG.warn("Ports were not found for circuit pack: {}", circuitPackName);
223 // com.google.common.collect.ImmutableList implementation of List
224 List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
225 portList.sort(Comparator.comparing(Ports::getPortName));
226 for (Ports port : portList) {
227 if (port.getPortQual() == null) {
228 LOG.warn("PortQual was not found for port {} on circuit pack: {}", port.getPortName(),
232 if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
233 && port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) {
234 String lcp = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
235 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
236 mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
238 } else if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
239 && port.getPortDirection().getIntValue() != Direction.Bidirectional.getIntValue()
240 && port.getPartnerPort() != null
241 && port.getPartnerPort().getCircuitPackName() != null
242 && port.getPartnerPort().getPortName() != null) {
243 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
246 String lcp1 = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
247 Optional<CircuitPacks> cpOpt = circuitPackList.stream().filter(cP -> cP.getCircuitPackName()
248 .equals(port.getPartnerPort().getCircuitPackName())).findFirst();
249 if (cpOpt.isPresent()) {
250 Optional<Ports> poOpt = cpOpt.get().nonnullPorts()
251 .values().stream().filter(p -> p.getPortName().equals(port
252 .getPartnerPort().getPortName().toString())).findFirst();
253 if (poOpt.isPresent()) {
254 Ports port2 = poOpt.get();
255 if ((Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
256 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
257 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
258 && port2.getPartnerPort().getPortName() != null
259 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
260 && port2.getPartnerPort().getPortName().equals(port.getPortName()))
262 (Direction.Tx.getIntValue() == port.getPortDirection().getIntValue()
263 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
264 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
265 && port2.getPartnerPort().getPortName() != null
266 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
267 && port2.getPartnerPort().getPortName().equals(port.getPortName()))) {
268 String lcp2 = new StringBuilder("XPDR1-").append(StringConstants.NETWORK_TOKEN)
269 .append(line + 1).toString();
270 if (!lcpMap.containsKey(lcp1) && !lcpMap.containsKey(lcp2)) {
271 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
272 lcpMap.put(cpOpt.get().getCircuitPackName() + '+' + port2.getPortName(), lcp2);
273 mappingMap.put(lcp1, createXpdrMappingObject(nodeId, port, circuitPackName, lcp1,
275 mappingMap.put(lcp2, createXpdrMappingObject(nodeId, port2,
276 cpOpt.get().getCircuitPackName(), lcp2, lcp1, null, null));
278 LOG.warn("mapping already exists for {} or {}", lcp1, lcp2);
282 LOG.error("port {} on {} is not a correct partner port of {} on {}",
283 port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(),
287 LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(),
288 port.getPartnerPort().getCircuitPackName(), nodeId);
291 LOG.error("Error fetching circuit-pack {} for {}", port.getPartnerPort().getCircuitPackName(),
294 } else if (Port.PortQual.XpdrClient.getIntValue() == port.getPortQual().getIntValue()) {
295 String lcp = "XPDR1-" + StringConstants.CLIENT_TOKEN + client;
296 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
297 mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
300 LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(), circuitPackName,
305 Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
308 for (ConnectionMap cm : connectionMap) {
309 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
310 if (lcpMap.containsKey(skey)) {
311 slcp = lcpMap.get(skey);
313 Destination destination0 = cm.nonnullDestination().values().iterator().next();
314 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
315 if (lcpMap.containsKey(dkey)) {
316 dlcp = lcpMap.get(dkey);
319 Mapping mapping = mappingMap.get(slcp);
320 mappingMap.remove(slcp);
321 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp));
323 LOG.error("Error in connection-map analysis");
326 if (!mappingMap.isEmpty()) {
327 for (Mapping m : mappingMap.values()) {
334 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
335 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
336 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
337 .CircuitPacks>> cpPerSrg = new HashMap<>();
339 // Get value for max Srg from info subtree, required for iteration
340 // if not present assume to be 20 (temporary)
341 if (ordmInfo.getMaxSrgs() != null) {
342 maxSrg = ordmInfo.getMaxSrgs().toJava();
346 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
347 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps
349 LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter);
350 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
351 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
352 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
353 LogicalDatastoreType.OPERATIONAL, srgIID,
354 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
355 if (ordmSrgObject.isPresent()) {
356 srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
357 cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
360 LOG.info("Device {} has {} Srg", deviceId, cpPerSrg.size());
364 //last LOG info message in this method is too long
365 @SuppressWarnings("checkstyle:linelength")
366 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
367 // Creating mapping data for SRG's PP
368 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>> srgCps
369 = getSrgCps(nodeId, deviceInfo);
371 for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>> srgCpEntry : srgCps.entrySet()) {
372 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> cpList =
373 srgCps.get(srgCpEntry.getKey());
374 List<String> keys = new ArrayList<>();
375 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cp : cpList) {
376 String circuitPackName = cp.getCircuitPackName();
377 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
378 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
379 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
380 LogicalDatastoreType.OPERATIONAL, cpIID,
381 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
383 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
384 LOG.warn("{} : Circuit pack {} not found or without ports.", nodeId, circuitPackName);
387 // com.google.common.collect.ImmutableList implementation of List
389 List<Ports> portList = new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
390 Collections.sort(portList, new SortPort121ByName());
392 for (Ports port : portList) {
393 String currentKey = circuitPackName + "-" + port.getPortName();
394 if (port.getPortQual() == null) {
396 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
397 && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()
398 && !keys.contains(currentKey)) {
399 String logicalConnectionPoint = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
400 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
401 port.getPortName(), logicalConnectionPoint);
402 portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
404 keys.add(currentKey);
405 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
406 && (Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
407 || Direction.Tx.getIntValue() == port.getPortDirection().getIntValue())
408 && !keys.contains(currentKey)
409 && port.getPartnerPort() != null) {
410 String logicalConnectionPoint1 = createLogicalConnectionPort(port, srgCpEntry.getKey(),
412 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
413 port.getPortName(), logicalConnectionPoint1);
414 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
415 .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
416 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName().toString()));
417 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
418 LogicalDatastoreType.OPERATIONAL, port2ID,
419 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
420 if (port2Object.isPresent()
421 && port2Object.get().getPortQual().getIntValue()
422 == Port.PortQual.RoadmExternal.getIntValue()) {
423 Ports port2 = port2Object.get();
424 if ((port.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
425 && port2.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
426 && port2.getPartnerPort() != null
427 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
428 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))
430 (port.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
431 && port2.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
432 && port2.getPartnerPort() != null
433 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
434 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))) {
435 String logicalConnectionPoint2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),
437 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
438 port2.getPortName(), logicalConnectionPoint2);
439 portMapList.add(createMappingObject(nodeId, port, circuitPackName,
440 logicalConnectionPoint1));
441 portMapList.add(createMappingObject(nodeId, port2, port.getPartnerPort()
442 .getCircuitPackName(), logicalConnectionPoint2));
444 keys.add(currentKey);
445 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
447 LOG.error("Error with partner port configuration for port {} of {} - {}",
448 port.getPortName(), circuitPackName, nodeId);
452 LOG.error("error getting partner port {} of {} - {}",
453 port.getPartnerPort().getPortName().toString(),
454 port.getPartnerPort().getCircuitPackName(), nodeId);
458 LOG.info("{} : port {} on {} is not roadm-external or has already been handled. No logicalConnectionPoint assignment for this port.",
459 nodeId, port.getPortName(), circuitPackName);
467 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
469 switch (port.getPortDirection()) {
471 lcp = "SRG" + index + "-PP" + portIndex + "-TX";
474 lcp = "SRG" + index + "-PP" + portIndex + "-RX";
477 lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
480 LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
485 private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
486 List<Degree> degrees = new ArrayList<>();
489 // Get value for max degree from info subtree, required for iteration
490 // if not present assume to be 20 (temporary)
491 if (ordmInfo.getMaxDegrees() != null) {
492 maxDegree = ordmInfo.getMaxDegrees().toJava();
497 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
498 LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
499 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
500 .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
501 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
502 LogicalDatastoreType.OPERATIONAL, deviceIID,
503 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
504 if (ordmDegreeObject.isPresent()) {
505 degrees.add(ordmDegreeObject.get());
508 LOG.info("Device {} has {} degree", deviceId, degrees.size());
512 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
513 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
516 if (ordmInfo.getMaxDegrees() != null) {
517 maxDegree = ordmInfo.getMaxDegrees().toJava();
521 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
522 LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
523 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
524 .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
525 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
526 LogicalDatastoreType.OPERATIONAL, deviceIID,
527 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
528 if (ordmDegreeObject.isPresent()) {
529 conPortMap.put(degreeCounter, new ArrayList<>(ordmDegreeObject.get()
530 .nonnullConnectionPorts().values()));
533 LOG.info("Device {} has {} degree", deviceId, conPortMap.size());
537 private Map<String, String> getEthInterfaceList(String nodeId) {
538 LOG.info("It is calling get ethernet interface");
539 Map<String, String> cpToInterfaceMap = new HashMap<>();
540 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
541 .child(Protocols.class);
542 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
543 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
544 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
545 if (protocolObject.isPresent() && protocolObject.get().augmentation(Protocols1.class).getLldp() != null) {
546 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
547 for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
548 if (portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
549 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
550 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
551 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
552 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
553 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
554 if (interfaceObject.isPresent() && (interfaceObject.get().getSupportingCircuitPackName() != null)) {
555 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
556 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
557 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
558 .create(OrgOpenroadmDevice.class)
559 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
560 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
561 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
562 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
563 if (circuitPackObject.isPresent() && (circuitPackObject.get().getParentCircuitPack() != null)) {
564 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
565 portConfig.getIfName());
571 LOG.warn("Couldnt find port config under LLDP for Node : {}", nodeId);
573 LOG.info("Processiong is done.. now returning..");
574 return cpToInterfaceMap;
577 private List<CpToDegree> getCpToDegreeList(List<Degree> degrees, String nodeId,
578 Map<String, String> interfaceList) {
579 List<CpToDegree> cpToDegreeList = new ArrayList<>();
580 for (Degree degree : degrees) {
581 if (degree.getCircuitPacks() != null) {
582 LOG.info("Inside CP to degree list");
583 cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream()
584 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
585 degree.getDegreeNumber().toString(), nodeId, interfaceList))
586 .collect(Collectors.toList()));
589 return cpToDegreeList;
592 private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
593 List<CpToDegree> cp2DegreeList) {
594 NodesBuilder nodesBldr = new NodesBuilder();
595 nodesBldr.withKey(new NodesKey(nodeId)).setNodeId(nodeId);
596 if (nodeInfo != null) {
597 nodesBldr.setNodeInfo(nodeInfo);
599 if (portMapList != null) {
600 Map<MappingKey, Mapping> mappingMap = new HashMap<>();
601 for (Mapping mapping: portMapList) {
602 if (mapping != null) {
603 mappingMap.put(mapping.key(), mapping);
606 nodesBldr.setMapping(mappingMap);
608 if (cp2DegreeList != null) {
609 Map<CpToDegreeKey, CpToDegree> cpToDegreeMap = new HashMap<>();
610 for (CpToDegree cp2Degree: cp2DegreeList) {
611 if (cp2Degree != null) {
612 cpToDegreeMap.put(cp2Degree.key(), cp2Degree);
615 nodesBldr.setCpToDegree(cpToDegreeMap);
618 Map<NodesKey,Nodes> nodesList = new HashMap<>();
619 Nodes nodes = nodesBldr.build();
620 nodesList.put(nodes.key(),nodes);
622 NetworkBuilder nwBldr = new NetworkBuilder();
623 nwBldr.setNodes(nodesList);
625 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
626 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
627 Network network = nwBldr.build();
628 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
629 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
634 } catch (InterruptedException | ExecutionException e) {
635 LOG.warn("Failed to post {}", network, e);
640 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, String nodeId,
641 Map<String, String> interfaceList) {
642 String interfaceName = null;
643 if (interfaceList.get(circuitPackName) != null) {
644 interfaceName = interfaceList.get(circuitPackName);
646 return new CpToDegreeBuilder().withKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
647 .setDegreeNumber(Uint32.valueOf(degreeNumber)).setInterfaceName(interfaceName).build();
650 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
651 String logicalConnectionPoint) {
652 MappingBuilder mpBldr = new MappingBuilder();
653 mpBldr.withKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
654 .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName())
655 .setPortDirection(port.getPortDirection().getName());
657 // Get OMS and OTS interface provisioned on the TTP's
658 if (logicalConnectionPoint.contains(StringConstants.TTP_TOKEN) && (port.getInterfaces() != null)) {
659 for (Interfaces interfaces : port.getInterfaces()) {
661 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
662 interfaces.getInterfaceName());
663 if (openRoadmInterface.isPresent()) {
664 Class<? extends InterfaceType> interfaceType
665 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
666 // Check if interface type is OMS or OTS
667 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
668 mpBldr.setSupportingOms(interfaces.getInterfaceName());
670 if (interfaceType.equals(OpticalTransport.class)) {
671 mpBldr.setSupportingOts(interfaces.getInterfaceName());
674 LOG.warn("Interface {} from node {} was null!", interfaces.getInterfaceName(), nodeId);
676 } catch (OpenRoadmInterfaceException ex) {
677 LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
682 return mpBldr.build();
685 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
686 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String assoLcp) {
687 MappingBuilder mpBldr;
689 if (mapping != null && assoLcp != null) {
690 // update existing mapping
691 mpBldr = new MappingBuilder(mapping);
692 mpBldr.setConnectionMapLcp(assoLcp);
694 // create a new mapping
695 mpBldr = new MappingBuilder();
696 String nodeIdLcp = nodeId + "-" + logicalConnectionPoint;
697 mpBldr.withKey(new MappingKey(logicalConnectionPoint))
698 .setLogicalConnectionPoint(logicalConnectionPoint)
699 .setSupportingCircuitPackName(circuitPackName)
700 .setSupportingPort(port.getPortName())
701 .setPortDirection(port.getPortDirection().getName())
702 .setLcpHashVal(fnv(nodeIdLcp));
703 if (port.getPortQual() != null) {
704 mpBldr.setPortQual(port.getPortQual().getName());
706 if (partnerLcp != null) {
707 mpBldr.setPartnerLcp(partnerLcp);
710 return mpBldr.build();
713 // some LOG messages are too long
714 @SuppressWarnings("checkstyle:linelength")
715 @SuppressFBWarnings("DM_CONVERT_CASE")
716 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
717 // Creating mapping data for degree TTP's
718 List<Degree> degrees = getDegrees(nodeId, deviceInfo);
719 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
720 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList);
721 LOG.info("Map looks like this {}", interfaceList);
722 postPortMapping(nodeId, null, null, cpToDegreeList);
724 Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
725 for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
726 switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
728 // port is bidirectional
729 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
730 .child(CircuitPacks.class, new CircuitPacksKey(connectionPortMap.get(cpMapEntry.getKey()).get(0)
731 .getCircuitPackName()))
732 .child(Ports.class, new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0)
733 .getPortName().toString()));
734 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap
735 .get(cpMapEntry.getKey()).get(0).getPortName().toString(), connectionPortMap
736 .get(cpMapEntry.getKey()).get(0).getCircuitPackName());
737 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
738 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
739 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
740 if (portObject.isPresent()) {
741 Ports port = portObject.get();
742 if (port.getPortQual() == null) {
744 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
745 && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()) {
746 String logicalConnectionPoint = new StringBuilder("DEG").append(cpMapEntry.getKey())
747 .append("-TTP-TXRX").toString();
748 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
749 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(),
750 port.getPortName(), logicalConnectionPoint);
751 portMapList.add(createMappingObject(nodeId, port,
752 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(),
753 logicalConnectionPoint));
756 "Impossible to create logical connection point for port {} of {} on node {} - Error in configuration with port-qual or port-direction",
757 port.getPortName(), connectionPortMap
758 .get(cpMapEntry.getKey()).get(0).getCircuitPackName(), nodeId);
761 LOG.error("No port {} on circuit pack {} for node {}",
762 connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName().toString(),
763 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(), nodeId);
768 // ports are unidirectionals
769 String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
770 String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
771 InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
772 .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
773 .child(Ports.class, new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()
775 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap
776 .get(cpMapEntry.getKey()).get(0).getPortName().toString(), cp1Name);
777 Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
778 LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
779 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
780 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
781 .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
782 .child(Ports.class, new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()
784 LOG.info("Fetching connection-port {} at circuit pack {}",
785 connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName().toString(), cp2Name);
786 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
787 LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
788 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
789 if (port1Object.isPresent() && port2Object.isPresent()) {
790 Ports port1 = port1Object.get();
791 Ports port2 = port2Object.get();
792 if (port1.getPortQual() == null || port2.getPortQual() == null) {
794 } else if ((Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
795 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
796 && Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
797 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
798 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
799 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
800 && port1.getPartnerPort().getPortName().equals(port2.getPortName())
801 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
802 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))
804 (Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
805 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
806 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
807 && Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
808 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
809 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
810 && port1.getPartnerPort().getPortName().equals(port2.getPortName())
811 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
812 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))) {
813 String logicalConnectionPoint1 = new StringBuilder("DEG").append(cpMapEntry.getKey())
814 .append("-TTP-").append(port1.getPortDirection().getName().toUpperCase()).toString();
815 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
816 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(),
817 port1.getPortName(), logicalConnectionPoint1);
818 portMapList.add(createMappingObject(nodeId, port1, connectionPortMap
819 .get(cpMapEntry.getKey()).get(0).getCircuitPackName(), logicalConnectionPoint1));
820 String logicalConnectionPoint2 = new StringBuilder("DEG").append(cpMapEntry.getKey())
821 .append("-TTP-").append(port2.getPortDirection().getName().toUpperCase()).toString();
822 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
823 connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName(),
824 port2.getPortName(), logicalConnectionPoint2);
825 portMapList.add(createMappingObject(nodeId, port2, connectionPortMap
826 .get(cpMapEntry.getKey()).get(1).getCircuitPackName(), logicalConnectionPoint2));
829 "Impossible to create logical connection point for port {} or port {} on node {} - Error in configuration with port-qual, port-direction or partner-port configuration",
830 port1.getPortName(), port2.getPortName(), nodeId);
833 LOG.error("No port {} on circuit pack {} for node {}",
834 connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName().toString(),
835 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(), nodeId);
841 LOG.error("Number of connection port for DEG{} on {} is incorrect", cpMapEntry.getKey(), nodeId);
848 private NodeInfo createNodeInfo(Info deviceInfo) {
849 NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder();
850 if (deviceInfo.getNodeType() != null) {
851 nodeInfoBldr.setOpenroadmVersion(OpenroadmVersion._121);
852 if (deviceInfo.getNodeType().getIntValue() == 1) {
853 nodeInfoBldr.setNodeType(NodeTypes.Rdm);
854 } else if (deviceInfo.getNodeType().getIntValue() == 2) {
855 nodeInfoBldr.setNodeType(NodeTypes.Xpdr);
857 LOG.error("Error with node-type of {}", deviceInfo.getNodeId());
859 if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
860 nodeInfoBldr.setNodeClli(deviceInfo.getClli());
862 nodeInfoBldr.setNodeClli("defaultCLLI");
864 if (deviceInfo.getModel() != null) {
865 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
867 if (deviceInfo.getVendor() != null) {
868 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
870 if (deviceInfo.getIpAddress() != null) {
871 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
874 // TODO make mandatory in yang
875 LOG.error("Node type field is missing");
878 return nodeInfoBldr.build();
882 * Implements the FNV-1 64bit algorithm.
883 * FNV-1 128bit would be ideal for 16 bytes but we need an overhead for Base64 encoding.
884 * Otherwise, the hash cannot be stored in a UTF-8 string.
885 * https://www.wikiwand.com/en/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#/FNV-1_hash
886 * https://github.com/pmdamora/fnv-cracker-app/blob/master/src/main/java/passwordcrack/cracking/HashChecker.java
887 * @param stringdata the String to be hashed
888 * @return the base64 formatted hash string
890 private String fnv(String stringdata) {
891 BigInteger hash = FNV_INIT;
892 byte[] data = stringdata.getBytes(StandardCharsets.UTF_8);
894 for (byte b : data) {
895 hash = hash.multiply(FNV_PRIME).mod(FNV_MOD);
896 hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
899 return Base64.getEncoder().encodeToString(hash.toByteArray());