blob: 0f44cb800ee2db8f10bfc6817e9299f76fef5f3b [file] [log] [blame]
daniel parkb5817102018-02-15 00:18:51 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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.impl;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
22import org.onosproject.openstacknetworking.api.ExternalPeerRouter;
23
24import java.util.Objects;
25
Jian Li5e2ad4a2018-07-16 13:40:53 +090026import static com.google.common.base.Preconditions.checkArgument;
27
daniel parkb5817102018-02-15 00:18:51 +090028/**
29 * Implementation of external peer router.
30 */
Jian Lifae7b382018-07-12 22:27:47 +090031public final class DefaultExternalPeerRouter implements ExternalPeerRouter {
daniel parkb5817102018-02-15 00:18:51 +090032
Jian Li5e2ad4a2018-07-16 13:40:53 +090033 private final IpAddress ipAddress;
34 private final MacAddress macAddress;
35 private final VlanId vlanId;
daniel parkb5817102018-02-15 00:18:51 +090036
Jian Li5e2ad4a2018-07-16 13:40:53 +090037 private static final String NOT_NULL_MSG = "External Peer Router % cannot be null";
38
39 // private constructor not intended for invoked from external
40 private DefaultExternalPeerRouter(IpAddress ipAddress,
41 MacAddress macAddress,
42 VlanId vlanId) {
43 this.ipAddress = ipAddress;
44 this.macAddress = macAddress;
45 this.vlanId = vlanId;
daniel parkb5817102018-02-15 00:18:51 +090046 }
47
48 @Override
Jian Li5e2ad4a2018-07-16 13:40:53 +090049 public IpAddress ipAddress() {
50 return this.ipAddress;
daniel parkb5817102018-02-15 00:18:51 +090051 }
Jian Li5e2ad4a2018-07-16 13:40:53 +090052
daniel parkb5817102018-02-15 00:18:51 +090053 @Override
Jian Li5e2ad4a2018-07-16 13:40:53 +090054 public MacAddress macAddress() {
55 return this.macAddress;
daniel parkb5817102018-02-15 00:18:51 +090056 }
Jian Li5e2ad4a2018-07-16 13:40:53 +090057
daniel parkb5817102018-02-15 00:18:51 +090058 @Override
Jian Li5e2ad4a2018-07-16 13:40:53 +090059 public VlanId vlanId() {
60 return this.vlanId;
daniel parkb5817102018-02-15 00:18:51 +090061 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68
69 if (obj instanceof DefaultExternalPeerRouter) {
70 DefaultExternalPeerRouter that = (DefaultExternalPeerRouter) obj;
Jian Li5e2ad4a2018-07-16 13:40:53 +090071 return Objects.equals(ipAddress, that.ipAddress) &&
72 Objects.equals(macAddress, that.macAddress) &&
73 Objects.equals(vlanId, that.vlanId);
daniel parkb5817102018-02-15 00:18:51 +090074 }
75 return false;
76 }
77
78 @Override
79 public int hashCode() {
Jian Li5e2ad4a2018-07-16 13:40:53 +090080 return Objects.hash(ipAddress, macAddress, vlanId);
daniel parkb5817102018-02-15 00:18:51 +090081 }
82
83 @Override
84 public String toString() {
85 return MoreObjects.toStringHelper(getClass())
Jian Li5e2ad4a2018-07-16 13:40:53 +090086 .add("ipAddress", ipAddress)
87 .add("macAddress", macAddress)
88 .add("vlanId", vlanId)
daniel parkb5817102018-02-15 00:18:51 +090089 .toString();
90 }
Jian Li5e2ad4a2018-07-16 13:40:53 +090091
92 /**
93 * Obtains an external peer router builder.
94 *
95 * @return external peer router builder
96 */
97 public static Builder builder() {
98 return new Builder();
99 }
100
101 /**
102 * A builder class for external peer router.
103 */
104 public static final class Builder implements ExternalPeerRouter.Builder {
105
106 private IpAddress ipAddress;
107 private MacAddress macAddress;
108 private VlanId vlanId;
109
110 // private constructor not intended to use from external
111 private Builder() {
112 }
113
114 @Override
115 public ExternalPeerRouter build() {
116
117 checkArgument(ipAddress != null, NOT_NULL_MSG, "IP address");
118 checkArgument(macAddress != null, NOT_NULL_MSG, "MAC address");
119 checkArgument(vlanId != null, NOT_NULL_MSG, "VLAN ID");
120
121 return new DefaultExternalPeerRouter(ipAddress, macAddress, vlanId);
122 }
123
124 @Override
125 public Builder ipAddress(IpAddress ipAddress) {
126 this.ipAddress = ipAddress;
127 return this;
128 }
129
130 @Override
131 public Builder macAddress(MacAddress macAddress) {
132 this.macAddress = macAddress;
133 return this;
134 }
135
136 @Override
137 public Builder vlanId(VlanId vlanId) {
138 this.vlanId = vlanId;
139 return this;
140 }
141 }
daniel parkb5817102018-02-15 00:18:51 +0900142}