List of usage examples for com.google.common.net InetAddresses forString
public static InetAddress forString(String ipString)
From source file:org.opendaylight.openflowplugin.applications.statistics.manager.impl.helper.FlowComparator.java
/** * Method return integer version of ip address. Converted int will be mask if * mask specified/* ww w .j av a 2 s . c o m*/ */ private static IntegerIpAddress StrIpToIntIp(final String ipAddresss) { final String[] parts = ipAddresss.split("/"); final String ip = parts[0]; int prefix; if (parts.length < 2) { prefix = 32; } else { prefix = Integer.parseInt(parts[1]); } IntegerIpAddress integerIpAddress = null; final Inet4Address addr = ((Inet4Address) InetAddresses.forString(ip)); final byte[] addrBytes = addr.getAddress(); final int ipInt = ((addrBytes[0] & 0xFF) << 24) | ((addrBytes[1] & 0xFF) << 16) | ((addrBytes[2] & 0xFF) << 8) | ((addrBytes[3] & 0xFF) << 0); // FIXME: Is this valid? final int mask = 0xffffffff << 32 - prefix; integerIpAddress = new IntegerIpAddress(ipInt, mask); return integerIpAddress; }
From source file:org.opendaylight.netvirt.ipv6service.IfMgr.java
public void updateRouterIntf(Uuid portId, Uuid rtrId, List<FixedIps> fixedIpsList) { LOG.debug("updateRouterIntf portId {}, fixedIpsList {} ", portId, fixedIpsList); VirtualPort intf = vintfs.get(portId); if (intf == null) { LOG.info("Skip Router interface update for non-ipv6 port {}", portId); return;//from ww w . j a v a2 s . c o m } List<Ipv6Address> existingIPv6AddressList = intf.getIpv6AddressesWithoutLLA(); List<Ipv6Address> newlyAddedIpv6AddressList = new ArrayList<>(); intf.clearSubnetInfo(); for (FixedIps fip : fixedIpsList) { IpAddress fixedIp = fip.getIpAddress(); if (fixedIp.getIpv4Address() != null) { continue; } //Save the interface ipv6 address in its fully expanded format Ipv6Address addr = new Ipv6Address( InetAddresses.forString(fixedIp.getIpv6Address().getValue()).getHostAddress()); fixedIp = new IpAddress(addr); intf.setSubnetInfo(fip.getSubnetId(), fixedIp); VirtualRouter rtr = vrouters.get(rtrId); VirtualSubnet snet = vsubnets.get(fip.getSubnetId()); if (rtr != null && snet != null) { snet.setRouter(rtr); intf.setSubnet(fip.getSubnetId(), snet); rtr.addSubnet(snet); } else if (snet != null) { intf.setSubnet(fip.getSubnetId(), snet); addUnprocessed(unprocessedRouterIntfs, rtrId, intf); } else { addUnprocessed(unprocessedRouterIntfs, rtrId, intf); addUnprocessed(unprocessedSubnetIntfs, fip.getSubnetId(), intf); } vrouterv6IntfMap.put(intf.getNetworkID(), intf); if (existingIPv6AddressList.contains(fixedIp.getIpv6Address())) { existingIPv6AddressList.remove(fixedIp.getIpv6Address()); } else { newlyAddedIpv6AddressList.add(fixedIp.getIpv6Address()); } } /* This is a port update event for routerPort. Check if any IPv6 subnet is added or removed from the router port. Depending on subnet added/removed, we add/remove the corresponding flows from IPV6_TABLE(45). */ for (Ipv6Address ipv6Address : newlyAddedIpv6AddressList) { // Some v6 subnets are associated to the routerPort add the corresponding NS Flows. programIcmpv6NSPuntFlowForAddress(intf, ipv6Address, Ipv6Constants.ADD_FLOW); } for (Ipv6Address ipv6Address : existingIPv6AddressList) { // Some v6 subnets are disassociated from the routerPort, remove the corresponding NS Flows. programIcmpv6NSPuntFlowForAddress(intf, ipv6Address, Ipv6Constants.DEL_FLOW); } return; }
From source file:org.dcache.srm.server.SRMServerV2.java
private Object dispatch(SRMUser user, String requestName, Object request) throws RemoteException { Class<?> requestClass = request.getClass(); String capitalizedRequestName = Character.toUpperCase(requestName.charAt(0)) + requestName.substring(1); try {//from ww w.j av a 2 s . c o m LOGGER.debug("About to call {} handler", requestName); Constructor<?> handlerConstructor; Object handler; Method handleGetResponseMethod; String remoteIP = Axis.getRemoteAddress(); String remoteHost = isClientDNSLookup ? InetAddresses.forString(remoteIP).getCanonicalHostName() : remoteIP; try { Class<?> handlerClass = Class.forName("org.dcache.srm.handler." + capitalizedRequestName); handlerConstructor = handlerClass.getConstructor(SRMUser.class, requestClass, AbstractStorageElement.class, SRM.class, String.class); handler = handlerConstructor.newInstance(user, request, storage, srm, remoteHost); if (handler instanceof CredentialAwareHandler) { CredentialAwareHandler credentialAware = (CredentialAwareHandler) handler; try { credentialAware.setCredential(srmAuth.getRequestCredential()); } catch (SRMAuthenticationException e) { LOGGER.warn(e.getMessage()); return getFailedResponse(capitalizedRequestName, e.getStatusCode(), "Authentication failed (server log contains additional information)."); } } handleGetResponseMethod = handlerClass.getMethod("getResponse"); } catch (ClassNotFoundException e) { if (LOGGER.isDebugEnabled()) { LOGGER.info("handler discovery and dynamic loading failed", e); } else { LOGGER.info("handler discovery and dynamic loading failed"); } return getFailedResponse(capitalizedRequestName, TStatusCode.SRM_NOT_SUPPORTED, requestName + " is unsupported"); } return handleGetResponseMethod.invoke(handler); } catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException | RuntimeException e) { LOGGER.error("Please report this failure to support@dcache.org", e); return getFailedResponse(capitalizedRequestName, TStatusCode.SRM_INTERNAL_ERROR, "Internal error (server log contains additional information)"); } }
From source file:org.opendaylight.netvirt.ipv6service.utils.Ipv6ServiceUtils.java
public Ipv6Address getIpv6SolicitedNodeMcastAddress(Ipv6Address ipv6Address) { /* According to RFC 4291, a Solicited Node Multicast Address is derived by adding the 24 lower order bits with the Solicited Node multicast prefix (i.e., FF02::1:FF00:0/104). Example: For IPv6Address of FE80::2AA:FF:FE28:9C5A, the corresponding solicited node multicast address would be FF02::1:FF28:9C5A *///from ww w . ja v a2 s .c o m byte[] octets; try { octets = InetAddress.getByName(ipv6Address.getValue()).getAddress(); } catch (UnknownHostException e) { LOG.error("getIpv6SolicitedNodeMcastAddress: Failed to serialize ipv6Address ", e); return null; } // Return the address in its fully expanded format. Ipv6Address solictedV6Address = new Ipv6Address( InetAddresses .forString( "ff02::1:ff" + 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")) .getHostAddress()); return solictedV6Address; }
From source file:com.facebook.presto.cassandra.CassandraType.java
public Object getJavaValue(Object nativeValue) { switch (this) { case ASCII:/*from www .j ava2 s .co m*/ case TEXT: case VARCHAR: return ((Slice) nativeValue).toStringUtf8(); case BIGINT: case BOOLEAN: case DOUBLE: case COUNTER: return nativeValue; case INET: return InetAddresses.forString(((Slice) nativeValue).toStringUtf8()); case INT: return ((Long) nativeValue).intValue(); case FLOAT: // conversion can result in precision lost return ((Double) nativeValue).floatValue(); case DECIMAL: // conversion can result in precision lost // Presto uses double for decimal, so to keep the floating point precision, convert it to string. // Otherwise partition id doesn't match return new BigDecimal(nativeValue.toString()); case TIMESTAMP: return new Date((Long) nativeValue); case UUID: case TIMEUUID: return java.util.UUID.fromString(((Slice) nativeValue).toStringUtf8()); case BLOB: case CUSTOM: return ((Slice) nativeValue).toStringUtf8(); case VARINT: return new BigInteger(((Slice) nativeValue).toStringUtf8()); case SET: case LIST: case MAP: default: throw new IllegalStateException("Back conversion not implemented for " + this); } }
From source file:io.prestosql.plugin.cassandra.CassandraType.java
public Object getJavaValue(Object nativeValue) { switch (this) { case ASCII:/*w ww.ja v a 2 s . co m*/ case TEXT: case VARCHAR: return ((Slice) nativeValue).toStringUtf8(); case BIGINT: case BOOLEAN: case DOUBLE: case COUNTER: return nativeValue; case INET: return InetAddresses.forString(((Slice) nativeValue).toStringUtf8()); case INT: return ((Long) nativeValue).intValue(); case FLOAT: // conversion can result in precision lost return intBitsToFloat(((Long) nativeValue).intValue()); case DECIMAL: // conversion can result in precision lost // Presto uses double for decimal, so to keep the floating point precision, convert it to string. // Otherwise partition id doesn't match return new BigDecimal(nativeValue.toString()); case TIMESTAMP: return new Date((Long) nativeValue); case UUID: case TIMEUUID: return java.util.UUID.fromString(((Slice) nativeValue).toStringUtf8()); case BLOB: case CUSTOM: return ((Slice) nativeValue).toStringUtf8(); case VARINT: return new BigInteger(((Slice) nativeValue).toStringUtf8()); case SET: case LIST: case MAP: default: throw new IllegalStateException("Back conversion not implemented for " + this); } }
From source file:org.opendaylight.protocol.bgp.rib.impl.BGPPeer.java
@Override public synchronized void onSessionUp(final BGPSession session) { final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes(); LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", this.name, addPathTablesType, session.getAdvertisedAddPathTableTypes()); this.session = session; this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress(); final PeerId peerId = RouterIds.createPeerId(session.getBgpId()); this.tables.addAll(this.session.getAdvertisedTableTypes().stream() .map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList())); final boolean announceNone = isAnnounceNone(this.simpleRoutingPolicy); if (!announceNone) { createAdjRibOutListener(peerId); }// w w w . ja va 2 s .c om addBgp4Support(peerId, announceNone); if (!isLearnNone(this.simpleRoutingPolicy)) { final YangInstanceIdentifier peerIId = this.rib.getYangRibId().node( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer.QNAME) .node(IdentifierUtils.domPeerId(peerId)); this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), peerIId, this.rib.getImportPolicyPeerTracker(), this.rib.getRibSupportContext(), this.peerRole, this.peerStats.getEffectiveRibInRouteCounters(), this.peerStats.getAdjRibInRouteCounters()); } this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables, addPathTablesType); // register BGP Peer stats this.peerStats.getSessionEstablishedCounter().increaseCount(); if (this.registrator != null) { this.runtimeReg = this.registrator.register(this); } if (this.rpcRegistry != null) { this.rpcRegistration = this.rpcRegistry.addRoutedRpcImplementation(BgpPeerRpcService.class, new BgpPeerRpc(session, this.tables)); final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer, PeerKey> path = this.rib .getInstanceIdentifier() .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer.class, new PeerKey(peerId)); this.rpcRegistration.registerPath(PeerContext.class, path); } this.rib.getRenderStats().getConnectedPeerCounter().increaseCount(); }
From source file:org.opendaylight.sxp.core.SxpNode.java
/** * Gets SxpPeerGroups in which specified connection is * * @param connection SxpConnections to look for in PeerGroups * @return List of PeerGroups that contain SxpConnection *//*from w w w .j a v a 2 s . c o m*/ private List<SxpPeerGroup> getPeerGroup(SxpConnection connection) { List<SxpPeerGroup> sxpPeerGroups = new ArrayList<>(); synchronized (peerGroupMap) { for (SxpPeerGroupBuilder peerGroup : peerGroupMap.values()) { if (peerGroup.getSxpPeers().getSxpPeer() == null || peerGroup.getSxpPeers().getSxpPeer().isEmpty()) { sxpPeerGroups.add(peerGroup.build()); continue; } for (SxpPeer peer : peerGroup.getSxpPeers().getSxpPeer()) { InetAddress address = InetAddresses.forString(Search.getAddress(peer.getPeerAddress())); if (address.equals(connection.getDestination().getAddress())) { sxpPeerGroups.add(peerGroup.build()); } } } } return sxpPeerGroups; }
From source file:org.opendaylight.netvirt.ipv6service.IfMgr.java
public void addHostIntf(Uuid portId, Uuid snetId, Uuid networkId, IpAddress fixedIp, String macAddress, String deviceOwner) {/* w w w.ja v a2 s . co m*/ LOG.debug("addHostIntf portId {}, snetId {}, networkId {}, ip {}, mac {}", portId, snetId, networkId, fixedIp, macAddress); //Save the interface ipv6 address in its fully expanded format Ipv6Address addr = new Ipv6Address( InetAddresses.forString(fixedIp.getIpv6Address().getValue()).getHostAddress()); fixedIp = new IpAddress(addr); VirtualPort intf = vintfs.get(portId); if (intf == null) { intf = new VirtualPort(); if (intf != null) { vintfs.put(portId, intf); } else { LOG.error("Create host intf failed for :{}", portId); return; } intf.setIntfUUID(portId).setSubnetInfo(snetId, fixedIp).setNetworkID(networkId) .setMacAddress(macAddress).setRouterIntfFlag(false).setDeviceOwner(deviceOwner); Long elanTag = getNetworkElanTag(networkId); // Do service binding for the port and set the serviceBindingStatus to true. ipv6ServiceUtils.bindIpv6Service(dataBroker, portId.getValue(), elanTag, NwConstants.IPV6_TABLE); intf.setServiceBindingStatus(Boolean.TRUE); } else { intf.setSubnetInfo(snetId, fixedIp); } VirtualSubnet snet = vsubnets.get(snetId); if (snet != null) { intf.setSubnet(snetId, snet); } else { addUnprocessed(unprocessedSubnetIntfs, snetId, intf); } return; }
From source file:com.eucalyptus.www.X509Download.java
@SuppressWarnings("ConstantConditions") private static URI hostMap(final URI uri) { final Optional<Cidr> hostMatcher = InetAddresses.isInetAddress(uri.getHost()) ? Cidr.parse().apply(AuthenticationProperties.CREDENTIAL_DOWNLOAD_HOST_MATCH) : Optional.<Cidr>absent(); if (hostMatcher.isPresent()) { final Host host = Hosts.lookup(InetAddresses.forString(uri.getHost())); if (host != null) { final Optional<InetAddress> mappedHost = Iterables.tryFind(host.getHostAddresses(), hostMatcher.get());// w ww .java 2 s . c o m if (mappedHost.isPresent()) { return URI .create(uri.toString().replaceFirst(uri.getHost(), mappedHost.get().getHostAddress())); } } } return uri; }