CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ovsdb.controller; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import org.onlab.packet.IpAddress; |
| 24 | |
| 25 | /** |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 26 | * The class representing an ovsdb tunnel. |
| 27 | * This class is immutable. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 28 | */ |
| 29 | public final class OvsdbTunnel { |
| 30 | |
| 31 | private final IpAddress localIp; |
| 32 | private final IpAddress remoteIp; |
| 33 | |
| 34 | public enum Type { |
| 35 | VXLAN, GRE |
| 36 | } |
| 37 | |
| 38 | private final Type tunnelType; |
| 39 | private final OvsdbTunnelName tunnelName; |
| 40 | |
| 41 | /** |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 42 | * Constructor from an IpAddress localIp, IpAddress remoteIp Type tunnelType, |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 43 | * OvsdbTunnelName tunnelName. |
| 44 | * |
| 45 | * @param localIp the localIp to use |
| 46 | * @param remoteIp the remoteIp to use |
| 47 | * @param tunnelType the tunnelType to use |
| 48 | * @param tunnelName the tunnelName to use |
| 49 | */ |
| 50 | public OvsdbTunnel(IpAddress localIp, IpAddress remoteIp, Type tunnelType, |
| 51 | OvsdbTunnelName tunnelName) { |
| 52 | checkNotNull(localIp, "portName is not null"); |
| 53 | checkNotNull(remoteIp, "portName is not null"); |
| 54 | checkNotNull(tunnelName, "portName is not null"); |
| 55 | this.localIp = localIp; |
| 56 | this.remoteIp = remoteIp; |
| 57 | this.tunnelType = tunnelType; |
| 58 | this.tunnelName = tunnelName; |
| 59 | } |
| 60 | |
| 61 | /** |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 62 | * Gets the local IP of tunnel. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 63 | * |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 64 | * @return the local IP of tunnel |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 65 | */ |
| 66 | public IpAddress localIp() { |
| 67 | return localIp; |
| 68 | } |
| 69 | |
| 70 | /** |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 71 | * Gets the remote IP of tunnel. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 72 | * |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 73 | * @return the remote IP of tunnel |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 74 | */ |
| 75 | public IpAddress remoteIp() { |
| 76 | return remoteIp; |
| 77 | } |
| 78 | |
| 79 | /** |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 80 | * Gets the tunnel type of tunnel. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 81 | * |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 82 | * @return the tunnel type of tunnel |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 83 | */ |
| 84 | public Type tunnelType() { |
| 85 | return tunnelType; |
| 86 | } |
| 87 | |
| 88 | /** |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 89 | * Gets the tunnel name of tunnel. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 90 | * |
BitOhenry | 5e97069 | 2015-11-02 19:35:01 +0800 | [diff] [blame] | 91 | * @return the tunnel name of tunnel |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 92 | */ |
| 93 | public OvsdbTunnelName tunnelName() { |
| 94 | return tunnelName; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public int hashCode() { |
| 99 | return Objects.hash(localIp, remoteIp, tunnelType, tunnelName); |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean equals(Object obj) { |
| 104 | if (this == obj) { |
| 105 | return true; |
| 106 | } |
| 107 | if (obj instanceof OvsdbTunnel) { |
| 108 | final OvsdbTunnel otherOvsdbTunnel = (OvsdbTunnel) obj; |
| 109 | return Objects.equals(this.localIp, otherOvsdbTunnel.localIp) |
| 110 | && Objects.equals(this.remoteIp, otherOvsdbTunnel.remoteIp) |
| 111 | && Objects.equals(this.tunnelType, |
| 112 | otherOvsdbTunnel.tunnelType) |
| 113 | && Objects.equals(this.tunnelName, |
| 114 | otherOvsdbTunnel.tunnelName); |
| 115 | } |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public String toString() { |
| 121 | return toStringHelper(this).add("localIp", localIp.toString()) |
| 122 | .add("remoteIp", remoteIp.toString()) |
| 123 | .add("tunnelType", tunnelType).add("tunnelName", tunnelName) |
| 124 | .toString(); |
| 125 | } |
| 126 | } |