blob: 3843c025322bfe3168fe74c30768864c82f011d5 [file] [log] [blame]
Pingping Lin9a445c82016-04-07 11:40:29 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Pingping Lin9a445c82016-04-07 11:40:29 -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
17package org.onosproject.routing.config;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.google.common.collect.Sets;
21
22import java.util.Set;
23
24import org.onlab.packet.IpAddress;
25import org.onlab.packet.IpPrefix;
26import org.onlab.packet.MacAddress;
27import org.onosproject.core.ApplicationId;
28import org.onosproject.net.config.Config;
29import org.onosproject.routing.config.LocalIpPrefixEntry.IpPrefixType;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33/**
34 * Configuration object for prefix config.
35 */
36public class ReactiveRoutingConfig extends Config<ApplicationId> {
37
38 private final Logger log = LoggerFactory.getLogger(getClass());
39
40 public static final String IP4LOCALPREFIXES = "ip4LocalPrefixes";
41 public static final String IP6LOCALPREFIXES = "ip6LocalPrefixes";
42 public static final String IPPREFIX = "ipPrefix";
43 public static final String TYPE = "type";
44 public static final String GATEWAYIP = "gatewayIp";
45 public static final String VIRTUALGATEWAYMACADDRESS =
46 "virtualGatewayMacAddress";
47
48 /**
49 * Gets the set of configured local IPv4 prefixes.
50 *
51 * @return IPv4 prefixes
52 */
53 public Set<LocalIpPrefixEntry> localIp4PrefixEntries() {
54 Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
55
56 JsonNode prefixesNode = object.get(IP4LOCALPREFIXES);
57 if (prefixesNode == null) {
58 log.warn("ip4LocalPrefixes is null!");
59 return prefixes;
60 }
61
62 prefixesNode.forEach(jsonNode -> {
63
64 prefixes.add(new LocalIpPrefixEntry(
65 IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
66 IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
67 IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
68 });
69
70 return prefixes;
71 }
72
73 /**
74 * Gets the set of configured local IPv6 prefixes.
75 *
76 * @return IPv6 prefixes
77 */
78 public Set<LocalIpPrefixEntry> localIp6PrefixEntries() {
79 Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
80
81 JsonNode prefixesNode = object.get(IP6LOCALPREFIXES);
82
83 if (prefixesNode == null) {
84 log.warn("ip6LocalPrefixes is null!");
85 return prefixes;
86 }
87
88 prefixesNode.forEach(jsonNode -> {
89
90 prefixes.add(new LocalIpPrefixEntry(
91 IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
92 IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
93 IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
94 });
95
96 return prefixes;
97 }
98
99 /**
100 * Gets of the virtual gateway MAC address.
101 *
102 */
103 public MacAddress virtualGatewayMacAddress() {
104 return MacAddress.valueOf(
105 object.get(VIRTUALGATEWAYMACADDRESS).asText());
106 }
107}