blob: 200b3757c50bf5931ba15d909882c50688ddfecd [file] [log] [blame]
Simon Huntf59d36b2016-10-04 19:05:53 -07001/*
2 * Copyright 2016-present 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.net.config.basics;
18
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.config.Config;
21import org.onosproject.net.region.Region;
22import org.onosproject.net.region.RegionId;
23
24import java.util.List;
25
26/**
27 * Basic configuration for network regions.
28 */
29public final class BasicRegionConfig extends Config<RegionId> {
30
31 private static final String TYPE = "type";
32 private static final String DEVICES = "devices";
33
34 @Override
35 public boolean isValid() {
36 return hasOnlyFields(TYPE, DEVICES);
37 }
38
39 /**
40 * Returns the region type.
41 *
42 * @return the region type
43 */
44 public Region.Type getType() {
45 String t = get(TYPE, null);
46 return t == null ? null : regionTypeFor(t);
47 }
48
49 private Region.Type regionTypeFor(String t) {
50 try {
51 return Region.Type.valueOf(t.toUpperCase());
52 } catch (IllegalArgumentException ignored) {
53 }
54 return null;
55 }
56
57 /**
58 * Returns the identities of the devices in this region.
59 *
60 * @return list of device identifiers
61 */
62 public List<DeviceId> getDevices() {
63 return getList(DEVICES, DeviceId::deviceId);
64 }
65
66 // TODO: implement setters
67}