blob: 5532e540b2b05181ec8e54de1f59d34a29a1271e [file] [log] [blame]
Jonathan Harte533a422015-10-20 17:31:24 -07001/*
Brian O'Connord4fbd352016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jonathan Harte533a422015-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
alshabib000b6fc2016-02-01 17:25:00 -080017package org.onosproject.olt;
Jonathan Harte533a422015-10-20 17:31:24 -070018
Jonathan Hart52998382015-11-10 16:09:22 -080019import com.fasterxml.jackson.databind.JsonNode;
Jonathan Harte533a422015-10-20 17:31:24 -070020import org.onlab.packet.VlanId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.PortNumber;
23import org.onosproject.net.config.Config;
24
Jonathan Hart52998382015-11-10 16:09:22 -080025import java.util.Optional;
26
Jonathan Harte533a422015-10-20 17:31:24 -070027/**
28 * Config object for access device data.
29 */
30public class AccessDeviceConfig extends Config<DeviceId> {
31
32 private static final String UPLINK = "uplink";
33 private static final String VLAN = "vlan";
Jonathan Hart52998382015-11-10 16:09:22 -080034 private static final String DEFAULT_VLAN = "defaultVlan";
Jonathan Harte533a422015-10-20 17:31:24 -070035
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 Hart52998382015-11-10 16:09:22 -080044 JsonNode defaultVlanNode = node.path(DEFAULT_VLAN);
Jonathan Harte533a422015-10-20 17:31:24 -070045
Jonathan Hart52998382015-11-10 16:09:22 -080046 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 Harte533a422015-10-20 17:31:24 -070054 }
55}