@@ -21,8 +21,8 @@ export class ViewRouter extends ViewNetworkDevice {
2121
2222 private packetQueueSize : number ;
2323 private packetQueue : PacketQueue ;
24- // Time in ms to process a single byte
25- private timePerByte : number ;
24+ // Number of bytes to process per second
25+ private bytesPerSecond : number ;
2626 // Number of bytes processed
2727 private processingProgress = 0 ;
2828
@@ -42,7 +42,7 @@ export class ViewRouter extends ViewNetworkDevice {
4242 tag : string ,
4343 mask : IpAddress ,
4444 packetQueueSize : number = ROUTER_CONSTANTS . PACKET_QUEUE_MAX_SIZE ,
45- timePerByte : number = ROUTER_CONSTANTS . PROCESSING_SPEED ,
45+ bytesPerSecond : number = ROUTER_CONSTANTS . PROCESSING_SPEED ,
4646 ) {
4747 super (
4848 id ,
@@ -56,7 +56,7 @@ export class ViewRouter extends ViewNetworkDevice {
5656 ) ;
5757 this . packetQueueSize = packetQueueSize ;
5858 this . packetQueue = new PacketQueue ( this . packetQueueSize ) ;
59- this . timePerByte = timePerByte ;
59+ this . bytesPerSecond = bytesPerSecond ;
6060 }
6161
6262 showInfo ( ) : void {
@@ -90,7 +90,7 @@ export class ViewRouter extends ViewNetworkDevice {
9090 } ,
9191 {
9292 label : TOOLTIP_KEYS . PROCESSING_SPEED_PARAMETER ,
93- initialValue : this . timePerByte ,
93+ initialValue : this . bytesPerSecond ,
9494 onChange : ( newSpeed : number ) => {
9595 this . modifyProcessingSpeed ( newSpeed ) ;
9696 } ,
@@ -118,8 +118,8 @@ export class ViewRouter extends ViewNetworkDevice {
118118 this . packetQueueSize = newSize ;
119119 }
120120
121- setTimePerByte ( newTime : number ) {
122- this . timePerByte = newTime ;
121+ setBytesPerSecond ( newTime : number ) {
122+ this . bytesPerSecond = newTime ;
123123 }
124124
125125 /**
@@ -150,16 +150,16 @@ export class ViewRouter extends ViewNetworkDevice {
150150 * @param newSpeed - The new processing speed to set, represented as the time per byte.
151151 *
152152 * This method updates the internal processing speed of the device by calling
153- * `setTimePerByte ` with the provided `newSpeed`. It also ensures that the
153+ * `setBytesPerSecond ` with the provided `newSpeed`. It also ensures that the
154154 * corresponding device in the data graph is updated with the same processing speed,
155155 * but only if the device is an instance of `DataRouter`. If the device is not a
156156 * `DataRouter`, a warning is logged to the console.
157157 */
158158 modifyProcessingSpeed ( newSpeed : number ) : void {
159- this . setTimePerByte ( newSpeed ) ;
159+ this . setBytesPerSecond ( newSpeed ) ;
160160 this . viewgraph . getDataGraph ( ) . modifyDevice ( this . id , ( device ) => {
161161 if ( device instanceof DataRouter ) {
162- device . setTimePerByte ( newSpeed ) ;
162+ device . setBytesPerSecond ( newSpeed ) ;
163163 } else {
164164 console . warn ( "Device is not a DataRouter, cannot set time per byte" ) ;
165165 }
@@ -225,13 +225,12 @@ export class ViewRouter extends ViewNetworkDevice {
225225 }
226226
227227 getPacketsToProcess ( timeMs : number ) : IPv4Packet | null {
228- this . processingProgress += timeMs ;
228+ this . processingProgress += ( this . bytesPerSecond * timeMs ) / 1000 ;
229229 const packetLength = this . packetQueue . getHead ( ) ?. totalLength ;
230- const progressNeeded = this . timePerByte * packetLength ;
231- if ( this . processingProgress < progressNeeded ) {
230+ if ( this . processingProgress < packetLength ) {
232231 return null ;
233232 }
234- this . processingProgress -= progressNeeded ;
233+ this . processingProgress -= packetLength ;
235234 return this . packetQueue . dequeue ( ) ;
236235 }
237236
0 commit comments