sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [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 | */ |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 16 | package org.onosproject.openstackinterface; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 17 | |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableMap; |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 19 | import com.google.common.collect.Maps; |
| 20 | import org.onlab.packet.Ip4Address; |
| 21 | import java.util.Map; |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * A configurable external gateway modes extension model in openstack router. |
| 26 | */ |
| 27 | public final class OpenstackExternalGateway { |
| 28 | |
| 29 | private final String networkId; |
| 30 | private final boolean enablePnat; |
| 31 | private final Map<String, Ip4Address> externalFixedIps; |
| 32 | |
| 33 | private OpenstackExternalGateway(String networkId, boolean enablePnat, |
| 34 | Map<String, Ip4Address> externalFixedIps) { |
| 35 | this.networkId = networkId; |
| 36 | this.enablePnat = enablePnat; |
| 37 | this.externalFixedIps = externalFixedIps; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns network ID. |
| 42 | * |
| 43 | * @return Network ID |
| 44 | */ |
| 45 | public String networkId() { |
| 46 | return networkId; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns the PNAT status for external gateway. |
| 51 | * |
| 52 | * @return PNAT status |
| 53 | */ |
| 54 | public boolean isEnablePnat() { |
| 55 | return enablePnat; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns external fixed IP informations. |
| 60 | * |
| 61 | * @return External fixed IP informations |
| 62 | */ |
| 63 | public Map<String, Ip4Address> externalFixedIps() { |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 64 | return ImmutableMap.copyOf(externalFixedIps); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object o) { |
| 69 | if (this == o) { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | if (o instanceof OpenstackExternalGateway) { |
| 74 | OpenstackExternalGateway that = (OpenstackExternalGateway) o; |
| 75 | |
| 76 | return this.networkId.equals(that.networkId) && |
| 77 | this.enablePnat == that.enablePnat && |
| 78 | this.externalFixedIps.equals(that.externalFixedIps); |
| 79 | } |
| 80 | |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return Objects.hash(networkId, enablePnat, externalFixedIps); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * An Openstack External Gateway Builder class. |
| 91 | */ |
| 92 | public static final class Builder { |
| 93 | private String networkId; |
| 94 | private boolean enablePnat; |
| 95 | private Map<String, Ip4Address> externalFixedIps; |
| 96 | |
| 97 | public Builder() { |
| 98 | externalFixedIps = Maps.newHashMap(); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Sets network ID. |
| 103 | * |
| 104 | * @param networkId Network ID |
| 105 | * @return Builder object |
| 106 | */ |
| 107 | public Builder networkId(String networkId) { |
| 108 | this.networkId = networkId; |
| 109 | return this; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Sets whether PNAT status is enabled or not. |
| 114 | * |
| 115 | * @param enablePnat true if PNAT status is enabled, false otherwise |
| 116 | * @return Builder object |
| 117 | */ |
| 118 | public Builder enablePnat(boolean enablePnat) { |
| 119 | this.enablePnat = enablePnat; |
| 120 | return this; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Sets external fixed IP address information. |
| 125 | * |
| 126 | * @param externalFixedIps External fixed IP information |
| 127 | * @return Builder object |
| 128 | */ |
| 129 | |
| 130 | public Builder externalFixedIps(Map<String, Ip4Address> externalFixedIps) { |
| 131 | this.externalFixedIps.putAll(externalFixedIps); |
| 132 | return this; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Builds an OpenstackExternalGateway object. |
| 137 | * |
| 138 | * @return OpenstackExternalGateway object |
| 139 | */ |
| 140 | public OpenstackExternalGateway build() { |
Kyuhwi Choi | e2b37e3 | 2016-02-05 14:04:14 +0900 | [diff] [blame] | 141 | return new OpenstackExternalGateway(networkId, enablePnat, ImmutableMap.copyOf(externalFixedIps)); |
sangho | 0c2a3da | 2016-02-16 13:39:07 +0900 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
| 145 | } |