Search in sources :

Example 1 with ModemInterfaceImpl

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

the class NetworkServiceImpl method getModemInterface.

private ModemInterface<ModemInterfaceAddress> getModemInterface(String interfaceName, boolean isUp, ModemDevice modemDevice) throws KuraException {
    ModemInterfaceImpl<ModemInterfaceAddress> modemInterface = new ModemInterfaceImpl<ModemInterfaceAddress>(interfaceName);
    modemInterface.setModemDevice(modemDevice);
    if (modemDevice instanceof UsbModemDevice) {
        UsbModemDevice usbModemDevice = (UsbModemDevice) modemDevice;
        SupportedUsbModemInfo supportedUsbModemInfo = null;
        supportedUsbModemInfo = SupportedUsbModemsInfo.getModem(usbModemDevice.getVendorId(), usbModemDevice.getProductId(), usbModemDevice.getProductName());
        modemInterface.setTechnologyTypes(supportedUsbModemInfo.getTechnologyTypes());
        modemInterface.setUsbDevice((UsbModemDevice) modemDevice);
    } else if (modemDevice instanceof SerialModemDevice) {
        SupportedSerialModemInfo supportedSerialModemInfo = null;
        supportedSerialModemInfo = SupportedSerialModemsInfo.getModem();
        modemInterface.setTechnologyTypes(supportedSerialModemInfo.getTechnologyTypes());
    }
    int pppNum = 0;
    if (interfaceName.startsWith("ppp")) {
        pppNum = Integer.parseInt(interfaceName.substring(3));
    }
    modemInterface.setPppNum(pppNum);
    modemInterface.setManufacturer(modemDevice.getManufacturerName());
    modemInterface.setModel(modemDevice.getProductName());
    modemInterface.setModemIdentifier(modemDevice.getProductName());
    // these properties required net.admin packages
    modemInterface.setDriver(getDriver());
    modemInterface.setDriverVersion(getDriverVersion());
    modemInterface.setFirmwareVersion(getFirmwareVersion());
    modemInterface.setSerialNumber("unknown");
    modemInterface.setLoopback(false);
    modemInterface.setPointToPoint(true);
    modemInterface.setState(getState(interfaceName, isUp));
    modemInterface.setHardwareAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
    LinuxIfconfig ifconfig = LinuxNetworkUtil.getInterfaceConfiguration(interfaceName);
    if (ifconfig != null) {
        modemInterface.setMTU(ifconfig.getMtu());
        modemInterface.setSupportsMulticast(ifconfig.isMulticast());
    }
    modemInterface.setUp(isUp);
    modemInterface.setVirtual(isVirtual());
    modemInterface.setNetInterfaceAddresses(getModemInterfaceAddresses(interfaceName, isUp));
    return modemInterface;
}
Also used : UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) ModemInterfaceImpl(org.eclipse.kura.core.net.modem.ModemInterfaceImpl) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) ModemInterfaceAddress(org.eclipse.kura.net.modem.ModemInterfaceAddress) SupportedUsbModemInfo(org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo) WifiAccessPoint(org.eclipse.kura.net.wifi.WifiAccessPoint) LinuxIfconfig(org.eclipse.kura.linux.net.util.LinuxIfconfig)

Example 2 with ModemInterfaceImpl

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

the class NetworkConfigurationServiceImpl method getNetworkConfiguration.

