public static int getAFItranslatedfromPrefix(String argPrefix) {
int retValue = af_afi.AFI_IP.getValue();//default afiValue is 1 (= ipv4)
String prefixOnly;
- if (argPrefix.indexOf("/") == -1) {
+ if (!argPrefix.contains("/")) {
prefixOnly = argPrefix;
} else {
prefixOnly = argPrefix.substring(0, argPrefix.indexOf("/"));
String inputCmd = "show " + command;
outToSocket.println(inputCmd);
- StringBuffer output = new StringBuffer();
+ StringBuilder output = new StringBuilder();
String errorMsg = "";
while (true) {
char[] opBuf = new char[100];
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
builder1.setKey(new ManagersKey(new Uri(MANAGER_KEY)));
List<ManagerOtherConfigs> otherConfigses = new ArrayList<>();
- StringBuffer stringBuffer = new StringBuffer();
- for (NodeId nodeId : nodeIds) {
- stringBuffer.append(nodeId.getValue());
- stringBuffer.append(",");
- }
-
- String children = stringBuffer.substring(0, stringBuffer.toString().length() - 1);
-
+ String children = nodeIds.stream().map(NodeId::getValue).collect(Collectors.joining(","));
otherConfigses.add(getOtherConfigBuilder(HA_CHILDREN, children).build());
builder1.setManagerOtherConfigs(otherConfigses);
List<Managers> managers = new ArrayList<>();
* @return true if the param subnet contained the prefixToTest false otherwise
*/
public static boolean doesPrefixBelongToSubnet(String prefixToTest, String subnet, boolean exactMatch) {
- boolean rep = false;
if (prefixToTest == null || prefixToTest.length() < 7 || subnet == null || subnet.length() < 7) {
- return rep;
+ return false;
}
if (isIpv4Prefix(prefixToTest) && isIpv4Prefix(subnet)
|| isIpv6Prefix(prefixToTest) && isIpv6Prefix(subnet)) {
String ipPref = getIpFromPrefix(prefixToTest);
String ipSub = getIpFromPrefix(subnet);
String maskSubString = subnet.substring(subnet.indexOf("/") + 1);
- String maskPrefString = null;
- if (prefixToTest.indexOf("/") > -1) {
+ String maskPrefString;
+ if (prefixToTest.contains("/")) {
maskPrefString = prefixToTest.substring(prefixToTest.indexOf("/") + 1);
} else if (ipVersion == 4) {
maskPrefString = "32";
maskPrefString = "128";
}
- int maskPref = -1;
- int maskSub = -1;
try {
- maskPref = Integer.parseInt(maskPrefString);
- maskSub = Integer.parseInt(maskSubString);
+ int maskPref = Integer.parseInt(maskPrefString);
+ int maskSub = Integer.parseInt(maskSubString);
if (exactMatch && maskPref != maskSub) {
/*because the mask must be exactly the same between them, the return type is false. This behavior could
* be changed to ignored it in including a boolean options to force or not the same mask control*/
- rep = false;
- return rep;
+ return false;
}
BigInteger maskSubBig = getMaskNetwork(ipVersion, maskSub);
byte[] byteIpSub = InetAddress.getByName(ipSub).getAddress();
byte[] byteIpPref = InetAddress.getByName(ipPref).getAddress();
BigInteger netFromIpSub = packBigInteger(byteIpSub).and(maskSubBig);
BigInteger netFromIpPref = packBigInteger(byteIpPref).and(maskSubBig);
- if (netFromIpSub.compareTo(netFromIpPref) == 0) {
- rep = true;
- }
+ return netFromIpSub.compareTo(netFromIpPref) == 0;
} catch (NumberFormatException | UnknownHostException e) {
- return rep;
+ return false;
}
- return rep;
}
- return rep;
+ return false;
}
/**This method converts a byte[] to a BigInteger value.
if (prefixOrSubnetOption != null && prefixOrSubnetOption.length() > 0) {
prefixOrSubnet = prefixOrSubnetOption.replace("[", "");
prefixOrSubnet = prefixOrSubnet.replace("]", "");
- if (prefixOrSubnet.indexOf("/") < 0) {
+ if (!prefixOrSubnet.contains("/")) {
String maskFull = null;
try {
Inet4Address tempAdd = (Inet4Address) InetAddress.getByName(prefixOrSubnet);
if (bytes == null) {
return "null";
}
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
if (i > 0) {
buf.append(":");
3. Use the prefix "FE80::/10" along with the above 64 bit Interface
identifier to generate the IPv6 LLA. */
- StringBuffer interfaceID = new StringBuffer();
+ StringBuilder interfaceID = new StringBuilder();
short u8byte = (short) (octets[0] & 0xff);
u8byte ^= 1 << 1;
interfaceID.append(Integer.toHexString(0xFF & u8byte));
return null;
}
- StringBuffer macAddress = new StringBuffer();
- macAddress.append("33:33:");
- macAddress.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[12]), 2, "0") + ":");
- macAddress.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[13]), 2, "0") + ":");
- macAddress.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[14]), 2, "0") + ":");
- macAddress.append(StringUtils.leftPad(Integer.toHexString(0xFF & octets[15]), 2, "0"));
+ String macAddress = "33:33:"
+ + StringUtils.leftPad(Integer.toHexString(0xFF & octets[12]), 2, "0") + ":"
+ + StringUtils.leftPad(Integer.toHexString(0xFF & octets[13]), 2, "0") + ":"
+ + StringUtils.leftPad(Integer.toHexString(0xFF & octets[14]), 2, "0") + ":"
+ + StringUtils.leftPad(Integer.toHexString(0xFF & octets[15]), 2, "0");
- return new MacAddress(macAddress.toString());
+ return new MacAddress(macAddress);
}
private static List<MatchInfo> getIcmpv6RSMatch(Long elanTag) {
package org.opendaylight.netvirt.ipv6service.shell;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
private String getPortIpv6Addresses(IVirtualPort vport) {
List<Ipv6Address> ipv6Addresses = vport.getIpv6Addresses();
- StringBuffer str = new StringBuffer();
- for (Ipv6Address ipaddr: ipv6Addresses) {
- str.append(ipaddr.getValue());
- str.append(" ");
- }
- return str.toString();
+ return ipv6Addresses.stream().map(Ipv6Address::getValue).collect(Collectors.joining(" "));
}
@Override
return;
}
int oldRdsCount = originalRds.size();
- Iterator<String> originalRdsInter = originalRds.iterator();
- while (originalRdsInter.hasNext()) {
- String rd = originalRdsInter.next();
+ for (String rd : originalRds) {
//If the existing rd is not present in the updateRds list, not allow to process the updateRDs.
if (!updateRDs.contains(rd)) {
LOG.error("The existing RD {} not present in the updatedRDsList:{}", rd, updateRDs);
3. Use the prefix "FE80::/10" along with the above 64 bit Interface
identifier to generate the IPv6 LLA. */
- StringBuffer interfaceID = new StringBuffer();
+ StringBuilder interfaceID = new StringBuilder();
short u8byte = (short) (octets[0] & 0xff);
u8byte ^= 1 << 1;
interfaceID.append(Integer.toHexString(0xFF & u8byte));
*/
public static IpVersionChoice getIpVersionFromString(String ipAddress) {
IpVersionChoice ipchoice = IpVersionChoice.UNDEFINED;
- if (ipAddress.indexOf("/") >= 0) {
+ if (ipAddress.contains("/")) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf("/"));
}
try {
try {
CompletableFuture<Void> allOf = CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0]));
allOf.get(nodeResultTimeout, TimeUnit.SECONDS);
- for (int i = 0; i < futureList.size(); i++) {
- CompletableFuture<NodeConnectorStatisticsSupplierOutput> completableCurrentResult = futureList.get(i);
+ for (CompletableFuture<NodeConnectorStatisticsSupplierOutput> completableCurrentResult : futureList) {
if (completableCurrentResult == null) {
LOG.warn("Unable to retrieve node counters");
counters.failedGettingNodeCounters.inc();
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
String nhTepIp = null;
BigInteger nhDpnId = null;
- Iterator<SubnetToDpn> subnetDpnIter = subDpnList.iterator();
- while (subnetDpnIter.hasNext()) {
- SubnetToDpn subnetToDpn = subnetDpnIter.next();
+ for (SubnetToDpn subnetToDpn : subDpnList) {
if (subnetToDpn.getDpnId().equals(oldDpnId)) {
// Is this same is as input dpnId, then ignore it
continue;
} catch (Exception e) {
LOG.warn("{} electNewDpnForSubnetRoute: Unable to find TepIp for rd {} subnetroute subnetip {}"
+ " for dpnid {}, attempt next", LOGGING_PREFIX, rd, subnetIp, nhDpnId.toString(), e);
- continue;
}
}
}