blob: fe918295c9fbe84cb5807768e6ac0d3597500530 [file] [log] [blame]
Satish Kf6d87cb2015-11-30 19:59:22 +05301/*
2 * Copyright 2014-2015 Open Networking Laboratory
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.iptopology.api.device;
17
18import org.onosproject.iptopology.api.DeviceTed;
19import org.onosproject.iptopology.api.IpDeviceIdentifier;
20import org.onosproject.net.AbstractDescription;
21import org.onosproject.net.SparseAnnotations;
22
23import java.net.URI;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26import static com.google.common.base.Preconditions.checkNotNull;
27import static org.onosproject.iptopology.api.IpDevice.Type;
28
29/**
30 * Default implementation of immutable device description entity.
31 */
32public 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 Hart51539b82015-10-29 09:53:04 -070063 this(base.deviceUri(), base.type(), base.deviceIdentifier(),
Satish Kf6d87cb2015-11-30 19:59:22 +053064 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 Hart51539b82015-10-29 09:53:04 -070074 this(base.deviceUri(), type, base.deviceIdentifier(),
Satish Kf6d87cb2015-11-30 19:59:22 +053075 base.deviceTed(), annotations);
76 }
77
78 @Override
Jonathan Hart51539b82015-10-29 09:53:04 -070079 public URI deviceUri() {
Satish Kf6d87cb2015-11-30 19:59:22 +053080 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}