blob: f3b38c91a48efc7b51182477aa53a6e22bbb19d6 [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
25/**
26 * Basic implementation of description of a legacy device interface.
27 */
28public class DefaultDeviceInterfaceDescription implements
29 DeviceInterfaceDescription {
30 private String name;
31 private Mode mode;
32 private List<VlanId> vlans;
33 private boolean isRateLimited;
34 private short rateLimit;
35
36 /**
37 * Device interface description object constructor.
38 *
39 * @param name the name of the interface
40 * @param mode the operation mode of the interface
41 * @param vlans the vlan-id of the interface (none, one or multiple can be
42 * specified based on if mode is normal, access or trunk).
43 * @param isRateLimited bandwidth limit application indication
44 * @param rateLimit percentage of bandwidth limit
45 */
46 public DefaultDeviceInterfaceDescription(String name,
47 Mode mode,
48 List<VlanId> vlans,
49 boolean isRateLimited,
50 short rateLimit) {
51 this.name = name;
52 this.mode = (mode != null ? mode : Mode.NORMAL);
53 this.vlans = (vlans != null ? vlans : Lists.newArrayList());
54 this.isRateLimited = isRateLimited;
55 this.rateLimit = rateLimit;
56 }
57
58 /**
59 * Returns the name of the interface.
60 *
61 * @return name of the interface
62 */
63 @Override
64 public String name() {
65 return this.name;
66 }
67
68 /**
69 * Returns the operation mode of the interface.
70 *
71 * @return operation mode of the interface
72 */
73 @Override
74 public Mode mode() {
75 return this.mode;
76 }
77
78 /**
79 * Returns the VLAN-IDs configured for the interface. No VLAN-ID should be
80 * returned for NORMAL mode, 1 VLAN-ID for access mode and 1 or more
81 * VLAN-IDs for trunking mode.
82 *
83 * @return VLAN-ID(s) configured for the interface.
84 */
85 @Override
86 public List<VlanId> vlans() {
87 return vlans;
88 }
89
90 /**
91 * Indicates whether a rate limit has been set on the interface.
92 *
93 * @return indication whether interface is rate limited or not
94 */
95 @Override
96 public boolean isRateLimited() {
97 return isRateLimited;
98 }
99
100 /**
101 * Returns the rate limit set on the interface bandwidth.
102 *
103 * @return the rate limit set on the interface bandwidth
104 */
105 @Override
106 public short rateLimit() {
107 return rateLimit;
108 }
109
110 @Override
111 public boolean equals(Object other) {
112 if (!(other instanceof DefaultDeviceInterfaceDescription)) {
113 return false;
114 }
115
116 DefaultDeviceInterfaceDescription otherInterface =
117 (DefaultDeviceInterfaceDescription) other;
118
119 return Objects.equals(name, otherInterface.name) &&
120 Objects.equals(mode, otherInterface.mode) &&
121 Objects.equals(vlans, otherInterface.vlans) &&
122 Objects.equals(isRateLimited, otherInterface.isRateLimited) &&
123 Objects.equals(rateLimit, otherInterface.rateLimit);
124 }
125
126 @Override
127 public int hashCode() {
128 return Objects.hash(name, mode, vlans, isRateLimited, rateLimit);
129 }
130}