blob: 278b82dce9b3baf0524ce44f063f3aca8889a566 [file] [log] [blame]
Phaneendra Manda1c0061d2015-08-06 12:29:38 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Phaneendra Manda1c0061d2015-08-06 12:29:38 +05303 *
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.pcep.controller;
17
Jian Li597d7b22016-02-29 14:06:55 -080018import org.onlab.packet.IpAddress;
19import org.onlab.util.Identifier;
20
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053021import java.net.URI;
22import java.net.URISyntaxException;
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053023
Jian Li597d7b22016-02-29 14:06:55 -080024import static com.google.common.base.Preconditions.checkArgument;
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053025
26/**
27 * The class representing a network client pc ip.
28 * This class is immutable.
29 */
Jian Li597d7b22016-02-29 14:06:55 -080030public final class PccId extends Identifier<IpAddress> {
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053031
32 private static final String SCHEME = "pcep";
33 private static final long UNKNOWN = 0;
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053034
35 /**
36 * Private constructor.
37 */
38 private PccId(IpAddress ipAddress) {
Jian Li597d7b22016-02-29 14:06:55 -080039 super(ipAddress);
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053040 }
41
42 /**
43 * Create a PccId from ip address.
44 *
45 * @param ipAddress IP address
46 * @return ipAddress
47 */
48 public static PccId pccId(IpAddress ipAddress) {
49 return new PccId(ipAddress);
50 }
51
52 /**
53 * Returns the ip address.
54 *
55 * @return ipAddress
56 */
57 public IpAddress ipAddress() {
Jian Li597d7b22016-02-29 14:06:55 -080058 return identifier;
Phaneendra Manda1c0061d2015-08-06 12:29:38 +053059 }
60
61 /**
62 * Returns PccId created from the given client URI.
63 *
64 * @param uri device URI
65 * @return pccid
66 */
67 public static PccId pccid(URI uri) {
68 checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme");
69 return new PccId(IpAddress.valueOf(uri.getSchemeSpecificPart()));
70 }
71
72 /**
73 * Produces client URI from the given DPID.
74 *
75 * @param pccid client pccid
76 * @return client URI
77 */
78 public static URI uri(PccId pccid) {
79 return uri(pccid.ipAddress());
80 }
81
82 /**
83 * Produces client URI from the given ip address.
84 *
85 * @param ipAddress ip of client
86 * @return client URI
87 */
88 public static URI uri(IpAddress ipAddress) {
89 try {
90 return new URI(SCHEME, ipAddress.toString(), null);
91 } catch (URISyntaxException e) {
92 return null;
93 }
94 }
95}