Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.device; |
| 17 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 18 | import org.onlab.onos.net.AbstractDescription; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 19 | import org.onlab.onos.net.PortNumber; |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 20 | import org.onlab.onos.net.SparseAnnotations; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 21 | |
Yuta HIGUCHI | 9ee60f6 | 2014-10-09 10:00:01 -0700 | [diff] [blame] | 22 | import com.google.common.base.MoreObjects; |
| 23 | |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Default implementation of immutable port description. |
| 26 | */ |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 27 | public class DefaultPortDescription extends AbstractDescription |
| 28 | implements PortDescription { |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 29 | |
| 30 | private final PortNumber number; |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 31 | private final boolean isEnabled; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 32 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Creates a port description using the supplied information. |
| 35 | * |
| 36 | * @param number port number |
| 37 | * @param isEnabled port enabled state |
| 38 | * @param annotations optional key/value annotations map |
| 39 | */ |
| 40 | public DefaultPortDescription(PortNumber number, boolean isEnabled, |
| 41 | SparseAnnotations... annotations) { |
| 42 | super(annotations); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 43 | this.number = number; |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 44 | this.isEnabled = isEnabled; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Yuta HIGUCHI | 55710e7 | 2014-10-02 14:58:32 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Creates a port description using the supplied information. |
| 49 | * |
| 50 | * @param base PortDescription to get basic information from |
| 51 | * @param annotations optional key/value annotations map |
| 52 | */ |
| 53 | public DefaultPortDescription(PortDescription base, |
| 54 | SparseAnnotations annotations) { |
| 55 | this(base.portNumber(), base.isEnabled(), annotations); |
| 56 | } |
| 57 | |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 58 | @Override |
| 59 | public PortNumber portNumber() { |
| 60 | return number; |
| 61 | } |
| 62 | |
| 63 | @Override |
tom | d40fc7a | 2014-09-04 16:41:10 -0700 | [diff] [blame] | 64 | public boolean isEnabled() { |
| 65 | return isEnabled; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Yuta HIGUCHI | 9ee60f6 | 2014-10-09 10:00:01 -0700 | [diff] [blame] | 68 | @Override |
| 69 | public String toString() { |
| 70 | return MoreObjects.toStringHelper(getClass()) |
| 71 | .add("number", number) |
| 72 | .add("isEnabled", isEnabled) |
| 73 | .add("annotations", annotations()) |
| 74 | .toString(); |
| 75 | } |
| 76 | |
Yuta HIGUCHI | f1f1d32 | 2014-10-07 21:09:56 -0700 | [diff] [blame] | 77 | // default constructor for serialization |
| 78 | private DefaultPortDescription() { |
| 79 | this.number = null; |
| 80 | this.isEnabled = false; |
| 81 | } |
tom | d1900f3 | 2014-09-03 14:08:16 -0700 | [diff] [blame] | 82 | } |