| 01 import javax.virtualsense.network.*; |
| 02 |
| 03 public class MinPathProtocol extends Protocol{ |
| 04 |
| 05 private short minHops = Short.MAX_VALUE; |
| 06 private short epoch = 0; |
| 07 |
| 08 protected void packetHandler(Packet p){ |
| 09 if(p instanceof InterestMsg){ |
| 10 InterestMsg interest = (InterestMsg)p; |
| 11 if(interest.getEpoch() > this.epoch){ |
| 12 this.epoch = interest.getEpoch(); |
| 13 super.bestPath = −1; |
| 14 this.minHops = Short.MAX_VALUE; |
| 15 } |
| 16 if(interest.getHops() < this.minHops){ |
| 17 this.minHops = interest.getHops(); |
| 18 super.bestPath = interest.getSender(); |
| 19 interest.setHops(interest.getHops()+1); |
| 20 super.sendBroadcast(interest); |
| 21 } |
| 22 }else if(p instanceof DataMsg) { |
| 23 DataMsg data = (DataMsg)p; |
| 24 if(data.toForward()) |
| 25 super.send(data); |
| 26 else |
| 27 super.notifyReceiver(); |
| 28 } |
| 29 }//end method |
| 30 }// Tend class |