Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Satish K | f6d87cb | 2015-11-30 19:59:22 +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.iptopology.api.device; |
| 17 | |
| 18 | import org.onosproject.iptopology.api.DeviceTed; |
| 19 | import org.onosproject.iptopology.api.IpDeviceIdentifier; |
| 20 | import org.onosproject.net.AbstractDescription; |
| 21 | import org.onosproject.net.SparseAnnotations; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | import static org.onosproject.iptopology.api.IpDevice.Type; |
| 28 | |
| 29 | /** |
| 30 | * Default implementation of immutable device description entity. |
| 31 | */ |
| 32 | public class DefaultIpDeviceDescription extends AbstractDescription |
| 33 | implements IpDeviceDescription { |
| 34 | private final URI uri; |
| 35 | private final Type type; |
| 36 | private final IpDeviceIdentifier deviceIdentifier; |
| 37 | private final DeviceTed deviceTed; |
| 38 | |
| 39 | /** |
| 40 | * Creates an ip device description using the supplied information. |
| 41 | * |
| 42 | * @param uri device URI |
| 43 | * @param type device type |
| 44 | * @param deviceIdentifier device manufacturer |
| 45 | * @param deviceTed device Traffic Engineering parameters |
| 46 | * @param annotations optional key/value annotations map |
| 47 | */ |
| 48 | public DefaultIpDeviceDescription(URI uri, Type type, IpDeviceIdentifier deviceIdentifier, |
| 49 | DeviceTed deviceTed, SparseAnnotations... annotations) { |
| 50 | super(annotations); |
| 51 | this.uri = checkNotNull(uri, "Device URI cannot be null"); |
| 52 | this.type = checkNotNull(type, "Device type cannot be null"); |
| 53 | this.deviceIdentifier = deviceIdentifier; |
| 54 | this.deviceTed = deviceTed; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Creates an ip device description using the supplied information. |
| 59 | * @param base IpDeviceDescription to basic information |
| 60 | * @param annotations Annotations to use. |
| 61 | */ |
| 62 | public DefaultIpDeviceDescription(IpDeviceDescription base, SparseAnnotations... annotations) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 63 | this(base.deviceUri(), base.type(), base.deviceIdentifier(), |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 64 | base.deviceTed(), annotations); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Creates an ip device description using the supplied information. |
| 69 | * @param base IpDeviceDescription to basic information (except for type) |
| 70 | * @param type device type |
| 71 | * @param annotations Annotations to use. |
| 72 | */ |
| 73 | public DefaultIpDeviceDescription(IpDeviceDescription base, Type type, SparseAnnotations... annotations) { |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 74 | this(base.deviceUri(), type, base.deviceIdentifier(), |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 75 | base.deviceTed(), annotations); |
| 76 | } |
| 77 | |
| 78 | @Override |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 79 | public URI deviceUri() { |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 80 | return uri; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public Type type() { |
| 85 | return type; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public IpDeviceIdentifier deviceIdentifier() { |
| 90 | return deviceIdentifier; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public DeviceTed deviceTed() { |
| 95 | return deviceTed; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String toString() { |
| 100 | return toStringHelper(this) |
| 101 | .add("uri", uri) |
| 102 | .add("type", type) |
| 103 | .add("devid", deviceIdentifier) |
| 104 | .add("devTed", deviceTed) |
| 105 | .toString(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Default constructor for serialization. |
| 110 | */ |
| 111 | private DefaultIpDeviceDescription() { |
| 112 | this.uri = null; |
| 113 | this.type = null; |
| 114 | this.deviceIdentifier = null; |
| 115 | this.deviceTed = null; |
| 116 | } |
| 117 | } |