// @Override
// FIXME:MC Introducing a short lived cache will make startup much faster.
@Override
public synchronized NetworkConfiguration getNetworkConfiguration() throws KuraException {
    NetworkConfiguration networkConfiguration = new NetworkConfiguration();
    // Get the current values
    List<NetInterface<? extends NetInterfaceAddress>> allNetworkInterfaces = this.m_networkService.getNetworkInterfaces();
    Map<String, NetInterface<? extends NetInterfaceAddress>> allNetworkInterfacesMap = new HashMap<String, NetInterface<? extends NetInterfaceAddress>>();
    Map<String, NetInterface<? extends NetInterfaceAddress>> activeNetworkInterfacesMap = new HashMap<String, NetInterface<? extends NetInterfaceAddress>>();
    for (NetInterface<? extends NetInterfaceAddress> netInterface : allNetworkInterfaces) {
        allNetworkInterfacesMap.put(netInterface.getName(), netInterface);
        if (netInterface.isUp()) {
            activeNetworkInterfacesMap.put(netInterface.getName(), netInterface);
        }
    }
    // Create the NetInterfaceConfig objects
    if (allNetworkInterfacesMap.keySet() != null) {
        for (NetInterface<? extends NetInterfaceAddress> netInterface : allNetworkInterfacesMap.values()) {
            String interfaceName = netInterface.getName();
            try {
                // ignore mon interface
                if (interfaceName.startsWith("mon.")) {
                    continue;
                }
                // ignore redpine vlan interface
                if (interfaceName.startsWith("rpine")) {
                    continue;
                }
                // ignore usb0 for beaglebone
                if (interfaceName.startsWith("usb0") && System.getProperty("target.device").equals("beaglebone")) {
                    continue;
                }
                NetInterfaceType type = netInterface.getType();
                if (type == NetInterfaceType.UNKNOWN) {
                    if (interfaceName.matches(UNCONFIGURED_MODEM_REGEX)) {
                        // If the interface name is in a form such as "1-3.4", assume it is a modem
                        type = NetInterfaceType.MODEM;
                    } else {
                        SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
                        if (serialModemInfo != null && serialModemInfo.getModemName().equals(interfaceName)) {
                            type = NetInterfaceType.MODEM;
                        }
                    }
                }
                s_logger.debug("Getting config for {} type: {}", interfaceName, type);
                switch(type) {
                    case LOOPBACK:
                        LoopbackInterface<? extends NetInterfaceAddress> activeLoopInterface = (LoopbackInterface<? extends NetInterfaceAddress>) netInterface;
                        LoopbackInterfaceConfigImpl loopbackInterfaceConfig = null;
                        loopbackInterfaceConfig = new LoopbackInterfaceConfigImpl(activeLoopInterface);
                        networkConfiguration.addNetInterfaceConfig(loopbackInterfaceConfig);
                        break;
                    case ETHERNET:
                        EthernetInterface<? extends NetInterfaceAddress> activeEthInterface = (EthernetInterface<? extends NetInterfaceAddress>) netInterface;
                        EthernetInterfaceConfigImpl ethernetInterfaceConfig = null;
                        ethernetInterfaceConfig = new EthernetInterfaceConfigImpl(activeEthInterface);
                        networkConfiguration.addNetInterfaceConfig(ethernetInterfaceConfig);
                        break;
                    case WIFI:
                        WifiInterfaceImpl<? extends NetInterfaceAddress> activeWifiInterface = (WifiInterfaceImpl<? extends NetInterfaceAddress>) netInterface;
                        WifiInterfaceConfigImpl wifiInterfaceConfig = null;
                        wifiInterfaceConfig = new WifiInterfaceConfigImpl(activeWifiInterface);
                        networkConfiguration.addNetInterfaceConfig(wifiInterfaceConfig);
                        break;
                    case MODEM:
                        ModemInterfaceImpl<? extends NetInterfaceAddress> activeModemInterface = (ModemInterfaceImpl<? extends NetInterfaceAddress>) netInterface;
                        addPropertiesInModemInterface(activeModemInterface);
                        ModemInterfaceConfigImpl modemInterfaceConfig = null;
                        modemInterfaceConfig = new ModemInterfaceConfigImpl(activeModemInterface);
                        networkConfiguration.addNetInterfaceConfig(modemInterfaceConfig);
                        break;
                    case UNKNOWN:
                        s_logger.debug("Found interface of unknown type in current configuration: {}. Ignoring it.", interfaceName);
                        break;
                    default:
                        s_logger.debug("Unsupported type: {} - not adding to configuration. Ignoring it.", type);
                }
            } catch (Exception e) {
                s_logger.warn("Error fetching information for network interface: {}", interfaceName, e);
            }
        }
    }
    // populate the NetInterfaceConfigs
    for (NetworkConfigurationVisitor visitor : this.m_readVisitors) {
        networkConfiguration.accept(visitor);
    }
    return networkConfiguration;
}
Also used : HashMap(java.util.HashMap) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) WifiInterfaceImpl(org.eclipse.kura.core.net.WifiInterfaceImpl) KuraException(org.eclipse.kura.KuraException) ModemInterfaceImpl(org.eclipse.kura.core.net.modem.ModemInterfaceImpl) WifiInterfaceConfigImpl(org.eclipse.kura.core.net.WifiInterfaceConfigImpl) EthernetInterfaceConfigImpl(org.eclipse.kura.core.net.EthernetInterfaceConfigImpl) NetInterface(org.eclipse.kura.net.NetInterface) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) LoopbackInterface(org.eclipse.kura.net.LoopbackInterface) ModemInterfaceConfigImpl(org.eclipse.kura.core.net.modem.ModemInterfaceConfigImpl) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration) NetworkConfigurationVisitor(org.eclipse.kura.core.net.NetworkConfigurationVisitor) LoopbackInterfaceConfigImpl(org.eclipse.kura.core.net.LoopbackInterfaceConfigImpl) EthernetInterface(org.eclipse.kura.net.EthernetInterface)

Aggregations

ModemInterfaceImpl (org.eclipse.kura.core.net.modem.ModemInterfaceImpl)2 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)2 HashMap (java.util.HashMap)1 KuraException (org.eclipse.kura.KuraException)1 EthernetInterfaceConfigImpl (org.eclipse.kura.core.net.EthernetInterfaceConfigImpl)1 LoopbackInterfaceConfigImpl (org.eclipse.kura.core.net.LoopbackInterfaceConfigImpl)1 NetworkConfiguration (org.eclipse.kura.core.net.NetworkConfiguration)1 NetworkConfigurationVisitor (org.eclipse.kura.core.net.NetworkConfigurationVisitor)1 WifiInterfaceConfigImpl (org.eclipse.kura.core.net.WifiInterfaceConfigImpl)1 WifiInterfaceImpl (org.eclipse.kura.core.net.WifiInterfaceImpl)1 ModemInterfaceConfigImpl (org.eclipse.kura.core.net.modem.ModemInterfaceConfigImpl)1 SupportedUsbModemInfo (org.eclipse.kura.linux.net.modem.SupportedUsbModemInfo)1 LinuxIfconfig (org.eclipse.kura.linux.net.util.LinuxIfconfig)1 EthernetInterface (org.eclipse.kura.net.EthernetInterface)1 LoopbackInterface (org.eclipse.kura.net.LoopbackInterface)1 NetInterface (org.eclipse.kura.net.NetInterface)1 NetInterfaceAddress (org.eclipse.kura.net.NetInterfaceAddress)1 NetInterfaceType (org.eclipse.kura.net.NetInterfaceType)1 ModemInterfaceAddress (org.eclipse.kura.net.modem.ModemInterfaceAddress)1 SerialModemDevice (org.eclipse.kura.net.modem.SerialModemDevice)1