blob: 18c59e14aee6902874a16785f734d3362b7cb654 [file] [log] [blame]
CNlucius74fd4942015-07-20 14:28:04 +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.ovsdb.controller;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23/**
BitOhenrycec4eea2015-10-23 17:14:02 +080024 * The class representing an ovsdb bridge.
25 * This class is immutable.
CNlucius74fd4942015-07-20 14:28:04 +080026 */
27public final class OvsdbBridge {
28
29 private final OvsdbBridgeName bridgeName;
30 private final OvsdbDatapathId datapathId;
31
32 /**
BitOhenrycec4eea2015-10-23 17:14:02 +080033 * Constructor from an OvsdbBridgeName bridgeName and an OvsdbDatapathId
CNlucius74fd4942015-07-20 14:28:04 +080034 * datapathId.
35 *
36 * @param bridgeName the bridgeName to use
37 * @param datapathId the datapathId to use
38 */
39 public OvsdbBridge(OvsdbBridgeName bridgeName, OvsdbDatapathId datapathId) {
40 checkNotNull(bridgeName, "bridgeName is not null");
41 checkNotNull(datapathId, "datapathId is not null");
42 this.bridgeName = bridgeName;
43 this.datapathId = datapathId;
44 }
45
46 /**
BitOhenrycec4eea2015-10-23 17:14:02 +080047 * Gets the bridge name of bridge.
CNlucius74fd4942015-07-20 14:28:04 +080048 *
BitOhenrycec4eea2015-10-23 17:14:02 +080049 * @return the bridge name of bridge
CNlucius74fd4942015-07-20 14:28:04 +080050 */
51 public OvsdbBridgeName bridgeName() {
52 return bridgeName;
53 }
54
55 /**
BitOhenrycec4eea2015-10-23 17:14:02 +080056 * Gets the datapathId of bridge.
CNlucius74fd4942015-07-20 14:28:04 +080057 *
58 * @return datapathId the datapathId to use
59 */
60 public OvsdbDatapathId datapathId() {
61 return datapathId;
62 }
63
64 @Override
65 public int hashCode() {
66 return Objects.hash(bridgeName, datapathId);
67 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (this == obj) {
72 return true;
73 }
74 if (obj instanceof OvsdbBridge) {
75 final OvsdbBridge otherOvsdbBridge = (OvsdbBridge) obj;
76 return Objects.equals(this.bridgeName, otherOvsdbBridge.bridgeName)
77 && Objects.equals(this.datapathId,
78 otherOvsdbBridge.datapathId);
79 }
80 return false;
81 }
82
83 @Override
84 public String toString() {
85 return toStringHelper(this).add("bridgeName", bridgeName.value())
86 .add("datapathId", datapathId.value()).toString();
87 }
88}