Advertisement
Guest User

alma

a guest
Oct 31st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. package router;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class Node {
  7.     private Node parent;
  8.     private List<Node> childs;
  9.     private IPAddress own;
  10.     private IPAddress a;
  11.     private IPAddress b;
  12.    
  13.    
  14.     public Node(IPAddress own, IPAddress a, IPAddress b) {
  15.         this.childs = new ArrayList<>();
  16.         this.own=own;
  17.         this.a=a;
  18.         this.b=b;
  19.     }
  20.    
  21.     public Node(Node parent, IPAddress own, IPAddress a, IPAddress b) {
  22.         this.parent=parent;
  23.         this.childs = new ArrayList<>();
  24.         parent.childs.add(this);
  25.         this.own=own;
  26.         this.a=a;
  27.         this.b=b;
  28.     }
  29.    
  30.     private IPAddress getOwn() {
  31.         return own;
  32.     }
  33.    
  34. public String tracePacket(Packet packet) {
  35.     /*if(packet.getDestination().isTheSame(this.own)){
  36.         if(packet.isLive() == true) {
  37.             packet.recordPath(this.own);
  38.             return packet.toString();
  39.         }else{
  40.             return "LOOP";
  41.         }
  42.     }else{
  43.         if(packet.getDestination().insideRng(this.a, this.b)){
  44.             for(Node child : childs){
  45.                 if(packet.getDestination().insideRng(child.a, child.b)){
  46.                     if(packet.isLive() == true) {
  47.                         packet.recordPath(this.own);
  48.                         child.tracePacket(packet);
  49.                     }else {
  50.                         return "LOOP";
  51.                     }
  52.                 }
  53.             }
  54.         }else{
  55.             if(parent == null){
  56.                 return "OUT";
  57.                 }else{
  58.                     if(packet.isLive() == true) {
  59.                         packet.recordPath(this.own);
  60.                         this.parent.tracePacket(packet);
  61.                     }else {
  62.                         return "LOOP";
  63.                     }
  64.                 }
  65.                 }
  66.         }
  67.             return packet.toString();*/
  68.         packet.recordPath(own);
  69.         IPAddress destiny = packet.getDestination();
  70.         if(own == destiny) {
  71.             return packet.toString();
  72.         } else {
  73.             if(!childs.isEmpty()) {
  74.                 for(Node child : childs) {
  75.                     if(destiny.insideRng(child.a,child.b)) {
  76.                         if(packet.isLive()) {
  77.                             return child.tracePacket(packet);
  78.                         } else {
  79.                             return "LOOP";
  80.                         }
  81.                     }
  82.                 }
  83.             }
  84.             if(parent != null && packet.isLive()) {
  85.                 return parent.tracePacket(packet);
  86.             } else {
  87.                 return "OUT";
  88.             }
  89.         }
  90.  
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement