private static RandomAccessFile randomAccessFile;
private static boolean isMac = false;
private static boolean isWin = false;
+ private static boolean isWin8 = false;
private static boolean isLinux = false;
static {
isLinux = true;
} else if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) {
isWin = true;
+ if (System.getProperty("os.name").startsWith("Windows 8")) {
+ isWin8 = true;
+ }
} else if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
isMac = true;
}
return isWin;
}
+ public static boolean isWin8() {
+ return isWin8;
+ }
+
public static boolean isLinux() {
return isLinux;
}
/* Emulator Manager
*
- * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2011 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
* Minkee Lee <minkee.lee@samsung.com>
* SeokYeon Hwang <syeon.hwang@samsung.com>
* Sangho Park <sangho1206.park@samsung.com>
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
public class TapUtil {
-
- public static String getBridgeFromDevice(String device) throws VMWorkerException {
+ private static String devconPath = FilePathResources.getBinPath() + File.separator + "devcon.exe";
+ public static String getBridgeFromDevice(String device)
+ throws VMWorkerException {
String result = null;
if (EmulatorManager.isLinux()) {
return result;
}
- public static List<String> getDefaultGateway(String ifName) throws VMWorkerException {
+ public static List<String> getDefaultGateway(String ifName)
+ throws VMWorkerException {
List<String> result = new ArrayList<String>();
if (EmulatorManager.isLinux()) {
} else {
if (arr.length >= 5) {
- if (arr[0].equals("default") && arr[4].equals(ifName)) {
+ if (arr[0].equals("default")
+ && arr[4].equals(ifName)) {
result.add(arr[2]);
}
}
}
- public static List<String> getTapList() {
- List<String> list = new ArrayList<String>();
+ public static ArrayList<String> getTapList() {
+ ArrayList<String> list = new ArrayList<String>();
// Get tap device list from Host OS.
if (EmulatorManager.isLinux()) {
return list;
}
- private static List<String> getTapListForMac() {
- List<String> result = new ArrayList<String>();
+ private static ArrayList<String> getTapListForMac() {
+ ArrayList<String> result = new ArrayList<String>();
result.add("auto");
return result;
}
List<String> cmd = Arrays.asList("ip", "tuntap");
ProcessResult res = HelperClass.runProcess(cmd);
if (res.isSuccess() == false) {
- EMLogger.getLogger().warning("Get tap list fail. Command returns fail:" + "cmd : " + cmd.toString() + ", return : " + res.getExitValue());
+ EMLogger.getLogger().warning(
+ "Get tap list fail. Command returns fail:" + "cmd : "
+ + cmd.toString() + ", return : "
+ + res.getExitValue());
} else {
for (String line : res.getStdOutMsg()) {
String arr[] = line.split(":");
private static List<String> getTapListForWin() {
List<String> result = new ArrayList<String>();
List<String> cmd = new ArrayList<String>();
- ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn", "--show-adapters" });
+ ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn",
+ "--show-adapters" });
int exitValue = 0;
Process process;
try {
process = pb.start();
- List<String> stdOut = ProcessOutputReader.readStdOut(process, cmd.toString());
+ List<String> stdOut = ProcessOutputReader.readStdOut(process,
+ cmd.toString());
exitValue = process.waitFor();
if (exitValue != 0) {
- EMLogger.getLogger().warning("Get tap list fail. Command returns fail:" + "cmd : " + cmd.toString() + ", return : " + exitValue);
+ EMLogger.getLogger().warning(
+ "Get tap list fail. Command returns fail:" + "cmd : "
+ + cmd.toString() + ", return : " + exitValue);
} else {
for (String line : stdOut) {
if (line.contains("'")) {
}
} catch (IOException e) {
- EMLogger.getLogger().warning("Get tap list fail. " + e.getMessage());
+ EMLogger.getLogger()
+ .warning("Get tap list fail. " + e.getMessage());
e.printStackTrace();
} catch (InterruptedException e) {
- EMLogger.getLogger().warning("Get tap list fail. " + e.getMessage());
+ EMLogger.getLogger()
+ .warning("Get tap list fail. " + e.getMessage());
e.printStackTrace();
}
return result;
}
- private static List<String> getTapListForWin2() {
- List<String> tapNameList = new ArrayList<String>();
- List<String> tapIdList = getTapIdList();
+ private static ArrayList<String> getTapListForWin2() {
+ ArrayList<String> tapNameList = new ArrayList<String>();
+ ArrayList<String> tapIdList = getTapIdList();
HKEY root = WinReg.HKEY_LOCAL_MACHINE;
String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
String key = "Connection";
for (String subKey : subKeys) {
for (String tapId : tapIdList) {
if (subKey.equals(tapId)) {
- String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey);
+ String[] subKeys2 = Advapi32Util.registryGetKeys(root,
+ topKey + "\\" + subKey);
for (String subKey2 : subKeys2) {
if (subKey2.equals(key)) {
- String tapName = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value);
+ String tapName = Advapi32Util
+ .registryGetStringValue(root, topKey
+ + "\\" + subKey + "\\" + key,
+ value);
if (tapName != null) {
- EMLogger.getLogger().warning("tapname added: " + tapName);
+ EMLogger.getLogger().warning(
+ "tapname added: " + tapName);
tapNameList.add(tapName);
}
}
}
} catch (Win32Exception e) {
-
+ EMLogger.getLogger().info(e.getMessage());
} finally {
if (regKey != null) {
Advapi32Util.registryCloseKey(regKey.getValue());
return tapNameList;
}
- private static List<String> getTapIdList() {
+ private static ArrayList<String> getTapIdList() {
- List<String> tapIdList = new ArrayList<String>();
+ ArrayList<String> tapIdList = new ArrayList<String>();
HKEY root = WinReg.HKEY_LOCAL_MACHINE;
String topKey = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
for (String subKey : subKeys) {
- String compId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value1);
- String tapId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value2);
+ String compId = Advapi32Util.registryGetStringValue(root,
+ topKey + "\\" + subKey, value1);
+ String tapId = Advapi32Util.registryGetStringValue(root, topKey
+ + "\\" + subKey, value2);
if (compId != null && tapId != null) {
if (compId.startsWith("tap")) {
tapIdList.add(tapId);
}
} catch (Win32Exception e) {
-
+ EMLogger.getLogger().info(e.getMessage());
} finally {
if (regKey != null) {
Advapi32Util.registryCloseKey(regKey.getValue());
String value = "Name";
HKEYByReference regKey = null;
try {
- regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
- String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ regKey = Advapi32Util.registryGetKey(root, topKey,
+ WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey
+ .getValue());
for (String subKey : subKeys) {
for (String tapId : tapIdList) {
if (subKey.equals(tapId)) {
- String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey);
+ String[] subKeys2 = Advapi32Util.registryGetKeys(
+ root, topKey + "\\" + subKey);
for (String subKey2 : subKeys2) {
if (subKey2.equals(key)) {
- String name = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value);
+ String name = Advapi32Util
+ .registryGetStringValue(root,
+ topKey + "\\" + subKey
+ + "\\" + key, value);
if (name != null) {
if (name.equals(tapName)) {
foundTapId = tapId;
}
}
EMLogger.getLogger().warning("found tapid: " + foundTapId);
- if (System.getProperty("os.name").startsWith("Windows 8")) {
+ if (EmulatorManager.isWin8()) {
topKey = "SYSTEM\\CurrentControlSet\\services\\NdisImPlatform\\Linkage";
} else {
topKey = "SYSTEM\\CurrentControlSet\\services\\Bridge\\Linkage";
}
value = "Route";
- String valueArr[] = Advapi32Util.registryGetStringArray(root, topKey, value);
+ String valueArr[] = Advapi32Util.registryGetStringArray(root,
+ topKey, value);
for (String str : valueArr) {
if (str.replace("\"", "").equals(foundTapId)) {
result = true;
}
} catch (Win32Exception e) {
- EMLogger.getLogger().warning("Failed to check if tap exists in bridge or not" + e.getMessage());
+ EMLogger.getLogger().warning(
+ "Failed to check if tap exists in bridge or not"
+ + e.getMessage());
} finally {
if (regKey != null) {
Advapi32Util.registryCloseKey(regKey.getValue());
HKEY key = getBridgeTcpipKey();
if (key != null) {
try {
- String data[] = Advapi32Util.registryGetStringArray(key, "SubnetMask");
+ String data[] = Advapi32Util.registryGetStringArray(key,
+ "SubnetMask");
if (data.length > 0) {
netMask = data[0];
}
key = getInterfaceTcpipKey(getBridgeId());
if (key != null) {
try {
- String data[] = Advapi32Util.registryGetStringArray(key, "SubnetMask");
+ String data[] = Advapi32Util.registryGetStringArray(
+ key, "SubnetMask");
if (data.length > 0) {
netMask = data[0];
}
}
}
} else if (EmulatorManager.isMac()) {
- List<String> cmd = Arrays.asList("/bin/sh", "-c", "ifconfig en0 | grep \"inet \" | awk '{print $4}'");
+ List<String> cmd = Arrays.asList("/bin/sh", "-c",
+ "ifconfig en0 | grep \"inet \" | awk '{print $4}'");
ProcessResult res = HelperClass.runProcess(cmd);
boolean isCommandSuccess = false;
if (res.isSuccess()) {
}
if (netMask.length() == 0) {
isCommandSuccess = false;
- cmd = Arrays.asList("/bin/sh", "-c", "ifconfig bridge1 | grep \"inet \" | awk '{print $4}'");
+ cmd = Arrays
+ .asList("/bin/sh", "-c",
+ "ifconfig bridge1 | grep \"inet \" | awk '{print $4}'");
res = HelperClass.runProcess(cmd);
if (res.isSuccess()) {
for (String str : res.getStdOutMsg()) {
isCommandSuccess = true;
- long ipAddress = Long.parseLong(str.substring(2), 16);
+ long ipAddress = Long.parseLong(str.substring(2),
+ 16);
netMask = longToIpAddress(ipAddress);
- EMLogger.getLogger().info("netmask bridge1: " + netMask);
+ EMLogger.getLogger().info(
+ "netmask bridge1: " + netMask);
}
}
}
}
HKEY root = WinReg.HKEY_LOCAL_MACHINE;
- String topKey = "SYSTEM\\CurrentControlSet\\services";
- HKEYByReference regKey = null;
- try {
- regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
- String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
- for (String subKey : subKeys) {
- if (subKey.equals(bridgeId)) {
- resultKey = Advapi32Util.registryGetKey(root, topKey + "\\" + subKey + "\\Parameters\\Tcpip", WinNT.KEY_READ).getValue();
- break;
- }
- }
- } catch (Win32Exception e) {
- EMLogger.getLogger().warning(e.getMessage());
- } finally {
- if (regKey != null) {
- Advapi32Util.registryCloseKey(regKey.getValue());
- }
- }
+ String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces";
+
+ resultKey = Advapi32Util.registryGetKey(root, topKey + "\\" + bridgeId,
+ WinNT.KEY_READ).getValue();
return resultKey;
}
HKEY resultKey = null;
HKEY root = WinReg.HKEY_LOCAL_MACHINE;
- String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces" + "\\" + ifId;
+ String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces"
+ + "\\" + ifId;
try {
- resultKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ).getValue();
+ resultKey = Advapi32Util.registryGetKey(root, topKey,
+ WinNT.KEY_READ).getValue();
} catch (Win32Exception e) {
EMLogger.getLogger().warning(e.getMessage());
return resultKey;
}
+ private static void setWinbridgeNetwork(String interfaceClassID)
+ throws VMWorkerException {
+ HKEY interfaceKey = getInterfaceTcpipKey(interfaceClassID);
+ // HKEY bridgeKey = getInterfaceTcpipKey(getBridgeId());
+ System.out.println("interfaceKey: " + interfaceClassID);
+ System.out.println("bridgeKey: " + getBridgeId());
+ String dns = null;
+ String ip = null;
+ String gateway = null;
+ String netmask = null;
+ if (interfaceKey != null) {
+ try {
+ String ips[] = Advapi32Util.registryGetStringArray(
+ interfaceKey, "IPAddress");
+ if (ips.length > 0) {
+ ip = ips[0];
+ }
+
+ String gateways[] = Advapi32Util.registryGetStringArray(
+ interfaceKey, "DefaultGateway");
+ if (gateways.length > 0) {
+ gateway = gateways[0];
+ }
+
+ String netmasks[] = Advapi32Util.registryGetStringArray(
+ interfaceKey, "SubnetMask");
+ if (netmasks.length > 0) {
+ netmask = netmasks[0];
+ }
+
+ String val = Advapi32Util.registryGetStringValue(interfaceKey,
+ "NameServer");
+
+ String[] arr = val.split(",");
+ if (arr.length > 0) {
+ dns = arr[0];
+ }
+
+ String interfaceName = getBridgeNameFromClassID(interfaceClassID);
+ List<String> cmd = Arrays.asList("netsh.exe", "interface",
+ "ip", "delete", "address", interfaceName, "addr=" + ip,
+ "gateway=all");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ String bridgeKey = "HKLM\\SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces\\"
+ + getBridgeId();
+ // TOOD: Advapi32Util.registrySetStringValue(...) not work
+ cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v",
+ "EnableDHCP", "/t", "REG_DWORD", "/d", "0");
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v",
+ "IPAddress", "/t", "REG_MULTI_SZ", "/d", ip);
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v",
+ "SubnetMask", "/t", "REG_MULTI_SZ", "/d", netmask);
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v",
+ "DefaultGateway", "/t", "REG_MULTI_SZ", "/d", gateway);
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ cmd = Arrays
+ .asList("reg.exe", "add", bridgeKey, "/f", "/v",
+ "DefaultGatewayMetric", "/t", "REG_MULTI_SZ",
+ "/d", "1");
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ cmd = Arrays.asList("reg.exe", "add", bridgeKey, "/f", "/v",
+ "NameServer", "/t", "REG_SZ", "/d", dns);
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(interfaceKey);
+ }
+ }
+
+ }
+
private static String getBridgeId() {
String bridgeId = null;
if (EmulatorManager.isWin()) {
String topKey = "SYSTEM\\CurrentControlSet\\services\\BridgeMP";
String value = "Device";
try {
- String data = Advapi32Util.registryGetStringValue(root, topKey, value);
+ String data = Advapi32Util.registryGetStringValue(root, topKey,
+ value);
if (data != null) {
String arr[] = data.split("\\\\");
bridgeId = arr[arr.length - 1];
}
} catch (Win32Exception e) {
- EMLogger.getLogger().warning("Failed to getBridgeId(): " + e.getMessage());
+ EMLogger.getLogger().warning(
+ "Failed to getBridgeId(): " + e.getMessage());
}
}
return bridgeId;
HKEY key = getBridgeTcpipKey();
if (key != null) {
try {
- String data[] = Advapi32Util.registryGetStringArray(key, "DefaultGateway");
+ String data[] = Advapi32Util.registryGetStringArray(key,
+ "DefaultGateway");
if (data.length > 0) {
gateway = data[0];
}
key = getInterfaceTcpipKey(getBridgeId());
if (key != null) {
try {
- String data[] = Advapi32Util.registryGetStringArray(key, "DefaultGateway");
+ String data[] = Advapi32Util.registryGetStringArray(
+ key, "DefaultGateway");
if (data.length > 0) {
gateway = data[0];
}
}
}
} else if (EmulatorManager.isMac()) {
- List<String> cmd = Arrays.asList("/bin/sh", "-c", "netstat -rn | grep ^default | awk '{print $2}'");
+ List<String> cmd = Arrays.asList("/bin/sh", "-c",
+ "netstat -rn | grep ^default | awk '{print $2}'");
ProcessResult res = HelperClass.runProcess(cmd);
boolean isCommandSuccess = false;
if (res.isSuccess()) {
private static String getDnsForMac(String tapName) {
String dnsServer = "";
- List<String> cmd = Arrays.asList("/bin/sh", "-c", "/usr/sbin/scutil --dns | grep nameserver\\[[0]*\\] | awk '{print $3}' | head -n 1");
+ List<String> cmd = Arrays
+ .asList("/bin/sh",
+ "-c",
+ "/usr/sbin/scutil --dns | grep nameserver\\[[0]*\\] | awk '{print $3}' | head -n 1");
ProcessResult res = HelperClass.runProcess(cmd);
boolean isCommandSuccess = false;
if (res.isSuccess()) {
List<String> cmd = Arrays.asList("nm-tool", brName);
ProcessResult res = HelperClass.runProcess(cmd);
if (!res.isSuccess()) {
- EMLogger.getLogger().warning("Get dns failed. " + res.getResultMessage());
+ EMLogger.getLogger().warning(
+ "Get dns failed. " + res.getResultMessage());
return "";
}
HKEY key = getInterfaceTcpipKey(getBridgeId());
if (key != null) {
try {
- String val = Advapi32Util.registryGetStringValue(key, "NameServer");
+ String val = Advapi32Util.registryGetStringValue(key,
+ "NameServer");
String[] arr = val.split(",");
if (arr.length > 0) {
dns = arr[0];
while (interfaces.hasMoreElements()) {
NetworkInterface current = interfaces.nextElement();
if (current.getName().equals(ifName)) {
- for (InterfaceAddress addr : current.getInterfaceAddresses()) {
+ for (InterfaceAddress addr : current
+ .getInterfaceAddresses()) {
if (addr.getAddress() instanceof Inet4Address) {
return addr;
}
return isNotExist;
}
- public static void createTapDevice(String tapName, ComboViewItem comboViewItem) {
+ public static void createTapDevice(String tapName, String ifName,
+ ComboViewItem comboViewItem) {
if (EmulatorManager.isWin()) {
MessageDialog msgDialog = new MessageDialog();
- msgDialog.openNoButtonInfoDialog("Creating tap device.\nThis will take few seconds..");
- TapCreateWorker worker = new TapCreateWorker(tapName, msgDialog, comboViewItem);
+ msgDialog
+ .openNoButtonInfoDialog("Creating tap device.\nThis will take minutes..");
+ TapCreateWorker worker = new TapCreateWorker(tapName, ifName,
+ msgDialog, comboViewItem);
worker.start();
}
if (ifAddr != null)
ipAddr = ifAddr.getAddress().getHostAddress();
} catch (VMWorkerException e) {
- EMLogger.getLogger().warning((new StringBuilder()).append("Failed to get bridge ip address. ").append(e.getMessage()).toString());
+ EMLogger.getLogger().warning(
+ (new StringBuilder())
+ .append("Failed to get bridge ip address. ")
+ .append(e.getMessage()).toString());
}
else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
- String proxyCommand = "check-net.exe";
- List<String> cmd = Arrays.asList(FilePathResources.getBinPath() + File.separator + proxyCommand, "--bridge");
- ProcessResult res = HelperClass.runProcess(cmd);
- boolean isCommandSuccess = false;
- if (res.isSuccess()) {
- for (String str : res.getStdOutMsg()) {
- if (str.startsWith("IP Address:")) {
- isCommandSuccess = true;
- ipAddr = str.split("IP Address: ")[1].trim();
- EMLogger.getLogger().info("bridge IP address: " + ipAddr);
- if (ipAddr.equals("0.0.0.0")) {
- return null;
- }
+ HKEY key = getInterfaceTcpipKey(getBridgeId());
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key,
+ "IPAddress");
+ if (data.length > 0) {
+ ipAddr = data[0];
}
- }
- } else if (!res.isSuccess() || !isCommandSuccess) {
- EMLogger.getLogger().warning(res.getResultMessage());
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
}
if (ipAddr == null) {
EMLogger.getLogger().warning("Can't find host bridge IP");
- EMLogger.getLogger().warning("check-net result : " + res.getResultMessage());
}
} else if (EmulatorManager.isMac()) {
- List<String> cmd = Arrays.asList("/bin/sh", "-c", "ifconfig en0 | grep \"inet \" | awk '{print $2}'");
+ List<String> cmd = Arrays.asList("/bin/sh", "-c",
+ "ifconfig en0 | grep \"inet \" | awk '{print $2}'");
ProcessResult res = HelperClass.runProcess(cmd);
boolean isCommandSuccess = false;
if (res.isSuccess()) {
}
if (ipAddr.length() == 0) {
isCommandSuccess = false;
- cmd = Arrays.asList("/bin/sh", "-c", "ifconfig bridge1 | grep \"inet \" | awk '{print $2}'");
+ cmd = Arrays
+ .asList("/bin/sh", "-c",
+ "ifconfig bridge1 | grep \"inet \" | awk '{print $2}'");
res = HelperClass.runProcess(cmd);
if (res.isSuccess()) {
for (String str : res.getStdOutMsg()) {
isCommandSuccess = true;
ipAddr = str.trim();
- EMLogger.getLogger().info("host IP bridge1: " + ipAddr);
+ EMLogger.getLogger().info(
+ "host IP bridge1: " + ipAddr);
}
}
}
return newName;
}
-}
-class TapCreateWorker extends Thread {
+ public static boolean isWinBridgeExist() {
+ String proxyCommand = "check-net.exe";
+ boolean isExist = false;
+ List<String> cmd = Arrays.asList(FilePathResources.getBinPath()
+ + File.separator + proxyCommand, "--bridge");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ boolean isCommandSuccess = false;
+ if (res.isSuccess()) {
+ for (String str : res.getStdOutMsg()) {
+ if (str.startsWith("Adapter Desc:")) {
+ isExist = true;
+ isCommandSuccess = true;
+ break;
+ }
+ }
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger().warning(res.getResultMessage());
+ }
+ return isExist;
+ }
+
+ public static String getClassIDFromPnpInstanceID(String name) {
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+ String key = "Connection";
+ String value = "PnpInstanceID";
+ HKEYByReference regKey = null;
+ try {
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ for (String subKey : subKeys) {
+ String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey
+ + "\\" + subKey);
+ for (String subKey2 : subKeys2) {
+ if (subKey2.equals(key)) {
+ if (Advapi32Util.registryValueExists(root, topKey
+ + "\\" + subKey + "\\" + key, value) == false) {
+ continue;
+ }
+ String pnpInstanceID = Advapi32Util
+ .registryGetStringValue(root, topKey + "\\"
+ + subKey + "\\" + key, value);
+ if (pnpInstanceID.equals(name)) {
+ return subKey;
+ }
+ }
+ }
+ }
- final MessageDialog dialog;
- final String tapName;
- final ComboViewItem comboViewItem; // for refresh combo-list
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().info(e.getMessage());
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
+ }
+ }
- public TapCreateWorker(String tapName, MessageDialog dialog, ComboViewItem comboViewItem) {
- this.dialog = dialog;
- this.tapName = tapName;
- this.comboViewItem = comboViewItem;
+ return null;
}
- @Override
- public void run() {
- // Create tap device
- // - Create tap device and rename(user input name) because
- // windows OS generate device name automatically.
- // - For rename, inquire tap list before and after create and
- // compare both to find what is new one.
+ public static String getBridgeNameFromClassID(String classID) {
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\"
+ + classID + "\\Connection";
+ String value = "Name";
+ HKEYByReference regKey = null;
try {
- // 1. Get tap list before create new tap.
- List<String> before = TapUtil.getTapList();
- try { // TODO for test
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
- // 2. Create tap
- List<String> cmd = Arrays.asList("devcon", "install",
- "OemWin2k.inf", "Tap0901");
- ProcessResult res = HelperClass.runProcess(cmd);
+ return Advapi32Util.registryGetStringValue(root, topKey, value);
- if (!res.isSuccess()) {
- throw new VMWorkerException(res.getResultMessage());
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().info(e.getMessage());
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
}
+ }
- // 3. Get tap list and find new one.
- List<String> after = TapUtil.getTapList();
- String newOne = null;
- for (String str : after) {
- if (!before.contains(str)) {
- newOne = str;
- break;
+ return null;
+ }
+
+ public static String getPnpInstanceIDFromName(String name) {
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+ String key = "Connection";
+ String value = "Name";
+ String pnpInstanceID = "PnpInstanceID";
+ HKEYByReference regKey = null;
+ try {
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ for (String subKey : subKeys) {
+ String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey
+ + "\\" + subKey);
+ for (String subKey2 : subKeys2) {
+ if (subKey2.equals(key)) {
+ String tapName = Advapi32Util.registryGetStringValue(
+ root, topKey + "\\" + subKey + "\\" + key,
+ value);
+ if (tapName.equals(name)) {
+ return Advapi32Util.registryGetStringValue(root,
+ topKey + "\\" + subKey + "\\" + key,
+ pnpInstanceID);
+ }
+ }
}
}
- if (newOne == null) {
- throw new VMWorkerException("Tap create fail. Cannot find new tap device.");
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().info(e.getMessage());
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
}
+ }
- // 4. Rename
- cmd = Arrays.asList("netsh", "interface", "set", "interface", "name=" + newOne, "newname=" + tapName);
- res = HelperClass.runProcess(cmd);
- if (!res.isSuccess()) {
- throw new VMWorkerException(res.getResultMessage());
- }
+ return null;
+ }
- // 5. Check tap create in success.
- boolean isTapExist = false;
- for (String str : TapUtil.getTapList()) {
- if (str.equals(tapName)) {
- isTapExist = true;
- }
- }
+ static class TapCreateWorker extends Thread {
- final MessageDialog resultDialog = new MessageDialog();
- if (isTapExist) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- int res = resultDialog.openSelectionDialog("Tap device created : " + tapName + "\nDo you want to see the guide for bridge network ?");
- if (res == SWT.OK) {
- // Show bridge guide dialog
- TapGuideDialogForWin.open();
+ final MessageDialog dialog;
+ final String tapName;
+ final String ifName;
+ final ComboViewItem comboViewItem; // for refresh combo-list
+
+ public TapCreateWorker(String tapName, String ifName,
+ MessageDialog dialog, ComboViewItem comboViewItem) {
+ this.dialog = dialog;
+ this.tapName = tapName;
+ this.ifName = ifName;
+ this.comboViewItem = comboViewItem;
+ }
+
+ @Override
+ public void run() {
+ // Create tap device
+ // - Create tap device and rename(user input name) because
+ // windows OS generate device name automatically.
+ // - For rename, inquire tap list before and after create and
+ // compare both to find what is new one.
+ List<String> cmd;
+ ProcessResult res;
+ try {
+ if (!EmulatorManager.isWin8()) {
+ EMLogger.getLogger().info(
+ "get CompatibleIDs from pci network device");
+ cmd = Arrays.asList(devconPath, "find", "=net",
+ "@pci*");
+ res = HelperClass.runProcess(cmd);
+ boolean isCommandSuccess = false;
+ String CompatibleIDs = null;
+ if (res.isSuccess()) {
+ for (String str : res.getStdOutMsg()) {
+ if (str.endsWith(ifName)) {
+ isCommandSuccess = true;
+ CompatibleIDs = str.split(":")[0].trim();
+ EMLogger.getLogger().info(
+ "CompatibleIDs: " + CompatibleIDs);
+ break;
+ }
}
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger().warning(res.getResultMessage());
}
- });
- } else {
- throw new VMWorkerException("Tap is not exist : " + tapName);
- }
+ if (isWinBridgeExist() == false) {
+ // Create Bridge device and set IP
+ EMLogger.getLogger().info("create bridge");
+ cmd = Arrays
+ .asList(devconPath,
+ "install",
+ "c:\\windows\\inf\\netbrdgm.inf",
+ "ms_bridgemp");
+ res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
- } catch (VMWorkerException e) {
- EMLogger.getLogger().warning("Failed to create tap device.");
- EMLogger.getLogger().warning(e.getMessage());
- final String msg = e.getMessage();
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- new MessageDialog().openWarningDialog("\nFailed to create tap device.\n\n" + msg);
+ EMLogger.getLogger().info("bind interface to bridge");
+ cmd = Arrays.asList(FilePathResources.getBinPath()
+ + File.separator + "bindbridge.exe",
+ "ms_bridge", CompatibleIDs, "bind");
+ res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ throw new VMWorkerException("Fail to Create Bridge"
+ + res.getResultMessage());
+ }
+ EMLogger.getLogger().info("set bridge's IP");
+ setWinbridgeNetwork(getClassIDFromPnpInstanceID(CompatibleIDs));
+ }
}
- });
- } finally {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- dialog.close();
- comboViewItem.resetCombo();
+ // Get tap list before create new tap.
+ EMLogger.getLogger()
+ .info("Get tap list before create new tap.");
+ List<String> before = TapUtil.getTapList();
+
+ // Create new tap
+ EMLogger.getLogger().info("Create new tap.");
+ cmd = Arrays.asList(devconPath, "install",
+ FilePathResources.getBinPath() + File.separator
+ + "OemWin2k.inf", "Tap0901");
+ res = HelperClass.runProcess(cmd);
+
+ if (!res.isSuccess()) {
+ throw new VMWorkerException(res.getResultMessage());
}
- });
- }
+ // Get tap list and find new one.
+ EMLogger.getLogger().info("Get tap list and find new one.");
+ List<String> after = TapUtil.getTapList();
+ String newOne = null;
+ for (String str : after) {
+ if (!before.contains(str)) {
+ newOne = str;
+ break;
+ }
+ }
+
+ if (newOne == null) {
+ throw new VMWorkerException(
+ "Tap create fail. Cannot find new tap device.");
+ }
+
+ // Rename new tap to tapX
+ EMLogger.getLogger().info("Rename new tap to tapX.");
+ cmd = Arrays.asList("netsh", "interface", "set", "interface",
+ "name=" + newOne, "newname=" + tapName);
+ res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ // Check tap create in success.
+ EMLogger.getLogger().info("Check tap create in success.");
+ boolean isTapExist = false;
+ for (String str : TapUtil.getTapList()) {
+ if (str.equals(tapName)) {
+ isTapExist = true;
+ }
+ }
+
+ if (!EmulatorManager.isWin8()) {
+ EMLogger.getLogger().info("bind host network to bridge");
+ String tapPnpInstanceID = getPnpInstanceIDFromName(tapName);
+
+ cmd = Arrays.asList(FilePathResources.getBinPath()
+ + File.separator + "bindbridge.exe", "ms_bridge",
+ tapPnpInstanceID, "bind");
+ res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ EMLogger.getLogger().info(
+ "wait while finishing bridged network setting");
+ String proxyCommand = "check-net.exe";
+ cmd = Arrays.asList(FilePathResources.getBinPath()
+ + File.separator + proxyCommand, "--bridge");
+ res = HelperClass.runProcess(cmd);
+ while (!res.getStdOutMsg().isEmpty()) {
+ boolean isCommandSuccess = false;
+ String ipAddr = null;
+ if (res.isSuccess()) {
+ for (String str : res.getStdOutMsg()) {
+ if (str.startsWith("IP Address:")) {
+ isCommandSuccess = true;
+ ipAddr = str.split("IP Address: ")[1]
+ .trim();
+ EMLogger.getLogger().info(
+ "bridge IP address: " + ipAddr);
+ break;
+ }
+ }
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger()
+ .warning(res.getResultMessage());
+ }
+ if (ipAddr != null) {
+ break;
+ }
+ res = HelperClass.runProcess(cmd);
+ }
+
+ // shows success message
+ final MessageDialog messageDialog = new MessageDialog();
+ if (isTapExist) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ messageDialog
+ .openInfoDialog("Tap device created : "
+ + tapName);
+ }
+ });
+ }
+ } else {
+ final MessageDialog resultDialog = new MessageDialog();
+ if (isTapExist) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ int res = resultDialog
+ .openSelectionDialog("Tap device created : "
+ + tapName
+ + "\nDo you want to see the guide for bridge network ?");
+ if (res == SWT.OK) {
+ // Show bridge guide dialog
+ TapGuideDialogForWin.open();
+ }
+ }
+ });
+
+ } else {
+ throw new VMWorkerException("Tap is not exist : "
+ + tapName);
+ }
+ }
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning("Failed to create tap device.");
+ EMLogger.getLogger().warning(e.getMessage());
+ final String msg = e.getMessage();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ new MessageDialog()
+ .openWarningDialog("\nFailed to create tap device.\n\n"
+ + msg);
+ }
+ });
+
+ } finally {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ dialog.close();
+ comboViewItem.resetCombo();
+ }
+ });
+ }
+ }
}
}
package org.tizen.emulator.manager.ui.detail.item.property;
import org.eclipse.swt.events.SelectionEvent;
-
import org.eclipse.swt.events.SelectionListener;
import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
item = lineLabelViewItem
.getItem(CommonItemListFactory.ITEM_NET_TAP_DEVICE);
+ if (item != null && item instanceof NetTapDeviceViewItemWin) {
+ ((NetTapDeviceViewItemWin) item).resetCombo(newValue);
+ }
+
if (item != null && item instanceof NetTapDeviceViewItem) {
((NetTapDeviceViewItem) item).resetCombo(newValue);
}
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
+import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.tool.TapUtil;
import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
private boolean useDHCP() {
if (parentItem instanceof NetIPInfoViewItem) {
- NetIPInfoViewItem netItem = (NetIPInfoViewItem)parentItem;
+ NetIPInfoViewItem netItem = (NetIPInfoViewItem) parentItem;
if (netItem.useDHCP()) {
return true;
}
String tapName = null;
AdvancedViewItem item = parentItem.getLineLabelViewItem()
.getItem(CommonItemListFactory.ITEM_NET_TAP_DEVICE);
- if (item instanceof NetTapDeviceViewItem)
- tapName = ((NetTapDeviceViewItem) item).getValue();
+ if (!EmulatorManager.isWin()) {
+ if (item instanceof NetTapDeviceViewItem)
+ tapName = ((NetTapDeviceViewItem) item).getValue();
+ } else {
+ if (item instanceof NetTapDeviceViewItemWin)
+ tapName = ((NetTapDeviceViewItemWin) item)
+ .getValue();
+ }
// Set subnet, gateway if empty.
if (tapName != null || tapName.isEmpty()) {
item = parentItem.getLineLabelViewItem().getItem(
CommonItemListFactory.ITEM_NET_DNS);
if (item instanceof NetDnsViewItem) {
- NetDnsViewItem netDnsItem = (NetDnsViewItem)item;
+ NetDnsViewItem netDnsItem = (NetDnsViewItem) item;
String dns = TapUtil.getDnsFromTap(tapName);
if (dns == null || dns.isEmpty()) {
netDnsItem.setDns("");
- } else if (netDnsItem.getDns() == null || netDnsItem.getDns().isEmpty()) {
+ } else if (netDnsItem.getDns() == null
+ || netDnsItem.getDns().isEmpty()) {
netDnsItem.setDns(dns);
}
}
}
public ItemState checkValue() {
- String msg = TapUtil.checkIPString(text.isEnabled(), newValue, title);
+ String msg = TapUtil.checkIPString(text.isEnabled(), newValue, title);
if (msg.isEmpty()) {
itemState.setNormal();
} else {
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Button;
import org.tizen.emulator.manager.EmulatorManager;
-import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.ImageResources;
import org.tizen.emulator.manager.resources.PatchImageResources;
import org.tizen.emulator.manager.tool.TapUtil;
import org.tizen.emulator.manager.ui.widgets.ImageCombo;
import org.tizen.emulator.manager.ui.widgets.WSTATE;
import org.tizen.emulator.manager.vms.VMPropertyValue;
-import org.tizen.emulator.manager.vms.helper.HelperClass;
import org.tizen.emulator.manager.vms.xml.template.Item;
import org.tizen.emulator.manager.vms.xml.template.Option;
public class NetTapDeviceViewItem extends ComboViewItem {
- Button createButton;
protected static int BUTTON_WIDTH = 48;
protected static int BUTTON_HEIGHT = 20;
protected static int COMBOBOX_WIDTH_MODIFY = 123;
public void drawModify() {
if (INPUTBOX_ON_IMAGE == null) {
INPUTBOX_ON_IMAGE = PatchImageResources
- .getInputBoxON(COMBOBOX_WIDTH_MODIFY);
+ .getInputBoxON(COMBOBOX_WIDTH);
}
if (INPUTBOX_OFF_IMAGE == null) {
INPUTBOX_OFF_IMAGE = PatchImageResources
- .getInputBoxOff(COMBOBOX_WIDTH_MODIFY);
+ .getInputBoxOff(COMBOBOX_WIDTH);
}
combo = new ImageCombo(compList.get(0), SWT.NONE);
combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
combo.setLayout(new FormLayout());
- createButton = new Button(compList.get(0), SWT.NORMAL);
- createButton.setText("...");
- createButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
- createButton.setToolTipText("setting");
-
FormData data = new FormData();
data.left = new FormAttachment(0, INPUTBOX_OFFSET);
data.top = new FormAttachment(0, INPUTBOX_TOP_GAP);
data.height = INPUTBOX_ON_IMAGE.getImageData().height;
combo.setLayoutData(data);
- data = new FormData();
- data.left = new FormAttachment(combo, 5);
- data.top = new FormAttachment(0, 3);
- data.width = BUTTON_WIDTH;
- data.height = BUTTON_HEIGHT;
- createButton.setLayoutData(data);
-
// make combobox list
addWidgetListener();
}
@Override
- protected void addWidgetListener() {
- combo.addSelectionListener(new SelectionListener() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- newValue = combo.getText();
-
- // Set netmask, gateway
- resetAddress();
-
- if (!isCreateMode()) {
- // getListener().ChangeValue(getThis());
- getListener().changeModifyConfirmButton(getThis());
- }
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- });
-
- createButton.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent arg0) {
- if (EmulatorManager.isLinux()) {
- TapDeviceDialogForLinux.open();
- } else if (EmulatorManager.isWin()) {
- TapDeviceDialogForWin.open(thisItem);
- } else if (EmulatorManager.isMac()) {
- TapDeviceDialogForMac.open();
- }
- resetCombo(NetConnectTypeViewItem.VALUE_BRIDGE);
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent arg0) {
- }
-
- });
- }
-
- @Override
public boolean settingModifyItem(VMPropertyValue value) {
oldValue = newValue = value.getAdvancedOptionValue(name);
// text.setText(newValue);
-
AdvancedViewItem item = lineLabelViewItem
.getItem(CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
if (item != null && item instanceof NetConnectTypeViewItem) {
if (connectType.equals("Bridge") && !oldValue.equals(newValue)) {
resetAddress();
(new MessageDialog()).openWarningDialog((new StringBuilder())
- .append("Tap device (").append(oldValue)
+ .append("Base Network (").append(oldValue)
.append(") is removed or unavailable.")
.append("\nCheck tap configuration.").toString());
}
}
@Override
+ protected void addWidgetListener() {
+ combo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ newValue = combo.getText();
+
+ // Set netmask, gateway
+ resetAddress();
+
+ if (!isCreateMode()) {
+ // getListener().ChangeValue(getThis());
+ getListener().changeModifyConfirmButton(getThis());
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ }
+
+ @Override
public void resetCombo() {
String connectType = isBridge ? NetConnectTypeViewItem.VALUE_BRIDGE
: NetConnectTypeViewItem.VALUE_NAT;
// Enable if "Bridge"
if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
isBridge = true;
- comboOptions = TapUtil.getTapList();
+ if (EmulatorManager.isLinux()) {
+ comboOptions = TapDeviceDialogForLinux.getInterfaceList();
+ } else if (EmulatorManager.isMac()) {
+ comboOptions = TapDeviceDialogForMac.getInterfaceList();
+ } else if (EmulatorManager.isWin()) {
+ comboOptions = TapDeviceDialogForWin.getInterfaceList();
+ }
newValue = oldValue; // restore
// make combo box list
if (comboOptions != null) {
for (String option : comboOptions) {
+ EMLogger.getLogger().info("add option: " + option);
combo.add(option);
}
}
}
newValue = combo.getText();
combo.setEnabled(true);
- createButton.setEnabled(true);
// Disable if "NAT"
} else {
newValue = "";
combo.setText(newValue);
combo.setEnabled(false);
- createButton.setEnabled(false);
}
if (EmulatorManager.isMac()) {
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.ImageResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.ItemState;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForWin;
+import org.tizen.emulator.manager.ui.widgets.ImageCombo;
+import org.tizen.emulator.manager.ui.widgets.WSTATE;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+import org.tizen.emulator.manager.vms.xml.template.Option;
+
+public class NetTapDeviceViewItemWin extends ComboViewItem {
+
+ Button createButton;
+ protected static int BUTTON_WIDTH = 48;
+ protected static int BUTTON_HEIGHT = 20;
+ protected static int COMBOBOX_WIDTH_MODIFY = 123;
+
+ boolean isBridge = false;
+ NetTapDeviceViewItemWin thisItem;
+
+ public NetTapDeviceViewItemWin(Item template,
+ LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+ lineLabelViewItem.addItem(name, this);
+ }
+
+ @Override
+ protected void parseOption(List<Option> optionList) {
+ comboOptions = TapUtil.getTapList();
+ }
+
+ @Override
+ public void drawModify() {
+ if (INPUTBOX_ON_IMAGE == null) {
+ INPUTBOX_ON_IMAGE = PatchImageResources
+ .getInputBoxON(COMBOBOX_WIDTH_MODIFY);
+ }
+
+ if (INPUTBOX_OFF_IMAGE == null) {
+ INPUTBOX_OFF_IMAGE = PatchImageResources
+ .getInputBoxOff(COMBOBOX_WIDTH_MODIFY);
+ }
+
+ combo = new ImageCombo(compList.get(0), SWT.NONE);
+ combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
+
+ combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
+ combo.setEnabled(true);
+ combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
+ combo.setLayout(new FormLayout());
+
+ createButton = new Button(compList.get(0), SWT.NORMAL);
+ createButton.setText("...");
+ createButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ createButton.setToolTipText("setting");
+
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, INPUTBOX_OFFSET);
+ data.top = new FormAttachment(0, INPUTBOX_TOP_GAP);
+ data.width = INPUTBOX_ON_IMAGE.getImageData().width;
+ data.height = INPUTBOX_ON_IMAGE.getImageData().height;
+ combo.setLayoutData(data);
+
+ data = new FormData();
+ data.left = new FormAttachment(combo, 5);
+ data.top = new FormAttachment(0, 3);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ createButton.setLayoutData(data);
+
+ // make combobox list
+ addWidgetListener();
+
+ thisItem = this;
+ }
+
+ @Override
+ protected void addWidgetListener() {
+ combo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ newValue = combo.getText();
+
+ // Set netmask, gateway
+ resetAddress();
+
+ if (!isCreateMode()) {
+ // getListener().ChangeValue(getThis());
+ getListener().changeModifyConfirmButton(getThis());
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ createButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ TapDeviceDialogForWin.open(thisItem);
+ resetCombo(NetConnectTypeViewItem.VALUE_BRIDGE);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+
+ });
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+ oldValue = newValue = value.getAdvancedOptionValue(name);
+ // text.setText(newValue);
+
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
+ if (item != null && item instanceof NetConnectTypeViewItem) {
+ String connectType = ((NetConnectTypeViewItem) item).getValue();
+ resetCombo(connectType);
+ if (connectType.equals("Bridge") && !oldValue.equals(newValue)) {
+ resetAddress();
+ (new MessageDialog()).openWarningDialog((new StringBuilder())
+ .append("Tap device (").append(oldValue)
+ .append(") is removed or unavailable.")
+ .append("\nCheck tap configuration.").toString());
+ }
+ }
+
+ getListener().changeModifyConfirmButton(getThis());
+
+ return true;
+ }
+
+ @Override
+ public void resetCombo() {
+ String connectType = isBridge ? NetConnectTypeViewItem.VALUE_BRIDGE
+ : NetConnectTypeViewItem.VALUE_NAT;
+ resetCombo(connectType);
+ }
+
+ // called when NAT/Bridge changed.
+ public void resetCombo(String connectType) {
+ // Reset combo when connect type(NAT/Bridge) is changed.
+ if (combo != null) {
+ combo.removeAll();
+ }
+
+ // Enable if "Bridge"
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
+ isBridge = true;
+ comboOptions = TapUtil.getTapList();
+ newValue = oldValue; // restore
+
+ // make combo box list
+ if (comboOptions != null) {
+ for (String option : comboOptions) {
+ combo.add(option);
+ }
+ }
+
+ // Select combo-box item.
+ int index = -1;
+ for (int i = 0; i < comboOptions.size(); i++) {
+ if (comboOptions.get(i).equals(newValue)) {
+ index = i;
+ break;
+ }
+ }
+ if (comboOptions.size() > 0) {
+ if (index == -1) {
+ // if value not matches..
+ combo.select(0);
+ newValue = combo.getItem(0);
+ } else {
+ combo.select(index);
+ }
+ resetAddress();
+ }
+ newValue = combo.getText();
+ combo.setEnabled(true);
+ createButton.setEnabled(true);
+
+ // Disable if "NAT"
+ } else {
+ isBridge = false;
+ oldValue = newValue; // save
+ newValue = "";
+ combo.setText(newValue);
+ combo.setEnabled(false);
+ createButton.setEnabled(false);
+ }
+
+ if (EmulatorManager.isMac()) {
+ combo.setEnabled(false);
+ }
+ }
+
+ @Override
+ public ItemState checkValue() {
+ if (!combo.isEnabled()) {
+ itemState.setNormal();
+
+ } else if (newValue == null || !newValue.isEmpty()) {
+ itemState.setNormal();
+
+ } else {
+ itemState.setError("At least one Tap device should be created.");
+ }
+
+ return itemState;
+ }
+
+ private void resetAddress() {
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_IP_INFO);
+ if (item != null && item instanceof NetIPInfoViewItem) {
+ NetIPInfoViewItem netIPInfoItem = (NetIPInfoViewItem) item;
+ netIPInfoItem.setSubnet(TapUtil.getNetmaskFromTap(newValue));
+ netIPInfoItem.setGateway(TapUtil.getGatewayFromTap(newValue));
+ }
+
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_DNS);
+ if (item != null && item instanceof NetDnsViewItem) {
+ ((NetDnsViewItem) item).setDns(TapUtil.getDnsFromTap(newValue));
+ }
+
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_MAC);
+ if (item != null && item instanceof NetMacViewItem) {
+ ((NetMacViewItem) item).resetText(newValue);
+ }
+
+ }
+
+}
package org.tizen.emulator.manager.ui.dialog;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.swt.widgets.Text;
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.ColorResources;
-import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.FontResources;
-import org.tizen.emulator.manager.resources.ImageResources;
import org.tizen.emulator.manager.resources.PatchImageResources;
import org.tizen.emulator.manager.tool.TapUtil;
import org.tizen.emulator.manager.ui.MainDialog;
-import org.tizen.emulator.manager.ui.widgets.ImageCombo;
import org.tizen.emulator.manager.ui.widgets.ImageLabel;
-import org.tizen.emulator.manager.ui.widgets.WSTATE;
-import org.tizen.emulator.manager.vms.helper.HelperClass;
-import org.tizen.emulator.manager.vms.helper.ProcessResult;
import org.tizen.emulator.manager.vms.helper.VMWorkerException;
public class TapDeviceDialogForLinux {
- private static Shell dialog = null;
- private static int width = 300;
- private static int height = 155;
- private static Image image;
- private static int COMP_WIDTH = 270;
- private static int UPPER_HEIGHT = 54;
- private static int ITEM_COUNT = 2;
-
- private static Text nameText;
- private static ImageCombo combo;
-
- private static Button okButton;
- private static Button cancelButton;
-
- private static String tapName;
- private static String ifName;
-
- static {
- image = PatchImageResources.getDetailListView2(ITEM_COUNT);
- }
-
- public static void open() {
- makeDialog();
- dialog.open();
- while (!dialog.isDisposed()) {
- if (!Display.getCurrent().readAndDispatch()) {
- Display.getCurrent().sleep();
- }
- }
- }
-
- private static void makeDialog() {
- dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
- | SWT.APPLICATION_MODAL);
- dialog.setText("Setting tap device.");
- dialog.setSize(width, height);
- dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
- RowLayout rowLayout = new RowLayout();
- rowLayout.type = SWT.VERTICAL;
- rowLayout.marginTop = 15;
- rowLayout.marginLeft = 10;
- rowLayout.spacing = 15;
-
- dialog.setLayout(rowLayout);
-
- makeUpperComposite();
- makeLowerComposite();
- addListener();
-
- }
-
- private static void makeUpperComposite() {
- Composite upperComp = new Composite(dialog, SWT.BORDER);
- upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
- upperComp.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- Rectangle rect = ((Composite) e.widget).getClientArea();
- e.gc.drawImage(image, rect.x - 2, rect.y);
-
- }
- });
- upperComp.setLayout(new FormLayout());
-
- // tap name (text input)
- Label nameLabel = new Label(upperComp, SWT.NONE);
- nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
- nameLabel.setText("Tap name");
- nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
- FormData data = new FormData();
- data.left = new FormAttachment(0, 15);
- data.top = new FormAttachment(0, 4);
- data.width = 85;
- data.height = 20;
- nameLabel.setLayoutData(data);
-
- Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
- ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
- valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
- valueLabel.setLayout(new FormLayout());
- data = new FormData();
- data.left = new FormAttachment(0, 100);
- data.top = new FormAttachment(0, 4);
- data.width = 150;
- data.height = 19;
- valueLabel.setLayoutData(data);
-
- nameText = new Text(valueLabel, SWT.NONE);
- nameText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
- nameText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
- nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
- .getColor());
- nameText.setTextLimit(20);
-
- data = new FormData();
- data.left = new FormAttachment(0, 5);
- data.top = new FormAttachment(0, 2);
- data.right = new FormAttachment(100, -5);
- data.bottom = new FormAttachment(100, -2);
- nameText.setLayoutData(data);
- nameText.setEnabled(false);
- nameText.setText(TapUtil.getAvailableTapName());
-
- // interface (combo select)
- Label ifLabel = new Label(upperComp, SWT.NONE);
- ifLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
- ifLabel.setText("Interface");
- ifLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
- data = new FormData();
- data.left = new FormAttachment(0, 15);
- data.top = new FormAttachment(0, 31);
- data.width = 85;
- data.height = 20;
- ifLabel.setLayoutData(data);
-
- combo = new ImageCombo(upperComp, SWT.NONE);
- combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
- combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
- combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
- combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
-
- combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
- combo.setEnabled(true);
- combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
- combo.setLayout(new FormLayout());
-
- data = new FormData();
- data.left = new FormAttachment(0, 100);
- data.top = new FormAttachment(0, 31);
- data.width = INPUTBOX_ON_IMAGE.getImageData().width;
- data.height = INPUTBOX_ON_IMAGE.getImageData().height;
- combo.setLayoutData(data);
-
- try {
- for (String str : getInterfaceList()) {
- if (str.equals("eth0")) {
- combo.add(str, 0);
- continue;
- }
- combo.add(str);
- }
- combo.select(0);
- } catch (VMWorkerException e) {
- EMLogger.getLogger().warning("Failed to get interface list.");
- EMLogger.getLogger().warning(e.getMessage());
- new MessageDialog()
- .openWarningDialog("Failed to get interface list.\n"
- + e.getMessage());
- }
-
- }
-
- private static void makeLowerComposite() {
- Composite lowerComp = new Composite(dialog, 0);
- lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 30));
- lowerComp
- .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
- lowerComp.setLayout(new FormLayout());
-
- int BUTTON_WIDTH = 128;
- int BUTTON_HEIGHT = 26;
-
- okButton = new Button(lowerComp, SWT.PUSH);
- okButton.setText("OK");
- okButton.setEnabled(true);
- okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
- FormData data = new FormData();
- data.left = new FormAttachment(0, 0);
- data.top = new FormAttachment(0, 0);
- data.width = BUTTON_WIDTH;
- data.height = BUTTON_HEIGHT;
- okButton.setLayoutData(data);
-
- cancelButton = new Button(lowerComp, SWT.PUSH);
- cancelButton.setText("CANCEL");
- cancelButton.setEnabled(true);
- cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
- data = new FormData();
- data.left = new FormAttachment(okButton, 16);
- data.top = new FormAttachment(0, 0);
- data.width = BUTTON_WIDTH;
- data.height = BUTTON_HEIGHT;
- cancelButton.setLayoutData(data);
-
- }
-
- private static void addListener() {
- cancelButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent arg0) {
- dialog.close();
- }
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
-
- }
- });
-
- okButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent arg0) {
-
- tapName = nameText.getText();
- ifName = combo.getText();
- dialog.close();
- try {
- createTapDevice();
-
- } catch (VMWorkerException e) {
- EMLogger.getLogger()
- .warning("Failed to create tap device.");
- EMLogger.getLogger().warning(e.getMessage());
- new MessageDialog()
- .openWarningDialog("\nFailed to create tap device.\n"
- + e.getMessage());
- }
-
- }
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
- // TODO Auto-generated method stub
- }
- });
-
- }
-
- private static List<String> getInterfaceList() throws VMWorkerException {
- List<String> result = new ArrayList<String>();
+ public static ArrayList<String> getInterfaceList() {
+ ArrayList<String> result = new ArrayList<String>();
// Get intereface list
- List<String> ifList = new ArrayList<String>();
+ ArrayList<String> ifList = new ArrayList<String>();
Enumeration<NetworkInterface> interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
ifList.add(current.getName());
}
}
- } catch (SocketException e) {
- EMLogger.getLogger().warning(e.getMessage());
- throw new VMWorkerException(e.getMessage());
- }
-
- // Except bridges in list
- List<String> brList = TapUtil.getBridgeList();
- for (String str : ifList) {
- if (!brList.contains(str)) {
- result.add(str);
- }
- }
-
- return result;
- }
-
- // Generate script file and run as admin(sudo)
- private static boolean createTapDevice() throws VMWorkerException {
- boolean result = true;
-
- String script = generateScript();
-
- File tempFile = null;
- FileWriter writer = null;
- List<String> cmd = null;
- ProcessResult res = null;
- try {
- // create temp file and write script
- File dir = new File(FilePathResources.getBinPath());
- tempFile = File.createTempFile("tap_script~", ".sh", dir);
- writer = new FileWriter(tempFile);
- writer.append(script);
- writer.flush();
- writer.close();
-
- // Add executable attribute.
- cmd = Arrays.asList("chmod", "+x", tempFile.getAbsolutePath());
- res = HelperClass.runProcess(cmd);
- if (res.isSuccess() == false) {
- EMLogger.getLogger().warning(
- "Fail to run process. " + cmd + " failed");
- result = false;
-
- } else {
- // Run script. TODO if gksudo not exist ?
- if (isCommandExist("gksudo"))
- cmd = Arrays
- .asList(new String[] {
- "gksudo",
- "-m",
- "\nEnter your password to create tap device and change bridge configuration.",
- tempFile.getAbsolutePath() });
- else {
- cmd = Arrays.asList(new String[] { "pkexec",
- tempFile.getAbsolutePath() });
- }
- res = HelperClass.runProcess(cmd);
-
- if (res.isSuccess() == true && isTapCreated(tapName, ifName)) {
- EMLogger.getLogger()
- .info("Tap device created : " + tapName);
- result = true;
- new MessageDialog().openInfoDialog("Tap device created : "
- + tapName);
-
- } else {
- EMLogger.getLogger().warning(
- "Fail to run script with sudo. " + cmd + " failed");
- for (String str : res.getStdOutMsg()) {
- EMLogger.getLogger().warning(str);
- }
- for (String str : res.getStdErrMsg()) {
- EMLogger.getLogger().warning(str);
- }
- result = false;
- new VMWorkerException(res.getResultMessage());
+ // Except bridges in list
+ List<String> brList = TapUtil.getBridgeList();
+ for (String str : ifList) {
+ if (!brList.contains(str)) {
+ result.add(str);
}
}
-
- } catch (IOException e) {
- EMLogger.getLogger().warning(
- "Failed to create tap device. " + e.getMessage());
-
- } finally {
- // close writer
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- // delete temp file
- if (tempFile != null) {
- tempFile.delete();
- }
+ } catch (SocketException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning(e.getMessage());
}
return result;
}
-
- private static boolean isCommandExist(String command)
- throws VMWorkerException {
- List<String> cmd = Arrays.asList(new String[] { "which", command });
- ProcessResult res = HelperClass.runProcess(cmd);
- return res.isSuccess() && res.getResultMessage().contains(command);
- }
-
- private static String generateScript() throws VMWorkerException {
- // Script.
- // - Create tap.
- // - Add tap and interface to bridge.
- // - If interface is already a member of another bridge,
- // - add tap to that bridge. And set bridge ip information as
- // interface's ip.
- // - If interface is not a member of other bridge,
- // - create new bridge and add tap and interface to new bridge.
-
- // Create tap device.
- StringBuilder script = new StringBuilder();
- script.append("#!/bin/bash +x\n\n");
-
- script.append("# Create the tap device.\n");
- script.append("openvpn --mktun --dev ").append(tapName).append("\n");
- script.append("ifconfig ").append(tapName)
- .append(" 0.0.0.0 promisc up\n\n");
-
- // Create the bridge if need.
- String bridgeName;
- String bridge = TapUtil.getBridgeFromDevice(ifName);
- if (bridge == null) {
- bridgeName = getNewBridgeName();
- script.append("# Create the bridge.\n");
- script.append("brctl addbr ").append(bridgeName).append("\n\n");
-
- InterfaceAddress addr = TapUtil.getInterfaceIpInfo(ifName);
- if (addr == null) {
- throw new VMWorkerException(
- "Cannot get the ip address information of interface : "
- + ifName);
- }
- String ipAddr = addr.getAddress().getHostAddress();
- String broadCastAddr = addr.getBroadcast().getHostAddress();
- String netMask = TapUtil.getNetMask(addr.getNetworkPrefixLength());
- script.append("# Bring up the bridge.\n");
- script.append("ifconfig ").append(bridgeName).append(" ")
- .append(ipAddr).append(" netmask ").append(netMask)
- .append(" broadcast ").append(broadCastAddr).append("\n\n");
-
- } else {
- bridgeName = bridge;
- // TODO Popup message about change.. (bridge ip info may be
- // changed..)
- }
-
- // Add tap to bridge
- script.append("# Take interface down.\n");
- script.append("ifdown ").append(ifName).append("\n");
- script.append("ifconfig ").append(ifName)
- .append(" 0.0.0.0 promisc up\n\n");
-
- script.append("# Add tap device and interface to bridge.\n");
- if (bridge == null) {
- script.append("brctl addif ").append(bridgeName).append(" ")
- .append(ifName).append("\n");
- }
- script.append("brctl addif ").append(bridgeName).append(" ")
- .append(tapName).append("\n\n");
-
- // Add default gateway
- List<String> gatewayList = TapUtil.getDefaultGateway(null);
- if (gatewayList.size() == 0) {
- // user input gateway address
- String gw = IPAddressInputDialog.open("Input gateway address");
- if (gw != null) {
- gatewayList.add(gw);
-
- } else {
- throw new VMWorkerException("User canceled.");
- }
- }
- script.append("# Add the default route.\n");
- for (String gateway : gatewayList) {
- script.append("route add default gw ").append(gateway)
- .append("\n\n");
- }
-
- script.append("exit 0\n");
- return script.toString();
- }
-
- private static boolean isTapCreated(String tapName, String ifName) {
- for (String str : TapUtil.getTapList()) {
- if (str.equals(tapName)) {
- return true;
- }
- }
- // TODO Check tap, interface is bridged correctly.
- return false;
- }
-
- private static String getNewBridgeName() throws VMWorkerException {
- final String prefix = "br-tizen-vm-";
- int index = 1;
-
- String bridgeName;
- List<String> bridgeList = TapUtil.getBridgeList();
-
- boolean isExist;
- do {
- isExist = false;
- bridgeName = prefix + String.valueOf(index++);
- for (String str : bridgeList) {
- if (bridgeName.equals(str)) {
- isExist = true;
- break;
- }
- }
- } while (isExist);
-
- return bridgeName;
- }
-
}
// Gateway Input dialog.
package org.tizen.emulator.manager.ui.dialog;
import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.RowData;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.tizen.emulator.manager.logging.EMLogger;
-import org.tizen.emulator.manager.resources.ColorResources;
-import org.tizen.emulator.manager.resources.FontResources;
-import org.tizen.emulator.manager.resources.ImageResources;
-import org.tizen.emulator.manager.resources.PatchImageResources;
-import org.tizen.emulator.manager.ui.MainDialog;
-import org.tizen.emulator.manager.ui.widgets.ImageCombo;
-import org.tizen.emulator.manager.ui.widgets.ImageLabel;
-import org.tizen.emulator.manager.ui.widgets.WSTATE;
-import org.tizen.emulator.manager.vms.helper.VMWorkerException;
public class TapDeviceDialogForMac {
- private static Shell dialog = null;
- private static int width = 300;
- private static int height = 155;
- private static Image image;
- private static int COMP_WIDTH = 270;
- private static int UPPER_HEIGHT = 54;
- private static int ITEM_COUNT = 2;
-
- private static Text nameText;
- private static ImageCombo combo;
-
- private static Button okButton;
- private static Button cancelButton;
-
- private static String tapName;
- private static String ifName;
-
- static {
- image = PatchImageResources.getDetailListView2(ITEM_COUNT);
- }
-
- public static void open() {
- makeDialog();
- dialog.open();
- while (!dialog.isDisposed()) {
- if (!Display.getCurrent().readAndDispatch()) {
- Display.getCurrent().sleep();
- }
- }
- }
-
- private static void makeDialog() {
- dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
- | SWT.APPLICATION_MODAL);
- dialog.setText("Setting tap device.");
- dialog.setSize(width, height);
- dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
- RowLayout rowLayout = new RowLayout();
- rowLayout.type = SWT.VERTICAL;
- rowLayout.marginTop = 15;
- rowLayout.marginLeft = 10;
- rowLayout.spacing = 15;
-
- dialog.setLayout(rowLayout);
-
- makeUpperComposite();
- makeLowerComposite();
- addListener();
-
- }
-
- private static void makeUpperComposite() {
- Composite upperComp = new Composite(dialog, SWT.BORDER);
- upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
- upperComp.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- Rectangle rect = ((Composite) e.widget).getClientArea();
- e.gc.drawImage(image, rect.x - 2, rect.y);
-
- }
- });
- upperComp.setLayout(new FormLayout());
-
- // tap name (text input)
- Label nameLabel = new Label(upperComp, SWT.NONE);
- nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
- nameLabel.setText("Tap name");
- nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
- FormData data = new FormData();
- data.left = new FormAttachment(0, 15);
- data.top = new FormAttachment(0, 4);
- data.width = 85;
- data.height = 20;
- nameLabel.setLayoutData(data);
-
- Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
- ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
- valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
- valueLabel.setLayout(new FormLayout());
- data = new FormData();
- data.left = new FormAttachment(0, 100);
- data.top = new FormAttachment(0, 4);
- data.width = 150;
- data.height = 19;
- valueLabel.setLayoutData(data);
-
- nameText = new Text(valueLabel, SWT.NONE);
- nameText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
- nameText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
- nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
- .getColor());
- nameText.setTextLimit(20);
-
- data = new FormData();
- data.left = new FormAttachment(0, 5);
- data.top = new FormAttachment(0, 2);
- data.right = new FormAttachment(100, -5);
- data.bottom = new FormAttachment(100, -2);
- nameText.setLayoutData(data);
- nameText.setText("auto");
- nameText.setEnabled(false);
- valueLabel.setEnabled(false);
-
- // interface (combo select)
- Label ifLabel = new Label(upperComp, SWT.NONE);
- ifLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
- ifLabel.setText("Interface");
- ifLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
- data = new FormData();
- data.left = new FormAttachment(0, 15);
- data.top = new FormAttachment(0, 31);
- data.width = 85;
- data.height = 20;
- ifLabel.setLayoutData(data);
-
- combo = new ImageCombo(upperComp, SWT.NONE);
- combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
- combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
- combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
- combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
-
- combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
- combo.setEnabled(true);
- combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
- combo.setLayout(new FormLayout());
-
- data = new FormData();
- data.left = new FormAttachment(0, 100);
- data.top = new FormAttachment(0, 31);
- data.width = INPUTBOX_ON_IMAGE.getImageData().width;
- data.height = INPUTBOX_ON_IMAGE.getImageData().height;
- combo.setLayoutData(data);
-
- try {
- for (String str : getInterfaceList()) {
- if (str.equals("en0")) {
- combo.add(str, 0);
- continue;
- }
- combo.add(str);
- }
- combo.select(0);
- } catch (VMWorkerException e) {
- EMLogger.getLogger().warning("Failed to get interface list.");
- EMLogger.getLogger().warning(e.getMessage());
- new MessageDialog()
- .openWarningDialog("Failed to get interface list.\n"
- + e.getMessage());
- }
-
- }
-
- private static void makeLowerComposite() {
- Composite lowerComp = new Composite(dialog, 0);
- lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 30));
- lowerComp
- .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
- lowerComp.setLayout(new FormLayout());
-
- int BUTTON_WIDTH = 128;
- int BUTTON_HEIGHT = 26;
-
- okButton = new Button(lowerComp, SWT.PUSH);
- okButton.setText("OK");
- okButton.setEnabled(true);
- okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
- FormData data = new FormData();
- data.left = new FormAttachment(0, 0);
- data.top = new FormAttachment(0, 0);
- data.width = BUTTON_WIDTH;
- data.height = BUTTON_HEIGHT;
- okButton.setLayoutData(data);
-
- cancelButton = new Button(lowerComp, SWT.PUSH);
- cancelButton.setText("CANCEL");
- cancelButton.setEnabled(true);
- cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
- data = new FormData();
- data.left = new FormAttachment(okButton, 16);
- data.top = new FormAttachment(0, 0);
- data.width = BUTTON_WIDTH;
- data.height = BUTTON_HEIGHT;
- cancelButton.setLayoutData(data);
-
- }
-
- private static void addListener() {
- cancelButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent arg0) {
- dialog.close();
- }
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
-
- }
- });
-
- okButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent arg0) {
-
- tapName = nameText.getText();
- ifName = combo.getText();
- dialog.close();
-
- }
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
- // TODO Auto-generated method stub
- }
- });
-
- }
-
- private static List<String> getInterfaceList() throws VMWorkerException {
- List<String> result = new ArrayList<String>();
+ public static ArrayList<String> getInterfaceList() {
+ ArrayList<String> result = new ArrayList<String>();
//TODO: currently support only en0
result.add("en0");
return result;
*
*/
-
package org.tizen.emulator.manager.ui.dialog;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.ImageResources;
import org.tizen.emulator.manager.resources.PatchImageResources;
import org.tizen.emulator.manager.tool.TapUtil;
import org.tizen.emulator.manager.ui.MainDialog;
import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.widgets.ImageCombo;
import org.tizen.emulator.manager.ui.widgets.ImageLabel;
+import org.tizen.emulator.manager.ui.widgets.WSTATE;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.ProcessResult;
public class TapDeviceDialogForWin {
private static Shell dialog = null;
- private static int width = 300;
- private static int height = 130;
- private static Image image;
- private static int COMP_WIDTH = 270;
- private static int UPPER_HEIGHT = 27;
- private static int ITEM_COUNT = 1;
+ private static int width = 385;
+ private static int height = 155;
+ private static int comboWidth = 250;
+ private static int COMP_WIDTH = width - 30;
private static Text nameText;
+ private static ImageCombo combo;
private static Button okButton;
private static Button cancelButton;
private static String tapName;
+ private static String ifName;
private static ComboViewItem comboViewItem;
+ public static ArrayList<String> getInterfaceList() {
+ // Get intereface list
+ ProcessResult res;
+ ArrayList<String> ifList = new ArrayList<String>();
+ List<String> cmd = Arrays.asList(FilePathResources.getBinPath()
+ + File.separator + "devcon.exe", "find", "=net", "@pci*");
+ res = HelperClass.runProcess(cmd);
+ boolean isCommandSuccess = false;
+ if (res.isSuccess()) {
+ for (String str : res.getStdOutMsg()) {
+ if (str.contains(": ")) {
+ isCommandSuccess = true;
+ String pciNet = str.split(": ")[1].trim();
+ EMLogger.getLogger().info(
+ "PCI network interface: " + pciNet);
+ ifList.add(pciNet);
+ }
+ }
- static {
- image = PatchImageResources.getDetailListView2(ITEM_COUNT);
+ } else if (!res.isSuccess() || !isCommandSuccess) {
+ EMLogger.getLogger().warning(res.getResultMessage());
+ }
+
+ return ifList;
}
public static void open(ComboViewItem comboViewItem) {
}
}
-
private static void makeDialog() {
dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
| SWT.APPLICATION_MODAL);
rowLayout.type = SWT.VERTICAL;
rowLayout.marginTop = 15;
rowLayout.marginLeft = 10;
+ rowLayout.marginRight = 10;
rowLayout.spacing = 3;
dialog.setLayout(rowLayout);
private static void makeUpperComposite() {
Composite upperComp = new Composite(dialog, SWT.BORDER);
- upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
- upperComp.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent e) {
- Rectangle rect = ((Composite) e.widget).getClientArea();
- e.gc.drawImage(image, rect.x - 2, rect.y);
-
- }
- });
upperComp.setLayout(new FormLayout());
// tap name (text input)
Label nameLabel = new Label(upperComp, SWT.NONE);
nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
nameLabel.setText("Tap name");
- nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
FormData data = new FormData();
data.left = new FormAttachment(0, 15);
data.top = new FormAttachment(0, 4);
data.height = 20;
nameLabel.setLayoutData(data);
- Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
+ Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(comboWidth);
ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
valueLabel.setLayout(new FormLayout());
data = new FormData();
data.left = new FormAttachment(0, 100);
data.top = new FormAttachment(0, 4);
- data.width = 150;
+ data.width = comboWidth;
data.height = 19;
valueLabel.setLayoutData(data);
nameText = new Text(valueLabel, SWT.NONE);
nameText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
nameText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
- nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR.getColor());
+ nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
+ .getColor());
nameText.setTextLimit(20);
data = new FormData();
nameText.setEnabled(false);
nameText.setText(TapUtil.getAvailableTapName());
+ // interface (combo select)
+ Label ifLabel = new Label(upperComp, SWT.NONE);
+ ifLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ ifLabel.setText("Interface");
+ data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, 31);
+ data.width = 85;
+ data.height = 20;
+ ifLabel.setLayoutData(data);
+
+ combo = new ImageCombo(upperComp, SWT.NONE);
+ combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
+
+ combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
+ combo.setEnabled(true);
+ combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
+ combo.setLayout(new FormLayout());
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 100);
+ data.right = new FormAttachment(100, -5);
+ data.top = new FormAttachment(0, 31);
+ data.width = INPUTBOX_ON_IMAGE.getImageData().width;
+ data.height = INPUTBOX_ON_IMAGE.getImageData().height;
+ combo.setLayoutData(data);
+
+ for (String str : getInterfaceList()) {
+ combo.add(str);
+ }
+ combo.select(0);
+
}
private static void makeLowerComposite() {
Composite lowerComp = new Composite(dialog, 0);
lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 40));
- lowerComp.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ lowerComp
+ .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
lowerComp.setLayout(new FormLayout());
FormData data = new FormData();
-// Label infoLabel = new Label(lowerComp, SWT.NONE);
-// data.left = new FormAttachment(5, 0);
-// data.top = new FormAttachment(0, 0);
-// data.right = new FormAttachment(100,-1);
-// data.height = 13;
-// infoLabel.setLayoutData(data);
-// infoLabel.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
-// infoLabel.setForeground(ColorResources.TEAL.getColor());
-// infoLabel.setFont(FontResources.TOOLTIP.getFont());
-// infoLabel.setText("- Input tap device name.(alphanumeric)"); // TODO
+ // Label infoLabel = new Label(lowerComp, SWT.NONE);
+ // data.left = new FormAttachment(5, 0);
+ // data.top = new FormAttachment(0, 0);
+ // data.right = new FormAttachment(100,-1);
+ // data.height = 13;
+ // infoLabel.setLayoutData(data);
+ // infoLabel.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ // infoLabel.setForeground(ColorResources.TEAL.getColor());
+ // infoLabel.setFont(FontResources.TOOLTIP.getFont());
+ // infoLabel.setText("- Input tap device name.(alphanumeric)"); // TODO
int BUTTON_WIDTH = 128;
int BUTTON_HEIGHT = 26;
okButton.setEnabled(true);
okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
data = new FormData();
- data.left = new FormAttachment(0, 0);
+ data.left = new FormAttachment(0, 45);
data.top = new FormAttachment(0, 15);
data.width = BUTTON_WIDTH;
data.height = BUTTON_HEIGHT;
private static void addListener() {
-// nameText.addModifyListener(new ModifyListener() {
-// public void modifyText(ModifyEvent arg0) {
-// // name invalidation
-// if (!nameText.getText().isEmpty() &&
-// HelperClass.checkString(nameText.getText())) {
-// okButton.setEnabled(true);
-// } else {
-// okButton.setEnabled(false);
-// }
-// }
-// });
+ // nameText.addModifyListener(new ModifyListener() {
+ // public void modifyText(ModifyEvent arg0) {
+ // // name invalidation
+ // if (!nameText.getText().isEmpty() &&
+ // HelperClass.checkString(nameText.getText())) {
+ // okButton.setEnabled(true);
+ // } else {
+ // okButton.setEnabled(false);
+ // }
+ // }
+ // });
okButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent arg0) {
// Check Tap duplication
-// if (TapUtil.nameNotExist(nameText.getText())) {
- tapName = nameText.getText();
- dialog.close();
+ // if (TapUtil.nameNotExist(nameText.getText())) {
+ tapName = nameText.getText();
+ ifName = combo.getText();
+ dialog.close();
- TapUtil.createTapDevice(tapName, comboViewItem);
+ TapUtil.createTapDevice(tapName, ifName, comboViewItem);
-// } else {
-// new MessageDialog().openWarningDialog("Name already exist.");
-// }
+ // } else {
+ // new MessageDialog().openWarningDialog("Name already exist.");
+ // }
}
}
-
}
-
import org.tizen.emulator.manager.ui.detail.item.property.NetMacViewItem;
import org.tizen.emulator.manager.ui.detail.item.property.NetProxyViewItem;
import org.tizen.emulator.manager.ui.detail.item.property.NetTapDeviceViewItem;
+import org.tizen.emulator.manager.ui.detail.item.property.NetTapDeviceViewItemWin;
import org.tizen.emulator.manager.ui.detail.item.template.CheckLabelViewItem;
import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
import org.tizen.emulator.manager.ui.detail.item.template.FileViewItem;
continue;
} else if (name.equals(ITEM_NET_TAP_DEVICE)) {
+ if (EmulatorManager.isWin()) {
+ itemList.add(new NetTapDeviceViewItemWin(item,
+ currentLineLabel));
+ } else {
itemList.add(new NetTapDeviceViewItem(item,
currentLineLabel));
+ }
continue;
} else if (name.equals(ITEM_NET_PROXY)) {
public static final String OPT_NET_PROXY = CommonItemListFactory.ITEM_NET_PROXY;
public static final String OPT_NET_DHCP = NetIPInfoViewItem.ITEM_USE_DHCP;
-
public static Launcher getInstance() {
if (launcher == null) {
launcher = new Launcher();
isConsole = EmulatorManager.isConsoleMode();
}
-
@Override
public List<String> getLaunchCommand(VMProperty property, String path) throws VMLauncherException {
String binary;
boolean useBridgeNet = property.getPropertyValue()
.getAdvancedOptionValue(OPT_NET_CONNECT_TYPE).equals("Bridge") &&
(EmulatorManager.isLinux() || EmulatorManager.isWin() || EmulatorManager.isMac());
-
+ String tapName = null;
if (useBridgeNet) {
- String ipAddr = property.getPropertyValue()
- .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
- if (isIpAddrUsing(ipAddr))
- throw new VMLauncherException((new StringBuilder())
- .append("VM's ip address(").append(ipAddr)
- .append(") is being used by other VM.")
- .append("\nPlease modify current VM's ip address.")
- .toString());
-
- if (!EmulatorManager.isMac()) {
- String tapName = property.getPropertyValue()
+ if (EmulatorManager.isWin()) {
+ tapName = property.getPropertyValue()
.getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
if (TapUtil.nameNotExist(tapName))
throw new VMLauncherException((new StringBuilder())
.append(") is being used by other VM.")
.append("\nPlease select another tap device for current VM.")
.toString());
+ String ipAddr = property.getPropertyValue()
+ .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
+ if (isIpAddrUsing(ipAddr))
+ throw new VMLauncherException((new StringBuilder())
+ .append("VM's ip address(").append(ipAddr)
+ .append(") is being used by other VM.")
+ .append("\nPlease modify current VM's ip address.")
+ .toString());
+ }
+ if (EmulatorManager.isWin()) {
try {
if (!TapUtil.isTapInBridge(tapName)) {
MessageDialog dialog = new MessageDialog();
int res = dialog
- .openWarningAndSelectionDialog("\nTap device is not connected with Bridge." +
- "\nGuest network would work as NAT." +
- "\nKeep launching ?");
+ .openWarningAndSelectionDialog("\nTap device is not connected with Bridge."
+ + "\nGuest network would work as NAT."
+ + "\nKeep launching ?");
if (res != SWT.OK) {
throw new VMLauncherException("User canceled.");
}
}
}
}
-
/* check available port number */
portNo = new PortHelper().getPortNo();
if(portNo == -1) {
/* get MAC address of host set as guest MAC address */
String macAddr = useBridgeNet ? property.getPropertyValue()
- .getAdvancedOptionValue(OPT_NET_MAC) : SettingInfoFile
- .getMACaddr();
+ .getAdvancedOptionValue(OPT_NET_MAC) : SettingInfoFile
+ .getMACaddr();
if(macAddr.isEmpty()) {
macAddr = "52:54:00:12:34:56";
+ getIP(useBridgeNet, property)
+ " vm_name=" + property.getConfiguration().getBaseInformation().getName();
String hostIp = "10.0.2.2";
- if (useBridgeNet) {
+ if (useBridgeNet && EmulatorManager.isWin()) {
String bridgeIp = TapUtil.getBridgeIpAddr(property
.getPropertyValue().getAdvancedOptionValue(
OPT_NET_TAP_DEVICE));
cmd.add("-kernel");
cmd.add(FilePathResources.getKernelPath() + File.separator+ "bzImage." + property.getArch().toString());
cmd.add("-net");
- if (useBridgeNet) {
- if (!EmulatorManager.isMac()) {
- String tapName = property.getPropertyValue()
- .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
- if (TapUtil.nameNotExist(tapName)) {
- throw new VMLauncherException("Tap device is not exist : "
- + tapName + "\nCheck VM's tap configuration.");
- }
- cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
- } else {
- cmd.add("tap,script=" + FilePathResources.getBinPath() + File.separator + IFUP_SCRIPT +",downscript=no");
+ if (useBridgeNet && EmulatorManager.isWin()) {
+ tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+ if (TapUtil.nameNotExist(tapName)) {
+ throw new VMLauncherException("Tap device is not exist : "
+ + tapName + "\nCheck VM's tap configuration.");
}
+ cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
+ } else if (useBridgeNet && EmulatorManager.isLinux()) {
+ cmd.add("tap,script=/etc/" + IFUP_SCRIPT +",downscript=no");
+ } else if (useBridgeNet && EmulatorManager.isMac()) {
+ //TODO: need changing path to /etc/emulator-ifup.sh
+ cmd.add("tap,script=" + FilePathResources.getBinPath() + File.separator + IFUP_SCRIPT +",downscript=no");
} else {
cmd.add("user,dhcpstart=10.0.2.16");
}
private boolean isConsole = false;
private String binPath = null;
private static Launcher launcher;
-
+ public static final String IFUP_SCRIPT = "emulator-ifup.sh";
// Option names in vm_config.xml
// Add if need.
int portNo;
boolean useBridgeNet = property.getPropertyValue()
.getAdvancedOptionValue(OPT_NET_CONNECT_TYPE).equals("Bridge") &&
- (EmulatorManager.isLinux() || EmulatorManager.isWin());
-
+ (EmulatorManager.isLinux() || EmulatorManager.isWin() || EmulatorManager.isMac());
+ String tapName = null;
if (useBridgeNet) {
- String tapName = property.getPropertyValue()
- .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
- if (TapUtil.nameNotExist(tapName))
- throw new VMLauncherException((new StringBuilder())
- .append("Tap device is not exist : ").append(tapName)
- .append("\nCheck VM's tap configuration.").toString());
- if (isTapUsing(tapName))
- throw new VMLauncherException(
- (new StringBuilder())
- .append("Tap device(")
- .append(tapName)
- .append(") is being used by other VM.")
- .append("\nPlease select another tap device for current VM.")
- .toString());
- String ipAddr = property.getPropertyValue()
- .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
- if (isIpAddrUsing(ipAddr))
- throw new VMLauncherException((new StringBuilder())
- .append("VM's ip address(").append(ipAddr)
- .append(") is being used by other VM.")
- .append("\nPlease modify current VM's ip address.")
- .toString());
- try {
- if (!TapUtil.isTapInBridge(tapName)) {
- MessageDialog dialog = new MessageDialog();
- int res = dialog
- .openWarningAndSelectionDialog("\nTap device is not connected with Bridge." +
- "\nGuest network would work as NAT." +
- "\nKeep launching ?");
- if (res != SWT.OK) {
- throw new VMLauncherException("User canceled.");
+ if (EmulatorManager.isWin()) {
+ tapName = property.getPropertyValue()
+ .getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
+ if (TapUtil.nameNotExist(tapName))
+ throw new VMLauncherException((new StringBuilder())
+ .append("Tap device is not exist : ").append(tapName)
+ .append("\nCheck VM's tap configuration.").toString());
+ if (isTapUsing(tapName))
+ throw new VMLauncherException(
+ (new StringBuilder())
+ .append("Tap device(")
+ .append(tapName)
+ .append(") is being used by other VM.")
+ .append("\nPlease select another tap device for current VM.")
+ .toString());
+ String ipAddr = property.getPropertyValue()
+ .getAdvancedOptionSubValue(OPT_NET_IP_INFO, "ipAddr");
+ if (isIpAddrUsing(ipAddr))
+ throw new VMLauncherException((new StringBuilder())
+ .append("VM's ip address(").append(ipAddr)
+ .append(") is being used by other VM.")
+ .append("\nPlease modify current VM's ip address.")
+ .toString());
+ }
+ if (EmulatorManager.isWin()) {
+ try {
+ if (!TapUtil.isTapInBridge(tapName)) {
+ MessageDialog dialog = new MessageDialog();
+ int res = dialog
+ .openWarningAndSelectionDialog("\nTap device is not connected with Bridge."
+ + "\nGuest network would work as NAT."
+ + "\nKeep launching ?");
+ if (res != SWT.OK) {
+ throw new VMLauncherException("User canceled.");
+ }
+ useBridgeNet = false;
}
- useBridgeNet = false;
- }
- } catch (VMWorkerException e) {
- throw new VMLauncherException(e.getMessage());
+ } catch (VMWorkerException e) {
+ throw new VMLauncherException(e.getMessage());
+ }
}
}
/* check available port number */
+ " ip=10.0.2.16::10.0.2.2:255.255.255.0::eth0:none"
+ " vm_name=" + property.getConfiguration().getBaseInformation().getName();
String hostIp = "10.0.2.2";
- if (useBridgeNet) {
+ if (useBridgeNet && EmulatorManager.isWin()) {
String bridgeIp = TapUtil.getBridgeIpAddr(property
.getPropertyValue().getAdvancedOptionValue(
OPT_NET_TAP_DEVICE));
cmd.add(kernelOption);
/* use fileshare [non-kernel option] */
- if(isFileshare) {
+ if (isFileshare) {
cmd.add("-virtfs");
cmd.add("local,path=" + property.getConfiguration().getUsability().getFileSharing().getPath() +",security_model=none,mount_tag=fileshare");
}
cmd.add("-kernel");
cmd.add(FilePathResources.getKernelPath() + File.separator+ "bzImage." + property.getArch().toString());
cmd.add("-net");
- if (useBridgeNet) {
- String tapName = property.getPropertyValue()
+ if (useBridgeNet && EmulatorManager.isWin()) {
+ tapName = property.getPropertyValue()
.getAdvancedOptionValue(OPT_NET_TAP_DEVICE);
if (TapUtil.nameNotExist(tapName)) {
throw new VMLauncherException("Tap device is not exist : "
+ tapName + "\nCheck VM's tap configuration.");
}
cmd.add("tap,ifname=" + tapName + ",script=no,downscript=no");
+ } else if (useBridgeNet && EmulatorManager.isLinux()) {
+ cmd.add("tap,script=/etc/" + IFUP_SCRIPT +",downscript=no");
+ } else if (useBridgeNet && EmulatorManager.isMac()) {
+ //TODO: need changing path to /etc/emulator-ifup.sh
+ cmd.add("tap,script=" + FilePathResources.getBinPath() + File.separator + IFUP_SCRIPT +",downscript=no");
} else {
cmd.add("user,dhcpstart=10.0.2.16");
}