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