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.io.Serializable;
21 import java.util.Random;
22 import javax.annotation.concurrent.NotThreadSafe;
25 class ClassifyTableProviderImpl implements ClassifyTableProvider {
27 * Static seed to make rnd.nextBytes() output the same for all test run.
29 private static final long SEED = -2084670072119134328L;
30 private final int tableSetSize;
31 private final ClassifyAddDelTable[] tables;
32 private final Random rnd = new Random(SEED);
35 * Pointer to Classify table to be returned by invocation of {@link #next()} method.
37 private int currentTable = 0;
39 ClassifyTableProviderImpl(final int tableSetSize) {
40 this.tableSetSize = tableSetSize;
41 tables = new ClassifyAddDelTable[tableSetSize];
42 initTables(tableSetSize);
46 public ClassifyAddDelTable next() {
47 final ClassifyAddDelTable result = tables[currentTable];
48 currentTable = (currentTable + 1) % tableSetSize;
52 private void initTables(final int tableSetSize) {
53 for (int i = 0; i < tableSetSize; ++i) {
54 tables[i] = createTable();
58 private ClassifyAddDelTable createTable() {
59 final ClassifyAddDelTable addDelTable = new ClassifyAddDelTable();
60 addDelTable.isAdd = 1;
61 addDelTable.tableIndex = -1;
62 addDelTable.nbuckets = 2;
63 addDelTable.memorySize = 2 << 20;
64 addDelTable.nextTableIndex = ~0;
65 addDelTable.missNextIndex = ~0;
66 addDelTable.skipNVectors = 0;
67 addDelTable.matchNVectors = 1;
68 addDelTable.mask = new byte[16];
69 rnd.nextBytes(addDelTable.mask);