blob: 290cc170c2ff9e426e522adee17eb9c936664e74 [file] [log] [blame]
Hyunsun Moon9f0814b2015-11-04 17:34:35 -08001/*
2 * Copyright 2014-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.cordvtn;
17
18import org.onlab.packet.IpAddress;
19import org.onlab.packet.MacAddress;
20import org.onosproject.net.Port;
21
22import java.util.List;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Contains destination information.
28 */
29public final class DestinationInfo {
30
31 private final Port output;
32 private final List<IpAddress> ip;
33 private final MacAddress mac;
34 private final IpAddress remoteIp;
35 private final long tunnelId;
36
37 /**
38 * Creates a new destination information.
39 *
40 * @param output output port
41 * @param ip destination ip address
42 * @param mac destination mac address
43 * @param remoteIp tunnel remote ip address
44 * @param tunnelId segment id
45 */
46 public DestinationInfo(Port output, List<IpAddress> ip, MacAddress mac,
47 IpAddress remoteIp, long tunnelId) {
48 this.output = checkNotNull(output);
49 this.ip = ip;
50 this.mac = mac;
51 this.remoteIp = remoteIp;
52 this.tunnelId = tunnelId;
53 }
54
55 /**
56 * Returns output port.
57 *
58 * @return port
59 */
60 public Port output() {
61 return output;
62 }
63
64 /**
65 * Returns destination ip addresses.
66 *
67 * @return list of ip address
68 */
69 public List<IpAddress> ip() {
70 return ip;
71 }
72
73 /**
74 * Returns destination mac address.
75 *
76 * @return mac address
77 */
78 public MacAddress mac() {
79 return mac;
80 }
81
82 /**
83 * Returns tunnel remote ip address.
84 *
85 * @return ip address
86 */
87 public IpAddress remoteIp() {
88 return remoteIp;
89 }
90
91 /**
92 * Returns tunnel id.
93 *
94 * @return tunnel id
95 */
96 public long tunnelId() {
97 return tunnelId;
98 }
99
100 /**
101 * Returns a new destination info builder.
102 *
103 * @return destination info builder
104 */
105 public static DestinationInfo.Builder builder(Port output) {
106 return new Builder(output);
107 }
108
109 /**
110 * DestinationInfo builder class.
111 */
112 public static final class Builder {
113
114 private final Port output;
115 private List<IpAddress> ip;
116 private MacAddress mac;
117 private IpAddress remoteIp;
118 private long tunnelId;
119
120 /**
121 * Creates a new destination information builder.
122 *
123 * @param output output port
124 */
125 public Builder(Port output) {
126 this.output = checkNotNull(output, "Output port cannot be null");
127 }
128
129 /**
130 * Sets the destination ip address.
131 *
132 * @param ip ip address
133 * @return destination info builder
134 */
135 public Builder setIp(List<IpAddress> ip) {
136 this.ip = checkNotNull(ip, "IP cannot be null");
137 return this;
138 }
139
140 /**
141 * Sets the destination mac address.
142 *
143 * @param mac mac address
144 * @return destination info builder
145 */
146 public Builder setMac(MacAddress mac) {
147 this.mac = checkNotNull(mac, "MAC address cannot be null");
148 return this;
149 }
150
151 /**
152 * Sets the tunnel remote ip address.
153 *
154 * @param remoteIp ip address
155 * @return destination info builder
156 */
157 public Builder setRemoteIp(IpAddress remoteIp) {
158 this.remoteIp = checkNotNull(remoteIp, "Remote IP address cannot be null");
159 return this;
160 }
161
162 /**
163 * Sets the tunnel id.
164 *
165 * @param tunnelId tunnel id
166 * @return destination info builder
167 */
168 public Builder setTunnelId(long tunnelId) {
169 this.tunnelId = checkNotNull(tunnelId, "Tunnel ID cannot be null");
170 return this;
171 }
172
173 /**
174 * Build a destination information.
175 *
176 * @return destination info object
177 */
178 public DestinationInfo build() {
179 return new DestinationInfo(this);
180 }
181 }
182
183 private DestinationInfo(Builder builder) {
184 output = builder.output;
185 ip = builder.ip;
186 mac = builder.mac;
187 remoteIp = builder.remoteIp;
188 tunnelId = builder.tunnelId;
189 }
190}