use of org.eclipse.kura.core.net.NetworkConfigurationVisitor 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;
}
use of org.eclipse.kura.core.net.NetworkConfigurationVisitor in project kura by eclipse.
the class NetworkConfigurationServiceImpl method updated.
public synchronized void updated(Map<String, Object> properties) {
// skip the first config
if (this.m_firstConfig) {
s_logger.debug("Ignoring first configuration");
this.m_firstConfig = false;
return;
}
try {
if (properties != null) {
s_logger.debug("new properties - updating");
s_logger.debug("modified.interface.names: {}", properties.get("modified.interface.names"));
// dynamically insert the type properties..
Map<String, Object> modifiedProps = new HashMap<String, Object>();
modifiedProps.putAll(properties);
String interfaces = (String) properties.get("net.interfaces");
StringTokenizer st = new StringTokenizer(interfaces, ",");
while (st.hasMoreTokens()) {
String interfaceName = st.nextToken();
StringBuilder sb = new StringBuilder();
sb.append("net.interface.").append(interfaceName).append(".type");
NetInterfaceType type = LinuxNetworkUtil.getType(interfaceName);
if (type == NetInterfaceType.UNKNOWN) {
if (interfaceName.matches(UNCONFIGURED_MODEM_REGEX)) {
// If the interface name is in a form such as "1-3.4" (USB address), assume it is a modem
type = NetInterfaceType.MODEM;
} else {
SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
if (serialModemInfo != null && serialModemInfo.getModemName().equals(interfaceName)) {
type = NetInterfaceType.MODEM;
}
}
}
modifiedProps.put(sb.toString(), type.toString());
}
NetworkConfiguration networkConfig = new NetworkConfiguration(modifiedProps);
for (NetworkConfigurationVisitor visitor : this.m_writeVisitors) {
networkConfig.accept(visitor);
}
// raise the event because there was a change
this.m_eventAdmin.postEvent(new NetworkConfigurationChangeEvent(modifiedProps));
} else {
s_logger.debug("properties are null");
}
} catch (Exception e) {
// TODO - would still want an event if partially successful?
s_logger.error("Error updating the configuration", e);
}
}
Aggregations