Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.pcep.controller; |
| 17 | |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 18 | import org.onlab.packet.IpAddress; |
| 19 | import org.onlab.util.Identifier; |
| 20 | |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 21 | import java.net.URI; |
| 22 | import java.net.URISyntaxException; |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 23 | |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 24 | import static com.google.common.base.Preconditions.checkArgument; |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * The class representing a network client pc ip. |
| 28 | * This class is immutable. |
| 29 | */ |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 30 | public final class PccId extends Identifier<IpAddress> { |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 31 | |
Priyanka B | 9bee080 | 2016-04-27 22:06:02 +0530 | [diff] [blame] | 32 | private static final String SCHEME = "l3"; |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 33 | private static final long UNKNOWN = 0; |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Private constructor. |
| 37 | */ |
| 38 | private PccId(IpAddress ipAddress) { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 39 | super(ipAddress); |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 40 | } |
| 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 Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 58 | return identifier; |
Phaneendra Manda | 1c0061d | 2015-08-06 12:29:38 +0530 | [diff] [blame] | 59 | } |
| 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 | } |