Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
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 | |
Jonathan Hart | bb782be | 2017-02-09 17:45:49 -0800 | [diff] [blame] | 17 | package org.onosproject.reactive.routing; |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 18 | |
| 19 | import com.fasterxml.jackson.databind.JsonNode; |
| 20 | import com.google.common.collect.Sets; |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.IpPrefix; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.net.config.Config; |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
Jonathan Hart | bb782be | 2017-02-09 17:45:49 -0800 | [diff] [blame] | 29 | import java.util.Set; |
| 30 | |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Configuration object for prefix config. |
| 33 | */ |
| 34 | public 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 Hart | bb782be | 2017-02-09 17:45:49 -0800 | [diff] [blame] | 64 | LocalIpPrefixEntry.IpPrefixType.valueOf(jsonNode.get(TYPE).asText()), |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 65 | 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 Hart | bb782be | 2017-02-09 17:45:49 -0800 | [diff] [blame] | 90 | LocalIpPrefixEntry.IpPrefixType.valueOf(jsonNode.get(TYPE).asText()), |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 91 | IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText()))); |
| 92 | }); |
| 93 | |
| 94 | return prefixes; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Gets of the virtual gateway MAC address. |
| 99 | * |
Ray Milkey | bee3509 | 2016-04-12 10:01:26 -0700 | [diff] [blame] | 100 | * @return virtual gateway MAC address |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 101 | */ |
| 102 | public MacAddress virtualGatewayMacAddress() { |
| 103 | return MacAddress.valueOf( |
| 104 | object.get(VIRTUALGATEWAYMACADDRESS).asText()); |
| 105 | } |
| 106 | } |