Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: willijar/LENS
base: 1c32afb349
...
head fork: willijar/LENS
compare: aef71c0da4
  • 2 commits
  • 14 files changed
  • 0 commit comments
  • 2 contributors
View
13 core/application.lisp
@@ -32,13 +32,12 @@ a web browser model with multiple simultaneous connections."))
(slot-value app 'name)
(call-next-method)))
+(defmethod start((app application)))
+(defmethod stop((app application) &key &allow-other-keys))
+(defmethod reset((app application)))
+
(defmethod trace:default-trace-detail((application application))
'(length-bytes))
-(defmethod initialize-instance :after ((app application) &key node &allow-other-keys)
- (push app (node:applications node)))
-
-(defmethod receive((application application) data layer4 &key &allow-other-keys)
- "Called by layer 4 protocol object when data is received. Default -
-do nothing"
- (declare (ignore application data layer4)))
+(defmethod initialize-instance :after ((app application) &key &allow-other-keys)
+ (push app (node:applications (node app))))
View
2  core/node.lisp
@@ -124,7 +124,7 @@ form the packets are derived from this class."))
(direction :rx :type (member :tx :rx))
(layer 0 :type (integer 5))
(protocol-number 0 :type integer)
- (interface nil :type interface)
+ (interface nil)
(callback nil :type function)) ;; function of protocol entity and packet
(defun add-callback(callback node)
View
11 core/protocol.lisp
@@ -59,7 +59,7 @@ See http://www.iana.org/assignments/protocol-numbers")
(write-trace sender (peek-pdu packet) :packet packet :text "-"))
(:method :before((receiver protocol) (pdu pdu) (sender protocol)
&key &allow-other-keys)
- (write-trace sender pdu :text "-"))
+ (write-trace sender pdu :packet pdu :text "-"))
(:method :around (receiver packet (sender protocol) &key &allow-other-keys)
(when (node:call-callbacks :tx sender packet) (call-next-method))))
@@ -71,7 +71,7 @@ See http://www.iana.org/assignments/protocol-numbers")
(write-trace receiver (peek-pdu packet) :packet packet :text "+"))
(:method :before((receiver protocol) (pdu pdu) (sender protocol)
&key &allow-other-keys)
- (write-trace receiver pdu :text "+"))
+ (write-trace receiver pdu :packet pdu :text "+"))
(:method :around((receiver protocol) packet sender &key &allow-other-keys)
(when (node:call-callbacks :rx receiver packet) (call-next-method))))
@@ -412,7 +412,7 @@ this occurs when the acknowledgement is received from the peer.")
(declare (ignore application protocol))
t))
-(declaim (inline seq+ seq- seq< seq-max))
+;(declaim (inline seq+ seq- seq< seq-max))
(defun seq+(seq length-bytes)
"32 bit modulus addition of a sequence number and a byte length"
@@ -490,11 +490,6 @@ given segment-start and no-bytes"
(defmethod length-bytes((pdu null)) 0)
-(defmethod send((layer4 layer4:protocol) (length-bytes integer) application &rest args)
- (apply #'send layer4
- (make-instance 'data :length-bytes length-bytes)
- application args))
-
(defmethod print-object((data data) stream)
(print-unreadable-object (data stream :type t :identity t)
(format stream "~:/print-eng/bytes" (length-bytes data))))
View
87 layer4/tcp-newreno.lisp
@@ -1,87 +0,0 @@
-;; TCP Reno implementation
-;; Copyright (C) 2007 Dr. John A.R. Williams
-
-;; Author: Dr. John A.R. Williams <J.A.R.Williams@jarw.org.uk>
-;; Keywords:
-
-;; This file is part of Lisp Educational Network Simulator (LENS)
-
-;; This is free software released under the GNU General Public License (GPL)
-;; See <http://www.gnu.org/copyleft/gpl.html>
-
-;;; Commentary:
-
-;;
-
-;;; Code:
-
-(in-package :protocol.tcp)
-
-(defclass tcp-newreno(tcp-reno)
- ((reno-high-tx-mark :initform 0 :type seq :accessor reno-high-tx-mark)
- (partial-ack-count :initform 0 :type counter :accessor partial-ack-count))
- (:documentation "Implementation of the NewReno variation of TCP"))
-
-(defmethod newack(seq (tcp tcp-tahoe))
- ;; New acknowledgement up to sequence number seq
- (let ((skip-timer nil)
- (seg-size (seg-size tcp)))
- (cond
- ((fast-recovery-mode tcp)
- ;; If in fast recovery and have a new data ack, check for
- ;; full or partial ack, per rfc3782
- (cond
- ((>= seq (reno-high-tx-mark tcp))
- ;; Reset cWnd and exit fastRecovery
- (setf (cwnd tcp)
- (min (ssthresh tcp) (+ seg-size (unack-data-count tcp)))
- (fast-recovery-mode tcp) nil
- (partial-ack-count tcp) 0))
- (t
- (let ((delta (- seq (highest-rx-ack tcp))))
- (decf (cwnd tcp) delta)
- (when (>= delta seg-size) (incf (cwnd tcp) (seg-size tcp))))
- (setf (highest-rx-ack tcp) seq)
- (setf skip-timer (> (partial-ack-count tcp) 0))
- (retransmit tcp))))
- ((< (cwnd tcp) (ssthresh tcp))
- ;; slow start mode add one seg-size to cwnd
- (incf (cwnd tcp) seg-size))
- (t ;; Congestion avoidance mode, adjust by (segsize*segize) / cWnd
- (setf (cwnd tcp) (max 1.0 (/ (* seg-size seg-size) (cwnd tcp))))))
- (note-time-seq log-cwin (cwnd tcp) tcp)
- (common-newack seq tcp skip-timer)))
-
-(defmethod dupack(tcp-header count (tcp tcp-newreno))
- ;; Dup ack received
- (note-time-seq log-dupack count tcp)
- (cond
- ((fast-recovery-mode tcp)
- (incf (cwnd tcp) (seg-size tcp))
- (tcp-send-pending tcp))
- ((and (= count 3) (> (ack-number tcp-header) (reno-high-tx-mark tcp)))
- ;;Count of three indicates triple dupack has been received
- ;;and covers at least "recover" bytes
- (setf (fast-recovery-mode tcp) t
- (partial-ack-count tcp) 0
- (ssthresh tcp) (max (/ (window tcp) 2) (* 2 (seg-size tcp))))
- (note-time-seq log-ssthresh (ssthresh tcp) tcp)
- (setf (cwnd tcp) (* 3 (seg-size tcp))
- (reno-high-tx-mark tcp) (next-tx-seq tcp))
- (retransmit tcp)))
- (note-time-seq log-cwin (cwnd tcp) tcp))
-
-(defmethod retx-timeout-event((tcp tcp-newreno))
- ;;As Per RFC2581
- (setf (ssthresh tcp)
- (max (/ (window tcp) 2) (* 2 (seg-size tcp))))
- (note-time-seq log-ssthresh (ssthresh tcp) tcp)
- ;; reset cwnd to seg-size
- (setf (cwnd tcp) (initial-cwnd tcp))
- (note-time-seq log-cwin (cwnd tcp) tcp)
- ;; Start from highest ack
- (setf (next-tx-seq tcp) (highest-rx-ack tcp)
- (fast-recovery-mode tcp) nil
- (partial-ack-count tcp) 0)
- (lens.math::increase-multiplier (rtt tcp))
- (retransmit tcp))
View
73 layer4/tcp-reno.lisp
@@ -1,73 +0,0 @@
-;; TCP Reno implementation
-;; Copyright (C) 2007 Dr. John A.R. Williams
-
-;; Author: Dr. John A.R. Williams <J.A.R.Williams@jarw.org.uk>
-;; Keywords:
-
-;; This file is part of Lisp Educational Network Simulator (LENS)
-
-;; This is free software released under the GNU General Public License (GPL)
-;; See <http://www.gnu.org/copyleft/gpl.html>
-
-;;; Commentary:
-
-;;
-
-;;; Code:
-
-(in-package :protocol.tcp)
-
-(defclass tcp-reno(tcp)
- ((fast-recovery-mode :initform nil :type boolean
- :accessor fast-recovery-mode))
- (:documentation "Implementation of the Reno variation of TCP"))
-
-(defmethod newack(seq (tcp tcp-reno))
- ;; New acknowledgement up to sequence number seq
- (let ((seg-size (seg-size tcp)))
- (cond
- ((fast-recovery-mode tcp)
- ;; If in fast recovery and have a new data ack, reset cWnd
- ;; to the ssthresh calculated when we entered fast recovery
- ;; and exit fast recovery mode
- (setf (cwnd tcp) (ssthresh tcp)
- (fast-recovery-mode tcp) nil))
- ((< (cwnd tcp) (ssthresh tcp))
- ;; slow start mode add one seg-size to cwnd
- (incf (cwnd tcp) seg-size))
- (t ;; Congestion avoidance mode, adjust by (segsize*segize) / cWnd
- (setf (cwnd tcp) (max 1.0 (/ (* seg-size seg-size) (cwnd tcp))))))
- (note-time-seq log-cwin (cwnd tcp) tcp)
- (common-newack seq tcp)))
-
-(defmethod dupack(tcp-header count (tcp tcp-reno))
- ;; Dup ack received
- (note-time-seq log-dupack count tcp)
- (cond
- ((fast-recovery-mode tcp)
- (incf (cwnd tcp) (seg-size tcp))
- (tcp-send-pending tcp))
- ((= count 3)
- (setf (fast-recovery-mode tcp) t)
- ;;As Per RFC2581
- (setf (ssthresh tcp)
- (max (/ (window tcp) 2) (* 2 (seg-size tcp))))
- (note-time-seq log-ssthresh (ssthresh tcp) tcp)
- ;; reenter slow start
- (setf (cwnd tcp) (* 3 (seg-size tcp)))
- (retransmit tcp)))
- (note-time-seq log-cwin (cwnd tcp) tcp))
-
-(defmethod retx-timeout-event((tcp tcp-reno))
- ;;As Per RFC2581
- (setf (ssthresh tcp)
- (max (/ (window tcp) 2) (* 2 (seg-size tcp))))
- (note-time-seq log-ssthresh (ssthresh tcp) tcp)
- ;; reset cwnd to seg-size
- (setf (cwnd tcp) (seg-size tcp))
- (note-time-seq log-cwin (cwnd tcp) tcp);
- ;; Start from highest ack
- (setf (next-tx-seq tcp) (highest-rx-ack tcp))
- (setf (fast-recovery-mode tcp) nil)
- (lens.math::increase-multiplier (rtt tcp))
- (retransmit tcp))
View
63 layer4/tcp-tahoe.lisp
@@ -1,63 +0,0 @@
-;; TCP Tahoe implementation
-;; Copyright (C) 2007 Dr. John A.R. Williams
-
-;; Author: Dr. John A.R. Williams <J.A.R.Williams@jarw.org.uk>
-;; Keywords:
-
-;; This file is part of Lisp Educational Network Simulator (LENS)
-
-;; This is free software released under the GNU General Public License (GPL)
-;; See <http://www.gnu.org/copyleft/gpl.html>
-
-;;; Commentary:
-
-;;
-
-;;; Code:
-
-(in-package :protocol.tcp)
-
-(defclass tcp-tahoe(tcp)
- ()
- (:documentation "Implementation of the Tahoe variation of TCP"))
-
-(defmethod newack(seq (tcp tcp-tahoe))
- ;; New acknowledgement up to sequence number seq
- ;; Adjust congestion window in response to new ack's received"
- (let ((seg-size (seg-size tcp)))
- (incf (cwnd tcp)
- (if (> (cwnd tcp) (ssthresh tcp))
- ;; Slow start mode, add one segSize to cWnd
- seg-size
- ;; Congestion avoidance mode, adjust by (segsize*segize) / cWnd
- (max 1.0 (/ (* seg-size seg-size) (cwnd tcp))))))
- (note-time-seq log-cwin (cwnd tcp) tcp)
- (common-newack seq tcp))
-
-(defmethod dupack(tcp-header count (tcp tcp-tahoe))
- ;; Dup ack received
- (note-time-seq log-dupack count tcp)
- (when (= count 3) ; triple duplicate ack
- ;As Per RFC2581
- (setf (ssthresh tcp)
- (max (/ (window tcp) 2) (* 2 (seg-size tcp))))
- (note-time-seq log-ssthresh (ssthresh tcp) tcp)
- ;; reenter slow start
- (setf (cwnd tcp) (* (initial-cwnd tcp) (seg-size tcp)))
- (note-time-seq log-cwin (cwnd tcp) tcp);
- ;; For Tahoe, we also reset next-tx-seq
- (setf (next-tx-seq tcp) (highest-rx-ack tcp))
- (tcp-send-pending tcp)))
-
-(defmethod retx-timeout-event((tcp tcp-tahoe))
- ;;As Per RFC2581
- (setf (ssthresh tcp)
- (max (/ (window tcp) 2) (* 2 (seg-size tcp))))
- (note-time-seq log-ssthresh (ssthresh tcp) tcp)
- ;; reset cwnd to seg-size
- (setf (cwnd tcp) (seg-size tcp))
- (note-time-seq log-cwin (cwnd tcp) tcp);
- ;; Start from highest ack
- (setf (next-tx-seq tcp) (highest-rx-ack tcp))
- (lens.math::increase-multiplier (rtt tcp))
- (retransmit tcp))
View
40 layer4/tcp.lisp
@@ -719,9 +719,9 @@
(unless (connected-p tcp)
(funcall (process-event app-listen tcp) tcp)))
-(defun unack-data-count(tcp) (- (next-tx-seq tcp) (highest-rx-ack tcp)))
+(defun unack-data-count(tcp) (seq- (next-tx-seq tcp) (highest-rx-ack tcp)))
-(defun bytes-in-flight(tcp) (- (high-tx-mark tcp) (highest-rx-ack tcp)))
+(defun bytes-in-flight(tcp) (seq- (high-tx-mark tcp) (highest-rx-ack tcp)))
(defmethod window((tcp tcp)) (min (rx-window tcp) (congestion-window tcp)))
@@ -767,7 +767,8 @@
(schedule 'connection-timer tcp)
(setf (syn-time tcp) (simulation-time)) ;; for initial RTT estimate
(initialise-sequence-number tcp)
- (send-packet tcp syn :ack-number 0))
+ (send-packet tcp syn :ack-number 0)
+ (setf (next-tx-seq tcp) (seq+ (next-tx-seq tcp) 1)))
(defun syn-ack-tx(tcp &key header dst-address
&allow-other-keys)
@@ -783,10 +784,12 @@
(initialise-sequence-number copy)
(setf (next-rx-seq copy) (seq+ (sequence-number header) 1))
(setf (last-rx-ack copy) (ack-number header))
+ (setf (highest-rx-ack copy) (ack-number header))
(setf (slot-value copy 'fid)
(incf (slot-value copy 'layer4::last-fid)))
(bind copy :peer-address dst-address :peer-port dst-port)
(send-packet copy (logior syn ack))
+ (setf (next-tx-seq tcp) (seq+ (next-tx-seq tcp) 1))
(schedule 'connection-timer copy))
;; otherwise reject by sending rst from listener
(send-packet copy rst :sequence-number 0
@@ -902,19 +905,19 @@
(pending-data (pending-data tcp))
(ipv4 (layer3:find-protocol 'layer3:ipv4 (node tcp)))
(interface (find-interface (peer-address tcp) (node tcp))))
- (break "~A sending ~A" tcp pending-data)
(loop
;; if no data finished
- (when (zerop (length-bytes pending-data)) (return))
- (let ((w (available-window tcp))
- (mss (maximum-segment-size tcp)))
- (when (and (< w mss) (> (length-bytes pending-data) w))
+ (let* ((index (seq- (next-tx-seq tcp) (highest-rx-ack tcp)))
+ (no-bytes (- (length-bytes pending-data) index)))
+
+ (when (zerop no-bytes) (return))
+ (let ((w (available-window tcp))
+ (mss (maximum-segment-size tcp)))
+ (when (and (< w mss) (> no-bytes w))
;; don't send small segment unnecessarily
- (return))
+ (return))
(let ((data
- (data-subseq pending-data
- (seq- (next-tx-seq tcp) (highest-rx-ack tcp))
- (min w mss))))
+ (data-subseq pending-data index (min w mss))))
;; if no buffer available stop and request
;;(100 extra bytes is to allow for headers)
(unless (layer1:buffer-available-p
@@ -924,7 +927,7 @@
(let ((flags (if with-ack ack 0)))
;; see if we need fin flag
(when (and (close-on-empty tcp)
- (= (length-bytes data) (length-bytes pending-data)))
+ (= (length-bytes data) no-bytes))
(setf flags (logior flags fin))
(setf (state tcp) fin-wait-1))
(send-packet tcp flags :data data :ipv4 ipv4)
@@ -933,9 +936,10 @@
(seq+ (next-tx-seq tcp) (length-bytes data)))
(setf (high-tx-mark tcp)
(seq-max (next-tx-seq tcp) (high-tx-mark tcp)))
- (incf (bytes-sent tcp) (length-bytes data))))))
+ (incf (bytes-sent tcp) (length-bytes data)))))))
(when (> n-sent 0)
- (schedule 'retransmit-packet tcp)
+ (when (not (busy-p (timer 'retransmit-packet-timer tcp)))
+ (schedule 'retransmit-packet-timer tcp))
t)))
(defmethod control-message((tcp tcp) (msg (eql :destination-unreachable))
@@ -1133,9 +1137,9 @@
:documentation "High tx mark for new reno")
(partial-ack-count :initform 0 :accessor partial-ack-count
:documentation "Number of parial acks in a row"))
- (:documentation "Reno TCP implementation"))
+ (:documentation "NewReno TCP implementation"))
-(defmethod new-ack ((tcp tcp-reno) &key header
+(defmethod new-ack ((tcp tcp-newreno) &key header
(ack-number (ack-number header)) &allow-other-keys)
(let ((seg-size (maximum-segment-size tcp))
(slow-start-threshold (slow-start-threshold tcp))
@@ -1181,6 +1185,6 @@
(recover tcp) (next-tx-seq tcp))
(retransmit tcp)))))
-(defmethod retransmit-packet-timeout((tcp tcp-reno))
+(defmethod retransmit-packet-timeout((tcp tcp-newreno))
(setf (partial-ack-count tcp) 0)
(call-next-method))
View
38 layer5/abr-source.lisp
@@ -17,47 +17,33 @@
(in-package :protocol.layer5)
-(defclass abr-source(application event)
- ((peer-address :type network-address
- :initarg :peer-address :reader peer-address
- :documentation "Destination address for data")
- (peer-port :type ipport :initarg :peer-port :reader peer-port
- :documentation "Destination port for packets")
- (protocol :type layer4:protocol :reader protocol)
- (rate :initarg :rate :initform 500000 :accessor rate
+(defclass abr-source(client-application event)
+ ((rate :initarg :rate :initform 500000 :accessor rate
:documentation "Rate at which data is generated - may be a
random variable or an integer or zero for as fast as possible")
(pkt-size :initarg :pkt-size :initform 512 :type integer :accessor pkt-size
:documentation "Size of packets"))
+ (:default-initargs :protocol (make-instance 'udp))
(:documentation "A constant or average bit rate source transmitting
either at rate (which may be a random variable or a constant) or as
fast as possible if rate is 0"))
-(defmethod initialize-instance :after
- ((app abr-source) &key (protocol-type 'layer4:udp) &allow-other-keys)
- (setf (slot-value app 'protocol)
- (make-instance protocol-type :node (node app) :application app)))
-
(defmethod sent((app abr-source) n socket)
"Send a packet on every notification if rate is 0"
- (when (equal (rate app) 0) (send socket (pkt-size app) app)))
+ (call-next-method)
+ (when (zerop (rate app))
+ (send socket (make-instance 'data :length-bytes (pkt-size app)) app)))
(defmethod handle((app abr-source))
"Send a packet and reschedule"
- (with-slots(rate protocol pkt-size) app
- (send protocol (make-instance 'data :length-bytes pkt-size) app)
- (schedule (/ (* pkt-size 8) (math:random-value rate)) app)))
+ (let ((n (pkt-size app)))
+ (send (protocol app) (make-instance 'data :length-bytes n) app)
+ (schedule (/ (* n 8) (math:random-value (rate app))) app)))
(defmethod start((app abr-source))
(open-connection (peer-address app) (peer-port app) (protocol app)))
(defmethod connection-complete((app abr-source) layer4)
- (with-slots(protocol rate pkt-size) app
- (setf protocol layer4)
- (if (equal rate 0)
- (send protocol (make-instance 'data :length-bytes pkt-size) app)
- (handle app))))
-
-(defmethod stop((app abr-source) &key &allow-other-keys)
- (call-next-method)
- (close-connection (protocol app)))
+ (if (zerop (rate app))
+ (send layer4 (make-instance 'data :length-bytes (pkt-size app)) app)
+ (handle app)))
View
71 layer5/client.lisp
@@ -0,0 +1,71 @@
+;; Client application
+;; Copyright (C) 2011 Dr. John A.R. Williams
+
+;; Author: Dr. John A.R. Williams <J.A.R.Williams@jarw.org.uk>
+;; Keywords:
+
+;; This file is part of Lisp Educations Network Simulator (LENS)
+
+;; This is free software released under the GNU General Public License (GPL)
+;; See <http://www.gnu.org/copyleft/gpl.html>
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(in-package :layer5)
+
+(defclass client-application(application)
+ ((peer-address :initarg :peer-address :type network-address
+ :reader peer-address
+ :documentation "IP address of peer to send to")
+ (peer-port :initarg :peer-port
+ :type ipport :reader peer-port
+ :documentation "Port of peer to send to")
+ (protocol :type layer4:protocol :reader protocol :initarg :protocol
+ :documentation "The layer 4 protocol instance")
+ (bytes-sent :initform 0 :accessor bytes-sent
+ :documentation "Bytes sent")
+ (bytes-received :initform 0 :accessor bytes-received
+ :documentation "Bytes received")
+ (bytes-ack :initform 0 :accessor bytes-ack
+ :documentation "Bytes acknowledged")
+ (bytes-requested :initform 0 :accessor bytes-requested
+ :documentation "Bytes requested"))
+ (:documentation "Basis for single transport agent client applications"))
+
+(defmethod initialize-instance :after ((app client-application)
+ &key
+ &allow-other-keys)
+ (with-slots(protocol) app
+ (setf (node protocol) (node app)
+ (application protocol) app)))
+
+(defmethod stop((app client-application) &key &allow-other-keys)
+ (call-next-method)
+ (close-connection (protocol app)))
+
+(defmethod reset((app client-application))
+ (call-next-method)
+ (setf (bytes-sent app) 0
+ (bytes-received app) 0
+ (bytes-ack app) 0
+ (bytes-requested app) 0)
+ (reset (protocol app)))
+
+(defmethod receive((app client-application) data protocol &key &allow-other-keys)
+ (incf (bytes-received app) (length-bytes data)))
+
+(defmethod send :before(layer4 data (app client-application) &key &allow-other-keys)
+ (incf (bytes-sent app) (length-bytes data)))
+
+(defmethod send :before(layer4 (data message-data) (app client-application)
+ &key &allow-other-keys)
+ (incf (bytes-requested app)
+ (reduce #'+ (mapcar #'message-response-size (messages data)))))
+
+(defmethod sent((app client-application) n protocol)
+ (declare (ignore protocol))
+ (incf (bytes-ack app) n))
View
2  layer5/message-responder.lisp
@@ -24,7 +24,7 @@
(local-port :initarg :local-port
:type ipport :reader local-port
:documentation "Port number to bind to")
- (responders :type list :accessor responders
+ (responders :initform nil :type list :accessor responders
:documentation "List of responders (connections)")
(bytes-sent :initform 0 :accessor bytes-sent
:documentation "Bytes sent")
View
77 layer5/message-source.lisp
@@ -17,82 +17,35 @@
(in-package :protocol.layer5)
-(defclass message-source(application scheduler:event)
- ((peer-address :initarg :peer-address :initform nil :type ipaddr
- :reader peer-address
- :documentation "IP address of peer to send to")
- (peer-port :initarg :peer-port :initform nil
- :type ipport :reader peer-port
- :documentation "Port of peer to send to")
- (protocol :type tcp :reader protocol :initarg :protocol
- :initform (make-instance 'tcp-reno)
- :documentation "The tcp (layer 4) protocol instance")
- (sleep-time :initarg :sleep-time :accessor sleep-time :initform 5
+(defclass message-source(client-application event)
+ ((sleep-time :initarg :sleep-time :accessor sleep-time :initform 5
:documentation "Random time to sleep between transmissions")
(data-size :initarg :data-size :initform 512 :accessor data-size
:documentation "Random size of message to send")
(response-size :initarg :response-size :initform nil :accessor response-size
:documentation "Random size of response to request")
(loop-count :initarg :loop-count :initform 1 :accessor loop-count)
- (repeat-count :initform 0 :accessor repeat-count)
- (bytes-sent :initform 0 :accessor bytes-sent
- :documentation "Bytes sent this loop")
- (bytes-ack :initform 0 :accessor bytes-ack
- :documentation "Bytes acknowledged this loop")
- (bytes-requested :initform 0 :accessor bytes-requested
- :documentation "Bytes requested this loop")
- (bytes-received :initform 0 :accessor bytes-received
- :documentation "Bytes received this loop"))
+ (repeat-count :initform 0 :accessor repeat-count))
+ (:default-initargs :protocol (make-instance 'tcp-reno))
(:documentation "An application that sends a random amount of data
to a TCP server. The application will optionally sleep for a random
amount of time and send some more data, up to a user specified limit
on the number of sending iterations."))
-(defmethod initialize-instance :after ((app message-source)
- &key
- &allow-other-keys)
- (with-slots(protocol) app
- (setf (node protocol) (node app)
- (application protocol) app)))
+(defmethod start((app message-source)) (handle app))
-(defmethod start((app message-source))
- (setf (repeat-count app) 0
- (bytes-sent app) 0
- (bytes-ack app) 0
- (bytes-requested app) 0
- (bytes-received app) 0)
- (open-connection (peer-address app) (peer-port app) (protocol app)))
-
-(defmethod stop((app message-source) &key &allow-other-keys)
+(defmethod reset((app message-source))
(call-next-method)
- (break "Stopping ~A" app)
- (close-connection (protocol app))
- (unbind (protocol app)))
-
-(defmethod reset((app message-source)) (stop app))
+ (setf (repeat-count app) 0))
(defmethod connection-complete((app message-source) layer4)
- (handle app))
+ (let* ((data-size (random-value (data-size app)))
+ (response-size (random-value (response-size app)))
+ (data (make-message-data data-size :response-size response-size)))
+ (send (protocol app) data app)
+ (close-connection (protocol app))
+ (schedule (random-value (sleep-time app)) app)))
(defmethod handle((app message-source))
- (if (<= (incf (repeat-count app)) (loop-count app))
- (let* ((data-size (random-value (data-size app)))
- (response-size (random-value (response-size app)))
- (data (make-message-data data-size :response-size response-size)))
- (incf (bytes-requested app) response-size)
- (incf (bytes-sent app) data-size)
- (send (protocol app) data app)
- (schedule (random-value (sleep-time app)) app))
- (stop app)))
-
-(defmethod sent((app message-source) n protocol)
- (declare (ignore protocol))
- (incf (bytes-ack app) n))
-
-(defmethod receive((app message-source) data protocol &key &allow-other-keys)
- (declare (ignore protocol))
- (incf (bytes-received app) (length-bytes data)))
-
-(defmethod control-message ((app message-source) msg protocol
- &key &allow-other-keys)
- (stop app))
+ (when (<= (incf (repeat-count app)) (loop-count app))
+ (open-connection (peer-address app) (peer-port app) (protocol app))))
View
3  layer5/message.lisp
@@ -64,6 +64,7 @@
:response-size (message-response-size m)
:created (message-created m)
:offset (- o start))))))
- (messages data)))))
+ (messages data)))
+ result))
View
5 lens.asd
@@ -82,8 +82,9 @@
(:file "tcp" :depends-on ("rtt"))))
(:module "layer5" :depends-on ("core")
:components
- ((:file "abr-source")
+ ((:file "client" :depends-on ("message"))
+ (:file "abr-source" :depends-on ("client"))
(:file "udp-sink")
(:file "message")
- (:file "message-source" :depends-on ("message"))
+ (:file "message-source" :depends-on ("message" "client"))
(:file "message-responder" :depends-on ("message"))))))
View
7 tests/tcp1.lisp
@@ -37,10 +37,9 @@
(make-instance
'message-source
:node (node 0)
- :data-size '(math:uniform 100 512)
- :response-size '(math::uniform 5000 20000)
- :loop-count 5
- :sleep-time '(math:uniform 0.5 5.0)
+ :data-size 100
+ :response-size 100
+ :loop-count 1
:peer-address (ipaddr (node 5))
:peer-port 20000))

No commit comments for this range

Something went wrong with that request. Please try again.