blob: ac7070119aa12a0d017a8e92f6d4a3e745847e7b [file] [log] [blame]
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +09001/*
2 * Copyright 2016 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 */
16package org.onosproject.openstackrouting;
17
Daniel Park3a06c522016-01-28 20:51:12 +090018import com.google.common.collect.ImmutableMap;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090019import org.onlab.packet.Ip4Address;
20
21import java.util.HashMap;
Daniel Park3a06c522016-01-28 20:51:12 +090022import java.util.Map;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090023
24/**
25 * A configurable external gateway modes extension model in openstack router.
26 */
27public final class OpenstackExternalGateway {
28
29 private String networkId;
Jonathan Hart51539b82015-10-29 09:53:04 -070030 private boolean enablePnat;
Daniel Park3a06c522016-01-28 20:51:12 +090031 private Map<String, Ip4Address> externalFixedIps;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090032
Jonathan Hart51539b82015-10-29 09:53:04 -070033 private OpenstackExternalGateway(String networkId, boolean enablePnat,
Daniel Park3a06c522016-01-28 20:51:12 +090034 Map<String, Ip4Address> externalFixedIps) {
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090035 this.networkId = networkId;
Jonathan Hart51539b82015-10-29 09:53:04 -070036 this.enablePnat = enablePnat;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090037 this.externalFixedIps = externalFixedIps;
38 }
39
Daniel Park3a06c522016-01-28 20:51:12 +090040 public static OpenstackExternalGateway.Builder builder() {
41 return new Builder();
42 }
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090043 /**
44 * Returns network ID.
45 *
46 * @return Network ID
47 */
48 public String networkId() {
49 return networkId;
50 }
51
52 /**
53 * Returns the PNAT status for external gateway.
54 *
55 * @return PNAT status
56 */
Jonathan Hart51539b82015-10-29 09:53:04 -070057 public boolean isEnablePnat() {
58 return enablePnat;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090059 }
60
Daniel Park3a06c522016-01-28 20:51:12 +090061 public Map<String, Ip4Address> externalFixedIps() {
62 return ImmutableMap.copyOf(externalFixedIps);
63 }
64
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090065 /**
66 * An Openstack External Gateway Builder class.
67 */
68 public static final class Builder {
69 private String networkId;
Jonathan Hart51539b82015-10-29 09:53:04 -070070 private boolean enablePnat;
Daniel Park3a06c522016-01-28 20:51:12 +090071 private Map<String, Ip4Address> externalFixedIps;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090072
73 Builder() {
Jonathan Hart51539b82015-10-29 09:53:04 -070074 externalFixedIps = new HashMap<>();
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090075 }
76
77 /**
78 * Sets network ID.
79 *
80 * @param networkId Network ID
81 * @return Builder object
82 */
83 public Builder networkId(String networkId) {
84 this.networkId = networkId;
85 return this;
86 }
87
88 /**
89 * Sets whether PNAT status is enabled or not.
90 *
Jonathan Hart51539b82015-10-29 09:53:04 -070091 * @param enablePnat true if PNAT status is enabled, false otherwise
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090092 * @return Builder object
93 */
Jonathan Hart51539b82015-10-29 09:53:04 -070094 public Builder enablePnat(boolean enablePnat) {
95 this.enablePnat = enablePnat;
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +090096 return this;
97 }
98
99 /**
100 * Sets external fixed IP address information.
101 *
Daniel Park3a06c522016-01-28 20:51:12 +0900102 * @param externalFixedIps External fixed IP information
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +0900103 * @return Builder object
104 */
Daniel Park3a06c522016-01-28 20:51:12 +0900105
106 public Builder externalFixedIps(Map<String, Ip4Address> externalFixedIps) {
107 this.externalFixedIps.putAll(externalFixedIps);
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +0900108 return this;
109 }
110
111 /**
112 * Builds an OpenstackExternalGateway object.
113 *
114 * @return OpenstackExternalGateway object
115 */
116 public OpenstackExternalGateway build() {
Jonathan Hart51539b82015-10-29 09:53:04 -0700117 return new OpenstackExternalGateway(networkId, enablePnat, externalFixedIps);
Kyuhwi Choi5d7c9982016-01-20 13:55:55 +0900118 }
119 }
120
121}