Browse Source

setting up spoofs 2 and switch device script

cecylia 8 years ago
parent
commit
01b4d839b3
3 changed files with 41 additions and 8 deletions
  1. 32 1
      js/devicescripts.js
  2. 1 1
      levels/02 Spoofs/spoofs02.html
  3. 8 6
      levels/02 Spoofs/spoofs02.json

+ 32 - 1
js/devicescripts.js

@@ -66,9 +66,40 @@ var deviceScripts = {
             }
 
         }
+    },
+    switch: {
+        onPacketReceived: function(device, packet) {
+            var found = false;
+            for (var i = 0; (i < device.rules.length) && !found; i++) {
+                if (device.rules[i].dstip == packet.network.dstip) {
+                    sendPacket(device.id, device.rules[i].portNum, packet);
+                    found = true;
+                }
+            }
+            if(!found){
+                //broadcast packet to all ports except where it was received
+                for(var i=0; i<device.ports; i++){
+                    sendPacket(device.id, i, packet);
+                }
+            }
+            //update rules with info from this packet
+            var found = false;
+            for (var i = 0; (i < device.rules.length) && !found; i++) {
+                if (device.rules[i].dstip == packet.network.srcip) {
+                    found = true;
+                }
+            }
+            if(!found){
+                device.rules[device.rules.length] = {
+                    dstip: packet.network.srcip,
+                    portNum: 3
+                }
+            }
+        }
     }
+}
 
 
-        
+    
 }
 

+ 1 - 1
levels/02 Spoofs/spoofs02.html

@@ -12,7 +12,7 @@ connected over time.
 To do this, take advantage of the switch's learning process to direct packets with a dstip of Charlie to Alice's
 computer.
 
-<p><em><strong>Hint:</strong> Use the timer in the top right of the Simulator&mdash;beating this level will require careful timing!</em>
+<p><em><strong>Hint:</strong> This level will require careful timing! Make sure you launch your packet at the correct time in the simulation. Use the restart button to experiment with different timings.</em>
 
 <h3>Level Objectives</h3>
 

+ 8 - 6
levels/02 Spoofs/spoofs02.json

@@ -2,7 +2,7 @@
 	devices:[
 		{
 			id:"Alice",
-			type:"NullComputer",
+                        image: "macbook",
 			ports:1,
 			x:0.25,
 			y:0.25,
@@ -10,28 +10,30 @@
 		},
 		{
 			id:"Bob",
-			type:"NullComputer",
+                        image: "macbook",
 			ports:1,
 			x:0.25,
 			y:0.5
 		},
 		{
 			id:"Charlie",
-			type:"NullComputer",
+                        image: "iphone-1",
 			ports:1,
 			x:0.25,
 			y:0.75
 		},
 		{
 			id:"Central Hub",
-			type:"Switch",
+                        image: "router",
 			ports:4,
 			x:0.5,
-			y:0.5
+			y:0.5,
+                        script: deviceScripts.switch,
+                        rules: []
 		},
 		{
 			id:"Google",
-			type:"NullComputer",
+                        image: "server",
 			ports:1,
 			x:0.75,
 			y:0.5