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