blob: 17408347901c904b89ae0723109644958f5b0a59 [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
Carmelo Cascone7b821702017-06-19 11:26:08 +090024import static com.google.common.base.Preconditions.checkArgument;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040025import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Identifier of a table in a protocol-independent pipeline.
29 */
30@Beta
31public final class PiTableId extends Identifier<String> {
32
33 private final String scope;
34 private final String name;
35
Carmelo Cascone7b821702017-06-19 11:26:08 +090036 private PiTableId(String scope, String name) {
37 super((scope != null ? scope + "." : "") + name);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040038 this.scope = scope;
39 this.name = name;
40 }
41
42 /**
Carmelo Cascone7b821702017-06-19 11:26:08 +090043 * Returns a table identifier for the given table scope and name.
44 *
45 * @param scope table scope
46 * @param name table name
47 * @return table identifier
48 */
49 public static PiTableId of(String scope, String name) {
50 checkNotNull(name);
51 checkNotNull(scope);
52 checkArgument(!name.isEmpty(), "Name can't be empty");
53 checkArgument(!scope.isEmpty(), "Scope can't be empty");
54 return new PiTableId(scope, name);
55 }
56
57 /**
58 * Returns a table identifier for the given table name.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040059 *
60 * @param name table name
Carmelo Cascone7b821702017-06-19 11:26:08 +090061 * @return table identifier
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040062 */
Carmelo Cascone7b821702017-06-19 11:26:08 +090063 public static PiTableId of(String name) {
64 checkNotNull(name);
65 checkArgument(!name.isEmpty(), "Name can't be empty");
66 return new PiTableId(null, name);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040067 }
68
69
70 /**
71 * Returns the name of this table.
72 *
73 * @return table name
74 */
75 public String name() {
76 return name;
77 }
78
79 /**
80 * Returns the scope of this table, if present.
81 *
82 * @return optional scope
83 */
84 public Optional<String> scope() {
85 return Optional.ofNullable(scope);
86 }
87
88
89}