blob: 8c857da424e8e245728f82536bc611bb8cbaa0e7 [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
23import org.onlab.packet.IpAddress;
24
25/**
BitOhenry5e970692015-11-02 19:35:01 +080026 * The class representing an ovsdb tunnel.
27 * This class is immutable.
CNlucius74fd4942015-07-20 14:28:04 +080028 */
29public 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 /**
BitOhenry5e970692015-11-02 19:35:01 +080042 * Constructor from an IpAddress localIp, IpAddress remoteIp Type tunnelType,
CNlucius74fd4942015-07-20 14:28:04 +080043 * 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 /**
BitOhenry5e970692015-11-02 19:35:01 +080062 * Gets the local IP of tunnel.
CNlucius74fd4942015-07-20 14:28:04 +080063 *
BitOhenry5e970692015-11-02 19:35:01 +080064 * @return the local IP of tunnel
CNlucius74fd4942015-07-20 14:28:04 +080065 */
66 public IpAddress localIp() {
67 return localIp;
68 }
69
70 /**
BitOhenry5e970692015-11-02 19:35:01 +080071 * Gets the remote IP of tunnel.
CNlucius74fd4942015-07-20 14:28:04 +080072 *
BitOhenry5e970692015-11-02 19:35:01 +080073 * @return the remote IP of tunnel
CNlucius74fd4942015-07-20 14:28:04 +080074 */
75 public IpAddress remoteIp() {
76 return remoteIp;
77 }
78
79 /**
BitOhenry5e970692015-11-02 19:35:01 +080080 * Gets the tunnel type of tunnel.
CNlucius74fd4942015-07-20 14:28:04 +080081 *
BitOhenry5e970692015-11-02 19:35:01 +080082 * @return the tunnel type of tunnel
CNlucius74fd4942015-07-20 14:28:04 +080083 */
84 public Type tunnelType() {
85 return tunnelType;
86 }
87
88 /**
BitOhenry5e970692015-11-02 19:35:01 +080089 * Gets the tunnel name of tunnel.
CNlucius74fd4942015-07-20 14:28:04 +080090 *
BitOhenry5e970692015-11-02 19:35:01 +080091 * @return the tunnel name of tunnel
CNlucius74fd4942015-07-20 14:28:04 +080092 */
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}