Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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.model; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onlab.util.Identifier; |
| 21 | import org.onosproject.net.flow.TableId; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkArgument; |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Identifier of a table in a protocol-independent pipeline, unique within the scope of a pipeline model. |
| 28 | */ |
| 29 | @Beta |
| 30 | public final class PiTableId extends Identifier<String> implements TableId { |
| 31 | |
| 32 | private PiTableId(String name) { |
| 33 | super(name); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns an identifier for the given table name. |
| 38 | * |
| 39 | * @param name table name |
| 40 | * @return table ID |
| 41 | */ |
| 42 | public static PiTableId of(String name) { |
| 43 | checkNotNull(name); |
| 44 | checkArgument(!name.isEmpty(), "Name can't be empty"); |
| 45 | return new PiTableId(name); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public Type type() { |
| 50 | return Type.PIPELINE_INDEPENDENT; |
| 51 | } |
Charles Chan | dc579c5 | 2018-08-28 13:49:29 -0700 | [diff] [blame] | 52 | |
| 53 | @Override |
| 54 | public int compareTo(TableId other) { |
| 55 | if (this.type() != other.type()) { |
| 56 | return this.type().compareTo(other.type()); |
| 57 | } else { |
| 58 | PiTableId piTableId = (PiTableId) other; |
| 59 | checkNotNull(this.identifier, "PiTableId identifier should not be null"); |
| 60 | checkNotNull(piTableId.identifier, "PiTableId identifier should not be null"); |
| 61 | return this.identifier.compareTo(piTableId.identifier); |
| 62 | } |
| 63 | } |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 64 | } |