blob: 7b988b15ca1248ecaa34a1e9d4661db6880a4459 [file] [log] [blame]
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Cascone1022a4e2017-05-25 00:16:18 -04003 *
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;
Carmelo Cascone41605742017-06-19 15:46:44 +090021import org.onosproject.net.flow.TableId;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040022
23import java.util.Optional;
24
Carmelo Cascone7b821702017-06-19 11:26:08 +090025import static com.google.common.base.Preconditions.checkArgument;
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040026import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Identifier of a table in a protocol-independent pipeline.
30 */
31@Beta
Carmelo Cascone41605742017-06-19 15:46:44 +090032public final class PiTableId extends Identifier<String> implements TableId {
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040033
34 private final String scope;
35 private final String name;
36
Carmelo Cascone7b821702017-06-19 11:26:08 +090037 private PiTableId(String scope, String name) {
38 super((scope != null ? scope + "." : "") + name);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040039 this.scope = scope;
40 this.name = name;
41 }
42
43 /**
Carmelo Cascone7b821702017-06-19 11:26:08 +090044 * Returns a table identifier for the given table scope and name.
45 *
46 * @param scope table scope
47 * @param name table name
48 * @return table identifier
49 */
50 public static PiTableId of(String scope, String name) {
51 checkNotNull(name);
52 checkNotNull(scope);
53 checkArgument(!name.isEmpty(), "Name can't be empty");
54 checkArgument(!scope.isEmpty(), "Scope can't be empty");
55 return new PiTableId(scope, name);
56 }
57
58 /**
59 * Returns a table identifier for the given table name.
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040060 *
61 * @param name table name
Carmelo Cascone7b821702017-06-19 11:26:08 +090062 * @return table identifier
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040063 */
Carmelo Cascone7b821702017-06-19 11:26:08 +090064 public static PiTableId of(String name) {
65 checkNotNull(name);
66 checkArgument(!name.isEmpty(), "Name can't be empty");
67 return new PiTableId(null, name);
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040068 }
69
70
71 /**
72 * Returns the name of this table.
73 *
74 * @return table name
75 */
76 public String name() {
77 return name;
78 }
79
80 /**
81 * Returns the scope of this table, if present.
82 *
83 * @return optional scope
84 */
85 public Optional<String> scope() {
86 return Optional.ofNullable(scope);
87 }
88
Carmelo Cascone41605742017-06-19 15:46:44 +090089 @Override
90 public Type type() {
91 return Type.PIPELINE_INDEPENDENT;
92 }
Carmelo Cascone1022a4e2017-05-25 00:16:18 -040093}