2
(begin-book);$ACL2s-Preamble$|#
6
(include-book "../../../generic-modules/flowcontrol")
7
(include-book "../../datalink/simple/datalink")
11
(defun switchBuffer (nst from to)
12
;; move the head of the buffer of the from port to the tail of the buffer of the to port.
13
;;returns the update nst list.
16
;; - nst : the list of all ports of this node
17
;; - from : The input port which is switched
18
;; - to : The output port which is switched
21
(if (equal (port-address (car nst)) (port-address to))
22
(cons (port-updateBuffer to (port-buffer from)) (switchBuffer (cdr nst) from to))
23
(if (equal (port-address (car nst)) (port-address from))
24
(cons (port-updateBuffer from nil) (switchBuffer (cdr nst) from to))
25
(cons (car nst) (switchBuffer (cdr nst) from to))))))
28
(defun switch-port (portlist nst from)
29
;; Switch the input port from by looping over the nst in portlist until the port where the from port is routed to is reached.
32
;; - portlist : The list of output ports of this node
33
;; - nst : the list of all ports of this node
34
;; - from : The input port which is switched
35
(let ((to (car portlist)))
36
(cond ((endp portlist)
38
((and (equal (port-portname to) (status-route (port-status from)))
39
(endp (port-buffer to)))
40
(switchBuffer nst from to))
41
(t (switch-port (cdr portlist) nst from)))))
44
(defun switch-ports (portslist nst)
45
;; Switches each port in portlist. If a port has a msg in its buffer switch the port. The switched ports are returned.
48
;; - portlist : The list of input ports of this node
49
;; - nst : the list of all ports of this node
52
(let* ((inport (car portslist)))
53
(if (not (endp (port-buffer inport))) ;; and something to send
54
(switch-ports (cdr portslist) (switch-port (ports-outputports nst) nst inport)) ;; clean
55
(switch-ports (cdr portslist) nst)))))
57
(defun packet-FlowControl (nst memory)
58
;; This is the function that performs the flowcontrol in a router. This consists of scheduling the routed input nodes and switching the sheduled msg.
61
;; - nst : list of ports in a node
62
;; - memory : the global memory of a node
63
(mv (switch-ports (ports-inputports nst) nst) memory))
65
(definstance GenericFlowControl check-compliance-Flowcontrol
66
:functional-substitution
67
((flowcontrol packet-FlowControl)))#|ACL2s-ToDo-Line|#