package org.kne.cloud.network.tun;

import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Enumeration;
import java.util.List;

import org.kne.util.SystemInfo;


public abstract class TUNNetworkDevice implements Closeable,AutoCloseable{
	private static final SystemInfo sysiInfo=new SystemInfo();
	public static TUNNetworkDevice createDevice(String name,String type)throws IOException {
		String osnamel=sysiInfo.getOsName().toLowerCase();
		if(osnamel.contains("windows")) {
			try {
			return new WindowsTUNNetworkDevice(name,type);
			}catch(UnsatisfiedLinkError err) {
				throw new IOException("Load native driver failed!",err);
			}
		}else 		if(osnamel.contains("linux")) {
			try {
				return new LinuxTUNNetworkDevice(name,type);
				}catch(UnsatisfiedLinkError err) {
					throw new IOException("Load native driver failed!",err);
				}
		}else {
			throw new UnsupportedOperationException("unsupport Operating System");
		}
	}
	
		public abstract boolean isOpen() ;//判断是否开启
		
	    public abstract void close() throws IOException;//关闭网卡
	    
		public abstract TUNChannel openSession() throws IOException;//开启IO会话

	    public abstract List<InetAddressRow> getIPAddress() throws IOException;//查询网卡IP和掩码

	    public abstract void setIPAddress(List<InetAddressRow> rows) throws IOException;//设置网卡IP和掩码

	    public abstract int getMTU() throws IOException;//查询MTU

	    public abstract void setMTU(int mtu) throws IOException;//设置MTU

		public abstract void setDNSAddress(List<InetAddress> address) throws IOException ;//设置DNS服务器地址
		
		public abstract List<InetAddress> getDNSAddress()throws SocketException;

}
