blob: 3967030f3f33fb13340d9f415f6ba3fd9d97fbf5 [file] [log] [blame]
tomd1900f32014-09-03 14:08:16 -07001package org.onlab.onos.net.device;
2
Yuta HIGUCHI55710e72014-10-02 14:58:32 -07003import org.onlab.onos.net.AbstractDescription;
tomca20e0c2014-09-03 23:22:24 -07004import org.onlab.onos.net.PortNumber;
Yuta HIGUCHI55710e72014-10-02 14:58:32 -07005import org.onlab.onos.net.SparseAnnotations;
tomca20e0c2014-09-03 23:22:24 -07006
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -07007import com.google.common.base.MoreObjects;
8
tomd1900f32014-09-03 14:08:16 -07009/**
10 * Default implementation of immutable port description.
11 */
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070012public class DefaultPortDescription extends AbstractDescription
13 implements PortDescription {
tomca20e0c2014-09-03 23:22:24 -070014
15 private final PortNumber number;
tomd40fc7a2014-09-04 16:41:10 -070016 private final boolean isEnabled;
tomca20e0c2014-09-03 23:22:24 -070017
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070018 /**
19 * Creates a port description using the supplied information.
20 *
21 * @param number port number
22 * @param isEnabled port enabled state
23 * @param annotations optional key/value annotations map
24 */
25 public DefaultPortDescription(PortNumber number, boolean isEnabled,
26 SparseAnnotations... annotations) {
27 super(annotations);
tomca20e0c2014-09-03 23:22:24 -070028 this.number = number;
tomd40fc7a2014-09-04 16:41:10 -070029 this.isEnabled = isEnabled;
tomca20e0c2014-09-03 23:22:24 -070030 }
31
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070032 /**
33 * Creates a port description using the supplied information.
34 *
35 * @param base PortDescription to get basic information from
36 * @param annotations optional key/value annotations map
37 */
38 public DefaultPortDescription(PortDescription base,
39 SparseAnnotations annotations) {
40 this(base.portNumber(), base.isEnabled(), annotations);
41 }
42
tomca20e0c2014-09-03 23:22:24 -070043 @Override
44 public PortNumber portNumber() {
45 return number;
46 }
47
48 @Override
tomd40fc7a2014-09-04 16:41:10 -070049 public boolean isEnabled() {
50 return isEnabled;
tomca20e0c2014-09-03 23:22:24 -070051 }
52
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -070053 @Override
54 public String toString() {
55 return MoreObjects.toStringHelper(getClass())
56 .add("number", number)
57 .add("isEnabled", isEnabled)
58 .add("annotations", annotations())
59 .toString();
60 }
61
Yuta HIGUCHIf1f1d322014-10-07 21:09:56 -070062 // default constructor for serialization
63 private DefaultPortDescription() {
64 this.number = null;
65 this.isEnabled = false;
66 }
tomd1900f32014-09-03 14:08:16 -070067}