Daniel Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Daniel Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.ofagent.impl; |
| 17 | |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Daniel Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.TpPort; |
| 21 | import org.onosproject.ofagent.api.OFController; |
| 22 | |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 23 | import java.util.Objects; |
Daniel Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 24 | |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Implementation of the default OpenFlow controller. |
| 29 | */ |
| 30 | public 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 Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 36 | this.ip = ip; |
| 37 | this.port = port; |
| 38 | } |
| 39 | |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 40 | /** |
| 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 Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 53 | @Override |
| 54 | public IpAddress ip() { |
| 55 | return ip; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public TpPort port() { |
| 60 | return port; |
| 61 | } |
Hyunsun Moon | f4ba44f | 2017-03-14 03:25:52 +0900 | [diff] [blame] | 62 | |
| 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 Park | be6b673 | 2016-11-11 15:52:19 +0900 | [diff] [blame] | 91 | } |