var deviceScripts = {
	manualRouter: {
		onPacketReceived: function(device, packet) {
			for (var i = 0; i < device.rules.length; i++) {
				if (device.rules[i].dstip == packet.network.dstip) {
					sendPacket(device.id, device.rules[i].portNum, packet);
				}
			}
		}
	},

	hub: {
		onPacketReceived: function (device, packet) {
			//.
		}
	},

    ping: {
		onPacketReceived: function(device, packet) {
                    if(packet.hasOwnProperty("proto")){
                        if(packet.transport.proto == "ICMP"){
                            var new_packet = {
                                network: {
                                    srcip: packet.network.dstip,
                                    dstip: packet.network.srcip
                                },
                                transport: {
                                    proto: "ICMP"
                                }
                            };
                            sendPacket(device.id, 0, new_packet);
                        }
                    }
		}
    },
    modem: {
        onPacketReceived: function(device, packet) {
            if(packet.network.dstip == device.id){//look up ip in NAT table
                var new_packet = {
                    network: {
                        srcip: packet.network.srcip,
                        dstip: getPortRecipient(device.id, 0)
                    }
                };
                sendPacket(device.id, 0, new_packet);
            } else { //replace src ip with device IP and save in NAT table
                var new_packet = {
                    network: {
                        srcip: device.id,
                        dstip: packet.network.dstip
                    }
                };
                sendPacket(device.id, 1, new_packet);
            }

        }
    }


        
}


@@ -1224,32 +1224,34 @@
 r new_packet = %7B
+%7D;
 %0A               
@@ -1255,507 +1255,1067 @@
     
-    network: %7B%0A                        srcip: packet.network.srcip,%0A                        dstip: getPortRecipient(device.id, 0)%0A                    %7D%0A                %7D;%0A                sendPacket(device.id, 0, new_packet);%0A            %7D else %7B //replace src ip with device IP and save in NAT table%0A                var new_packet = %7B%0A                    network: %7B%0A                        srcip: device.id,%0A                        dstip: packet.network.dstip%0A                    %7D%0A                %7D
+for (var i = 0; i %3C packetFields.length; i++) %7B%0A                    new_packet%5BpacketFields%5Bi%5D.layer%5D = %7B%7D;%0A                    for (var j = 0; j %3C packetFields%5Bi%5D.fields.length; j++) %7B%0A                        new_packet%5BpacketFields%5Bi%5D.layer%5D%5B packetFields%5Bi%5D.fields%5Bj%5D %5D = packet%5BpacketFields%5Bi%5D.layer%5D%5B packetFields%5Bi%5D.fields%5Bj%5D %5D;%0A                    %7D%0A                %7D%0A                new_packet.network.dstip = getPortRecipient(device.id, 0);%0A                sendPacket(device.id, 0, new_packet);%0A            %7D else %7B //replace src ip with device IP and save in NAT table%0A                var new_packet = %7B%7D;%0A                for (var i = 0; i %3C packetFields.length; i++) %7B%0A                    new_packet%5BpacketFields%5Bi%5D.layer%5D = %7B%7D;%0A                    for (var j = 0; j %3C packetFields%5Bi%5D.fields.length; j++) %7B%0A                        new_packet%5BpacketFields%5Bi%5D.layer%5D%5B packetFields%5Bi%5D.fields%5Bj%5D %5D = packet%5BpacketFields%5Bi%5D.layer%5D%5B packetFields%5Bi%5D.fields%5Bj%5D %5D;%0A                    %7D%0A                %7D%0A                new_packet.network.srcip = device.id
 ;%0A  

update to modem script