Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
| 16 | package org.onosproject.iptopology.api.device; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.packet.Ip6Address; |
| 20 | import org.onlab.packet.Ip4Address; |
| 21 | import org.onosproject.iptopology.api.InterfaceIdentifier; |
| 22 | import org.onosproject.net.AbstractDescription; |
| 23 | import org.onosproject.net.SparseAnnotations; |
| 24 | |
| 25 | /** |
| 26 | * Default implementation of immutable Interface description. |
| 27 | */ |
| 28 | public class DefaultInterfaceDescription extends AbstractDescription |
| 29 | implements InterfaceDescription { |
| 30 | |
| 31 | private final InterfaceIdentifier intfId; |
| 32 | private final Ip4Address ipv4Address; |
| 33 | private final Ip6Address ipv6Address; |
| 34 | |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * Creates an interface description using the supplied information. |
| 39 | * |
| 40 | * @param intfId interface identifier |
| 41 | * @param ipv4Address ipv4 address of an interface |
| 42 | * @param ipv6Address ipv6 address of an interface |
| 43 | * @param annotations optional key/value annotations map |
| 44 | */ |
| 45 | public DefaultInterfaceDescription(InterfaceIdentifier intfId, Ip4Address ipv4Address, |
| 46 | Ip6Address ipv6Address, SparseAnnotations...annotations) { |
| 47 | super(annotations); |
| 48 | this.intfId = intfId; |
| 49 | this.ipv4Address = ipv4Address; |
| 50 | this.ipv6Address = ipv6Address; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Default constructor for serialization. |
| 55 | */ |
| 56 | private DefaultInterfaceDescription() { |
| 57 | this.intfId = null; |
| 58 | this.ipv4Address = null; |
| 59 | this.ipv6Address = null; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates an interface description using the supplied information. |
| 64 | * |
| 65 | * @param base InterfaceDescription to get basic information from |
| 66 | * @param annotations optional key/value annotations map |
| 67 | */ |
| 68 | public DefaultInterfaceDescription(InterfaceDescription base, |
| 69 | SparseAnnotations annotations) { |
| 70 | this(base.intfId(), base.ipv4Address(), base.ipv6Address(), annotations); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public InterfaceIdentifier intfId() { |
| 75 | return intfId; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Ip4Address ipv4Address() { |
| 80 | return ipv4Address; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public Ip6Address ipv6Address() { |
| 85 | return ipv6Address; } |
| 86 | |
| 87 | @Override |
| 88 | public String toString() { |
| 89 | return MoreObjects.toStringHelper(getClass()) |
| 90 | .add("intfId", intfId) |
| 91 | .add("ipv4Address", ipv4Address) |
| 92 | .add("ipv6Address", ipv6Address) |
| 93 | .add("annotations", annotations()) |
| 94 | .toString(); |
| 95 | } |
| 96 | |
| 97 | } |