blob: 6aef24ed4865f4cd6dc58b5d31f1b4b526cfdf07 [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Madan Jampanic27b6b22016-02-05 11:36:31 -08003 *
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.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Collection;
22import java.util.Objects;
yuanyoue2ed3862016-05-06 13:18:08 +080023import java.util.Set;
Madan Jampanic27b6b22016-02-05 11:36:31 -080024
25/**
26 * Representation of a Router gateway.
27 */
28public final class RouterGateway {
29
30 private final TenantNetworkId networkId;
31 private final boolean enableSnat;
yuanyoue2ed3862016-05-06 13:18:08 +080032 private final Set<FixedIp> externalFixedIps;
Madan Jampanic27b6b22016-02-05 11:36:31 -080033
34 // Public construction is prohibited
35 private RouterGateway(TenantNetworkId networkId, boolean enableSnat,
yuanyoue2ed3862016-05-06 13:18:08 +080036 Set<FixedIp> externalFixedIps) {
Madan Jampanic27b6b22016-02-05 11:36:31 -080037 this.networkId = checkNotNull(networkId, "networkId cannot be null");
Yuta HIGUCHI1edc36b2018-01-24 23:39:06 -080038 this.enableSnat = enableSnat;
Madan Jampanic27b6b22016-02-05 11:36:31 -080039 this.externalFixedIps = checkNotNull(externalFixedIps, "externalFixedIps cannot be null");
40 }
41
42 /**
43 * Creates router gateway object.
44 *
45 * @param networkId network identifier
46 * @param enableSnat SNAT enable or not
47 * @param externalFixedIps external fixed IP
48 * @return RouterGateway
49 */
50 public static RouterGateway routerGateway(TenantNetworkId networkId, boolean enableSnat,
yuanyoue2ed3862016-05-06 13:18:08 +080051 Set<FixedIp> externalFixedIps) {
Madan Jampanic27b6b22016-02-05 11:36:31 -080052 return new RouterGateway(networkId, enableSnat, externalFixedIps);
53 }
54
55 /**
56 * Returns network identifier.
57 *
58 * @return networkId
59 */
60 public TenantNetworkId networkId() {
61 return networkId;
62 }
63
64 /**
65 * Return SNAT enable or not.
66 *
67 * @return enableSnat
68 */
69 public boolean enableSnat() {
70 return enableSnat;
71 }
72
73 /**
74 * Return external fixed Ip.
75 *
76 * @return externalFixedIps
77 */
78 public Collection<FixedIp> externalFixedIps() {
79 return externalFixedIps;
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(networkId, enableSnat, externalFixedIps);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (obj instanceof RouterGateway) {
93 final RouterGateway that = (RouterGateway) obj;
94 return Objects.equals(this.networkId, that.networkId)
95 && Objects.equals(this.enableSnat, that.enableSnat)
96 && Objects.equals(this.externalFixedIps, that.externalFixedIps);
97 }
98 return false;
99 }
100
101 @Override
102 public String toString() {
103 return toStringHelper(this)
104 .add("networkId", networkId)
105 .add("enableSnat", enableSnat)
106 .add("externalFixedIps", externalFixedIps)
107 .toString();
108 }
109}