use of java.net.Inet6Address in project EngineDriver by JMRI.
the class ServiceInfoImpl method getURLs.
/*
* (non-Javadoc)
* @see javax.jmdns.ServiceInfo#getURLs(java.lang.String)
*/
@Override
public String[] getURLs(String protocol) {
InetAddress[] addresses = this.getInetAddresses();
List<String> urls = new ArrayList<String>(addresses.length);
for (InetAddress address : addresses) {
String hostAddress = address.getHostAddress();
if (address instanceof Inet6Address) {
hostAddress = "[" + hostAddress + "]";
}
String url = protocol + "://" + hostAddress + ":" + getPort();
String path = getPropertyString("path");
if (path != null) {
if (path.indexOf("://") >= 0) {
url = path;
} else {
url += path.startsWith("/") ? path : "/" + path;
}
}
urls.add(url);
}
return urls.toArray(new String[urls.size()]);
}
use of java.net.Inet6Address in project EngineDriver by JMRI.
the class ServiceInfoImpl method clone.
/*
* (non-Javadoc)
* @see javax.jmdns.ServiceInfo#clone()
*/
@Override
public ServiceInfoImpl clone() {
ServiceInfoImpl serviceInfo = new ServiceInfoImpl(this.getQualifiedNameMap(), _port, _weight, _priority, _persistent, _text);
Inet6Address[] ipv6Addresses = this.getInet6Addresses();
for (Inet6Address address : ipv6Addresses) {
serviceInfo._ipv6Addresses.add(address);
}
Inet4Address[] ipv4Addresses = this.getInet4Addresses();
for (Inet4Address address : ipv4Addresses) {
serviceInfo._ipv4Addresses.add(address);
}
return serviceInfo;
}
use of java.net.Inet6Address in project netvirt by opendaylight.
the class BgpUtil method getAFItranslatedfromPrefix.
/**
* get a translation from prefix ipv6 to afi<br>.
* "ffff::1/128" sets afi as 2 because is an IPv6 value
* @param argPrefix ip address as ipv4 or ipv6
* @return afi 1 for AFI_IP 2 for AFI_IPV6
*/
public static int getAFItranslatedfromPrefix(String argPrefix) {
// default afiValue is 1 (= ipv4)
int retValue = af_afi.AFI_IP.getValue();
String prefixOnly;
if (argPrefix.indexOf("/") == -1) {
prefixOnly = argPrefix;
} else {
prefixOnly = argPrefix.substring(0, argPrefix.indexOf("/"));
}
try {
InetAddress address = InetAddress.getByName(prefixOnly);
if (address instanceof Inet6Address) {
retValue = af_afi.AFI_IPV6.getValue();
} else if (address instanceof Inet4Address) {
retValue = af_afi.AFI_IP.getValue();
}
} catch (java.net.UnknownHostException e) {
/*if exception is catched then the prefix is not an IPv6 and IPv4*/
LOG.error("Unrecognized ip address ipAddress: {}", argPrefix);
// default afiValue is 1 (= ipv4)
retValue = af_afi.AFI_IP.getValue();
}
return retValue;
}
use of java.net.Inet6Address in project netvirt by opendaylight.
the class SubnetGwMacChangeListener method handleSubnetGwIpChange.
private void handleSubnetGwIpChange(LearntVpnVipToPort learntVpnVipToPort) {
String macAddress = learntVpnVipToPort.getMacAddress();
if (macAddress == null) {
LOG.error("handleSubnetGwIpChange : Mac address is null for LearntVpnVipToPort for vpn {} prefix {}", learntVpnVipToPort.getVpnName(), learntVpnVipToPort.getPortFixedip());
return;
}
String fixedIp = learntVpnVipToPort.getPortFixedip();
if (fixedIp == null) {
LOG.error("handleSubnetGwIpChange : Fixed ip is null for LearntVpnVipToPort for vpn {}", learntVpnVipToPort.getVpnName());
return;
}
try {
InetAddress address = InetAddress.getByName(fixedIp);
if (address instanceof Inet6Address) {
// TODO: Revisit when IPv6 North-South communication support is added.
LOG.debug("handleSubnetGwIpChange : Skipping ipv6 address {}.", address);
return;
}
} catch (UnknownHostException e) {
LOG.warn("handleSubnetGwIpChange : Invalid ip address {}", fixedIp, e);
return;
}
for (Uuid subnetId : nvpnManager.getSubnetIdsForGatewayIp(new IpAddress(new Ipv4Address(fixedIp)))) {
LOG.trace("handleSubnetGwIpChange : Updating MAC resolution on vpn {} for GW ip {} to {}", learntVpnVipToPort.getVpnName(), fixedIp, macAddress);
extNetworkInstaller.installExtNetGroupEntries(subnetId, macAddress);
}
}
use of java.net.Inet6Address in project netvirt by opendaylight.
the class VpnUtil method getIpVersionFromString.
/**
*Get IpVersionChoice from String IP like x.x.x.x or an representation IPv6.
* @param ipAddress String of an representation IP address V4 or V6
* @return the IpVersionChoice of the version or IpVersionChoice.UNDEFINED otherwise
*/
public static IpVersionChoice getIpVersionFromString(String ipAddress) {
IpVersionChoice ipchoice = IpVersionChoice.UNDEFINED;
int indexIpAddress = ipAddress.indexOf('/');
if (indexIpAddress >= 0) {
ipAddress = ipAddress.substring(0, indexIpAddress);
}
try {
InetAddress address = InetAddress.getByName(ipAddress);
if (address instanceof Inet4Address) {
return IpVersionChoice.IPV4;
} else if (address instanceof Inet6Address) {
return IpVersionChoice.IPV6;
}
} catch (UnknownHostException | SecurityException e) {
ipchoice = IpVersionChoice.UNDEFINED;
}
return ipchoice;
}
Aggregations