List of usage examples for org.apache.commons.net.util SubnetUtils getInfo
public final SubnetInfo getInfo()
From source file:org.hkfree.topoagent.module.protocol.NetBIOSScheduleCrate.java
@Override public void execute(final JobExecutionContext jec) throws JobExecutionException, ConcurrentModificationException { Core core = (Core) jec.getJobDetail().getJobDataMap().get("core"); Probe probe = (Probe) jec.getJobDetail().getJobDataMap().get("probe"); byte[] mask = core.getNetworkManager().getActiveDeviceNetmaskAsByte(); SubnetUtils su = new SubnetUtils(core.getNetworkManager().getActiveDeviceIPasString(), FormatUtils.ip(mask));// w w w . j a v a 2s. c o m SubnetInfo info = su.getInfo(); for (String ip : info.getAllAddresses()) { ((NetBIOSProbeService) probe.getProbeService()).GetNetBIOSName(ip); } }
From source file:org.inria.myriads.snoozenode.database.api.impl.memory.GroupLeaderMemoryRepository.java
/** * Generates the address pool./*from w ww . j a v a 2 s. c o m*/ * * @param virtualMachineSubnets The virtual machine subnet * @return The list of IP addresses */ protected List<String> generateAddressPool(String[] virtualMachineSubnets) { log_.debug("Generating address pool"); List<String> addressPool = new ArrayList<String>(); for (String virtualMachineSubnet : virtualMachineSubnets) { if (!virtualMachineSubnet.equals("")) { SubnetUtils subnetUtils = new SubnetUtils(virtualMachineSubnet); SubnetInfo subnetInfo = subnetUtils.getInfo(); addressPool.addAll(Arrays.asList(subnetInfo.getAllAddresses())); } } return addressPool; }
From source file:org.openbaton.clients.interfaces.client.openstack.OpenstackClient.java
private static String translateToNAT(String floatingIp) throws UnknownHostException { Properties natRules = new Properties(); try {// www .j a va2 s.co m File file = new File("/etc/openbaton/plugin/openstack/nat-translation-rules.properties"); if (file.exists()) { natRules.load(new FileInputStream(file)); } else { natRules.load(OpenstackClient.class.getResourceAsStream("/nat-translation-rules.properties")); } } catch (IOException e) { log.warn("no translation rules!"); return floatingIp; } for (Map.Entry<Object, Object> entry : natRules.entrySet()) { String fromCidr = (String) entry.getKey(); String toCidr = (String) entry.getValue(); log.debug("cidr is: " + fromCidr); SubnetUtils utilsFrom = new SubnetUtils(fromCidr); SubnetUtils utilsTo = new SubnetUtils(toCidr); SubnetUtils.SubnetInfo subnetInfoFrom = utilsFrom.getInfo(); SubnetUtils.SubnetInfo subnetInfoTo = utilsTo.getInfo(); InetAddress floatingIpNetAddr = InetAddress.getByName(floatingIp); if (subnetInfoFrom.isInRange(floatingIp)) { //translation! log.debug("From networkMask " + subnetInfoFrom.getNetmask()); log.debug("To networkMask " + subnetInfoTo.getNetmask()); if (!subnetInfoFrom.getNetmask().equals(subnetInfoTo.getNetmask())) { log.error("Not translation possible, netmasks are different"); return floatingIp; } byte[] host = new byte[4]; for (int i = 0; i < floatingIpNetAddr.getAddress().length; i++) { byte value = (byte) (floatingIpNetAddr.getAddress()[i] | InetAddress.getByName(subnetInfoFrom.getNetmask()).getAddress()[i]); if (value == -1) { host[i] = 0; } else { host[i] = value; } } byte[] netaddress = InetAddress.getByName(subnetInfoTo.getNetworkAddress()).getAddress(); String[] result = new String[4]; for (int i = 0; i < netaddress.length; i++) { int intValue = new Byte((byte) (netaddress[i] | Byte.valueOf(host[i]))).intValue(); if (intValue < 0) { intValue = intValue & 0xFF; } result[i] = String.valueOf(intValue); } return StringUtils.join(result, "."); } } return floatingIp; }
From source file:org.openbmp.db_rest.resources.Orr.java
/** * Lookup the IGP metric for the prefix (e.g. next hop) passed * * @param prefix IP in print form (this is the next-hop) * @param igpMap IGP RIB map// w ww .j ava2 s . co m * * @return null if no match, otherwise the column def list that matches is returned */ List<DbColumnDef> getIgpPrefixMetric(String prefix, Map<String, List<DbColumnDef>> igpMap) { List<DbColumnDef> found_cols = null; System.out.println("Lookup IGP metric cost for prefix " + prefix); for (Map.Entry<String, List<DbColumnDef>> row : igpMap.entrySet()) { // Prefix,PrefixLen,LocalPref,ASPath_Count,Origin,MED,NH List<DbColumnDef> cols = row.getValue(); SubnetUtils subU = new SubnetUtils(cols.get(0).getValue() + '/' + cols.get(1).getValue()); subU.setInclusiveHostCount(true); if (subU.getInfo().isInRange(prefix)) { System.out.println(" Found matching prefix, metric is " + cols.get(6).getValue()); found_cols = cols; break; } } return found_cols; }
From source file:org.opendaylight.controller.networkconfig.neutron.NeutronSubnet.java
public boolean isValidCIDR() { try {// www . j av a2s. c om SubnetUtils util = new SubnetUtils(cidr); SubnetInfo info = util.getInfo(); if (!info.getNetworkAddress().equals(info.getAddress())) { return false; } } catch (Exception e) { return false; } return true; }
From source file:org.opendaylight.controller.networkconfig.neutron.NeutronSubnet.java
public boolean initDefaults() { if (enableDHCP == null) { enableDHCP = true;/*from www . j a v a 2 s . com*/ } if (ipVersion == null) { ipVersion = 4; } gatewayIPAssigned = false; dnsNameservers = new ArrayList<String>(); if (hostRoutes == null) { hostRoutes = new ArrayList<NeutronSubnet_HostRoute>(); } if (allocationPools == null) { allocationPools = new ArrayList<NeutronSubnet_IPAllocationPool>(); try { SubnetUtils util = new SubnetUtils(cidr); SubnetInfo info = util.getInfo(); if (gatewayIP == null || ("").equals(gatewayIP)) { gatewayIP = info.getLowAddress(); } if (allocationPools.size() < 1) { NeutronSubnet_IPAllocationPool source = new NeutronSubnet_IPAllocationPool(info.getLowAddress(), info.getHighAddress()); allocationPools = source.splitPool(gatewayIP); } } catch (Exception e) { return false; } } return true; }
From source file:org.opendaylight.controller.networkconfig.neutron.NeutronSubnet.java
public boolean isValidIP(String ipAddress) { try {/*from ww w . j a va 2 s . c o m*/ SubnetUtils util = new SubnetUtils(cidr); SubnetInfo info = util.getInfo(); return info.isInRange(ipAddress); } catch (Exception e) { return false; } }
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.pipeline.PipelineL3Routing.java
public void programRouterInterface(Long dpid, Long sourceSegId, Long destSegId, String macAddress, IpAddress address, int mask, boolean isWriteFlow) { String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid; MatchBuilder matchBuilder = new MatchBuilder(); NodeBuilder nodeBuilder = Openflow13Provider.createNodeBuilder(nodeName); FlowBuilder flowBuilder = new FlowBuilder(); // Instructions List Stores Individual Instructions InstructionsBuilder isb = new InstructionsBuilder(); List<Instruction> instructions = Lists.newArrayList(); InstructionBuilder ib = new InstructionBuilder(); ApplyActionsBuilder aab = new ApplyActionsBuilder(); ActionBuilder ab = new ActionBuilder(); List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = Lists .newArrayList();/* ww w . j a v a 2s . co m*/ OfMatchUtils.createTunnelIDMatch(matchBuilder, BigInteger.valueOf(sourceSegId.longValue())); SubnetUtils addressSubnetInfo = new SubnetUtils(address.getIpv4Address().getValue() + "/" + mask); final String prefixString = addressSubnetInfo.getInfo().getNetworkAddress() + "/" + mask; OfMatchUtils.createDstL3IPv4Match(matchBuilder, prefixString); String flowId = "Routing_" + sourceSegId + "_" + destSegId + "_" + prefixString; flowBuilder.setId(new FlowId(flowId)); FlowKey key = new FlowKey(new FlowId(flowId)); flowBuilder.setBarrier(true); flowBuilder.setTableId(this.getTable()); flowBuilder.setKey(key); flowBuilder.setPriority(BASE_ROUTING_PRIORITY + mask); flowBuilder.setFlowName(flowId); flowBuilder.setHardTimeout(0); flowBuilder.setIdleTimeout(0); flowBuilder.setMatch(matchBuilder.build()); if (isWriteFlow) { // Set source Mac address ab.setAction(OfActionUtils.setDlSrcAction(macAddress)); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // DecTTL ab.setAction(OfActionUtils.decNwTtlAction()); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // Set Destination Tunnel ID ab.setAction(OfActionUtils.setTunnelIdAction(BigInteger.valueOf(destSegId.longValue()))); ab.setOrder(actionList.size()); ab.setKey(new ActionKey(actionList.size())); actionList.add(ab.build()); // Create Apply Actions Instruction aab.setAction(actionList); ib.setInstruction(new ApplyActionsCaseBuilder().setApplyActions(aab.build()).build()); ib.setOrder(instructions.size()); ib.setKey(new InstructionKey(instructions.size())); instructions.add(ib.build()); // Goto Next Table ib = getMutablePipelineInstructionBuilder(); ib.setOrder(instructions.size()); ib.setKey(new InstructionKey(instructions.size())); instructions.add(ib.build()); flowBuilder.setInstructions(isb.setInstruction(instructions).build()); writeFlow(flowBuilder, nodeBuilder); } else { removeFlow(flowBuilder, nodeBuilder); } }
From source file:org.opendaylight.genius.itm.cli.TepCommandHelper.java
private boolean validateIPs(String ipAddress, String subnetMask, String gatewayIp) { SubnetUtils utils = new SubnetUtils(subnetMask); if (utils.getInfo().isInRange(ipAddress) && (gatewayIp == null || utils.getInfo().isInRange(gatewayIp))) { return true; } else {/*from w ww. j a v a 2 s . c o m*/ LOG.trace("InValid IP"); return false; } }
From source file:org.opendaylight.genius.itm.confighelpers.ItmExternalTunnelAddWorker.java
public static List<ListenableFuture<Void>> buildTunnelsToExternalEndPoint(DataBroker dataBroker, IdManagerService idManagerService, List<DPNTEPsInfo> cfgDpnList, IpAddress extIp, Class<? extends TunnelTypeBase> tunType) { List<ListenableFuture<Void>> futures = new ArrayList<>(); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); if (null != cfgDpnList) { for (DPNTEPsInfo teps : cfgDpnList) { // CHECK -- Assumption -- Only one End Point / Dpn for GRE/Vxlan Tunnels TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0); String interfaceName = firstEndPt.getInterfaceName(); String tunTypeStr = tunType.getName(); String trunkInterfaceName = ItmUtils.getTrunkInterfaceName(idManagerService, interfaceName, new String(firstEndPt.getIpAddress().getValue()), new String(extIp.getValue()), tunTypeStr); char[] subnetMaskArray = firstEndPt.getSubnetMask().getValue(); boolean useOfTunnel = ItmUtils.falseIfNull(firstEndPt.isOptionOfTunnel()); String subnetMaskStr = String.valueOf(subnetMaskArray); SubnetUtils utils = new SubnetUtils(subnetMaskStr); String dcGwyIpStr = String.valueOf(extIp.getValue()); IpAddress gatewayIpObj = new IpAddress("0.0.0.0".toCharArray()); IpAddress gwyIpAddress = utils.getInfo().isInRange(dcGwyIpStr) ? gatewayIpObj : firstEndPt.getGwIpAddress(); LOG.debug(//from w w w . j ava2s .c om " Creating Trunk Interface with parameters trunk I/f Name - {}, parent I/f name - {}," + " source IP - {}, DC Gateway IP - {} gateway IP - {}", trunkInterfaceName, interfaceName, firstEndPt.getIpAddress(), extIp, gwyIpAddress); Interface iface = ItmUtils.buildTunnelInterface(teps.getDPNID(), trunkInterfaceName, String.format("%s %s", ItmUtils.convertTunnelTypetoString(tunType), "Trunk Interface"), true, tunType, firstEndPt.getIpAddress(), extIp, gwyIpAddress, firstEndPt.getVLANID(), false, false, ITMConstants.DEFAULT_MONITOR_PROTOCOL, null, useOfTunnel); LOG.debug(" Trunk Interface builder - {} ", iface); InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(trunkInterfaceName); LOG.debug(" Trunk Interface Identifier - {} ", trunkIdentifier); LOG.trace(" Writing Trunk Interface to Config DS {}, {} ", trunkIdentifier, iface); transaction.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, iface, true); // update external_tunnel_list ds InstanceIdentifier<ExternalTunnel> path = InstanceIdentifier.create(ExternalTunnelList.class).child( ExternalTunnel.class, new ExternalTunnelKey(extIp.toString(), teps.getDPNID().toString(), tunType)); ExternalTunnel tnl = ItmUtils.buildExternalTunnel(teps.getDPNID().toString(), extIp.toString(), tunType, trunkInterfaceName); transaction.merge(LogicalDatastoreType.CONFIGURATION, path, tnl, true); } futures.add(transaction.submit()); } return futures; }