Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -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 | package org.onosproject.virtualbng; |
| 17 | |
| 18 | import com.fasterxml.jackson.annotation.JsonCreator; |
| 19 | import com.fasterxml.jackson.annotation.JsonProperty; |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.IpPrefix; |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 22 | import org.onlab.packet.MacAddress; |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
| 24 | |
| 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| 27 | import java.util.Map; |
| 28 | import java.util.stream.Collectors; |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Contains the configuration data for virtual BNG that has been read from a |
| 32 | * JSON-formatted configuration file. |
| 33 | */ |
| 34 | public final class VbngConfiguration { |
| 35 | |
| 36 | private final List<IpPrefix> localPublicIpPrefixes; |
| 37 | private final IpAddress nextHopIpAddress; |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 38 | private final MacAddress publicFacingMac; |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 39 | private final IpAddress xosIpAddress; |
| 40 | private final int xosRestPort; |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame] | 41 | private final Map<String, ConnectPointConfiguration> hosts; |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Default constructor. |
| 45 | */ |
| 46 | private VbngConfiguration() { |
| 47 | localPublicIpPrefixes = null; |
| 48 | nextHopIpAddress = null; |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 49 | publicFacingMac = null; |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 50 | xosIpAddress = null; |
| 51 | xosRestPort = 0; |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame] | 52 | hosts = null; |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Constructor. |
| 57 | * |
| 58 | * @param nextHopIpAddress the IP address of the next hop |
| 59 | * @param prefixes the public IP prefix list for local SDN network |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 60 | * @param publicFacingMac the MAC address configured for all local |
| 61 | * public IP addresses |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 62 | * @param xosIpAddress the XOS server IP address |
| 63 | * @param xosRestPort the port of the XOS server for REST |
Ray Milkey | f64cf41 | 2015-10-28 16:17:30 -0700 | [diff] [blame] | 64 | * @param hosts map of hosts |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 65 | */ |
| 66 | @JsonCreator |
| 67 | public VbngConfiguration(@JsonProperty("localPublicIpPrefixes") |
| 68 | List<IpPrefix> prefixes, |
| 69 | @JsonProperty("nextHopIpAddress") |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 70 | IpAddress nextHopIpAddress, |
| 71 | @JsonProperty("publicFacingMac") |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 72 | MacAddress publicFacingMac, |
| 73 | @JsonProperty("xosIpAddress") |
| 74 | IpAddress xosIpAddress, |
| 75 | @JsonProperty("xosRestPort") |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame] | 76 | int xosRestPort, |
| 77 | @JsonProperty("hosts") |
| 78 | Map<String, ConnectPointConfiguration> hosts) { |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 79 | localPublicIpPrefixes = prefixes; |
| 80 | this.nextHopIpAddress = nextHopIpAddress; |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 81 | this.publicFacingMac = publicFacingMac; |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 82 | this.xosIpAddress = xosIpAddress; |
| 83 | this.xosRestPort = xosRestPort; |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame] | 84 | this.hosts = hosts; |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Gets a list of public IP prefixes configured for local SDN network. |
| 89 | * |
| 90 | * @return the list of public IP prefixes |
| 91 | */ |
| 92 | public List<IpPrefix> getLocalPublicIpPrefixes() { |
| 93 | return Collections.unmodifiableList(localPublicIpPrefixes); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Gets the IP address configured for the next hop (upstream gateway). |
| 98 | * |
| 99 | * @return the IP address of the next hop |
| 100 | */ |
| 101 | public IpAddress getNextHopIpAddress() { |
| 102 | return nextHopIpAddress; |
| 103 | } |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Gets the MAC address configured for all the public IP addresses. |
| 107 | * |
| 108 | * @return the MAC address |
| 109 | */ |
| 110 | public MacAddress getPublicFacingMac() { |
| 111 | return publicFacingMac; |
| 112 | } |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * Gets the IP address configured for XOS server. |
| 116 | * |
| 117 | * @return the IP address configured for the XOS server |
| 118 | */ |
| 119 | public IpAddress getXosIpAddress() { |
| 120 | return xosIpAddress; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Gets the REST communication port configured for XOS server. |
| 125 | * |
| 126 | * @return the REST communication port configured for XOS server |
| 127 | */ |
| 128 | public int getXosRestPort() { |
| 129 | return xosRestPort; |
| 130 | } |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame] | 131 | |
| 132 | public Map<String, ConnectPoint> getHosts() { |
| 133 | return hosts.entrySet() |
| 134 | .stream() |
| 135 | .collect(Collectors.toMap( |
| 136 | e -> e.getKey(), |
| 137 | e -> e.getValue().connectPoint() |
| 138 | )); |
| 139 | } |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 140 | } |