Jonathan Hart | 2b5ceec | 2017-12-04 13:57:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.opencord.cordconfig.access; |
| 18 | |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import com.fasterxml.jackson.databind.JsonNode; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.config.Config; |
| 25 | |
| 26 | import java.util.Optional; |
| 27 | |
| 28 | /** |
| 29 | * Config object for access device data. |
| 30 | */ |
| 31 | public class AccessDeviceConfig extends Config<DeviceId> { |
| 32 | |
| 33 | private static final String UPLINK = "uplink"; |
| 34 | private static final String VLAN = "vlan"; |
| 35 | private static final String DEFAULT_VLAN = "defaultVlan"; |
| 36 | |
| 37 | /** |
| 38 | * Gets the access device configuration for this device. |
| 39 | * |
| 40 | * @return access device configuration |
| 41 | * @deprecated in Goldeneye release. Use {@link #getAccessDevice()} instead. |
| 42 | */ |
| 43 | @Deprecated |
| 44 | public AccessDeviceData getOlt() { |
| 45 | return getAccessDevice(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Gets the access device configuration for this device. |
| 50 | * |
| 51 | * @return access device configuration |
| 52 | */ |
| 53 | public AccessDeviceData getAccessDevice() { |
| 54 | PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); |
| 55 | VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); |
| 56 | JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); |
| 57 | |
| 58 | Optional<VlanId> defaultVlan; |
| 59 | if (defaultVlanNode.isMissingNode()) { |
| 60 | defaultVlan = Optional.empty(); |
| 61 | } else { |
| 62 | defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); |
| 63 | } |
| 64 | |
| 65 | return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); |
| 66 | } |
| 67 | } |