blob: e1c5c7fd5b13e10d395c63a3925e641d98e40437 [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/**
26 * The class representing a ovsdb tunnel. This class is immutable.
27 */
28public final class OvsdbTunnel {
29
30 private final IpAddress localIp;
31 private final IpAddress remoteIp;
32
33 public enum Type {
34 VXLAN, GRE
35 }
36
37 private final Type tunnelType;
38 private final OvsdbTunnelName tunnelName;
39
40 /**
41 * Constructor from a IpAddress localIp, IpAddress remoteIp Type tunnelType,
42 * OvsdbTunnelName tunnelName.
43 *
44 * @param localIp the localIp to use
45 * @param remoteIp the remoteIp to use
46 * @param tunnelType the tunnelType to use
47 * @param tunnelName the tunnelName to use
48 */
49 public OvsdbTunnel(IpAddress localIp, IpAddress remoteIp, Type tunnelType,
50 OvsdbTunnelName tunnelName) {
51 checkNotNull(localIp, "portName is not null");
52 checkNotNull(remoteIp, "portName is not null");
53 checkNotNull(tunnelName, "portName is not null");
54 this.localIp = localIp;
55 this.remoteIp = remoteIp;
56 this.tunnelType = tunnelType;
57 this.tunnelName = tunnelName;
58 }
59
60 /**
61 * Gets the local IP of the tunnel.
62 *
63 * @return the local IP of the tunnel
64 */
65 public IpAddress localIp() {
66 return localIp;
67 }
68
69 /**
70 * Gets the remote IP of the tunnel.
71 *
72 * @return the remote IP of the tunnel
73 */
74 public IpAddress remoteIp() {
75 return remoteIp;
76 }
77
78 /**
79 * Gets the tunnel type of the tunnel.
80 *
81 * @return the tunnel type of the tunnel
82 */
83 public Type tunnelType() {
84 return tunnelType;
85 }
86
87 /**
88 * Gets the tunnel name of the tunnel.
89 *
90 * @return the tunnel name of the tunnel
91 */
92 public OvsdbTunnelName tunnelName() {
93 return tunnelName;
94 }
95
96 @Override
97 public int hashCode() {
98 return Objects.hash(localIp, remoteIp, tunnelType, tunnelName);
99 }
100
101 @Override
102 public boolean equals(Object obj) {
103 if (this == obj) {
104 return true;
105 }
106 if (obj instanceof OvsdbTunnel) {
107 final OvsdbTunnel otherOvsdbTunnel = (OvsdbTunnel) obj;
108 return Objects.equals(this.localIp, otherOvsdbTunnel.localIp)
109 && Objects.equals(this.remoteIp, otherOvsdbTunnel.remoteIp)
110 && Objects.equals(this.tunnelType,
111 otherOvsdbTunnel.tunnelType)
112 && Objects.equals(this.tunnelName,
113 otherOvsdbTunnel.tunnelName);
114 }
115 return false;
116 }
117
118 @Override
119 public String toString() {
120 return toStringHelper(this).add("localIp", localIp.toString())
121 .add("remoteIp", remoteIp.toString())
122 .add("tunnelType", tunnelType).add("tunnelName", tunnelName)
123 .toString();
124 }
125}