use of org.eclipse.kura.net.NetConfigIP4 in project kura by eclipse.
the class NetworkAdminServiceImpl method enableInterface.
@Override
public void enableInterface(String interfaceName, boolean dhcp) throws KuraException {
try {
NetInterfaceType type = LinuxNetworkUtil.getType(interfaceName);
NetInterfaceStatus status = NetInterfaceStatus.netIPv4StatusUnknown;
WifiMode wifiMode = WifiMode.UNKNOWN;
WifiConfig wifiConfig = null;
WifiInterfaceState wifiInterfaceState = null;
if (type == NetInterfaceType.WIFI) {
List<NetInterfaceConfig<? extends NetInterfaceAddressConfig>> wifiNetInterfaceConfigs = getWifiInterfaceConfigs();
List<? extends NetInterfaceAddressConfig> wifiNetInterfaceAddressConfigs = getWifiNetInterfaceAddressConfigs(interfaceName, wifiNetInterfaceConfigs);
WifiInterfaceAddressConfig wifiInterfaceAddressConfig = getWifiAddressConfig(wifiNetInterfaceAddressConfigs);
wifiMode = wifiInterfaceAddressConfig.getMode();
wifiInterfaceState = new WifiInterfaceState(interfaceName, wifiMode);
for (NetConfig netConfig : wifiInterfaceAddressConfig.getConfigs()) {
if (netConfig instanceof NetConfigIP4) {
status = ((NetConfigIP4) netConfig).getStatus();
s_logger.debug("Interface status is set to {}", status);
} else if (netConfig instanceof WifiConfig && ((WifiConfig) netConfig).getMode() == wifiMode) {
wifiConfig = (WifiConfig) netConfig;
}
}
}
if (!LinuxNetworkUtil.hasAddress(interfaceName) || ((type == NetInterfaceType.WIFI) && (wifiInterfaceState != null) && !wifiInterfaceState.isLinkUp())) {
s_logger.info("bringing interface {} up", interfaceName);
if (type == NetInterfaceType.WIFI) {
enableWifiInterface(interfaceName, status, wifiMode, wifiConfig);
}
if (dhcp) {
renewDhcpLease(interfaceName);
} else {
LinuxNetworkUtil.enableInterface(interfaceName);
}
// if it isn't up - at least make sure the Ethernet controller is powered on
if (!LinuxNetworkUtil.hasAddress(interfaceName)) {
LinuxNetworkUtil.bringUpDeletingAddress(interfaceName);
}
} else {
s_logger.info("not bringing interface {} up because it is already up", interfaceName);
if (dhcp) {
renewDhcpLease(interfaceName);
}
}
} catch (Exception e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e);
}
}
use of org.eclipse.kura.net.NetConfigIP4 in project kura by eclipse.
the class NetworkAdminServiceImpl method updateEthernetInterfaceConfig.
@Override
public void updateEthernetInterfaceConfig(String interfaceName, boolean autoConnect, int mtu, List<NetConfig> netConfigs) throws KuraException {
NetConfigIP4 netConfig4 = null;
NetConfigIP6 netConfig6 = null;
DhcpServerConfigIP4 dhcpServerConfigIP4 = null;
FirewallAutoNatConfig natConfig = null;
boolean hadNetConfig4 = false;
boolean hadNetConfig6 = false;
boolean hadDhcpServerConfigIP4 = false;
boolean hadNatConfig = false;
if (netConfigs != null && !netConfigs.isEmpty()) {
for (NetConfig netConfig : netConfigs) {
if (!netConfig.isValid()) {
throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, "NetConfig Configuration is invalid: " + netConfig.toString());
}
if (netConfig instanceof NetConfigIP4) {
netConfig4 = (NetConfigIP4) netConfig;
} else if (netConfig instanceof NetConfigIP6) {
netConfig6 = (NetConfigIP6) netConfig;
} else if (netConfig instanceof DhcpServerConfigIP4) {
dhcpServerConfigIP4 = (DhcpServerConfigIP4) netConfig;
} else if (netConfig instanceof FirewallAutoNatConfig) {
natConfig = (FirewallAutoNatConfig) netConfig;
}
}
}
// validation
if (netConfig4 == null && netConfig6 == null) {
throw new KuraException(KuraErrorCode.CONFIGURATION_REQUIRED_ATTRIBUTE_MISSING, "Either IPv4 or IPv6 configuration must be defined");
}
List<String> modifiedInterfaceNames = new ArrayList<String>();
boolean configurationChanged = false;
ComponentConfiguration originalNetworkComponentConfiguration = ((SelfConfiguringComponent) this.m_networkConfigurationService).getConfiguration();
if (originalNetworkComponentConfiguration == null) {
s_logger.debug("Returning for some unknown reason - no existing config???");
return;
}
try {
NetworkConfiguration newNetworkConfiguration = new NetworkConfiguration(originalNetworkComponentConfiguration.getConfigurationProperties());
List<NetInterfaceConfig<? extends NetInterfaceAddressConfig>> netInterfaceConfigs = newNetworkConfiguration.getNetInterfaceConfigs();
for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig : netInterfaceConfigs) {
if (netInterfaceConfig.getName().equals(interfaceName)) {
// handle MTU
if (mtu != netInterfaceConfig.getMTU()) {
AbstractNetInterface<?> absNetInterfaceConfig = (AbstractNetInterface<?>) netInterfaceConfig;
s_logger.debug("updating MTU for {}", interfaceName);
absNetInterfaceConfig.setMTU(mtu);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
// handle autoconnect
if (autoConnect != netInterfaceConfig.isAutoConnect()) {
AbstractNetInterface<?> absNetInterfaceConfig = (AbstractNetInterface<?>) netInterfaceConfig;
s_logger.debug("updating autoConnect for {} to be {}", interfaceName, autoConnect);
absNetInterfaceConfig.setAutoConnect(autoConnect);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
// replace existing configs
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
if (netInterfaceAddressConfigs != null && !netInterfaceAddressConfigs.isEmpty()) {
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
List<NetConfig> existingNetConfigs = netInterfaceAddressConfig.getConfigs();
List<NetConfig> newNetConfigs = new ArrayList<NetConfig>();
for (NetConfig netConfig : existingNetConfigs) {
s_logger.debug("looking at existing NetConfig for {} with value: {}", interfaceName, netConfig);
if (netConfig instanceof NetConfigIP4) {
if (netConfig4 == null) {
s_logger.debug("removing NetConfig4 for {}", interfaceName);
} else {
hadNetConfig4 = true;
newNetConfigs.add(netConfig4);
if (!netConfig.equals(netConfig4)) {
s_logger.debug("updating NetConfig4 for {}", interfaceName);
s_logger.debug("Is new State DHCP? {}", netConfig4.isDhcp());
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating NetConfig4 for {} because it is unchanged", interfaceName);
}
}
} else if (netConfig instanceof NetConfig6) {
if (netConfig6 == null) {
s_logger.debug("removing NetConfig6 for {}", interfaceName);
} else {
hadNetConfig6 = true;
newNetConfigs.add(netConfig6);
if (!netConfig.equals(netConfig6)) {
s_logger.debug("updating NetConfig6 for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating NetConfig6 for {} because it is unchanged", interfaceName);
}
}
} else if (netConfig instanceof DhcpServerConfigIP4) {
if (dhcpServerConfigIP4 == null) {
s_logger.debug("removing DhcpServerConfigIP4 for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
hadDhcpServerConfigIP4 = true;
newNetConfigs.add(dhcpServerConfigIP4);
if (!netConfig.equals(dhcpServerConfigIP4)) {
s_logger.debug("updating DhcpServerConfigIP4 for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating DhcpServerConfigIP4 for {} because it is unchanged", interfaceName);
}
}
} else if (netConfig instanceof FirewallAutoNatConfig) {
if (natConfig == null) {
s_logger.debug("removing FirewallAutoNatConfig for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
hadNatConfig = true;
newNetConfigs.add(natConfig);
if (!netConfig.equals(natConfig)) {
s_logger.debug("updating FirewallAutoNatConfig for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating FirewallAutoNatConfig for {} because it is unchanged", interfaceName);
}
}
} else {
s_logger.debug("Found unsupported configuration: {}", netConfig.toString());
}
}
// add configs that did not match any in the current configuration
if (netConfigs != null && !netConfigs.isEmpty()) {
for (NetConfig netConfig : netConfigs) {
if (netConfig instanceof NetConfigIP4 && !hadNetConfig4) {
s_logger.debug("adding new NetConfig4 to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
if (netConfig instanceof NetConfigIP6 && !hadNetConfig6) {
s_logger.debug("adding new NetConfig6 to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
if (netConfig instanceof DhcpServerConfigIP4 && !hadDhcpServerConfigIP4) {
s_logger.debug("adding new DhcpServerConfigIP4 to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
if (netConfig instanceof FirewallAutoNatConfig && !hadNatConfig) {
s_logger.debug("adding new FirewallAutoNatConfig to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
}
}
for (NetConfig netConfig : newNetConfigs) {
s_logger.debug("New NetConfig: {} :: {}", netConfig.getClass().toString(), netConfig.toString());
}
// replace with new list
((NetInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(newNetConfigs);
}
}
}
}
if (configurationChanged) {
submitNetworkConfiguration(modifiedInterfaceNames, newNetworkConfiguration);
}
} catch (UnknownHostException e) {
s_logger.warn("Exception while updating EthernetInterfaceConfig", e);
}
}
use of org.eclipse.kura.net.NetConfigIP4 in project kura by eclipse.
the class NetworkAdminServiceImpl method updateModemInterfaceConfig.
@Override
public void updateModemInterfaceConfig(String interfaceName, String serialNum, String modemId, int pppNumber, boolean autoConnect, int mtu, List<NetConfig> netConfigs) throws KuraException {
NetConfigIP4 netConfig4 = null;
NetConfigIP6 netConfig6 = null;
ModemConfig modemConfig = null;
boolean hadNetConfig4 = false;
boolean hadNetConfig6 = false;
boolean hadModemConfig = false;
if (netConfigs != null && !netConfigs.isEmpty()) {
for (NetConfig netConfig : netConfigs) {
if (!netConfig.isValid()) {
throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, "NetConfig Configuration is invalid: " + netConfig.toString());
}
if (netConfig instanceof NetConfigIP4) {
netConfig4 = (NetConfigIP4) netConfig;
} else if (netConfig instanceof NetConfigIP6) {
netConfig6 = (NetConfigIP6) netConfig;
} else if (netConfig instanceof ModemConfig) {
modemConfig = (ModemConfig) netConfig;
}
}
}
// validation
if (netConfig4 == null && netConfig6 == null) {
throw new KuraException(KuraErrorCode.CONFIGURATION_REQUIRED_ATTRIBUTE_MISSING, "Either IPv4 or IPv6 configuration must be defined");
}
if (modemConfig == null) {
throw new KuraException(KuraErrorCode.CONFIGURATION_REQUIRED_ATTRIBUTE_MISSING, "Modem configuration must be defined");
}
List<String> modifiedInterfaceNames = new ArrayList<String>();
boolean configurationChanged = false;
ComponentConfiguration originalNetworkComponentConfiguration = ((SelfConfiguringComponent) this.m_networkConfigurationService).getConfiguration();
if (originalNetworkComponentConfiguration == null) {
return;
}
try {
NetworkConfiguration newNetworkConfiguration = new NetworkConfiguration(originalNetworkComponentConfiguration.getConfigurationProperties());
List<NetInterfaceConfig<? extends NetInterfaceAddressConfig>> netInterfaceConfigs = newNetworkConfiguration.getNetInterfaceConfigs();
for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig : netInterfaceConfigs) {
if (netInterfaceConfig.getName().equals(interfaceName)) {
// handle MTU
if (mtu != netInterfaceConfig.getMTU()) {
AbstractNetInterface<?> absNetInterfaceConfig = (AbstractNetInterface<?>) netInterfaceConfig;
s_logger.debug("updating MTU for {}", interfaceName);
absNetInterfaceConfig.setMTU(mtu);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
if (netInterfaceConfig instanceof ModemInterfaceConfigImpl) {
ModemInterfaceConfigImpl modemInterfaceConfig = (ModemInterfaceConfigImpl) netInterfaceConfig;
if (modemId == null) {
modemId = "";
}
// handle modem id
if (!modemId.equals(modemInterfaceConfig.getModemIdentifier())) {
s_logger.debug("updating Modem identifier: {}", modemId);
modemInterfaceConfig.setModemIdentifier(modemId);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
// handle ppp num
if (pppNumber != modemInterfaceConfig.getPppNum()) {
s_logger.debug("updating PPP number: {}", pppNumber);
modemInterfaceConfig.setPppNum(pppNumber);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
}
// replace existing configs
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
if (netInterfaceAddressConfigs != null && !netInterfaceAddressConfigs.isEmpty()) {
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
List<NetConfig> existingNetConfigs = netInterfaceAddressConfig.getConfigs();
List<NetConfig> newNetConfigs = new ArrayList<NetConfig>();
for (NetConfig netConfig : existingNetConfigs) {
s_logger.debug("looking at existing NetConfig for {} with value: {}", interfaceName, netConfig);
if (netConfig instanceof NetConfigIP4) {
if (netConfig4 == null) {
s_logger.debug("removing NetConfig4 for {}", interfaceName);
} else {
hadNetConfig4 = true;
newNetConfigs.add(netConfig4);
if (!netConfig.equals(netConfig4)) {
s_logger.debug("updating NetConfig4 for {}", interfaceName);
s_logger.debug("Is new State DHCP? {}", netConfig4.isDhcp());
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating NetConfig4 for {} because it is unchanged", interfaceName);
}
}
} else if (netConfig instanceof NetConfig6) {
if (netConfig6 == null) {
s_logger.debug("removing NetConfig6 for {}", interfaceName);
} else {
hadNetConfig6 = true;
newNetConfigs.add(netConfig6);
if (!netConfig.equals(netConfig6)) {
s_logger.debug("updating NetConfig6 for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating NetConfig6 for {} because it is unchanged", interfaceName);
}
}
} else if (netConfig instanceof ModemConfig) {
if (modemConfig == null) {
s_logger.debug("removing ModemConfig for {}", interfaceName);
} else {
hadModemConfig = true;
newNetConfigs.add(modemConfig);
if (!netConfig.equals(modemConfig)) {
s_logger.debug("updating ModemConfig for {}", interfaceName);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
} else {
s_logger.debug("not updating ModemConfig for {} because it is unchanged", interfaceName);
}
}
} else {
s_logger.debug("Found unsupported configuration: {}", netConfig.toString());
}
}
// add configs that did not match any in the current configuration
if (netConfigs != null && !netConfigs.isEmpty()) {
for (NetConfig netConfig : netConfigs) {
if (netConfig instanceof NetConfigIP4 && !hadNetConfig4) {
s_logger.debug("adding new NetConfig4 to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
if (netConfig instanceof NetConfigIP6 && !hadNetConfig6) {
s_logger.debug("adding new NetConfig6 to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
if (netConfig instanceof ModemConfig && !hadModemConfig) {
s_logger.debug("adding new ModemConfig to existing config for {}", interfaceName);
newNetConfigs.add(netConfig);
configurationChanged = true;
if (!modifiedInterfaceNames.contains(interfaceName)) {
modifiedInterfaceNames.add(interfaceName);
}
}
}
}
for (NetConfig netConfig : newNetConfigs) {
s_logger.debug("Current NetConfig: {} :: {}", netConfig.getClass(), netConfig);
}
// replace with new list
((ModemInterfaceAddressConfigImpl) netInterfaceAddressConfig).setNetConfigs(newNetConfigs);
}
}
}
newNetworkConfiguration.addNetInterfaceConfig(netInterfaceConfig);
}
if (configurationChanged) {
submitNetworkConfiguration(modifiedInterfaceNames, newNetworkConfiguration);
}
} catch (UnknownHostException e) {
s_logger.warn("Exception while updating ModemInterfaceConfig", e);
}
}
use of org.eclipse.kura.net.NetConfigIP4 in project kura by eclipse.
the class NetworkConfiguration method recomputeNetworkProperties.
// ---------------------------------------------------------------
//
// Private Methods
//
// ---------------------------------------------------------------
private void recomputeNetworkProperties() {
Map<String, Object> properties = new HashMap<String, Object>();
String netIfPrefix = null;
String netIfReadOnlyPrefix = null;
String netIfConfigPrefix = null;
StringBuilder sbPrefix = null;
StringBuilder sbInterfaces = new StringBuilder();
if (this.m_modifiedInterfaceNames != null && !this.m_modifiedInterfaceNames.isEmpty()) {
StringBuilder sb = new StringBuilder();
String prefix = "";
for (String interfaceName : this.m_modifiedInterfaceNames) {
sb.append(prefix);
prefix = ",";
sb.append(interfaceName);
}
String result = sb.toString();
s_logger.debug("Set modified interface names: {}", result);
properties.put("modified.interface.names", result);
}
Iterator<String> it = this.m_netInterfaceConfigs.keySet().iterator();
while (it.hasNext()) {
NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig = this.m_netInterfaceConfigs.get(it.next());
// add the interface to the list of interface found in the platform
if (sbInterfaces.length() != 0) {
sbInterfaces.append(",");
}
sbInterfaces.append(netInterfaceConfig.getName());
// build the prefixes for all the properties associated with this interface
sbPrefix = new StringBuilder("net.interface.").append(netInterfaceConfig.getName()).append(".");
netIfReadOnlyPrefix = sbPrefix.toString();
netIfPrefix = sbPrefix.append("config.").toString();
netIfConfigPrefix = sbPrefix.toString();
// add the properties of the interface
properties.put(netIfReadOnlyPrefix + "type", netInterfaceConfig.getType().toString());
properties.put(netIfPrefix + "name", netInterfaceConfig.getName());
if (netInterfaceConfig.getState() != null) {
properties.put(netIfPrefix + "state", netInterfaceConfig.getState().toString());
}
properties.put(netIfPrefix + "autoconnect", netInterfaceConfig.isAutoConnect());
properties.put(netIfPrefix + "mtu", netInterfaceConfig.getMTU());
properties.put(netIfReadOnlyPrefix + "driver", netInterfaceConfig.getDriver());
properties.put(netIfReadOnlyPrefix + "driver.version", netInterfaceConfig.getDriverVersion());
properties.put(netIfReadOnlyPrefix + "firmware.version", netInterfaceConfig.getFirmwareVersion());
properties.put(netIfReadOnlyPrefix + "mac", NetUtil.hardwareAddressToString(netInterfaceConfig.getHardwareAddress()));
properties.put(netIfReadOnlyPrefix + "loopback", netInterfaceConfig.isLoopback());
properties.put(netIfReadOnlyPrefix + "ptp", netInterfaceConfig.isPointToPoint());
properties.put(netIfReadOnlyPrefix + "up", netInterfaceConfig.isUp());
properties.put(netIfReadOnlyPrefix + "virtual", netInterfaceConfig.isVirtual());
// usb
if (netInterfaceConfig.getUsbDevice() != null) {
UsbDevice usbDev = netInterfaceConfig.getUsbDevice();
properties.put(netIfReadOnlyPrefix + "usb.vendor.id", usbDev.getVendorId());
properties.put(netIfReadOnlyPrefix + "usb.vendor.name", usbDev.getManufacturerName());
properties.put(netIfReadOnlyPrefix + "usb.product.id", usbDev.getProductId());
properties.put(netIfReadOnlyPrefix + "usb.product.name", usbDev.getProductName());
properties.put(netIfReadOnlyPrefix + "usb.busNumber", usbDev.getUsbBusNumber());
properties.put(netIfReadOnlyPrefix + "usb.devicePath", usbDev.getUsbDevicePath());
}
// custom readonly props for Ethernet and Wifi
if (netInterfaceConfig instanceof EthernetInterfaceConfigImpl) {
properties.put(netIfReadOnlyPrefix + "eth.link.up", ((EthernetInterfaceConfigImpl) netInterfaceConfig).isLinkUp());
} else if (netInterfaceConfig instanceof WifiInterfaceConfigImpl) {
EnumSet<Capability> capabilities = ((WifiInterfaceConfigImpl) netInterfaceConfig).getCapabilities();
if (capabilities != null && !capabilities.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (Capability capability : capabilities) {
sb.append(capability.toString());
sb.append(",");
}
String capabilitiesString = sb.toString();
capabilitiesString = capabilitiesString.substring(0, capabilitiesString.length() - 1);
properties.put(netIfReadOnlyPrefix + "wifi.capabilities", capabilitiesString);
}
}
// add wifi properties
if (netInterfaceConfig.getType() == NetInterfaceType.WIFI) {
// capabilities
StringBuilder sbCapabilities = new StringBuilder();
EnumSet<Capability> capabilities = ((WifiInterface) netInterfaceConfig).getCapabilities();
if (capabilities != null) {
Iterator<Capability> it2 = ((WifiInterface) netInterfaceConfig).getCapabilities().iterator();
while (it2.hasNext()) {
sbCapabilities.append(it2.next().name()).append(" ");
}
properties.put(netIfReadOnlyPrefix + "wifi.capabilities", sbCapabilities.toString());
}
}
// add modem properties
if (netInterfaceConfig.getType() == NetInterfaceType.MODEM) {
String delim;
// revision
StringBuffer revisionIdBuf = new StringBuffer();
String[] revisionId = ((ModemInterface<?>) netInterfaceConfig).getRevisionId();
if (revisionId != null) {
delim = null;
for (String rev : revisionId) {
if (delim != null) {
revisionIdBuf.append(delim);
}
revisionIdBuf.append(rev);
delim = ",";
}
}
// technology types
StringBuffer techTypesBuf = new StringBuffer();
List<ModemTechnologyType> techTypes = ((ModemInterface<?>) netInterfaceConfig).getTechnologyTypes();
if (techTypes != null) {
delim = null;
for (ModemTechnologyType techType : techTypes) {
if (delim != null) {
techTypesBuf.append(delim);
}
techTypesBuf.append(techType.toString());
delim = ",";
}
}
ModemPowerMode powerMode = ModemPowerMode.UNKNOWN;
if (((ModemInterface<?>) netInterfaceConfig).getPowerMode() != null) {
powerMode = ((ModemInterface<?>) netInterfaceConfig).getPowerMode();
}
properties.put(netIfReadOnlyPrefix + "manufacturer", ((ModemInterface<?>) netInterfaceConfig).getManufacturer());
properties.put(netIfReadOnlyPrefix + "model", ((ModemInterface<?>) netInterfaceConfig).getModel());
properties.put(netIfReadOnlyPrefix + "revisionId", revisionIdBuf.toString());
properties.put(netIfReadOnlyPrefix + "serialNum", ((ModemInterface<?>) netInterfaceConfig).getSerialNumber());
properties.put(netIfReadOnlyPrefix + "technologyTypes", techTypesBuf.toString());
properties.put(netIfConfigPrefix + "identifier", ((ModemInterface<?>) netInterfaceConfig).getModemIdentifier());
properties.put(netIfConfigPrefix + "powerMode", powerMode.toString());
properties.put(netIfConfigPrefix + "pppNum", ((ModemInterface<?>) netInterfaceConfig).getPppNum());
properties.put(netIfConfigPrefix + "poweredOn", ((ModemInterface<?>) netInterfaceConfig).isPoweredOn());
}
for (NetInterfaceAddress nia : netInterfaceConfig.getNetInterfaceAddresses()) {
String typePrefix = "ip4.";
if (nia != null) {
if (nia.getAddress() != null) {
properties.put(netIfReadOnlyPrefix + typePrefix + "address", nia.getAddress().getHostAddress());
}
if (nia.getBroadcast() != null) {
properties.put(netIfReadOnlyPrefix + typePrefix + "broadcast", nia.getBroadcast().getHostAddress());
}
if (nia.getGateway() != null) {
properties.put(netIfReadOnlyPrefix + typePrefix + "gateway", nia.getGateway().getHostAddress());
}
if (nia.getNetmask() != null) {
properties.put(netIfReadOnlyPrefix + typePrefix + "netmask", nia.getNetmask().getHostAddress());
}
if (nia.getNetmask() != null) {
properties.put(netIfReadOnlyPrefix + typePrefix + "prefix", Short.valueOf(nia.getNetworkPrefixLength()));
}
if (nia.getDnsServers() != null) {
StringBuilder dnsServers = new StringBuilder();
for (IPAddress dnsServer : nia.getDnsServers()) {
if (dnsServers.length() != 0) {
dnsServers.append(",");
}
dnsServers.append(dnsServer);
}
properties.put(netIfReadOnlyPrefix + typePrefix + "dnsServers", dnsServers.toString());
}
// Wifi interface address
if (nia instanceof WifiInterfaceAddress) {
// access point
WifiAccessPoint wap = ((WifiInterfaceAddress) nia).getWifiAccessPoint();
if (wap != null) {
/*
* TODO: need fields to reflect current state?
* properties.put(sbNetIfPrefix+"wifi.ssid", wap.getSSID());
* properties.put(sbNetIfPrefix+"wifi.mode", wap.getMode());
*/
}
long bitrate = ((WifiInterfaceAddress) nia).getBitrate();
properties.put(netIfReadOnlyPrefix + "wifi.bitrate", Long.valueOf(bitrate));
WifiMode wifiMode;
if (((WifiInterfaceAddress) nia).getMode() != null) {
wifiMode = ((WifiInterfaceAddress) nia).getMode();
} else {
wifiMode = WifiMode.UNKNOWN;
}
properties.put(netIfPrefix + "wifi.mode", wifiMode.toString());
}
// Modem interface address
if (nia instanceof ModemInterfaceAddress) {
if (((ModemInterfaceAddress) nia).getConnectionType() != null) {
properties.put(netIfConfigPrefix + "connection.type", ((ModemInterfaceAddress) nia).getConnectionType().toString());
}
if (((ModemInterfaceAddress) nia).getConnectionStatus() != null) {
properties.put(netIfConfigPrefix + "connection.status", ((ModemInterfaceAddress) nia).getConnectionStatus().toString());
}
}
}
}
// add the properties of the network configurations associated to the interface
List<? extends NetInterfaceAddressConfig> netInterfaceAddressConfigs = netInterfaceConfig.getNetInterfaceAddresses();
s_logger.trace("netInterfaceAddressConfigs.size() for {}: {}", netInterfaceConfig.getName(), netInterfaceAddressConfigs.size());
for (NetInterfaceAddressConfig netInterfaceAddressConfig : netInterfaceAddressConfigs) {
List<NetConfig> netConfigs = netInterfaceAddressConfig.getConfigs();
if (netConfigs != null) {
s_logger.trace("netConfigs.size(): {}", netConfigs.size());
for (NetConfig netConfig : netConfigs) {
if (netConfig instanceof WifiConfig) {
s_logger.trace("adding netconfig WifiConfigIP4 for {}", netInterfaceConfig.getName());
addWifiConfigIP4Properties((WifiConfig) netConfig, netIfConfigPrefix, properties);
} else if (netConfig instanceof ModemConfig) {
s_logger.trace("adding netconfig ModemConfig for {}", netInterfaceConfig.getName());
addModemConfigProperties((ModemConfig) netConfig, netIfConfigPrefix, properties);
} else if (netConfig instanceof NetConfigIP4) {
s_logger.trace("adding netconfig NetConfigIP4 for {}", netInterfaceConfig.getName());
addNetConfigIP4Properties((NetConfigIP4) netConfig, netIfConfigPrefix, properties);
/*
* Iterator<String> it2 = properties.keySet().iterator();
* while(it2.hasNext()) {
* String key = it2.next();
* System.out.println("\t\t\t"+key+"="+properties.get(key));
* }
*/
} else if (netConfig instanceof NetConfigIP6) {
s_logger.trace("adding netconfig NetConfigIP6 for {}", netInterfaceConfig.getName());
addNetConfigIP6Properties((NetConfigIP6) netConfig, netIfConfigPrefix, properties);
/*
* Iterator<String> it = properties.keySet().iterator();
* while(it.hasNext()) {
* String key = it.next();
* System.out.println("\t\t\t"+key+"="+properties.get(key));
* }
*/
} else if (netConfig instanceof DhcpServerConfig4) {
s_logger.trace("adding netconfig DhcpServerConfig4 for {}", netInterfaceConfig.getName());
addDhcpServerConfig4((DhcpServerConfig4) netConfig, netIfConfigPrefix, properties);
} else if (netConfig instanceof FirewallAutoNatConfig) {
s_logger.trace("adding netconfig FirewallNatConfig for {}", netInterfaceConfig.getName());
addFirewallNatConfig((FirewallAutoNatConfig) netConfig, netIfConfigPrefix, properties);
}
}
}
}
}
properties.put("net.interfaces", sbInterfaces.toString());
this.m_properties = properties;
}
Aggregations