Skip to content

Commit fc04600

Browse files
committed
intial commit
0 parents  commit fc04600

21 files changed

+425
-0
lines changed

.Rbuildignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^\.travis\.yml$
4+
^README\.*md$
5+
^README\.*html$
6+
^NOTES\.*Rmd$
7+
^NOTES\.*html$

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Rproj
5+
src/*.o
6+
src/*.so
7+
src/*.dll

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: r
2+
warnings_are_errors: true
3+
sudo: required
4+
5+
apt_packages:
6+
- binutils
7+
- libproj-dev
8+
- gdal-bin
9+
10+
env:
11+
global:
12+
- CRAN: http://cran.rstudio.com
13+
14+
notifications:
15+
email:
16+
on_success: change
17+
on_failure: change

DESCRIPTION

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Package: bgpdump
2+
Type: Package
3+
Title: Tools to Retrieve and Process 'BGP' Files
4+
Version: 0.1.0
5+
Date: 2016-07-18
6+
Author: Bob Rudis (@hrbrmstr)
7+
Maintainer: Bob Rudis <bob@rudis.net>
8+
Description: A compendium of utilities to retrieve and process BGP files. Presently supports
9+
download and converting MRT v2 files from RouteViews.
10+
URL: http://github.com/hrbrmstr/bgpdump
11+
BugReports: https://github.com/hrbrmstr/bgpdump/issues
12+
License: AGPL
13+
Suggests:
14+
testthat
15+
Depends:
16+
R (>= 3.0.0)
17+
Imports:
18+
purrr,
19+
Rcpp,
20+
tibble,
21+
curl
22+
LinkingTo: Rcpp
23+
RoxygenNote: 5.0.1

NAMESPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(get_latest_rib)
4+
export(rib_to_asn_table)
5+
import(tibble)
6+
importFrom(Rcpp,sourceCpp)
7+
importFrom(curl,curl_download)
8+
useDynLib(bgpdump)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0.1.0
2+
* Initial release

R/RcppExports.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file was generated by Rcpp::compileAttributes
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#' Convert RouteViews RIB (bgpdump table dump v2) to subnet/asn map
5+
#'
6+
#' It presently ONLY works with the modern RouteViews v2 format.
7+
#'
8+
#' @param path path to RouteViews RIB (can be compressed)
9+
#' @param progress if \code{TRUE} output a message every 50,000 records.
10+
#' @return \code{tbl_df} (tibble) or \code{NULL}
11+
#' @export
12+
rib_to_asn_table <- function(path, progress = FALSE) {
13+
.Call('bgpdump_rib_to_asn_table', PACKAGE = 'bgpdump', path, progress)
14+
}
15+

R/bgpdump-package.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#' Tools to work with 'BGP' 'dump' files
2+
#'
3+
#' A compendium of utilities to retrieve and process BGP files. Presently supports
4+
#' download and converting MRT v2 files from RouteViews.
5+
#'
6+
#' @name bgpdump
7+
#' @docType package
8+
#' @author Bob Rudis (@@hrbrmstr)
9+
#' @useDynLib bgpdump
10+
#' @import tibble
11+
#' @importFrom curl curl_download
12+
#' @importFrom Rcpp sourceCpp
13+
NULL

R/routeviews.r

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#' Retrieve the latest RouteViews RIB file
2+
#'
3+
#' @param output_dir where the downloaded RIB should be stored
4+
#' @param .progress show download progress (default: \code{FALSE})
5+
#' @note this function handles the UTC time zone adjustment properly
6+
#' @return the filename (invisibly)
7+
#' @export
8+
get_latest_rib <- function(output_dir=".", .progress=FALSE) {
9+
10+
tdy <- Sys.time()
11+
12+
hr <- as.numeric(format(tdy, "%H", tz="UTC"))
13+
hr <- ifelse(((hr %% 2) == 0), hr, hr-1)
14+
15+
day <- format(tdy, "%Y-%m-%d", tz="UTC")
16+
17+
get_rib(day, hr, output_dir, .progress)
18+
19+
}
20+
21+
#' Retrieve a specific, historical RouteViews RIB file
22+
#'
23+
#' @param date the date (`YYYY-mm-dd` string or \code{Date}) of the file (remembering
24+
#' that the filenames are in UTC time zone)
25+
#' @param hour the hour of the file (remembering that RouteViews dumps a RIB every 2 hours)
26+
#' @param .progress show download progress (default: \code{FALSE})
27+
#' @return the filename (invisibly)
28+
get_rib <- function(date, hour, output_dir=".", .progress=FALSE) {
29+
30+
output_dir <- path.expand(output_dir)
31+
if (!file.exists(output_dir)) stop("Output directory not found", call.=FALSE)
32+
33+
date_dir <- format(as.Date(date), "%Y.%m")
34+
day_fil <- format(as.Date(date), "%Y%m%d")
35+
36+
URL <- sprintf("ftp://archive.routeviews.org/bgpdata/%s/RIBS/rib.%s.%s.bz2",
37+
date_dir, day_fil, sprintf("%02d00", as.numeric(hour)))
38+
39+
fil <- file.path(output_dir, basename(URL))
40+
41+
message(URL)
42+
43+
curl::curl_download(URL, fil, quiet=!(.progress))
44+
45+
return(invisible(fil))
46+
47+
}

README.Rmd

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
output: rmarkdown::github_document
3+
---
4+
5+
`bgpdump` : Tools to Retrieve and Process 'BGP' Files
6+
7+
The following functions are implemented:
8+
9+
- `get_latest_rib`: Retrieve the latest RouteViews RIB file
10+
- `get_rib`: Retrieve a specific, historical RouteViews RIB file
11+
- `rib_to_asn_table`: Convert RouteViews RIB (bgpdump table dump v2) to subnet/asn map
12+
13+
### Installation
14+
15+
```{r eval=FALSE}
16+
devtools::install_github("hrbrmstr/bgpdump")
17+
```
18+
19+
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
20+
options(width=120)
21+
```
22+
23+
### Usage
24+
25+
```{r}
26+
library(bgpdump)
27+
28+
# current verison
29+
packageVersion("bgpdump")
30+
31+
```
32+
33+
### Test Results
34+
35+
```{r}
36+
library(bgpdump)
37+
library(testthat)
38+
39+
date()
40+
41+
test_dir("tests/")
42+
```
43+

0 commit comments

Comments
 (0)