Browse Source

Implement route<

master
haskal 10 months ago
parent
commit
549f486168
2 changed files with 18 additions and 4 deletions
  1. +6
    -3
      msg.rkt
  2. +12
    -1
      router

+ 6
- 3
msg.rkt View File

@@ -12,7 +12,8 @@
(struct msg [src dst]
#:transparent)

(struct route [subnet pref self-origin? as-path origin]
(struct route [nexthop subnet pref self-origin? as-path origin]
;; nexthop : IP
;; subnet : Subnet
;; pref : Int
;; self-origin? : Boolean
@@ -66,7 +67,8 @@
(match type
["update"
(msg:update src dst
(route (hash->subnet data)
(route src
(hash->subnet data)
(hash-ref data 'localpref)
(hash-ref data 'selfOrigin)
(hash-ref data 'ASPath)
@@ -105,7 +107,8 @@
(msg:update
(string->ip "1.2.3.4")
(string->ip "1.2.3.7")
(route (subnet (string->ip "1.2.3.5") 7)
(route (string->ip "1.2.3.4")
(subnet (string->ip "1.2.3.5") 7)
100
#t
'(1 2)


+ 12
- 1
router View File

@@ -40,7 +40,18 @@
If multiple routes have the best origin...
5. The path from the neighbor router with the lowest IP address.
|#
#t)
(let/ec meow
(define (cmp mapper)
(let ([x2 (mapper r1)]
[y2 (mapper r2)])
(cond [(< x2 y2) (meow #t)]
[(> x2 y2) (meow #f)])))
(cmp (compose - route-pref))
(cmp (lambda (x) (if (route-self-origin? x) 1 0)))
(cmp (compose length route-as-path))
(cmp (lambda (x) (match (route-origin x) ['IGP 3] ['EGP 2] ['UNK 1])))
(cmp route-nexthop)
(error "your router is angery...")))

;; Router IP -> (U Peer #f)
(define (router-find-best rt src-ip)


Loading…
Cancel
Save