Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.routing.config; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.google.common.collect.Sets; |
| 21 | |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import org.onlab.packet.IpAddress; |
| 25 | import org.onlab.packet.IpPrefix; |
| 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.net.config.Config; |
| 29 | import org.onosproject.routing.config.LocalIpPrefixEntry.IpPrefixType; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | /** |
| 34 | * Configuration object for prefix config. |
| 35 | */ |
| 36 | public 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 | * |
Ray Milkey | bee3509 | 2016-04-12 10:01:26 -0700 | [diff] [blame] | 102 | * @return virtual gateway MAC address |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 103 | */ |
| 104 | public MacAddress virtualGatewayMacAddress() { |
| 105 | return MacAddress.valueOf( |
| 106 | object.get(VIRTUALGATEWAYMACADDRESS).asText()); |
| 107 | } |
| 108 | } |