Skip to content
Browse files

Some fixes to address masking and other things.

  • Loading branch information...
1 parent 046d1f7 commit 9504221315f932b26b1b3c9bdefc1c24fba80070 @leth committed Mar 10, 2011
View
5 .gitignore
@@ -1 +1,4 @@
-target
+target
+.classpath
+.project
+.settings
View
4 src/main/java/uk/co/marcuscobden/allocationcurve/AllocationCurve.java
@@ -74,8 +74,8 @@ public static void main(final String[] args)
// }
// else
// {
- File input = new File("target/test-classes/examples/UoS.yaml");
- File output = new File("target/test-classes/examples/test1.svg");
+ File input = new File("target/test-classes/examples/test4.yaml");
+ File output = new File("target/test-classes/examples/test4.svg");
try
{
generateOutput(input, output);
View
2 src/main/java/uk/co/marcuscobden/allocationcurve/allocation/Inet4NetworkAllocationBlock.java
@@ -25,7 +25,7 @@
{
public Inet4NetworkAllocationBlock(final Inet4Address address,
- final byte size)
+ final int size)
{
super(address, size);
View
6 src/main/java/uk/co/marcuscobden/allocationcurve/allocation/Inet6NetworkAllocationBlock.java
@@ -25,12 +25,12 @@
{
public Inet6NetworkAllocationBlock(final Inet6Address address,
- final byte size)
+ final int size)
{
super(address, size);
- if (size >= 128)
- throw new IllegalArgumentException("TODO");
+ if (size > 128)
+ throw new IllegalArgumentException("TODO"); // TODO proper exception message.
}
public int compareTo(final Inet6NetworkAllocationBlock o)
View
19 src/main/java/uk/co/marcuscobden/allocationcurve/allocation/InetNetworkAllocationBlock.java
@@ -55,25 +55,28 @@ public static void printAddress(InetAddress add)
}
protected static InetAddress blankSuffix(final InetAddress address,
- final byte size)
+ final int size)
{
byte[] bytes = address.getAddress();
boolean changed = false;
- // TODO test this works correctly
for (int i = 0; i < bytes.length * 8; i += 8)
{
int block = (int) Math.floor(i / 8);
byte mask;
- if (i +(8-1) <= size)
+ if (i +(8-1) < size)
{
mask = ~0;
}
+ else if (i > size)
+ {
+ mask = 0;
+ }
else
{
- mask = (byte) ((~0) << (7 - (i % 8)));
+ mask = (byte) ((~0) << (8 - ((size -i) % 8)));
}
byte prev = bytes[block];
@@ -134,7 +137,7 @@ protected static InetAddress blankSuffix(final InetAddress address,
{
throw new IllegalArgumentException(e);
}
- byte size = Byte.parseByte(matcher.group(2));
+ int size = Integer.parseInt(matcher.group(2));
if (type == Inet4NetworkAllocationBlock.class)
{
@@ -155,11 +158,11 @@ else if (type == Inet6NetworkAllocationBlock.class)
protected InetAddressType address;
- protected byte size;
+ protected int size;
@SuppressWarnings("unchecked")
protected InetNetworkAllocationBlock(final InetAddressType address,
- final byte size)
+ final int size)
{
this.address = (InetAddressType) blankSuffix(address, size);
this.size = size;
@@ -209,7 +212,7 @@ public InetAddressType getAddress()
return address;
}
- public byte getSize()
+ public int getSize()
{
return size;
}
View
149 src/main/java/uk/co/marcuscobden/allocationcurve/renderer/HilbertAllocationRenderer.java
@@ -79,85 +79,80 @@ public HilbertAllocationRenderer(final Dimension size)
public Rectangle2D.Double getBlockBounds(
final InetNetworkAllocationBlock<InetAddress> block, int startBit, int finishBit)
{
-// void in6_addr_to_xy(struct in6_addr* ip_addr, char size,
-// char start_bit, char finish_bit,
-// int width, int height,
-// double *xp, double *yp, double *wp, double *hp)
-// {
- // State shapes
- // 0 = u, 1 = c, 2 = n, 3 = ]
- // Initial state of lines = 3
- int state = 0;
-
- double x, y, oX, oY, w, h;
- x = y = 0;
- // inital offset is half the size
- oX = this.size.width /2d;
- oY = this.size.height /2d;
- w = this.size.width;
- h = this.size.height;
-
- // Which positions cause x/y offset, by state
- byte match[][][] = {
- {{2, 3}, {1, 2}},
- {{0, 3}, {0, 1}},
- {{0, 1}, {0, 3}},
- {{1, 2}, {2, 3}}
- };
-
- // What is the next state, indexed by state, then quad position
- byte next[][] = {
- {3, 0, 0, 1},
- {2, 1, 1, 0},
- {1, 2, 2, 3},
- {0, 3, 3, 2}
- };
-
- // 0 = down, 1 = left, 2 = up, 3 = right
- // if we change the initial state, these will need to change
- byte direction[][] ={
- {0, -1, 2, -1},
- {1, -1, 3, -1},
- {2, -1, 0, -1},
- {3, -1, 1, -1}
- };
-
- // we compare 2 bits each iteration.
- for(int bit = startBit; bit +1 <= finishBit && bit < block.getSize(); bit += 2)
+ // State shapes
+ // 0 = u, 1 = c, 2 = n, 3 = ]
+ // Initial state of lines = 3
+ int state = 0;
+
+ double x, y, oX, oY, w, h;
+ x = y = 0;
+ // inital offset is half the size
+ oX = this.size.width /2d;
+ oY = this.size.height /2d;
+ w = this.size.width;
+ h = this.size.height;
+
+ // Which positions cause x/y offset, by state
+ byte match[][][] = {
+ {{2, 3}, {1, 2}},
+ {{0, 3}, {0, 1}},
+ {{0, 1}, {0, 3}},
+ {{1, 2}, {2, 3}}
+ };
+
+ // What is the next state, indexed by state, then quad position
+ byte next[][] = {
+ {3, 0, 0, 1},
+ {2, 1, 1, 0},
+ {1, 2, 2, 3},
+ {0, 3, 3, 2}
+ };
+
+ // 0 = down, 1 = left, 2 = up, 3 = right
+ // if we change the initial state, these will need to change
+ byte direction[][] ={
+ {0, -1, 2, -1},
+ {1, -1, 3, -1},
+ {2, -1, 0, -1},
+ {3, -1, 1, -1}
+ };
+
+ // we compare 2 bits each iteration.
+ for(int bit = startBit; bit +1 <= finishBit && bit < block.getSize(); bit += 2)
+ {
+ int pos = getPos(block, bit);
+
+ if (pos == match[state][0][0] || pos == match[state][0][1])
+ x += oX;
+ if (pos == match[state][1][0] || pos == match[state][1][1])
+ y += oY;
+
+ int next_state = next[state][pos];
+
+ // shrink the size of the offsets for the next set of comparisons
+ oX /= 2;
+ oY /= 2;
+ w /= 2;
+ h /= 2;
+
+ if (bit +1 >= block.getSize())
{
- int pos = getPos(block, bit);
-
- if (pos == match[state][0][0] || pos == match[state][0][1])
- x += oX;
- if (pos == match[state][1][0] || pos == match[state][1][1])
- y += oY;
-
- int next_state = next[state][pos];
-
- // shrink the size of the offsets for the next set of comparisons
- oX /= 2;
- oY /= 2;
- w /= 2;
- h /= 2;
-
- if (bit +1 >= block.getSize())
- {
- byte d = direction[state][pos];
- assert(d != -1);
-
- if ((direction[state][pos] % 2) != 0)
- w *= 2;
- else
- h *= 2;
-
- if (d == 1)
- x -= w/2;
- else if (d == 2)
- y -= h/2;
- }
-
- state = next_state;
+ byte d = direction[state][pos];
+ assert(d != -1);
+
+ if ((direction[state][pos] % 2) != 0)
+ w *= 2;
+ else
+ h *= 2;
+
+ if (d == 1)
+ x -= w/2;
+ else if (d == 2)
+ y -= h/2;
}
+
+ state = next_state;
+ }
return new Rectangle2D.Double(x, y, w, h);
}
View
9 src/main/java/uk/co/marcuscobden/allocationcurve/renderer/SVGAllocationRenderer.java
@@ -121,7 +121,14 @@ else if (blocks.size() == 1)
if (children == null || children.size() == 0 || currentDepth == depthLimit)
leaves.add(current);
}
-
+
+ // FIXME this will only work for ipv6.
+ if (finishBit == 128)
+ {
+ startBit--;
+ finishBit--;
+ }
+
out.println("<?xml version=\"1.0\"?>");
out.println("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">");
out.printf("<svg xmlns='http://www.w3.org/2000/svg' width='%d' height='%d' version='1.1'>\n", size.width, size.height);
View
0 src/test/java/.gitignore
No changes.
View
65 src/test/resources/examples/test1.txt
@@ -1,65 +0,0 @@
-::/58
-::0/64 A
-::1/64 B
-::2/64 C
-::3/64 D
-::4/64 e
-::5/64 f
-::6/64 g
-::7/64 h
-::8/64 i
-::9/64 j
-::a/64 k
-::b/64 l
-::c/64 m
-::d/64 n
-::e/64 o
-::f/64 p
-::10/64 AA
-::11/64 BB
-::12/64 CC
-::13/64 DD
-::14/64 ee
-::15/64 ff
-::16/64 gg
-::17/64 hh
-::18/64 ii
-::19/64 jj
-::1a/64 kk
-::1b/64 ll
-::1c/64 mm
-::1d/64 nn
-::1e/64 oo
-::1f/64 pp
-::20/64 A
-::21/64 B
-::22/64 C
-::23/64 D
-::24/64 e
-::25/64 f
-::26/64 g
-::27/64 h
-::28/64 i
-::29/64 j
-::2a/64 k
-::2b/64 l
-::2c/64 m
-::2d/64 n
-::2e/64 o
-::2f/64 p
-::30/64 A
-::31/64 B
-::32/64 C
-::33/64 D
-::34/64 e
-::35/64 f
-::36/64 g
-::37/64 h
-::38/64 i
-::39/64 j
-::3a/64 k
-::3b/64 l
-::3c/64 m
-::3d/64 n
-::3e/64 o
-::3f/64 p
View
196 src/test/resources/examples/test1.yaml
@@ -0,0 +1,196 @@
+label: Root block
+blocks:
+ - "::/121"
+allocations:
+ - label: A
+ blocks:
+ - "::0/128"
+ - label: B
+ blocks:
+ - "::1/128"
+ - label: C
+ blocks:
+ - "::2/128"
+ - label: D
+ blocks:
+ - "::3/128"
+ - label: e
+ blocks:
+ - "::4/128"
+ - label: f
+ blocks:
+ - "::5/128"
+ - label: g
+ blocks:
+ - "::6/128"
+ - label: h
+ blocks:
+ - "::7/128"
+ - label: i
+ blocks:
+ - "::8/128"
+ - label: j
+ blocks:
+ - "::9/128"
+ - label: k
+ blocks:
+ - "::a/128"
+ - label: l
+ blocks:
+ - "::b/128"
+ - label: m
+ blocks:
+ - "::c/128"
+ - label: n
+ blocks:
+ - "::d/128"
+ - label: o
+ blocks:
+ - "::e/128"
+ - label: p
+ blocks:
+ - "::f/128"
+ - label: AA
+ blocks:
+ - "::10/128"
+ - label: BB
+ blocks:
+ - "::11/128"
+ - label: CC
+ blocks:
+ - "::12/128"
+ - label: DD
+ blocks:
+ - "::13/128"
+ - label: ee
+ blocks:
+ - "::14/128"
+ - label: ff
+ blocks:
+ - "::15/128"
+ - label: gg
+ blocks:
+ - "::16/128"
+ - label: hh
+ blocks:
+ - "::17/128"
+ - label: ii
+ blocks:
+ - "::18/128"
+ - label: jj
+ blocks:
+ - "::19/128"
+ - label: kk
+ blocks:
+ - "::1a/128"
+ - label: ll
+ blocks:
+ - "::1b/128"
+ - label: mm
+ blocks:
+ - "::1c/128"
+ - label: nn
+ blocks:
+ - "::1d/128"
+ - label: oo
+ blocks:
+ - "::1e/128"
+ - label: pp
+ blocks:
+ - "::1f/128"
+ - label: A
+ blocks:
+ - "::20/128"
+ - label: B
+ blocks:
+ - "::21/128"
+ - label: C
+ blocks:
+ - "::22/128"
+ - label: D
+ blocks:
+ - "::23/128"
+ - label: e
+ blocks:
+ - "::24/128"
+ - label: f
+ blocks:
+ - "::25/128"
+ - label: g
+ blocks:
+ - "::26/128"
+ - label: h
+ blocks:
+ - "::27/128"
+ - label: i
+ blocks:
+ - "::28/128"
+ - label: j
+ blocks:
+ - "::29/128"
+ - label: k
+ blocks:
+ - "::2a/128"
+ - label: l
+ blocks:
+ - "::2b/128"
+ - label: m
+ blocks:
+ - "::2c/128"
+ - label: n
+ blocks:
+ - "::2d/128"
+ - label: o
+ blocks:
+ - "::2e/128"
+ - label: p
+ blocks:
+ - "::2f/128"
+ - label: A
+ blocks:
+ - "::30/128"
+ - label: B
+ blocks:
+ - "::31/128"
+ - label: C
+ blocks:
+ - "::32/128"
+ - label: D
+ blocks:
+ - "::33/128"
+ - label: e
+ blocks:
+ - "::34/128"
+ - label: f
+ blocks:
+ - "::35/128"
+ - label: g
+ blocks:
+ - "::36/128"
+ - label: h
+ blocks:
+ - "::37/128"
+ - label: i
+ blocks:
+ - "::38/128"
+ - label: j
+ blocks:
+ - "::39/128"
+ - label: k
+ blocks:
+ - "::3a/128"
+ - label: l
+ blocks:
+ - "::3b/128"
+ - label: m
+ blocks:
+ - "::3c/128"
+ - label: n
+ blocks:
+ - "::3d/128"
+ - label: o
+ blocks:
+ - "::3e/128"
+ - label: p
+ blocks:
+ - "::3f/128"
View
6 src/test/resources/examples/test2.txt
@@ -1,6 +0,0 @@
-::/60
-::0/63 A
-::2/63 B
-::4/62 i
-::8/63 j
-::39/63 ja
View
19 src/test/resources/examples/test2.yaml
@@ -0,0 +1,19 @@
+label: Root block
+blocks:
+ - "::/60"
+allocations:
+ - label: A
+ blocks:
+ - "::0:0:0:0:0/63"
+ - label: B
+ blocks:
+ - "::2:0:0:0:0/63"
+ - label: i
+ blocks:
+ - "::4:0:0:0:0/62"
+ - label: j
+ blocks:
+ - "::8:0:0:0:0/63"
+ - label: ja
+ blocks:
+ - "::39:0:0:0:0/63"
View
12 src/test/resources/examples/test3.txt
@@ -1,12 +0,0 @@
-ffff:ffff:ffff:ffff/60
-ffff:ffff:ffff:ffff/64 A
-ffff:ffff:ffff:ffff/63 A
-ffff:ffff:ffff:fffe/63 B
-ffff:ffff:ffff:fffd/63 i
-ffff:ffff:ffff:fffc/63 j
-ffff:ffff:ffff:fffb/63 k
-ffff:ffff:ffff:fffa/63 l
-ffff:ffff:ffff:fff9/63 m
-ffff:ffff:ffff:fff8/63 n
-ffff:ffff:ffff:fff7/63 o
-ffff:ffff:ffff:fff6/63 p
View
37 src/test/resources/examples/test3.yaml
@@ -0,0 +1,37 @@
+label: Root block
+blocks:
+ - "ffff:ffff:ffff:ffff::/60"
+allocations:
+ - label: A
+ blocks:
+ - "ffff:ffff:ffff:ffff::/64"
+ - label: A
+ blocks:
+ - "ffff:ffff:ffff:ffff::/63"
+ - label: B
+ blocks:
+ - "ffff:ffff:ffff:fffe::/63"
+ - label: i
+ blocks:
+ - "ffff:ffff:ffff:fffd::/63"
+ - label: j
+ blocks:
+ - "ffff:ffff:ffff:fffc::/63"
+ - label: k
+ blocks:
+ - "ffff:ffff:ffff:fffb::/63"
+ - label: l
+ blocks:
+ - "ffff:ffff:ffff:fffa::/63"
+ - label: m
+ blocks:
+ - "ffff:ffff:ffff:fff9::/63"
+ - label: n
+ blocks:
+ - "ffff:ffff:ffff:fff8::/63"
+ - label: o
+ blocks:
+ - "ffff:ffff:ffff:fff7::/63"
+ - label: p
+ blocks:
+ - "ffff:ffff:ffff:fff6::/63"
View
22 src/test/resources/examples/test4.yaml
@@ -0,0 +1,22 @@
+label: Root block
+blocks:
+ - "::/0"
+allocations:
+ - label: A
+ blocks:
+ - "0000::/1"
+ - label: B
+ blocks:
+ - "8000::/2"
+ - label: C
+ blocks:
+ - "c000::/3"
+ - label: D
+ blocks:
+ - "e000::/3"
+ - label: E
+ blocks:
+ - "efff::/3"
+ - label: F
+ blocks:
+ - "ffff::/3"

0 comments on commit 9504221

Please sign in to comment.
Something went wrong with that request. Please try again.