Search in sources :

Example 1 with ModemInterfaceAddressImpl

use of org.eclipse.kura.core.net.modem.ModemInterfaceAddressImpl in project kura by eclipse.

the class NetworkServiceImpl method getModemInterfaceAddresses.

private List<ModemInterfaceAddress> getModemInterfaceAddresses(String interfaceName, boolean isUp) throws KuraException {
    List<ModemInterfaceAddress> modemInterfaceAddresses = new ArrayList<ModemInterfaceAddress>();
    if (isUp) {
        ConnectionInfo conInfo = new ConnectionInfoImpl(interfaceName);
        ModemInterfaceAddressImpl modemInterfaceAddress = new ModemInterfaceAddressImpl();
        modemInterfaceAddresses.add(modemInterfaceAddress);
        try {
            LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
            if (ifconfig != null) {
                String currentNetmask = ifconfig.getInetMask();
                if (currentNetmask != null) {
                    modemInterfaceAddress.setAddress(IPAddress.parseHostAddress(ifconfig.getInetAddress()));
                    modemInterfaceAddress.setBroadcast(IPAddress.parseHostAddress(ifconfig.getInetBcast()));
                    modemInterfaceAddress.setNetmask(IPAddress.parseHostAddress(currentNetmask));
                    modemInterfaceAddress.setNetworkPrefixLength(NetworkUtil.getNetmaskShortForm(currentNetmask));
                    modemInterfaceAddress.setGateway(conInfo.getGateway());
                    modemInterfaceAddress.setDnsServers(conInfo.getDnsServers());
                    ModemConnectionStatus connectionStatus = isUp ? ModemConnectionStatus.CONNECTED : ModemConnectionStatus.DISCONNECTED;
                    modemInterfaceAddress.setConnectionStatus(connectionStatus);
                // TODO - other attributes
                } else {
                    return null;
                }
            } else {
                return null;
            }
        } catch (UnknownHostException e) {
            throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
        }
    }
    return modemInterfaceAddresses;
}
Also used : ModemConnectionStatus(org.eclipse.kura.net.modem.ModemConnectionStatus) UnknownHostException(java.net.UnknownHostException) KuraException(org.eclipse.kura.KuraException) ArrayList(java.util.ArrayList) ConnectionInfo(org.eclipse.kura.net.ConnectionInfo) ModemInterfaceAddress(org.eclipse.kura.net.modem.ModemInterfaceAddress) ModemInterfaceAddressImpl(org.eclipse.kura.core.net.modem.ModemInterfaceAddressImpl) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 KuraException (org.eclipse.kura.KuraException)1 ModemInterfaceAddressImpl (org.eclipse.kura.core.net.modem.ModemInterfaceAddressImpl)1 LinuxIfconfig (org.eclipse.kura.linux.net.util.LinuxIfconfig)1 ConnectionInfo (org.eclipse.kura.net.ConnectionInfo)1 ModemConnectionStatus (org.eclipse.kura.net.modem.ModemConnectionStatus)1 ModemInterfaceAddress (org.eclipse.kura.net.modem.ModemInterfaceAddress)1