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_GET_DEV_CONF_LOGMSG =
30 "{} : impossible to get device configuration";
31 public static final String CANNOT_GET_LLDP_CONF_LOGMSG =
32 "- cannot find port config under LLDP";
33 public static final String CONMAP_ISSUE_LOGMSG =
34 "{} : connection-map analysis for source {} and dest (CP+port) {} - no entry found for source in LCP map";
35 public static final String CREATE = "create";
36 public static final String CREATE_MAPPING_DATA_LOGMSG =
37 "{} : OpenROADM version {} node - Creating Mapping Data";
38 public static final String DEVICE_HAS_LOGMSG =
39 "{} : device has {} {}";
40 public static final String FETCH_CONNECTIONPORT_LOGMSG =
41 "{} : fetching connection-port {} at circuit-pack {}";
42 public static final String FOUND = "found";
43 public static final String GETTING_CONPORT_LOGMSG =
44 "{} : getting connection-ports for degree number {}";
45 public static final String GETTING_CP_LOGMSG =
46 "{} : getting circuit-packs for SRG number {}";
47 public static final String GETTING_ETH_LIST_LOGMSG =
48 "{} : getting Ethernet interfaces list";
49 public static final String GETTING_MC_CAPA_LOGMSG =
50 "{} : getting MC capabilities for {}";
51 public static final String GOT_INTF_LOGMSG =
52 "{} : got interface {} of type {}";
53 public static final String INTF_ISSUE_LOGMSG =
54 "{} : error while getting interface {} ";
55 public static final String MAP_LOOKS_LOGMSG =
56 "{} : map looks like this {}";
57 public static final String MISSING_CP_LOGMSG =
58 "{} : no circuit-pack {} in the device";
59 public static final String NO_ASSOC_FOUND_LOGMSG =
60 "{} : port {} on {} - no association found {}";
61 public static final String NO_CONMAP_LOGMSG =
62 "{} : no connection-map found inside device configuration";
63 public static final String NO_MC_LOGMSG =
64 "{} : no MC profile found on {} {} - assuming fixed grid";
65 public static final String NO_PORT_ON_CP_LOGMSG =
66 "{} : no port {} on circuit pack {}";
67 public static final String NO_VALID_PARTNERPORT_LOGMSG =
68 "{} : port {} on {} has no valid partner port";
69 public static final String NODE_TYPE_LOGMSG =
71 public static final String NOT_CORRECT_CONPORT_LOGMSG =
72 "{} : the number of connection-port is not correct for DEG{}";
73 public static final String NOT_CORRECT_PARTNERPORT_LOGMSG =
74 "{} : port {} on {} is not a correct partner port of {} on {}";
75 public static final String PARTNERPORT_CONF_ERROR_LOGMSG =
76 " - error with partner port configuration";
77 public static final String PARTNERPORT_GET_ERROR_LOGMSG =
78 " - error getting partner port";
79 public static final String PORT_ALREADY_HANDLED_LOGMSG =
80 "{} : port {} on {} has already been handled";
81 public static final String PORT_NOT_RDMEXT_LOGMSG =
82 "{} : port {} on {} is not roadm-external";
83 public static final String PORTDIR_ERROR_LOGMSG =
84 "{} : port {} on {} - error in configuration with port-direction";
85 public static final String PORTMAPPING_IGNORE_LOGMSG =
86 " - ignoring it in port-mapping";
87 public static final String PORTMAPPING_POST_FAIL_LOGMSG =
88 "{} : port-mapping post-treatment failure for {}";
89 public static final String PORTQUAL_LOGMSG =
90 "{} : port {} on {} - PortQual {}";
91 public static final String PROCESSING_DONE_LOGMSG =
92 "{} : processing done {}";
93 public static final String UNABLE_MAPPING_LOGMSG =
94 "{} : unable to {} mapping for {}";
95 public static final String UNABLE_MC_CAPA_LOGMSG =
96 "{} : unable to create MC capabilities";
97 public static final String UNSUPPORTED_DIR_LOGMSG =
98 "{} : port {} on {} - unsupported Direction {}";
99 public static final String UPDATE = "update";
100 public static final String UPDATE_MAPPING_LOGMSG =
101 "{} : Updating old mapping data {} for {} by new mapping data {}";
102 public static final String XPDR_LIST_IN_CONF_LOGMSG =
103 "{} : list of Xponders {} in configuration";
106 * Implements the FNV-1 64bit algorithm.
107 * FNV-1 128bit would be ideal for 16 bytes but we need an overhead for Base64 encoding.
108 * Otherwise, the hash cannot be stored in a UTF-8 string.
109 * https://www.wikiwand.com/en/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#/FNV-1_hash
110 * https://github.com/pmdamora/fnv-cracker-app/blob/master/src/main/java/passwordcrack/cracking/HashChecker.java
111 * @param stringdata the String to be hashed
112 * @return the hash string
114 public static String fnv1size64(String stringdata) {
115 BigInteger hash = FNV_INIT;
116 byte[] data = stringdata.getBytes(StandardCharsets.UTF_8);
118 for (byte b : data) {
119 hash = hash.multiply(FNV_PRIME).mod(FNV_MOD);
120 hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
123 return Base64.getEncoder().encodeToString(hash.toByteArray());
126 protected static String degreeTtpNodeName(String cpIndex, String direction) {
127 ArrayList<String> array = new ArrayList<>();
128 array.add("DEG" + cpIndex);
129 array.add(StringConstants.TTP_TOKEN);
130 if (direction != null) {
131 array.add(direction);
133 return String.join("-", array);
136 protected static String createXpdrLogicalConnectionPort(int xponderNb, int lcpNb, String token) {
137 return new StringBuilder("XPDR").append(xponderNb)
139 .append(token).append(lcpNb)
143 private PortMappingUtils() {
144 //Noop - should not be called