blob: c062500f70c1eaf4ccad77db83436fd149de15b1 [file] [log] [blame]
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04001/*
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.runtime;
18
19import com.google.common.annotations.Beta;
20import org.onlab.util.Identifier;
21
22import java.util.Optional;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Identifier of a table in a protocol-independent pipeline.
28 */
29@Beta
30public final class PiTableId extends Identifier<String> {
31
32 private final String scope;
33 private final String name;
34
35 /**
36 * Creates a new table identifier for the given scope and table name.
37 *
38 * @param scope table scope
39 * @param name table name
40 */
41 public PiTableId(String scope, String name) {
42 super(checkNotNull(scope) + '.' + checkNotNull(name));
43 this.scope = scope;
44 this.name = name;
45 }
46
47 /**
48 * Creates a new table identifier for the given table name.
49 *
50 * @param name table name
51 */
52 public PiTableId(String name) {
53 super(checkNotNull(name));
54 this.name = name;
55 this.scope = null;
56 }
57
58
59 /**
60 * Returns the name of this table.
61 *
62 * @return table name
63 */
64 public String name() {
65 return name;
66 }
67
68 /**
69 * Returns the scope of this table, if present.
70 *
71 * @return optional scope
72 */
73 public Optional<String> scope() {
74 return Optional.ofNullable(scope);
75 }
76
77
78}