public static IpAddress getIpAddress(IpPrefix ip) { StringBuilder buf = new StringBuilder(); for (char x : ip.getValue()) { if (x == '/') { break; } buf.append(x); } return new IpAddress(buf.toString().toCharArray()); }
private static void validateAndAddIpAddressToList(SubnetInfo subnetInfo, final List<IpAddress> lstIpAddress, String ipAddress) { String ip = StringUtils.trim(ipAddress); Preconditions.checkArgument(InetAddresses.isInetAddress(ip), new StringBuilder("Invalid exclude IP filter: invalid IP address value ").append(ip).toString()); Preconditions.checkArgument(subnetInfo.isInRange(ip), new StringBuilder("Invalid exclude IP filter: IP address [").append(ip).append("] not in subnet range ") .append(subnetInfo.getCidrSignature()).toString()); lstIpAddress.add(new IpAddress(ip.toCharArray())); } private static int[] toIpArray(int val) {
private static IpAddress parseIp(final ByteBuf buffer) { final int ipLength = buffer.readUnsignedByte(); if (ipLength == Ipv6Util.IPV6_BITS_LENGTH) { return new IpAddress(Ipv6Util.addressForByteBuf(buffer)); } else if (ipLength == Ipv4Util.IP4_BITS_LENGTH) { return new IpAddress(Ipv4Util.addressForByteBuf(buffer)); } return null; } }
public static IpAddress parseOrigRouteIp(final ByteBuf buffer) { final int ipLength = buffer.readUnsignedByte(); if (ipLength == Ipv6Util.IPV6_BITS_LENGTH) { return new IpAddress(Ipv6Util.addressForByteBuf(buffer)); } else if (ipLength == Ipv4Util.IP4_BITS_LENGTH) { return new IpAddress(Ipv4Util.addressForByteBuf(buffer)); } return null; }
private static IpAddress resolveIpAddress(final InetAddress address) { String hostAddress = address.getHostAddress(); if (address instanceof Inet4Address) { return new IpAddress(new Ipv4Address(hostAddress)); } if (address instanceof Inet6Address) { return new IpAddress(new Ipv6Address(hostAddress)); } throw new IllegalArgumentException("Unsupported IP address type!"); }
private static IpAddress resolveIpAddress(final InetAddress address) { String hostAddress = address.getHostAddress(); if (address instanceof Inet4Address) { return new IpAddress(new Ipv4Address(hostAddress)); } if (address instanceof Inet6Address) { return new IpAddress(new Ipv6Address(hostAddress)); } throw new IllegalArgumentException("Unsupported IP address type!"); }
@Override public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final PceIdBuilder builder = new PceIdBuilder(); builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); return builder.build(); }
private IpAddress getNodeIP(BigInteger dpId) throws Exception { Node node = getPortsNode(dpId); String localIp = southBoundUtils.getOpenvswitchOtherConfig(node, LOCAL_IP); if (localIp == null) { throw new Exception("missing local_ip key in ovsdb:openvswitch-other-configs in operational" + " network-topology for node: " + node.getNodeId().getValue()); } return new IpAddress(localIp.toCharArray()); }
@Override public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final PceIdBuilder builder = new PceIdBuilder(); builder.setIpAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))); return builder.build(); }
@Override public Object parseObject(final ObjectHeader header, final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); final PccIdReqBuilder builder = new PccIdReqBuilder(); builder.setIpAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); return builder.build(); }
/** * {@inheritDoc} */ @Override public IpAddress getIpAddress() { return new IpAddress(new Ipv4Address(getHostAddress())); }
private IpAddress getRemoteIp() { final IpAddress remoteIp = StrictBGPPeerRegistry.getIpAddress(this.channel.remoteAddress()); if (remoteIp.getIpv6Address() != null) { return new IpAddress(Ipv6Util.getFullForm(remoteIp.getIpv6Address())); } return remoteIp; }
private Subnets newSubnets(String subnetIp) { SubnetsBuilder subnetsBuilder = new SubnetsBuilder(); subnetsBuilder.setDeviceVteps(new ArrayList<>()); subnetsBuilder.setGatewayIp(new IpAddress("0.0.0.0".toCharArray())); subnetsBuilder.setKey(new SubnetsKey(new IpPrefix(subnetIp.toCharArray()))); subnetsBuilder.setVlanId(0); subnetsBuilder.setVteps(new ArrayList<Vteps>()); return subnetsBuilder.build(); }
private Uuid getSubnetIdOfIp(String ip) { if (ip != null) { IpAddress externalIpv4Address = new IpAddress(new Ipv4Address(ip)); Port port = NatUtil.getNeutronPortForRouterGetewayIp(dataBroker, externalIpv4Address); Uuid subnetId = NatUtil.getSubnetIdForFloatingIp(port, externalIpv4Address); return subnetId; } return null; }
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final RedirectIpNhExtendedCommunityBuilder builder = new RedirectIpNhExtendedCommunityBuilder(); if (buffer.readableBytes() > Ipv6Util.IPV6_LENGTH ) { builder.setNextHopAddress(new IpAddress(Ipv6Util.addressForByteBuf(buffer))); } else { builder.setNextHopAddress(new IpAddress(Ipv4Util.addressForByteBuf(buffer))); } builder.setCopy((buffer.readUnsignedShort() & COPY) == 1); return new RedirectIpNhExtendedCommunityCaseBuilder().setRedirectIpNhExtendedCommunity(builder.build()).build(); }
private Segment parseSrv6Sid(final long i, final Srv6Sid srv6Sid) { // shifting index by 1 so it matches original indexing long index = i + 1L; SegmentBuilder builder = new SegmentBuilder().withKey(new SegmentKey(index)).setState( new org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.oc.srte.policy.rev170918.segment.properties.StateBuilder() .setIndex(index) .setType(SegmentType.Type2) .setSidValue(new SidValueType( new IpAddress(new Ipv6Address(arrayToIpv6AddressNoZone(srv6Sid.addr))))) .build()); return builder.build(); }
private static Neighbor toAppNeighbor(final BGPAppPeerInstanceConfiguration config) { final IpAddress ipAddress = new IpAddress(new Ipv4Address(config.getBgpId().getValue())); return new NeighborBuilder() .setNeighborAddress(ipAddress) .setKey(new NeighborKey(ipAddress)) .setConfig( new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder() .addAugmentation(Config1.class, new Config1Builder().setPeerGroup(OpenConfigUtil.APPLICATION_PEER_GROUP_NAME).build()) .build()) .build(); } }
@Override public Neighbor fromApplicationPeer(final ApplicationRibId applicationRibId, final BgpId bgpId) { final NeighborBuilder neighborBuilder = new NeighborBuilder(); neighborBuilder.setNeighborAddress(new IpAddress(new Ipv4Address(bgpId.getValue()))); neighborBuilder.setKey(new NeighborKey(neighborBuilder.getNeighborAddress())); neighborBuilder.setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder() .setDescription(applicationRibId.getValue()) .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build()) .build()); return neighborBuilder.build(); }