blob: 47e3280ae32a23e27a73d3996683e78d35cc390f [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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 */
tomd1900f32014-09-03 14:08:16 -070016package org.onlab.onos.net.device;
17
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070018import org.onlab.onos.net.AbstractDescription;
tomca20e0c2014-09-03 23:22:24 -070019import org.onlab.onos.net.PortNumber;
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070020import org.onlab.onos.net.SparseAnnotations;
tomca20e0c2014-09-03 23:22:24 -070021
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -070022import com.google.common.base.MoreObjects;
23
tomd1900f32014-09-03 14:08:16 -070024/**
25 * Default implementation of immutable port description.
26 */
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070027public class DefaultPortDescription extends AbstractDescription
28 implements PortDescription {
tomca20e0c2014-09-03 23:22:24 -070029
30 private final PortNumber number;
tomd40fc7a2014-09-04 16:41:10 -070031 private final boolean isEnabled;
tomca20e0c2014-09-03 23:22:24 -070032
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070033 /**
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);
tomca20e0c2014-09-03 23:22:24 -070043 this.number = number;
tomd40fc7a2014-09-04 16:41:10 -070044 this.isEnabled = isEnabled;
tomca20e0c2014-09-03 23:22:24 -070045 }
46
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070047 /**
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
tomca20e0c2014-09-03 23:22:24 -070058 @Override
59 public PortNumber portNumber() {
60 return number;
61 }
62
63 @Override
tomd40fc7a2014-09-04 16:41:10 -070064 public boolean isEnabled() {
65 return isEnabled;
tomca20e0c2014-09-03 23:22:24 -070066 }
67
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -070068 @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 HIGUCHIf1f1d322014-10-07 21:09:56 -070077 // default constructor for serialization
78 private DefaultPortDescription() {
79 this.number = null;
80 this.isEnabled = false;
81 }
tomd1900f32014-09-03 14:08:16 -070082}