2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.vtnrsc.sfc;
18 import static com.google.common.base.MoreObjects.toStringHelper;
19 import static com.google.common.base.Preconditions.checkNotNull;
21 import java.util.Objects;
23 import org.onosproject.vtnrsc.TenantId;
26 * Implementation of port pair.
28 public final class DefaultPortPair implements PortPair {
30 private final PortPairId portPairId;
31 private final TenantId tenantId;
32 private final String name;
33 private final String description;
34 private final String ingress;
35 private final String egress;
38 * Default constructor to create Port Pair.
40 * @param portPairId port pair id
41 * @param tenantId tenant id
42 * @param name name of port pair
43 * @param description description of port pair
44 * @param ingress ingress port
45 * @param egress egress port
47 private DefaultPortPair(PortPairId portPairId, TenantId tenantId,
48 String name, String description,
49 String ingress, String egress) {
51 this.portPairId = portPairId;
52 this.tenantId = tenantId;
54 this.description = description;
55 this.ingress = ingress;
60 public PortPairId portPairId() {
65 public TenantId tenantId() {
70 public String name() {
75 public String description() {
80 public String ingress() {
85 public String egress() {
90 public int hashCode() {
91 return Objects.hash(portPairId, tenantId, name, description,
96 public boolean equals(Object obj) {
100 if (obj instanceof DefaultPortPair) {
101 DefaultPortPair that = (DefaultPortPair) obj;
102 return Objects.equals(portPairId, that.portPairId) &&
103 Objects.equals(tenantId, that.tenantId) &&
104 Objects.equals(name, that.name) &&
105 Objects.equals(description, that.description) &&
106 Objects.equals(ingress, that.ingress) &&
107 Objects.equals(egress, that.egress);
113 public boolean exactMatch(PortPair portPair) {
114 return this.equals(portPair) &&
115 Objects.equals(this.portPairId, portPair.portPairId()) &&
116 Objects.equals(this.tenantId, portPair.tenantId());
120 public String toString() {
121 return toStringHelper(this)
122 .add("id", portPairId.toString())
123 .add("tenantId", tenantId.tenantId())
125 .add("description", description)
126 .add("ingress", ingress)
127 .add("egress", egress)
132 * To create an instance of the builder.
134 * @return instance of builder
136 public static Builder builder() {
137 return new Builder();
141 * Builder class for Port pair.
143 public static final class Builder implements PortPair.Builder {
145 private PortPairId portPairId;
146 private TenantId tenantId;
148 private String description;
149 private String ingress;
150 private String egress;
153 public Builder setId(PortPairId portPairId) {
154 this.portPairId = portPairId;
159 public Builder setTenantId(TenantId tenantId) {
160 this.tenantId = tenantId;
165 public Builder setName(String name) {
171 public Builder setDescription(String description) {
172 this.description = description;
177 public Builder setIngress(String ingress) {
178 this.ingress = ingress;
183 public Builder setEgress(String egress) {
184 this.egress = egress;
189 public PortPair build() {
191 checkNotNull(portPairId, "Port pair id cannot be null");
192 checkNotNull(tenantId, "Tenant id cannot be null");
193 checkNotNull(ingress, "Ingress of a port pair cannot be null");
194 checkNotNull(egress, "Egress of a port pair cannot be null");
196 return new DefaultPortPair(portPairId, tenantId, name, description,