blob: c7a2242b421d14dea4ddb284a55e56dcb472ad81 [file] [log] [blame]
Charles Chan16631de2019-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
18/**
19 * Represents cross connect endpoint.
20 */
21public abstract class XconnectEndpoint {
22 public static final String LB_KEYWORD = "LB:";
23 static final String PORT_PATTERN = "^\\d+$";
24 static final String LOAD_BALANCER_PATTERN = "^" + LB_KEYWORD + "\\d+$";
25
26 /**
27 * Types of endpoint.
28 */
29 public enum Type {
30 /**
31 * The endpoint is specified by an port number.
32 */
33 PORT,
34
35 /**
36 * The endpoint is specified by a load balancer.
37 */
38 LOAD_BALANCER
39 }
40
41 /**
42 * Type of this endpoint.
43 *
44 * @return type
45 */
46 public abstract XconnectEndpoint.Type type();
47
48 /**
49 * Constructs XconnectEndpoint from string.
50 *
51 * @param s string
52 * @return XconnectEndpoint
53 * @throws IllegalArgumentException if given string is in a wrong format
54 */
55 public static XconnectEndpoint fromString(String s) {
56 if (s.matches(XconnectEndpoint.PORT_PATTERN)) {
57 return XconnectPortEndpoint.fromString(s);
58 } else if (s.matches(XconnectEndpoint.LOAD_BALANCER_PATTERN)) {
59 return XconnectLoadBalancerEndpoint.fromString(s);
60 } else {
61 throw new IllegalArgumentException("Illegal endpoint format: " + s);
62 }
63 }
64}