2 * Copyright © 2020 Orange, Inc. 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 java.math.BigInteger;
12 import java.nio.charset.StandardCharsets;
13 import java.util.ArrayList;
14 import java.util.Base64;
15 import org.opendaylight.transportpce.common.StringConstants;
17 public final class PortMappingUtils {
19 //FNV1 64 bit hash constants
20 private static final BigInteger FNV_PRIME = new BigInteger("100000001b3", 16);
21 private static final BigInteger FNV_INIT = new BigInteger("cbf29ce484222325", 16);
22 private static final BigInteger FNV_MOD = new BigInteger("2").pow(64);
25 public static final String ASSOCIATED_LCP_LOGMSG =
26 "{} : port {} on {} - associated Logical Connection Point is {}";
27 public static final String CANNOT_AS_LCP_LOGMSG =
28 " - cannot assign Logical Connection Point";
29 public static final String CANNOT_CREATE_LCP_LOGMSG =
30 "{} : port {} on {} - Impossible to create logical connection point";
31 public static final String CANNOT_GET_DEV_CONF_LOGMSG =
32 "{} : Impossible to get device configuration";
33 public static final String CANNOT_GET_LLDP_CONF_LOGMSG =
34 "- cannot find port config under LLDP";
35 public static final String CREATE_MAPPING_DATA_LOGMSG =
36 "{} : OpenROADM version {} node - Creating Mapping Data";
37 public static final String DEVICE_HAS_LOGMSG =
38 "{} : Device has {} {}";
39 public static final String FETCH_CONNECTIONPORT_LOGMSG =
40 "{} : Fetching connection-port {} at circuit pack {}";
41 public static final String GETTING_ETH_LIST_LOGMSG =
42 "{} : getting Ethernet interfaces list";
43 public static final String GETTING_MC_CAPA_LOGMSG =
44 "{} : Getting the MC capabilities for {}";
45 public static final String MISSING_CP_LOGMSG =
46 "{} : No Circuit-pack {} in the device";
47 public static final String NO_ASSOC_FOUND_LOGMSG =
48 "{} : port {} on {} - no association found {}";
49 public static final String NO_MC_LOGMSG =
50 "{} : No MC profile found on {} {} - assuming fixed grid";
51 public static final String NO_PORT_ON_CP_LOGMSG =
52 "{} : No port {} on circuit pack {}";
53 public static final String NO_VALID_PARTNERPORT_UNIDIR_LOGMSG =
54 "{} : port {} on {} is unidirectional but has no valid partnerPort";
55 public static final String NOT_CORRECT_PARTNERPORT_LOGMSG =
56 "{} : port {} on {} is not a correct partner port of {} on {}";
57 public static final String PARTNERPORT_CONF_ERROR_LOGMSG =
58 " - Error with partner port configuration";
59 public static final String PARTNERPORT_GET_ERROR_LOGMSG =
60 " - Error getting partner port";
61 public static final String PORTDIR_ERROR_LOGMSG =
62 " - Error in configuration with port-direction";
63 public static final String PORTMAPPING_IGNORE_LOGMSG =
64 " - ignoring it in port-mapping";
65 public static final String PORTQUAL_ERROR_LOGMSG =
66 " - Error in configuration with port-qual";
67 public static final String PROCESSING_DONE_LOGMSG =
68 "{} : Processing done {}";
69 public static final String UNABLE_MAPPING_LOGMSG =
70 "{} : Unable to {} mapping for {}";
71 public static final String UNABLE_MC_CAPA_LOGMSG =
72 "{} : Unable to create MC capabilities";
73 public static final String UNSUPPORTED_DIR_LOGMSG =
74 "{} : port {} on {} - unsupported Direction {}";
77 * Implements the FNV-1 64bit algorithm.
78 * FNV-1 128bit would be ideal for 16 bytes but we need an overhead for Base64 encoding.
79 * Otherwise, the hash cannot be stored in a UTF-8 string.
80 * https://www.wikiwand.com/en/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#/FNV-1_hash
81 * https://github.com/pmdamora/fnv-cracker-app/blob/master/src/main/java/passwordcrack/cracking/HashChecker.java
82 * @param stringdata the String to be hashed
83 * @return the hash string
85 protected static String fnv1size64(String stringdata) {
86 BigInteger hash = FNV_INIT;
87 byte[] data = stringdata.getBytes(StandardCharsets.UTF_8);
90 hash = hash.multiply(FNV_PRIME).mod(FNV_MOD);
91 hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
94 return Base64.getEncoder().encodeToString(hash.toByteArray());
97 protected static String degreeTtpNodeName(String cpIndex, String direction) {
98 ArrayList<String> array = new ArrayList<>();
99 array.add("DEG" + cpIndex);
100 array.add(StringConstants.TTP_TOKEN);
101 if (direction != null) {
102 array.add(direction);
104 return String.join("-", array);
107 protected static String createXpdrLogicalConnectionPort(int xponderNb, int lcpNb, String token) {
108 return new StringBuilder("XPDR").append(xponderNb)
110 .append(token).append(lcpNb)
114 private PortMappingUtils() {
115 //Noop - should not be called