Implement router-dump
This commit is contained in:
parent
549f486168
commit
8ac12c2a10
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(require "iputil.rkt")
|
(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-node [edge0 edge1 data] #:transparent #:mutable)
|
||||||
(struct rt-edge [label target] #:transparent)
|
(struct rt-edge [label target] #:transparent)
|
||||||
|
@ -82,6 +82,15 @@
|
||||||
[(list _ ... visited)
|
[(list _ ... visited)
|
||||||
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 (make-rt))
|
||||||
; (define (test-insert! x)
|
; (define (test-insert! x)
|
||||||
; (rt-update!
|
; (rt-update!
|
||||||
|
|
7
router
7
router
|
@ -63,6 +63,13 @@
|
||||||
[(list* (cons peer _) _) peer]
|
[(list* (cons peer _) _) peer]
|
||||||
[_ #f]))
|
[_ #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
|
;; Str [Listof Peer-Conn] -> Void
|
||||||
;; --
|
;; --
|
||||||
;; Runs router logic, given a list of peer connections.
|
;; Runs router logic, given a list of peer connections.
|
||||||
|
|
Loading…
Reference in New Issue