blob: b8cdbe94bb43e08968edf07ad4d517b2b7e07617 [file] [log] [blame]
Hyunsun Moond0e932a2015-09-15 22:39:16 -07001/*
2 * Copyright 2014-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.cordvtn;
17
18import org.onlab.packet.IpAddress;
19import org.onlab.packet.TpPort;
20import org.onosproject.net.DeviceId;
21
22import java.util.Objects;
23
24/**
25 * OvsdbNode implementation.
26 */
27public class DefaultOvsdbNode implements OvsdbNode {
28
29 private final String hostname;
30 private final IpAddress ip;
31 private final TpPort port;
32 private final DeviceId deviceId;
33 private final DeviceId bridgeId;
34 private final State state;
35
36 public DefaultOvsdbNode(String hostname, IpAddress ip, TpPort port,
37 DeviceId bridgeId, State state) {
38 this.hostname = hostname;
39 this.ip = ip;
40 this.port = port;
41 this.deviceId = DeviceId.deviceId(
42 "ovsdb:" + ip.toString() + ":" + port.toString());
43 this.bridgeId = bridgeId;
44 this.state = state;
45 }
46
47 @Override
48 public IpAddress ip() {
49 return this.ip;
50 }
51
52 @Override
53 public TpPort port() {
54 return this.port;
55 }
56
57 @Override
58 public String hostname() {
59 return this.hostname;
60 }
61
62 @Override
63 public State state() {
64 return this.state;
65 }
66
67 @Override
68 public DeviceId deviceId() {
69 return this.deviceId;
70 }
71
72 @Override
73 public DeviceId bridgeId() {
74 return this.bridgeId;
75 }
76
77 @Override
78 public boolean equals(Object o) {
79 if (this == o) {
80 return true;
81 }
82
83 if (o instanceof DefaultOvsdbNode) {
84 DefaultOvsdbNode that = (DefaultOvsdbNode) o;
85 // We compare the ip and port only.
86 if (this.ip.equals(that.ip) && this.port.equals(that.port)) {
87 return true;
88 }
89 }
90 return false;
91 }
92
93 @Override
94 public int hashCode() {
95 return Objects.hash(ip, port);
96 }
97}