From 0dffd904d71e88f6708e0bec5ab0ce2233525e8a Mon Sep 17 00:00:00 2001 From: brianhigh Date: Tue, 5 Jan 2016 23:07:10 -0800 Subject: [PATCH] Rewrite to be more automated. --- data/home_cern/ipinfo.csv | 10 ++ data/home_cern/route.csv | 12 ++ data/home_cern/route.txt | 16 ++ data/udrive_uw_edu/ipinfo.csv | 4 - data/udrive_uw_edu/route.csv | 5 - data/udrive_uw_edu/route_4225roo_linux.txt | 4 - data/udrive_uw_edu/route_4225roo_windows.txt | 10 -- data/udrive_uw_edu/route_mhsf_osx.txt | 4 - plot_route.R | 160 ++++++++----------- 9 files changed, 103 insertions(+), 122 deletions(-) create mode 100644 data/home_cern/ipinfo.csv create mode 100644 data/home_cern/route.csv create mode 100644 data/home_cern/route.txt delete mode 100644 data/udrive_uw_edu/ipinfo.csv delete mode 100644 data/udrive_uw_edu/route.csv delete mode 100644 data/udrive_uw_edu/route_4225roo_linux.txt delete mode 100644 data/udrive_uw_edu/route_4225roo_windows.txt delete mode 100644 data/udrive_uw_edu/route_mhsf_osx.txt diff --git a/data/home_cern/ipinfo.csv b/data/home_cern/ipinfo.csv new file mode 100644 index 0000000..86eb216 --- /dev/null +++ b/data/home_cern/ipinfo.csv @@ -0,0 +1,10 @@ +"ip","country_code","country_name","region_code","region_name","city","zip_code","time_zone","latitude","longitude","metro_code","mean_rtt" +"128.95.230.102","US","United States","WA","Washington","Seattle","98105","America/Los_Angeles",47.6606,-122.2919,"819",0 +"209.124.181.134","US","United States","WA","Washington","Seattle","98105","America/Los_Angeles",47.6606,-122.2919,"819",0 +"64.57.28.53","US","United States","MI","Michigan","Ann Arbor","48104","America/Detroit",42.2734,-83.7133,"505",0 +"198.71.45.24","US","United States","MI","Michigan","Ann Arbor","48104","America/Detroit",42.2734,-83.7133,"505",18.886 +"198.71.45.18","US","United States","MI","Michigan","Ann Arbor","48104","America/Detroit",42.2734,-83.7133,"505",34.893 +"198.71.45.14","US","United States","MI","Michigan","Ann Arbor","48104","America/Detroit",42.2734,-83.7133,"505",46.863 +"192.91.246.126","CH","Switzerland","GE","Geneva","Geneva","1205","Europe/Zurich",46.1956,6.1481,"0",182.871 +"192.65.196.38","CH","Switzerland","GE","Geneva","Geneva","1205","Europe/Zurich",46.1956,6.1481,"0",166.646333333333 +"188.184.37.205","CH","Switzerland","GE","Geneva","Meyrin","1217","Europe/Zurich",46.2324,6.0502,"0",164.322 diff --git a/data/home_cern/route.csv b/data/home_cern/route.csv new file mode 100644 index 0000000..b58c94c --- /dev/null +++ b/data/home_cern/route.csv @@ -0,0 +1,12 @@ +"addr","mean_rtt","rtt.1","rtt.2","rtt.3" +"128.95.230.102",0,0,0,0 +"10.132.1.73",0,0,0,0 +"10.132.1.75",0,0,0,0 +"209.124.181.134",0,0,0,0 +"64.57.28.53",0,0,0,0 +"198.71.45.24",18.886,18.886,18.886,18.886 +"198.71.45.18",34.893,34.893,34.893,34.893 +"198.71.45.14",46.863,46.863,46.863,46.863 +"192.91.246.126",182.871,182.871,182.871,182.871 +"192.65.196.38",166.646333333333,163.985,167.977,167.977 +"188.184.37.205",164.322,163.993,163.993,164.98 diff --git a/data/home_cern/route.txt b/data/home_cern/route.txt new file mode 100644 index 0000000..38853d7 --- /dev/null +++ b/data/home_cern/route.txt @@ -0,0 +1,16 @@ +traceroute to home.cern (188.184.37.205), 30 hops max, 60 byte packets + 1 128.95.230.102 0.000 ms 0.000 ms 0.000 ms + 2 10.132.1.73 0.000 ms 0.000 ms 0.000 ms + 3 10.132.1.75 0.000 ms 0.000 ms 0.000 ms + 4 209.124.181.134 0.000 ms 0.000 ms 0.000 ms + 5 64.57.28.53 0.000 ms 0.000 ms 0.000 ms + 6 198.71.45.24 18.886 ms 18.886 ms 18.886 ms + 7 198.71.45.18 34.893 ms 34.893 ms 34.893 ms + 8 198.71.45.14 46.863 ms 46.863 ms 46.863 ms + 9 192.91.246.126 182.871 ms 182.871 ms 182.871 ms +10 * * * +11 * * * +12 192.65.196.38 163.985 ms 167.977 ms 167.977 ms +13 * * * +14 * * * +15 188.184.37.205 163.993 ms 163.993 ms 164.980 ms diff --git a/data/udrive_uw_edu/ipinfo.csv b/data/udrive_uw_edu/ipinfo.csv deleted file mode 100644 index 2b318eb..0000000 --- a/data/udrive_uw_edu/ipinfo.csv +++ /dev/null @@ -1,4 +0,0 @@ -"ip","country_code","country_name","region_code","region_name","city","zip_code","time_zone","latitude","longitude","metro_code","mean_rtt" -"128.95.230.102","US","United States","WA","Washington","Seattle","98105","America/Los_Angeles",47.6606,-122.2919,"819",1 -"128.95.155.131","US","United States","WA","Washington","Seattle","98105","America/Los_Angeles",47.6606,-122.2919,"819",7.33333333333333 -"128.95.155.161","US","United States","WA","Washington","Seattle","98105","America/Los_Angeles",47.6606,-122.2919,"819",1 diff --git a/data/udrive_uw_edu/route.csv b/data/udrive_uw_edu/route.csv deleted file mode 100644 index 55ec858..0000000 --- a/data/udrive_uw_edu/route.csv +++ /dev/null @@ -1,5 +0,0 @@ -"addr","mean_rtt" -"128.95.230.102",1 -"10.132.0.76",1 -"128.95.155.131",7.33333333333333 -"128.95.155.161",1 diff --git a/data/udrive_uw_edu/route_4225roo_linux.txt b/data/udrive_uw_edu/route_4225roo_linux.txt deleted file mode 100644 index ac8b9cc..0000000 --- a/data/udrive_uw_edu/route_4225roo_linux.txt +++ /dev/null @@ -1,4 +0,0 @@ -|1|128.95.230.102|0.000|ms|0.000|ms|0.000|ms -|2|10.132.0.76|0.000|ms|0.000|ms|0.000|ms -|3|128.95.155.195|0.000|ms|0.000|ms|0.000|ms -|4|128.95.155.222|0.000|ms|0.000|ms|0.000|ms diff --git a/data/udrive_uw_edu/route_4225roo_windows.txt b/data/udrive_uw_edu/route_4225roo_windows.txt deleted file mode 100644 index 4b85889..0000000 --- a/data/udrive_uw_edu/route_4225roo_windows.txt +++ /dev/null @@ -1,10 +0,0 @@ - -Tracing route to udrive.uw.edu [128.95.155.222] -over a maximum of 30 hops: - - 1 1 ms <1 ms <1 ms 128.95.230.102 - 2 1 ms 2 ms 1 ms 10.132.0.76 - 3 <1 ms <1 ms <1 ms 128.95.155.195 - 4 1 ms 1 ms <1 ms 128.95.155.222 - -Trace complete. diff --git a/data/udrive_uw_edu/route_mhsf_osx.txt b/data/udrive_uw_edu/route_mhsf_osx.txt deleted file mode 100644 index f6bf7b5..0000000 --- a/data/udrive_uw_edu/route_mhsf_osx.txt +++ /dev/null @@ -1,4 +0,0 @@ -|1|128.95.21.102|0.615|ms|0.263|ms|0.253|ms -|2|10.132.0.82|0.903|ms|0.883|ms|0.853|ms -|3|128.95.155.195|0.407|ms|0.370|ms|0.357|ms -|4|128.95.155.222|0.553|ms|0.396|ms|0.388|ms diff --git a/plot_route.R b/plot_route.R index 1cd420b..9d9fb00 100644 --- a/plot_route.R +++ b/plot_route.R @@ -1,96 +1,66 @@ -# Plot network hops to reach hosts by round-trip time (rtt) with error bars. - -# Data files were created with these commands from the Terminal (console): -# -# DOS> tracert -d example.com > "route.txt" -# -# bash-linux$ sudo traceroute -I \ -# -n example.com 2>&1 | sed 's/\*/* ms/g' | tr -s " " "|" | \ -# tail -n +2 > "route.txt" -# -# bash-osx$ traceroute -I \ -# -n example.com 2>&1 | sed 's/\*/* ms/g' | tr -s " " "|" | \ -# tail -n +3 > "route.txt" - -# Function to install packages as needed then load them into R. -load_packages <- function(pkgs) { - # Install packages (if necessary) and load them into memory. - - for (pkg in pkgs) { - if (! suppressWarnings(suppressPackageStartupMessages(require( - pkg, character.only=TRUE, quietly=TRUE))) ) { - install.packages(pkg, repos="http://cran.fhcrc.org", - dependencies=TRUE) - if (! suppressWarnings(suppressPackageStartupMessages(require( - pkg, character.only=TRUE, quietly=TRUE))) ) { - stop(paste0(c("Can't load package: ", pkg, "!"), - collapse = "")) - } - } - } -} - -# Function to import route hop data from text files. -import.route <- function(fname, troute.type, host) { - # We have two different formats, so parse differently for each type. - if (troute.type == "tracert") { - route <- read.fwf(fname, - widths=c(3, 6, 3, 6, 3, 6, 3, 16), - header=F, skip=4, strip.white=TRUE, - stringsAsFactors=F) - route <- route[,c(1, 2, 4, 6, 8)] - route <- route[complete.cases(route),] - names(route) <- c("hop", "query.1", "query.2", "query.3", "ip.addr") - route[,2:4] <- as.numeric(gsub("[<*]", "", as.matrix(route[2:4]))) - } else { - route <- read.table(fname, sep="|", header=F, stringsAsFactors=F) - route <- route[,c(2, 3, 4, 6, 8)] - route <- route[complete.cases(route),] - names(route) <- c("hop", "ip.addr", "query.1", "query.2", "query.3") - route[,3:5] <- as.numeric(gsub("<", "", as.matrix(route[3:5]))) - route <- route[, c(1, 3:5, 2)] - } - - route$hop <- sprintf("%02d", as.numeric(route$hop)) - route$hop <- as.factor(route$hop) - route.long <- melt(route, id=c("hop","ip.addr")) - names(route.long) <- c("hop", "ip.addr", "query", "rtt") - route.long$host <- rep(host, nrow(route.long)) - route.long$query <- as.factor(gsub("query.", "", route.long$query, - fixed = TRUE)) - return(na.omit(as.data.table(route.long))) -} - -# Load packages needed for this script. -load_packages(c("reshape", "Rmisc", "ggplot2", "data.table")) - -# Define information about the data files to be used as route data. -files <- c("data/www_gov_za/route.txt", - "data/www_gov_bb/route.txt", - "data/www_gov_ro/route.txt", - "data/www_cubagob_cu/route.txt") -types <- c("tracert", "tracert", "tracert", "tracert") -hosts <- c("www.gov.za", "www.gov.bb", "www.gov.ro", "www.cubagob.cu") -route.info <- cbind(file=files, type=types, host=hosts) - -# Process the routes using the route info. -routes <- rbindlist(lapply(1:nrow(route.info), - function(n) import.route(files[n], types[n], hosts[n]))) - -# Combine all route data into a singe data table. -route.summary <- summarySE(routes, measurevar="rtt", groupvars=c("host", "hop")) - - -# Make a basic line and point graph. - -# Plotting code (below) based on this example: -# http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2) - -# Use 95% confidence interval for error bars. -g <- ggplot(route.summary, aes(x=hop, y=rtt, colour=host)) + - geom_errorbar(aes(ymin=rtt-ci, ymax=rtt+ci), width=.1) + - geom_line(aes(group=host)) + - geom_point() + theme_bw() + - xlab("network hop") + ylab("round-trip time (ms)") + - ggtitle("Round-trip time (ms) per network hop") +# Plot network hops to reach hosts by round-trip time (rtt) with error bars. + +# Function to install packages as needed then load them into R. +load_packages <- function(pkgs) { + # Install packages (if necessary) and load them into memory. + + for (pkg in pkgs) { + if (! suppressWarnings(suppressPackageStartupMessages(require( + pkg, character.only=TRUE, quietly=TRUE))) ) { + install.packages(pkg, repos="http://cran.fhcrc.org", + dependencies=TRUE) + if (! suppressWarnings(suppressPackageStartupMessages(require( + pkg, character.only=TRUE, quietly=TRUE))) ) { + stop(paste0(c("Can't load package: ", pkg, "!"), + collapse = "")) + } + } + } +} + +# Function to import and tidy route hop data from CSV file. +import.route <- function(fname, host) { + if (file.exists(fname) == TRUE) { + route <- read.table(fname, sep=",", header=T, stringsAsFactors=F) + route$hop <- row.names(route) + route$mean_rtt <- NULL + route$hop <- sprintf("%02d", as.numeric(route$hop)) + route$hop <- as.factor(route$hop) + route.long <- melt(route, id=c("hop","addr")) + names(route.long) <- c("hop", "addr", "query", "rtt") + route.long$host <- rep(host, nrow(route.long)) + route.long$query <- as.factor(gsub("rtt.", "", route.long$query, + fixed = TRUE)) + return(na.omit(as.data.table(route.long))) + } else { + return(as.data.table(NULL)) + } +} + +# Load packages needed for this script. +load_packages(c("reshape", "Rmisc", "ggplot2", "data.table")) + +# Search the "data" folder for "route.csv" files. +hosts <- gsub("_", ".", list.dirs('data', recursive=FALSE, full.names=FALSE)) +files <- gsub("$", "/route.csv", list.dirs('data', recursive=FALSE)) + +# Process the routes using the route info. +routes <- rbindlist(lapply(1:length(files), + function(n) import.route(files[n], hosts[n]))) + +# Combine all route data into a singe data table. +route.summary <- summarySE(routes, measurevar="rtt", groupvars=c("host", "hop")) + +# Make a basic line and point graph with error bars. + +# Plotting code (below) based on this example: +# http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2) + +# Use 95% confidence interval for error bars. +g <- ggplot(route.summary, aes(x=hop, y=rtt, colour=host)) + + geom_errorbar(aes(ymin=rtt-ci, ymax=rtt+ci), width=.1, size=2) + + geom_line(aes(group=host), size=2) + + theme_bw() + + xlab("network hop") + ylab("round-trip time (ms)") + + ggtitle("Round-trip time (ms) per network hop") plot(g) \ No newline at end of file