blob: c2f076cbd034eaf91297ce98d1ff7f10f7d7b0f1 [file] [log] [blame]
Jonathan Hart2b5ceec2017-12-04 13:57:19 -08001/*
2 * Copyright 2016-present Open Networking Foundation
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 */
16
17package org.opencord.cordconfig.access;
18
19import com.google.common.base.MoreObjects;
20import org.onlab.packet.VlanId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.PortNumber;
23
24import java.util.Optional;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Information about an access device.
30 */
31public class AccessDeviceData {
32 private static final String DEVICE_ID_MISSING = "Device ID cannot be null";
33 private static final String UPLINK_MISSING = "Uplink cannot be null";
34 private static final String VLAN_MISSING = "VLAN ID cannot be null";
35
36 private final DeviceId deviceId;
37 private final PortNumber uplink;
38 private final VlanId vlan;
39 private final Optional<VlanId> defaultVlan;
40
41 /**
42 * Class constructor.
43 *
44 * @param deviceId access device ID
45 * @param uplink uplink port number
46 * @param vlan device VLAN ID
47 * @param defaultVlan default device VLAN ID
48 */
49 public AccessDeviceData(DeviceId deviceId, PortNumber uplink, VlanId vlan,
50 Optional<VlanId> defaultVlan) {
51 this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING);
52 this.uplink = checkNotNull(uplink, UPLINK_MISSING);
53 this.vlan = checkNotNull(vlan, VLAN_MISSING);
54 this.defaultVlan = checkNotNull(defaultVlan);
55 }
56
57 /**
58 * Retrieves the access device ID.
59 *
60 * @return device ID
61 */
62 public DeviceId deviceId() {
63 return deviceId;
64 }
65
66 /**
67 * Retrieves the uplink port number.
68 *
69 * @return port number
70 */
71 public PortNumber uplink() {
72 return uplink;
73 }
74
75 /**
76 * Retrieves the VLAN ID assigned to the device.
77 *
78 * @return VLAN ID
79 */
80 public VlanId vlan() {
81 return vlan;
82 }
83
84 /**
85 * Retrieves the default VLAN ID that will be used for this device.
86 *
87 * @return default VLAN ID
88 */
89 public Optional<VlanId> defaultVlan() {
90 return defaultVlan;
91 }
92
93 @Override
94 public String toString() {
95 return MoreObjects.toStringHelper(getClass())
96 .add("deviceId", deviceId)
97 .add("uplink", uplink)
98 .add("vlan", vlan)
99 .add("defaultVlan", defaultVlan)
100 .toString();
101 }
102}