List of usage examples for org.apache.commons.net.util SubnetUtils getInfo
public final SubnetInfo getInfo()
From source file:org.opennaas.extensions.genericnetwork.actionsets.internal.circuitaggregation.actions.CalculateAggregatedCircuitsAction.java
private String getIP24WithShortMask(String ipAddress) { SubnetUtils utils = new SubnetUtils(ipAddress, "255.255.255.0"); return utils.getInfo().getNetworkAddress() + "/24"; }
From source file:org.openo.sdnhub.sptndriver.utils.Ipv4Util.java
/** * Transform integer mask to string dot mask. * * @param intMask Integer value of mask, like 24 * @return Mask in form of "255.255.255.0" *//*from w w w . j a v a 2 s . c o m*/ private static String ipInt2DotStr(int intMask) { String cidr = "255.255.255.255/" + intMask; SubnetUtils subnet = new SubnetUtils(cidr); return subnet.getInfo().getNetmask(); }
From source file:org.ow2.sirocco.cloudmanager.connector.vcd.VcdCloudProvider.java
private void fromVappNetworkToNetwork(final VappNetwork vappNetwork, final Network n) { ReferenceType vappNetworkReferenceType = vappNetwork.getReference(); n.setName(vappNetworkReferenceType.getName()); n.setProviderAssignedId(vappNetworkReferenceType.getHref()); n.setState(Network.State.STARTED); // Mapping Rule /* If the vAppNetwork is not isolated and its name = the CIMI public network configuration parameter * then the CIMI network is set to PUBLIC else to PRIVATE */ /* Applying this rule with a vApp created outside Sirocco might not work properly ! * A workaround in this case is to use the OrgVdcNetwork to which the vAppNetwork is connected */ /*if (!vappNetwork.getResource().getConfiguration().getFenceMode().equals(FenceModeValuesType.ISOLATED.value()) && vappNetworkReferenceType.getName().equals(this.vCloudContext.getCimiPublicOrgVdcNetworkName())) { n.setNetworkType(Network.Type.PUBLIC); } else {//from www . j a va 2s. c om n.setNetworkType(Network.Type.PRIVATE); }*/ // subnet List<Subnet> subnets = new ArrayList<Subnet>(); n.setSubnets(subnets); /*SubnetUtils utils = new SubnetUtils(vappNetwork.getResource().getConfiguration().getIpScope().getGateway(), vappNetwork .getResource().getConfiguration().getIpScope().getNetmask());*/ SubnetUtils utils = new SubnetUtils( vappNetwork.getResource().getConfiguration().getIpScopes().getIpScope().get(0).getGateway(), vappNetwork.getResource().getConfiguration().getIpScopes().getIpScope().get(0).getNetmask()); utils = new SubnetUtils(utils.getInfo().getNetworkAddress(), utils.getInfo().getNetmask()); utils.setInclusiveHostCount(false); SubnetInfo info = utils.getInfo(); Subnet subnet = new Subnet(); subnet.setCidr(info.getCidrSignature()); // subnet.setName(????); // subnet.setEnableDhcp(???); // subnet.setProviderAssignedId(???); subnet.setState(Subnet.State.AVAILABLE); subnet.setProtocol("IPv4"); subnets.add(subnet); }
From source file:org.ow2.sirocco.cloudmanager.connector.vcd.VcdCloudProvider.java
private void fromOrgVdcNetworkToNetwork(final OrgVdcNetwork orgVdcNetwork, final Network n) { ReferenceType orgVdcNetworkReferenceType = orgVdcNetwork.getReference(); n.setName(orgVdcNetworkReferenceType.getName()); n.setProviderAssignedId(orgVdcNetworkReferenceType.getHref()); n.setState(Network.State.STARTED); // Mapping Rule /* If the orgVdcNetwork name = the CIMI public network configuration parameter * then the CIMI network is set to PUBLIC else to PRIVATE */ /*if (orgVdcNetworkReferenceType.getName().equals(this.vCloudContext.getCimiPublicOrgVdcNetworkName())) { n.setNetworkType(Network.Type.PUBLIC); } else {// w w w . ja v a 2 s . co m n.setNetworkType(Network.Type.PRIVATE); }*/ // subnet List<Subnet> subnets = new ArrayList<Subnet>(); n.setSubnets(subnets); /*SubnetUtils utils = new SubnetUtils(orgVdcNetwork.getResource().getConfiguration().getIpScope().getGateway(), orgVdcNetwork .getResource().getConfiguration().getIpScope().getNetmask());*/ SubnetUtils utils = new SubnetUtils( orgVdcNetwork.getResource().getConfiguration().getIpScopes().getIpScope().get(0).getGateway(), orgVdcNetwork.getResource().getConfiguration().getIpScopes().getIpScope().get(0).getNetmask()); utils = new SubnetUtils(utils.getInfo().getNetworkAddress(), utils.getInfo().getNetmask()); utils.setInclusiveHostCount(false); SubnetInfo info = utils.getInfo(); Subnet subnet = new Subnet(); subnet.setCidr(info.getCidrSignature()); // subnet.setName(????); // subnet.setEnableDhcp(???); // subnet.setProviderAssignedId(???); subnet.setState(Subnet.State.AVAILABLE); subnet.setProtocol("IPv4"); subnets.add(subnet); }
From source file:org.ow2.sirocco.cloudmanager.connector.vcd.VcdCloudProvider.java
VAppNetworkConfigurationType createIsolatedVAppNetworkConfigurationType(final String networkName, final NetworkConfiguration networkConfiguration) throws ConnectorException { VAppNetworkConfigurationType private_vAppNetworkConfigurationType = new VAppNetworkConfigurationType(); NetworkConfigurationType private_networkConfigurationType = new NetworkConfigurationType(); VcdCloudProvider.logger.info("vAppNetworkConfiguration Isolated:" + networkName); private_vAppNetworkConfigurationType.setNetworkName(networkName); // private_networkConfigurationType.setParentNetwork(vdc.getAvailableNetworkRefByName(this.cimiPublicOrgVdcNetworkName)); private_networkConfigurationType.setFenceMode(FenceModeValuesType.ISOLATED.value()); private_networkConfigurationType.setRetainNetInfoAcrossDeployments(true); // Configure Internal IP Settings if (networkConfiguration.getSubnets().size() != 1) { throw new ConnectorException( "validation error on field 'networkConfiguration.subnets.size': should be equal to 1"); }//from w ww .j av a2 s.co m SubnetUtils utils = new SubnetUtils(networkConfiguration.getSubnets().get(0).getCidr()); utils.setInclusiveHostCount(false); SubnetInfo info = utils.getInfo(); if (info.getAddressCount() < 2) { /* gateway @ + IP range @ >= 2 */ throw new ConnectorException("no usable addresses"); } IpScopeType ipScope = new IpScopeType(); /*ipScope.setNetmask("255.255.255.0"); ipScope.setGateway("192.168.2.1");*/ ipScope.setNetmask(info.getNetmask()); ipScope.setGateway(info.getLowAddress()); ipScope.setIsEnabled(true); ipScope.setIsInherited(false); // ??? IpRangesType ipRangesType = new IpRangesType(); IpRangeType ipRangeType = new IpRangeType(); /*ipRangeType.setStartAddress("192.168.2.100"); ipRangeType.setEndAddress("192.168.2.199");*/ ipRangeType.setStartAddress(info.getAllAddresses()[1]); ipRangeType.setEndAddress(info.getHighAddress()); ipRangesType.getIpRange().add(ipRangeType); ipScope.setIpRanges(ipRangesType); ipScope.setIsEnabled(true); IpScopesType ipScopes = new IpScopesType(); ipScopes.getIpScope().add(ipScope); private_networkConfigurationType.setIpScopes(ipScopes); private_vAppNetworkConfigurationType.setConfiguration(private_networkConfigurationType); return private_vAppNetworkConfigurationType; }
From source file:org.restcomm.sbc.chain.impl.NATHelperProcessor.java
private boolean isRoutedAddress(String ipAddress) { List<String> localNetworks = ConfigurationCache.getLocalNetworks(); for (String localNetwork : localNetworks) { if (LOG.isTraceEnabled()) { LOG.trace("Traversing localNetworks " + localNetwork); }//from ww w. j ava 2s.c o m SubnetUtils utils = new SubnetUtils(localNetwork); if (utils.getInfo().isInRange(ipAddress)) { if (LOG.isTraceEnabled()) { LOG.trace("ipAddress " + ipAddress + " Is in network " + localNetwork); } return true; } if (LOG.isTraceEnabled()) { LOG.trace("ipAddress " + ipAddress + " Is NOT in network " + localNetwork); } } return false; }
From source file:org.rm3l.ddwrt.tiles.status.lan.DHCPStatusTile.java
@Nullable @Override/*ww w.j a va2s . com*/ protected Loader<NVRAMInfo> getLoader(int id, Bundle args) { return new AsyncTaskLoader<NVRAMInfo>(this.mParentFragmentActivity) { @Nullable @Override public NVRAMInfo loadInBackground() { try { Log.d(LOG_TAG, "Init background loader for " + DHCPStatusTile.class + ": routerInfo=" + mRouter + " / this.mAutoRefreshToggle= " + mAutoRefreshToggle + " / nbRunsLoader=" + nbRunsLoader); if (nbRunsLoader > 0 && !mAutoRefreshToggle) { //Skip run Log.d(LOG_TAG, "Skip loader run"); return new NVRAMInfo().setException(new DDWRTTileAutoRefreshNotAllowedException()); } nbRunsLoader++; @Nullable final NVRAMInfo nvramInfo = new NVRAMInfo(); NVRAMInfo nvramInfoTmp = null; try { nvramInfoTmp = SSHUtils.getNVRamInfoFromRouter(mRouter, mGlobalPreferences, NVRAMInfo.LAN_PROTO, NVRAMInfo.DHCP_DNSMASQ, NVRAMInfo.DHCP_START, NVRAMInfo.DHCP_NUM, NVRAMInfo.DHCP_LEASE, NVRAMInfo.LAN_IPADDR, NVRAMInfo.LAN_NETMASK); } finally { if (nvramInfoTmp != null) { nvramInfo.putAll(nvramInfoTmp); } //Manually compute Start and End IP Addresses final String lanAddr = nvramInfo.getProperty(NVRAMInfo.LAN_IPADDR); final String dhcpStart = nvramInfo.getProperty(NVRAMInfo.DHCP_START); String dhcpStartIp = null; if (dhcpStart != null && lanAddr != null) { final List<String> lowAddressSplit = IP_ADDR_SPLITTER.splitToList(lanAddr); if (lowAddressSplit != null && lowAddressSplit.size() >= 3) { dhcpStartIp = String.format("%s.%s.%s.%s", lowAddressSplit.get(0), lowAddressSplit.get(1), lowAddressSplit.get(2), dhcpStart); nvramInfo.setProperty(DHCP_START_IP, dhcpStartIp); } } final String dhcpHostCountStr = nvramInfo.getProperty(NVRAMInfo.DHCP_NUM); final String netmask = nvramInfo.getProperty(NVRAMInfo.LAN_NETMASK); if (netmask != null) { if (dhcpStartIp != null) { final SubnetUtils subnetUtils = new SubnetUtils(dhcpStartIp, netmask); final SubnetUtils.SubnetInfo subnetInfo = subnetUtils.getInfo(); if (dhcpHostCountStr != null) { try { final int dhcpHostCount = Integer.parseInt(dhcpHostCountStr); final String[] allAddresses = subnetInfo.getAllAddresses(); //Compute number of hosts between low ip and dhcp_start ip if (allAddresses != null) { int distFromLowIpToStartIp = 0; for (String address : allAddresses) { if (address.equals(dhcpStartIp)) { break; } distFromLowIpToStartIp++; } //Then get end address, starting from DHCP Start IP if (allAddresses.length >= distFromLowIpToStartIp + dhcpHostCount) { nvramInfo.setProperty(DHCP_END_IP, allAddresses[distFromLowIpToStartIp + dhcpHostCount - 1]); } } } catch (final NumberFormatException nfe) { //No worries nfe.printStackTrace(); } } } } } if (nvramInfo.isEmpty()) { throw new DDWRTNoDataException("No Data!"); } return nvramInfo; } catch (@NotNull final Exception e) { e.printStackTrace(); return new NVRAMInfo().setException(e); } } }; }
From source file:org.springframework.data.hadoop.util.net.DefaultHostInfoDiscovery.java
private boolean matchIpv4(String addressMatch, String address) { // TODO: should we fork utils from jakarta commons? SubnetUtils subnetUtils = new SubnetUtils(addressMatch); SubnetInfo info = subnetUtils.getInfo(); return info.isInRange(address); }
From source file:org.wikimedia.analytics.kraken.pageview.CidrFilter.java
/** * * @param ipAddress string that needs to be checked whether it falls in a given CIDR range. * @return true if ipAddress is within one of the specified CIDR ranges otherwise return false. *///w w w. ja v a 2 s . c om public final boolean ipAddressFallsInRange(final String ipAddress) { if (isIp4Address(ipAddress)) { for (SubnetUtils subnet : subnets) { if (subnet.getInfo().isInRange(ipAddress)) { return true; } } return false; } else { //TODO: IPv6 Range checking is not yet implemented return false; } }
From source file:org.xdi.oxauth.service.external.context.ExternalScriptContext.java
public boolean isInNetwork(String cidrNotation) { final String ip = getIpAddress(); if (Util.allNotBlank(ip, cidrNotation)) { final SubnetUtils utils = new SubnetUtils(cidrNotation); return utils.getInfo().isInRange(ip); }/*from w w w . ja v a2 s.c o m*/ return false; }