diff --git a/radix-tree.rkt b/radix-tree.rkt index 679fdcb..7dafeed 100644 --- a/radix-tree.rkt +++ b/radix-tree.rkt @@ -2,7 +2,7 @@ (require "iputil.rkt") -(provide make-rt rt-update! rt-lookup rt-dump) +(provide make-rt rt-update! rt-lookup rt-dump rt-flatten) (struct rt-node [edge0 edge1 data] #:transparent #:mutable) (struct rt-edge [label target] #:transparent) @@ -82,6 +82,15 @@ [(list _ ... visited) visited]))) +(define (rt-flatten node) + (if node + (let* ([e1 (rt-node-edge0 node)] + [e2 (rt-node-edge1 node)] + [data (rt-node-data node)] + [rst (append (rt-flatten e1) (rt-flatten e2))]) + (if (equal? data empty-node-data) rst (cons data rst))) + '())) + ; (define test (make-rt)) ; (define (test-insert! x) ; (rt-update! diff --git a/router b/router index 0952a66..0779af9 100755 --- a/router +++ b/router @@ -63,6 +63,13 @@ [(list* (cons peer _) _) peer] [_ #f])) +;; Router -> Msg +;; Dumps routing table +(define (router-dump rt src dst) + (msg:table (sub1 src) src + (map (lambda (route) (list (route-subnet route) (route-nexthop route))) + (rt-flatten rt)))) + ;; Str [Listof Peer-Conn] -> Void ;; -- ;; Runs router logic, given a list of peer connections.