Add FlowIdGenerator's implementation class.
- Updated FlowId to use long internally
- Implemented FlowIdGeneratorWithIdBlockAllocator class as an implementation class of FlowIdGenerator.
Change-Id: Id3bcb47c63217b0ea4a2f7d5ae208532783c323a
diff --git a/src/test/java/net/onrc/onos/core/flowmanager/FlowIdGeneratorWithIdBlockAllocatorTest.java b/src/test/java/net/onrc/onos/core/flowmanager/FlowIdGeneratorWithIdBlockAllocatorTest.java
new file mode 100644
index 0000000..9546f6e
--- /dev/null
+++ b/src/test/java/net/onrc/onos/core/flowmanager/FlowIdGeneratorWithIdBlockAllocatorTest.java
@@ -0,0 +1,48 @@
+package net.onrc.onos.core.flowmanager;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import net.onrc.onos.api.flowmanager.FlowId;
+import net.onrc.onos.core.util.IdBlock;
+import net.onrc.onos.core.util.IdBlockAllocator;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link FlowIdGeneratorWithIdBlockAllocator} class.
+ */
+public class FlowIdGeneratorWithIdBlockAllocatorTest {
+ private IdBlockAllocator allocator;
+ private FlowIdGeneratorWithIdBlockAllocator flowIdGenerator;
+
+ @Before
+ public void setUp() {
+ allocator = createMock(IdBlockAllocator.class);
+
+ }
+
+ /**
+ * Tests generated FlowId sequences using two {@link IdBlock blocks}.
+ */
+ @Test
+ public void testIds() {
+ expect(allocator.allocateUniqueIdBlock())
+ .andReturn(new IdBlock(0, 3))
+ .andReturn(new IdBlock(4, 3));
+
+ replay(allocator);
+ flowIdGenerator = new FlowIdGeneratorWithIdBlockAllocator(allocator);
+
+ assertThat(flowIdGenerator.getNewId(), is(new FlowId(0L)));
+ assertThat(flowIdGenerator.getNewId(), is(new FlowId(1L)));
+ assertThat(flowIdGenerator.getNewId(), is(new FlowId(2L)));
+
+ assertThat(flowIdGenerator.getNewId(), is(new FlowId(4L)));
+ assertThat(flowIdGenerator.getNewId(), is(new FlowId(5L)));
+ assertThat(flowIdGenerator.getNewId(), is(new FlowId(6L)));
+ }
+}
diff --git a/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java b/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java
index 6c83e86..c9da728 100644
--- a/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java
+++ b/src/test/java/net/onrc/onos/core/newintent/PathFlowIntentTest.java
@@ -19,7 +19,7 @@
private final IntentId intentId1 = new IntentId(123);
private final IntentId intentId2 = new IntentId(456);
- private final FlowId flowId1 = new FlowId("path1");
+ private final FlowId flowId1 = new FlowId(1L);
private final PacketMatch match = new PacketMatchBuilder().build();
private final PortNumber port = new PortNumber((short) 1);
diff --git a/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java b/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java
index 4ad202e..3799889 100644
--- a/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java
+++ b/src/test/java/net/onrc/onos/core/newintent/SingleDstTreeFlowIntentTest.java
@@ -22,7 +22,7 @@
private final IntentId intentId1 = new IntentId(1L);
private final IntentId intentId2 = new IntentId(2L);
- private final FlowId flowId1 = new FlowId("intent1");
+ private final FlowId flowId1 = new FlowId(1L);
private final PacketMatch match = new PacketMatchBuilder().build();
private final short port1 = (short) 1;
private final short port2 = (short) 2;
diff --git a/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java b/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java
index 3330e47..cfd9391 100644
--- a/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java
+++ b/src/test/java/net/onrc/onos/core/newintent/SingleSrcTreeFlowIntentTest.java
@@ -25,8 +25,8 @@
private final IntentId intentId1 = new IntentId(1L);
private final IntentId intentId2 = new IntentId(2L);
- private final FlowId flowId1 = new FlowId("tree1");
- private final FlowId flowId2 = new FlowId("tree2");
+ private final FlowId flowId1 = new FlowId(1L);
+ private final FlowId flowId2 = new FlowId(2L);
private final Dpid dpid1 = new Dpid(1);
private final Dpid dpid2 = new Dpid(2);
private final Dpid dpid3 = new Dpid(3);