M. Kelly, Appendices Simulated Annealing and N Generals as applied to a Synchronized Distributed Operation Matthew R. Kelly Submitted for: CS695 – Monte Carlo Methods Old Dominion University April 26, 2011 1. Introduction This paper intends to determine the level of applicability of simulated annealing to a distributed operation where one host synchronously distributes a command with the potential for the coordination messages to be lost a la the Two Generals problem. Through the application of simulated annealing and a justified payload function, this paper hopes to find a global minimum or at least a function to specify the relation of local minima. 2. Integrating Problems and Techniques Because this paper attempts to integrate multiple problems and ideas, each of simulated annealing, the Two Generals problem and the variant means of distributed execution is explained here. Simulated annealing is a process adapted from the tempering of a sword to establish maximum molecular strength. The process can be applied to many classical problems including finding the global minimum of a function. Press applied simulated annealing to the discrete Travelling Salesman problem in “Simulated Annealing Methods” with little convincible success.1 However, because the problem this paper hopes to accomplish is a discrete process slightly similar to Traveling Salesman, exercising the versatility of Press’s method (he claims potentially wide application). The Two Generals problem is as follows. Two generals, in two valleys separated by a valley between them must coordinate a time to attack the enemy in the splitting valley. If attacks are not synchronized, they fail. To communicate, the generals must pass messages through the inner valley but some of the messages get trapped and are not communicated to the intended recipient. A scenario such as this is analogous to how networking protocols deal with packet loss. M. Kelly, Page 2/10 The problem we wish to overcome uses both simulated annealing and the Two Generals problem as a basis. Our objective is to determine the maximum payload of a distributed command. In the problem, many (potentially zombie, i.e. machines which have been hijacked) peers exist that would require data and the data is distributed from a single source and only broadcast to the reached peers once. We would like to maximize the number of peers that receive the data and execute the command from the source. An application for this method would be to distribute a command to many zombie PCs that have had malware installed to perform some action only after receiving the command from the source. The greater number of machines that receive the command, the greater the effectiveness of the attack. Much like the Two Generals problem, assurance of the reception of communications is key in executing the command effectively. We translate this to the form of “setup packets” that are initially sent to the zombie peers, telling them to open the receiving port on the machine at a certain time so the command can be received. This is much like one general sending the “attack at time X” message to the other general. The degree of success of this problem is gauged on the number of peers that issue the synchronized command. The effect of this single operation can be correlated to a Payload. 3. Building a Formula to Quantify Payload While any formula to calculate the payload value (i.e. a quantifier for the effectiveness of the number of zombie peers that receive the command) can be arbitrarily chosen to represent the effectiveness of the operation, building the formula piecemeal assures that we are initially obtaining results we desire so the procedure can then be abstracted onto arbitrary situation. Elements that should be accounted for in the payload equation are the total number of peers, the time required to complete the entire operation, the number of times the operation could have been performed but was delayed with the hope of obtaining a better penetration rate and the number of peers that receive the final command. We can first assume that the system takes minimally n+2 clock cycles to complete. This is derived from the assumption that on each clock cycle, the source can send then receive. The first operation would only have a “send”, the n+1th clock cycle would only have a “receive” and the n+2th clock cycle would contain the broadcast command. M. Kelly, Page 3/10 π‘ππ‘ππ ππ’ππππ ππ πππππ +2 The temporal efficiency of the operation be can represented as:π‘ππ‘ππ πππππ ππ¦ππππ ππππ’ππππ . At peek temporal efficiency, the payload will be 1. To account for situations where not all peers receive the command, we can add a scalar to the number of peers value of ( πππππ ππππππ£ππ πππππππ )π‘ππ‘ππ π‘ππ‘ππ ππ’ππππ ππ πππππ ππ’ππππ ππ πππππ +2 π‘ππ‘ππ πππππ ππ¦ππππ ππππ’ππππ . To enforce a penalty for mistimed executions (where the peers are told to expect an exec command at a certain time and the master node changes its heuristic to wait for more nodes to be included but fails to successfully deliver the re-schedule πππ π ππ ππ₯πππ message), a penalty of ∑#π=1 (πππππ ππππππ£ππ πππππππ π€βππ πππ π ππ ππ₯πππ ∗ π€πππβπ‘ ππ π πππ π ππ ππ₯ππ) where λ is a weight value/scalar that we can manipulate (i.e. a control variable T)for a final payload calculation formula of: πππ¦ππππ = πππππ ππππππ£ππ πππππππ )π‘ππ‘ππ ππ’ππππ ππ πππππ +2 π‘ππ‘ππ ππ’ππππ ππ πππππ # πππ π ππ ππ₯πππ πππππ ππ¦ππππ ππππ’ππππ+ ∑π=1 πππππ ππππππ£ππ πππππππ π€βππ πππ π ππ ( π‘ππ‘ππ ππ₯πππ ∗π€πππβπ‘ ππ π πππ π ππ ππ₯ππ #ππππ£π ( π )π + 2 πππ¦ππππ = πππ π ππ ππ₯πππ π + ∑#π=1 (#ππππ£ππ ∗ π) Contrary to a peer not knowing the state of other peers (which would be a requirement in a blind scenario like a Distributed Denial of Service [DDoS] attack), the common knowledge is not necessarily essential in accepting a result, as the likely result might be one where at least one (or more) peers will always be excluded from the broadcast.1 A quick trial to test this formula (Appendix A) shows that it is representative of the idea of, “more ACKs = greater payload”. To formalize the requirements of simulated annealing, four elements are needed: 1. The system configuration consists of the number of peers from 1 to n. When numbered in this way, we can determine the ideal and level of optimality of results execution scenarios. 1 Gyytrasiewicz et al state that common knowledge is essential in a “best payoff” system like this and that because common knowledge is not attainable in logic-based systems, an “eager protocol” involving blind faith (the host executes regardless of whether it has received all ACKs requested) defies the logical basis of the original problem. M. Kelly, Page 4/10 2. The random changes parameter will consist of extending and contracting the time coordination that is sent to the peers. A longer time penalty will result in less temporal efficiency but heighten the likelihood that all peers will receive a coordinated message. Too little time will result in a scenario with potentially few peers executing if the ACK is not received. 3. The objective function E is that of the Payload function described above. 4. The control parameter is the penalty incurred for incorrectly synchronized peers executing, λ. A further assumption is that the broadcast message from the source to the peers will not be intercepted. In practicality, this is easily implemented but without this trait, the sampling would not be accurately reflected in the result. 4. Preliminary Results Because the annealing schedule of λ can range from zero to infinity (resulting in no penalty to annihilation of any other parameters, respectively), using Press’s method of determining the ΔE (the range of the Payload function) on which to base λ will not work, as slowly decreasing λ from infinity is not practical. Each step requires the clock cycle to be incremented, leaving the possibilities (given a static λ) of either no effect on the payload (e.g. all peers have ACKed and are waiting for the broadcast) or a detrimental effect on the payload (either all peers have not ACKed and are still being requested to do so, the clock has exceeded the original synchronized time of broadcast or a broadcast command is issued and all Various Scenarios Given 3 Peers peers have no ACKed). With a large λ, the jump different colorized categories on the plot in Figure 1) are less likely to be selected and the sequence will continue payload w/ no miss payload with 1 miss(λ=1),100% recvd 0.6 payload with 1 0.4 miss(λ=1),missing 1 ACK payload with 1 0.2 miss(λ=0.5),100%recvd 05 payload with 1 7 execution, a potential payload value will cause categories to be Figure 1. Upon miss(λ=0.5),missing 1 ACK 9 switched if results 11 are not ideal payload with 1 Clock Cycle 13 15 miss(λ=1.5),100%recvd Required for 17 Completion Payload (%) between scenarios (the 1 0.8 M. Kelly, Page 5/10 cycling clocks until a final broadcast and a payload calculation. As the λ is decreased, the likelihood of the category to be switched, that is, the acceptance of the step toward increasing the required clock cycles in exchange for the possibility of receiving ACKs from more peers increases. Following this procedure will result in the optimal payload for a series of executions. 5. Improvements and Naïveté The dynamics of this system could be more simplistic or complicated and doing so would affect the rate of command efficiency and increase the payload. An improvement of this scheme, for example, would be to include a smarter, potentially adaptive algorithm for anticipating that a broadcast will have suboptimal results. 6. Works Cited Piotr J. Gmytrasiewicz and Edmund H. Durfee. “Decision-theoretic recursive modeling and the coordinated attack problem.” In Proceedings of the first international conference on Artificial intelligence planning systems, James Hendler (Ed.). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, 88-95. 1992. Press W.H. et al. “Simulated Annealing Methods.” Numerical Recipes in C: The Art of Scientific Computing. 2nd ed. Cambridge, MA: Cambridge Press, 1992. Web. M. Kelly, Appendices Appendix A: Sample Execution Ideal Transmission Procedure CC Send 1 sο peer 1, “exec cc5” 2 sο peer 2, “exec on cc5” 3 sο peer 3, “exec on cc5” 4 5 Recvd peer 1, “ok cc5” peer 2, “ok cc5” peer 3, “ok cc5” s broadcast Transmission Procedure With Latency and Successful Retry Send Recvd Transmission Procedure With Latency and Successful Retry Send Recvd Send sο peer 1, “exec on cc10” sο peer 2, “exec on cc10” sο peer 1, “exec on cc7” sο peer 2, “exec on cc7” sο peer 1, “exec on cc7” sο peer 2, “exec on cc7” sο peer 3, “exec on cc10” peer 1, “ok cc10” peer 2, “ok cc10” (waiting for peer 3) sο peer 3, “exec on cc10” 6 sο peer 3, “exec on cc7” peer 1, “ok cc7” peer 2, “ok cc7” (waiting for peer 3) sο peer 3, “exec on cc10” 8 9 peer 3, “ok cc10” idle waiting for cc10 10 s broadcast 1114 15 (waiting for peer 3) sο peer 1, “exec on cc15” sο peer 2, “exec on cc15” sο peer 3, “exec on cc15” 3 ( )3 + 2 3 = 0.5 10 + 0 ∗ π Recvd peer 1, “ok cc7” peer 2, “ok cc7” (waiting for peer 3) sο peer 3, “exec on cc7” peer 1, “ok cc15” peer 2, “ok cc15” peer 3, “ok cc15” idle waiting for cc15 3 ( )3 + 2 3 = 1.0 5+ 0∗π sο peer 3, “exec on cc7” (waiting for peer 3) sο peer 3, “exec on cc7” 7 Transmission With Latency and Failed Retry s broadcast 3 ( )3 + 2 3 = 0.33 15 + 0 ∗ π (waiting for peer 3) sο peer 1, “exec on cc15” sο peer 2, peer 1, “exec on “ok cc15” cc15” sο peer 2, (waiting “exec on for peer cc15” 2) sο peer 3, (waiting “exec on for peer cc15” 2) re-send to peer 2 & peer 3 without avail s broadcast 1 ( )3 + 2 3 = 0.33π 15 + 1 ∗ π M. Kelly, Appendices Appendix B: Sample Code package simulatedannealingpaper; import java.util.Random; import java.util.Arrays; public class Main { int peerFocus; //the current peer selected when traversing through set Peer [] peers; //accessible means for all peers String [] commandReceived; //populated by peer once ACK rececived String log = ""; public static void main(String[] args) { Main m = new Main(); int numberOfPeers = 100; //static, a given for(int ccToExec=numberOfPeers+2; ccToExec<(numberOfPeers+2)*3; ccToExec++){ //int ccToExec = numberOfPeers+2; double best = 0.0; //save best possible payload for sequence double payloadAvg = 0.0; int iterations = 10; Random penaltyRandom = new Random(); //decrement annealer with each iteration double lambda = (penaltyRandom.nextDouble()+1)*((numberOfPeers+2)ccToExec); for(int iteration=0; iteration<iterations; iteration++){ double payload = m.exec(numberOfPeers, ccToExec, lambda,true); System.out.println(iteration+1+"| numberOfPeers: "+numberOfPeers+" lambda:"+lambda+" payload: "+payload); payloadAvg += payload; if(payload > best){ //System.out.println("Found new best in "+payload); best = payload;} } System.out.println("Avg: "+payloadAvg/iterations); }// //System.out.println(m.log+"\r\n"+payload); } double exec(int numberOfPeers, int CCtoExec, double weightOfMissedExec, boolean oneHundredPercentNeeded){ this.log = ""; this.peers = new Peer[numberOfPeers]; this.commandReceived = new String[CCtoExec+1]; //messages received at a certain cc for(int p=0; p<peers.length; p++){peers[p] = new Peer();}//init peer objs int [] peersAlreadySyncd; //used to calculate lambda penalty this.peerFocus = 0; //the last peer sent a command M. Kelly, Page 8/10 for(int cc=1; cc<CCtoExec; cc++){ int peer = this.getNextPeerToProcess(); //System.out.println("Next peer:"+peer); this.log("CC"+cc); if(peer!=-1){ boolean reccmd = this.peers[peer].receivedCommand(CCtoExec,cc); this.log(" s->p"+peer); if(cc+1 >= CCtoExec){ if(!oneHundredPercentNeeded){this.peers[peer].syncd = false;} //no time to ACK! else { //copy commandReceived[] to array double the size this.commandReceived = Arrays.copyOf(this.commandReceived,this.commandReceived.length*2); CCtoExec *= 2; //here be the "lambda logic" //collect all that have been synced for(int pp = 0, pasAryI=0; pp<this.peers.length; pp++){ this.peers[pp].syncd = false; } } } else if(reccmd){//no time to receive ACK if CC before broadcast if(this.commandReceived[cc+1]==null){this.commandReceived[cc+1]="";} this.commandReceived[cc+1] += "| p"+this.peerFocus+":ok"+this.peers[this.peerFocus].ccToExec+""; } this.peerFocus++; //advance to next peer regardless of recvd if(this.commandReceived[cc]!=null){this.log(this.commandReceived[cc]);} }else if(this.commandReceived[cc]!=null){ //no send, just recv this.log(" |"+this.commandReceived[cc]); } else { this.log(" (waiting for exec)"); } this.log("\r\n"); } //exec int numberOfPeersReceivingCommand = 0; for(int p=0; p<this.peers.length; p++){if(this.peers[p].syncd){numberOfPeersReceivingCommand++;}} this.log("CC"+CCtoExec+" to "+numberOfPeersReceivingCommand+" peers\r\n"); //calc payload here return this.getPayload(CCtoExec,weightOfMissedExec); } double getPayload(int ccsRequired, double weightOfMissedExec){ //determine number of peers that received command M. Kelly, Page 9/10 int numberOfPeersReceivingCommand = 0; int missedExecs = 0; for(int p=0; p<this.peers.length; p++){ if(this.peers[p].syncd){numberOfPeersReceivingCommand++;} if(this.peers[p].missedExecs > 0){missedExecs += this.peers[p].missedExecs;} } double payload = (((double)numberOfPeersReceivingCommand/(double)this.peers.length)*(double)this.peers .length + 2.0 ) / ((double)ccsRequired+(double)weightOfMissedExec*(double)missedExecs); return payload; } int getNextPeerToProcess(){ if(this.peerFocus>=this.peers.length){this.peerFocus=0;} //start back at first peer if(!this.peers[this.peerFocus].syncd){return this.peerFocus;} //if current is not synced, ret current int peerFocusPivot = this.peerFocus; this.peerFocus++; int peersProcessed = 0; while(this.peerFocus != peerFocusPivot && peersProcessed <=this.peers.length){ if(this.peerFocus >= this.peers.length){this.peerFocus = 0;} if(!this.peers[this.peerFocus].syncd){return this.peerFocus;} this.peerFocus++; peersProcessed++; } return -1; //all peers satisfied } void log(String str){ this.log += str; } } class Peer { Random r; boolean syncd; int ccToExec; int missedExecs; Peer(){r = new Random(); syncd=false; missedExecs = 0;} boolean receivedCommand(int ccToExecIn, int currentClockCycle){ //if already set here, check if CC has passed, if so, add to missed val for penalty if(this.ccToExec != 0){ //it is being redefined here if(this.ccToExec<currentClockCycle){this.missedExecs++;} } boolean res = this.r.nextBoolean(); M. Kelly, Page 10/10 if(res){this.syncd = true;this.ccToExec = ccToExecIn;} return res; } }