| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 333409a commit e894658
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,17 +28,17 @@ | |||
| 28 | 28 | ||
| 29 | 29 | import javax.naming.ConfigurationException; | |
| 30 | 30 | ||
| 31 | + import com.cloud.utils.StringUtils; | ||
| 32 | + import com.cloud.utils.net.NetUtils; | ||
| 33 | + import com.cloud.utils.script.OutputInterpreter; | ||
| 34 | + import com.google.common.base.Strings; | ||
| 31 | 35 | import org.apache.log4j.Logger; | |
| 32 | 36 | import org.libvirt.LibvirtException; | |
| 33 | 37 | ||
| 34 | - import com.google.common.base.Strings; | ||
| 35 | - | ||
| 36 | 38 | import com.cloud.agent.api.to.NicTO; | |
| 37 | 39 | import com.cloud.exception.InternalErrorException; | |
| 38 | 40 | import com.cloud.network.Networks; | |
| 39 | 41 | import com.cloud.utils.NumbersUtil; | |
| 40 | - import com.cloud.utils.net.NetUtils; | ||
| 41 | - import com.cloud.utils.script.OutputInterpreter; | ||
| 42 | 42 | import com.cloud.utils.script.Script; | |
| 43 | 43 | ||
| 44 | 44 | public class BridgeVifDriver extends VifDriverBase { | |
@@ -49,7 +49,7 @@ public class BridgeVifDriver extends VifDriverBase { | |||
| 49 | 49 | private final Object _vnetBridgeMonitor = new Object(); | |
| 50 | 50 | private String _modifyVlanPath; | |
| 51 | 51 | private String _modifyVxlanPath; | |
| 52 | - private String bridgeNameSchema; | ||
| 52 | + private String _controlCidr = NetUtils.getLinkLocalCIDR(); | ||
| 53 | 53 | private Long libvirtVersion; | |
| 54 | 54 | ||
| 55 | 55 | @Override | |
@@ -67,7 +67,10 @@ public void configure(Map<String, Object> params) throws ConfigurationException | |||
| 67 | 67 | networkScriptsDir = "scripts/vm/network/vnet"; | |
| 68 | 68 | } | |
| 69 | 69 | ||
| 70 | - bridgeNameSchema = (String)params.get("network.bridge.name.schema"); | ||
| 70 | + String controlCidr = (String)params.get("control.cidr"); | ||
| 71 | + if (StringUtils.isNotBlank(controlCidr)) { | ||
| 72 | + _controlCidr = controlCidr; | ||
| 73 | + } | ||
| 71 | 74 | ||
| 72 | 75 | String value = (String)params.get("scripts.timeout"); | |
| 73 | 76 | _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000; | |
@@ -384,7 +387,7 @@ private void deleteVnetBr(String brName) { | |||
| 384 | 387 | private void deleteExistingLinkLocalRouteTable(String linkLocalBr) { | |
| 385 | 388 | Script command = new Script("/bin/bash", _timeout); | |
| 386 | 389 | command.add("-c"); | |
| 387 | - command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); | ||
| 390 | + command.add("ip route | grep " + _controlCidr); | ||
| 388 | 391 | OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); | |
| 389 | 392 | String result = command.execute(parser); | |
| 390 | 393 | boolean foundLinkLocalBr = false; | |
@@ -397,15 +400,16 @@ private void deleteExistingLinkLocalRouteTable(String linkLocalBr) { | |||
| 397 | 400 | } | |
| 398 | 401 | final String device = tokens[2]; | |
| 399 | 402 | if (!Strings.isNullOrEmpty(device) && !device.equalsIgnoreCase(linkLocalBr)) { | |
| 400 | - Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR() + " dev " + tokens[2]); | ||
| 403 | + Script.runSimpleBashScript("ip route del " + _controlCidr + " dev " + tokens[2]); | ||
| 401 | 404 | } else { | |
| 402 | 405 | foundLinkLocalBr = true; | |
| 403 | 406 | } | |
| 404 | 407 | } | |
| 405 | 408 | } | |
| 409 | + | ||
| 406 | 410 | if (!foundLinkLocalBr) { | |
| 407 | - Script.runSimpleBashScript("ip address add 169.254.0.1/16 dev " + linkLocalBr + ";" + "ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + | ||
| 408 | - NetUtils.getLinkLocalGateway()); | ||
| 411 | + Script.runSimpleBashScript("ip address add " + NetUtils.getLinkLocalAddressFromCIDR(_controlCidr) + " dev " + linkLocalBr); | ||
| 412 | + Script.runSimpleBashScript("ip route add " + _controlCidr + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway(_controlCidr)); | ||
| 409 | 413 | } | |
| 410 | 414 | } | |
| 411 | 415 | ||
@@ -417,7 +421,9 @@ private void createControlNetwork() { | |||
| 417 | 421 | public void createControlNetwork(String privBrName) { | |
| 418 | 422 | deleteExistingLinkLocalRouteTable(privBrName); | |
| 419 | 423 | if (!isExistingBridge(privBrName)) { | |
| 420 | - Script.runSimpleBashScript("brctl addbr " + privBrName + "; ip link set " + privBrName + " up; ip address add 169.254.0.1/16 dev " + privBrName, _timeout); | ||
| 424 | + Script.runSimpleBashScript("ip link add name " + privBrName + " type bridge"); | ||
| 425 | + Script.runSimpleBashScript("ip link set " + privBrName + " up"); | ||
| 426 | + Script.runSimpleBashScript("ip address add " + NetUtils.getLinkLocalAddressFromCIDR(_controlCidr) + " dev " + privBrName); | ||
| 421 | 427 | } | |
| 422 | 428 | } | |
| 423 | 429 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,7 @@ | |||
| 26 | 26 | ||
| 27 | 27 | import javax.naming.ConfigurationException; | |
| 28 | 28 | ||
| 29 | + import com.cloud.utils.StringUtils; | ||
| 29 | 30 | import org.apache.log4j.Logger; | |
| 30 | 31 | import org.libvirt.LibvirtException; | |
| 31 | 32 | ||
@@ -46,7 +47,7 @@ public class IvsVifDriver extends VifDriverBase { | |||
| 46 | 47 | private String _modifyVlanPath; | |
| 47 | 48 | private String _modifyVxlanPath; | |
| 48 | 49 | private String _ivsIfUpPath; | |
| 49 | - private Long libvirtVersion; | ||
| 50 | + private String _controlCidr = NetUtils.getLinkLocalCIDR(); | ||
| 50 | 51 | ||
| 51 | 52 | @Override | |
| 52 | 53 | public void configure(Map<String, Object> params) throws ConfigurationException { | |
@@ -70,9 +71,9 @@ public void configure(Map<String, Object> params) throws ConfigurationException | |||
| 70 | 71 | } | |
| 71 | 72 | _ivsIfUpPath = Script.findScript(utilScriptsDir, "qemu-ivs-ifup"); | |
| 72 | 73 | ||
| 73 | - libvirtVersion = (Long) params.get("libvirtVersion"); | ||
| 74 | - if (libvirtVersion == null) { | ||
| 75 | - libvirtVersion = 0L; | ||
| 74 | + String controlCidr = (String)params.get("control.cidr"); | ||
| 75 | + if (StringUtils.isNotBlank(controlCidr)) { | ||
| 76 | + _controlCidr = controlCidr; | ||
| 76 | 77 | } | |
| 77 | 78 | } | |
| 78 | 79 | ||
@@ -256,7 +257,7 @@ private void deleteVnetBr(String brName) { | |||
| 256 | 257 | private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { | |
| 257 | 258 | Script command = new Script("/bin/bash", _timeout); | |
| 258 | 259 | command.add("-c"); | |
| 259 | - command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); | ||
| 260 | + command.add("ip route | grep " + _controlCidr); | ||
| 260 | 261 | OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); | |
| 261 | 262 | String result = command.execute(parser); | |
| 262 | 263 | boolean foundLinkLocalBr = false; | |
@@ -265,23 +266,24 @@ private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { | |||
| 265 | 266 | for (String line : lines) { | |
| 266 | 267 | String[] tokens = line.split(" "); | |
| 267 | 268 | if (!tokens[2].equalsIgnoreCase(linkLocalBr)) { | |
| 268 | - Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR()); | ||
| 269 | + Script.runSimpleBashScript("ip route del " + _controlCidr); | ||
| 269 | 270 | } else { | |
| 270 | 271 | foundLinkLocalBr = true; | |
| 271 | 272 | } | |
| 272 | 273 | } | |
| 273 | 274 | } | |
| 274 | 275 | if (!foundLinkLocalBr) { | |
| 275 | - Script.runSimpleBashScript("ip address add 169.254.0.1/16 dev " + linkLocalBr + ";" + "ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + | ||
| 276 | - NetUtils.getLinkLocalGateway()); | ||
| 276 | + Script.runSimpleBashScript("ip address add " + NetUtils.getLinkLocalAddressFromCIDR(_controlCidr) + " dev " + linkLocalBr); | ||
| 277 | + Script.runSimpleBashScript("ip route add " + _controlCidr + " dev " + linkLocalBr + " src " + NetUtils.getLinkLocalGateway(_controlCidr)); | ||
| 277 | 278 | } | |
| 278 | 279 | } | |
| 279 | 280 | ||
| 280 | 281 | @Override | |
| 281 | 282 | public void createControlNetwork(String privBrName) { | |
| 282 | 283 | deleteExitingLinkLocalRouteTable(privBrName); | |
| 283 | 284 | if (!isBridgeExists(privBrName)) { | |
| 284 | - Script.runSimpleBashScript("brctl addbr " + privBrName + "; ip link set " + privBrName + " up; ip address add 169.254.0.1/16 dev " + privBrName, _timeout); | ||
| 285 | + Script.runSimpleBashScript("brctl addbr " + privBrName + "; ip link set " + privBrName + " up"); | ||
| 286 | + Script.runSimpleBashScript("ip address add " + NetUtils.getLinkLocalAddressFromCIDR(_controlCidr) + " dev " + privBrName, _timeout); | ||
| 285 | 287 | } | |
| 286 | 288 | } | |
| 287 | 289 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ | |||
| 44 | 44 | public class OvsVifDriver extends VifDriverBase { | |
| 45 | 45 | private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class); | |
| 46 | 46 | private int _timeout; | |
| 47 | + private String _controlCidr = NetUtils.getLinkLocalCIDR(); | ||
| 47 | 48 | private DpdkDriver dpdkDriver; | |
| 48 | 49 | ||
| 49 | 50 | @Override | |
@@ -62,6 +63,11 @@ public void configure(Map<String, Object> params) throws ConfigurationException | |||
| 62 | 63 | dpdkDriver = new DpdkDriverImpl(); | |
| 63 | 64 | } | |
| 64 | 65 | ||
| 66 | + String controlCidr = (String)params.get("control.cidr"); | ||
| 67 | + if (com.cloud.utils.StringUtils.isNotBlank(controlCidr)) { | ||
| 68 | + _controlCidr = controlCidr; | ||
| 69 | + } | ||
| 70 | + | ||
| 65 | 71 | String value = (String)params.get("scripts.timeout"); | |
| 66 | 72 | _timeout = NumbersUtil.parseInt(value, 30 * 60) * 1000; | |
| 67 | 73 | } | |
@@ -213,7 +219,7 @@ public void detach(LibvirtVMDef.InterfaceDef iface) { | |||
| 213 | 219 | private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { | |
| 214 | 220 | Script command = new Script("/bin/bash", _timeout); | |
| 215 | 221 | command.add("-c"); | |
| 216 | - command.add("ip route | grep " + NetUtils.getLinkLocalCIDR()); | ||
| 222 | + command.add("ip route | grep " + _controlCidr); | ||
| 217 | 223 | OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); | |
| 218 | 224 | String result = command.execute(parser); | |
| 219 | 225 | boolean foundLinkLocalBr = false; | |
@@ -222,23 +228,23 @@ private void deleteExitingLinkLocalRouteTable(String linkLocalBr) { | |||
| 222 | 228 | for (String line : lines) { | |
| 223 | 229 | String[] tokens = line.split(" "); | |
| 224 | 230 | if (!tokens[2].equalsIgnoreCase(linkLocalBr)) { | |
| 225 | - Script.runSimpleBashScript("ip route del " + NetUtils.getLinkLocalCIDR()); | ||
| 231 | + Script.runSimpleBashScript("ip route del " + _controlCidr); | ||
| 226 | 232 | } else { | |
| 227 | 233 | foundLinkLocalBr = true; | |
| 228 | 234 | } | |
| 229 | 235 | } | |
| 230 | 236 | } | |
| 231 | 237 | if (!foundLinkLocalBr) { | |
| 232 | - Script.runSimpleBashScript("ip address add 169.254.0.1/16 dev " + linkLocalBr + ";" + "ip route add " + NetUtils.getLinkLocalCIDR() + " dev " + linkLocalBr + " src " + | ||
| 233 | - NetUtils.getLinkLocalGateway()); | ||
| 238 | + Script.runSimpleBashScript("ip address add " + NetUtils.getLinkLocalAddressFromCIDR(_controlCidr) + " dev " + linkLocalBr + ";" + "ip route add " + _controlCidr + " dev " + linkLocalBr + " src " + | ||
| 239 | + NetUtils.getLinkLocalGateway(_controlCidr)); | ||
| 234 | 240 | } | |
| 235 | 241 | } | |
| 236 | 242 | ||
| 237 | 243 | @Override | |
| 238 | 244 | public void createControlNetwork(String privBrName) { | |
| 239 | 245 | deleteExitingLinkLocalRouteTable(privBrName); | |
| 240 | 246 | if (!isExistingBridge(privBrName)) { | |
| 241 | - Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ip link set " + privBrName + " up; ip address add 169.254.0.1/16 dev " + privBrName, _timeout); | ||
| 247 | + Script.runSimpleBashScript("ovs-vsctl add-br " + privBrName + "; ip link set " + privBrName + " up; ip address add " + NetUtils.getLinkLocalAddressFromCIDR(_controlCidr) + " dev " + privBrName, _timeout); | ||
| 242 | 248 | } | |
| 243 | 249 | } | |
| 244 | 250 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1613,7 +1613,7 @@ public HostPodVO doInTransaction(final TransactionStatus status) { | |||
| 1613 | 1613 | _zoneDao.addPrivateIpAddress(zoneId, pod.getId(), startIp, endIpFinal, false, null); | |
| 1614 | 1614 | } | |
| 1615 | 1615 | ||
| 1616 | - final String[] linkLocalIpRanges = getLinkLocalIPRange(); | ||
| 1616 | + final String[] linkLocalIpRanges = NetUtils.getLinkLocalIPRange(_configDao.getValue(Config.ControlCidr.key())); | ||
| 1617 | 1617 | if (linkLocalIpRanges != null) { | |
| 1618 | 1618 | _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]); | |
| 1619 | 1619 | } | |
@@ -4489,20 +4489,6 @@ private String getZoneName(final long zoneId) { | |||
| 4489 | 4489 | } | |
| 4490 | 4490 | } | |
| 4491 | 4491 | ||
| 4492 | - private String[] getLinkLocalIPRange() { | ||
| 4493 | - final String ipNums = _configDao.getValue("linkLocalIp.nums"); | ||
| 4494 | - final int nums = Integer.parseInt(ipNums); | ||
| 4495 | - if (nums > 16 || nums <= 0) { | ||
| 4496 | - throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "is wrong, should be 1~16"); | ||
| 4497 | - } | ||
| 4498 | - /* local link ip address starts from 169.254.0.2 - 169.254.(nums) */ | ||
| 4499 | - final String[] ipRanges = NetUtils.getLinkLocalIPRange(nums); | ||
| 4500 | - if (ipRanges == null) { | ||
| 4501 | - throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "may be wrong, should be 1~16"); | ||
| 4502 | - } | ||
| 4503 | - return ipRanges; | ||
| 4504 | - } | ||
| 4505 | - | ||
| 4506 | 4492 | @Override | |
| 4507 | 4493 | @ActionEvent(eventType = EventTypes.EVENT_VLAN_IP_RANGE_DELETE, eventDescription = "deleting vlan ip range", async = false) | |
| 4508 | 4494 | public boolean deleteVlanIpRange(final DeleteVlanIpRangeCmd cmd) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -160,11 +160,16 @@ public void reserve(NicProfile nic, Network config, VirtualMachineProfile vm, De | |||
| 160 | 160 | if (ip == null) { | |
| 161 | 161 | throw new InsufficientAddressCapacityException("Insufficient link local address capacity", DataCenter.class, dest.getDataCenter().getId()); | |
| 162 | 162 | } | |
| 163 | + | ||
| 164 | + String netmask = NetUtils.cidr2Netmask(_cidr); | ||
| 165 | + | ||
| 166 | + s_logger.debug(String.format("Reserved NIC for %s [ipv4:%s netmask:%s gateway:%s]", vm.getInstanceName(), ip, netmask, _gateway)); | ||
| 167 | + | ||
| 163 | 168 | nic.setIPv4Address(ip); | |
| 164 | 169 | nic.setMacAddress(NetUtils.long2Mac(NetUtils.ip2Long(ip) | (14l << 40))); | |
| 165 | - nic.setIPv4Netmask("255.255.0.0"); | ||
| 170 | + nic.setIPv4Netmask(netmask); | ||
| 166 | 171 | nic.setFormat(AddressFormat.Ip4); | |
| 167 | - nic.setIPv4Gateway(NetUtils.getLinkLocalGateway()); | ||
| 172 | + nic.setIPv4Gateway(_gateway); | ||
| 168 | 173 | } | |
| 169 | 174 | ||
| 170 | 175 | @Override | |
@@ -223,7 +228,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu | |||
| 223 | 228 | ||
| 224 | 229 | _cidr = dbParams.get(Config.ControlCidr.toString()); | |
| 225 | 230 | if (_cidr == null) { | |
| 226 | - _cidr = "169.254.0.0/16"; | ||
| 231 | + _cidr = NetUtils.getLinkLocalCIDR(); | ||
| 227 | 232 | } | |
| 228 | 233 | ||
| 229 | 234 | _gateway = dbParams.get(Config.ControlGateway.toString()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -904,12 +904,8 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws Intern | |||
| 904 | 904 | throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "is wrong, should be 1~16"); | |
| 905 | 905 | } | |
| 906 | 906 | /* local link ip address starts from 169.254.0.2 - 169.254.(nums) */ | |
| 907 | - String[] linkLocalIpRanges = NetUtils.getLinkLocalIPRange(nums); | ||
| 908 | - if (linkLocalIpRanges == null) { | ||
| 909 | - throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "may be wrong, should be 1~16"); | ||
| 910 | - } else { | ||
| 911 | - _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]); | ||
| 912 | - } | ||
| 907 | + String[] linkLocalIpRanges = NetUtils.getLinkLocalIPRange(_configDao.getValue(Config.ControlCidr.key())); | ||
| 908 | + _zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]); | ||
| 913 | 909 | } | |
| 914 | 910 | }); | |
| 915 | 911 | } catch (Exception e) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -436,7 +436,7 @@ public List<String> saveIPRange(String type, long podId, long zoneId, long vlanD | |||
| 436 | 436 | problemIPs = savePrivateIPRange(txn, startIPLong, endIPLong, podId, zoneId); | |
| 437 | 437 | } | |
| 438 | 438 | ||
| 439 | - String[] linkLocalIps = NetUtils.getLinkLocalIPRange(10); | ||
| 439 | + String[] linkLocalIps = NetUtils.getLinkLocalIPRange("169.254.0.0/16"); | ||
| 440 | 440 | long startLinkLocalIp = NetUtils.ip2Long(linkLocalIps[0]); | |
| 441 | 441 | long endLinkLocalIp = NetUtils.ip2Long(linkLocalIps[1]); | |
| 442 | 442 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -961,27 +961,34 @@ public static String getLinkLocalNetMask() { | |||
| 961 | 961 | return "255.255.0.0"; | |
| 962 | 962 | } | |
| 963 | 963 | ||
| 964 | + public static String getLinkLocalGateway(String cidr) { | ||
| 965 | + return getLinkLocalFirstAddressFromCIDR(cidr); | ||
| 966 | + } | ||
| 967 | + | ||
| 964 | 968 | public static String getLinkLocalGateway() { | |
| 965 | - return "169.254.0.1"; | ||
| 969 | + return getLinkLocalGateway(getLinkLocalCIDR()); | ||
| 966 | 970 | } | |
| 967 | 971 | ||
| 968 | 972 | public static String getLinkLocalCIDR() { | |
| 969 | 973 | return "169.254.0.0/16"; | |
| 970 | 974 | } | |
| 971 | 975 | ||
| 972 | - public static String[] getLinkLocalIPRange(final int size) { | ||
| 973 | - if (size > 16 || size <= 0) { | ||
| 974 | - return null; | ||
| 975 | - } | ||
| 976 | - /* reserve gateway */ | ||
| 977 | - final String[] range = getIpRangeFromCidr(getLinkLocalGateway(), MAX_CIDR - size); | ||
| 976 | + public static String getLinkLocalFirstAddressFromCIDR(final String cidr) { | ||
| 977 | + SubnetUtils subnetUtils = new SubnetUtils(cidr); | ||
| 978 | + return subnetUtils.getInfo().getLowAddress(); | ||
| 979 | + } | ||
| 980 | + | ||
| 981 | + public static String getLinkLocalAddressFromCIDR(final String cidr) { | ||
| 982 | + return getLinkLocalFirstAddressFromCIDR(cidr) + "/" + cidr2Netmask(cidr); | ||
| 983 | + } | ||
| 984 | + | ||
| 985 | + public static String[] getLinkLocalIPRange(final String cidr) { | ||
| 986 | + final SubnetUtils subnetUtils = new SubnetUtils(cidr); | ||
| 987 | + final String[] addresses = subnetUtils.getInfo().getAllAddresses(); | ||
| 988 | + final String[] range = new String[2]; | ||
| 989 | + range[0] = addresses[1]; | ||
| 990 | + range[1] = subnetUtils.getInfo().getHighAddress(); | ||
| 978 | 991 | ||
| 979 | - if (range[0].equalsIgnoreCase(getLinkLocalGateway())) { | ||
| 980 | - /* remove the gateway */ | ||
| 981 | - long ip = ip2Long(range[0]); | ||
| 982 | - ip += 1; | ||
| 983 | - range[0] = long2Ip(ip); | ||
| 984 | - } | ||
| 985 | 992 | return range; | |
| 986 | 993 | } | |
| 987 | 994 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -709,4 +709,26 @@ public void testIsIPv6EUI64() { | |||
| 709 | 709 | assertFalse(NetUtils.isIPv6EUI64("2001:db8::100:1")); | |
| 710 | 710 | assertFalse(NetUtils.isIPv6EUI64("2a01:4f9:2a:185f::2")); | |
| 711 | 711 | } | |
| 712 | + | ||
| 713 | + @Test | ||
| 714 | + public void testLinkLocal() { | ||
| 715 | + final String cidr = NetUtils.getLinkLocalCIDR(); | ||
| 716 | + assertEquals("255.255.0.0", NetUtils.getLinkLocalNetMask()); | ||
| 717 | + assertEquals("169.254.0.1", NetUtils.getLinkLocalGateway()); | ||
| 718 | + assertEquals("169.254.0.0/16", cidr); | ||
| 719 | + assertEquals("169.254.0.1", NetUtils.getLinkLocalFirstAddressFromCIDR(cidr)); | ||
| 720 | + assertEquals("169.254.0.1/255.255.0.0", NetUtils.getLinkLocalAddressFromCIDR(cidr)); | ||
| 721 | + assertEquals("169.254.240.1/255.255.240.0", NetUtils.getLinkLocalAddressFromCIDR("169.254.240.0/20")); | ||
| 722 | + | ||
| 723 | + String[] range = NetUtils.getLinkLocalIPRange("169.254.0.0/16"); | ||
| 724 | + assertEquals("169.254.0.2", range[0]); | ||
| 725 | + assertEquals("169.254.255.254", range[1]); | ||
| 726 | + } | ||
| 727 | + | ||
| 728 | + @Test | ||
| 729 | + public void testCidrNetmask() { | ||
| 730 | + assertEquals("255.255.255.0", NetUtils.cidr2Netmask("192.168.0.0/24")); | ||
| 731 | + assertEquals("255.255.0.0", NetUtils.cidr2Netmask("169.254.0.0/16")); | ||
| 732 | + assertEquals("255.255.240.0", NetUtils.cidr2Netmask("169.254.240.0/20")); | ||
| 733 | + } | ||
| 712 | 734 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments