blob: 105285a6aedca71b13bbb4269a6a0df4c0195b4c [file] [log] [blame]
Daniel Parkbe6b6732016-11-11 15:52:19 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Daniel Parkbe6b6732016-11-11 15:52:19 +09003 *
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.ofagent.impl;
17
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090018import com.google.common.base.MoreObjects;
Daniel Parkbe6b6732016-11-11 15:52:19 +090019import org.onlab.packet.IpAddress;
20import org.onlab.packet.TpPort;
21import org.onosproject.ofagent.api.OFController;
22
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090023import java.util.Objects;
Daniel Parkbe6b6732016-11-11 15:52:19 +090024
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090025import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Implementation of the default OpenFlow controller.
29 */
30public final class DefaultOFController implements OFController {
31
32 private final IpAddress ip;
33 private final TpPort port;
34
35 private DefaultOFController(IpAddress ip, TpPort port) {
Daniel Parkbe6b6732016-11-11 15:52:19 +090036 this.ip = ip;
37 this.port = port;
38 }
39
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090040 /**
41 * Returns new OpenFlow controller with the supplied IP and port.
42 *
43 * @param ip ip address
44 * @param port port number
45 * @return openflow controller
46 */
47 public static DefaultOFController of(IpAddress ip, TpPort port) {
48 checkNotNull(ip, "Controller IP address cannot be null");
49 checkNotNull(port, "Controller port address cannot be null");
50 return new DefaultOFController(ip, port);
51 }
52
Daniel Parkbe6b6732016-11-11 15:52:19 +090053 @Override
54 public IpAddress ip() {
55 return ip;
56 }
57
58 @Override
59 public TpPort port() {
60 return port;
61 }
Hyunsun Moonf4ba44f2017-03-14 03:25:52 +090062
63 @Override
64 public int hashCode() {
65 return Objects.hash(ip, port);
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73
74 if (obj instanceof DefaultOFController) {
75 DefaultOFController that = (DefaultOFController) obj;
76 if (Objects.equals(ip, that.ip) &&
77 Objects.equals(port, that.port)) {
78 return true;
79 }
80 }
81 return false;
82 }
83
84 @Override
85 public String toString() {
86 return MoreObjects.toStringHelper(this)
87 .add("ip", this.ip)
88 .add("port", this.port)
89 .toString();
90 }
Daniel Parkbe6b6732016-11-11 15:52:19 +090091}