getSelfIfaces + generalized setLinksRTT

parent 61194f23
package netMonitor;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.google.common.collect.BiMap;
import es.bsc.compss.nfr.model.CommunicationLink;
import es.bsc.compss.nfr.model.ElasticSystem;
import es.bsc.compss.nfr.model.Node;
......@@ -10,36 +19,41 @@ import resourceManager.ResourceManager;
import utils.HardwareInfo;
public class NetMonitor extends ResourceManager {
HardwareInfo hardwareInfo;
public NetMonitor(ElasticSystem elasticSystem) {
super(elasticSystem);
//this.hardwareInfo = new HardwareInfo("enp0s3");
// this.hardwareInfo = new HardwareInfo("enp0s3");
this.hardwareInfo = new HardwareInfo();
//this.node = getNodeByIP("10.0.2.15"); //TODO: get IP as I should
// this.node = getNodeByIP("10.0.2.15"); //TODO: get IP as I should
}
public NetMonitor() {
this.hardwareInfo = new HardwareInfo();
}
public void setLinksRTT(Node node) {
List<CommunicationLink> commsList = node.getCommunicationLinks().stream().
filter(cl -> cl.getIpNode1().equals(node.getIpEth())).
collect(Collectors.toList());
commsList.stream().forEach(cl -> {
cl.setDelayRtt(hardwareInfo.getLinkRTT(cl.getIpNode2(),"eth0"));
});
//hardwareInfo.getLinksRTT();
try {
BiMap<String, String> ifaces = getSelfIfaces();
//List<CommunicationLink> commsList = node.getCommunicationLinks().stream()
// .filter(cl -> cl.getIpNode1().equals(node.getIpEth())).collect(Collectors.toList());
List<CommunicationLink> commsList = node.getCommunicationLinks().stream()
.filter(cl -> ifaces.containsValue(cl.getIpNode1())).collect(Collectors.toList());
commsList.stream().forEach(cl -> {
cl.setDelayRtt(hardwareInfo.getLinkRTT(cl.getIpNode2(), ifaces.inverse().get(cl.getIpNode1())));
});
} catch (SocketException e) {
throw new RuntimeException(e);
}
// hardwareInfo.getLinksRTT();
}
}
package nfrTool;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
......@@ -14,52 +15,49 @@ import utils.Constants;
import utils.FileUtils;
import utils.HardwareInfo;
public class CommsMonitoringTask extends TimerTask {
ResourceManagerComms resourceManager;
NetMonitor netMonitor;
FileUtils fileUtils;
HardwareInfo hardWareInfo;
public CommsMonitoringTask(ResourceManagerComms resourceManager, NetMonitor netMonitor) {
this.resourceManager = resourceManager;
this.netMonitor = netMonitor;
this.fileUtils = new FileUtils();
this.hardWareInfo = new HardwareInfo();
}
@Override
public void run() {
this.resourceManager.getConfig(Constants.CONFIG_FILE_PATH);
this.netMonitor.setLinksRTT(this.resourceManager.getNodeByIP("10.0.2.15"));
this.resourceManager.getCosts(this.resourceManager.getNodeByIP("10.0.2.15"));
System.out.println();
/*Map<String, Integer> intResultsMap = this.resourceManager
.checkThresholds(hardWareInfo.getTelemetry(), Arrays.asList("devLevel", "rttmax"), Arrays.asList("devLevel", "pllmax"));
intResultsMap.forEach((k,v) -> {
switch(v) {
case 1:
System.out.println("[-] Could not obtain comms. attributes for Interface: \" + k");
break;
case 2:
System.out.println("[?] Comms. requirements not satisfied for Interface: " + k);
Map<String, Double> cost = this.resourceManager.getCost((JSONObject) hardWareInfo.getTelemetry().query("/net_interfaces"));
System.out.println("\tApplication costs: " + cost.toString());
double maxCost = Collections.max(cost.values());
System.out.println(maxCost);
break;
case 0:
System.out.println("[+] Interface " + k + " up and Running");
break;
}
});*/
@Override
public void run() {
try {
this.resourceManager.getConfig(Constants.CONFIG_FILE_PATH);
this.netMonitor
.setLinksRTT(this.resourceManager.getNodeByIP(this.resourceManager.getSelfIfaces().get("eth0")));
this.resourceManager.getCosts(this.resourceManager.getNodeByIP(this.resourceManager.getSelfIfaces().get("eth0")));
System.out.println();
} catch (SocketException e) {
throw new RuntimeException(e);
}
/*
* Map<String, Integer> intResultsMap = this.resourceManager
* .checkThresholds(hardWareInfo.getTelemetry(), Arrays.asList("devLevel",
* "rttmax"), Arrays.asList("devLevel", "pllmax"));
*
* intResultsMap.forEach((k,v) -> {
*
* switch(v) { case 1: System.out.
* println("[-] Could not obtain comms. attributes for Interface: \" + k");
* break; case 2:
* System.out.println("[?] Comms. requirements not satisfied for Interface: " +
* k); Map<String, Double> cost = this.resourceManager.getCost((JSONObject)
* hardWareInfo.getTelemetry().query("/net_interfaces"));
* System.out.println("\tApplication costs: " + cost.toString()); double maxCost
* = Collections.max(cost.values()); System.out.println(maxCost); break; case 0:
* System.out.println("[+] Interface " + k + " up and Running"); break; } });
*/
}
}
package resourceManager;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import es.bsc.compss.nfr.model.COMPSsApplication;
import es.bsc.compss.nfr.model.ElasticSystem;
......@@ -48,6 +55,22 @@ public abstract class ResourceManager {
return nodes;
}
public BiMap<String, String> getSelfIfaces() throws SocketException {
BiMap<String, String> iFacesMap = HashBiMap.create();
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
Enumeration<InetAddress> addresses = netint.getInetAddresses();
for (InetAddress addr : Collections.list(addresses)) {
if (InetAddress.class == addr.getClass())
iFacesMap.put(netint.getName(), addr.getHostAddress());
break;
}
}
return iFacesMap;
}
public Node getNodeByIP(String ip) {
return elasticSystem.getNodes().stream().filter(node -> node.getIpEth().equals(ip)).findFirst().orElse(null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment