blob: 10b92afbdbcb40c98c59ddbb78ad7a49f59ffa4e [file] [log] [blame]
Carmelo Cascone00a59962017-06-16 17:51:49 +09001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17package org.onosproject.net.pi.impl;
18
19
20import org.apache.commons.lang3.tuple.Pair;
21import org.onlab.util.ImmutableByteSequence;
22import org.onosproject.net.flow.criteria.Criterion;
23
24import static org.onlab.util.ImmutableByteSequence.ByteSequenceTrimException;
25
26/**
27 * A translator of a criterion instance to different match types represented as primitive byte sequences.
28 */
29interface CriterionTranslator {
30
31 /**
32 * Initialize this translator with the given criterion and field match bit-width.
33 *
34 * @param criterion criterion
35 * @param bitWidth field bit-width
36 * @throws ByteSequenceTrimException if the criterion cannot be trimmed to fit the field match bit-width
37 */
38 void init(Criterion criterion, int bitWidth) throws ByteSequenceTrimException;
39
40 /**
41 * Returns a pair of byte sequences representing a ternary match (value and mask) equivalent to the criterion given
42 * when initialized. The returned byte sequences will have minimum size (i.e. rounded to the nearest byte) to
43 * contain the initialized field bit-width.
44 *
45 * @return a pair of byte sequences with value on the left and mask on the right
46 * @throws CriterionTranslatorException if the criterion cannot be translated
47 */
48 Pair<ImmutableByteSequence, ImmutableByteSequence> ternaryMatch() throws CriterionTranslatorException;
49
50 /**
51 * Returns a pair comprising a byte sequence and a prefix length representing a longest-prefix match equivalent to
52 * the criterion given when initialized. The returned byte sequence will have minimum size (i.e. rounded to the
53 * nearest byte) to contain the initialized field bit-width.
54 *
55 * @return a pair with the match value's byte sequence on the left, and prefix length on the right
56 * @throws CriterionTranslatorException if the criterion cannot be translated
57 */
58 Pair<ImmutableByteSequence, Integer> lpmMatch() throws CriterionTranslatorException;
59
60 /**
61 * Returns a byte sequence representing an exact match equivalent to the criterion given when initialized. The
62 * returned byte sequence will have minimum size (i.e. rounded to the nearest byte) to contain the initialized field
63 * bit-width.
64 *
65 * @return exact match value as a byte sequence
66 * @throws CriterionTranslatorException if the criterion cannot be translated
67 */
68 ImmutableByteSequence exactMatch() throws CriterionTranslatorException;
69
70 /**
71 * Signifies that the criterion cannot be translated.
72 */
73 class CriterionTranslatorException extends Exception {
74 CriterionTranslatorException(String message) {
75 super(message);
76 }
77 }
78}