blob: 07b73c845afa088e76949f00b3df613f5f5cdc0f [file] [log] [blame]
Jonathan Hart3e594642015-10-20 17:31:24 -07001/*
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
17package org.onosproject.olt;
18
Jonathan Hart48327842015-11-10 16:09:22 -080019import com.fasterxml.jackson.databind.JsonNode;
Jonathan Hart3e594642015-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 Hart48327842015-11-10 16:09:22 -080025import java.util.Optional;
26
Jonathan Hart3e594642015-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 Hart48327842015-11-10 16:09:22 -080034 private static final String DEFAULT_VLAN = "defaultVlan";
Jonathan Hart3e594642015-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 Hart48327842015-11-10 16:09:22 -080044 JsonNode defaultVlanNode = node.path(DEFAULT_VLAN);
Jonathan Hart3e594642015-10-20 17:31:24 -070045
Jonathan Hart48327842015-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 Hart3e594642015-10-20 17:31:24 -070054 }
55}