C o n t a i n e r i z a t i o n
This commit is contained in:
parent
51dd6e8609
commit
1f06847846
|
@ -1 +1,2 @@
|
||||||
*.rkt~
|
*.rkt~
|
||||||
|
/build
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
.PHONY: all test clean
|
||||||
|
|
||||||
|
TESTS_DIR=build
|
||||||
|
TEST_SIM_PKG=https://course.ccs.neu.edu/cs3700sp20/archive/bgp-sim.tar.gz
|
||||||
|
|
||||||
|
all:
|
||||||
|
|
||||||
|
$(TESTS_DIR):
|
||||||
|
mkdir -p $(TESTS_DIR)
|
||||||
|
sudo ./scripts/nspawn-support.sh create $(TESTS_DIR)/container
|
||||||
|
cd $(TESTS_DIR) && wget -O bgp-sim.tar.gz $(TEST_SIM_PKG)
|
||||||
|
cd $(TESTS_DIR) && tar xf bgp-sim.tar.gz
|
||||||
|
|
||||||
|
clean:
|
||||||
|
sudo $(RM) -r $(TESTS_DIR)
|
||||||
|
|
||||||
|
test: $(TESTS_DIR)
|
||||||
|
sudo ./scripts/nspawn-support.sh boot $(TESTS_DIR)/container
|
|
@ -0,0 +1,54 @@
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require racket/struct)
|
||||||
|
|
||||||
|
(provide peer subnet
|
||||||
|
string->ip
|
||||||
|
ip->string
|
||||||
|
string->subnet
|
||||||
|
subnet->string
|
||||||
|
string->peer)
|
||||||
|
|
||||||
|
(struct peer [ip type]
|
||||||
|
#:methods gen:custom-write
|
||||||
|
[(define write-proc
|
||||||
|
(make-constructor-style-printer
|
||||||
|
(lambda (x) 'peer)
|
||||||
|
(lambda (x) (list (ip->string (peer-ip x)) (peer-type x)))))])
|
||||||
|
|
||||||
|
(struct subnet [ip mask]
|
||||||
|
#:methods gen:custom-write
|
||||||
|
[(define write-proc
|
||||||
|
(make-constructor-style-printer
|
||||||
|
(lambda (x) 'subnet)
|
||||||
|
(lambda (x) (list (subnet->string x)))))])
|
||||||
|
|
||||||
|
(define (string->ip str)
|
||||||
|
(let ([parts (reverse (string-split str "."))])
|
||||||
|
(for/sum ([i (in-range 4)]
|
||||||
|
[part parts])
|
||||||
|
(arithmetic-shift (string->number part) (* i 8)))))
|
||||||
|
|
||||||
|
(define (ip->string ip)
|
||||||
|
(string-join
|
||||||
|
(reverse
|
||||||
|
(for/list ([i (in-range 4)])
|
||||||
|
(number->string (bitwise-and
|
||||||
|
(arithmetic-shift ip (* i -8)) 255))))
|
||||||
|
"."))
|
||||||
|
|
||||||
|
(define (string->subnet str)
|
||||||
|
(match (string-split str "/")
|
||||||
|
[(list ipstr maskstr) (subnet (string->ip ipstr)
|
||||||
|
(string->number maskstr))]))
|
||||||
|
|
||||||
|
(define (subnet->string sub)
|
||||||
|
(string-append
|
||||||
|
(ip->string (subnet-ip sub))
|
||||||
|
"/"
|
||||||
|
(number->string (subnet-mask sub))))
|
||||||
|
|
||||||
|
(define (string->peer str)
|
||||||
|
(match (string-split str "-")
|
||||||
|
[(list ip type)
|
||||||
|
(peer (string->ip ip) (string->symbol type))]))
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/usr/bin/env racket
|
||||||
|
#lang racket
|
||||||
|
|
||||||
|
(require "iputil.rkt")
|
||||||
|
|
||||||
|
;; Str [Listof Peer] ->
|
||||||
|
;; Router main
|
||||||
|
(define (run-router asn peers)
|
||||||
|
(displayln asn)
|
||||||
|
(map displayln peers)
|
||||||
|
(void))
|
||||||
|
|
||||||
|
(module+ main
|
||||||
|
(command-line
|
||||||
|
#:program "router"
|
||||||
|
#:args
|
||||||
|
(asn . peers)
|
||||||
|
;; Run the router
|
||||||
|
(run-router asn (map string->peer peers))))
|
16
router.rkt
16
router.rkt
|
@ -1,16 +0,0 @@
|
||||||
#lang racket
|
|
||||||
|
|
||||||
;; Str [Listof Str] ->
|
|
||||||
;; Router main
|
|
||||||
(define (run-router asn ip-addrs)
|
|
||||||
(displayln asn)
|
|
||||||
(map displayln ip-addrs)
|
|
||||||
(void))
|
|
||||||
|
|
||||||
(module+ main
|
|
||||||
(command-line
|
|
||||||
#:program "router"
|
|
||||||
#:args
|
|
||||||
(asn . ip-addrs)
|
|
||||||
;; Run the router
|
|
||||||
(run-router asn ip-addrs)))
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cmd="$1"
|
||||||
|
dir="$2"
|
||||||
|
|
||||||
|
if [ "$cmd" == "create" ]; then
|
||||||
|
debootstrap --include=systemd-container --include=libpython3.6 --include=racket --components=main,universe bionic "$dir" http://archive.ubuntu.com/ubuntu/
|
||||||
|
elif [ "$cmd" == "boot" ]; then
|
||||||
|
systemd-nspawn -D "$dir" --bind "$PWD:/router" -- /bin/bash -c "cd /router && scripts/run-tests.sh /router/build; bash"
|
||||||
|
fi
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd $1
|
||||||
|
./sim --router ../router milestone
|
Loading…
Reference in New Issue