Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 64 | */ |
| 65 | @JsonCreator |
| 66 | public VbngConfiguration(@JsonProperty("localPublicIpPrefixes") |
| 67 | List<IpPrefix> prefixes, |
| 68 | @JsonProperty("nextHopIpAddress") |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 69 | IpAddress nextHopIpAddress, |
| 70 | @JsonProperty("publicFacingMac") |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 71 | MacAddress publicFacingMac, |
| 72 | @JsonProperty("xosIpAddress") |
| 73 | IpAddress xosIpAddress, |
| 74 | @JsonProperty("xosRestPort") |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame^] | 75 | int xosRestPort, |
| 76 | @JsonProperty("hosts") |
| 77 | Map<String, ConnectPointConfiguration> hosts) { |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 78 | localPublicIpPrefixes = prefixes; |
| 79 | this.nextHopIpAddress = nextHopIpAddress; |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 80 | this.publicFacingMac = publicFacingMac; |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 81 | this.xosIpAddress = xosIpAddress; |
| 82 | this.xosRestPort = xosRestPort; |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame^] | 83 | this.hosts = hosts; |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Gets a list of public IP prefixes configured for local SDN network. |
| 88 | * |
| 89 | * @return the list of public IP prefixes |
| 90 | */ |
| 91 | public List<IpPrefix> getLocalPublicIpPrefixes() { |
| 92 | return Collections.unmodifiableList(localPublicIpPrefixes); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Gets the IP address configured for the next hop (upstream gateway). |
| 97 | * |
| 98 | * @return the IP address of the next hop |
| 99 | */ |
| 100 | public IpAddress getNextHopIpAddress() { |
| 101 | return nextHopIpAddress; |
| 102 | } |
Pingping Lin | be12656 | 2015-05-06 17:57:10 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Gets the MAC address configured for all the public IP addresses. |
| 106 | * |
| 107 | * @return the MAC address |
| 108 | */ |
| 109 | public MacAddress getPublicFacingMac() { |
| 110 | return publicFacingMac; |
| 111 | } |
Pingping Lin | e10ece0 | 2015-06-11 19:26:24 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Gets the IP address configured for XOS server. |
| 115 | * |
| 116 | * @return the IP address configured for the XOS server |
| 117 | */ |
| 118 | public IpAddress getXosIpAddress() { |
| 119 | return xosIpAddress; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Gets the REST communication port configured for XOS server. |
| 124 | * |
| 125 | * @return the REST communication port configured for XOS server |
| 126 | */ |
| 127 | public int getXosRestPort() { |
| 128 | return xosRestPort; |
| 129 | } |
Jonathan Hart | bbc352f | 2015-10-27 19:24:36 -0700 | [diff] [blame^] | 130 | |
| 131 | public Map<String, ConnectPoint> getHosts() { |
| 132 | return hosts.entrySet() |
| 133 | .stream() |
| 134 | .collect(Collectors.toMap( |
| 135 | e -> e.getKey(), |
| 136 | e -> e.getValue().connectPoint() |
| 137 | )); |
| 138 | } |
Pingping Lin | ffa27d3 | 2015-04-30 14:41:03 -0700 | [diff] [blame] | 139 | } |