Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onlab.util.Identifier; |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 21 | import org.onosproject.net.flow.TableId; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 22 | |
| 23 | import java.util.Optional; |
| 24 | |
Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkArgument; |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * Identifier of a table in a protocol-independent pipeline. |
| 30 | */ |
| 31 | @Beta |
Carmelo Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 32 | public final class PiTableId extends Identifier<String> implements TableId { |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 33 | |
| 34 | private final String scope; |
| 35 | private final String name; |
| 36 | |
Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 37 | private PiTableId(String scope, String name) { |
| 38 | super((scope != null ? scope + "." : "") + name); |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 39 | this.scope = scope; |
| 40 | this.name = name; |
| 41 | } |
| 42 | |
| 43 | /** |
Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 44 | * 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 Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 60 | * |
| 61 | * @param name table name |
Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 62 | * @return table identifier |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 63 | */ |
Carmelo Cascone | 7b82170 | 2017-06-19 11:26:08 +0900 | [diff] [blame] | 64 | 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 Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 68 | } |
| 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 Cascone | 4160574 | 2017-06-19 15:46:44 +0900 | [diff] [blame] | 89 | @Override |
| 90 | public Type type() { |
| 91 | return Type.PIPELINE_INDEPENDENT; |
| 92 | } |
Carmelo Cascone | 1022a4e | 2017-05-25 00:16:18 -0400 | [diff] [blame] | 93 | } |