blob: da14faeeb807c9dd3961a7f6b9934a9199e0b93f [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
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 */
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;
23
24/**
25 * Representation of a Router gateway.
26 */
27public final class RouterGateway {
28
29 private final TenantNetworkId networkId;
30 private final boolean enableSnat;
31 private final Collection<FixedIp> externalFixedIps;
32
33 // Public construction is prohibited
34 private RouterGateway(TenantNetworkId networkId, boolean enableSnat,
35 Collection<FixedIp> externalFixedIps) {
36 this.networkId = checkNotNull(networkId, "networkId cannot be null");
37 this.enableSnat = checkNotNull(enableSnat, "enableSnat cannot be null");
38 this.externalFixedIps = checkNotNull(externalFixedIps, "externalFixedIps cannot be null");
39 }
40
41 /**
42 * Creates router gateway object.
43 *
44 * @param networkId network identifier
45 * @param enableSnat SNAT enable or not
46 * @param externalFixedIps external fixed IP
47 * @return RouterGateway
48 */
49 public static RouterGateway routerGateway(TenantNetworkId networkId, boolean enableSnat,
50 Collection<FixedIp> externalFixedIps) {
51 return new RouterGateway(networkId, enableSnat, externalFixedIps);
52 }
53
54 /**
55 * Returns network identifier.
56 *
57 * @return networkId
58 */
59 public TenantNetworkId networkId() {
60 return networkId;
61 }
62
63 /**
64 * Return SNAT enable or not.
65 *
66 * @return enableSnat
67 */
68 public boolean enableSnat() {
69 return enableSnat;
70 }
71
72 /**
73 * Return external fixed Ip.
74 *
75 * @return externalFixedIps
76 */
77 public Collection<FixedIp> externalFixedIps() {
78 return externalFixedIps;
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(networkId, enableSnat, externalFixedIps);
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (this == obj) {
89 return true;
90 }
91 if (obj instanceof RouterGateway) {
92 final RouterGateway that = (RouterGateway) obj;
93 return Objects.equals(this.networkId, that.networkId)
94 && Objects.equals(this.enableSnat, that.enableSnat)
95 && Objects.equals(this.externalFixedIps, that.externalFixedIps);
96 }
97 return false;
98 }
99
100 @Override
101 public String toString() {
102 return toStringHelper(this)
103 .add("networkId", networkId)
104 .add("enableSnat", enableSnat)
105 .add("externalFixedIps", externalFixedIps)
106 .toString();
107 }
108}