blob: 7e5f8e65007a955c0f6f72af5333c3d5e023da3d [file] [log] [blame]
Andreas Papazois1ed54cf2016-05-04 16:22:40 +03001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Andreas Papazois1ed54cf2016-05-04 16:22:40 +03003 *
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
17package org.onosproject.net.device;
18
19import com.google.common.collect.Lists;
20import org.onlab.packet.VlanId;
21
22import java.util.List;
23import java.util.Objects;
24
Georgios Katsikas9e75f8b2020-03-22 11:47:13 +010025import static com.google.common.base.MoreObjects.toStringHelper;
26
Andreas Papazois1ed54cf2016-05-04 16:22:40 +030027/**
28 * Basic implementation of description of a legacy device interface.
29 */
30public class DefaultDeviceInterfaceDescription implements
31 DeviceInterfaceDescription {
32 private String name;
33 private Mode mode;
34 private List<VlanId> vlans;
35 private boolean isRateLimited;
36 private short rateLimit;
37
38 /**
39 * Device interface description object constructor.
40 *
41 * @param name the name of the interface
42 * @param mode the operation mode of the interface
43 * @param vlans the vlan-id of the interface (none, one or multiple can be
44 * specified based on if mode is normal, access or trunk).
45 * @param isRateLimited bandwidth limit application indication
46 * @param rateLimit percentage of bandwidth limit
47 */
48 public DefaultDeviceInterfaceDescription(String name,
49 Mode mode,
50 List<VlanId> vlans,
51 boolean isRateLimited,
52 short rateLimit) {
53 this.name = name;
54 this.mode = (mode != null ? mode : Mode.NORMAL);
55 this.vlans = (vlans != null ? vlans : Lists.newArrayList());
56 this.isRateLimited = isRateLimited;
57 this.rateLimit = rateLimit;
58 }
59
60 /**
61 * Returns the name of the interface.
62 *
63 * @return name of the interface
64 */
65 @Override
66 public String name() {
67 return this.name;
68 }
69
70 /**
71 * Returns the operation mode of the interface.
72 *
73 * @return operation mode of the interface
74 */
75 @Override
76 public Mode mode() {
77 return this.mode;
78 }
79
80 /**
81 * Returns the VLAN-IDs configured for the interface. No VLAN-ID should be
82 * returned for NORMAL mode, 1 VLAN-ID for access mode and 1 or more
83 * VLAN-IDs for trunking mode.
84 *
85 * @return VLAN-ID(s) configured for the interface.
86 */
87 @Override
88 public List<VlanId> vlans() {
89 return vlans;
90 }
91
92 /**
93 * Indicates whether a rate limit has been set on the interface.
94 *
95 * @return indication whether interface is rate limited or not
96 */
97 @Override
98 public boolean isRateLimited() {
99 return isRateLimited;
100 }
101
102 /**
103 * Returns the rate limit set on the interface bandwidth.
104 *
105 * @return the rate limit set on the interface bandwidth
106 */
107 @Override
108 public short rateLimit() {
109 return rateLimit;
110 }
111
112 @Override
113 public boolean equals(Object other) {
114 if (!(other instanceof DefaultDeviceInterfaceDescription)) {
115 return false;
116 }
117
118 DefaultDeviceInterfaceDescription otherInterface =
119 (DefaultDeviceInterfaceDescription) other;
120
121 return Objects.equals(name, otherInterface.name) &&
122 Objects.equals(mode, otherInterface.mode) &&
123 Objects.equals(vlans, otherInterface.vlans) &&
124 Objects.equals(isRateLimited, otherInterface.isRateLimited) &&
125 Objects.equals(rateLimit, otherInterface.rateLimit);
126 }
127
128 @Override
129 public int hashCode() {
130 return Objects.hash(name, mode, vlans, isRateLimited, rateLimit);
131 }
Georgios Katsikas9e75f8b2020-03-22 11:47:13 +0100132
133 @Override
134 public String toString() {
135 return toStringHelper(this)
136 .omitNullValues()
137 .add("Device name", name())
138 .add("Device mode", mode())
139 .add("VLAN IDs", vlans())
140 .add("Rate limited", isRateLimited())
141 .add("Rate limit", rateLimit())
142 .toString();
143 }
144
Andreas Papazois1ed54cf2016-05-04 16:22:40 +0300145}