blob: 1e5e8cf9b2520ced7ce8d8c190850cae228aefb6 [file] [log] [blame]
Jonathan Hart3e594642015-10-20 17:31:24 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Hart3e594642015-10-20 17:31:24 -07003 *
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
alshabib4809e542016-04-28 15:52:22 -070017package org.onosproject.cordconfig.access;
Jonathan Hart3e594642015-10-20 17:31:24 -070018
alshabib4809e542016-04-28 15:52:22 -070019import org.onosproject.net.DeviceId;
Jonathan Hart48327842015-11-10 16:09:22 -080020import com.fasterxml.jackson.databind.JsonNode;
Jonathan Hart3e594642015-10-20 17:31:24 -070021import org.onlab.packet.VlanId;
alshabib4809e542016-04-28 15:52:22 -070022
Jonathan Hart3e594642015-10-20 17:31:24 -070023import org.onosproject.net.PortNumber;
24import org.onosproject.net.config.Config;
25
Jonathan Hart48327842015-11-10 16:09:22 -080026import java.util.Optional;
27
Jonathan Hart3e594642015-10-20 17:31:24 -070028/**
29 * Config object for access device data.
30 */
31public class AccessDeviceConfig extends Config<DeviceId> {
32
33 private static final String UPLINK = "uplink";
34 private static final String VLAN = "vlan";
Jonathan Hart48327842015-11-10 16:09:22 -080035 private static final String DEFAULT_VLAN = "defaultVlan";
Jonathan Hart3e594642015-10-20 17:31:24 -070036
37 /**
38 * Gets the access device configuration for this device.
39 *
40 * @return access device configuration
41 */
42 public AccessDeviceData getOlt() {
43 PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText());
44 VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText()));
Jonathan Hart48327842015-11-10 16:09:22 -080045 JsonNode defaultVlanNode = node.path(DEFAULT_VLAN);
Jonathan Hart3e594642015-10-20 17:31:24 -070046
Jonathan Hart48327842015-11-10 16:09:22 -080047 Optional<VlanId> defaultVlan;
48 if (defaultVlanNode.isMissingNode()) {
49 defaultVlan = Optional.empty();
50 } else {
51 defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText())));
52 }
53
54 return new AccessDeviceData(subject(), uplink, vlan, defaultVlan);
Jonathan Hart3e594642015-10-20 17:31:24 -070055 }
56}