2 * Copyright (c) 2018 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.hc2vpp.it.jvpp.benchmark.classify;
19 import io.fd.vpp.jvpp.core.dto.ClassifyAddDelTable;
20 import java.util.Random;
21 import javax.annotation.concurrent.NotThreadSafe;
24 class ClassifyTableProviderImpl implements ClassifyTableProvider {
26 * Static seed to make rnd.nextBytes() output the same for all test run.
28 private static final long SEED = -2084670072119134328L;
29 private final int tableSetSize;
30 private final ClassifyAddDelTable[] tables;
31 private final Random rnd = new Random(SEED);
34 * Pointer to Classify table to be returned by invocation of {@link #next()} method.
36 private int currentTable = 0;
38 ClassifyTableProviderImpl(final int tableSetSize) {
39 this.tableSetSize = tableSetSize;
40 tables = new ClassifyAddDelTable[tableSetSize];
41 initTables(tableSetSize);
45 public ClassifyAddDelTable next() {
46 final ClassifyAddDelTable result = tables[currentTable];
47 currentTable = (currentTable + 1) % tableSetSize;
51 private void initTables(final int tableSetSize) {
52 for (int i = 0; i < tableSetSize; ++i) {
53 tables[i] = createTable();
57 private ClassifyAddDelTable createTable() {
58 final ClassifyAddDelTable addDelTable = new ClassifyAddDelTable();
59 addDelTable.isAdd = 1;
60 addDelTable.tableIndex = -1;
61 addDelTable.nbuckets = 2;
62 addDelTable.memorySize = 2 << 20;
63 addDelTable.nextTableIndex = ~0;
64 addDelTable.missNextIndex = ~0;
65 addDelTable.skipNVectors = 0;
66 addDelTable.matchNVectors = 1;
67 addDelTable.mask = new byte[16];
68 addDelTable.maskLen = 16;
69 rnd.nextBytes(addDelTable.mask);