Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 16 | |
alshabib | 03adb49 | 2016-02-01 17:25:00 -0800 | [diff] [blame] | 17 | package org.onosproject.olt; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 18 | |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.JsonNode; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 20 | import org.onlab.packet.VlanId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.PortNumber; |
| 23 | import org.onosproject.net.config.Config; |
| 24 | |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 25 | import java.util.Optional; |
| 26 | |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Config object for access device data. |
| 29 | */ |
| 30 | public class AccessDeviceConfig extends Config<DeviceId> { |
| 31 | |
| 32 | private static final String UPLINK = "uplink"; |
| 33 | private static final String VLAN = "vlan"; |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 34 | private static final String DEFAULT_VLAN = "defaultVlan"; |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Gets the access device configuration for this device. |
| 38 | * |
| 39 | * @return access device configuration |
| 40 | */ |
| 41 | public AccessDeviceData getOlt() { |
| 42 | PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); |
| 43 | VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 44 | JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 45 | |
Jonathan Hart | 4832784 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 46 | Optional<VlanId> defaultVlan; |
| 47 | if (defaultVlanNode.isMissingNode()) { |
| 48 | defaultVlan = Optional.empty(); |
| 49 | } else { |
| 50 | defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); |
| 51 | } |
| 52 | |
| 53 | return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); |
Jonathan Hart | 3e59464 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 54 | } |
| 55 | } |