Browse Source

debugging device script

cecylia 8 years ago
parent
commit
b29e74405e
1 changed files with 3 additions and 3 deletions
  1. 3 3
      js/devicescripts.js

+ 3 - 3
js/devicescripts.js

@@ -68,7 +68,7 @@ var deviceScripts = {
         }
         }
     },
     },
     switch: {
     switch: {
-        onPacketReceived: function(device, packet) {
+        onPacketReceived: function(device, packet, portNum) {
             var found = false;
             var found = false;
             for (var i = 0; (i < device.rules.length) && !found; i++) {
             for (var i = 0; (i < device.rules.length) && !found; i++) {
                 if (device.rules[i].dstip == packet.network.dstip) {
                 if (device.rules[i].dstip == packet.network.dstip) {
@@ -79,7 +79,7 @@ var deviceScripts = {
             if(!found){
             if(!found){
                 //broadcast packet to all ports except where it was received
                 //broadcast packet to all ports except where it was received
                 console.log("Sending packet doesn "+ device.ports + " ports");
                 console.log("Sending packet doesn "+ device.ports + " ports");
-                for(var i=0; i<device.ports; i++){
+                for(var i=0; i<device.ports.length; i++){
                     sendPacket(device.id, i, packet);
                     sendPacket(device.id, i, packet);
                 }
                 }
             }
             }
@@ -93,7 +93,7 @@ var deviceScripts = {
             if(!found){
             if(!found){
                 device.rules[device.rules.length] = {
                 device.rules[device.rules.length] = {
                     dstip: packet.network.srcip,
                     dstip: packet.network.srcip,
-                    portNum: 3
+                    portNum: portNum
                 }
                 }
             }
             }
         }
         }