blob: f26eaf0bdf1e9458b0eacc609994a16de4aa2c3e [file] [log] [blame]
Charles Chan445659f2019-01-02 13:46:16 -08001/*
2 * Copyright 2019-present Open Networking Foundation
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.segmentrouting.xconnect.api;
17
18import org.onosproject.net.PortNumber;
19
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkArgument;
23
24/**
25 * Represents a cross connect endpoint specified by port number.
26 */
27public final class XconnectPortEndpoint extends XconnectEndpoint {
28 private final PortNumber port;
29
30 private XconnectPortEndpoint(PortNumber port) {
31 this.port = port;
32 }
33
34 /**
35 * Returns port number.
36 *
37 * @return port number
38 */
39 public PortNumber port() {
40 return port;
41 }
42
43 /**
44 * Returns an instance of XconnectPortEndpoint with given port number.
45 *
46 * @param port port number
47 * @return an instance of XconnectPortEndpoint
48 */
49 public static XconnectPortEndpoint of(PortNumber port) {
50 return new XconnectPortEndpoint(port);
51 }
52
53 /**
54 * Gets XconnectPortEndpoint from string.
55 *
56 * @param s string
57 * @return XconnectPortEndpoint
58 */
59 public static XconnectPortEndpoint fromString(String s) {
60 checkArgument(s.matches(PORT_PATTERN), "String {} does not match {} format", s, PORT_PATTERN);
61 return new XconnectPortEndpoint(PortNumber.fromString(s));
62 }
63
64 @Override
65 public XconnectEndpoint.Type type() {
66 return Type.PORT;
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hash(port);
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 if (this == obj) {
77 return true;
78 }
79 if (obj instanceof XconnectPortEndpoint) {
80 final XconnectPortEndpoint other = (XconnectPortEndpoint) obj;
81 return Objects.equals(this.port, other.port);
82 }
83 return false;
84 }
85
86 @Override
87 public String toString() {
88 return String.valueOf(port);
89 }
90}