blob: 572d201c348aeb235038a1ec5d0e5971e2d73ce6 [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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.device;
tomd1900f32014-09-03 14:08:16 -070017
Thomas Vachuskad16ce182014-10-29 17:25:29 -070018import com.google.common.base.MoreObjects;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.net.AbstractDescription;
20import org.onosproject.net.PortNumber;
21import org.onosproject.net.SparseAnnotations;
tomca20e0c2014-09-03 23:22:24 -070022
Brian O'Connorabafb502014-12-02 22:26:20 -080023import static org.onosproject.net.Port.Type;
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -070024
tomd1900f32014-09-03 14:08:16 -070025/**
26 * Default implementation of immutable port description.
27 */
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070028public class DefaultPortDescription extends AbstractDescription
29 implements PortDescription {
tomca20e0c2014-09-03 23:22:24 -070030
Thomas Vachuskad16ce182014-10-29 17:25:29 -070031 private static final long DEFAULT_SPEED = 1_000;
32
tomca20e0c2014-09-03 23:22:24 -070033 private final PortNumber number;
tomd40fc7a2014-09-04 16:41:10 -070034 private final boolean isEnabled;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070035 private final Type type;
36 private final long portSpeed;
tomca20e0c2014-09-03 23:22:24 -070037
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070038 /**
39 * Creates a port description using the supplied information.
40 *
Thomas Vachuskad16ce182014-10-29 17:25:29 -070041 * @param number port number
42 * @param isEnabled port enabled state
43 * @param annotations optional key/value annotations map
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070044 */
45 public DefaultPortDescription(PortNumber number, boolean isEnabled,
Thomas Vachuskad16ce182014-10-29 17:25:29 -070046 SparseAnnotations... annotations) {
47 this(number, isEnabled, Type.COPPER, DEFAULT_SPEED, annotations);
tomca20e0c2014-09-03 23:22:24 -070048 }
49
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070050 /**
51 * Creates a port description using the supplied information.
52 *
Thomas Vachuskad16ce182014-10-29 17:25:29 -070053 * @param number port number
54 * @param isEnabled port enabled state
55 * @param type port type
56 * @param portSpeed port speed in Mbps
57 * @param annotations optional key/value annotations map
58 */
59 public DefaultPortDescription(PortNumber number, boolean isEnabled,
60 Type type, long portSpeed,
61 SparseAnnotations...annotations) {
62 super(annotations);
63 this.number = number;
64 this.isEnabled = isEnabled;
65 this.type = type;
66 this.portSpeed = portSpeed;
67 }
68
69 // Default constructor for serialization
70 private DefaultPortDescription() {
71 this.number = null;
72 this.isEnabled = false;
73 this.portSpeed = DEFAULT_SPEED;
74 this.type = Type.COPPER;
75 }
76
77 /**
78 * Creates a port description using the supplied information.
79 *
80 * @param base PortDescription to get basic information from
81 * @param annotations optional key/value annotations map
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070082 */
83 public DefaultPortDescription(PortDescription base,
Thomas Vachuskad16ce182014-10-29 17:25:29 -070084 SparseAnnotations annotations) {
85 this(base.portNumber(), base.isEnabled(), base.type(), base.portSpeed(),
86 annotations);
Yuta HIGUCHI55710e72014-10-02 14:58:32 -070087 }
88
tomca20e0c2014-09-03 23:22:24 -070089 @Override
90 public PortNumber portNumber() {
91 return number;
92 }
93
94 @Override
tomd40fc7a2014-09-04 16:41:10 -070095 public boolean isEnabled() {
96 return isEnabled;
tomca20e0c2014-09-03 23:22:24 -070097 }
98
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -070099 @Override
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700100 public Type type() {
101 return type;
102 }
103
104 @Override
105 public long portSpeed() {
106 return portSpeed;
107 }
108
109 @Override
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -0700110 public String toString() {
111 return MoreObjects.toStringHelper(getClass())
112 .add("number", number)
113 .add("isEnabled", isEnabled)
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700114 .add("type", type)
115 .add("portSpeed", portSpeed)
Yuta HIGUCHI9ee60f62014-10-09 10:00:01 -0700116 .add("annotations", annotations())
117 .toString();
118 }
119
tomd1900f32014-09-03 14:08:16 -0700120}