blob: 912db1c2683f6598249b76e77e17ab8adb5caa0e [file] [log] [blame]
Jonathan Hart8f6dc092014-04-18 15:56:43 -07001package net.onrc.onos.apps.sdnip;
pingping-lina2cbfad2013-03-07 08:39:21 +08002
3import org.slf4j.Logger;
4import org.slf4j.LoggerFactory;
5
6public class PtreeNode {
Ray Milkey269ffb92014-04-03 14:43:30 -07007 public PtreeNode parent;
8 public PtreeNode left;
9 public PtreeNode right;
10
Ray Milkey45614c52014-04-07 16:30:54 -070011 public byte[] key;
Ray Milkey269ffb92014-04-03 14:43:30 -070012 public int keyBits;
13
14 public int refCount;
15
Pavlin Radoslavovb6309292014-04-11 03:25:47 -070016 // public RibEntry rib;
Jonathan Hart816512c2014-04-11 11:07:49 -070017 private static final Logger log = LoggerFactory.getLogger(PtreeNode.class);
Ray Milkey269ffb92014-04-03 14:43:30 -070018
Ray Milkey9526d6f2014-04-10 14:54:15 -070019 PtreeNode(byte[] key, int keyBits, int maxKeyOctet) {
Ray Milkey269ffb92014-04-03 14:43:30 -070020 parent = null;
21 left = null;
22 right = null;
23 refCount = 0;
Pavlin Radoslavovb6309292014-04-11 03:25:47 -070024 // rib = null;
Ray Milkey9526d6f2014-04-10 14:54:15 -070025 this.key = new byte[maxKeyOctet];
26 this.keyBits = keyBits;
27 log.debug("inside Ptreenode constructor key {} bits {}", key, keyBits);
Ray Milkey269ffb92014-04-03 14:43:30 -070028
Ray Milkey7531a342014-04-11 15:08:12 -070029 int octet = Ptree.bitToOctet(keyBits);
Ray Milkey9526d6f2014-04-10 14:54:15 -070030 for (int i = 0; i < maxKeyOctet; i++) {
Ray Milkey269ffb92014-04-03 14:43:30 -070031 if (i < octet) {
32 if (key != null) {
33 log.debug(octet + ": filling key[{}] {}", i, key[i]);
34 this.key[i] = key[i];
35 } else {
Naoki Shiota72afb332014-07-22 17:39:00 -070036 log.debug("no filling, null key");
Ray Milkey269ffb92014-04-03 14:43:30 -070037 }
38 } else {
39 log.debug("filling key {} as 0", i);
40 this.key[i] = 0;
41 }
42 }
43 }
pingping-lina2cbfad2013-03-07 08:39:21 +080044}