blob: 34b7f1687e8a2c4de0d4eb2c3f1b4b08a71787b5 [file] [log] [blame]
Jayakumar Thazhath28484572017-11-02 00:39:09 -04001/*
2 * Copyright 2017-present Open Networking Foundation
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.ra.config;
18
19import com.fasterxml.jackson.databind.node.ArrayNode;
20import com.google.common.collect.Lists;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.config.Config;
23import org.onosproject.net.host.InterfaceIpAddress;
24
25import java.util.List;
26
27/**
28 * Device configuration for Router Advertisement.
29 */
30public class RouterAdvertisementDeviceConfig extends Config<DeviceId> {
31
32 private static final String PREFIXES = "prefixes";
33
34 @Override
35 public boolean isValid() {
36 return hasOnlyFields(PREFIXES) && prefixes() != null;
37 }
38
39
40 /**
41 * Gets global router advertisement prefixes for device.
42 *
43 * @return global prefixes. Or null if not configured.
44 */
45 public List<InterfaceIpAddress> prefixes() {
46 if (!object.has(PREFIXES)) {
47 return null;
48 }
49
50 List<InterfaceIpAddress> ips = Lists.newArrayList();
51 ArrayNode prefixes = (ArrayNode) object.path(PREFIXES);
52 prefixes.forEach(i -> ips.add(InterfaceIpAddress.valueOf(i.asText())));
53 return ips;
54 }
55
56}
57
58