/** * Create an {@link IpNetwork} instance which represents the given IP * address. * * @param iaddr An {@link InetAddress} instance. * @return An {@link IpNetwork} instance which represents the given IP * address. Note that {@code null} is returned if {@code iaddr} * is {@code null}. * @throws IllegalArgumentException * The given IP address is invalid. */ public static final IpNetwork create(InetAddress iaddr) { return create(iaddr, 0); }
/** * Create an {@link IpNetwork} instance which represents the IP network * specified by CIDR notation. * * @param cidr A string representation of the IP network in CIDR notation. * Note that zero prefix means "no mask". So zero prefix is * treated as if the maximum prefix length is specified. * @return An {@link IpNetwork} instance which represents the IP network * specified by {@code cidr}. Note that {@code null} is returned * if {@code cidr} is {@code null}. * @throws IllegalArgumentException * The given network address is invalid. */ public static final IpNetwork create(String cidr) { if (cidr == null) { return null; } InetAddressPrefix ipfx = new InetAddressPrefix(cidr); return create(ipfx.getAddress(), ipfx.getPrefix()); }
/** * {@inheritDoc} */ @Override public Set<IpNetwork> getIpNetworkSet() { Set<IpNetwork> ipSet = ipAddressSet; if (ipSet == null) { ipSet = new HashSet<>(); ipAddressSet = ipSet; List<IpAddress> ipaddrs = theEntry.getIpAddresses(); if (!MiscUtils.isEmpty(ipaddrs)) { for (IpAddress ip: ipaddrs) { ipSet.add(IpNetwork.create(ip)); } } } return ipSet; }
/** * Construct a new {@link IpNetwork} instance which represents the IP * network specified by the given {@link IpPrefix} instance. * * @param type A class which specifies the type of {@link IpNetwork} * instance. * @param ipp An {@link IpPrefix} instance. * @param desc A brief description about the specified IP network. * @return An {@link IpNetwork} instance or {@code null}. * @throws RpcException * The given parameter is invalid. */ private IpNetwork getIpNetwork(Class<? extends IpNetwork> type, IpPrefix ipp, String desc) throws RpcException { try { IpNetwork ipn = IpNetwork.create(ipp); if (ipn != null && !type.isInstance(ipn)) { throw new IllegalArgumentException( "Unexpected IP prefix type"); } return ipn; } catch (RuntimeException e) { String msg = MiscUtils.joinColon(ipp, e.getMessage()); throw invalidInetAddress(msg, desc, e); } }
/** * Construct a new instance. * * @param act A {@link VtnIpaddrActionFields} instance. * @param ord An integer which determines the order of flow actions * in a flow entry. * @throws RpcException An invalid argument is specified. */ protected VTNInetAddrAction(VtnIpaddrActionFields act, Integer ord) throws RpcException { super(ord); if (act != null) { address = IpNetwork.create(act.getAddress()); } verify(); }
/** * Create an {@link IpNetwork} instance which represents the IP network * specified by the given {@link IpPrefix} instance. * * @param ipp An {@link IpPrefix} instance which represents the IP * network. * @return An {@link IpNetwork} instance which represents the IP network * specified by {@code ipp}. Note that {@code null} is returned * if {@code ipp} is {@code null} or it does not contain valid * value. * @throws IllegalArgumentException * The given {@link IpPrefix} instance is invalid. */ public static final IpNetwork create(IpPrefix ipp) { if (ipp != null) { Ipv4Prefix ipv4 = ipp.getIpv4Prefix(); if (ipv4 != null) { return create(ipv4.getValue()); } if (ipp.getIpv6Prefix() != null) { throw new IllegalArgumentException( "Unsupported IP prefix: " + ipp); } } return null; }
/** * Create an {@link IpNetwork} instance which represents the IP network * specified by the given {@link Address} instance. * * @param addr An {@link Address} instance which represents the * IP address. * @return An {@link IpNetwork} instance which represents the IP network * specified by {@code addr}. Note that {@code null} is returned * if {@code addr} is {@code null} or it does not contain valid * value. * @throws IllegalArgumentException * The given {@link Address} instance is invalid. */ public static final IpNetwork create(Address addr) { if (addr instanceof Ipv4) { Ipv4Prefix ipv4 = ((Ipv4)addr).getIpv4Address(); return (ipv4 == null) ? null : create(ipv4.getValue()); } else if (addr == null) { return null; } throw getUnsupportedAddressException(addr); }
List<VtnFlowMatch> matchList = new ArrayList<VtnFlowMatch>(); VlanId vlanId = new VlanId(0); IpNetwork ipaddrSrc = IpNetwork.create(InetAddress.getByName(addressSrc)); IpNetwork ipaddrDst = IpNetwork.create(InetAddress.getByName(addressDst)); MacAddress macAddress = null; VtnInetMatch match = new VtnInetMatchBuilder()