package cz.vutbr.feec.session.gnp;

import java.net.InetAddress;
import java.net.UnknownHostException;

import cz.vutbr.feec.session.ping.RttVectorMeasurement;

public class MeasureRttDistancesToHosts {
	
	public double[] measureRtt(LandmarkInfo[] lm) {

		int maxNumOfThreads = 10; // kolik bude merit soucasne
		int pingCount = 3; // pocet opakovani mereni RTT (vybira se minimum)
		InetAddress[] address = new InetAddress[lm.length];
		for(int i=0; i<lm.length; i++) {
			address[i] = lm[i].getAddress();
		}
		
		double[] rttVector = RttVectorMeasurement.measureRttVector(address,
				maxNumOfThreads, pingCount);

		// vypis vysledku
		for (int i = 0; i < rttVector.length; i++) {
			System.out.println("ADDR:" + address[i] + ",  RTT value:" + rttVector[i]);
		}
		return rttVector;
	}
	
	public double measureRtt(LandmarkInfo lm) {

		int maxNumOfThreads = 10; // kolik bude merit soucasne
		int pingCount = 3; // pocet opakovani mereni RTT (vybira se minimum)
		InetAddress[] address = new InetAddress[1];
		address[0] = lm.getAddress();
		
		double[] rttVector = RttVectorMeasurement.measureRttVector(address,
				maxNumOfThreads, pingCount);

		// vypis vysledku
		System.out.println("ADDR:" + address[0] + ",  RTT value:" + rttVector[0]);

		return rttVector[0];
	}
	
	public double[] measureRtt(String[] lm) {

		int maxNumOfThreads = 10; // kolik bude merit soucasne
		int pingCount = 3; // pocet opakovani mereni RTT (vybira se minimum)
		InetAddress[] address = new InetAddress[lm.length];
		for(int i=0; i<lm.length; i++) {
			try {
				address[i] = InetAddress.getByName(lm[i]);
			} catch (UnknownHostException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		double[] rttVector = RttVectorMeasurement.measureRttVector(address,
				maxNumOfThreads, pingCount);

		// vypis vysledku
		for (int i = 0; i < rttVector.length; i++) {
			System.out.println("ADDR:" + address[i] + ",  RTT value:" + rttVector[i]);
		}
		return rttVector;
	}	
}
/*
 * seznam.cz
 * IP Address  	:  	 147.229.146.241
 * Location 	: 	CZECH REPUBLIC, JIHOMORAVSKY KRAJ, BRNO
 * Latitude / Longitude 	: 	49.2 LATITUDE, 16.633 LONGITUDE
 * Connecting through 	: 	BRNO UNIVERSITY OF TECHNOLOGY
 * Time Zone 	: 	UTC +01:00
 * 
 * 
 */